Skip to content

Commit c31ed63

Browse files
Fixed morph targets to not be 0 index based (#1110)
* Fixed morph targets to not be 0 index based
1 parent 863ae03 commit c31ed63

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

3ds Max/Max2Babylon/Exporter/BabylonExporter.Mesh.cs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,11 @@ private BabylonNode ExportMesh(IIGameScene scene, IIGameNode meshNode, BabylonSc
125125
{
126126
bool isShareMat = masterMeshPair.Key.materialId == null || (meshNode.NodeMaterial != null && meshNode.NodeMaterial.MaxMaterial.GetGuid().ToString().Equals(masterMeshPair.Value.NodeMaterial.MaxMaterial.GetGuid().ToString()));
127127

128-
BabylonNode n = isShareMat?
128+
BabylonNode n = isShareMat ?
129129
ExportInstanceMesh(scene, meshNode, babylonScene, masterMeshPair.Key, masterMeshPair.Value) :
130130
exportParameters.useClone ? ExportCloneMesh(scene, meshNode, babylonScene, masterMeshPair.Key, masterMeshPair.Value) : null;
131-
132-
if( n != null)
131+
132+
if (n != null)
133133
{
134134
return n;
135135
}
@@ -469,7 +469,7 @@ private BabylonNode ExportMasterMesh(IIGameScene scene, IIGameNode meshNode, Bab
469469
babylonMesh.colors = colors;
470470
babylonMesh.hasVertexAlpha = hasAlpha;
471471
}
472-
472+
473473
}
474474

475475
babylonMesh.subMeshes = subMeshes.ToArray();
@@ -527,14 +527,14 @@ private BabylonNode ExportMasterMesh(IIGameScene scene, IIGameNode meshNode, Bab
527527
var maxMorphTarget = morpher.GetMorphTarget(i);
528528
// here we avoid to extract vertices in an optimize way, du to the fact that the actual optimize process is NOT garanty to keep a one to one relationship
529529
// with the source and target vertices.
530-
bool mustRebuildMorphTarget = (maxMorphTarget == null || optimizeVertices );
530+
bool mustRebuildMorphTarget = (maxMorphTarget == null || optimizeVertices);
531531
if (mustRebuildMorphTarget)
532532
{
533533
string actionStr = exportParameters.rebuildMorphTarget ? $" trying to rebuild {i}." : string.Empty;
534534
if (maxMorphTarget == null)
535535
{
536536
RaiseWarning($"Morph target [{i}] is not available anymore - ie: has been deleted in max and is baked into the scene.{actionStr}", 3);
537-
}
537+
}
538538
else
539539
{
540540
RaiseWarning($"Morph target [{i}] MUST be rebuilt to avoid artifacts, using the vertices export process.{actionStr}", 3);
@@ -550,13 +550,13 @@ private BabylonNode ExportMasterMesh(IIGameScene scene, IIGameNode meshNode, Bab
550550
var babylonMorphTarget = new BabylonMorphTarget
551551
{
552552
// the name is reconstructed if we have to rebuild the target
553-
name = maxMorphTarget?.Name ?? $"{meshNode.Name}.morpher({m}).target({i})"
553+
name = maxMorphTarget?.Name ?? $"{meshNode.Name}.morpher({m}).target({i})"
554554
};
555555
babylonMorphTargets.Add(babylonMorphTarget);
556-
RaiseMessage($"Morph target {babylonMorphTarget.name} added.",3);
556+
RaiseMessage($"Morph target {babylonMorphTarget.name} added.", 3);
557557

558558
// TODO - Influence
559-
babylonMorphTarget.influence = 0f;
559+
babylonMorphTarget.influence = 0f;
560560

561561
// Target geometry
562562
babylonMorphTarget.positions = targetVertices.SelectMany(v => new[] { v.Position.X, v.Position.Y, v.Position.Z }).ToArray();
@@ -566,7 +566,7 @@ private BabylonNode ExportMasterMesh(IIGameScene scene, IIGameNode meshNode, Bab
566566
if (mustRebuildMorphTarget)
567567
{
568568
// we do not recontruct the normals
569-
RaiseWarning("we do not have morph normals when morph target has been rebuilded.",4);
569+
RaiseWarning("we do not have morph normals when morph target has been rebuilded.", 4);
570570
babylonMorphTarget.normals = null;
571571
}
572572
else
@@ -656,7 +656,7 @@ private IEnumerable<IPoint3> ExtractMorphTargetPoints(BabylonAbstractMesh babylo
656656
// this is the place where we reconstruct the vertices.
657657
// the needed function is not available on the .net SDK, then we have to use Max Script.
658658
// TODO : use direct instance instead of manipulate string
659-
var script = $"with printAllElements on (for k in 0 to (WM3_MC_NumMPts ${babylonAbstractMesh.name}.Morpher {morphIndex}) collect (WM3_MC_GetMorphPoint ${babylonAbstractMesh.name}.morpher {morphIndex} k)) as string";
659+
var script = $"with printAllElements on (for k in 0 to (WM3_MC_NumMPts ${babylonAbstractMesh.name}.Morpher {morphIndex + 1}) collect (WM3_MC_GetMorphPoint ${babylonAbstractMesh.name}.morpher {morphIndex + 1} k)) as string";
660660
#if MAX2022 || MAX2023 || MAX2024
661661
var str = ManagedServices.MaxscriptSDK.ExecuteStringMaxscriptQuery(script, ManagedServices.MaxscriptSDK.ScriptSource.NotSpecified);
662662
#else
@@ -920,7 +920,7 @@ private void ExtractGeometry(BabylonAbstractMesh babylonAbstractMesh, List<Globa
920920
// Material Id is 0 if normal material, and GetMaterialID if multi-material
921921
// default is [1,n] increment by 1 but user can decide to change the id (still an int) and set for example [4,3,9,1]
922922
// note that GetMaterialID return the user id minus 1
923-
int materialId = multiMatsCount == 1? i : meshNode.NodeMaterial.GetMaterialID(i);
923+
int materialId = multiMatsCount == 1 ? i : meshNode.NodeMaterial.GetMaterialID(i);
924924
var subMesh = new BabylonSubMesh { indexStart = indexStart, materialIndex = i };
925925
if (multiMatsCount == 1)
926926
{
@@ -1135,7 +1135,7 @@ int CreateGlobalVertex(IIGameMesh mesh, BabylonAbstractMesh babylonAbstractMesh,
11351135
}
11361136
}
11371137
var texCoord = mesh.GetMapVertex(1, indices[facePart]);
1138-
vertex.UV = Loader.Global.Point2.Create(texCoord.X, 1 -texCoord.Y);
1138+
vertex.UV = Loader.Global.Point2.Create(texCoord.X, 1 - texCoord.Y);
11391139
}
11401140

11411141
if (hasUV2)
@@ -1149,7 +1149,7 @@ int CreateGlobalVertex(IIGameMesh mesh, BabylonAbstractMesh babylonAbstractMesh,
11491149
}
11501150
}
11511151
var texCoord = mesh.GetMapVertex(2, indices[facePart]);
1152-
vertex.UV2 = Loader.Global.Point2.Create(texCoord.X, 1 -texCoord.Y);
1152+
vertex.UV2 = Loader.Global.Point2.Create(texCoord.X, 1 - texCoord.Y);
11531153
}
11541154

11551155
if (hasColor)
@@ -1330,9 +1330,9 @@ private void exportAnimation(BabylonNode babylonNode, IIGameNode maxGameNode)
13301330
if (exportParameters.exportAnimations)
13311331
{
13321332
var animations = new List<BabylonAnimation>();
1333-
1333+
13341334
GenerateCoordinatesAnimations(maxGameNode, animations);
1335-
1335+
13361336
if (!ExportFloatController(maxGameNode.MaxNode.VisController, "visibility", animations))
13371337
{
13381338
ExportFloatAnimation("visibility", animations, key => new[] { maxGameNode.MaxNode.GetVisibility(key, Tools.Forever) });
@@ -1373,7 +1373,7 @@ private float GetW(IPoint3 normal, IPoint3 tangent, IPoint3 bitangent)
13731373
float bty = MathUtilities.RoundToIfAlmostEqualTo(bitangent.Y, 0, Tools.Epsilon);
13741374
float btz = MathUtilities.RoundToIfAlmostEqualTo(bitangent.Z, 0, Tools.Epsilon);
13751375

1376-
if( btx == 0 && bty == 0 && btz == 0)
1376+
if (btx == 0 && bty == 0 && btz == 0)
13771377
{
13781378
return 1;
13791379
}
@@ -1395,7 +1395,7 @@ private float GetW(IPoint3 normal, IPoint3 tangent, IPoint3 bitangent)
13951395
// then the two vectors point in the same general direction, meaning less than 90 degrees.
13961396
// If the dot product is negative, then the two vectors point in opposite directions,
13971397
// or above 90 and less than or equal to 180 degrees.
1398-
var dot = MathUtilities.DotProduct(btx, bty,btz, x,y,z);
1398+
var dot = MathUtilities.DotProduct(btx, bty, btz, x, y, z);
13991399
return dot < 0 ? -1 : 1;
14001400
}
14011401

0 commit comments

Comments
 (0)