|
mesh - mesh handle x_scale# - scale factor along x y_scale# - scale factor along y z_scale# - scale factor along z |
|
Scales every vertex of a mesh by the given factors, relative to the entity's pivot. Unlike ScaleEntity, this permanently modifies the geometry: MeshWidth-style measurements, collisions and picking all see the new size. It is the usual way to normalise a loaded model's size once at load time (or use FitMesh to hit an exact box), keeping ScaleEntity free for gameplay effects. Two things to watch: after a non-uniform scale, call UpdateNormals so lighting stays correct; and a negative factor mirrors the mesh, which reverses the triangle winding and makes it look inside-out - follow up with FlipMesh to fix the visible side. See also: FitMesh, ScaleEntity, PositionMesh, RotateMesh, UpdateNormals, FlipMesh. |
; ScaleMesh Example
; -----------------
; ScaleMesh rescales the mesh's VERTICES, and it is cumulative: every
; call multiplies on top of the last. ScaleEntity, by contrast, sets
; an absolute display scale and leaves the mesh data alone - which is
; why MeshWidth below tracks ScaleMesh but would ignore ScaleEntity.
Graphics3D 640,480
SetBuffer BackBuffer()
camera=CreateCamera()
PositionEntity camera,0,0,-4
light=CreateLight()
RotateEntity light,30,40,0
; Load a drum and fit it into a 2-unit box to start from a known size
drum=LoadMesh("media/oil-drum/oildrum.3ds")
FitMesh drum,-1,-1,-1,2,2,2,1
While Not KeyDown(1)
; Hold [ / ] to shrink / grow the mesh 2% per frame - the
; documented command, applied cumulatively
If KeyDown(26) Then ScaleMesh drum,0.98,0.98,0.98
If KeyDown(27) Then ScaleMesh drum,1.02,1.02,1.02
TurnEntity drum,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,"Hold [ / ] : shrink / grow the mesh Arrow keys: move camera Esc: exit"
Text 0,20,"MeshWidth after ScaleMesh: "+MeshWidth(drum)
Flip
Wend
End