# Simple Remeshing pipeline (legacy remesher)
This example shows how to create a new RemeshingLegacyPipeline
and how to set basic parameters for Remeshing and material baking.
-- create a Remeshing Pipeline object
remeshingPipeline = sgsdk_CreatePipeline "RemeshingLegacyPipeline"
-- set DefaultTangentCalculatorType to Autodesk3dsMax (1)
bResult = sgsdk_SetSetting remeshingPipeline "GlobalSettings/DefaultTangentCalculatorType" 1
defaultTangentCalculatorType = sgsdk_GetSetting remeshingPipeline "GlobalSettings/DefaultTangentCalculatorType"
print ("DefaultTangentCalculatorType: " + defaultTangentCalculatorType as string + "\n")
-- set the OnScreenSize for the generated mesh
bResult = sgsdk_SetSetting remeshingPipeline "RemeshingLegacyProcessor/RemeshingLegacySettings/OnScreenSize" 300
onScreenSize = sgsdk_GetSetting remeshingPipeline "RemeshingLegacyProcessor/RemeshingLegacySettings/OnScreenSize"
print ("OnScreenSize: " + onScreenSize as string + "\n")
-- set the merge distance for the Remeshing processor,
-- a lower value might be preferred for skinned assets to avoid small gaps to merge,
-- or when you want to preserve details (at a cost of triangles).
bResult = sgsdk_SetSetting remeshingPipeline "RemeshingLegacyProcessor/RemeshingLegacySettings/MergeDistance" 0
mergeDistance = sgsdk_GetSetting remeshingPipeline "RemeshingLegacyProcessor/RemeshingLegacySettings/MergeDistance"
print ("MergeDistance: " + mergeDistance as string + "\n")
-- more settings can be set for the Remeshing 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) for the generated mesh.
bMaterialBake = true
if bMaterialBake == true then
(
-- enable material baking
-- mapping image is required for material baking
bResult = sgsdk_SetSetting remeshingPipeline "RemeshingLegacyProcessor/MappingImageSettings/GenerateMappingImage" true
generateMappingImage = sgsdk_GetSetting remeshingPipeline "RemeshingLegacyProcessor/MappingImageSettings/GenerateMappingImage"
print ("GenerateMappingImage: " + generateMappingImage as string + "\n")
-- in this case we want to generate texture coordinates (UVs)
bResult = sgsdk_SetSetting remeshingPipeline "RemeshingLegacyProcessor/MappingImageSettings/GenerateTexCoords" true
generateTexCoords = sgsdk_GetSetting remeshingPipeline "RemeshingLegacyProcessor/MappingImageSettings/GenerateTexCoords"
print ("GenerateTexCoords: " + generateTexCoords as string + "\n")
-- the name of the resulting texture coordinate field
bResult = sgsdk_SetSetting remeshingPipeline "RemeshingLegacyProcessor/MappingImageSettings/TexCoordName" "MaterialLOD"
texCoordLevel = sgsdk_GetSetting remeshingPipeline "RemeshingLegacyProcessor/MappingImageSettings/TexCoordName"
print ("TexCoordName: " + texCoordLevel as string + "\n")
-- width of the baked textures
bResult = sgsdk_SetSetting remeshingPipeline "RemeshingLegacyProcessor/MappingImageSettings/Output0/TextureWidth" 512
textureWidth = sgsdk_GetSetting remeshingPipeline "RemeshingLegacyProcessor/MappingImageSettings/Output0/TextureWidth"
print ("TextureWidth: " + textureWidth as string + "\n")
-- height of the baked textures
bResult = sgsdk_SetSetting remeshingPipeline "RemeshingLegacyProcessor/MappingImageSettings/Output0/TextureHeight" 512
textureHeight = sgsdk_GetSetting remeshingPipeline "RemeshingLegacyProcessor/MappingImageSettings/Output0/TextureHeight"
print ("TextureHeight: " + textureHeight as string + "\n")
-- add material casters (Ambient_Color, Diffuse_Color, Specular_Color and Bump)
bCasterAdded = sgsdk_AddMaterialCaster remeshingPipeline "ColorCaster"
bResult = sgsdk_SetSetting remeshingPipeline "MaterialCaster/0/ColorCasterSettings/MaterialChannel" "Ambient_Color"
colorCaster0 = sgsdk_GetSetting remeshingPipeline "MaterialCaster/0/ColorCasterSettings/MaterialChannel"
print ("ColorCaster0: " + colorCaster0 as string + "\n")
bCasterAdded = sgsdk_AddMaterialCaster remeshingPipeline "ColorCaster"
bResult = sgsdk_SetSetting remeshingPipeline "MaterialCaster/1/ColorCasterSettings/MaterialChannel" "Diffuse_Color"
colorCaster1 = sgsdk_GetSetting remeshingPipeline "MaterialCaster/1/ColorCasterSettings/MaterialChannel"
print ("ColorCaster1: " + colorCaster1 as string + "\n")
bCasterAdded = sgsdk_AddMaterialCaster remeshingPipeline "ColorCaster"
bResult = sgsdk_SetSetting remeshingPipeline "MaterialCaster/2/ColorCasterSettings/MaterialChannel" "Specular_Color"
colorCaster2 = sgsdk_GetSetting remeshingPipeline "MaterialCaster/2/ColorCasterSettings/MaterialChannel"
print ("ColorCaster2: " + colorCaster2 as string + "\n")
-- note: normal caster for normals!
bCasterAdded = sgsdk_AddMaterialCaster remeshingPipeline "NormalCaster"
bResult = sgsdk_SetSetting remeshingPipeline "MaterialCaster/3/NormalCasterSettings/MaterialChannel" "Bump"
normalCaster3 = sgsdk_GetSetting remeshingPipeline "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 remeshingPipeline "MaterialCaster/3/NormalCasterSettings/GenerateTangentSpaceNormals" true
generateTangentSpaceNormals = sgsdk_GetSetting remeshingPipeline "MaterialCaster/3/NormalCasterSettings/GenerateTangentSpaceNormals"
print ("GenerateTangentSpaceNormals: " + generateTangentSpaceNormals as string + "\n")
)
if bMaterialBake then
(
bResult = sgsdk_SavePipeline remeshingPipeline "D:/Pipelines/Remeshing_With_Baking.json"
)
else
(
bResult = sgsdk_SavePipeline remeshingPipeline "D:/Pipelines/Remeshing.json"
)
-- clear all pipelines
sgsdk_ClearPipelines()
from pymxs import runtime as rt
# create a Remeshing Pipeline object
remeshingPipeline = rt.sgsdk_CreatePipeline('RemeshingLegacyPipeline')
# set DefaultTangentCalculatorType to Autodesk3dsMax (1)
bResult = rt.sgsdk_SetSetting(remeshingPipeline, 'GlobalSettings/DefaultTangentCalculatorType', 1)
defaultTangentCalculatorType = rt.sgsdk_GetSetting(remeshingPipeline, 'GlobalSettings/DefaultTangentCalculatorType')
print ('DefaultTangentCalculatorType: ' + str(defaultTangentCalculatorType) + '\n')
# set the OnScreenSize for the generated mesh
bResult = rt.sgsdk_SetSetting(remeshingPipeline, 'RemeshingLegacyProcessor/RemeshingLegacySettings/OnScreenSize', 300)
onScreenSize = rt.sgsdk_GetSetting(remeshingPipeline, 'RemeshingLegacyProcessor/RemeshingLegacySettings/OnScreenSize')
print ('OnScreenSize: ' + str(onScreenSize) + '\n')
# set the merge distance for the Remeshing processor,
# a lower value might be preferred for skinned assets to avoid small gaps to merge,
# or when you want to preserve details (at a cost of triangles).
bResult = rt.sgsdk_SetSetting(remeshingPipeline, 'RemeshingLegacyProcessor/RemeshingLegacySettings/MergeDistance', 0)
mergeDistance = rt.sgsdk_GetSetting(remeshingPipeline, 'RemeshingLegacyProcessor/RemeshingLegacySettings/MergeDistance')
print ('MergeDistance: ' + str(mergeDistance) + '\n')
# more settings can be set for the Remeshing 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) for the generated mesh.
bMaterialBake = True
if bMaterialBake:
# enable material baking
# mapping image is required for material baking
bResult = rt.sgsdk_SetSetting(remeshingPipeline, 'RemeshingLegacyProcessor/MappingImageSettings/GenerateMappingImage', True)
generateMappingImage = rt.sgsdk_GetSetting(remeshingPipeline, 'RemeshingLegacyProcessor/MappingImageSettings/GenerateMappingImage')
print ('GenerateMappingImage: ' + str(generateMappingImage) + '\n')
# in this case we want to generate texture coordinates (UVs)
bResult = rt.sgsdk_SetSetting(remeshingPipeline, 'RemeshingLegacyProcessor/MappingImageSettings/GenerateTexCoords', True)
generateTexCoords = rt.sgsdk_GetSetting(remeshingPipeline, 'RemeshingLegacyProcessor/MappingImageSettings/GenerateTexCoords')
print ('GenerateTexCoords: ' + str(generateTexCoords) + '\n')
# the name of the resulting texture coordinate field
bResult = rt.sgsdk_SetSetting(remeshingPipeline, 'RemeshingLegacyProcessor/MappingImageSettings/TexCoordName', 'MaterialLOD')
texCoordLevel = rt.sgsdk_GetSetting(remeshingPipeline, 'RemeshingLegacyProcessor/MappingImageSettings/TexCoordName')
print ('TexCoordName: ' + texCoordLevel + '\n')
# width of the baked textures
bResult = rt.sgsdk_SetSetting(remeshingPipeline, 'RemeshingLegacyProcessor/MappingImageSettings/Output0/TextureWidth', 512)
textureWidth = rt.sgsdk_GetSetting(remeshingPipeline, 'RemeshingLegacyProcessor/MappingImageSettings/Output0/TextureWidth')
print ('TextureWidth: ' + str(textureWidth) + '\n')
# height of the baked textures
bResult = rt.sgsdk_SetSetting(remeshingPipeline, 'RemeshingLegacyProcessor/MappingImageSettings/Output0/TextureHeight', 512)
textureHeight = rt.sgsdk_GetSetting(remeshingPipeline, 'RemeshingLegacyProcessor/MappingImageSettings/Output0/TextureHeight')
print ('TextureHeight: ' + str(textureHeight) + '\n')
# add material casters (Ambient_Color, Diffuse_Color, Specular_Color and Bump)
bCasterAdded = rt.sgsdk_AddMaterialCaster(remeshingPipeline, 'ColorCaster')
bResult = rt.sgsdk_SetSetting(remeshingPipeline, 'MaterialCaster/0/ColorCasterSettings/MaterialChannel', 'Ambient_Color')
colorCaster0 = rt.sgsdk_GetSetting(remeshingPipeline, 'MaterialCaster/0/ColorCasterSettings/MaterialChannel')
print ('ColorCaster0: ' + colorCaster0 + '\n')
bCasterAdded = rt.sgsdk_AddMaterialCaster(remeshingPipeline, 'ColorCaster')
bResult = rt.sgsdk_SetSetting(remeshingPipeline, 'MaterialCaster/1/ColorCasterSettings/MaterialChannel', 'Diffuse_Color')
colorCaster1 = rt.sgsdk_GetSetting(remeshingPipeline, 'MaterialCaster/1/ColorCasterSettings/MaterialChannel')
print ('ColorCaster1: ' + colorCaster1 + '\n')
bCasterAdded = rt.sgsdk_AddMaterialCaster(remeshingPipeline, 'ColorCaster')
bResult = rt.sgsdk_SetSetting(remeshingPipeline, 'MaterialCaster/2/ColorCasterSettings/MaterialChannel', 'Specular_Color')
colorCaster2 = rt.sgsdk_GetSetting(remeshingPipeline, 'MaterialCaster/2/ColorCasterSettings/MaterialChannel')
print ('ColorCaster2: ' + colorCaster2 + '\n')
# note: normal caster for normals!
bCasterAdded = rt.sgsdk_AddMaterialCaster(remeshingPipeline, 'NormalCaster')
bResult = rt.sgsdk_SetSetting(remeshingPipeline, 'MaterialCaster/3/NormalCasterSettings/MaterialChannel', 'Bump')
normalCaster3 = rt.sgsdk_GetSetting(remeshingPipeline, '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(remeshingPipeline, 'MaterialCaster/3/NormalCasterSettings/GenerateTangentSpaceNormals', True)
generateTangentSpaceNormals = rt.sgsdk_GetSetting(remeshingPipeline, 'MaterialCaster/3/NormalCasterSettings/GenerateTangentSpaceNormals')
print ('GenerateTangentSpaceNormals: ' + str(generateTangentSpaceNormals) + '\n')
if bMaterialBake:
bResult = rt.sgsdk_SavePipeline(remeshingPipeline, 'D:/Pipelines/Remeshing_With_Baking.json')
else:
bResult = rt.sgsdk_SavePipeline(remeshingPipeline, 'D:/Pipelines/Remeshing.json')
# clear all pipelines
rt.sgsdk_ClearPipelines()
# Next steps
Get to know how to use the Legacy Remeshing Pipeline: