Skip to content

Commit

Permalink
Merge pull request #54 from pish-pish/master
Browse files Browse the repository at this point in the history
Only Add Shape Matrix Attributes If Mesh Rigged To > 1 Joint
  • Loading branch information
RenolY2 authored Apr 29, 2024
2 parents 19f7e46 + 7dcbe14 commit 6c8cee1
Showing 1 changed file with 51 additions and 48 deletions.
99 changes: 51 additions & 48 deletions SuperBMDLib/source/Geometry/Shape.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using SuperBMD.source.Geometry.Enums;
using Newtonsoft.Json;
using SuperBMDLib.Materials;
using SuperBMDLib.Geometry.Enums;

namespace SuperBMDLib.Geometry
{
Expand Down Expand Up @@ -64,10 +65,10 @@ public void SetDescriptorAttributes(Mesh mesh, int jointCount, bool include_norm
{
int indexOffset = 0;

if (jointCount > 1) {
if (jointCount > 1 && mesh.BoneCount > 1) {
Descriptor.SetAttribute(Enums.GXVertexAttribute.PositionMatrixIdx, Enums.VertexInputType.Direct, indexOffset++);

if (addEnvAttrib)
if (addEnvAttrib) { }
SetEnvTexMtxIdxAttribute(ref indexOffset, matName, mat_presets);
}

Expand Down Expand Up @@ -518,35 +519,36 @@ public void ProcessVerticesWithWeights(Mesh mesh, VertexData vertData, Dictionar

vert.SetWeight(curWeight);

foreach (Enums.GXVertexAttribute attrib in activeAttribs) {
switch (attrib) {
case Enums.GXVertexAttribute.PositionMatrixIdx:
int newMatrixIndex = -1;
int newMatrixIndex = -1;

if (curWeight.WeightCount == 1) {
newMatrixIndex = partialWeight.MeshWeights.IndexOf(curWeight);
}
else {
if (!envelopes.Weights.Contains(curWeight))
envelopes.Weights.Add(curWeight);
if (curWeight.WeightCount == 1)
{
newMatrixIndex = partialWeight.MeshWeights.IndexOf(curWeight);
}
else
{
if (!envelopes.Weights.Contains(curWeight))
envelopes.Weights.Add(curWeight);

int envIndex = envelopes.Weights.IndexOf(curWeight);
int drwIndex = partialWeight.MeshWeights.IndexOf(curWeight);
int envIndex = envelopes.Weights.IndexOf(curWeight);
int drwIndex = partialWeight.MeshWeights.IndexOf(curWeight);

if (drwIndex == -1)
{
throw new System.Exception($"Model has unweighted vertices in mesh \"{mesh.Name}\". Please weight all vertices to at least one bone.");
}
if (drwIndex == -1)
{
throw new System.Exception($"Model has unweighted vertices in mesh \"{mesh.Name}\". Please weight all vertices to at least one bone.");
}

newMatrixIndex = drwIndex;
partialWeight.Indices[drwIndex] = envIndex;
}
newMatrixIndex = drwIndex;
partialWeight.Indices[drwIndex] = envIndex;
}

if (!pack.MatrixIndices.Contains(newMatrixIndex))
pack.MatrixIndices.Add(newMatrixIndex);
if (!pack.MatrixIndices.Contains(newMatrixIndex))
pack.MatrixIndices.Add(newMatrixIndex);

vert.SetAttributeIndex(Enums.GXVertexAttribute.PositionMatrixIdx, (uint)pack.MatrixIndices.IndexOf(newMatrixIndex));
break;
vert.SetAttributeIndex(Enums.GXVertexAttribute.PositionMatrixIdx, (uint)pack.MatrixIndices.IndexOf(newMatrixIndex));

foreach (Enums.GXVertexAttribute attrib in activeAttribs) {
switch (attrib) {
case Enums.GXVertexAttribute.Tex0Mtx:
case Enums.GXVertexAttribute.Tex1Mtx:
case Enums.GXVertexAttribute.Tex2Mtx:
Expand Down Expand Up @@ -752,35 +754,36 @@ public void ProcessVerticesWithWeights(Mesh mesh, VertexData vertData, Dictionar

vert.SetWeight(curWeight);

foreach (Enums.GXVertexAttribute attrib in activeAttribs) {
switch (attrib) {
case Enums.GXVertexAttribute.PositionMatrixIdx:
int newMatrixIndex = -1;
int newMatrixIndex = -1;

if (curWeight.WeightCount == 1) {
newMatrixIndex = partialWeight.MeshWeights.IndexOf(curWeight);
}
else {
if (!envelopes.Weights.Contains(curWeight))
envelopes.Weights.Add(curWeight);
if (curWeight.WeightCount == 1)
{
newMatrixIndex = partialWeight.MeshWeights.IndexOf(curWeight);
}
else
{
if (!envelopes.Weights.Contains(curWeight))
envelopes.Weights.Add(curWeight);

int envIndex = envelopes.Weights.IndexOf(curWeight);
int drwIndex = partialWeight.MeshWeights.IndexOf(curWeight);
int envIndex = envelopes.Weights.IndexOf(curWeight);
int drwIndex = partialWeight.MeshWeights.IndexOf(curWeight);

if (drwIndex == -1)
{
throw new System.Exception($"Model has unweighted vertices in mesh \"{mesh.Name}\". Please weight all vertices to at least one bone.");
}
if (drwIndex == -1)
{
throw new System.Exception($"Model has unweighted vertices in mesh \"{mesh.Name}\". Please weight all vertices to at least one bone.");
}

newMatrixIndex = drwIndex;
partialWeight.Indices[drwIndex] = envIndex;
}
newMatrixIndex = drwIndex;
partialWeight.Indices[drwIndex] = envIndex;
}

if (!pack.MatrixIndices.Contains(newMatrixIndex))
pack.MatrixIndices.Add(newMatrixIndex);
if (!pack.MatrixIndices.Contains(newMatrixIndex))
pack.MatrixIndices.Add(newMatrixIndex);

vert.SetAttributeIndex(Enums.GXVertexAttribute.PositionMatrixIdx, (uint)pack.MatrixIndices.IndexOf(newMatrixIndex));
break;
vert.SetAttributeIndex(Enums.GXVertexAttribute.PositionMatrixIdx, (uint)pack.MatrixIndices.IndexOf(newMatrixIndex));

foreach (Enums.GXVertexAttribute attrib in activeAttribs) {
switch (attrib) {
case Enums.GXVertexAttribute.Tex0Mtx:
case Enums.GXVertexAttribute.Tex1Mtx:
case Enums.GXVertexAttribute.Tex2Mtx:
Expand Down

0 comments on commit 6c8cee1

Please sign in to comment.