# 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 = sgsdk_CreatePipeline "AggregationPipeline"
-- set DefaultTangentCalculatorType to Autodesk3dsMax (1)
bResult = sgsdk_SetSetting aggregationPipeline "GlobalSettings/DefaultTangentCalculatorType" 1
defaultTangentCalculatorType = sgsdk_GetSetting aggregationPipeline "GlobalSettings/DefaultTangentCalculatorType"
print ("DefaultTangentCalculatorType: " + defaultTangentCalculatorType as string + "\n")
-- merge geometries
bResult = sgsdk_SetSetting aggregationPipeline "AggregationProcessor/AggregationSettings/MergeGeometries" true
mergeGeometries = sgsdk_GetSetting aggregationPipeline "AggregationProcessor/AggregationSettings/MergeGeometries"
print ("MergeGeometries: " + mergeGeometries as string + "\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 do
(
-- enable material baking
-- mapping image is required for material baking
bResult = sgsdk_SetSetting aggregationPipeline "AggregationProcessor/MappingImageSettings/GenerateMappingImage" true
generateMappingImage = sgsdk_GetSetting aggregationPipeline "AggregationProcessor/MappingImageSettings/GenerateMappingImage"
print ("GenerateMappingImage: " + generateMappingImage as string + "\n")
-- in this case we want to generate texture coordinates (UVs)
bResult = sgsdk_SetSetting aggregationPipeline "AggregationProcessor/MappingImageSettings/GenerateTexCoords" true
generateTexCoords = sgsdk_GetSetting aggregationPipeline "AggregationProcessor/MappingImageSettings/GenerateTexCoords"
print ("GenerateTexCoords: " + generateTexCoords as string + "\n")
-- the name of the resulting texture coordinate field
bResult = sgsdk_SetSetting aggregationPipeline "AggregationProcessor/MappingImageSettings/TexCoordName" "MaterialLOD"
texCoordLevel = sgsdk_GetSetting aggregationPipeline "AggregationProcessor/MappingImageSettings/TexCoordName"
print ("TexCoordName: " + texCoordLevel as string + "\n")
-- width of the baked textures
bResult = sgsdk_SetSetting aggregationPipeline "AggregationProcessor/MappingImageSettings/Output0/TextureWidth" 512
textureWidth = sgsdk_GetSetting aggregationPipeline "AggregationProcessor/MappingImageSettings/Output0/TextureWidth"
print ("TextureWidth: " + textureWidth as string + "\n")
-- height of the baked textures
bResult = sgsdk_SetSetting aggregationPipeline "AggregationProcessor/MappingImageSettings/Output0/TextureHeight" 512
textureHeight = sgsdk_GetSetting aggregationPipeline "AggregationProcessor/MappingImageSettings/Output0/TextureHeight"
print ("TextureHeight: " + textureHeight as string + "\n")
-- add material casters (Ambient_Color, Diffuse_Color, Specular_Color and Bump)
casterIndex = sgsdk_AddMaterialCaster aggregationPipeline "ColorCaster"
bResult = sgsdk_SetSetting aggregationPipeline ("MaterialCaster/" + casterindex + "/ColorCasterSettings/MaterialChannel") "Ambient_Color"
colorCaster0 = sgsdk_GetSetting aggregationPipeline ("MaterialCaster/" + casterindex + "/ColorCasterSettings/MaterialChannel")
print ("ColorCaster0: " + colorCaster0 as string + "\n")
casterIndex = sgsdk_AddMaterialCaster aggregationPipeline "ColorCaster"
bResult = sgsdk_SetSetting aggregationPipeline ("MaterialCaster/" + casterindex + "/ColorCasterSettings/MaterialChannel") "Diffuse_Color"
colorCaster1 = sgsdk_GetSetting aggregationPipeline ("MaterialCaster/" + casterindex + "/ColorCasterSettings/MaterialChannel")
print ("ColorCaster1: " + colorCaster1 as string + "\n")
casterIndex = sgsdk_AddMaterialCaster aggregationPipeline "ColorCaster"
bResult = sgsdk_SetSetting aggregationPipeline ("MaterialCaster/" + casterindex + "/ColorCasterSettings/MaterialChannel") "Specular_Color"
colorCaster2 = sgsdk_GetSetting aggregationPipeline ("MaterialCaster/" + casterindex + "/ColorCasterSettings/MaterialChannel")
print ("ColorCaster2: " + colorCaster2 as string + "\n")
-- note: normal caster for normals!
casterIndex = sgsdk_AddMaterialCaster aggregationPipeline "NormalCaster"
bResult = sgsdk_SetSetting aggregationPipeline ("MaterialCaster/" + casterindex + "/NormalCasterSettings/MaterialChannel") "Bump"
normalCaster3 = sgsdk_GetSetting aggregationPipeline ("MaterialCaster/" + casterindex + "/NormalCasterSettings/MaterialChannel")
print ("NormalCaster3: " + normalCaster3 as string + "\n")
-- set the correct tangent space type,
-- in this example we use tangent space normals
bResult = sgsdk_SetSetting aggregationPipeline ("MaterialCaster/" + casterindex + "/NormalCasterSettings/GenerateTangentSpaceNormals") true
generateTangentSpaceNormals = sgsdk_GetSetting aggregationPipeline ("MaterialCaster/" + casterindex + "/NormalCasterSettings/GenerateTangentSpaceNormals")
print ("GenerateTangentSpaceNormals: " + generateTangentSpaceNormals as string + "\n")
)
-- save the generated Pipeline object to file for later use
if bMaterialBake then
(
bResult = sgsdk_SavePipeline aggregationPipeline "D:/Pipelines/Aggregation_With_Baking.json"
)
else
(
bResult = sgsdk_SavePipeline aggregationPipeline "D:/Pipelines/Aggregation.json"
)
-- clear all pipelines
sgsdk_ClearPipelines()
from pymxs import runtime as rt
# create a AggregationPipeline object
aggregationPipeline = rt.sgsdk_CreatePipeline('AggregationPipeline')
# set DefaultTangentCalculatorType to Autodesk3dsMax (1)
bResult = rt.sgsdk_SetSetting(aggregationPipeline, 'GlobalSettings/DefaultTangentCalculatorType', 1)
defaultTangentCalculatorType = rt.sgsdk_GetSetting(aggregationPipeline, 'GlobalSettings/DefaultTangentCalculatorType')
print ('DefaultTangentCalculatorType: ' + str(defaultTangentCalculatorType) + '\n')
# merge geometries
bResult = rt.sgsdk_SetSetting(aggregationPipeline, 'AggregationProcessor/AggregationSettings/MergeGeometries', True)
mergeGeometries = rt.sgsdk_GetSetting(aggregationPipeline, '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 = rt.sgsdk_SetSetting(aggregationPipeline, 'AggregationProcessor/MappingImageSettings/GenerateMappingImage', True)
generateMappingImage = rt.sgsdk_GetSetting(aggregationPipeline, 'AggregationProcessor/MappingImageSettings/GenerateMappingImage')
print ('GenerateMappingImage: ' + str(generateMappingImage) + '\n')
# in this case we want to generate texture coordinates (UVs)
bResult = rt.sgsdk_SetSetting(aggregationPipeline, 'AggregationProcessor/MappingImageSettings/GenerateTexCoords', True)
generateTexCoords = rt.sgsdk_GetSetting(aggregationPipeline, 'AggregationProcessor/MappingImageSettings/GenerateTexCoords')
print ('GenerateTexCoords: ' + str(generateTexCoords) + '\n')
# the name of the resulting texture coordinate field
bResult = rt.sgsdk_SetSetting(aggregationPipeline, 'AggregationProcessor/MappingImageSettings/TexCoordName', 'MaterialLOD')
texCoordLevel = rt.sgsdk_GetSetting(aggregationPipeline, 'AggregationProcessor/MappingImageSettings/TexCoordName')
print ('TexCoordName: ' + texCoordLevel + '\n')
# width of the baked textures
bResult = rt.sgsdk_SetSetting(aggregationPipeline, 'AggregationProcessor/MappingImageSettings/Output0/TextureWidth', 512)
textureWidth = rt.sgsdk_GetSetting(aggregationPipeline, 'AggregationProcessor/MappingImageSettings/Output0/TextureWidth')
print ('TextureWidth: ' + str(textureWidth) + '\n')
# height of the baked textures
bResult = rt.sgsdk_SetSetting(aggregationPipeline, 'AggregationProcessor/MappingImageSettings/Output0/TextureHeight', 512)
textureHeight = rt.sgsdk_GetSetting(aggregationPipeline, 'AggregationProcessor/MappingImageSettings/Output0/TextureHeight')
print ('TextureHeight: ' + str(textureHeight) + '\n')
# add material casters (Ambient_Color, Diffuse_Color, Specular_Color and Bump)
casterIndex = rt.sgsdk_AddMaterialCaster(aggregationPipeline, 'ColorCaster')
bResult = rt.sgsdk_SetSetting(aggregationPipeline, ('MaterialCaster/' + str(casterIndex) + '/ColorCasterSettings/MaterialChannel'), 'Ambient_Color')
colorCaster0 = rt.sgsdk_GetSetting(aggregationPipeline, ('MaterialCaster/' + str(casterIndex) + '/ColorCasterSettings/MaterialChannel'))
print ('ColorCaster0: ' + colorCaster0 + '\n')
casterIndex = rt.sgsdk_AddMaterialCaster(aggregationPipeline, 'ColorCaster')
bResult = rt.sgsdk_SetSetting(aggregationPipeline, ('MaterialCaster/' + str(casterIndex) + '/ColorCasterSettings/MaterialChannel'), 'Diffuse_Color')
colorCaster1 = rt.sgsdk_GetSetting(aggregationPipeline, ('MaterialCaster/' + str(casterIndex) + '/ColorCasterSettings/MaterialChannel'))
print ('ColorCaster1: ' + colorCaster1 + '\n')
casterIndex = rt.sgsdk_AddMaterialCaster(aggregationPipeline, 'ColorCaster')
bResult = rt.sgsdk_SetSetting(aggregationPipeline, ('MaterialCaster/' + str(casterIndex) + '/ColorCasterSettings/MaterialChannel'), 'Specular_Color')
colorCaster2 = rt.sgsdk_GetSetting(aggregationPipeline, ('MaterialCaster/' + str(casterIndex) + '/ColorCasterSettings/MaterialChannel'))
print ('ColorCaster2: ' + colorCaster2 + '\n')
# note: normal caster for normals!
casterIndex = rt.sgsdk_AddMaterialCaster(aggregationPipeline, 'NormalCaster')
bResult = rt.sgsdk_SetSetting(aggregationPipeline, ('MaterialCaster/' + str(casterIndex) + '/NormalCasterSettings/MaterialChannel'), 'Bump')
normalCaster3 = rt.sgsdk_GetSetting(aggregationPipeline, ('MaterialCaster/' + str(casterIndex) + '/NormalCasterSettings/MaterialChannel'))
print ('NormalCaster3: ' + normalCaster3 + '\n')
# set the correct tangent space type,
# in this example we use tangent space normals
bResult = rt.sgsdk_SetSetting(aggregationPipeline, ('MaterialCaster/' + str(casterIndex) + '/NormalCasterSettings/GenerateTangentSpaceNormals'), True)
generateTangentSpaceNormals = rt.sgsdk_GetSetting(aggregationPipeline, ('MaterialCaster/' + str(casterIndex) + '/NormalCasterSettings/GenerateTangentSpaceNormals'))
print ('GenerateTangentSpaceNormals: ' + str(generateTangentSpaceNormals) + '\n')
# save the generated Pipeline object to file for later use
if bMaterialBake:
bResult = rt.sgsdk_SavePipeline(aggregationPipeline, 'D:/Pipelines/Aggregation_With_Baking.json')
else:
bResult = rt.sgsdk_SavePipeline(aggregationPipeline, 'D:/Pipelines/Aggregation.json')
# clear all pipelines
rt.sgsdk_ClearPipelines()
# Next steps
Get to know how to use the Aggregation Pipeline: