Code archives/3D Graphics - Mesh/CenterMesh ()

This code has been declared by its author to be Public Domain code.

Download source code

CenterMesh () by BlitzSupport2001
UPDATED

Sometimes models are offset when exported from editors, with the effect that rather than rotate around the mesh's centre, they rotate around some weird offset point way outside the mesh. This function will reposition the mesh at world co-ordinates 0, 0, 0 and centre it properly on its pivot.

Use this *before* trying to position a weird-offset mesh, as it will place the pivot on 0, 0, 0!

Now you can use those weirdo-offset models as you'd expect to!

(Note that the code inside the function should all be on one line, whereas it may not appear that way here!)
Function CenterMesh (entity)
	FitMesh entity, -(MeshWidth (entity) / 2), -(MeshHeight (entity) / 2), -(MeshDepth (entity) / 2), MeshWidth (entity), MeshHeight (entity), MeshDepth (entity)
End Function

; Example usage (don't try to run this!)...

planeModel = LoadMesh ("747.x")
CenterMesh (planeModel)
PositionEntity planeModel, 50, 100, 50

Comments

None.

Code Archives Forum