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