Skip to content
On this page

Simple reduction - Scripting

This example will create a simple reduction pipeline with a target Triangle Ratio of 0.5 (50%), send the selected scene off to Simplygon for optimization and return the result back to Maya once completed.

The first step is to create a minimalistic ReductionPipeline, just a simple reduction on geometries while preserving original materials, nothing more, nothing less.

MEL
// create a Reduction Pipeline object
$reductionPipeline = `SimplygonPipeline -c "ReductionPipeline"`;

// set the triangle ratio to 50%
$bResult = `SimplygonPipeline -ss "ReductionProcessor/ReductionSettings/ReductionTargetTriangleRatio" -v 0.5 $reductionPipeline`;

// set the reduction target to ReductionTargetTriangleRatio
$bResult = `SimplygonPipeline -ss "ReductionProcessor/ReductionSettings/ReductionTargetTriangleRatioEnabled" -v true $reductionPipeline`;

// disable triangle count reduction target
$bResult = `SimplygonPipeline -ss "ReductionProcessor/ReductionSettings/ReductionTargetTriangleCountEnabled" -v false $reductionPipeline`;

// disable max deviation reduction target
$bResult = `SimplygonPipeline -ss "ReductionProcessor/ReductionSettings/ReductionTargetMaxDeviationEnabled" -v false $reductionPipeline`;

// disable onscreensize reduction target
$bResult = `SimplygonPipeline -ss "ReductionProcessor/ReductionSettings/ReductionTargetOnScreenSizeEnabled" -v false $reductionPipeline`;

// more settings can be set for the Reduction pipeline,
// see Pipeline documentation and / or inspect the generated file
// that is saved out by this script!

// save the generated Pipeline object to file for later use,
// this is optional for this example and is mostly intended for inspection
// of the settings for the given Pipeline.
$bResult = `SimplygonPipeline -s "D:/Pipelines/Reduction.json" $reductionPipeline`;
python
import maya.cmds as cmds

# create a Reduction Pipeline object
reductionPipeline = cmds.SimplygonPipeline(c = 'ReductionPipeline')

# set the triangle ratio to 50%
bResult = cmds.SimplygonPipeline(reductionPipeline, ss = 'ReductionProcessor/ReductionSettings/ReductionTargetTriangleRatio', v = 0.5)

# set the reduction target to ReductionTargetTriangleRatio
bResult = cmds.SimplygonPipeline(reductionPipeline, ss = 'ReductionProcessor/ReductionSettings/ReductionTargetTriangleRatioEnabled', v = True)

# disable triangle count reduction target
bResult = cmds.SimplygonPipeline(reductionPipeline, ss = 'ReductionProcessor/ReductionSettings/ReductionTargetTriangleCountEnabled', v = False)

# disable max deviation reduction target
bResult = cmds.SimplygonPipeline(reductionPipeline, ss = 'ReductionProcessor/ReductionSettings/ReductionTargetMaxDeviationEnabled', v = False)

# disable onscreensize reduction target
bResult = cmds.SimplygonPipeline(reductionPipeline, ss = 'ReductionProcessor/ReductionSettings/ReductionTargetOnScreenSizeEnabled', v = False)

# more settings can be set for the Reduction pipeline,
# see Pipeline documentation and / or inspect the generated file
# that is saved out by this script!

# save the generated Pipeline object to file for later use,
# this is optional for this example and is mostly intended for inspection
# of the settings for the given Pipeline.
bResult = cmds.SimplygonPipeline(reductionPipeline, s = 'D:/Pipelines/Reduction.json')

The Simplygon-command has a number of flags which can be passed from script, for example the so (SettingsObject) flag which specifies which Pipeline / settings Simplygon will use during optimization.

The second part is to select the scene that is to be optimized (or parts of it) and start the optimization using the Simplygon command. The optimized result will get imported automatically once the optimization has completed.

MEL
// select objects in scene
select -all;

// execute Simplygon with the given Pipeline (settings-object)
Simplygon -so $reductionPipeline;
python
# select objects in scene
cmds.select(all=True)

# execute Simplygon with the given Pipeline (settings-object)
bResult = cmds.Simplygon(so = reductionPipeline, cte = False)

The third and last part is simply to clean up created and / or loaded Pipelines that resides in memory, they can of course be reused but it is easy to forget they were ever there.

MEL
// clear all pipelines
SimplygonPipeline -cl;
python
# clear all pipelines
cmds.SimplygonPipeline(cl = True)

Next steps

Get to know how to use the Simplygon Maya plug-in: