|
@@ -192,6 +192,7 @@ namespace Max2Babylon
|
|
var unskinnedMesh = gameMesh;
|
|
var unskinnedMesh = gameMesh;
|
|
IGMatrix skinInitPoseMatrix = Loader.Global.GMatrix.Create(Loader.Global.Matrix3.Create(true));
|
|
IGMatrix skinInitPoseMatrix = Loader.Global.GMatrix.Create(Loader.Global.Matrix3.Create(true));
|
|
List<int> boneIds = null;
|
|
List<int> boneIds = null;
|
|
|
|
+ int nbBones = 0;
|
|
if (isSkinned)
|
|
if (isSkinned)
|
|
{
|
|
{
|
|
bonesCount = skin.TotalSkinBoneCount;
|
|
bonesCount = skin.TotalSkinBoneCount;
|
|
@@ -250,6 +251,14 @@ namespace Max2Babylon
|
|
RaiseWarning($"Mesh {babylonMesh.name} has tmore than 65536 vertices which means that it will require specific WebGL extension to be rendered. This may impact portability of your scene on low end devices.", 2);
|
|
RaiseWarning($"Mesh {babylonMesh.name} has tmore than 65536 vertices which means that it will require specific WebGL extension to be rendered. This may impact portability of your scene on low end devices.", 2);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ if (skin != null)
|
|
|
|
+ {
|
|
|
|
+ for (var vertexIndex = 0; vertexIndex < unskinnedMesh.NumberOfVerts; vertexIndex++)
|
|
|
|
+ {
|
|
|
|
+ nbBones = Math.Max(nbBones, skin.GetNumberOfBones(vertexIndex));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
// Physics
|
|
// Physics
|
|
var impostorText = meshNode.MaxNode.GetStringProperty("babylonjs_impostor", "None");
|
|
var impostorText = meshNode.MaxNode.GetStringProperty("babylonjs_impostor", "None");
|
|
|
|
|
|
@@ -346,7 +355,7 @@ namespace Max2Babylon
|
|
for (int j = 0; j < unskinnedMesh.NumberOfFaces; ++j)
|
|
for (int j = 0; j < unskinnedMesh.NumberOfFaces; ++j)
|
|
{
|
|
{
|
|
var face = unskinnedMesh.GetFace(j);
|
|
var face = unskinnedMesh.GetFace(j);
|
|
- ExtractFace(skin, unskinnedMesh, vertices, indices, hasUV, hasUV2, hasColor, hasAlpha, verticesAlreadyExported, ref indexCount, ref minVertexIndex, ref maxVertexIndex, face, boneIds);
|
|
|
|
|
|
+ ExtractFace(skin, unskinnedMesh, vertices, indices, hasUV, hasUV2, hasColor, hasAlpha, verticesAlreadyExported, ref indexCount, ref minVertexIndex, ref maxVertexIndex, face, boneIds, nbBones);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
else
|
|
@@ -364,7 +373,7 @@ namespace Max2Babylon
|
|
#if !MAX2017
|
|
#if !MAX2017
|
|
Marshal.FreeHGlobal(faceIndexer);
|
|
Marshal.FreeHGlobal(faceIndexer);
|
|
#endif
|
|
#endif
|
|
- ExtractFace(skin, unskinnedMesh, vertices, indices, hasUV, hasUV2, hasColor, hasAlpha, verticesAlreadyExported, ref indexCount, ref minVertexIndex, ref maxVertexIndex, face, boneIds);
|
|
|
|
|
|
+ ExtractFace(skin, unskinnedMesh, vertices, indices, hasUV, hasUV2, hasColor, hasAlpha, verticesAlreadyExported, ref indexCount, ref minVertexIndex, ref maxVertexIndex, face, boneIds, nbBones);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -410,7 +419,8 @@ namespace Max2Babylon
|
|
babylonMesh.matricesWeights = vertices.SelectMany(v => v.Weights.ToArray()).ToArray();
|
|
babylonMesh.matricesWeights = vertices.SelectMany(v => v.Weights.ToArray()).ToArray();
|
|
babylonMesh.matricesIndices = vertices.Select(v => v.BonesIndices).ToArray();
|
|
babylonMesh.matricesIndices = vertices.Select(v => v.BonesIndices).ToArray();
|
|
|
|
|
|
- if (vertices[0].WeightsExtra != null)
|
|
|
|
|
|
+ babylonMesh.numBoneInfluencers = nbBones;
|
|
|
|
+ if (nbBones > 4)
|
|
{
|
|
{
|
|
babylonMesh.matricesWeightsExtra = vertices.SelectMany(v => v.WeightsExtra.ToArray()).ToArray();
|
|
babylonMesh.matricesWeightsExtra = vertices.SelectMany(v => v.WeightsExtra.ToArray()).ToArray();
|
|
babylonMesh.matricesIndicesExtra = vertices.Select(v => v.BonesIndicesExtra).ToArray();
|
|
babylonMesh.matricesIndicesExtra = vertices.Select(v => v.BonesIndicesExtra).ToArray();
|
|
@@ -513,11 +523,11 @@ namespace Max2Babylon
|
|
babylonScene.MeshesList.Add(babylonMesh);
|
|
babylonScene.MeshesList.Add(babylonMesh);
|
|
}
|
|
}
|
|
|
|
|
|
- private void ExtractFace(IIGameSkin skin, IIGameMesh unskinnedMesh, List<GlobalVertex> vertices, List<int> indices, bool hasUV, bool hasUV2, bool hasColor, bool hasAlpha, List<GlobalVertex>[] verticesAlreadyExported, ref int indexCount, ref int minVertexIndex, ref int maxVertexIndex, IFaceEx face, List<int> boneIds)
|
|
|
|
|
|
+ private void ExtractFace(IIGameSkin skin, IIGameMesh unskinnedMesh, List<GlobalVertex> vertices, List<int> indices, bool hasUV, bool hasUV2, bool hasColor, bool hasAlpha, List<GlobalVertex>[] verticesAlreadyExported, ref int indexCount, ref int minVertexIndex, ref int maxVertexIndex, IFaceEx face, List<int> boneIds, int nbBones)
|
|
{
|
|
{
|
|
- var a = CreateGlobalVertex(unskinnedMesh, face, 0, vertices, hasUV, hasUV2, hasColor, hasAlpha, verticesAlreadyExported, skin, boneIds);
|
|
|
|
- var b = CreateGlobalVertex(unskinnedMesh, face, 2, vertices, hasUV, hasUV2, hasColor, hasAlpha, verticesAlreadyExported, skin, boneIds);
|
|
|
|
- var c = CreateGlobalVertex(unskinnedMesh, face, 1, vertices, hasUV, hasUV2, hasColor, hasAlpha, verticesAlreadyExported, skin, boneIds);
|
|
|
|
|
|
+ var a = CreateGlobalVertex(unskinnedMesh, face, 0, vertices, hasUV, hasUV2, hasColor, hasAlpha, verticesAlreadyExported, skin, boneIds, nbBones);
|
|
|
|
+ var b = CreateGlobalVertex(unskinnedMesh, face, 2, vertices, hasUV, hasUV2, hasColor, hasAlpha, verticesAlreadyExported, skin, boneIds, nbBones);
|
|
|
|
+ var c = CreateGlobalVertex(unskinnedMesh, face, 1, vertices, hasUV, hasUV2, hasColor, hasAlpha, verticesAlreadyExported, skin, boneIds, nbBones);
|
|
indices.Add(a);
|
|
indices.Add(a);
|
|
indices.Add(b);
|
|
indices.Add(b);
|
|
indices.Add(c);
|
|
indices.Add(c);
|
|
@@ -615,7 +625,7 @@ namespace Max2Babylon
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
- int CreateGlobalVertex(IIGameMesh mesh, IFaceEx face, int facePart, List<GlobalVertex> vertices, bool hasUV, bool hasUV2, bool hasColor, bool hasAlpha, List<GlobalVertex>[] verticesAlreadyExported, IIGameSkin skin, List<int> boneIds)
|
|
|
|
|
|
+ int CreateGlobalVertex(IIGameMesh mesh, IFaceEx face, int facePart, List<GlobalVertex> vertices, bool hasUV, bool hasUV2, bool hasColor, bool hasAlpha, List<GlobalVertex>[] verticesAlreadyExported, IIGameSkin skin, List<int> boneIds, int nbBones)
|
|
{
|
|
{
|
|
var vertexIndex = (int)face.Vert[facePart];
|
|
var vertexIndex = (int)face.Vert[facePart];
|
|
|
|
|
|
@@ -687,7 +697,6 @@ namespace Max2Babylon
|
|
int bone1 = bonesCount;
|
|
int bone1 = bonesCount;
|
|
int bone2 = bonesCount;
|
|
int bone2 = bonesCount;
|
|
int bone3 = bonesCount;
|
|
int bone3 = bonesCount;
|
|
- int nbBones = skin.GetNumberOfBones(vertexIndex);
|
|
|
|
|
|
|
|
if (nbBones > 0)
|
|
if (nbBones > 0)
|
|
{
|
|
{
|