示例#1
0
    def apply_skin(self, keep_skin=False):
        data = self.data
        skin = self.skin
        if not keep_skin:
            self.skin = None

        deformed_verts = zeros(*data.vertices.shape)
        deformed_norms = zeros(*data.normals.shape)

        root_to_skin = skin.data.matrix
        for bone, bone_data in zip(skin.bones, skin.data.bone_data):
            skin_to_bone = bone_data.matrix

            bone_matrix = bone.matrix_relative_to(skin.root)
            bind_matrix = root_to_skin @ bone_matrix @ skin_to_bone

            location, rotation, scale = decompose_uniform(bind_matrix)

            # indices and weights
            i = bone_data.vertex_weights["f0"]
            w = bone_data.vertex_weights["f1"][:, None]

            if len(deformed_verts):
                deformed_verts[i] += w * (data.vertices[i] @ rotation.T * scale + location.T)
            if len(deformed_norms):
                deformed_norms[i] += w * (data.normals[i] @ rotation.T)

        data.vertices = deformed_verts
        data.normals = deformed_norms  # TODO: normalize?
示例#2
0
 def matrix(self, value: ndarray):
     self.translation, self.rotation, self.scale = decompose_uniform(value)