Center Point in Entity
Attention! 👉Starting November 2024, BlitzCoder.org will now be BlitzBasic.org.
Tweet blitz3d code-archives tutorials mesh
AutoMidHandle for Static and Animated Mesh.
This function will center a static mesh assuming it has a depth, height and width of > 0
Function MESHmidhandle( mesh )
Mw# = meshwidth( mesh )
Mh# = meshheight( mesh )
Md# = meshdepth( mesh )
fitmesh mesh, -.5*mw, -.5*mh, -.5*md, mw,mh,md
End Function
For animated meshes you cant use meshwidth on it but could try the code below.
It loads an animmesh and scales it using blitz units.
tharefore if you make it 4,4,4 you know the center is x+2,y+2,z+2
create a pivot at this point and parent the mesh to it and voila! a centrally referenced mesh
Function loadscaledanimmesh(filename$, sx#,sy#,sz#) ;Size in blitz units not percent!!
;By Dan @ D-Grafix
;useage : mesh=loadscaledanimmesh(file$,width,height,depth)
;create scaler and mesure static mesh
scaler=LoadMesh(filename)
mesh_SX# =MeshWidth(scaler)
mesh_SY# =MeshHeight(scaler)
mesh_SZ# =MeshDepth(scaler)
;and bin it
FreeEntity scaler
;load 'real' mesh
mesh=LoadAnimMesh(filename)
;do some maths
Xscale# = ((100/mesh_SX) * sx) / 100.0
Yscale# = ((100/mesh_SY) * sy) / 100.0
Zscale# = ((100/mesh_SZ) * sz) / 100.0
;scale it
ScaleEntity mesh,Xscale#,Yscale#,Zscale#
;return it
Return mesh
End Function
Reply To Topic (minimum 10 characters)
Please log in to reply