|
entity - mesh entity, or a parent of mesh entities, that gets the level level - which level of detail lod_mesh becomes, from 1 to one more than the mesh has; at most 8 lod_mesh - the simpler model: a mesh, or a parent of meshes whose names match the entity's parts |
|
Makes another mesh one of a mesh's levels of detail, such as a far version an artist made. Modelling programs often export a model with simpler versions of itself - rock_lod1.glb, rock_lod2.glb - each made by hand. SetEntityLODMesh puts them together: the full model draws close up, and each version takes over further away. The level keeps the version's own surfaces and materials, so a far tree can be a painted card. Its vertices are copied, so you can free lod_mesh afterwards. It returns how many meshes got the level. Characters can have hand-made levels too. A skinned level moves with the character's skeleton: each of its bones is matched with the character's bone of the same name, so export the levels with the same skeleton. Unlike AddEntityLOD, the levels switch as automatic versions do, by how much detail they lose on screen, so they follow the entity's scale and the camera's zoom; until you call SetEntityLODDistance, a level takes over where a version simplified to its share of the triangles would. For a model of several parts, each part of lod_mesh goes to the entity's part of the same name, as LoadAnimMesh names them; a model of one part and a version of one part match whatever their names. Place lod_mesh where the entity is: its parts take the places they have in it. Levels made this way and levels from SimplifyEntityLOD can be mixed in one mesh, and SaveMesh keeps them all in one file. Gotcha: a level with materials of its own has no lightmap coordinates, so BakeLighting lights a mesh with one by probes, as it does a mesh with AddEntityLOD levels. A skinned character's levels must be skinned too, and a static mesh's levels static. See also: SimplifyEntityLOD, SetEntityLODDistance, AddEntityLOD, CountEntityLODs, SaveMesh. |
; SetEntityLODMesh Example
; ------------------------
Graphics3D 640,480,0,2
SetBuffer BackBuffer()
camera=CreateCamera()
PositionEntity camera,0,2,-8
light=CreateLight()
RotateEntity light,45,45,0
; A detailed tree top
tree=CreateSphere(32)
ScaleMesh tree,1,1.6,1
EntityColor tree,60,150,70
; The far version an artist made: a plain cone
far=CreateCone(16)
ScaleMesh far,1,1.6,1
EntityColor far,200,80,60
; The cone is level 1 of the tree, taking over 15 metres from this camera
SetEntityLODMesh tree,1,far
SetEntityLODDistance tree,1,15,camera
FreeEntity far
While Not KeyDown(1)
TurnEntity tree,0,0.5,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 (walk back past 15 m) Esc: exit"
Text 0,20,"SetEntityLODMesh tree,1,far: "+EntityLODTriangles(tree,0)+" triangles, or "+EntityLODTriangles(tree,1)+" in the red cone"
Text 0,40,"Distance "+Int(EntityDistance(camera,tree))+" m: drawing level "+EntityLODLevel(tree)
Flip
Wend
End