Simplygon 9 Documentation Simplygon 9 Documentation
Overview
Simplygon API
Maya
Max
UE4
Unity
Download
Overview
Simplygon API
Maya
Max
UE4
Unity
Download
  • Simplygon API
  • Getting started

  • API Concepts

  • Examples

    • Getting started
    • Aggregation

    • Aggregation pipeline

    • Material Casting

    • Batching

    • Events

    • Scene

    • Reduction

    • Reduction pipeline

    • Remeshing

    • Remeshing pipeline

      • Remeshing pipeline
      • Remeshing pipeline with bone settings
      • Remeshing pipeline with hole filling
      • Remeshing pipeline with material casting
      • Remeshing pipeline with process selection set
    • Shading networks

  • API Reference

    // Copyright (c) Microsoft Corporation. 
    // Licensed under the MIT license. 
    
    #include <string>
    #include <stdlib.h>
    #include <filesystem>
    #include <future>
    #include "SimplygonLoader.h"
    
    
    void RunRemeshingWithMaterialCasting(Simplygon::ISimplygon* sg)
    {
    	Simplygon::spSceneImporter sgSceneImporter = sg->CreateSceneImporter();
    	sgSceneImporter->SetImportFilePath( "../Assets/RiggedSimplygonMan/RiggedSimplygonMan.fbx" );
    	if(!sgSceneImporter->RunImport())
    		throw std::exception("Failed to load RiggedSimplygonMan/RiggedSimplygonMan.fbx.");
    	Simplygon::spScene sgScene = sgSceneImporter->GetScene();
    
    	// Create the remeshing pipeline. 
    	Simplygon::spRemeshingPipeline sgRemeshingPipeline = sg->CreateRemeshingPipeline();
    
    	Simplygon::spRemeshingSettings sgRemeshingSettings = sgRemeshingPipeline->GetRemeshingSettings();
    	Simplygon::spMappingImageSettings sgMappingImageSettings = sgRemeshingPipeline->GetMappingImageSettings();
    
    	// Set on-screen size target for remeshing. 
    	sgRemeshingSettings->SetOnScreenSize( 300 );
    
    	// Generates a mapping image which is used after the remeshing to cast new materials to the new 
    	// remeshed object. 
    	sgMappingImageSettings->SetGenerateMappingImage( true );
    	sgMappingImageSettings->SetApplyNewMaterialIds( true );
    	sgMappingImageSettings->SetGenerateTangents( true );
    	sgMappingImageSettings->SetUseFullRetexturing( true );
    
    	Simplygon::spMappingImageOutputMaterialSettings sgOutputMaterialSettings = sgMappingImageSettings->GetOutputMaterialSettings(0);
    
    	// Setting the size of the output material for the mapping image. This will be the output size of the 
    	// textures when we do material casting in a later stage. 
    	sgOutputMaterialSettings->SetTextureWidth( 2048 );
    	sgOutputMaterialSettings->SetTextureHeight( 2048 );
    
    	// Add diffuse material caster to pipeline. 
    	Simplygon::spColorCaster sgDiffuseCaster = sg->CreateColorCaster();
    
    	Simplygon::spColorCasterSettings sgDiffuseCasterSettings = sgDiffuseCaster->GetColorCasterSettings();
    	sgDiffuseCasterSettings->SetMaterialChannel( "Diffuse" );
    	sgDiffuseCasterSettings->SetOutputImageFileFormat( Simplygon::EImageOutputFormat::PNG );
    
    	sgRemeshingPipeline->AddMaterialCaster( sgDiffuseCaster, 0 );
    
    	// Add normals material caster to pipeline. 
    	Simplygon::spNormalCaster sgNormalsCaster = sg->CreateNormalCaster();
    
    	Simplygon::spNormalCasterSettings sgNormalsCasterSettings = sgNormalsCaster->GetNormalCasterSettings();
    	sgNormalsCasterSettings->SetMaterialChannel( "Normals" );
    	sgNormalsCasterSettings->SetGenerateTangentSpaceNormals( true );
    	sgNormalsCasterSettings->SetOutputImageFileFormat( Simplygon::EImageOutputFormat::PNG );
    
    	sgRemeshingPipeline->AddMaterialCaster( sgNormalsCaster, 0 );
    
    	// Start the remeshing pipeline. 
    	sgRemeshingPipeline->RunScene(sgScene, Simplygon::EPipelineRunMode::RunInThisProcess);
    
    	// Get the processed scene. 
    	Simplygon::spScene sgProcessedScene = sgRemeshingPipeline->GetProcessedScene();
    
    	Simplygon::spSceneExporter  sgSceneExporter = sg->CreateSceneExporter();
    	sgSceneExporter->SetScene(sgProcessedScene);
    	sgSceneExporter->SetExportFilePath( "RemeshingOutput.fbx" );
    	if(!sgSceneExporter->RunExport())
    		throw std::exception("Failed to save RemeshingOutput.fbx.");
    
    }
    
    void main()
    {
    	Simplygon::ISimplygon* sg = NULL;
    	Simplygon::EErrorCodes initval = Simplygon::Initialize( &sg );
    	if( initval != Simplygon::EErrorCodes::NoError )
    	{
    		return;
    	}
    
    	RunRemeshingWithMaterialCasting(sg);
    
    	Simplygon::Deinitialize(sg);
    }
    
    
    
    // Copyright (c) Microsoft Corporation. 
    // Licensed under the MIT license. 
    
    using System;
    using System.IO;
    using System.Threading.Tasks;
    
    public class Program
    {
        static void RunRemeshingWithMaterialCasting(Simplygon.ISimplygon sg)
        {
            using (Simplygon.spSceneImporter  sgSceneImporter = sg.CreateSceneImporter())
            {
                sgSceneImporter.SetImportFilePath( "../Assets/RiggedSimplygonMan/RiggedSimplygonMan.fbx" );
                if(!sgSceneImporter.RunImport())
                    throw new System.Exception("Failed to load RiggedSimplygonMan/RiggedSimplygonMan.fbx.");
                Simplygon.spScene sgScene = sgSceneImporter.GetScene();
    
                // Create the remeshing pipeline. 
                using (Simplygon.spRemeshingPipeline sgRemeshingPipeline = sg.CreateRemeshingPipeline())
                {
                    using (Simplygon.spRemeshingSettings sgRemeshingSettings = sgRemeshingPipeline.GetRemeshingSettings())
                    using (Simplygon.spMappingImageSettings sgMappingImageSettings = sgRemeshingPipeline.GetMappingImageSettings())
                    {
                        // Set on-screen size target for remeshing. 
                        sgRemeshingSettings.SetOnScreenSize( 300 );
    
                        // Generates a mapping image which is used after the remeshing to cast new materials to the new 
                        // remeshed object. 
                        sgMappingImageSettings.SetGenerateMappingImage( true );
                        sgMappingImageSettings.SetApplyNewMaterialIds( true );
                        sgMappingImageSettings.SetGenerateTangents( true );
                        sgMappingImageSettings.SetUseFullRetexturing( true );
    
                        using (Simplygon.spMappingImageOutputMaterialSettings sgOutputMaterialSettings = sgMappingImageSettings.GetOutputMaterialSettings(0))
                        {
                            // Setting the size of the output material for the mapping image. This will be the output size of the 
                            // textures when we do material casting in a later stage. 
                            sgOutputMaterialSettings.SetTextureWidth( 2048 );
                            sgOutputMaterialSettings.SetTextureHeight( 2048 );
    
                        }
                    }
                    // Add diffuse material caster to pipeline. 
                    using (Simplygon.spColorCaster sgDiffuseCaster = sg.CreateColorCaster())
                    {
                        using (Simplygon.spColorCasterSettings sgDiffuseCasterSettings = sgDiffuseCaster.GetColorCasterSettings())
                        {
                            sgDiffuseCasterSettings.SetMaterialChannel( "Diffuse" );
                            sgDiffuseCasterSettings.SetOutputImageFileFormat( Simplygon.EImageOutputFormat.PNG );
                        }
    
                        sgRemeshingPipeline.AddMaterialCaster( sgDiffuseCaster, 0 );
                    }
    
                    // Add normals material caster to pipeline. 
                    using (Simplygon.spNormalCaster sgNormalsCaster = sg.CreateNormalCaster())
                    {
                        using (Simplygon.spNormalCasterSettings sgNormalsCasterSettings = sgNormalsCaster.GetNormalCasterSettings())
                        {
                            sgNormalsCasterSettings.SetMaterialChannel( "Normals" );
                            sgNormalsCasterSettings.SetGenerateTangentSpaceNormals( true );
                            sgNormalsCasterSettings.SetOutputImageFileFormat( Simplygon.EImageOutputFormat.PNG );
                        }
    
                        sgRemeshingPipeline.AddMaterialCaster( sgNormalsCaster, 0 );
                    }
    
                    // Start the remeshing pipeline. 
                    sgRemeshingPipeline.RunScene(sgScene, Simplygon.EPipelineRunMode.RunInThisProcess);
    
                    // Get the processed scene. 
                    using (Simplygon.spScene sgProcessedScene = sgRemeshingPipeline.GetProcessedScene())
                    {
                        using (Simplygon.spSceneExporter sgSceneExporter = sg.CreateSceneExporter())
                        {
                            sgSceneExporter.SetScene(sgProcessedScene);
                            sgSceneExporter.SetExportFilePath( "RemeshingOutput.fbx" );
                            if(!sgSceneExporter.RunExport())
                                throw new System.Exception("Failed to save RemeshingOutput.fbx.");
    
                        }
                    }
                }
            }
        }
        static void Main(string[] args)
        {
            using (var sg = Simplygon.Loader.InitSimplygon(out var errorCode, out var errorMessage))
            {
                if (errorCode != Simplygon.EErrorCodes.NoError)
                    return;
                RunRemeshingWithMaterialCasting(sg);
            }
        }
    }
    
    
    # Copyright (c) Microsoft Corporation. 
    # Licensed under the MIT license. 
    
    import math
    import os
    import sys
    import glob
    import gc
    import threading
    
    from pathlib import Path
    from simplygon import simplygon_loader
    from simplygon import Simplygon
    
    
    def RunRemeshingWithMaterialCasting(sg: Simplygon.ISimplygon):
        sgSceneImporter = sg.CreateSceneImporter()
        sgSceneImporter.SetImportFilePath( "../Assets/RiggedSimplygonMan/RiggedSimplygonMan.fbx" )
        if not sgSceneImporter.RunImport():
            raise Exception("Failed to load RiggedSimplygonMan/RiggedSimplygonMan.fbx.")
        sgScene = sgSceneImporter.GetScene()
    
        # Create the remeshing pipeline. 
        sgRemeshingPipeline = sg.CreateRemeshingPipeline()
    
        sgRemeshingSettings = sgRemeshingPipeline.GetRemeshingSettings()
        sgMappingImageSettings = sgRemeshingPipeline.GetMappingImageSettings()
    
        # Set on-screen size target for remeshing. 
        sgRemeshingSettings.SetOnScreenSize( 300 )
    
        # Generates a mapping image which is used after the remeshing to cast new materials to the new 
        # remeshed object. 
        sgMappingImageSettings.SetGenerateMappingImage( True )
        sgMappingImageSettings.SetApplyNewMaterialIds( True )
        sgMappingImageSettings.SetGenerateTangents( True )
        sgMappingImageSettings.SetUseFullRetexturing( True )
    
        sgOutputMaterialSettings = sgMappingImageSettings.GetOutputMaterialSettings(0)
    
        # Setting the size of the output material for the mapping image. This will be the output size of the 
        # textures when we do material casting in a later stage. 
        sgOutputMaterialSettings.SetTextureWidth( 2048 )
        sgOutputMaterialSettings.SetTextureHeight( 2048 )
    
        # Add diffuse material caster to pipeline. 
        sgDiffuseCaster = sg.CreateColorCaster()
        sgDiffuseCasterSettings = sgDiffuseCaster.GetColorCasterSettings()
        sgDiffuseCasterSettings.SetMaterialChannel( "Diffuse" )
        sgDiffuseCasterSettings.SetOutputImageFileFormat( Simplygon.EImageOutputFormat_PNG )
    
        sgRemeshingPipeline.AddMaterialCaster( sgDiffuseCaster, 0 )
    
        # Add normals material caster to pipeline. 
        sgNormalsCaster = sg.CreateNormalCaster()
        sgNormalsCasterSettings = sgNormalsCaster.GetNormalCasterSettings()
        sgNormalsCasterSettings.SetMaterialChannel( "Normals" )
        sgNormalsCasterSettings.SetGenerateTangentSpaceNormals( True )
        sgNormalsCasterSettings.SetOutputImageFileFormat( Simplygon.EImageOutputFormat_PNG )
    
        sgRemeshingPipeline.AddMaterialCaster( sgNormalsCaster, 0 )
    
        # Start the remeshing pipeline. 
        sgRemeshingPipeline.RunScene(sgScene, Simplygon.EPipelineRunMode_RunInThisProcess)
    
        # Get the processed scene. 
        sgProcessedScene = sgRemeshingPipeline.GetProcessedScene()
    
        sgSceneExporter = sg.CreateSceneExporter()
        sgSceneExporter.SetScene(sgProcessedScene)
        sgSceneExporter.SetExportFilePath( "RemeshingOutput.fbx" )
        if not sgSceneExporter.RunExport():
            raise Exception("Failed to save RemeshingOutput.fbx.")
    
    
    if __name__ == '__main__':
        sg = simplygon_loader.init_simplygon()
    
        RunRemeshingWithMaterialCasting(sg)
    
        sg = None
        gc.collect()
    
    
    

    ← Remeshing pipeline with hole filling Remeshing pipeline with process selection set →