Skip to content
Snippets Groups Projects
Commit ae731385 authored by CoDEmanX's avatar CoDEmanX
Browse files

Game Property Visualizer: added back modal method for realtime feedback (Area.tag_draw).

parent c993c924
Branches
Tags
No related merge requests found
...@@ -28,7 +28,8 @@ bl_info = { ...@@ -28,7 +28,8 @@ bl_info = {
"description": "Display the game properties next to selected objects " "description": "Display the game properties next to selected objects "
"in the 3d-view", "in the 3d-view",
"warning": "Script is returning errors", "warning": "Script is returning errors",
"wiki_url": "http://wiki.blender.org/index.php/Extensions:2.6/Py/Scripts/3D_interaction/Game_Property_Visualiser", "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.6/Py/"
"Scripts/3D_interaction/Game_Property_Visualiser",
"tracker_url": "https://developer.blender.org/T22607", "tracker_url": "https://developer.blender.org/T22607",
"category": "3D View"} "category": "3D View"}
...@@ -52,8 +53,8 @@ def calc_callback(self, context): ...@@ -52,8 +53,8 @@ def calc_callback(self, context):
return return
# get screen information # get screen information
mid_x = context.region.width/2.0 mid_x = context.region.width / 2.0
mid_y = context.region.height/2.0 mid_y = context.region.height / 2.0
width = context.region.width width = context.region.width
height = context.region.height height = context.region.height
...@@ -61,7 +62,7 @@ def calc_callback(self, context): ...@@ -61,7 +62,7 @@ def calc_callback(self, context):
view_mat = context.space_data.region_3d.perspective_matrix view_mat = context.space_data.region_3d.perspective_matrix
ob_mat = context.active_object.matrix_world ob_mat = context.active_object.matrix_world
total_mat = view_mat*ob_mat total_mat = view_mat * ob_mat
# calculate location info # calculate location info
texts = [] texts = []
...@@ -76,15 +77,15 @@ def calc_callback(self, context): ...@@ -76,15 +77,15 @@ def calc_callback(self, context):
for p in ob.game.properties: for p in ob.game.properties:
# d = {'data':p.name+':'+str(p.value)} # d = {'data':p.name+':'+str(p.value)}
# print (d) # print (d)
locs.append(mathutils.Vector((0,0,0,1))) locs.append(mathutils.Vector((0, 0, 0, 1)))
for loc in locs: for loc in locs:
vec = total_mat * loc # order is important vec = total_mat * loc # order is important
# dehomogenise # dehomogenise
vec = mathutils.Vector((vec[0]/vec[3],vec[1]/vec[3],vec[2]/vec[3])) vec = mathutils.Vector((vec[0]/vec[3], vec[1]/vec[3], vec[2]/vec[3]))
x = int(mid_x + vec[0]*width/2.0) x = int(mid_x + vec[0]*width / 2.0)
y = int(mid_y + vec[1]*height/2.0) y = int(mid_y + vec[1]*height / 2.0)
texts+=[x, y] texts += [x, y]
# store as ID property in mesh # store as ID property in mesh
context.scene['GamePropsVisualizer'] = texts context.scene['GamePropsVisualizer'] = texts
...@@ -110,21 +111,21 @@ def draw_callback(self, context): ...@@ -110,21 +111,21 @@ def draw_callback(self, context):
texts = context.scene['GamePropsVisualizer'] texts = context.scene['GamePropsVisualizer']
# draw # draw
i=0 i = 0
blf.size(0, 12, 72) blf.size(0, 12, 72)
bgl.glColor3f(1.0,1.0,1.0) bgl.glColor3f(1.0, 1.0, 1.0)
for ob in bpy.context.selected_objects: for ob in bpy.context.selected_objects:
for pi,p in enumerate(ob.game.properties): for pi,p in enumerate(ob.game.properties):
blf.position(0, texts[i], texts[i+1]-(pi+1)*14, 0) blf.position(0, texts[i], texts[i+1] - (pi+1) * 14, 0)
if p.type=='FLOAT': if p.type=='FLOAT':
t=p.name+': '+ str('%g'% p.value) t=p.name+': '+ str('%g' % p.value)
else: else:
t=p.name+': '+ str(p.value) t=p.name+': '+ str(p.value)
blf.draw(0, t) blf.draw(0, t)
i+=2 i += 2
# operator # operator
...@@ -156,22 +157,33 @@ class GamePropertyVisualizer(bpy.types.Operator): ...@@ -156,22 +157,33 @@ class GamePropertyVisualizer(bpy.types.Operator):
def poll(cls, context): def poll(cls, context):
return context.mode != 'EDIT_MESH' return context.mode != 'EDIT_MESH'
def execute(self, context): def modal(self, context, event):
if not context.scene.display_game_properties:
return self.cancel(context)
context.area.tag_redraw()
return {'PASS_THROUGH'}
def invoke(self, context, event):
if context.area.type == 'VIEW_3D': if context.area.type == 'VIEW_3D':
if not context.scene.display_game_properties: if not context.scene.display_game_properties:
# operator is called and not running # operator is called and not running
GamePropertyVisualizer.handle_add(self, context) GamePropertyVisualizer.handle_add(self, context)
context.scene.display_game_properties = True context.scene.display_game_properties = True
context.window_manager.modal_handler_add(self)
return {'RUNNING_MODAL'}
else: else:
# operator is called again, stop displaying # operator is called again, stop displaying
GamePropertyVisualizer.handle_remove() return self.cancel(context)
context.scene.display_game_properties = False
context.area.tag_redraw()
return {'FINISHED'}
else: else:
self.report({'WARNING'}, "View3D not found, can't run operator") self.report({'WARNING'}, "View3D not found, can't run operator")
return {'CANCELLED'} return {'CANCELLED'}
def cancel(self, context):
GamePropertyVisualizer.handle_remove()
context.scene.display_game_properties = False
context.area.tag_redraw()
return {'FINISHED'}
# defining the panel # defining the panel
def menu_func(self, context): def menu_func(self, context):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment