def getParent(self): # The method is called currently in the single place of the code: # in <Renderer.prerender(..)> if (not layer.singleObject and app.layered) parent = self.parent if not self.parent: parent = createEmptyObject(self.name, self.parentLocation.copy(), empty_draw_size=0.01) parent.parent = Renderer.parent self.parent = parent return parent
def getLayerParent(self): layerIndex = self.layerIndex layerParents = self.layerParents layerParent = layerParents[layerIndex] if not layerParent: layerParent = createEmptyObject(self.getLayerName( layerIndex, self.op), zeroVector(), empty_draw_size=0.01) layerParent.parent = Renderer.parent layerParents[layerIndex] = layerParent return layerParent
def getLayerParent(self): layerIndex = self.layerIndex layerParents = self.layerParents layerParent = layerParents[layerIndex] if not layerParent: layerParent = createEmptyObject( self.getLayerName(layerIndex, self.op), zeroVector(), empty_draw_size=0.01 ) layerParent.parent = Renderer.parent layerParents[layerIndex] = layerParent return layerParent
def parent_set(self, parent, obj): if "co" in parent: modelParent = parent.parent # <parent> must be for the level with the index zero parent = None for levelParent in modelParent.children: if "level" in levelParent and not levelParent["level"]: parent = levelParent break if not parent: # create a Blender parent object for the level with the index zero parent = createEmptyObject("level0", (0., 0., 0.), True, **Wall.emptyPropsLevel) parent["level"] = 0 parent_set(modelParent, parent) parent_set(parent, obj)
def invoke(self, context, event): o = context.object bpy.ops.object.mode_set(mode='OBJECT') childOffset = createEmptyObject("offset_" + o.name, context.scene.cursor_location - o.location, False, empty_draw_size=0.01) childOffset["t"] = "offset" childOffset.parent = o # make <childOffset> the active object o.select = False makeActiveSelected(context, childOffset) return {'FINISHED'}
def invoke(self, context, event): o = context.object bpy.ops.object.mode_set(mode='OBJECT') childOffset = createEmptyObject( "offset_" + o.name, context.scene.cursor_location - o.location, False, empty_draw_size=0.01 ) childOffset["t"] = "offset" childOffset.parent = o # make <childOffset> the active object o.select = False makeActiveSelected(context, childOffset) return {'FINISHED'}
def begin(self, app): self.name = os.path.basename(app.osmFilepath) if app.layered or not app.singleObject: self.parent = createEmptyObject( self.name, zeroVector(), empty_draw_size=0.01 ) if app.singleObject and not app.layered: self.bm = bmesh.new() self.obj = self.createBlenderObject(self.name, None, None) # cache material indices in <self.materialIndices> self.materialIndices = {} # store here Blender object that are to be joined self.toJoin = {}
def execute(self, context): o = context.object o["t"] = Template.type o.name = "T_Frame" o.data.name = "T_Frame" location = o.location.copy() o.location = zeroVector o.show_wire = True o.show_all_edges = True o["id"] = 1 # reverse the surface <s1> by default o["s1"] = "reversed" parent = createEmptyObject(self.objectNameBase, location, False, empty_draw_size=0.05) parent["t"] = context.scene.prk.workshopType o.parent = parent parent["part_counter"] = 2 parent["vert_counter"] = 1 return {'FINISHED'}
def invoke(self, context, event): o = context.object bpy.ops.object.mode_set(mode='OBJECT') assetType = context.scene.prk.item.window.assetType # Blender EMPTY object as a placeholder for the offset a = createEmptyObject( o.name + "_" + assetType, context.scene.cursor_location - o.location, False, empty_draw_size=0.01 ) a["t"] = "asset" a["t2"] = assetType a.parent = o props = context.scene.prk.item # side (internal or external) for the asset if props.assetSideIe != 'n': # <sie> stands for <side internal or external> a["sie"] = props.assetSideIe # check if there is a selected vertex and if it defines the node's open end index = 0 for v in o.data.vertices: if v.select: # iterate through vertex groups of the vertex <v> for g in v.groups: name = o.vertex_groups[g.group].name if name[:2] == "e_": index = int(name[2:]) break if index: break if index: # remember the index of the node's open end a["e"] = index # make <a> the active object o.select = False makeActiveSelected(context, a) return {'FINISHED'}
def begin(self, op): self.name = os.path.basename(op.filepath) if op.layered or not op.singleObject: self.parent = createEmptyObject(self.name, zeroVector(), empty_draw_size=0.01) if op.singleObject: if op.layered: self.layerMeshes = [None for _ in op.layerIndices] self.layerObjects = [None for _ in op.layerIndices] # cache material indices in <self.materialIndices> self.materialIndices = [None for _ in op.layerIndices] else: self.bm = bmesh.new() self.obj = self.createBlenderObject(self.name, None) # cache material indices in <self.materialIndices> self.materialIndices = {} else: if op.layered: self.layerParents = [None for _ in op.layerIndices]
def setupMaster(self, context, point1, point2): o = self.o # create a master EMPTY resembling <o> master = createEmptyObject("tmp", o.location, empty_draw_type=o.empty_draw_type, empty_draw_size=o.empty_draw_size) master.lock_location[2] = True self.master = master # rotate master along the line defined by point1 and point2 master.rotation_euler[2] = math.atan2(point2.y-point1.y, point2.x-point1.x) parent_set(o.parent, master) o.select = False # make <o> a slave of <master> # x x = o.driver_add("location", 0) addTransformsVariable(x, "x", master, "LOC_X") x.driver.expression = "x" # y y = o.driver_add("location", 1) addTransformsVariable(y, "y", master, "LOC_Y") y.driver.expression = "y" makeActiveSelected(context, master)
def invoke(self, context, event): o = context.object bpy.ops.object.mode_set(mode='OBJECT') assetType = context.scene.prk.item.window.assetType # Blender EMPTY object as a placeholder for the offset a = createEmptyObject(o.name + "_" + assetType, context.scene.cursor_location - o.location, False, empty_draw_size=0.01) a["t"] = "asset" a["t2"] = assetType a.parent = o props = context.scene.prk.item # side (internal or external) for the asset if props.assetSideIe != 'n': # <sie> stands for <side internal or external> a["sie"] = props.assetSideIe # check if there is a selected vertex and if it defines the node's open end index = 0 for v in o.data.vertices: if v.select: # iterate through vertex groups of the vertex <v> for g in v.groups: name = o.vertex_groups[g.group].name if name[:2] == "e_": index = int(name[2:]) break if index: break if index: # remember the index of the node's open end a["e"] = index # make <a> the active object o.select = False makeActiveSelected(context, a) return {'FINISHED'}
def begin(self, op): self.name = os.path.basename(op.filepath) if op.layered or not op.singleObject: self.parent = createEmptyObject( self.name, zeroVector(), empty_draw_size=0.01 ) if op.singleObject: if op.layered: self.layerMeshes = [None for _ in op.layerIndices] self.layerObjects = [None for _ in op.layerIndices] # cache material indices in <self.materialIndices> self.materialIndices = [None for _ in op.layerIndices] else: self.bm = bmesh.new() self.obj = self.createBlenderObject(self.name, None) # cache material indices in <self.materialIndices> self.materialIndices = {} else: if op.layered: self.layerParents = [None for _ in op.layerIndices]
def make(self, t, **kwargs): verts = t.bm.verts context = self.context hooksForNodes = kwargs["hooksForNodes"] # template Blender object _o = t.o # Create a Blender EMPTY object to serve as a parent for the window mesh; # its name doesn't have <T_> prefix name = _o.name[2:] # <pt> stands for parent template pt = t.parentTemplate if pt: p = createEmptyObject(name, _o.location-pt.o.location, False, empty_draw_size=0.01) else: # parent for the whole hierarchy of window Blender objects p = t.p t.meshParent = p # start a Blender object for the template o = createMeshObject(name + "_mesh") t.meshObject = o context.scene.update() # perform parenting parent_set(p, o) if t.parentTemplate: parent_set(pt.meshParent, p) context.scene.update() context.scene.objects.active = o t.prepareOffsets() # iterate through the vertices of the template Blender object numVerts = 0 for v in verts: # id of the vertex vid = t.getVid(v) if not (vid in _o and _o[vid] in bpy.data.objects): continue # Blender object for the node at the vertex j = bpy.data.objects[_o[vid]] t.setNode(v, j, o, context, hooksForNodes = hooksForNodes) numVerts += 1 # final operations: bridging or extruding edges loops of the nodes, making surfaces bm = getBmesh(o) t.bridgeOrExtendNodes(o, bm, kwargs["dissolveEndEdges"]) if numVerts == len(verts): t.makeSurfaces(o, bm) setBmesh(o, bm) # remove unneeded vertex group groups = [g for g in o.vertex_groups if g.name[0] in ("e", "s", "c")] for g in groups: o.vertex_groups.remove(g) # add Edge Split modifier if kwargs["addEdgeSplitModifier"]: addEdgeSplitModifier(o, o.name) # set maximum possible range for the shape keys if hooksForNodes and o.data.shape_keys: for kb in o.data.shape_keys.key_blocks: kb.slider_min = -10. kb.slider_max = 10. t.insertAssets(context) # hide the template Blender object and all its children hide(t.o, True)
def make(self, t, **kwargs): verts = t.bm.verts context = self.context hooksForNodes = kwargs["hooksForNodes"] # template Blender object _o = t.o # Create a Blender EMPTY object to serve as a parent for the window mesh; # its name doesn't have <T_> prefix name = _o.name[2:] # <pt> stands for parent template pt = t.parentTemplate if pt: p = createEmptyObject(name, _o.location - pt.o.location, False, empty_draw_size=0.01) else: # parent for the whole hierarchy of window Blender objects p = t.p t.meshParent = p # start a Blender object for the template o = createMeshObject(name + "_mesh") t.meshObject = o context.scene.update() # perform parenting parent_set(p, o) if t.parentTemplate: parent_set(pt.meshParent, p) context.scene.update() context.scene.objects.active = o t.prepareOffsets() # iterate through the vertices of the template Blender object numVerts = 0 for v in verts: # id of the vertex vid = t.getVid(v) if not (vid in _o and _o[vid] in bpy.data.objects): continue # Blender object for the node at the vertex j = bpy.data.objects[_o[vid]] t.setNode(v, j, o, context, hooksForNodes=hooksForNodes) numVerts += 1 # final operations: bridging or extruding edges loops of the nodes, making surfaces bm = getBmesh(o) t.bridgeOrExtendNodes(o, bm, kwargs["dissolveEndEdges"]) if numVerts == len(verts): t.makeSurfaces(o, bm) setBmesh(o, bm) # remove unneeded vertex group groups = [g for g in o.vertex_groups if g.name[0] in ("e", "s", "c")] for g in groups: o.vertex_groups.remove(g) # add Edge Split modifier if kwargs["addEdgeSplitModifier"]: addEdgeSplitModifier(o, o.name) # set maximum possible range for the shape keys if hooksForNodes and o.data.shape_keys: for kb in o.data.shape_keys.key_blocks: kb.slider_min = -10. kb.slider_max = 10. t.insertAssets(context) # hide the template Blender object and all its children hide(t.o, True)