def dict_to_scene_graph(node_dict, use_gui=True): node = GraphNode() node.name = node_dict["name"] node.id = node_dict["id"] node.data = [] node.use_gui = use_gui node.transform.load_from_dict(node_dict["transform"]) pos_component = EComponent.from_script("components.position") pos_component.property_vals["pos"][0] = str(int(node.transform.trans[0].item() * 1000) / 1000) pos_component.property_vals["pos"][1] = str(int(node.transform.trans[1].item() * 1000) / 1000) pos_component.property_vals["pos"][2] = str(int(node.transform.trans[2].item() * 1000) / 1000) pos_component.property_vals["rot"][0] = str(math.degrees(int(node.transform.rot[0].item() * 1000) / 1000)) pos_component.property_vals["rot"][1] = str(math.degrees(int(node.transform.rot[1].item() * 1000) / 1000)) pos_component.property_vals["rot"][2] = str(math.degrees(int(node.transform.rot[2].item() * 1000) / 1000)) pos_component.property_vals["scale"][0] = str(int(node.transform.scale[0].item() * 1000) / 1000) pos_component.property_vals["scale"][1] = str(int(node.transform.scale[1].item() * 1000) / 1000) pos_component.property_vals["scale"][2] = str(int(node.transform.scale[2].item() * 1000) / 1000) node.add_component(pos_component) for component_dict in node_dict["components"]: component = EComponent.load_from_dict(component_dict) node.add_component(component) for child in node_dict["children"]: node.add_child(GraphNode.dict_to_scene_graph(child, use_gui)) return node
def __init__(self): EComponent.__init__(self) self.x_arrow_gizmo = None self.y_arrow_gizmo = None self.z_arrow_gizmo = None self.x_ring_gizmo = None self.y_ring_gizmo = None self.z_ring_gizmo = None self.x_handle_gizmo = None self.y_handle_gizmo = None self.z_handle_gizmo = None
def __init__(self): EComponent.__init__(self) self.x_circle_gizmo = None self.y_circle_gizmo = None self.z_circle_gizmo = None self.x_min_gizmo = None self.x_max_gizmo = None self.y_min_gizmo = None self.y_max_gizmo = None self.z_min_gizmo = None self.z_max_gizmo = None self.start_size = 0 self.start_center = 0 self.rigidbody_component = None self.touching = []
def set_components(self, components): self.add_component_dropdown.menu.child.clear() self.components = components # Add "add component" menu items for component in self.components: component_item = GUIMenuItem() component_item.child.set_text(EComponent.from_script(component).name) component_item.on_release = self.add_component_handler component_item.data = component self.add_component_dropdown.menu.child.add_child(component_item)
def add_node_handler(self, item): # Create new node pos_comp = EComponent.from_script("components.position") pos_comp.property_vals["scale"][0] = "1" pos_comp.property_vals["scale"][1] = "1" pos_comp.property_vals["scale"][2] = "1" new_node = GraphNode(f"New Node ({len(item.data.sub_list)})", [pos_comp]) item.data.data.add_child(new_node) new_node.component_property_changed() # Update model self.envedit_data.modify() self.envedit_data.update()
def add_component_handler(self, item): component = EComponent.from_script(item.data) self.envedit_data.target_node.add_component(component) self.envedit_data.target_node.component_property_changed_selected() self.envedit_data.modify() self.envedit_data.update()
def __init__(self): EComponent.__init__(self)
def __init__(self): EComponent.__init__(self) self.parent_path = None self.update_parent = True
def __init__(self): EComponent.__init__(self) self.mesh = None self.mesh_gizmo = None self.armature = None
def __init__(self): EComponent.__init__(self) self.body_path = None self.kinematic = False
def __init__(self): EComponent.__init__(self) self.nodes = [] self.bone_mats = PTA_LMatrix4f() self.bind_mats = []
def process_node(scene_node, parent_mat, joint_node_dict, node_list, folder_name): node = GraphNode("Model Node", []) if "name" in scene_node.xmlnode.attrib: node.name = scene_node.xmlnode.attrib["name"] # Register joint if "type" in scene_node.xmlnode.attrib and scene_node.xmlnode.attrib[ "type"].lower() == "joint": bind_mat = np.linalg.inv(parent_mat.dot(scene_node.matrix)) bind_array = [] for y in range(4): for x in range(4): bind_array.append(str(bind_mat[y][x])) joint_node_dict[scene_node.xmlnode.attrib["sid"]] = { "id": node.id, "name": node.name, "bind_mat": ",".join(bind_array) } # Add the transform of the node if hasattr(scene_node, "matrix"): node.transform.set_matrix(scene_node.matrix) # Propagate to children if hasattr(scene_node, "children") or hasattr(scene_node, "nodes"): children = scene_node.nodes if isinstance( scene_node, Scene) else scene_node.children for child in children: child_node = ColladaImporter.process_node( child, parent_mat if not hasattr(scene_node, "matrix") else parent_mat.dot(scene_node.matrix), joint_node_dict, node_list, folder_name) if child_node is not None: # If child is ExtraNode or LightNode, skip the child if isinstance(child, collada.scene.ExtraNode) or isinstance( child, collada.scene.LightNode): continue # If child holds a mesh, add a MeshGraphic to node and skip the child if hasattr(child, "controller"): mesh_renderer = EComponent.from_script( "components.mesh_graphic") mesh_renderer.property_vals[ "mesh"] = folder_name + "/" + child.controller.geometry.name mesh_renderer.property_vals[ "armature_node"] = joint_node_dict[ child.controller.sourcebyid[ child.controller.joint_source][0]]["id"] node.data.append(mesh_renderer) # Set bind shape matrix node.transform.set_matrix( child.controller.bind_shape_matrix) continue # If child is a joint and this node isn't, add an armature to the child parent_attrib = scene_node.xmlnode.attrib child_attrib = child.xmlnode.attrib if ("type" not in parent_attrib or parent_attrib["type"].lower() != "joint") and ( "type" in child_attrib and child_attrib["type"].lower() == "joint"): armature = EComponent.from_script( "components.armature") armature.property_vals["nodes"] = [ joint_node_dict[joint_name]["name"] for joint_name in node_list ] armature.property_vals["bind_matrices"] = [ joint_node_dict[joint_name]["bind_mat"] for joint_name in node_list ] child_node.data.append(armature) node.add_child(child_node) return node