Center Point in Entity


👉 BlitzCoder will be building a new platform and other plans to preserve and continue the Blitz legacy.

To be able to achieve this goal, we need your support by becoming a Patreon Paid Member 👈

 

Tweet blitz3d code-archives tutorials mesh
BlitzCoder

AutoMidHandle for Static and Animated Mesh.

This function will center a static mesh assuming it has a depth, height and width of > 0

Archive Link

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

Archive Link

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