Exports surface-based mesh with all textures baked into single atlas and remapped UVs.
Takes meshHandle (surface-based mesh entity), filename (output .glb path), meshName (mesh name, defaults to "Mesh_0"), uvPadding (pixels between atlas regions, 0-8, prevents bleeding), atlasSize (atlas texture dimensions, e.g. 1024, 2048, 4096).
Returns 1 on success, 0 on failure.
3D Graphics
Parameters & Returns
Parameters
meshHandleInt
filenameString
meshNameString
uvPaddingInt
atlasSizeInt
Returns
Int
Quick Summary
Exports surface-based mesh with all textures baked into single atlas and remapped UVs.
Takes meshHandle (surface-based mesh entity), filename (output .glb path), meshName (mesh name, defaults to "Mesh_0"), uvPadding (pixels between atlas regions, 0-8, prevents bleeding), atlasSize (atlas texture dimensions, e.g. 1024, 2048, 4096).
Returns 1 on success, 0 on failure.
Technical Exegesis...
Exports surface-based mesh with all textures baked into single atlas and remapped UVs. Takes meshHandle (surface-based mesh entity), filename (output .glb path), meshName (mesh name, defaults to "Mesh_0"), uvPadding (pixels between atlas regions, 0-8, prevents bleeding), atlasSize (atlas texture dimensions, e.g. 1024, 2048, 4096). Returns 1 on success, 0 on failure. Only works with surface-based meshes (created with b3dCreateMesh, not loaded from files).
Exports surface-based mesh with all textures baked into single atlas and remapped UVs. Takes meshHandle (surface-based mesh entity), filename (output .glb path), meshName (mesh name, defaults to "Mesh_0"), uvPadding (pixels between atlas regions, 0-8, prevents bleeding), atlasSize (atlas texture dimensions, e.g. 1024, 2048, 4096). Returns 1 on success, 0 on failure. Only works with surface-based meshes (created with b3dCreateMesh, not loaded from files). Analyzes all surfaces to determine texture sizes and solid colors. Packs surface textures into atlas using bin-packing algorithm. Renders each surface texture to atlas region (GPU rendering for correct filtering). For solid color surfaces, fills atlas region with color. Remaps all vertex UVs from original surface coordinates to atlas coordinates. Creates new unified mesh with single texture (the atlas). Writes to GLB file. Automatically generates atlas texture image file (same name as GLB but .png extension). Returns 0 if: invalid handle, mesh not surface-based, packing fails (atlas too small), GPU rendering fails, file write fails.
This function enables multi-material procedural meshes to export as single-material assets for game engines. Texture atlas packing: (1) Analyze surface materials (texture dimensions or estimate solid color size), (2) Sort by area descending (largest first), (3) Bin-pack into atlas using shelf algorithm, (4) Render each texture/color to packed region, (5) Remap UVs: newUV = (oldUV * regionSize + regionOffset) / atlasSize. UVPadding prevents texture bleeding at mipmap levels - adds N pixel border around each region, filled with edge pixels (clamp/extend). AtlasSize must be power of 2 for GPU compatibility (512, 1024, 2048, 4096). If surfaces don't fit, increase atlasSize or reduce surface texture sizes. Common values: uvPadding=2 (safe default), atlasSize=2048 (good balance). Use cases: (1) Procedurally generated buildings with brick/window/door textures -> single-texture model for game, (2) Terrain chunks with multiple ground textures -> optimized mesh, (3) Character customization (skin/clothes/accessories) -> baked appearance. GPU rendering ensures correct texture filtering (bilinear/trilinear) and color space (sRGB). Generated PNG atlas saved alongside GLB for manual inspection/editing. Baked mesh loses ability to change individual surface materials (baked into texture). For runtime texture baking (modify then re-bake), use b3dBakeMesh which keeps mesh in memory. Export workflow: b3dCreateMesh -> AddMeshSurface x N -> b3dSaveMeshBaked.