Extracts a single surface from a multi-surface mesh as a new independent mesh.
Takes mesh (surface-based mesh entity), surface (surface index, 0-based).
Returns new mesh entity handle containing only specified surface, or 0 on failure.
3D Graphics
Parameters & Returns
Parameters
meshInt
surfaceInt
Returns
Int
Quick Summary
Extracts a single surface from a multi-surface mesh as a new independent mesh.
Takes mesh (surface-based mesh entity), surface (surface index, 0-based).
Returns new mesh entity handle containing only specified surface, or 0 on failure.
Technical Exegesis...
Extracts a single surface from a multi-surface mesh as a new independent mesh. Takes mesh (surface-based mesh entity), surface (surface index, 0-based). Returns new mesh entity handle containing only specified surface, or 0 on failure. Validates mesh exists and type is ENTITY_MESH. Validates mesh is surface-based (created with b3dCreateMesh, not loaded from file). Validates surface index in range (0 to surfaces.size()-1). Validates surface has geometry (vertices/indices not empty).
Extracts a single surface from a multi-surface mesh as a new independent mesh. Takes mesh (surface-based mesh entity), surface (surface index, 0-based). Returns new mesh entity handle containing only specified surface, or 0 on failure. Validates mesh exists and type is ENTITY_MESH. Validates mesh is surface-based (created with b3dCreateMesh, not loaded from file). Validates surface index in range (0 to surfaces.size()-1). Validates surface has geometry (vertices/indices not empty). Creates new mesh with b3dCreateMesh using same configuration as source (maxDetailSlots, allowsUVTransforms). Locks new mesh for editing. Creates single surface in new mesh via b3dCreateSurface. Deep copies vertices array from source surface. Deep copies indices array from source surface. Creates independent material copy from source material (not shared). Copies surface name string. Copies atlas region size. Unlocks mesh. Returns new mesh handle. Returns 0 if: invalid mesh handle, mesh not surface-based, surface index out of range, surface has no geometry, mesh creation fails.
This function separates multi-surface meshes for individual manipulation. Surface-based meshes created via b3dCreateMesh with multiple b3dAddMeshSurface calls - each surface can have different material/texture. Extract enables: (1) Material editing (extract surface, modify color independently), (2) LOD generation (extract high-poly surface, simplify, replace), (3) Export (extract specific building parts for separate files), (4) Collision (extract collision surfaces from visual mesh). Extracted surface becomes fully independent mesh with its own material - modifying doesn't affect original. Material deep copied - changing material properties (color, texture, etc.) on extracted surface doesn't affect original. Geometry deep copied (vertices/indices) - safe to modify without affecting original. Use cases: (1) Building construction (create complex building, extract roof surface for replacement with different color), (2) Vegetation (create tree with trunk/leaves surfaces, extract leaves for animation with different materials), (3) Vehicles (body/wheels/windows as surfaces, extract wheel for rotation with custom color), (4) Terrain chunks (multi-material terrain, extract grass surface for detail editing with independent textures). After extraction, new mesh can be: (1) Modified with b3dLockMesh / vertex editing, (2) Texture baked with b3dBakeMesh, (3) Exported with b3dSaveMesh, (4) Merged with other meshes via b3dMergeMesh, (5) Colored independently with b3dSetEntityColorFX. Surface index from b3dCreateSurface return value or surface iteration (0, 1, 2, ...). Common pattern: For i=0 To CountSurfaces(mesh)-1, extracted=b3dExtractSurface(mesh, i), b3dSetEntityColorFX(extracted, r, g, b), b3dSaveMesh(extracted, "surface_"+i+".glb").