Skip to content
On this page

Pipeline LOD-chain (cascaded / based on previous LOD)

This example executes Simplygon three times in a loop, where each optimization (in this case Reduction) is based on the previously optimized result (except the first which is based on the original asset). This behavior can be accomplished by overriding the ReductionTargetTriangleRatio one time before the loop, then in the loop execute Simplygon and after each optimization select the resulting meshes returned from the Simplygon call (which will be the source for the next iteration).

MEL
// load an asset
file -f -options "v=0;" -ignoreVersion -typ "mayaBinary" -o "D:/Assets/SomeAsset.mb";

// select everything in scene
select -all;

// load previously saved pipeline
$reductionPipeline = `SimplygonPipeline -l "D:/Pipelines/reductionPipeline.json"`;

// override reduction ratio to 75%
$bResult = `SimplygonPipeline -ss "ReductionProcessor/ReductionSettings/ReductionTargetTriangleRatio" -v 0.75 $reductionPipeline`;

// loop 3 times,
// 1 - reduce original asset by 25%
// 2 - reduce LOD1 by 25%
// 3 - reduce LOD2 by 25%
for( $i = 0; $i < 3; ++$i )
{
   // execute pipeline on selection,
   // returns result to Maya once completed
   string $processedMeshes[] = `Simplygon -so $reductionPipeline`;

   // clear selection
   select -cl;

   // select optimized meshes returned by Simplygon,
   // they will be the source in the next iteration
   for($m in $processedMeshes)
   {
       select -add $m;
   }
}

// clear all pipelines
SimplygonPipeline -cl;
python
import maya.cmds as cmds

# load an asset
cmds.file('D:/Assets/SomeAsset.mb', i = True, mergeNamespacesOnClash = True, namespace = ':', importFrameRate = True)

# select everything in scene
cmds.select(all = True)

# load previously saved pipeline
reductionPipeline = cmds.SimplygonPipeline(l = 'D:/Pipelines/reductionPipeline.json')

# override reduction ratio to 75%
bResult = cmds.SimplygonPipeline(reductionPipeline, ss = 'ReductionProcessor/ReductionSettings/ReductionTargetTriangleRatio', v = 0.75)

# loop 3 times,
# 1 - reduce original asset by 25%
# 2 - reduce LOD1 by 25%
# 3 - reduce LOD2 by 25%
for i in range(3):
    # execute pipeline on selection,
    # returns result to Maya once completed
    processedMeshes = cmds.Simplygon(so = reductionPipeline)

    # clear selection
    cmds.select(cl = True)

    # select optimized meshes returned by Simplygon,
    # they will be the source in the next iteration
    for m in processedMeshes:
        cmds.select(m, add = True)

# clear all pipelines
cmds.SimplygonPipeline(cl = True)