Creates a shallow copy of an entity sharing mesh data but with independent transform.
Takes entity (source entity handle).
Returns new entity handle or 0 on failure.
3D Graphics
Parameters & Returns
Parameters
entityInt
Returns
Int
Quick Summary
Creates a shallow copy of an entity sharing mesh data but with independent transform.
Takes entity (source entity handle).
Returns new entity handle or 0 on failure.
Technical Exegesis...
Creates a shallow copy of an entity sharing mesh data but with independent transform. Takes entity (source entity handle). Returns new entity handle or 0 on failure. Validates source exists. Allocates new handle (g_nextEntityHandle++). Creates new Entity3D structure. Copies entity type. Copies transform (position, rotation, scale) as independent values. Sets worldMatrixDirty=true. Copies visibility flag. Copies collision settings (type, mode, radius, box min/max) as independent.
Creates a shallow copy of an entity sharing mesh data but with independent transform. Takes entity (source entity handle). Returns new entity handle or 0 on failure. Validates source exists. Allocates new handle (g_nextEntityHandle++). Creates new Entity3D structure. Copies entity type. Copies transform (position, rotation, scale) as independent values. Sets worldMatrixDirty=true. Copies visibility flag. Copies collision settings (type, mode, radius, box min/max) as independent. Type-specific handling: ENTITY_MESH shares mesh pointer (GPU instancing), clones material if mesh->allowsUVTransforms (enables per-entity colors), intentionally "leaks" mesh structures for simplicity. ENTITY_CAMERA creates new Camera3D struct, copies FOV/near/far. ENTITY_LIGHT creates new Light3D struct, copies type/color/range/intensity. ENTITY_BILLBOARD creates new Billboard3D struct, copies texture/mode. Does NOT copy parent/children relationships (copy has no parent, no children). Does NOT copy physics body (new entity has no collision until configured). Returns 0 if source doesn't exist.
This function enables GPU instancing for meshes while allowing independent per-instance properties. Shallow copy means mesh vertex/index buffers shared in VRAM - multiple entities reference same GPU resources. Memory efficient: 1000 tree copies share single mesh, each has different position/rotation. Material cloning: if mesh loaded with BBR_TEXTURE_UV, material cloned so each copy can have different color (via b3dSetEntityColor). Without BBR_TEXTURE_UV, material shared (all copies same color). Use cases: (1) Forests/crowds (load tree once, copy 1000 times), (2) Particle systems (create prototype, copy for each particle), (3) Projectiles (copy bullet mesh per shot), (4) LOD swapping (copy then modify). Copy vs b3dCopyMesh: b3dCopyEntity shares mesh (fast, low memory), b3dCopyMesh deep copies mesh (slow, high memory, allows per-copy vertex editing). Hierarchy not copied - use b3dSetParent after copying to rebuild relationships. Collision not copied - collision body (if exists) remains on source only. Camera copy creates independent FOV/projection. Light copy creates independent color/intensity. Transform copy means position/rotation/scale fully independent - moving copy doesn't affect original. Common pattern: prototype = b3dLoadMesh(...), For i=1 To 100, copy=b3dCopyEntity(prototype), b3dSetPosition(copy, Rnd(-50,50), 0, Rnd(-50,50)). Note about material "leak": comment says intentionally leaking mesh structures - cloned materials persist in g_materials array, cloned Mesh3D structs allocated but never freed. Acceptable for typical usage (hundreds of copies), potential issue for extreme cases (millions of copies).