diff --git a/3ds Max/Max2Babylon/Exporter/BabylonExporter.Mesh.cs b/3ds Max/Max2Babylon/Exporter/BabylonExporter.Mesh.cs index a882dfc4..ee267f9a 100644 --- a/3ds Max/Max2Babylon/Exporter/BabylonExporter.Mesh.cs +++ b/3ds Max/Max2Babylon/Exporter/BabylonExporter.Mesh.cs @@ -1183,6 +1183,9 @@ int CreateGlobalVertex(IIGameMesh mesh, BabylonAbstractMesh babylonAbstractMesh, float[] weight = new float[4] { 0, 0, 0, 0 }; int[] bone = new int[4] { 0, 0, 0, 0 }; var nbBones = skin.GetNumberOfBones(vertexIndex); + // Babylon, nor GLTF do not support single bone skeleton, we may add a root node with no transform. + // this is echoing the process into BabylonExporter.Skeleton ExportBones(Skin) + var offset = skin.TotalBoneCount == 1 ? 1 : 0; int currentVtxBone = 0; int currentSkinBone = 0; @@ -1194,7 +1197,7 @@ int CreateGlobalVertex(IIGameMesh mesh, BabylonAbstractMesh babylonAbstractMesh, if (boneWeight <= 0) continue; - bone[currentVtxBone] = boneIds.IndexOf(skin.GetIGameBone(vertexIndex, currentSkinBone).NodeID); + bone[currentVtxBone] = boneIds.IndexOf(skin.GetIGameBone(vertexIndex, currentSkinBone).NodeID) + offset; // add optional offset weight[currentVtxBone] = skin.GetWeight(vertexIndex, currentSkinBone); ++currentVtxBone; } @@ -1227,7 +1230,7 @@ int CreateGlobalVertex(IIGameMesh mesh, BabylonAbstractMesh babylonAbstractMesh, break; } - bone[currentVtxBone - 4] = boneIds.IndexOf(skin.GetIGameBone(vertexIndex, currentSkinBone).NodeID); + bone[currentVtxBone - 4] = boneIds.IndexOf(skin.GetIGameBone(vertexIndex, currentSkinBone).NodeID) + offset; // add optional offset weight[currentVtxBone - 4] = skin.GetWeight(vertexIndex, currentSkinBone); ++currentVtxBone; } diff --git a/3ds Max/Max2Babylon/Exporter/BabylonExporter.Skeleton.cs b/3ds Max/Max2Babylon/Exporter/BabylonExporter.Skeleton.cs index 703edc89..c0e25775 100644 --- a/3ds Max/Max2Babylon/Exporter/BabylonExporter.Skeleton.cs +++ b/3ds Max/Max2Babylon/Exporter/BabylonExporter.Skeleton.cs @@ -423,6 +423,28 @@ private BabylonBone[] ExportBones(IIGameSkin skin) bones.Add(bone); } + // Babylon, nor GLTF do not support single bone skeleton, we may add a root node with no transform. + if( bones.Count == 1) + { + var root = new BabylonBone() + { + id = Guid.NewGuid().ToString(), + parentNodeId = null, + name = "root-bone-added", + index = 0, + parentBoneIndex = -1, + matrix = BabylonMatrix.Identity().m + }; + + var bone = bones[0]; + bone.parentNodeId = root.id; + bone.index = 1; + bone.parentBoneIndex = 0; + + bones.Insert(0, root); + } + + // finally return the bones. return bones.ToArray(); } }