Code archives/3D Graphics - Mesh/Mesh Position Getting Commands
This code has been declared by its author to be Public Domain code.
Download source code
| |||||
| These are not completely tested in multiple scenarios, but they should work well. The functions can be used to get the exact center point of a mesh, which can in turn be used to center an imported mesh in a modelling program, etc. The LeftMost(), RightMost(), etc. functions are also useful to align a mesh in a particular way. | |||||
Function MeshX#(mesh)
Local LeftX#,RightX#
For s = 1 To CountSurfaces(mesh)
su = GetSurface(mesh,s)
For v = 0 To CountVertices(su)-1
If VertexX(su,v)<LeftX Then LeftX=VertexX(su,v)
If VertexX(su,v)>RightX Then RightX=VertexX(su,v)
Next
Next
x# = LeftX + (RightX - LeftX) / 2
Return x#
End Function
Function MeshY#(mesh)
Local BottomY#,TopY#
For s = 1 To CountSurfaces(mesh)
su = GetSurface(mesh,s)
For v = 0 To CountVertices(su)-1
If VertexY(su,v)<BottomY Then BottomY=VertexY(su,v)
If VertexY(su,v)>TopY Then TopY=VertexY(su,v)
Next
Next
y# = BottomY + (TopY - BottomY) / 2
Return y#
End Function
Function MeshZ#(mesh)
Local BackZ#,FrontZ#
For s = 1 To CountSurfaces(mesh)
su = GetSurface(mesh,s)
For v = 0 To CountVertices(su)-1
If VertexZ(su,v)<BackZ Then BackZ=VertexZ(su,v)
If VertexZ(su,v)>FrontZ Then FrontZ=VertexZ(su,v)
Next
Next
z# = BackZ + (FrontZ - BackZ) / 2
Return z#
End Function
Function LeftMost#(mesh)
Local LeftX#,RightX#
For s = 1 To CountSurfaces(mesh)
su = GetSurface(mesh,s)
For v = 0 To CountVertices(su)-1
If VertexX(su,v)<LeftX Then LeftX=VertexX(su,v)
If VertexX(su,v)>RightX Then RightX=VertexX(su,v)
Next
Next
Return LeftX#
End Function
Function RightMost#(mesh)
Local LeftX#,RightX#
For s = 1 To CountSurfaces(mesh)
su = GetSurface(mesh,s)
For v = 0 To CountVertices(su)-1
If VertexX(su,v)<LeftX Then LeftX=VertexX(su,v)
If VertexX(su,v)>RightX Then RightX=VertexX(su,v)
Next
Next
Return RightX#
End Function
Function TopMost#(mesh)
Local BottomY#,TopY#
For s = 1 To CountSurfaces(mesh)
su = GetSurface(mesh,s)
For v = 0 To CountVertices(su)-1
If VertexY(su,v)<BottomY Then BottomY=VertexY(su,v)
If VertexY(su,v)>TopY Then TopY=VertexY(su,v)
Next
Next
Return TopY#
End Function
Function BottomMost#(mesh)
Local BottomY#,TopY#
For s = 1 To CountSurfaces(mesh)
su = GetSurface(mesh,s)
For v = 0 To CountVertices(su)-1
If VertexY(su,v)<BottomY Then BottomY=VertexY(su,v)
If VertexY(su,v)>TopY Then TopY=VertexY(su,v)
Next
Next
Return BottomY#
End Function
Function FrontMost#(mesh)
Local BackZ#,FrontZ#
For s = 1 To CountSurfaces(mesh)
su = GetSurface(mesh,s)
For v = 0 To CountVertices(su)-1
If VertexZ(su,v)<BackZ Then BackZ=VertexZ(su,v)
If VertexZ(su,v)>FrontZ Then FrontZ=VertexZ(su,v)
Next
Next
Return FrontZ#
End Function
Function BackMost#(mesh)
Local BackZ#,FrontZ#
For s = 1 To CountSurfaces(mesh)
su = GetSurface(mesh,s)
For v = 0 To CountVertices(su)-1
If VertexZ(su,v)<BackZ Then BackZ=VertexZ(su,v)
If VertexZ(su,v)>FrontZ Then FrontZ=VertexZ(su,v)
Next
Next
Return BackZ#
End Function |
Comments
None.
Code Archives Forum