1
# ##### BEGIN GPL LICENSE BLOCK #####
3
# This program is free software; you can redistribute it and/or
4
# modify it under the terms of the GNU General Public License
5
# as published by the Free Software Foundation; either version 2
6
# of the License, or (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software Foundation,
15
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
# ##### END GPL LICENSE BLOCK #####
23
'name': 'Game Property Visualiser',
24
'author': 'Bartius Crouch/Vilem Novak',
27
'location': 'View3D > Properties panel > Display tab',
28
'description': 'Display the game properties next to selected objects '\
30
'wiki_url': 'http://wiki.blender.org/index.php/Extensions:2.5/Py/Scripts/3D_interaction/Game_Property_Visualiser',
31
'tracker_url': 'http://projects.blender.org/tracker/?func=detail&aid=22607&group_id=153&atid=468',
32
'category': '3D View'}
35
Displays game properties next to selected objects(under name)
38
just toggle the button 'Visualise game props' in the right side panel
47
# calculate locations and store them as ID property in the mesh
48
def calc_callback(self, context):
50
if context.mode == 'EDIT_MESH':
53
# get screen information
54
mid_x = context.region.width/2.0
55
mid_y = context.region.height/2.0
56
width = context.region.width
57
height = context.region.height
60
view_mat = context.space_data.region_3d.perspective_matrix
62
ob_mat = context.active_object.matrix_world
63
total_mat = view_mat*ob_mat
65
# calculate location info
68
# uncomment 2 lines below, to enable live updating of the selection
69
#ob=context.active_object
70
for ob in context.selected_objects:
72
ob_mat = ob.matrix_world
73
total_mat = view_mat*ob_mat
75
for p in ob.game.properties:
76
d=0.0#{'data':p.name+':'+str(p.value)}
78
locs.append([ mathutils.Vector([0,0,0]).resize_4d()])
83
vec = loc[0]*total_mat # order is important
85
vec = mathutils.Vector((vec[0]/vec[3],vec[1]/vec[3],vec[2]/vec[3]))
86
x = int(mid_x + vec[0]*width/2.0)
87
y = int(mid_y + vec[1]*height/2.0)
91
# store as ID property in mesh
93
context.scene['GamePropsVisualiser'] = texts
97
def draw_callback(self, context):
99
if context.mode == 'EDIT_MESH':
101
# retrieving ID property data
103
#print(context.scene['GamePropsVisualiser'])
104
texts = context.scene['GamePropsVisualiser']
117
bgl.glColor3f(1.0,1.0,1.0)
118
for ob in bpy.context.selected_objects:
119
for pi,p in enumerate(ob.game.properties):
120
blf.position(0, texts[i], texts[i+1]-(pi+1)*14, 0)
122
t=p.name+': '+ str('%g'% p.value)
124
t=p.name+': '+ str(p.value)
130
class GamePropertyVisualiser(bpy.types.Operator):
131
bl_idname = "view3d.game_props_visualiser"
132
bl_label = "Game Properties Visualiser"
133
bl_description = "Toggle the visualisation of game properties"
136
def poll(cls, context):
137
return context.mode!='EDIT_MESH'
139
def modal(self, context, event):
140
context.area.tag_redraw()
142
# removal of callbacks when operator is called again
143
#print(context.scene.display_game_properties)
144
if context.scene.display_game_properties == -1:
147
context.scene.display_game_properties = 0
148
context.region.callback_remove(self.handle1)
149
context.region.callback_remove(self.handle2)
150
context.scene.display_game_properties = 0
154
return {'PASS_THROUGH'}
156
def invoke(self, context, event):
157
if context.area.type == 'VIEW_3D':
158
print(context.scene.display_game_properties)
159
if context.scene.display_game_properties == 0 or context.scene.display_game_properties == -1:
161
# operator is called for the first time, start everything
162
context.scene.display_game_properties = 1
163
context.window_manager.modal_handler_add(self)
164
self.handle1 = context.region.callback_add(calc_callback,
165
(self, context), 'POST_VIEW')
166
self.handle2 = context.region.callback_add(draw_callback,
167
(self, context), 'POST_PIXEL')
168
return {'RUNNING_MODAL'}
170
# operator is called again, stop displaying
171
context.scene.display_game_properties = -1
174
return {'RUNNING_MODAL'}
176
self.report({'WARNING'}, "View3D not found, can't run operator")
181
def menu_func(self, context):
182
col = self.layout.column(align=True)
183
col.operator(GamePropertyVisualiser.bl_idname, text="Visualise game props")
184
self.layout.separator()
188
bpy.types.Scene.display_game_properties = bpy.props.IntProperty(name='Visualise Game Poperties')
189
bpy.types.VIEW3D_PT_view3d_display.prepend(menu_func)
192
del bpy.types.Scene.display_game_properties
193
bpy.types.VIEW3D_PT_view3d_display.remove(menu_func)
195
if __name__ == "__main__":