'constants to distinguish between mesh buffer modes
Const MESHBUFFER_STANDARD=0
Const MESHBUFFER_LIGHTMAP=1
Const MESHBUFFER_TANGENTS=2
'this is an editable mesh container class. it holds an irrlicht
'static SMesh and performs simple manipulations on it. planning
'an animated mesh one too. seperately or integrated, I have not
'yet decided.
Type TMeshContainer
Field mesh:SMesh
Function create:TMeshContainer(mesh:SMesh)
irrmesh:TMeshContainer=New TMeshContainer
irrmesh.mesh=mesh
Return irrmesh
End Function
Method CreateSurface:TSurfaceContainer(buffermode=MESHBUFFER_STANDARD)
surface:TSurfaceContainer=TSurfaceContainer.create(buffermode)
mesh.addMeshBuffer surface.buffer
Return surface
End Method
Method CountSurfaces()
Return mesh.getMeshBufferCount()
End Method
Method GetSurface:TSurfaceContainer(index)
surface:TSurfaceContainer=New TSurfaceContainer
surface.buffer=SMeshBuffer(mesh.getMeshBuffer(index))
Return surface
End Method
Method GetWidth()
Return mesh.getBoundingBox().getExtent().getX()
End Method
Method GetHeight()
Return mesh.getBoundingBox().getExtent().getY()
End Method
Method GetDepth()
Return mesh.getBoundingBox().getExtent().getZ()
End Method
Method SetScale(sx#,sy#,sz#)
TIrrContainer.IrrMeshManip.scaleMesh ..
mesh,Vector3df.createFromVals(sx,sy,sz)
End Method
Method FlipNormals()
TIrrContainer.IrrMeshManip.flipSurfaces mesh
End Method
Method Normalize()
TIrrContainer.IrrMeshManip.recalculateNormals mesh
End Method
End Type
'this is a container for a surface, which is simply a mesh vertex buffer
'and a format and access mode. different formats are faster than others
'in specific operations but not others. it depends on what you're doing
'what vertex format is best. I'm partial to the standard format
Type TSurfaceContainer
Field buffer:IMeshBuffer
Field bufmode
Function create:TSurfaceContainer(buffermode=MESHBUFFER_STANDARD)
surface:TSurfaceContainer=New TSurfaceContainer
surface.bufmode=buffermode
Select buffermode
Case MESHBUFFER_STANDARD surface.buffer=SMeshBuffer.create()
Case MESHBUFFER_LIGHTMAP surface.buffer=SMeshBufferLightMap.create()
Case MESHBUFFER_TANGENTS surface.buffer=SMeshBufferTangents.create()
End Select
End Function
Method AddVertex(x#,y#,z#,nx#=0,ny#=0,nz#=0,u#=0,v#=0,color:TColor=Null,alpha=255)
If color=Null Then color=CreateColor(COLORTYPE_RGB,1,1,1)
vert:S3DVertex=S3DVertex.createFromVals(x,y,z,nx,ny,nz,..
_SCOLOR(alpha,..
color.Red()*255,color.Green()*255,color.Blue()*255),u,v)
buffer.getVertices().push_back vert
Return CountVertices()-1
End Method
Method AddTriangle(v0:Short,v1:Short,v2:Short)
indicies:Array_u16=buffer.getIndices()
indicies.push_back v0
indicies.push_back v1
indicies.push_back v2
End Method
Method CountVertices()
Return buffer.getVertexCount()
End Method
Method GetVertex:Vertex(index)
Return Vertex(buffer.getVertices().elementAt(index))
End Method
Method SetVertexCoords(index,px#,py#,pz#)
vert:Vertex=GetVertex(index)
vert.setPos Vector3df.createFromVals(px,py,pz)
End Method
Method SetVertexNormal(index,nx#,ny#,nz#)
vert:Vertex=GetVertex(index)
vert.setNormal Vector3df.createFromVals(nx,ny,nz)
End Method
Method SetSurfaceColor(color:TColor=Null,alpha=255)
If color=Null Then color=CreateColor(COLORTYPE_RGB,1,1,1)
For index=0 To CountVertices()-1
vert:Vertex=GetVertex(index)
vert.SetColor _SCOLOR(alpha,..
color.Red()*255,color.Green()*255,color.Blue()*255)
Next
End Method
Method SetVertexColor(index,color:TColor=Null,alpha=255)
If color=Null Then color=CreateColor(COLORTYPE_RGB,1,1,1)
vert:Vertex=GetVertex(index)
vert.SetColor _SCOLOR(alpha,..
color.Red()*255,color.Green()*255,color.Blue()*255)
End Method
Method SetVertexTextureCoords(index,u#,v#)
vert:Vertex=GetVertex(index)
vert.setTCoords(Vector2df.createFromVals(u,v))
End Method
Method GetVertexColor:TColor(index)
vertcolor:SColor=GetVertex(index).GetColor()
Return CreateColor(COLORTYPE_RGB,..
Float(vertcolor.getRed())/255#,..
Float(vertcolor.getGreen())/255#,..
Float(vertcolor.getBlue())/255#)
End Method
Method GetVertexAlpha#(index)
Return GetVertex(index).GetColor().GetAlpha()
End Method
Method GetVertexPosX#(index)
Return GetVertex(index).getPos().getX()
End Method
Method GetVertexPosY#(index)
Return GetVertex(index).getPos().getY()
End Method
Method GetVertexPosZ#(index)
Return GetVertex(index).getPos().getZ()
End Method
Method GetVertexNormX#(index)
Return GetVertex(index).getNormal().getX()
End Method
Method GetVertexNormY#(index)
Return GetVertex(index).getNormal().getY()
End Method
Method GetVertexNormZ#(index)
Return GetVertex(index).getNormal().getZ()
End Method
Method GetVertexTexU#(index)
Return GetVertex(index).getTCoords().getX()
End Method
Method GetVertexTexV#(index)
Return GetVertex(index).getTCoords().getY()
End Method
End Type
The only thing I like better than coffee and gaming is coding!