Skip to content

Commit 12ef296

Browse files
committed
Fixed most (if not all) armatures and now importing normals
1 parent c4435e9 commit 12ef296

File tree

2 files changed

+37
-25
lines changed

2 files changed

+37
-25
lines changed

README.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
![Replicant2Blender](https://i.imgur.com/jbwzCYB.png)
22

33
## CURRENTLY IN ALPHA:
4-
* Armature/Bones imports aren't perfect (only seems to work on certain models at the moment).
54
* Not all DXGI texture formats have been identified yet, so if you find any broken textures or textures failing to extract, please let me know!
65
* Please let me know of any other issues too (contact me here with an issue or on the [NieR:Modding Discord Server](https://discord.gg/7F76ZVv)).
76

@@ -13,7 +12,7 @@
1312
* Automatic texture extraction, conversion & material node setup (make sure you have Noesis path set in Add-on Preferences).
1413
* Multiple UV maps.
1514
* Vertex groups.
16-
* Basic armature (only for certain models).
15+
* Armatures.
1716
* Materials.
1817
* Extracting textures.
1918

importers/meshAsset_import.py

+36-23
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
from mathutils import Vector, Matrix
1+
from mathutils import Vector, Matrix, Quaternion
22
import bpy, bmesh, numpy, math
3-
3+
from operator import add
44

55
def get_meshAssetFiles(pack):
66
meshAssetFiles = []
@@ -24,18 +24,21 @@ def construct_meshes(pack):
2424
meshCollection.objects.link(amtObj)
2525
bpy.context.view_layer.objects.active = amtObj
2626
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+
3942
safeBones = []
4043
for bone in meshAsset.content.meshHead.bonesData:
4144
safeBones.append(bone.name)
@@ -46,8 +49,19 @@ def construct_meshes(pack):
4649
parentName = meshAsset.content.meshHead.bones[bone.parentBoneIndex].name
4750
if parentName in safeBones:
4851
edit_bone.parent = amt.edit_bones[parentName]
49-
edit_bone.head = edit_bone.parent.tail
5052
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+
5165
bpy.ops.object.mode_set(mode='OBJECT')
5266
amtObj.rotation_euler = (math.radians(90),0,0)
5367

@@ -57,30 +71,29 @@ def construct_meshes(pack):
5771
faces = pack.meshData[i].objectGroupIndices[k].indices
5872
weights = pack.meshData[i].objectGroupVertices[k].vertexWeights
5973
boneIndices = pack.meshData[i].objectGroupVertices[k].vertexBoneIndices
60-
61-
"""
74+
6275
normals = []
6376
for m in range(len(vertices)):
6477
nx = pack.meshData[i].objectGroupVertices[k].vertexNormals[m][0] / 127
6578
ny = pack.meshData[i].objectGroupVertices[k].vertexNormals[m][1] / 127
6679
nz = pack.meshData[i].objectGroupVertices[k].vertexNormals[m][2] / 127
67-
normals.append([nz, ny, nx])
68-
"""
80+
normals.append([nx, ny, nz])
81+
6982

7083
objName = meshAsset.name + str(k)
7184

7285
bObjMesh = bpy.data.meshes.new(objName)
7386
bObj = bpy.data.objects.new(objName, bObjMesh)
7487

75-
#bObj.data.use_auto_smooth = True
88+
bObj.data.use_auto_smooth = True
7689

7790
meshCollection.objects.link(bObj)
7891
bObjMesh.from_pydata(vertices, [], faces)
79-
#bObjMesh.normals_split_custom_set_from_vertices(normals)
92+
bObjMesh.normals_split_custom_set_from_vertices(normals)
8093
bObjMesh.update(calc_edges=True)
8194

82-
for poly in bObj.data.polygons:
83-
poly.use_smooth = True
95+
#for poly in bObj.data.polygons:
96+
# poly.use_smooth = True
8497

8598
# Create/Add Materials
8699
for m, material in enumerate(meshAsset.content.meshHead.materials):

0 commit comments

Comments
 (0)