Ejemplo n.º 1
0
    def _process_bones(self, parent_node, group, object_, armature):
        id_ = "{!s}_{!s}".format(armature.name, object_.name)

        controller_node = self._doc.createElement("controller")
        parent_node.appendChild(controller_node)
        controller_node.setAttribute("id", id_)

        skin_node = self._doc.createElement("skin")
        skin_node.setAttribute(
            "source", "#{!s}".format(utils.get_geometry_name(group, object_)))
        controller_node.appendChild(skin_node)

        bind_shape_matrix = self._doc.createElement("bind_shape_matrix")
        utils.write_matrix(Matrix(), bind_shape_matrix)
        skin_node.appendChild(bind_shape_matrix)

        self._process_bone_joints(object_, armature, skin_node, group)
        self._process_bone_matrices(object_, armature, skin_node)
        self._process_bone_weights(object_, armature, skin_node)

        joints = self._doc.createElement("joints")
        input = utils.write_input(id_, None, "joints", "JOINT")
        joints.appendChild(input)
        input = utils.write_input(id_, None, "matrices", "INV_BIND_MATRIX")
        joints.appendChild(input)
        skin_node.appendChild(joints)
Ejemplo n.º 2
0
    def _create_instance(self, group, object_):
        armature = utils.get_armature_for_object(object_)
        node_type = utils.get_node_type(group)
        instance = None
        if armature and node_type in ('chr', 'skin'):
            instance = self._doc.createElement("instance_controller")
            # This binds the mesh object to the armature in control of it
            instance.setAttribute(
                "url", "#{!s}_{!s}".format(armature.name, object_.name))
        elif object_.name[:6] != "_joint" and object_.type == "MESH":
            instance = self._doc.createElement("instance_geometry")
            instance.setAttribute(
                "url", "#{!s}".format(utils.get_geometry_name(group, object_)))

        if instance is not None:
            bind_material = self._create_bind_material(object_)
            instance.appendChild(bind_material)
            return instance
Ejemplo n.º 3
0
    def _write_bone_list(self, bones, object_, parent_node, group):
        scene = bpy.context.scene
        bone_names = []

        for bone in bones:
            props_name = self._create_properties_name(bone, group)
            props_ik = self._create_ik_properties(bone, object_)
            bone_name = join(bone.name, props_name, props_ik)
            bone_names.append(bone_name)

            node = self._doc.createElement("node")
            node.setAttribute("id", bone_name)
            node.setAttribute("name", bone_name)
            node.setIdAttribute("id")

            fakebone = utils.get_fakebone(bone.name)
            if fakebone is not None:
                self._write_transforms(fakebone, node)

                bone_geometry = utils.get_bone_geometry(bone)
                if bone_geometry is not None:
                    geo_name = utils.get_geometry_name(group, bone_geometry)
                    instance = self._create_bone_instance(
                        bone_geometry, geo_name)
                    node.appendChild(instance)

                    extra = self._create_physic_proxy_for_bone(
                        object_.parent, bone)
                    if extra is not None:
                        node.appendChild(extra)

            elif utils.is_physic_bone(bone):
                bone_geometry = utils.get_bone_geometry(bone)
                if fakebone is not None:
                    self._write_transforms(fakebone, node)

            parent_node.appendChild(node)

            if bone.children:
                self._write_bone_list(bone.children, object_, node, group)
Ejemplo n.º 4
0
    def _export_library_geometries(self, parent_element):
        libgeo = self._doc.createElement("library_geometries")
        parent_element.appendChild(libgeo)
        for group in utils.get_mesh_export_nodes(
                self._config.export_selected_nodes):
            for object_ in group.objects:
                if object_.type != 'MESH':
                    continue

                bmesh_, layer_state, scene_layer = utils.get_bmesh(object_)
                geometry_node = self._doc.createElement("geometry")
                geometry_name = utils.get_geometry_name(group, object_)
                geometry_node.setAttribute("id", geometry_name)
                mesh_node = self._doc.createElement("mesh")

                print()
                bcPrint('"{}" object is being processed...'.format(
                    object_.name))

                start_time = clock()
                self._write_positions(bmesh_, mesh_node, geometry_name)
                bcPrint('Positions have been writed {:.4f} seconds.'.format(
                    clock() - start_time))

                start_time = clock()
                self._write_normals(object_, bmesh_, mesh_node, geometry_name)
                bcPrint('Normals have been writed {:.4f} seconds.'.format(
                    clock() - start_time))

                start_time = clock()
                self._write_uvs(object_, bmesh_, mesh_node, geometry_name)
                bcPrint(
                    'UVs have been writed {:.4f} seconds.'.format(clock() -
                                                                  start_time))

                start_time = clock()
                self._write_vertex_colors(object_, bmesh_, mesh_node,
                                          geometry_name)
                bcPrint(
                    'Vertex colors have been writed {:.4f} seconds.'.format(
                        clock() - start_time))

                start_time = clock()
                self._write_vertices(mesh_node, geometry_name)
                bcPrint('Vertices have been writed {:.4f} seconds.'.format(
                    clock() - start_time))

                start_time = clock()
                self._write_triangle_list(object_, bmesh_, mesh_node,
                                          geometry_name)
                bcPrint(
                    'Triangle list have been writed {:.4f} seconds.'.format(
                        clock() - start_time))

                extra = self._create_double_sided_extra("MAYA")
                mesh_node.appendChild(extra)
                geometry_node.appendChild(mesh_node)
                libgeo.appendChild(geometry_node)

                utils.clear_bmesh(object_, layer_state, scene_layer)
                bcPrint('"{}" object has been processed for "{}" node.'.format(
                    object_.name, group.name))