def BlockDrawTypeLineType(self, block: Block, component: Component, vanilla_skins=False) -> 'Object': ''' This is the draw type intended for line type blocks. These blocks have a position, scale, rotation, start position, end position, start rotation and end rotation. These values are used to draw a block that connects 2 points. Parameters block : Block : Block to import component : Component : Component to import vanilla_skins : Bool : Import vanilla skins Returns : Object Exceptions : None ''' # Import the connector, start and end objects connector = self.ImportCustomModel(component.line_type_middle) start = self.ImportCustomModel(component.line_type_end) end = self.ImportCustomModel(component.line_type_start) # Set the material for models if self.setting_GenerateMaterial: material = self.GenerateMaterial( block, component, component.skin_name ) #if not self.setting_use_vanilla_skin else self.GenerateMaterial(block, component, "TemplateB") start.active_material = material end.active_material = material connector.active_material = material # Create the empty object. We'll be using it as # a parent parent = bpy.data.objects.new("empty", None) parent.empty_display_size = 0.25 parent.empty_display_type = 'CUBE' bpy.data.collections[bpy.context.view_layer.active_layer_collection. name].objects.link(parent) # Set the location of the blocks start.location = Vector(block.GetLineStartPosition()) end.location = Vector(block.GetLineEndPosition()) connector.location = Vector(block.GetLineStartPosition()) parent.location = Vector((block.getVectorPosition())) # Set parents of the start, end # and connector block to the empty object start.parent = parent end.parent = parent # Set the rotation of the parent, So it'll # transforming the other child blocks as well parent.rotation_mode = 'QUATERNION' parent.rotation_quaternion = Quaternion( block.getQuarternion()).inverted() parent.rotation_mode = 'XYZ' # Set the name of the blocks. We'll be # using the GUID in the name so it'll be # easier to debug parent.name = "LineType_" + block.guid start.name = "StartPoint_" + block.guid end.name = "EndPoint_" + block.guid connector.name = "Connector_" + block.guid # Reset the parent transformation data so that # the rotation is (0,0,0). Basically doing # parenting an object while keeping the transformation self.ResetParentTransformRotation(end, parent) self.ResetParentTransformRotation(start, parent) # Set the rotation of the start block start_rot = Euler(block.GetLineStartRotation()) start_rot.rotate(block.GetGlobalMachineRotation().inverted()) start.rotation_euler = start_rot start.rotation_mode = 'ZXY' self.InvertRotation(start) # Set the rotation of the end block end_rot = Euler(block.GetLineEndRotation()) end_rot.rotate(block.GetGlobalMachineRotation().inverted()) end.rotation_euler = end_rot end.rotation_mode = 'ZXY' self.InvertRotation(end) # Set the scale of the parent object, # which will deform the blocks parent.scale = block.getScale() # We'll be using a Track-To contraint to point the start block at the end block. # So here we'll be creating the contraint and configuring it to point at the end # block connector.parent = parent self.ResetParentTransformRotation(connector, parent) constraint = connector.constraints.new('TRACK_TO') constraint.track_axis = "TRACK_Y" constraint.up_axis = "UP_X" constraint.target = end distance = self.GetDistance([start, end]) connector.dimensions[1] = distance # If the length between the starting and end block is less than a specific value # the end and the connector block will be deleted. This specific value... we dont # know if distance < self.setting_brace_threshhold: bpy.data.objects.remove(connector) bpy.data.objects.remove(end) if self.setting_join_line_components: for obj in list(bpy.context.selected_objects): obj.select_set(False) bpy.context.view_layer.objects.active = start start.select_set(True) if not distance < self.setting_brace_threshhold: connector.select_set(True) end.select_set(True) bpy.ops.object.join() current_obj = bpy.context.selected_objects[0] if self.setting_clean_up_action == 'DELETE_EMPTIES': self.UnparentKeepTransform(current_obj) bpy.data.objects.remove(parent) elif self.setting_clean_up_action == 'HIDE_EMPTIES': parent.hide_set(True) return current_obj return parent