1
- from mathutils import Vector , Matrix
1
+ from mathutils import Vector , Matrix , Quaternion
2
2
import bpy , bmesh , numpy , math
3
-
3
+ from operator import add
4
4
5
5
def get_meshAssetFiles (pack ):
6
6
meshAssetFiles = []
@@ -24,18 +24,21 @@ def construct_meshes(pack):
24
24
meshCollection .objects .link (amtObj )
25
25
bpy .context .view_layer .objects .active = amtObj
26
26
bpy .ops .object .mode_set (mode = "EDIT" )
27
- for k , boneData in enumerate (meshAsset .content .meshHead .bonesData ):
28
- tailVector = numpy .matmul (boneData .unknownMatrix0 , [boneData .length , 0 , 0 , 1 ])
29
- newBone = amt .edit_bones .new (boneData .name )
30
- newBone .head = [tailVector [0 ], tailVector [1 ]- 0.05 , tailVector [2 ]]
31
- newBone .tail = [tailVector [0 ], tailVector [1 ], tailVector [2 ]]
32
- if k == 0 :
33
- newBone .head = [0 , tailVector [1 ]- 0.05 , tailVector [2 ]]
34
- newBone .tail = [0 , tailVector [1 ], tailVector [2 ]]
35
-
36
- bpy .ops .object .mode_set (mode = 'OBJECT' )
37
-
38
- bpy .ops .object .mode_set (mode = "EDIT" )
27
+ for k , bone in enumerate (meshAsset .content .meshHead .bonesData ):
28
+ transform = Matrix (bone .unknownMatrix0 )
29
+
30
+ if (bone .unknownParentIndex == - 1 ):
31
+ head = transform @ Vector ((0 , 0 , 0 , 1 ))
32
+ tail = transform @ Vector ((bone .length , 0 , 0 , 1 ))
33
+ else :
34
+ head = Vector ((0 , 0 , 0 ))
35
+ tail = Vector ((0 , 0.05 , 0 ))
36
+ newBone = amt .edit_bones .new (bone .name )
37
+ newBone .head = [head .x , head .y , head .z ]
38
+ newBone .tail = [tail .x , tail .y , tail .z ]
39
+ #newBone.roll = 90
40
+ #newBone.parent = amt.edit_bones[meshAsset.content.meshHead.bones[bone.parentBoneIndex].name] if bone.parentBoneIndex != -1 else None
41
+
39
42
safeBones = []
40
43
for bone in meshAsset .content .meshHead .bonesData :
41
44
safeBones .append (bone .name )
@@ -46,8 +49,19 @@ def construct_meshes(pack):
46
49
parentName = meshAsset .content .meshHead .bones [bone .parentBoneIndex ].name
47
50
if parentName in safeBones :
48
51
edit_bone .parent = amt .edit_bones [parentName ]
49
- edit_bone .head = edit_bone .parent .tail
50
52
break
53
+
54
+ bpy .ops .object .mode_set (mode = 'POSE' )
55
+ for pose_bone in amtObj .pose .bones :
56
+ for bone in meshAsset .content .meshHead .bonesData :
57
+ if bone .name == pose_bone .name :
58
+ if bone .unknownParentIndex != - 1 :
59
+ transformMat = Matrix (bone .unknownMatrix0 )
60
+ pose_bone .matrix_basis = transformMat @ pose_bone .matrix_basis
61
+ break
62
+ bpy .context .view_layer .update ()
63
+ bpy .ops .pose .armature_apply ()
64
+
51
65
bpy .ops .object .mode_set (mode = 'OBJECT' )
52
66
amtObj .rotation_euler = (math .radians (90 ),0 ,0 )
53
67
@@ -57,30 +71,29 @@ def construct_meshes(pack):
57
71
faces = pack .meshData [i ].objectGroupIndices [k ].indices
58
72
weights = pack .meshData [i ].objectGroupVertices [k ].vertexWeights
59
73
boneIndices = pack .meshData [i ].objectGroupVertices [k ].vertexBoneIndices
60
-
61
- """
74
+
62
75
normals = []
63
76
for m in range (len (vertices )):
64
77
nx = pack .meshData [i ].objectGroupVertices [k ].vertexNormals [m ][0 ] / 127
65
78
ny = pack .meshData [i ].objectGroupVertices [k ].vertexNormals [m ][1 ] / 127
66
79
nz = pack .meshData [i ].objectGroupVertices [k ].vertexNormals [m ][2 ] / 127
67
- normals.append([nz , ny, nx ])
68
- """
80
+ normals .append ([nx , ny , nz ])
81
+
69
82
70
83
objName = meshAsset .name + str (k )
71
84
72
85
bObjMesh = bpy .data .meshes .new (objName )
73
86
bObj = bpy .data .objects .new (objName , bObjMesh )
74
87
75
- # bObj.data.use_auto_smooth = True
88
+ bObj .data .use_auto_smooth = True
76
89
77
90
meshCollection .objects .link (bObj )
78
91
bObjMesh .from_pydata (vertices , [], faces )
79
- # bObjMesh.normals_split_custom_set_from_vertices(normals)
92
+ bObjMesh .normals_split_custom_set_from_vertices (normals )
80
93
bObjMesh .update (calc_edges = True )
81
94
82
- for poly in bObj .data .polygons :
83
- poly .use_smooth = True
95
+ # for poly in bObj.data.polygons:
96
+ # poly.use_smooth = True
84
97
85
98
# Create/Add Materials
86
99
for m , material in enumerate (meshAsset .content .meshHead .materials ):
0 commit comments