Combines two surface-based meshes into a single new mesh with optional transform baking.
Takes mesh1 (first surface-based mesh), mesh2 (second surface-based mesh), applyTransforms (0 = ignore entity transforms, non-zero = bake transforms into vertices).
Returns new merged mesh entity handle or 0 on failure.
3D Graphics
Parameters & Returns
Parameters
mesh1Int
mesh2Int
applyTransformsInt
Returns
Int
Quick Summary
Combines two surface-based meshes into a single new mesh with optional transform baking.
Takes mesh1 (first surface-based mesh), mesh2 (second surface-based mesh), applyTransforms (0 = ignore entity transforms, non-zero = bake transforms into vertices).
Returns new merged mesh entity handle or 0 on failure.
Technical Exegesis...
Combines two surface-based meshes into a single new mesh with optional transform baking. Takes mesh1 (first surface-based mesh), mesh2 (second surface-based mesh), applyTransforms (0 = ignore entity transforms, non-zero = bake transforms into vertices). Returns new merged mesh entity handle or 0 on failure. Validates both meshes exist and type is ENTITY_MESH. Validates both are surface-based (created with b3dCreateMesh, not loaded).
Combines two surface-based meshes into a single new mesh with optional transform baking. Takes mesh1 (first surface-based mesh), mesh2 (second surface-based mesh), applyTransforms (0 = ignore entity transforms, non-zero = bake transforms into vertices). Returns new merged mesh entity handle or 0 on failure. Validates both meshes exist and type is ENTITY_MESH. Validates both are surface-based (created with b3dCreateMesh, not loaded). Uses mesh1's configuration (maxDetailSlots, allowsUVTransforms) for merged mesh. Creates new mesh via b3dCreateMesh. Locks mesh for editing. If applyTransforms=1, builds world transform matrices for both meshes (scale * rotation * translation) from entity position/rotation/scale. Copies all surfaces from mesh1: creates new surface, copies vertices (transformed if applyTransforms), copies indices, copies material, copies name. Increments totalSurfacesCopied. Copies all surfaces from mesh2 with same process (transformed if applyTransforms). Unlocks merged mesh. Returns merged mesh handle. Returns 0 if: invalid mesh handles, meshes not surface-based, mesh creation fails.
This function combines procedural geometry for optimization and organization. Surface preservation: merged mesh contains all surfaces from both sources - total surfaces = mesh1.surfaces.count + mesh2.surfaces.count. Material preservation: each surface retains original material reference (materials not merged/deduplicated). Transform baking: when applyTransforms=1, vertex positions transformed to world space before merging - enables combining meshes at different positions/rotations into single mesh at origin. Use cases with applyTransforms=0 (ignore transforms): (1) Combine mesh parts at same position (head+body+legs created separately), (2) Merge procedurally generated chunks in local space, (3) Template combination (merge base mesh with detail mesh). Use cases with applyTransforms=1 (bake transforms): (1) Freeze scene geometry (building pieces at various positions -> single building mesh), (2) Prefab instantiation (place furniture instances, merge into room mesh), (3) Static batching (multiple small objects -> single optimized mesh for rendering). Performance benefit: merged mesh renders in fewer draw calls than separate meshes. Memory: merged mesh allocates new vertex/index buffers (doesn't share with sources). After merging, source meshes remain unchanged - safe to free with b3dFreeEntity if no longer needed. Transform matrix: scale -> rotation (roll-pitch-yaw) -> translation order. Rotation uses DirectX::XMConvertToRadians for degree-to-radian conversion. Common workflow: wall1=b3dCreateMesh(...), b3dSetPosition(wall1,0,0,0), wall2=b3dCreateMesh(...), b3dSetPosition(wall2,10,0,0), room=b3dMergeMesh(wall1,wall2,1) creates single mesh with walls at world positions. Alternative: use b3dCopyMesh then manually append vertices/indices for full control.