FitMesh mesh,x#,y#,z#,width#,height#,depth#[,uniform]
Parameters
|
mesh - mesh handle x# - x coordinate of the box corner (minimum x) y# - y coordinate of the box corner (minimum y) z# - z coordinate of the box corner (minimum z) width# - width of the box height# - height of the box depth# - depth of the box uniform (optional) - True to scale all three axes by the same factor so the mesh keeps its proportions; False (default) |
Description
|
Scales and translates all vertices of a mesh so the mesh fits the specified box. This is the quickest way to bring a loaded model of unknown size to game scale: FitMesh model,-1,0,-1,2,2,2,True squeezes anything into a 2-unit box sitting on the ground at the origin. With uniform True the smallest scale factor is used on all three axes and the mesh is centred in the box, so it is not distorted; with uniform False the mesh is stretched to fill the box exactly. Like the other mesh commands this permanently modifies the vertex data relative to the entity's pivot - MeshWidth and friends report the new size, and collisions and picking use the new shape. ScaleEntity, by contrast, only changes how the entity is drawn. Never pass 0 for width#, height# or depth# - collapsing an axis to zero destroys that dimension of the mesh for good. Use a small value such as 0.001 if you want a flat result. See also: ScaleMesh, PositionMesh, MeshWidth, MeshHeight, MeshDepth, ScaleEntity. |
Example
; FitMesh Example ; --------------- ; FitMesh scales and translates a mesh's vertices so the mesh exactly ; occupies a given box. Uniform mode keeps the mesh's proportions; ; non-uniform mode stretches every axis to fill the box completely. ; Space cycles: original cone -> uniform fit -> non-uniform fit. Graphics3D 640,480 SetBuffer BackBuffer() camera=CreateCamera() PositionEntity camera,0,1,-4 RotateEntity camera,10,0,0 light=CreateLight() RotateEntity light,30,40,0 ; A see-through box marks the target space: 2 wide, 1 high, 2 deep target=CreateCube() EntityColor target,80,160,255 EntityAlpha target,0.4 FitMesh target,-1,-0.5,-1,2,1,2 cone=CreateCone() EntityColor cone,255,80,80 state=0 While Not KeyDown(1) ; Space rebuilds a fresh cone and fits it into the target box If KeyHit(57) Then state=(state+1) Mod 3 FreeEntity cone cone=CreateCone() EntityColor cone,255,80,80 ; Uniform fit: scaled equally, so at least one axis fits If state=1 Then FitMesh cone,-1,-0.5,-1,2,1,2,1 ; Non-uniform fit: distorted so ALL axes fill the box If state=2 Then FitMesh cone,-1,-0.5,-1,2,1,2 EndIf TurnEntity target,0,1,0 TurnEntity cone,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,"Space: cycle fit mode Arrow keys: move camera Esc: exit" If state=0 Then Text 0,20,"Original cone - press Space to fit it into the box" If state=1 Then Text 0,20,"FitMesh cone,-1,-0.5,-1,2,1,2,1 - uniform, proportions kept" If state=2 Then Text 0,20,"FitMesh cone,-1,-0.5,-1,2,1,2 - non-uniform, box filled" Flip Wend End
Index