# Simple Aggregation pipeline - Hollow shell
This example shows how to use the AggregationPipeline
to combine objects and remove interiors using the geometry culling functionality. Keep in mind that the selection set names listed in this example must exist in Maya for the optimization to work.
Hollow shell functionality can also be achieved by using the AggregationProcessor.
-- create a Aggregation Pipeline 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")
-- enable geometry culling (hollow shell)
bResult = sgsdk_SetSetting aggregationPipeline "AggregationProcessor/AggregationSettings/EnableGeometryCulling" true
enableGeometryCulling = sgsdk_GetSetting aggregationPipeline "AggregationProcessor/AggregationSettings/EnableGeometryCulling"
print ("EnableGeometryCulling: " + enableGeometryCulling as string + "\n")
-- geometry culling precision (hollow shell)
bResult = sgsdk_SetSetting aggregationPipeline "AggregationProcessor/AggregationSettings/GeometryCullingPrecision" 0.2
geometryCullingPrecision = sgsdk_GetSetting aggregationPipeline "AggregationProcessor/AggregationSettings/GeometryCullingPrecision"
print ("GeometryCullingPrecision: " + geometryCullingPrecision as string + "\n")
-- enable geometry clipping (hollow shell)
bResult = sgsdk_SetSetting aggregationPipeline "AggregationProcessor/GeometryCullingSettings/UseClippingGeometry" true
useClippingGeometry = sgsdk_GetSetting aggregationPipeline "AggregationProcessor/GeometryCullingSettings/UseClippingGeometry"
print ("UseClippingGeometry: " + useClippingGeometry as string + "\n")
-- clipping selection set (hollow shell)
bResult = sgsdk_SetSetting aggregationPipeline "AggregationProcessor/GeometryCullingSettings/ClippingGeometrySelectionSetName" "clippingSelectionSet"
clippingGeometrySelectionSetName = sgsdk_GetSetting aggregationPipeline "AggregationProcessor/GeometryCullingSettings/ClippingGeometrySelectionSetName"
print ("ClippingGeometrySelectionSetName: " + clippingGeometrySelectionSetName as string + "\n")
-- process selection sets
bResult = sgsdk_SetSetting aggregationPipeline "AggregationProcessor/AggregationSettings/ProcessSelectionSetName" "processSelectionSet"
processSelectionSetName = sgsdk_GetSetting aggregationPipeline "AggregationProcessor/AggregationSettings/ProcessSelectionSetName"
print ("ProcessSelectionSetName: " + processSelectionSetName 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)
bCasterAdded = sgsdk_AddMaterialCaster aggregationPipeline "ColorCaster"
bResult = sgsdk_SetSetting aggregationPipeline "MaterialCaster/0/ColorCasterSettings/MaterialChannel" "Ambient_Color"
colorCaster0 = sgsdk_GetSetting aggregationPipeline "MaterialCaster/0/ColorCasterSettings/MaterialChannel"
print ("ColorCaster0: " + colorCaster0 as string + "\n")
bCasterAdded = sgsdk_AddMaterialCaster aggregationPipeline "ColorCaster"
bResult = sgsdk_SetSetting aggregationPipeline "MaterialCaster/1/ColorCasterSettings/MaterialChannel" "Diffuse_Color"
colorCaster1 = sgsdk_GetSetting aggregationPipeline "MaterialCaster/1/ColorCasterSettings/MaterialChannel"
print ("ColorCaster1: " + colorCaster1 as string + "\n")
bCasterAdded = sgsdk_AddMaterialCaster aggregationPipeline "ColorCaster"
bResult = sgsdk_SetSetting aggregationPipeline "MaterialCaster/2/ColorCasterSettings/MaterialChannel" "Specular_Color"
colorCaster2 = sgsdk_GetSetting aggregationPipeline "MaterialCaster/2/ColorCasterSettings/MaterialChannel"
print ("ColorCaster2: " + colorCaster2 as string + "\n")
-- note: normal caster for normals!
bCasterAdded = sgsdk_AddMaterialCaster aggregationPipeline "NormalCaster"
bResult = sgsdk_SetSetting aggregationPipeline "MaterialCaster/3/NormalCasterSettings/MaterialChannel" "Bump"
normalCaster3 = sgsdk_GetSetting aggregationPipeline "MaterialCaster/3/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/3/NormalCasterSettings/GenerateTangentSpaceNormals" true
generateTangentSpaceNormals = sgsdk_GetSetting aggregationPipeline "MaterialCaster/3/NormalCasterSettings/GenerateTangentSpaceNormals"
print ("GenerateTangentSpaceNormals: " + generateTangentSpaceNormals as string + "\n")
)
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 Aggregation Pipeline object
aggregationPipeline = rt.sgsdk_CreatePipeline('AggregationPipeline')
# set DefaultTangentCalculatorType to Autodesk3dsMax (1)
bResult = rt.sgsdk_SetSetting(aggregationPipeline, 'GlobalSettings/DefaultTangentCalculatorType', 0)
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')
# enable geometry culling (hollow shell)
bResult = rt.sgsdk_SetSetting(aggregationPipeline, 'AggregationProcessor/AggregationSettings/EnableGeometryCulling', True)
enableGeometryCulling = rt.sgsdk_GetSetting(aggregationPipeline, 'AggregationProcessor/AggregationSettings/EnableGeometryCulling')
print ('EnableGeometryCulling: ' + str(enableGeometryCulling) + '\n')
# geometry culling precision (hollow shell)
bResult = rt.sgsdk_SetSetting(aggregationPipeline, 'AggregationProcessor/AggregationSettings/GeometryCullingPrecision', 0.2)
geometryCullingPrecision = rt.sgsdk_GetSetting(aggregationPipeline, 'AggregationProcessor/AggregationSettings/GeometryCullingPrecision')
print ('GeometryCullingPrecision: ' + str(geometryCullingPrecision) + '\n')
# enable geometry clipping (hollow shell)
bResult = rt.sgsdk_SetSetting(aggregationPipeline, 'AggregationProcessor/GeometryCullingSettings/UseClippingGeometry', True)
useClippingGeometry = rt.sgsdk_GetSetting(aggregationPipeline, 'AggregationProcessor/GeometryCullingSettings/UseClippingGeometry')
print ('UseClippingGeometry: ' + str(useClippingGeometry) + '\n')
# clipping selection set (hollow shell)
bResult = rt.sgsdk_SetSetting(aggregationPipeline, 'AggregationProcessor/GeometryCullingSettings/ClippingGeometrySelectionSetName', 'clippingSelectionSet')
clippingGeometrySelectionSetName = rt.sgsdk_GetSetting(aggregationPipeline, 'AggregationProcessor/GeometryCullingSettings/ClippingGeometrySelectionSetName')
print ('ClippingGeometrySelectionSetName: ' + clippingGeometrySelectionSetName + '\n')
# process selection sets
bResult = rt.sgsdk_SetSetting(aggregationPipeline, 'AggregationProcessor/AggregationSettings/ProcessSelectionSetName', 'processSelectionSet')
processSelectionSetName = rt.sgsdk_GetSetting(aggregationPipeline, 'AggregationProcessor/AggregationSettings/ProcessSelectionSetName')
print ('ProcessSelectionSetName: ' + processSelectionSetName + '\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)
bCasterAdded = rt.sgsdk_AddMaterialCaster(aggregationPipeline, 'ColorCaster')
bResult = rt.sgsdk_SetSetting(aggregationPipeline, 'MaterialCaster/0/ColorCasterSettings/MaterialChannel', 'Ambient_Color')
colorCaster0 = rt.sgsdk_GetSetting(aggregationPipeline, 'MaterialCaster/0/ColorCasterSettings/MaterialChannel')
print ('ColorCaster0: ' + colorCaster0 + '\n')
bCasterAdded = rt.sgsdk_AddMaterialCaster(aggregationPipeline, 'ColorCaster')
bResult = rt.sgsdk_SetSetting(aggregationPipeline, 'MaterialCaster/1/ColorCasterSettings/MaterialChannel', 'Diffuse_Color')
colorCaster1 = rt.sgsdk_GetSetting(aggregationPipeline, 'MaterialCaster/1/ColorCasterSettings/MaterialChannel')
print ('ColorCaster1: ' + colorCaster1 + '\n')
bCasterAdded = rt.sgsdk_AddMaterialCaster(aggregationPipeline, 'ColorCaster')
bResult = rt.sgsdk_SetSetting(aggregationPipeline, 'MaterialCaster/2/ColorCasterSettings/MaterialChannel', 'Specular_Color')
colorCaster2 = rt.sgsdk_GetSetting(aggregationPipeline, 'MaterialCaster/2/ColorCasterSettings/MaterialChannel')
print ('ColorCaster2: ' + colorCaster2 + '\n')
# note: normal caster for normals!
bCasterAdded = rt.sgsdk_AddMaterialCaster(aggregationPipeline, 'NormalCaster')
bResult = rt.sgsdk_SetSetting(aggregationPipeline, 'MaterialCaster/3/NormalCasterSettings/MaterialChannel', 'Bump')
normalCaster3 = rt.sgsdk_GetSetting(aggregationPipeline, 'MaterialCaster/3/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/3/NormalCasterSettings/GenerateTangentSpaceNormals', True)
generateTangentSpaceNormals = rt.sgsdk_GetSetting(aggregationPipeline, 'MaterialCaster/3/NormalCasterSettings/GenerateTangentSpaceNormals')
print ('GenerateTangentSpaceNormals: ' + str(generateTangentSpaceNormals) + '\n')
if bMaterialBake:
bResult = rt.sgsdk_SavePipeline(aggregationPipeline, 'D:/Pipelines/Aggregation_With_Baking_HollowShell.json')
else:
bResult = rt.sgsdk_SavePipeline(aggregationPipeline, 'D:/Pipelines/Aggregation_HollowShell.json')
# clear all pipelines
rt.sgsdk_ClearPipelines()
# Next steps
Get to know how to use the Aggregation Pipeline: