# Simple Remeshing pipeline (new remesher)
This example shows how to create a new RemeshingPipeline
and how to set basic parameters for Remeshing and material baking.
-- create a Remeshing Pipeline object
remeshingPipeline = sgsdk_CreatePipeline "RemeshingPipeline"
-- 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 "RemeshingProcessor/RemeshingSettings/OnScreenSize" 300
onScreenSize = sgsdk_GetSetting remeshingPipeline "RemeshingProcessor/RemeshingSettings/OnScreenSize"
print ("OnScreenSize: " + onScreenSize as string + "\n")
-- Hole filling defines how deep cavities that should be filled are allowed to be,
-- and how large the openings of the holes and cavities the processor will attempt to fill will be.
-- 0 = no hole filling, 1 = low, 2 = medium, 3 = high
bResult = sgsdk_SetSetting remeshingPipeline "RemeshingProcessor/RemeshingSettings/HoleFilling" 1
holeFilling = sgsdk_GetSetting remeshingPipeline "RemeshingProcessor/RemeshingSettings/HoleFilling"
print ("HoleFilling: " + holeFilling 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 do
(
-- enable material baking
-- mapping image is required for material baking
bResult = sgsdk_SetSetting remeshingPipeline "RemeshingProcessor/MappingImageSettings/GenerateMappingImage" true
generateMappingImage = sgsdk_GetSetting remeshingPipeline "RemeshingProcessor/MappingImageSettings/GenerateMappingImage"
print ("GenerateMappingImage: " + generateMappingImage as string + "\n")
-- in this case we want to generate texture coordinates (UVs)
bResult = sgsdk_SetSetting remeshingPipeline "RemeshingProcessor/MappingImageSettings/GenerateTexCoords" true
generateTexCoords = sgsdk_GetSetting remeshingPipeline "RemeshingProcessor/MappingImageSettings/GenerateTexCoords"
print ("GenerateTexCoords: " + generateTexCoords as string + "\n")
-- the name of the resulting texture coordinate field
bResult = sgsdk_SetSetting remeshingPipeline "RemeshingProcessor/MappingImageSettings/TexCoordName" "MaterialLOD"
texCoordLevel = sgsdk_GetSetting remeshingPipeline "RemeshingProcessor/MappingImageSettings/TexCoordName"
print ("TexCoordName: " + texCoordLevel as string + "\n")
-- width of the baked textures
bResult = sgsdk_SetSetting remeshingPipeline "RemeshingProcessor/MappingImageSettings/Output0/TextureWidth" 512
textureWidth = sgsdk_GetSetting remeshingPipeline "RemeshingProcessor/MappingImageSettings/Output0/TextureWidth"
print ("TextureWidth: " + textureWidth as string + "\n")
-- height of the baked textures
bResult = sgsdk_SetSetting remeshingPipeline "RemeshingProcessor/MappingImageSettings/Output0/TextureHeight" 512
textureHeight = sgsdk_GetSetting remeshingPipeline "RemeshingProcessor/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('RemeshingPipeline')
# 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, 'RemeshingProcessor/RemeshingSettings/OnScreenSize', 300)
onScreenSize = rt.sgsdk_GetSetting(remeshingPipeline, 'RemeshingProcessor/RemeshingSettings/OnScreenSize')
print ('OnScreenSize: ' + str(onScreenSize) + '\n')
# Hole filling defines how deep cavities that should be filled are allowed to be,
# and how large the openings of the holes and cavities the processor will attempt to fill will be.
# 0 = no hole filling, 1 = low, 2 = medium, 3 = high
bResult = rt.sgsdk_SetSetting(remeshingPipeline, 'RemeshingProcessor/RemeshingSettings/HoleFilling', 1)
holeFilling = rt.sgsdk_GetSetting(remeshingPipeline, 'RemeshingProcessor/RemeshingSettings/HoleFilling')
print ('HoleFilling: ' + str(holeFilling) + '\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, 'RemeshingProcessor/MappingImageSettings/GenerateMappingImage', True)
generateMappingImage = rt.sgsdk_GetSetting(remeshingPipeline, 'RemeshingProcessor/MappingImageSettings/GenerateMappingImage')
print ('GenerateMappingImage: ' + str(generateMappingImage) + '\n')
# in this case we want to generate texture coordinates (UVs)
bResult = rt.sgsdk_SetSetting(remeshingPipeline, 'RemeshingProcessor/MappingImageSettings/GenerateTexCoords', True)
generateTexCoords = rt.sgsdk_GetSetting(remeshingPipeline, 'RemeshingProcessor/MappingImageSettings/GenerateTexCoords')
print ('GenerateTexCoords: ' + str(generateTexCoords) + '\n')
# the name of the resulting texture coordinate field
bResult = rt.sgsdk_SetSetting(remeshingPipeline, 'RemeshingProcessor/MappingImageSettings/TexCoordName', 'MaterialLOD')
texCoordLevel = rt.sgsdk_GetSetting(remeshingPipeline, 'RemeshingProcessor/MappingImageSettings/TexCoordName')
print ('TexCoordName: ' + texCoordLevel + '\n')
# width of the baked textures
bResult = rt.sgsdk_SetSetting(remeshingPipeline, 'RemeshingProcessor/MappingImageSettings/Output0/TextureWidth', 512)
textureWidth = rt.sgsdk_GetSetting(remeshingPipeline, 'RemeshingProcessor/MappingImageSettings/Output0/TextureWidth')
print ('TextureWidth: ' + str(textureWidth) + '\n')
# height of the baked textures
bResult = rt.sgsdk_SetSetting(remeshingPipeline, 'RemeshingProcessor/MappingImageSettings/Output0/TextureHeight', 512)
textureHeight = rt.sgsdk_GetSetting(remeshingPipeline, 'RemeshingProcessor/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 Remeshing Pipeline: