well all of that is required to meet the DB/P standard load..
Vertex . Normal . UV
There is quite a bit more I could've added.
The last template is a very cool one, because it combined multiple Vertex Indicies when loading.
So if you have 2 identical Indicies it'll only act as one.
In DB/P what would happen would be that it'd export the code, but you'd have 6 Vertex Points for 2 Triangle Faces. Given DB/P only renders Triangles, there is no point in worrying about Quad or above.
So the final type will basically load DB/P's 6 Vertex Points like mine is, with only 4 Vertex Indexes.
It seems a little complex, but it actually makes sense.
In DirectX everything is Indexed from base values. These are then accessed via Look-up tables/arrays.
If say you were to recreate this using DB/P and the Mesh Memblock it would come out like this (exclusing the Header mind you)
#Constant _default = 1
#Constant _SizeOfDword = 4
#Constant _SizeOfFloat = 4
Type Vector
x As Float
y As Float
z As Float
EndType
Type Coords2d
u As Float
v As Float
EndType
Type Index
a As Integer
b As Integer
c As Integer
EndType
Type Vertex
Index As Vector
TexCoord As Coords2D
EndType
Global Dim MeshVertex(0) As Vertex
Global Dim MeshFaces(0, 4) As Index
Global Dim MeshNormal(0) As Vector
Global Dim MeshFaceNormal(0, 4) As Index
Global Dim MeshTextureCoords(0) As Coords2d
Global TestObject As Integer
`/Vertex/
AddVertex(2.0, 0.0, -2.0)
AddVertex(2.0, 0.0, 2.0)
AddVertex(-2.0, 0.0, 2.0)
AddVertex(-2.0, 0.0, -2.0)
`/Faces/
AddFace(1, 3, 2)
AddFace(2, 3, 1)
`/Normals/
AddNormal(0.0, 1.0, 0.0)
`/FaceNormals/
AddFaceNormal(1, 1, 1)
`/TexCoords/
AddTexCoord(1, 0.0, 0.0)
AddTexCoord(2, 0.0, 0.0)
AddTexCoord(3, 0.0, 0.0)
AddTexCoord(4, 0.0, 0.0)
TestObject = CreateObject()
Repeat
Sync
Until EscapeKey()
Function AddVertex( x As Float, y As Float, z As Float )
Local Current As Integer
Array Insert At Bottom MeshVertex(0)
Current = Array Count(MeshVertex(0))
MeshVertex(Current).Index.x = x
MeshVertex(Current).Index.y = y
MeshVertex(Current).Index.z = z
EndFunction
Function AddFace( x As Integer, y As Integer, z As Integer )
Local Current As Integer
Array Insert At Bottom MeshFaces(0)
Current = Array Count(MeshFaces(0))
MeshFaces(Current, 1) = x
MeshFaces(Current, 2) = y
MeshFaces(Current, 3) = z
EndFunction
Function AddNormal( x As Float, y As Float, z As Float )
Local Current As Integer
Array Insert At Bottom MeshNormal(0)
Current = Array Count(MeshNormal(0))
MeshNormal(Current).x = x
MeshNormal(Current).y = y
MeshNormal(Current).z = z
EndFunction
Function AddFaceNormal( x As Integer, y As Integer, z As Integer )
Local Current As Integer
Array Insert At Bottom MeshFaceNormal(0)
Current = Array Count(MeshFaceNormal(0))
MeshFaceNormal(Current, 1) = x
MeshFaceNormal(Current, 2) = y
MeshFaceNormal(Current, 3) = z
EndFunction
Function AddTexCoord( Current As Integer, u As Float, v As Float )
MeshVertex(Current).TexCoord.u = u
MeshVertex(Current).TexCoord.v = v
EndFunction
Function MakeObject()
Local Result As Integer = null
Local position As Integer = null
Local Current As Integer = null
Make Memblock _default, 12 + ((4 * Array Count(MeshFaces(0))) * 32)
Write Memblock Dword _default, position, (0x002 || 0x010 || 0x100) : Inc position, _SizeOfDword
Write Memblock Dword _default, position, 32 : Inc position, _SizeOfDword
Write Memblock Dword _default, position, 4 * Array Count(MeshFaces(0)) : Inc position, _SizeOfDword
For Face = 1 To Array Count(MeshFaces(0))
For Index = 1 To 4
If Index = 4 Then Current = 1 : Else : Current = Index
`/ vertex
Write Memblock Float _default, position, MeshVertex(MeshFaces(Face, Current)).Index.x : Inc position, _SizeOfFloat
Write Memblock Float _default, position, MeshVertex(MeshFaces(Face, Current)).Index.y : Inc position, _SizeOfFloat
Write Memblock Float _default, position, MeshVertex(MeshFaces(Face, Current)).Index.z : Inc position, _SizeOfFloat
`/ normal
Write Memblock Float _default, position, MeshNormal(MeshFaces(Face, Current)).x : Inc position, _SizeOfFloat
Write Memblock Float _default, position, MeshNormal(MeshFaces(Face, Current)).y : Inc position, _SizeOfFloat
Write Memblock Float _default, position, MeshNormal(MeshFaces(Face, Current)).z : Inc position, _SizeOfFloat
` / texcoord
Write Memblock Float _default, position, MeshVertex(MeshFaces(Face, Current)).TexCoord.y : Inc position, _SizeOfFloat
Write Memblock Float _default, position, MeshVertex(MeshFaces(Face, Current)).TexCoord.z : Inc position, _SizeOfFloat
Next Index
Next Face
Make Mesh From Memblock _default, _default
Make Object _default, _default, null
`/ GC /
Delete Mesh _default
Delete Memblock _default
EndFunction Result
In a more familiar coding it should become far more obvious what's going on.
It looks long and complimacated, but trust me it's pretty easy to follow ^_^