Skip to content
On this page

Simple Reduction pipeline

This example shows how to create a new ReductionPipeline and how to set basic parameters for reduction and material baking.

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

// set DefaultTangentCalculatorType to OrthonormalRightHanded (0)
$bResult = `SimplygonPipeline -ss "GlobalSettings/DefaultTangentCalculatorType" -v 0 $reductionPipeline`;
$defaultTangentCalculatorType = `SimplygonPipeline -gs "GlobalSettings/DefaultTangentCalculatorType" $reductionPipeline`;
print ("DefaultTangentCalculatorType: " + $defaultTangentCalculatorType + "\n");

// set the triangle ratio to 50%
$bResult = `SimplygonPipeline -ss "ReductionProcessor/ReductionSettings/ReductionTargetTriangleRatio" -v 0.5 $reductionPipeline`;
$reductionTargetTriangleRatio = `SimplygonPipeline -gs "ReductionProcessor/ReductionSettings/ReductionTargetTriangleRatio" $reductionPipeline`;
print ("ReductionTargetTriangleRatio: " + $reductionTargetTriangleRatio + "\n");

// set the reduction target to ReductionTargetTriangleRatio
$bResult = `SimplygonPipeline -ss "ReductionProcessor/ReductionSettings/ReductionTargetTriangleRatioEnabled" -v true $reductionPipeline`;
$reductionTargetTriangleRatioEnabled = `SimplygonPipeline -gs "ReductionProcessor/ReductionSettings/ReductionTargetTriangleRatioEnabled" $reductionPipeline`;
print ("ReductionTargetTriangleRatioEnabled: " + $reductionTargetTriangleRatioEnabled + "\n");

// disable triangle count reduction target
$bResult = `SimplygonPipeline -ss "ReductionProcessor/ReductionSettings/ReductionTargetTriangleCountEnabled" -v false $reductionPipeline`;
$reductionTargetTriangleCountEnabled = `SimplygonPipeline -gs "ReductionProcessor/ReductionSettings/ReductionTargetTriangleCountEnabled" $reductionPipeline`;
print ("ReductionTargetTriangleCountEnabled: " + $reductionTargetTriangleCountEnabled + "\n");

// disable max deviation reduction target
$bResult = `SimplygonPipeline -ss "ReductionProcessor/ReductionSettings/ReductionTargetMaxDeviationEnabled" -v false $reductionPipeline`;
$reductionTargetMaxDeviationEnabled = `SimplygonPipeline -gs "ReductionProcessor/ReductionSettings/ReductionTargetMaxDeviationEnabled" $reductionPipeline`;
print ("ReductionTargetMaxDeviationEnabled: " + $reductionTargetMaxDeviationEnabled + "\n");

// disable onscreensize reduction target
$bResult = `SimplygonPipeline -ss "ReductionProcessor/ReductionSettings/ReductionTargetOnScreenSizeEnabled" -v false $reductionPipeline`;
$reductionTargetOnScreenSizeEnabled = `SimplygonPipeline -gs "ReductionProcessor/ReductionSettings/ReductionTargetOnScreenSizeEnabled" $reductionPipeline`;
print ("ReductionTargetOnScreenSizeEnabled: " + $reductionTargetOnScreenSizeEnabled + "\n");

// 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!

// set bMaterialBake to true to enable material baking,
// if material baking is enabled Simplygon will generate
// a new material (with textures) shared by all the optimized meshes.
$bMaterialBake = true;
if($bMaterialBake)
{
   // enable material baking
   // mapping image is required for material baking
   $bResult = `SimplygonPipeline -ss "ReductionProcessor/MappingImageSettings/GenerateMappingImage" -v true $reductionPipeline`;
   $generateMappingImage = `SimplygonPipeline -gs "ReductionProcessor/MappingImageSettings/GenerateMappingImage" $reductionPipeline`;
   print ("GenerateMappingImage: " + $generateMappingImage + "\n");

   // in this case we want to generate texture coordinates (UVs)
   $bResult = `SimplygonPipeline -ss "ReductionProcessor/MappingImageSettings/GenerateTexCoords" -v true $reductionPipeline`;
   $generateTexCoords = `SimplygonPipeline -gs "ReductionProcessor/MappingImageSettings/GenerateTexCoords" $reductionPipeline`;
   print ("GenerateTexCoords: " + $generateTexCoords + "\n");

   // the name of the resulting texture coordinate field
   $bResult = `SimplygonPipeline -ss "ReductionProcessor/MappingImageSettings/TexCoordName" -v "MaterialLOD" $reductionPipeline`;
   $texCoordLevel = `SimplygonPipeline -gs "ReductionProcessor/MappingImageSettings/TexCoordName" $reductionPipeline`;
   print ("TexCoordName: " + $texCoordLevel + "\n");

   // width of the baked textures
   $bResult = `SimplygonPipeline -ss "ReductionProcessor/MappingImageSettings/Output0/TextureWidth" -v 512 $reductionPipeline`;
   $textureWidth = `SimplygonPipeline -gs "ReductionProcessor/MappingImageSettings/Output0/TextureWidth" $reductionPipeline`;
   print ("TextureWidth: " + $textureWidth + "\n");

   // height of the baked textures
   $bResult = `SimplygonPipeline -ss "ReductionProcessor/MappingImageSettings/Output0/TextureHeight" -v 512 $reductionPipeline`;
   $textureHeight = `SimplygonPipeline -gs "ReductionProcessor/MappingImageSettings/Output0/TextureHeight" $reductionPipeline`;
   print ("TextureHeight: " + $textureHeight + "\n");

   // add material casters (ambientColor, color, specularColor and normalCamera)
   $casterIndex = `SimplygonPipeline -amc "ColorCaster" $reductionPipeline`;
   $bResult = `SimplygonPipeline -ss ("MaterialCaster/" + $casterIndex + "/ColorCasterSettings/MaterialChannel") -v "ambientColor" $reductionPipeline`;
   $colorCaster0 = `SimplygonPipeline -gs ("MaterialCaster/" + $casterIndex + "/ColorCasterSettings/MaterialChannel") $reductionPipeline`;
   print ("ColorCaster0: " + $colorCaster0 + "\n");

   $casterIndex = `SimplygonPipeline -amc "ColorCaster" $reductionPipeline`;
   $bResult = `SimplygonPipeline -ss ("MaterialCaster/" + $casterIndex + "/ColorCasterSettings/MaterialChannel") -v "color" $reductionPipeline`;
   $colorCaster1 = `SimplygonPipeline -gs ("MaterialCaster/" + $casterIndex + "/ColorCasterSettings/MaterialChannel") $reductionPipeline`;
   print ("ColorCaster1: " + $colorCaster1 + "\n");

   $casterIndex = `SimplygonPipeline -amc "ColorCaster" $reductionPipeline`;
   $bResult = `SimplygonPipeline -ss ("MaterialCaster/" + $casterIndex + "/ColorCasterSettings/MaterialChannel") -v "specularColor" $reductionPipeline`;
   $colorCaster2 = `SimplygonPipeline -gs ("MaterialCaster/" + $casterIndex + "/ColorCasterSettings/MaterialChannel") $reductionPipeline`;
   print ("ColorCaster2: " + $colorCaster2 + "\n");

   // note: normal caster for normals!
   $casterIndex = `SimplygonPipeline -amc "NormalCaster" $reductionPipeline`;
   $bResult = `SimplygonPipeline -ss ("MaterialCaster/" + $casterIndex + "/NormalCasterSettings/MaterialChannel") -v "normalCamera" $reductionPipeline`;
   $normalCaster3 = `SimplygonPipeline -gs ("MaterialCaster/" + $casterIndex + "/NormalCasterSettings/MaterialChannel") $reductionPipeline`;
   print ("NormalCaster3: " + $normalCaster3 + "\n");

   // set the correct tangent space type,
   // in this example we use tangent space normals
   $bResult = `SimplygonPipeline -ss ("MaterialCaster/" + $casterIndex + "/NormalCasterSettings/GenerateTangentSpaceNormals") -v true $reductionPipeline`;
   $generateTangentSpaceNormals = `SimplygonPipeline -gs ("MaterialCaster/" + $casterIndex + "/NormalCasterSettings/GenerateTangentSpaceNormals") $reductionPipeline`;
   print ("GenerateTangentSpaceNormals: " + $generateTangentSpaceNormals + "\n");
}

// save the generated Pipeline object to file for later use
if($bMaterialBake)
{
   $bResult = `SimplygonPipeline -s "D:/Pipelines/Reduction_With_Baking.json" $reductionPipeline`;
}
else
{
   $bResult = `SimplygonPipeline -s "D:/Pipelines/Reduction.json" $reductionPipeline`;
}

// clear all pipelines
SimplygonPipeline -cl;
python
# create a ReductionPipeline object
reductionPipeline = cmds.SimplygonPipeline(c = 'ReductionPipeline')

# set DefaultTangentCalculatorType to OrthonormalRightHanded (0)
bResult = cmds.SimplygonPipeline(reductionPipeline, ss = 'GlobalSettings/DefaultTangentCalculatorType', v = 0)
defaultTangentCalculatorType = cmds.SimplygonPipeline(reductionPipeline, gs = 'GlobalSettings/DefaultTangentCalculatorType')
print ('DefaultTangentCalculatorType: ' + str(defaultTangentCalculatorType) + '\n')

# set the triangle ratio to 50%
bResult = cmds.SimplygonPipeline(reductionPipeline, ss = 'ReductionProcessor/ReductionSettings/ReductionTargetTriangleRatio', v = 0.5)
reductionTargetTriangleRatio = cmds.SimplygonPipeline(reductionPipeline, gs = 'ReductionProcessor/ReductionSettings/ReductionTargetTriangleRatio')
print ('ReductionTargetTriangleRatio: ' + str(reductionTargetTriangleRatio) + '\n')

# set the reduction target to ReductionTargetTriangleRatio
bResult = cmds.SimplygonPipeline(reductionPipeline, ss = 'ReductionProcessor/ReductionSettings/ReductionTargetTriangleRatioEnabled', v = True)
reductionTargetTriangleRatioEnabled = cmds.SimplygonPipeline(reductionPipeline, gs = 'ReductionProcessor/ReductionSettings/ReductionTargetTriangleRatioEnabled')
print ('ReductionTargetTriangleRatioEnabled: ' + str(reductionTargetTriangleRatioEnabled) + '\n')

# disable triangle count reduction target
bResult = cmds.SimplygonPipeline(reductionPipeline, ss = 'ReductionProcessor/ReductionSettings/ReductionTargetTriangleCountEnabled', v = False)
reductionTargetTriangleCountEnabled = cmds.SimplygonPipeline(reductionPipeline, gs = 'ReductionProcessor/ReductionSettings/ReductionTargetTriangleCountEnabled')
print ('ReductionTargetTriangleCountEnabled: ' + str(reductionTargetTriangleCountEnabled) + '\n')

# disable max deviation reduction target
bResult = cmds.SimplygonPipeline(reductionPipeline, ss = 'ReductionProcessor/ReductionSettings/ReductionTargetMaxDeviationEnabled', v = False)
reductionTargetMaxDeviationEnabled = cmds.SimplygonPipeline(reductionPipeline, gs = 'ReductionProcessor/ReductionSettings/ReductionTargetMaxDeviationEnabled')
print ('ReductionTargetMaxDeviationEnabled: ' + str(reductionTargetMaxDeviationEnabled) + '\n')

# disable onscreensize reduction target
bResult = cmds.SimplygonPipeline(reductionPipeline, ss = 'ReductionProcessor/ReductionSettings/ReductionTargetOnScreenSizeEnabled', v = False)
reductionTargetOnScreenSizeEnabled = cmds.SimplygonPipeline(reductionPipeline, gs = 'ReductionProcessor/ReductionSettings/ReductionTargetOnScreenSizeEnabled')
print ('ReductionTargetOnScreenSizeEnabled: ' + str(reductionTargetOnScreenSizeEnabled) + '\n')

# 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!

# set bMaterialBake to True to enable material baking,
# if material baking is enabled Simplygon will generate
# a new material (with textures) shared by all the optimized meshes.
bMaterialBake = True
if bMaterialBake:
    # enable material baking
    # mapping image is required for material baking
    bResult = cmds.SimplygonPipeline(reductionPipeline, ss = 'ReductionProcessor/MappingImageSettings/GenerateMappingImage', v = True)
    generateMappingImage = cmds.SimplygonPipeline(reductionPipeline, gs = 'ReductionProcessor/MappingImageSettings/GenerateMappingImage')
    print ('GenerateMappingImage: ' + str(generateMappingImage) + '\n')

    # in this case we want to generate texture coordinates (UVs)
    bResult = cmds.SimplygonPipeline(reductionPipeline, ss = 'ReductionProcessor/MappingImageSettings/GenerateTexCoords', v = True)
    generateTexCoords = cmds.SimplygonPipeline(reductionPipeline, gs = 'ReductionProcessor/MappingImageSettings/GenerateTexCoords')
    print ('GenerateTexCoords: ' + str(generateTexCoords) + '\n')

    # the name of the resulting texture coordinate field
    bResult = cmds.SimplygonPipeline(reductionPipeline, ss = 'ReductionProcessor/MappingImageSettings/TexCoordName', v = 'MaterialLOD')
    texCoordLevel = cmds.SimplygonPipeline(reductionPipeline, gs = 'ReductionProcessor/MappingImageSettings/TexCoordName')
    print ('TexCoordName: ' + texCoordLevel + '\n')

    # width of the baked textures
    bResult = cmds.SimplygonPipeline(reductionPipeline, ss = 'ReductionProcessor/MappingImageSettings/Output0/TextureWidth', v = 512)
    textureWidth = cmds.SimplygonPipeline(reductionPipeline, gs = 'ReductionProcessor/MappingImageSettings/Output0/TextureWidth')
    print ('TextureWidth: ' + str(textureWidth) + '\n')

    # height of the baked textures
    bResult = cmds.SimplygonPipeline(reductionPipeline, ss = 'ReductionProcessor/MappingImageSettings/Output0/TextureHeight', v = 512)
    textureHeight = cmds.SimplygonPipeline(reductionPipeline, gs = 'ReductionProcessor/MappingImageSettings/Output0/TextureHeight')
    print ('TextureHeight: ' + str(textureHeight) + '\n')

    # add material casters (ambientColor, color, specularColor and normalCamera)
    casterIndex = cmds.SimplygonPipeline(reductionPipeline, amc =  'ColorCaster')
    bResult = cmds.SimplygonPipeline(reductionPipeline, ss = ('MaterialCaster/' + str(casterIndex) + '/ColorCasterSettings/MaterialChannel'), v = 'ambientColor')
    colorCaster0 = cmds.SimplygonPipeline(reductionPipeline, gs = ('MaterialCaster/' + str(casterIndex) + '/ColorCasterSettings/MaterialChannel'))
    print ('ColorCaster0: ' + colorCaster0 + '\n')

    casterIndex = cmds.SimplygonPipeline(reductionPipeline, amc =  'ColorCaster')
    bResult = cmds.SimplygonPipeline(reductionPipeline, ss = ('MaterialCaster/' + str(casterIndex) + '/ColorCasterSettings/MaterialChannel'), v = 'color')
    colorCaster1 = cmds.SimplygonPipeline(reductionPipeline, gs = ('MaterialCaster/' + str(casterIndex) + '/ColorCasterSettings/MaterialChannel'))
    print ('ColorCaster1: ' + colorCaster1 + '\n')

    casterIndex = cmds.SimplygonPipeline(reductionPipeline, amc =  'ColorCaster')
    bResult = cmds.SimplygonPipeline(reductionPipeline, ss = ('MaterialCaster/' + str(casterIndex) + '/ColorCasterSettings/MaterialChannel'), v = 'specularColor')
    colorCaster2 = cmds.SimplygonPipeline(reductionPipeline, gs = ('MaterialCaster/' + str(casterIndex) + '/ColorCasterSettings/MaterialChannel'))
    print ('ColorCaster2: ' + colorCaster2 + '\n')

    # note: normal caster for normals!
    casterIndex = cmds.SimplygonPipeline(reductionPipeline, amc =  'NormalCaster')
    bResult = cmds.SimplygonPipeline(reductionPipeline, ss = ('MaterialCaster/' + str(casterIndex) + '/NormalCasterSettings/MaterialChannel'), v = 'normalCamera')
    normalCaster3 = cmds.SimplygonPipeline(reductionPipeline, gs = ('MaterialCaster/' + str(casterIndex) + '/NormalCasterSettings/MaterialChannel'))
    print ('NormalCaster3: ' + normalCaster3 + '\n')

    # set the correct tangent space type,
    # in this example we use tangent space normals
    bResult = cmds.SimplygonPipeline(reductionPipeline, ss = ('MaterialCaster/' + str(casterIndex) + '/NormalCasterSettings/GenerateTangentSpaceNormals'), v = True)
    generateTangentSpaceNormals = cmds.SimplygonPipeline(reductionPipeline, gs = ('MaterialCaster/' + str(casterIndex) + '/NormalCasterSettings/GenerateTangentSpaceNormals'))
    print ('GenerateTangentSpaceNormals: ' + str(generateTangentSpaceNormals) + '\n')

# save the generated Pipeline object to file for later use
if bMaterialBake:
    bResult = cmds.SimplygonPipeline(reductionPipeline, s = 'D:/Pipelines/Reduction_With_Baking.json')
else:
    bResult = cmds.SimplygonPipeline(reductionPipeline, s = 'D:/Pipelines/Reduction.json')

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

Next steps

Get to know how to use the Reduction Pipeline: