Skip to content

Commit

Permalink
Morph target export performance improvement (#1096)
Browse files Browse the repository at this point in the history
- Added small performance improvements to morph targets import, reducing load time by 50%.
  • Loading branch information
SergioRZMasson authored Sep 19, 2023
1 parent 0d548e0 commit 53e75fb
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions 3ds Max/Max2Babylon/Exporter/BabylonExporter.Mesh.cs
Original file line number Diff line number Diff line change
Expand Up @@ -623,30 +623,32 @@ private BabylonNode ExportMasterMesh(IIGameScene scene, IIGameNode meshNode, Bab
return babylonMesh;
}

private IEnumerable<GlobalVertex> ExtractMorphTargetVertices(BabylonAbstractMesh babylonAbstractMesh, List<GlobalVertex> vertices, IMatrix3 offsetTM, int morphIndex, IIGameNode maxMorphTarget, bool optimizeVertices, List<int> faceIndexes)
private IList<GlobalVertex> ExtractMorphTargetVertices(BabylonAbstractMesh babylonAbstractMesh, List<GlobalVertex> vertices, IMatrix3 offsetTM, int morphIndex, IIGameNode maxMorphTarget, bool optimizeVertices, List<int> faceIndexes)
{
if (maxMorphTarget != null )
if (maxMorphTarget != null)
{
foreach(var v in ExtractVertices(babylonAbstractMesh, maxMorphTarget, optimizeVertices, faceIndexes))
{
yield return v;
}
yield break;
return ExtractVertices(babylonAbstractMesh, maxMorphTarget, optimizeVertices, faceIndexes);
}
// rebuild Morph Target
if (exportParameters.rebuildMorphTarget)

var result = new List<GlobalVertex>();

if (!exportParameters.rebuildMorphTarget)
{
var points = ExtractMorphTargetPoints(babylonAbstractMesh, morphIndex, offsetTM).ToList();
for (int i = 0; i != vertices.Count; i++)
return result;
}

var points = ExtractMorphTargetPoints(babylonAbstractMesh, morphIndex, offsetTM).ToList();
for (int i = 0; i != vertices.Count; i++)
{
int bi = vertices[i].BaseIndex;
result.Add(new GlobalVertex()
{
int bi = vertices[i].BaseIndex;
yield return new GlobalVertex()
{
BaseIndex = bi,
Position = points[bi]
};
}
BaseIndex = bi,
Position = points[bi]
});
}

return result;
}

private IEnumerable<IPoint3> ExtractMorphTargetPoints(BabylonAbstractMesh babylonAbstractMesh, int morphIndex, IMatrix3 offsetTM)
Expand Down

0 comments on commit 53e75fb

Please sign in to comment.