# Simple Aggregation pipeline
This example shows how to create a new AggregationPipeline
and how to set basic parameters for Aggregation as well as material baking.
// create a AggregationPipeline object
$aggregationPipeline = `SimplygonPipeline -c "AggregationPipeline"`;
// set DefaultTangentCalculatorType to OrthonormalRightHanded (0)
$bResult = `SimplygonPipeline -ss "GlobalSettings/DefaultTangentCalculatorType" -v 0 $aggregationPipeline`;
$defaultTangentCalculatorType = `SimplygonPipeline -gs "GlobalSettings/DefaultTangentCalculatorType" $aggregationPipeline`;
print ("DefaultTangentCalculatorType: " + $defaultTangentCalculatorType + "\n");
// merge geometries
$bResult = `SimplygonPipeline -ss "AggregationProcessor/AggregationSettings/MergeGeometries" -v true $aggregationPipeline`;
$mergeGeometries = `SimplygonPipeline -gs "AggregationProcessor/AggregationSettings/MergeGeometries" $aggregationPipeline`;
print ("MergeGeometries: " + $mergeGeometries + "\n");
// more settings can be set for the Aggregation 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 == true)
{
// enable material baking
// mapping image is required for material baking
$bResult = `SimplygonPipeline -ss "AggregationProcessor/MappingImageSettings/GenerateMappingImage" -v true $aggregationPipeline`;
$generateMappingImage = `SimplygonPipeline -gs "AggregationProcessor/MappingImageSettings/GenerateMappingImage" $aggregationPipeline`;
print ("GenerateMappingImage: " + $generateMappingImage + "\n");
// in this case we want to generate texture coordinates (UVs)
$bResult = `SimplygonPipeline -ss "AggregationProcessor/MappingImageSettings/GenerateTexCoords" -v true $aggregationPipeline`;
$generateTexCoords = `SimplygonPipeline -gs "AggregationProcessor/MappingImageSettings/GenerateTexCoords" $aggregationPipeline`;
print ("GenerateTexCoords: " + $generateTexCoords + "\n");
// the name of the resulting texture coordinate field
$bResult = `SimplygonPipeline -ss "AggregationProcessor/MappingImageSettings/TexCoordName" -v "MaterialLOD" $aggregationPipeline`;
$texCoordLevel = `SimplygonPipeline -gs "AggregationProcessor/MappingImageSettings/TexCoordName" $aggregationPipeline`;
print ("TexCoordName: " + $texCoordLevel + "\n");
// width of the baked textures
$bResult = `SimplygonPipeline -ss "AggregationProcessor/MappingImageSettings/Output0/TextureWidth" -v 512 $aggregationPipeline`;
$textureWidth = `SimplygonPipeline -gs "AggregationProcessor/MappingImageSettings/Output0/TextureWidth" $aggregationPipeline`;
print ("TextureWidth: " + $textureWidth + "\n");
// height of the baked textures
$bResult = `SimplygonPipeline -ss "AggregationProcessor/MappingImageSettings/Output0/TextureHeight" -v 512 $aggregationPipeline`;
$textureHeight = `SimplygonPipeline -gs "AggregationProcessor/MappingImageSettings/Output0/TextureHeight" $aggregationPipeline`;
print ("TextureHeight: " + $textureHeight + "\n");
// add material casters (ambientColor, color, specularColor and normalCamera)
$casterIndex = `SimplygonPipeline -amc "ColorCaster" $aggregationPipeline`;
$bResult = `SimplygonPipeline -ss ("MaterialCaster/" + $casterIndex + "/ColorCasterSettings/MaterialChannel") -v "ambientColor" $aggregationPipeline`;
$colorCaster0 = `SimplygonPipeline -gs ("MaterialCaster/" + $casterIndex + "/ColorCasterSettings/MaterialChannel") $aggregationPipeline`;
print ("ColorCaster0: " + $colorCaster0 + "\n");
$casterIndex = `SimplygonPipeline -amc "ColorCaster" $aggregationPipeline`;
$bResult = `SimplygonPipeline -ss ("MaterialCaster/" + $casterIndex + "/ColorCasterSettings/MaterialChannel") -v "color" $aggregationPipeline`;
$colorCaster1 = `SimplygonPipeline -gs ("MaterialCaster/" + $casterIndex + "/ColorCasterSettings/MaterialChannel") $aggregationPipeline`;
print ("ColorCaster1: " + $colorCaster1 + "\n");
$casterIndex = `SimplygonPipeline -amc "ColorCaster" $aggregationPipeline`;
$bResult = `SimplygonPipeline -ss ("MaterialCaster/" + $casterIndex + "/ColorCasterSettings/MaterialChannel") -v "specularColor" $aggregationPipeline`;
$colorCaster2 = `SimplygonPipeline -gs ("MaterialCaster/" + $casterIndex + "/ColorCasterSettings/MaterialChannel") $aggregationPipeline`;
print ("ColorCaster2: " + $colorCaster2 + "\n");
// note: normal caster for normals!
$casterIndex = `SimplygonPipeline -amc "NormalCaster" $aggregationPipeline`;
$bResult = `SimplygonPipeline -ss ("MaterialCaster/" + $casterIndex + "/NormalCasterSettings/MaterialChannel") -v "normalCamera" $aggregationPipeline`;
$normalCaster3 = `SimplygonPipeline -gs ("MaterialCaster/" + $casterIndex + "/NormalCasterSettings/MaterialChannel") $aggregationPipeline`;
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 $aggregationPipeline`;
$generateTangentSpaceNormals = `SimplygonPipeline -gs ("MaterialCaster/" + $casterIndex + "/NormalCasterSettings/GenerateTangentSpaceNormals") $aggregationPipeline`;
print ("GenerateTangentSpaceNormals: " + $generateTangentSpaceNormals + "\n");
}
// save the generated Pipeline object to file for later use
if($bMaterialBake)
{
$bResult = `SimplygonPipeline -s "D:/Pipelines/Aggregation_With_Baking.json" $aggregationPipeline`;
}
else
{
$bResult = `SimplygonPipeline -s "D:/Pipelines/Aggregation.json" $aggregationPipeline`;
}
// clear all pipelines
SimplygonPipeline -cl;
import maya.cmds as cmds
# create a AggregationPipeline object
aggregationPipeline = cmds.SimplygonPipeline(c = 'AggregationPipeline')
# set DefaultTangentCalculatorType to OrthonormalRightHanded (0)
bResult = cmds.SimplygonPipeline(aggregationPipeline, ss = 'GlobalSettings/DefaultTangentCalculatorType', v = 0)
defaultTangentCalculatorType = cmds.SimplygonPipeline(aggregationPipeline, gs = 'GlobalSettings/DefaultTangentCalculatorType')
print ('DefaultTangentCalculatorType: ' + str(defaultTangentCalculatorType) + '\n')
# merge geometries
bResult = cmds.SimplygonPipeline(aggregationPipeline, ss = 'AggregationProcessor/AggregationSettings/MergeGeometries', v = True)
mergeGeometries = cmds.SimplygonPipeline(aggregationPipeline, gs = 'AggregationProcessor/AggregationSettings/MergeGeometries')
print ('MergeGeometries: ' + str(mergeGeometries) + '\n')
# more settings can be set for the Aggregation 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(aggregationPipeline, ss = 'AggregationProcessor/MappingImageSettings/GenerateMappingImage', v = True)
generateMappingImage = cmds.SimplygonPipeline(aggregationPipeline, gs = 'AggregationProcessor/MappingImageSettings/GenerateMappingImage')
print ('GenerateMappingImage: ' + str(generateMappingImage) + '\n')
# in this case we want to generate texture coordinates (UVs)
bResult = cmds.SimplygonPipeline(aggregationPipeline, ss = 'AggregationProcessor/MappingImageSettings/GenerateTexCoords', v = True)
generateTexCoords = cmds.SimplygonPipeline(aggregationPipeline, gs = 'AggregationProcessor/MappingImageSettings/GenerateTexCoords')
print ('GenerateTexCoords: ' + str(generateTexCoords) + '\n')
# the name of the resulting texture coordinate field
bResult = cmds.SimplygonPipeline(aggregationPipeline, ss = 'AggregationProcessor/MappingImageSettings/TexCoordName', v = 'MaterialLOD')
texCoordLevel = cmds.SimplygonPipeline(aggregationPipeline, gs = 'AggregationProcessor/MappingImageSettings/TexCoordName')
print ('TexCoordName: ' + texCoordLevel + '\n')
# width of the baked textures
bResult = cmds.SimplygonPipeline(aggregationPipeline, ss = 'AggregationProcessor/MappingImageSettings/Output0/TextureWidth', v = 512)
textureWidth = cmds.SimplygonPipeline(aggregationPipeline, gs = 'AggregationProcessor/MappingImageSettings/Output0/TextureWidth')
print ('TextureWidth: ' + str(textureWidth) + '\n')
# height of the baked textures
bResult = cmds.SimplygonPipeline(aggregationPipeline, ss = 'AggregationProcessor/MappingImageSettings/Output0/TextureHeight', v = 512)
textureHeight = cmds.SimplygonPipeline(aggregationPipeline, gs = 'AggregationProcessor/MappingImageSettings/Output0/TextureHeight')
print ('TextureHeight: ' + str(textureHeight) + '\n')
# add material casters (ambientColor, color, specularColor and normalCamera)
casterIndex = cmds.SimplygonPipeline(aggregationPipeline, amc = 'ColorCaster')
bResult = cmds.SimplygonPipeline(aggregationPipeline, ss = ('MaterialCaster/' + str(casterindex) '/ColorCasterSettings/MaterialChannel'), v = 'ambientColor')
colorCaster0 = cmds.SimplygonPipeline(aggregationPipeline, gs = ('MaterialCaster/' + str(casterindex) '/ColorCasterSettings/MaterialChannel'))
print ('ColorCaster0: ' + colorCaster0 + '\n')
casterIndex = cmds.SimplygonPipeline(aggregationPipeline, amc = 'ColorCaster')
bResult = cmds.SimplygonPipeline(aggregationPipeline, ss = ('MaterialCaster/' + str(casterindex) '/ColorCasterSettings/MaterialChannel'), v = 'color')
colorCaster1 = cmds.SimplygonPipeline(aggregationPipeline, gs = ('MaterialCaster/' + str(casterindex) '/ColorCasterSettings/MaterialChannel'))
print ('ColorCaster1: ' + colorCaster1 + '\n')
casterIndex = cmds.SimplygonPipeline(aggregationPipeline, amc = 'ColorCaster')
bResult = cmds.SimplygonPipeline(aggregationPipeline, ss = ('MaterialCaster/' + str(casterindex) '/ColorCasterSettings/MaterialChannel'), v = 'specularColor')
colorCaster2 = cmds.SimplygonPipeline(aggregationPipeline, gs = ('MaterialCaster/' + str(casterindex) '/ColorCasterSettings/MaterialChannel'))
print ('ColorCaster2: ' + colorCaster2 + '\n')
# note: normal caster for normals!
casterIndex = cmds.SimplygonPipeline(aggregationPipeline, amc = 'NormalCaster')
bResult = cmds.SimplygonPipeline(aggregationPipeline, ss = ('MaterialCaster/' + str(casterindex) '/NormalCasterSettings/MaterialChannel'), v = 'normalCamera')
normalCaster3 = cmds.SimplygonPipeline(aggregationPipeline, 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(aggregationPipeline, ss = ('MaterialCaster/' + str(casterindex) '/NormalCasterSettings/GenerateTangentSpaceNormals'), v = True)
generateTangentSpaceNormals = cmds.SimplygonPipeline(aggregationPipeline, 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(aggregationPipeline, s = 'D:/Pipelines/Aggregation_With_Baking.json')
else:
bResult = cmds.SimplygonPipeline(aggregationPipeline, s = 'D:/Pipelines/Aggregation.json')
# clear all pipelines
cmds.SimplygonPipeline(cl = True)
# Next steps
Get to know how to use the Aggregation Pipeline: