Skip to main content

Tutorial: CLI Preserve UVs

This tutorial contains these key points:
✔️ Import a 3D model
✔️ Create a Settings Preset Config
✔️ Optimize geometry
✔️ Preserve tiling UVs
✔️ Bake ambient occlusion to 2nd UV
✔️ Compare the results

This tutorial shows how use RapidPipeline 3D Processor CLI to optimize a 3D model, preserving existing tiled UV coordinates, generating a second shared UV, and baking a single ambient occlusion texture for the whole model.

RapidPipeline 3D Processor is a powerful 3D data optimization and automation toolset; for more information please see the product overview.

Before and after renders of the chair
Input model (left) at 61.6mb with 906,426 triangles. Output model (right) is 6.5mb with 50,000 triangles.

Before and after renders of the chair, in wireframe
Wireframes of the input and output models.

Files Used in this Tutorial

Examine the Input Model

Before deciding on which settings to use, it is important to examine statistics for the input 3D model. Download the 3D asset chairwiththrow.glb (61.6 mb) and save it into a folder on the hard drive. In this tutorial C:\temp\ is used.

RapidPipeline 3D Processor CLI can be used to extract salient info by typing rpdx -i chairwiththrow.glb --write_info info-input.json

This process will generate a JSON-formatted text file with more than 70 lines of information about the 3D model. The info file can alternatively be downloaded here.

This asset has 26 meshes: "numMeshes": 26, so Scene Graph Flattening will be useful. This will attach all pieces together that share the same material, which helps prevent gaps from appearing during optimization.

Chair meshes in solid colors, and with UV checker applied
The chair has multiple meshes, and tiled UVs.

Settings Presets

To control the optimization process, a JSON-formatted Settings Preset Config is required. This is a text file with a specific layout, containing settings that can be edited as needed.

Config files can be created in multiple ways: by using the CLI, or using the Blender Plugin, or using the Web Platform, or using the REST API.

In this tutorial, a Config will be created using the Web Platform, then exported to use with the CLI. The Config file can alternatively be downloaded here.

Presets are great for automatically processing large batches of 3D assets, to create well-formed output files. Presets help to effectively convert, optimize, render and prepare 3D content for any use-case, platform or device.

Create a Settings Preset Config

  1. Open the RapidPipeline web platform and go to 3D Processor Presets.
    Web Platform UI with button shown

  2. Turn on Preview New Settings to enable settings compatible with 3D Processor 7.x, the most current version.
    Web Platform UI with button shown

  3. Click on Create Preset which will start the preset with a blank template.
    Web Platform UI with button shown

  4. Click the down arrow next to Custom Workflow to open the available settings.
    Web Platform UI with button shown

  5. Change the mode to Expert to expose all settings.
    Web Platform UI with button shown

Settings for Scene Graph Flattening

  1. Enable the Scene Graph Flattening section, which opens the available settings.
    Web Platform UI with button shown

  2. Set the Flattening Method to use byMaterial.
    Web Platform UI with button shown
    This will merge all the meshes together that share the same material. Merging meshes together will help prevent gaps from appearing between them when they are optimized.
    Two closeups of the chair arm
    Scene Graph Flattening byMaterial (left), versus None (right)

  3. Use the Save button at the top of the preset to save the settings created so far.
    Web Platform UI with button shown

For more information, see the reference documentation on Scene Graph Flattening.

Settings for Optimize

  1. Enable the Optimize section, which opens the available settings.
    Web Platform UI with button shown

  2. Enable the 3D Model Optimization Method, and use Mesh and Material Optimization.
    Web Platform UI with button shown
    The mesh for this model will be simplified, and an ambient occlusion texture will be baked for the materials.

  3. Enable Target, choose Faces, choose Faces Value, and enter a triangle count of 50000.
    Web Platform UI with button shown
    This is a good amount for a complex mesh; this asset has a throw blanket with fine tassles, which requires a bit more detail in the optimized model.

    tip

    For more information on triangle decimation, see the reference documentation for the Decimator.

  4. Next to the Target heading, choose Material Optimization.
    Web Platform UI with button shown
    This will expose the controls for ambient occlusion baking.

  5. The first dropdown should be set to Keep Materials and UVs.
    Web Platform UI with button shown

  6. Click on the heading Generate 2nd UV Atlas, then enable the checkbox next to Generate 2nd UV Atlas.
    Web Platform UI with button shown

  7. UV Atlas Mode should be changed to single.
    Web Platform UI with button shown
    This will create a 2nd UV which is shared by all the asset materials, which means they will all use a single shared ambient occlusion texture.

  8. Enable the checkbox next to 2nd UV Atlas Texture Baker and enable Bake Combined Scene.
    Web Platform UI with button shown
    This will cause all meshes to cast occlusion onto each other, so for example the throw blanket will cast shadowing onto the chair. When this setting is disabled, each material will only create occlusions using its own meshes, ignoring all other meshes in the scene.

  9. Click on the heading 2nd UV Ambient Occlusion Map Baker, and enable the checkbox next to 2nd UV Ambient Occlusion Map Baker.
    Web Platform UI with button shown
    This will bake the ambient occlusion texture using the 2nd UV.

    tip

    For more information on ambient occlusion baking, see the reference documentation for the Ambient Occlusion Baker.

  10. Use the Save button at the top of the preset to save the settings created so far.
    Web Platform UI with button shown

Settings for Export

  1. Click on the Export section to expose the Export controls.
    Web Platform UI with button shown

  2. Set the first output to GLB Format, and click the down arrow to open the export settings.
    Web Platform UI with button shown
    This will be a single self-contained glTF asset in binary form, which makes it easier to share the finished asset.

  3. Enable the checkbox for Exclude Tangents.
    Web Platform UI with button shown
    Tangents are not needed for this model because it uses tiled normal maps. Excluding the tangents will help reduce the file size.

    tip

    When is it good to include tangents? If normal maps are baked with mesh data in them (not tiled) then tangents will help a renderer understand how to correctly light the model, and to avoid causing seams on UV borders.

  4. Enable the checkbox next to glTF PBR Material, enable Maximum Texture Map Resolution, and set it to 1024.
    Web Platform UI with button shown
    The default resolution is 2048x2048, but this asset doesn't need that much resolution, so it helps to reduce the file size by setting the ambient occlusion texture to 1024.

  5. Use the Save button at the top of the preset to save the finished settings.
    Web Platform UI with button shown

Export the Preset

  1. Rename the preset if desired, by hovering over the default title Custom Workflow and clicking on the edit button.
    Web Platform UI with button shown
    This name is only used within the Web Platform; the exported preset will always be named preset.json.

  2. In the ACTIONS column, click the three dots menu button, and choose Download.
    Web Platform UI with button shown

  3. Open the downloaded ZIP file, extract the preset.json file into the same folder as the 3D model that will be optimized, then rename it preset-preserve.json.

    tip

    It is a good idea to rename preset files to keep them organized, to and prevent files from being overwritten by subsequent presets.

    The finished Settings Preset Config file can alternatively be downloaded here.

The finished preset file looks like this:

{
"export": [
{
"preserveTextureFilenames": false,
"reencodeTextures": "auto",
"format": {
"glb": {
"pbrMaterial": {
"maxTextureResolution": {
"default": 1024
}
}
}
}
}
],
"sceneGraphFlattening": {
"method": "byMaterial"
},
"optimize": {
"3dModelOptimizationMethod": {
"meshAndMaterialOptimization": {
"decimator": {
"materialOptimization": {
"keepMaterialsUVs": {
"atlasGenerator2ndUV": {
"atlasMode": "single",
"textureBaker2ndUV": {
"bakeCombinedScene": true,
"aoBaker2ndUV": {}
}
}
}
},
"target": {
"faces": {
"value": 50000
}
}
}
}
}
}
}

Processing the Model

Step by Step
1. In the same folder containing the 3D model and the Settings Preset Config, open a Windows PowerShell. This can be done by holding the Shift key, right-clicking in the folder, and choosing Open PowerShell window here.
2. Type (or copy-paste) the CLI command below, and press the Enter key.

rpdx -i chairwiththrow.glb --read_config preset-preserve.json -r -o out

The results in the CLI:

CLI shown after processing
CLI output from the optimization and baking process

CLI Commands Explained

CommandResult
rpdxStarts the CLI
-i chairwiththrow.glbImports the 3d asset for processing
--read_config preset-preserve.jsonLoads the Settings Preset Config file (created above)
-rRuns the 3D Processor
-o outOutputs the processed 3D asset into a folder named \out

Understanding the Outputs

Before and after renders of the chair
Input model (left) at 61.6mb with 906,426 triangles. Output model (right) is 6.5mb with 50,000 triangles.

The output file is saved into a subfolder named \out\0_glb. A numbered subfolder is created because an Output command can save multiple file formats in the same command, so each is saved into its own folder, to avoid conflicts.

The output filename will use the same prefix as the input file chairwiththrow and use whatever file extension was specified in the Settings Preset Config, in this case .glb.

The input model had 26 meshes and 4 materials; the output has 4 meshes and 4 materials.

Texture thumbnails and details, before and after
Input model has six textures (left), output (right) has the same six textures plus one additional 1024x1024 ambient occlusion texture.

Input / Output Statistics

Input AssetOutput Asset
906,426 triangles50,000 triangles
26 meshes4 meshes
4 materials4 materials
4 BaseColor maps4 BaseColor maps
2 Normal maps2 Normal maps
No Occlusion map1 Occlusion map
File size 61.6mbFile size 6.5mb