Blitz3D+ Command Reference

PositionMesh mesh,x#,y#,z#

Parameters

mesh - mesh handle
x# - amount to move the vertices along x
y# - amount to move the vertices along y
z# - amount to move the vertices along z

Description

Moves every vertex of a mesh by the given offset.

Unlike PositionEntity, this permanently modifies the geometry relative to the entity's pivot - the entity itself doesn't move, the shape shifts around it. The change also affects MeshWidth-style measurements, collisions and picking.

The classic job is fixing a model's origin: if a character was exported with its pivot at the waist, PositionMesh model,0,MeshHeight(model)/2.0,0 drops the pivot to its feet, so PositionEntity and turning behave sensibly. It is also how you set up rotation about an off-centre point, like shifting a door mesh sideways so RotateEntity swings it around its hinge.

See also: PositionEntity, RotateMesh, ScaleMesh, FitMesh, MeshHeight.

Example

; PositionMesh Example
; --------------------

; PositionMesh shifts the mesh's VERTICES; the entity itself (its
; pivot) stays where it was. Compare PositionEntity, which moves the
; entity and leaves the mesh data alone. Because the crate spins
; around its pivot, an offset mesh visibly ORBITS the magenta marker.

Graphics3D 640,480
SetBuffer BackBuffer()

camera=CreateCamera()
PositionEntity camera,0,2,-6
RotateEntity camera,15,0,0

light=CreateLight()
RotateEntity light,30,40,0

crate=CreateCube()
EntityColor crate,210,160,70

; A fullbright marker parented to the crate marks the entity's pivot
pivot_marker=CreateSphere()
ScaleEntity pivot_marker,0.15,0.15,0.15
EntityColor pivot_marker,255,0,255
EntityFX pivot_marker,1
EntityParent pivot_marker,crate

offset#=0

While Not KeyDown(1)

    ; Space shifts the mesh sideways - the documented command.
    ; Note the pivot marker does NOT move.
    If KeyHit(57) Then PositionMesh crate,0.5,0,0 : offset=offset+0.5

    ; R gathers the mesh back onto its pivot
    If KeyHit(19) Then PositionMesh crate,-offset,0,0 : offset=0

    ; The entity spins in place - the offset mesh orbits the pivot
    TurnEntity crate,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: PositionMesh 0.5 along x   R: reset   Arrow keys: move camera   Esc: exit"
    Text 0,20,"Mesh is offset "+offset+" units from its pivot (magenta marker)"

    Flip

Wend

End

Index