boneWeight がすべて 0 のときに Export しない

This commit is contained in:
ousttrue 2022-06-17 16:50:33 +09:00
parent 03c2c83880
commit 0e826fbb14
2 changed files with 21 additions and 9 deletions

View File

@ -34,6 +34,10 @@ namespace UniGLTF
var normals = mesh.normals;
var uv = mesh.uv;
var boneWeights = mesh.boneWeights;
if (boneWeights.All(x => x.weight0 == 0 && x.weight1 == 0 && x.weight2 == 0 && x.weight3 == 0))
{
boneWeights = null;
}
var colors = mesh.colors;
Func<int, int> getJointIndex = null;

View File

@ -57,15 +57,23 @@ namespace UniGLTF
colorAccessorIndex = data.ExtendBufferAndGetAccessorIndex(mesh.colors, glBufferTarget.ARRAY_BUFFER);
}
var boneweights = mesh.boneWeights;
var weightAccessorIndex = data.ExtendBufferAndGetAccessorIndex(boneweights.Select(y => new Vector4(y.weight0, y.weight1, y.weight2, y.weight3)).ToArray(), glBufferTarget.ARRAY_BUFFER);
var jointsAccessorIndex = data.ExtendBufferAndGetAccessorIndex(boneweights.Select(y =>
new UShort4(
(ushort)unityMesh.GetJointIndex(y.boneIndex0),
(ushort)unityMesh.GetJointIndex(y.boneIndex1),
(ushort)unityMesh.GetJointIndex(y.boneIndex2),
(ushort)unityMesh.GetJointIndex(y.boneIndex3))
).ToArray(), glBufferTarget.ARRAY_BUFFER);
var boneWeights = mesh.boneWeights;
var weightAccessorIndex = -1;
var jointsAccessorIndex = -1;
if (boneWeights.All(x => x.weight0 == 0 && x.weight1 == 0 && x.weight2 == 0 && x.weight3 == 0))
{
}
else
{
weightAccessorIndex = data.ExtendBufferAndGetAccessorIndex(boneWeights.Select(y => new Vector4(y.weight0, y.weight1, y.weight2, y.weight3)).ToArray(), glBufferTarget.ARRAY_BUFFER);
jointsAccessorIndex = data.ExtendBufferAndGetAccessorIndex(boneWeights.Select(y =>
new UShort4(
(ushort)unityMesh.GetJointIndex(y.boneIndex0),
(ushort)unityMesh.GetJointIndex(y.boneIndex1),
(ushort)unityMesh.GetJointIndex(y.boneIndex2),
(ushort)unityMesh.GetJointIndex(y.boneIndex3))
).ToArray(), glBufferTarget.ARRAY_BUFFER);
}
var attributes = new glTFAttributes
{