Skip to content

Commit b66b270

Browse files
Fixed normals so that those with only one bone influencing them are
transformed into bone space.
1 parent 7485e1c commit b66b270

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

SuperBMDLib/source/BMD/SHP1.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ private SHP1(EndianBinaryReader reader, int offset)
130130
reader.BaseStream.Seek(offset + shp1Size, System.IO.SeekOrigin.Begin);
131131
}
132132

133-
private SHP1(Assimp.Scene scene, VertexData vertData, Dictionary<string, int> boneNames, EVP1 envelopes, DRW1 partialWeight)
133+
private SHP1(Assimp.Scene scene, VertexData vertData, Dictionary<string, int> boneNames, EVP1 envelopes, DRW1 partialWeight, List<Rigging.Bone> skeleton)
134134
{
135135
Shapes = new List<Shape>();
136136
RemapTable = new List<int>();
@@ -141,7 +141,7 @@ private SHP1(Assimp.Scene scene, VertexData vertData, Dictionary<string, int> bo
141141
meshShape.SetDescriptorAttributes(mesh, boneNames.Count);
142142

143143
if (boneNames.Count > 1)
144-
meshShape.ProcessVerticesWithWeights(mesh, vertData, boneNames, envelopes, partialWeight);
144+
meshShape.ProcessVerticesWithWeights(mesh, vertData, boneNames, envelopes, partialWeight, skeleton);
145145
else
146146
{
147147
meshShape.ProcessVerticesWithoutWeights(mesh, vertData);
@@ -158,9 +158,9 @@ public static SHP1 Create(EndianBinaryReader reader, int offset)
158158
return new SHP1(reader, offset);
159159
}
160160

161-
public static SHP1 Create(Scene scene, Dictionary<string, int> boneNames, VertexData vertData, EVP1 evp1, DRW1 drw1)
161+
public static SHP1 Create(Scene scene, Dictionary<string, int> boneNames, VertexData vertData, EVP1 evp1, DRW1 drw1, JNT1 jnt1)
162162
{
163-
SHP1 shp1 = new SHP1(scene, vertData, boneNames, evp1, drw1);
163+
SHP1 shp1 = new SHP1(scene, vertData, boneNames, evp1, drw1, jnt1.FlatSkeleton);
164164

165165
return shp1;
166166
}

SuperBMDLib/source/Geometry/Shape.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ public void ProcessVerticesWithoutWeights(Mesh mesh, VertexData vertData)
177177
Bounds.GetBoundsValues(AttributeData.Positions);
178178
}
179179

180-
public void ProcessVerticesWithWeights(Mesh mesh, VertexData vertData, Dictionary<string, int> boneNames, EVP1 envelopes, DRW1 partialWeight)
180+
public void ProcessVerticesWithWeights(Mesh mesh, VertexData vertData, Dictionary<string, int> boneNames, EVP1 envelopes, DRW1 partialWeight, List<SuperBMDLib.Rigging.Bone> skeleton)
181181
{
182182
Packet pack = new Packet();
183183

@@ -322,11 +322,15 @@ public void ProcessVerticesWithWeights(Mesh mesh, VertexData vertData, Dictionar
322322
}
323323
else
324324
{
325-
for(int v = 0; v < curWeight.WeightCount; v++)
325+
/*Matrix4 mat = Matrix4.Identity;
326+
327+
for (int v = 0; v < curWeight.WeightCount; v++)
326328
{
327-
Matrix4 ibm = envelopes.InverseBindMatrices[curWeight.BoneIndices[v]];
328-
vertNrm = Vector3.TransformNormal(vertNrm, ibm * curWeight.Weights[v]);
329+
int boneIndex = curWeight.BoneIndices[v];
330+
mat += Matrix4.Mult(envelopes.InverseBindMatrices[boneIndex], curWeight.Weights[v]);
329331
}
332+
333+
vertNrm = Vector3.TransformNormal(vertNrm, mat);*/
330334
}
331335

332336
AttributeData.Normals.Add(vertNrm);

SuperBMDLib/source/Model.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public Model(Scene scene, Arguments args)
107107

108108
PartialWeightData = new DRW1(scene, Joints.BoneNameIndices);
109109

110-
Shapes = SHP1.Create(scene, Joints.BoneNameIndices, VertexData.Attributes, SkinningEnvelopes, PartialWeightData);
110+
Shapes = SHP1.Create(scene, Joints.BoneNameIndices, VertexData.Attributes, SkinningEnvelopes, PartialWeightData, Joints);
111111

112112
Materials = new MAT3(scene, Textures, Shapes, args);
113113
Scenegraph = new INF1(scene, Joints);

0 commit comments

Comments
 (0)