Skip to content
On this page

Pipeline LOD-chain (based on original asset)

This example executes Simplygon three times in a loop, where each optimization (in this case Reduction) is based on the original asset. This is accomplished by simply overriding the ReductionTargetTriangleRatio each loop before sending the asset off to Simplygon.

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 triangle ratio to 100%
$bResult = `SimplygonPipeline -ss "ReductionProcessor/ReductionSettings/ReductionTargetTriangleRatio" -v 1.0 $reductionPipeline`;

// loop 3 times,
// 1 - reduce original asset to 100 - 25 = 75% (LOD1)
// 2 - reduce original asset to 75 - 25 = 50% (LOD2)
// 3 - reduce original asset to 50 - 25 = 25% (LOD3)
for( $i = 0; $i < 3; ++$i )
{
    // fetch current triangle ratio
    $reductionTargetTriangleRatio = `SimplygonPipeline -gs "ReductionProcessor/ReductionSettings/ReductionTargetTriangleRatio" $reductionPipeline`;

    // subtract triangle ratio by 25%
    $bResult = `SimplygonPipeline -ss "ReductionProcessor/ReductionSettings/ReductionTargetTriangleRatio" -v ($reductionTargetTriangleRatio - 0.25) $reductionPipeline`;

    // execute pipeline on selection,
    // returns result to Maya once completed
    Simplygon -so $reductionPipeline;
}

// 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 triangle ratio to 100%
bResult = cmds.SimplygonPipeline(reductionPipeline, ss = 'ReductionProcessor/ReductionSettings/ReductionTargetTriangleRatio', v = 1.0)

# loop 3 times,
# 1 - reduce original asset to 100 - 25 = 75% (LOD1)
# 2 - reduce original asset to 75 - 25 = 50% (LOD2)
# 3 - reduce original asset to 50 - 25 = 25% (LOD3)
for i in range(3):
    # fetch current triangle ratio
    reductionTargetTriangleRatio = cmds.SimplygonPipeline(reductionPipeline, gs = 'ReductionProcessor/ReductionSettings/ReductionTargetTriangleRatio')

    # subtract triangle ratio by 25%
    bResult = cmds.SimplygonPipeline(reductionPipeline, ss = 'ReductionProcessor/ReductionSettings/ReductionTargetTriangleRatio', v = (reductionTargetTriangleRatio - 0.25))

    # execute pipeline on selection,
    # returns result to Maya once completed
    cmds.Simplygon(so = reductionPipeline)

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