CopyMesh ( mesh[,parent] )
Parameters
|
mesh - mesh entity to copy parent (optional) - parent entity for the new mesh; 0 for no parent (default) |
Description
|
Creates a new mesh entity with an independent copy of a mesh's geometry, and returns its handle. The copy gets its own vertices, triangles, surfaces and materials, so later mesh or surface edits to either mesh do not affect the other. That makes CopyMesh the right tool when you want to load a model once and then deform or repaint each copy differently. For repeated identical props - trees, crates, pickups - use CopyEntity instead: copies made that way share geometry and benefit from automatic GPU instancing, which is far cheaper than duplicating the data. Reach for CopyMesh only when the copied geometry genuinely needs to be edited on its own. Only the mesh geometry is copied - animation and hierarchy loaded with LoadAnimMesh are not carried over. See also: CopyEntity, CreateMesh, LoadMesh, AddMesh, FlipMesh. |
Example
; CopyMesh Example ; ---------------- ; CopyMesh duplicates a mesh with its OWN copy of the geometry, so ; the copy can be edited without touching the original. (Use ; CopyEntity for simple repeated props: copies share geometry and ; render faster.) Graphics3D 640,480 SetBuffer BackBuffer() camera=CreateCamera() PositionEntity camera,0,0,-6 light=CreateLight() RotateEntity light,30,30,0 source=CreateCube() PositionEntity source,-2,0,0 EntityColor source,80,160,255 ; The documented command: an independent copy of the cube's mesh copy=CopyMesh(source) PositionEntity copy,2,0,0 EntityColor copy,255,150,70 ; Edit the COPY's geometry: only the right-hand mesh becomes a tower ScaleMesh copy,0.5,1.75,0.5 While Not KeyDown(1) TurnEntity source,0,1,0 TurnEntity copy,0,1,0 ; Arrow keys move the camera If KeyDown(200) Then MoveEntity camera,0,0,0.1 If KeyDown(208) Then MoveEntity camera,0,0,-0.1 If KeyDown(203) Then TurnEntity camera,0,1,0 If KeyDown(205) Then TurnEntity camera,0,-1,0 RenderWorld Text 0,0,"Arrow keys: move camera Esc: exit" Text 0,20,"CopyMesh: the right-hand copy was reshaped independently" Flip Wend End
Index