def __init__( self, target_obj, target_mx=None, source_bvh=None, source_mx=None ): self.calllist = None if type(target_obj) is bpy.types.Object: print('Creating BMeshRender for ' + target_obj.name) self.tar_bmesh = bmesh.new() self.tar_bmesh.from_object( target_obj, bpy.context.scene, deform=True) self.tar_mx = target_mx or target_obj.matrix_world elif type(target_obj) is bmesh.types.BMesh: self.tar_bmesh = target_obj self.tar_mx = target_mx or Matrix() else: assert False, 'Unhandled type: ' + str(type(target_obj)) self.src_bvh = source_bvh self.src_mx = source_mx or Matrix() self.src_imx = invert_matrix(self.src_mx) self.src_mxnorm = matrix_normal(self.src_mx) self.bglMatrix = bgl.Buffer(bgl.GL_FLOAT, [16]) for i, v in enumerate( v for r in self.tar_mx.transposed() for v in r ): self.bglMatrix[i] = v self.is_dirty = True self.calllist = bgl.glGenLists(1)
def __init__(self, bmesh, mx=None): self.calllist = None self.bmesh = bmesh self.mx = mx if mx: self.bglMatrix = bgl.Buffer(bgl.GL_FLOAT, [16]) for i,v in enumerate([v for r in self.mx.transposed() for v in r]): self.bglMatrix[i] = v self.is_dirty = True self.calllist = bgl.glGenLists(1)
def __init__(self, bmesh, mx=None): self.calllist = None self.bmesh = bmesh self.mx = mx if mx: self.bglMatrix = bgl.Buffer(bgl.GL_FLOAT, [16]) for i, v in enumerate([v for r in self.mx.transposed() for v in r]): self.bglMatrix[i] = v self.is_dirty = True self.calllist = bgl.glGenLists(1)
def __init__(self, obj, xform=None): self.calllist = None if type(obj) is bpy.types.Object: print('Creating BMeshRender for ' + obj.name) self.bme = bmesh.new() self.bme.from_object(obj, bpy.context.scene, deform=True) self.xform = xform or XForm(obj.matrix_world) elif type(obj) is bmesh.types.BMesh: self.bme = obj self.xform = xform or XForm() else: assert False, 'Unhandled type: ' + str(type(obj)) self.buf_matrix_model = self.xform.to_bglMatrix_Model() self.buf_matrix_normal = self.xform.to_bglMatrix_Normal() self.is_dirty = True self.calllist = bgl.glGenLists(1)
def draw_callback_view(n_id, cached_view, options): def Vector_generate2(prop): # try: # return [[Vector(v[:3]) for v in obj] for obj in prop] # except ValueEror: # return [] return [[Vector(v) for v in obj] for obj in prop] # context = bpy.context if options["timings"]: start = time.perf_counter() if options['draw_list'] == 0: sl1 = cached_view[n_id + 'v'] sl2 = cached_view[n_id + 'ep'] sl3 = cached_view[n_id + 'm'] if sl1: data_vector = Vector_generate2(sl1) verlen = len(data_vector) - 1 else: if not sl3: # end early: no matrix and no vertices callback_disable(n_id) return # display matrix repr only. data_vector = [] verlen = 0 options['verlen'] = verlen data_polygons = [] data_edges = [] if sl2 and sl2[0]: if isinstance(sl2[0], int): #callback_disable(n_id) return len_sl2 = len(sl2[0][0]) if len_sl2 == 2: data_edges = sl2 elif len_sl2 > 2: data_polygons = sl2 if sl3: data_matrix = Matrix_generate(sl3) else: data_matrix = [Matrix() for i in range(verlen + 1)] if (data_vector, data_polygons, data_matrix, data_edges) == (0, 0, 0, 0): #callback_disable(n_id) return try: the_display_list = glGenLists(1) glNewList(the_display_list, GL_COMPILE) draw_geometry(n_id, options, data_vector, data_polygons, data_matrix, data_edges) except Exception as err: print("Error in callback!:") traceback.print_exc() options['error'] = True finally: glEndList() options['genlist'] = the_display_list elif options['draw_list'] == 1: the_display_list = options['genlist'] if not 'error' in options: glCallList(the_display_list) glFlush() # restore to system state glLineWidth(1) if options["timings"]: stop = time.perf_counter() print("callback drawn in {:4f}".format(stop - start)) # has drawn once with success. options['draw_list'] = 1
from . scene_props import * import bgl from . constants import * from . material import * from . collision import * from . export_thug1 import * from . export_thug2 import * from . export_shared import * from . import_nodes import * from . presets import * from . import script_template from mathutils import Vector # PROPERTIES ############################################# draw_stuff_display_list_id = bgl.glGenLists(1) draw_stuff_dirty = True draw_stuff_objects = set() draw_handle = None # METHODS ############################################# @bpy.app.handlers.persistent def draw_stuff_post_update(scene): # print("draw_stuff_post_update") global draw_stuff_dirty, draw_stuff_objects if draw_stuff_dirty: return if not draw_stuff_objects: draw_stuff_dirty = True return
def draw_callback_view(n_id, cached_view, options): def Vector_generate2(prop): # try: # return [[Vector(v[:3]) for v in obj] for obj in prop] # except ValueEror: # return [] return [[Vector(v) for v in obj] for obj in prop] # context = bpy.context if options["timings"]: start = time.perf_counter() if options['draw_list'] == 0: sl1 = cached_view[n_id + 'v'] sl2 = cached_view[n_id + 'ep'] sl3 = cached_view[n_id + 'm'] if sl1: data_vector = Vector_generate2(sl1) verlen = len(data_vector)-1 else: if not sl3: # end early: no matrix and no vertices callback_disable(n_id) return # display matrix repr only. data_vector = [] verlen = 0 options['verlen'] = verlen data_polygons = [] data_edges = [] if sl2 and sl2[0]: if isinstance(sl2[0], int): callback_disable(n_id) return len_sl2 = len(sl2[0][0]) if len_sl2 == 2: data_edges = sl2 elif len_sl2 > 2: data_polygons = sl2 if sl3: data_matrix = Matrix_generate(sl3) else: data_matrix = [Matrix() for i in range(verlen+1)] if (data_vector, data_polygons, data_matrix, data_edges) == (0, 0, 0, 0): callback_disable(n_id) return try: the_display_list = glGenLists(1) glNewList(the_display_list, GL_COMPILE) draw_geometry(n_id, options, data_vector, data_polygons, data_matrix, data_edges) except Exception as err: print("Error in callback!:") traceback.print_exc() options['error'] = True finally: glEndList() options['genlist'] = the_display_list elif options['draw_list'] == 1: the_display_list = options['genlist'] if not 'error' in options: glCallList(the_display_list) glFlush() # restore to system state glLineWidth(1) if options["timings"]: stop = time.perf_counter() print("callback drawn in {:4f}".format(stop-start)) # has drawn once with success. options['draw_list'] = 1
def __init__(self): self.update = True self.ignore_next_update = False self.list = bgl.glGenLists(1)