예제 #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)
예제 #2
0
    def _write_triangle_list(self, object_, bmesh_, mesh_node, geometry_name):
        tessfaces = utils.get_tessfaces(bmesh_)
        current_material_index = 0
        for material, materialname in self._m_exporter.get_materials_for_object(
                object_).items():
            triangles = ''
            triangle_count = 0
            normal_uv_index = 0
            for face in bmesh_.faces:
                norm_uv_indices = {}

                for index in range(0, len(face.verts)):
                    norm_uv_indices[str(
                        face.verts[index].index)] = normal_uv_index + index

                if face.material_index == current_material_index:
                    for tessface in tessfaces[face.index]:
                        triangle_count += 1
                        for vert in tessface:
                            normal_uv = norm_uv_indices[str(vert)]
                            dae_vertex = self._write_vertex_data(
                                vert, normal_uv, normal_uv,
                                object_.data.vertex_colors)
                            triangles = join(triangles, dae_vertex)

                normal_uv_index += len(face.verts)

            current_material_index += 1

            if triangle_count == 0:
                continue

            triangle_list = self._doc.createElement('triangles')
            triangle_list.setAttribute('material', materialname)
            triangle_list.setAttribute('count', str(triangle_count))

            inputs = []
            inputs.append(utils.write_input(geometry_name, 0, 'vtx', 'VERTEX'))
            inputs.append(
                utils.write_input(geometry_name, 1, 'normal', 'NORMAL'))
            inputs.append(
                utils.write_input(geometry_name, 2, 'uvs', 'TEXCOORD'))
            if object_.data.vertex_colors:
                inputs.append(
                    utils.write_input(geometry_name, 3, 'vcol', 'COLOR'))

            for input in inputs:
                triangle_list.appendChild(input)

            p = self._doc.createElement('p')
            p_text = self._doc.createTextNode(triangles)
            p.appendChild(p_text)

            triangle_list.appendChild(p)
            mesh_node.appendChild(triangle_list)
예제 #3
0
    def _process_bone_weights(self, object_, armature, skin_node):

        bones = utils.get_bones(armature)
        group_weights = []
        vw = ""
        vertex_groups_lengths = ""
        vertex_count = 0
        bone_list = {}

        for bone_id, bone in enumerate(bones):
            bone_list[bone.name] = bone_id

        for vertex in object_.data.vertices:
            vertex_group_count = 0
            for group in vertex.groups:
                group_name = object_.vertex_groups[group.group].name
                if (group.weight == 0 or
                        group_name not in bone_list):
                    continue
                if vertex_group_count == 8:
                    bcPrint("Too many bone references in {}:{} vertex group"
                            .format(object_.name, group_name))
                    continue
                group_weights.append(group.weight)
                vw = "{}{} {} ".format(vw, bone_list[group_name], vertex_count)
                vertex_count += 1
                vertex_group_count += 1

            vertex_groups_lengths = "{}{} ".format(vertex_groups_lengths,
                                                   vertex_group_count)

        id_ = "{!s}_{!s}-weights".format(armature.name, object_.name)
        source = utils.write_source(id_, "float", group_weights, [])
        skin_node.appendChild(source)

        vertex_weights = self._doc.createElement("vertex_weights")
        vertex_weights.setAttribute("count", str(len(object_.data.vertices)))

        id_ = "{!s}_{!s}".format(armature.name, object_.name)
        input = utils.write_input(id_, 0, "joints", "JOINT")
        vertex_weights.appendChild(input)
        input = utils.write_input(id_, 1, "weights", "WEIGHT")
        vertex_weights.appendChild(input)

        vcount = self._doc.createElement("vcount")
        vcount_text = self._doc.createTextNode(vertex_groups_lengths)
        vcount.appendChild(vcount_text)
        vertex_weights.appendChild(vcount)

        v = self._doc.createElement("v")
        v_text = self._doc.createTextNode(vw)
        v.appendChild(v_text)
        vertex_weights.appendChild(v)

        skin_node.appendChild(vertex_weights)
예제 #4
0
 def _write_vertices(self, mesh_node, geometry_name):
     vertices = self._doc.createElement("vertices")
     vertices.setAttribute("id", "{}-vtx".format(geometry_name))
     input = utils.write_input(geometry_name, None, "pos", "POSITION")
     vertices.appendChild(input)
     mesh_node.appendChild(vertices)