# Simple Reduction pipeline
This example shows how to create a new ReductionPipeline
and how to set basic parameters for reduction and material baking.
// create a Reduction Pipeline 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/ReductionTargetTriangleRatioEnabled" $reductionPipeline`;
print ("ReductionTargetTriangleCountEnabled: " + $reductionTargetTriangleCountEnabled + "\n");
// disable max deviation reduction target
$bResult = `SimplygonPipeline -ss "ReductionProcessor/ReductionSettings/ReductionTargetMaxDeviationEnabled" -v false $reductionPipeline`;
$reductionTargetMaxDeviationEnabled = `SimplygonPipeline -gs "ReductionProcessor/ReductionSettings/ReductionTargetTriangleRatioEnabled" $reductionPipeline`;
print ("ReductionTargetMaxDeviationEnabled: " + $reductionTargetMaxDeviationEnabled + "\n");
// disable onscreensize reduction target
$bResult = `SimplygonPipeline -ss "ReductionProcessor/ReductionSettings/ReductionTargetOnScreenSizeEnabled" -v false $reductionPipeline`;
$reductionTargetOnScreenSizeEnabled = `SimplygonPipeline -gs "ReductionProcessor/ReductionSettings/ReductionTargetTriangleRatioEnabled" $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)
$bCasterAdded = `SimplygonPipeline -amc "ColorCaster" $reductionPipeline`;
$bResult = `SimplygonPipeline -ss "MaterialCaster/0/ColorCasterSettings/MaterialChannel" -v "ambientColor" $reductionPipeline`;
$colorCaster0 = `SimplygonPipeline -gs "MaterialCaster/0/ColorCasterSettings/MaterialChannel" $reductionPipeline`;
print ("ColorCaster0: " + $colorCaster0 + "\n");
$bCasterAdded = `SimplygonPipeline -amc "ColorCaster" $reductionPipeline`;
$bResult = `SimplygonPipeline -ss "MaterialCaster/1/ColorCasterSettings/MaterialChannel" -v "color" $reductionPipeline`;
$colorCaster1 = `SimplygonPipeline -gs "MaterialCaster/1/ColorCasterSettings/MaterialChannel" $reductionPipeline`;
print ("ColorCaster1: " + $colorCaster1 + "\n");
$bCasterAdded = `SimplygonPipeline -amc "ColorCaster" $reductionPipeline`;
$bResult = `SimplygonPipeline -ss "MaterialCaster/2/ColorCasterSettings/MaterialChannel" -v "specularColor" $reductionPipeline`;
$colorCaster2 = `SimplygonPipeline -gs "MaterialCaster/2/ColorCasterSettings/MaterialChannel" $reductionPipeline`;
print ("ColorCaster2: " + $colorCaster2 + "\n");
// note: normal caster for normals!
$bCasterAdded = `SimplygonPipeline -amc "NormalCaster" $reductionPipeline`;
$bResult = `SimplygonPipeline -ss "MaterialCaster/3/NormalCasterSettings/MaterialChannel" -v "normalCamera" $reductionPipeline`;
$normalCaster3 = `SimplygonPipeline -gs "MaterialCaster/3/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/3/NormalCasterSettings/GenerateTangentSpaceNormals" -v true $reductionPipeline`;
$generateTangentSpaceNormals = `SimplygonPipeline -gs "MaterialCaster/3/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;
# create a Reduction Pipeline 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: ' + 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: ' + 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: ' + reductionTargetTriangleRatioEnabled + '\n')
# disable triangle count reduction target
bResult = cmds.SimplygonPipeline(reductionPipeline, ss = 'ReductionProcessor/ReductionSettings/ReductionTargetTriangleCountEnabled', v = False)
reductionTargetTriangleCountEnabled = cmds.SimplygonPipeline(reductionPipeline, gs = 'ReductionProcessor/ReductionSettings/ReductionTargetTriangleRatioEnabled')
print ('ReductionTargetTriangleCountEnabled: ' + reductionTargetTriangleCountEnabled + '\n')
# disable max deviation reduction target
bResult = cmds.SimplygonPipeline(reductionPipeline, ss = 'ReductionProcessor/ReductionSettings/ReductionTargetMaxDeviationEnabled', v = False)
reductionTargetMaxDeviationEnabled = cmds.SimplygonPipeline(reductionPipeline, gs = 'ReductionProcessor/ReductionSettings/ReductionTargetTriangleRatioEnabled')
print ('ReductionTargetMaxDeviationEnabled: ' + reductionTargetMaxDeviationEnabled + '\n')
# disable onscreensize reduction target
bResult = cmds.SimplygonPipeline(reductionPipeline, ss = 'ReductionProcessor/ReductionSettings/ReductionTargetOnScreenSizeEnabled', v = False)
reductionTargetOnScreenSizeEnabled = cmds.SimplygonPipeline(reductionPipeline, gs = 'ReductionProcessor/ReductionSettings/ReductionTargetTriangleRatioEnabled')
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 = cmds.SimplygonPipeline(reductionPipeline, ss = 'ReductionProcessor/MappingImageSettings/GenerateMappingImage', v = True)
generateMappingImage = cmds.SimplygonPipeline(reductionPipeline, gs = 'ReductionProcessor/MappingImageSettings/GenerateMappingImage')
print ('GenerateMappingImage: ' + 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: ' + 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: ' + 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: ' + textureHeight + '\n')
# add material casters (ambientColor, color, specularColor and normalCamera)
bCasterAdded = cmds.SimplygonPipeline(reductionPipeline, amc = 'ColorCaster')
bResult = cmds.SimplygonPipeline(reductionPipeline, ss = 'MaterialCaster/0/ColorCasterSettings/MaterialChannel', v = 'ambientColor')
colorCaster0 = cmds.SimplygonPipeline(reductionPipeline, gs = 'MaterialCaster/0/ColorCasterSettings/MaterialChannel')
print ('ColorCaster0: ' + colorCaster0 + '\n')
bCasterAdded = cmds.SimplygonPipeline(reductionPipeline, amc = 'ColorCaster')
bResult = cmds.SimplygonPipeline(reductionPipeline, ss = 'MaterialCaster/1/ColorCasterSettings/MaterialChannel', v = 'color')
colorCaster1 = cmds.SimplygonPipeline(reductionPipeline, gs = 'MaterialCaster/1/ColorCasterSettings/MaterialChannel')
print ('ColorCaster1: ' + colorCaster1 + '\n')
bCasterAdded = cmds.SimplygonPipeline(reductionPipeline, amc = 'ColorCaster')
bResult = cmds.SimplygonPipeline(reductionPipeline, ss = 'MaterialCaster/2/ColorCasterSettings/MaterialChannel', v = 'specularColor')
colorCaster2 = cmds.SimplygonPipeline(reductionPipeline, gs = 'MaterialCaster/2/ColorCasterSettings/MaterialChannel')
print ('ColorCaster2: ' + colorCaster2 + '\n')
# note: normal caster for normals!
bCasterAdded = cmds.SimplygonPipeline(reductionPipeline, amc = 'NormalCaster')
bResult = cmds.SimplygonPipeline(reductionPipeline, ss = 'MaterialCaster/3/NormalCasterSettings/MaterialChannel', v = 'normalCamera')
normalCaster3 = cmds.SimplygonPipeline(reductionPipeline, gs = 'MaterialCaster/3/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/3/NormalCasterSettings/GenerateTangentSpaceNormals', v = True)
generateTangentSpaceNormals = cmds.SimplygonPipeline(reductionPipeline, gs = 'MaterialCaster/3/NormalCasterSettings/GenerateTangentSpaceNormals')
print ('GenerateTangentSpaceNormals: ' + 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: