From c31ed63269a79fc42a94fba779ffbcbab1944d66 Mon Sep 17 00:00:00 2001 From: "Sergio R. Z. Masson" <97050577+SergioRZMasson@users.noreply.github.com> Date: Thu, 25 Jan 2024 15:53:28 -0300 Subject: [PATCH] Fixed morph targets to not be 0 index based (#1110) * Fixed morph targets to not be 0 index based --- .../Exporter/BabylonExporter.Mesh.cs | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/3ds Max/Max2Babylon/Exporter/BabylonExporter.Mesh.cs b/3ds Max/Max2Babylon/Exporter/BabylonExporter.Mesh.cs index 50ba8e58..fc27489d 100644 --- a/3ds Max/Max2Babylon/Exporter/BabylonExporter.Mesh.cs +++ b/3ds Max/Max2Babylon/Exporter/BabylonExporter.Mesh.cs @@ -125,11 +125,11 @@ private BabylonNode ExportMesh(IIGameScene scene, IIGameNode meshNode, BabylonSc { bool isShareMat = masterMeshPair.Key.materialId == null || (meshNode.NodeMaterial != null && meshNode.NodeMaterial.MaxMaterial.GetGuid().ToString().Equals(masterMeshPair.Value.NodeMaterial.MaxMaterial.GetGuid().ToString())); - BabylonNode n = isShareMat? + BabylonNode n = isShareMat ? ExportInstanceMesh(scene, meshNode, babylonScene, masterMeshPair.Key, masterMeshPair.Value) : exportParameters.useClone ? ExportCloneMesh(scene, meshNode, babylonScene, masterMeshPair.Key, masterMeshPair.Value) : null; - - if( n != null) + + if (n != null) { return n; } @@ -469,7 +469,7 @@ private BabylonNode ExportMasterMesh(IIGameScene scene, IIGameNode meshNode, Bab babylonMesh.colors = colors; babylonMesh.hasVertexAlpha = hasAlpha; } - + } babylonMesh.subMeshes = subMeshes.ToArray(); @@ -527,14 +527,14 @@ private BabylonNode ExportMasterMesh(IIGameScene scene, IIGameNode meshNode, Bab var maxMorphTarget = morpher.GetMorphTarget(i); // 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 // with the source and target vertices. - bool mustRebuildMorphTarget = (maxMorphTarget == null || optimizeVertices ); + bool mustRebuildMorphTarget = (maxMorphTarget == null || optimizeVertices); if (mustRebuildMorphTarget) { string actionStr = exportParameters.rebuildMorphTarget ? $" trying to rebuild {i}." : string.Empty; if (maxMorphTarget == null) { RaiseWarning($"Morph target [{i}] is not available anymore - ie: has been deleted in max and is baked into the scene.{actionStr}", 3); - } + } else { 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 var babylonMorphTarget = new BabylonMorphTarget { // the name is reconstructed if we have to rebuild the target - name = maxMorphTarget?.Name ?? $"{meshNode.Name}.morpher({m}).target({i})" + name = maxMorphTarget?.Name ?? $"{meshNode.Name}.morpher({m}).target({i})" }; babylonMorphTargets.Add(babylonMorphTarget); - RaiseMessage($"Morph target {babylonMorphTarget.name} added.",3); + RaiseMessage($"Morph target {babylonMorphTarget.name} added.", 3); // TODO - Influence - babylonMorphTarget.influence = 0f; + babylonMorphTarget.influence = 0f; // Target geometry 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 if (mustRebuildMorphTarget) { // we do not recontruct the normals - RaiseWarning("we do not have morph normals when morph target has been rebuilded.",4); + RaiseWarning("we do not have morph normals when morph target has been rebuilded.", 4); babylonMorphTarget.normals = null; } else @@ -656,7 +656,7 @@ private IEnumerable ExtractMorphTargetPoints(BabylonAbstractMesh babylo // this is the place where we reconstruct the vertices. // the needed function is not available on the .net SDK, then we have to use Max Script. // TODO : use direct instance instead of manipulate string - 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"; + 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"; #if MAX2022 || MAX2023 || MAX2024 var str = ManagedServices.MaxscriptSDK.ExecuteStringMaxscriptQuery(script, ManagedServices.MaxscriptSDK.ScriptSource.NotSpecified); #else @@ -920,7 +920,7 @@ private void ExtractGeometry(BabylonAbstractMesh babylonAbstractMesh, List(); - + GenerateCoordinatesAnimations(maxGameNode, animations); - + if (!ExportFloatController(maxGameNode.MaxNode.VisController, "visibility", animations)) { ExportFloatAnimation("visibility", animations, key => new[] { maxGameNode.MaxNode.GetVisibility(key, Tools.Forever) }); @@ -1373,7 +1373,7 @@ private float GetW(IPoint3 normal, IPoint3 tangent, IPoint3 bitangent) float bty = MathUtilities.RoundToIfAlmostEqualTo(bitangent.Y, 0, Tools.Epsilon); float btz = MathUtilities.RoundToIfAlmostEqualTo(bitangent.Z, 0, Tools.Epsilon); - if( btx == 0 && bty == 0 && btz == 0) + if (btx == 0 && bty == 0 && btz == 0) { return 1; } @@ -1395,7 +1395,7 @@ private float GetW(IPoint3 normal, IPoint3 tangent, IPoint3 bitangent) // then the two vectors point in the same general direction, meaning less than 90 degrees. // If the dot product is negative, then the two vectors point in opposite directions, // or above 90 and less than or equal to 180 degrees. - var dot = MathUtilities.DotProduct(btx, bty,btz, x,y,z); + var dot = MathUtilities.DotProduct(btx, bty, btz, x, y, z); return dot < 0 ? -1 : 1; }