Quote: "MEMBLOCK MESHES!"
AddObjectMeshFromMemblock
CreateMemblockFromObjectMesh
CreateObjectFromMeshMemblock
GetMeshMemblockVertexNormalX
GetMeshMemblockVertexNormalY
GetMeshMemblockVertexNormalZ
GetMeshMemblockVertexU
GetMeshMemblockVertexV
GetMeshMemblockVertexX
GetMeshMemblockVertexY
GetMeshMemblockVertexZ
SetMeshMemblockVertexNormal
SetMeshMemblockVertexPosition
SetMeshMemblockVertexUV
SetObjectMeshFromMemblock
And your timing is impeccable. Here is some code I wrote this week to extract all the useful data into an array. Start by running GetMeshDataFromMemblock()
global gMesh as tMesh[]
TYPE tMesh
memBlock as integer
numVertices as integer
numIndices as integer
numAttributes as integer
sizeVertex as integer
offsetVertex as integer
offsetIndex as integer
offsetVertexPosition as integer
offsetVertexNormal as integer
offsetVertexUV as integer
attribute as tMeshAttribute[]
ENDTYPE
TYPE tMeshAttribute
offset as integer
size as integer
dataType as integer
componentCount as integer
normalise as integer
stringLength as integer
attributeString as string
ENDTYPE
function getMeshDatafromMemblock(mb)
//Create element and references
gMesh.length = gMesh.length + 1
id = gMesh.length
gMesh[id].memblock = mb
//Create header data
gMesh[id].numVertices = GetMemblockInt(mb, cMESH_NUM_VERTICES)
gMesh[id].numIndices = GetMemblockInt(mb, cMESH_NUM_INDICES)
gMesh[id].numAttributes = GetMemblockInt(mb, cMESH_NUM_ATTRIBUTES)
gMesh[id].sizeVertex = GetMemblockInt(mb, cMESH_SIZE_VERTEX)
gMesh[id].offsetVertex = GetMemblockInt(mb, cMESH_OFFSET_VERTEX)
gMesh[id].offsetIndex = GetMemblockInt(mb, cMESH_OFFSET_INDEX)
gMesh[id].offsetVertexPosition = -1
gMesh[id].offsetVertexNormal = -1
gMesh[id].offsetVertexUV = -1
//set size of subarray
gMesh[id].attribute.length = gMesh[id].numAttributes
//Get all attributes
attStart = cMESH_OFFSET_ATTRIBUTES
compStart = 0
for n = 1 to gMesh[id].numAttributes
gMesh[id].attribute[n].offset = attStart
gMesh[id].attribute[n].dataType = GetMemblockByte(mb, attStart)
gMesh[id].attribute[n].componentCount = GetMemblockByte(mb, attStart + 1)
gMesh[id].attribute[n].normalise = GetMemblockByte(mb, attStart + 2)
gMesh[id].attribute[n].stringLength = GetMemblockbyte(mb, attStart + 3)
gMesh[id].attribute[n].attributeString = GetMemblockString(mb, attStart + 4,gMesh[id].attribute[n].stringLength)
//If one of the standard attributes, record the index
select upper(gMesh[id].attribute[n].attributeString)
case "POSITION"
gMesh[id].offsetVertexPosition = compStart
endcase
case "NORMAL"
gMesh[id].offsetVertexNormal = compStart
endcase
case "UV"
gMesh[id].offsetVertexUV = compStart
endcase
endselect
if gMesh[id].attribute[n].dataType = cMESH_DATATYPE_FLOAT
inc compStart, gMesh[id].attribute[n].componentCount * 4
else
inc compStart, gMesh[id].attribute[n].componentCount * 1
endif
//Start of next attribute
attStart = attStart + 4 + gMesh[id].attribute[n].stringLength
next n
endfunction id
// ****************************************************
// Get Number of Vertices in Mesh
// ****************************************************
function getMeshVertexCount(meshId)
exitfunction gMesh[meshId].numVertices
endfunction 0
// ****************************************************
// Get Number of Indexes in Mesh
// ****************************************************
function getMeshIndexCount(meshId)
exitfunction gMesh[meshId].numIndices
endfunction 0
// ****************************************************
// Get Position of Vertex
// ****************************************************
function getMeshVertexPosition(meshId as integer, vertexId as integer, pos ref as tVector)
offVertex = gMesh[meshId].offsetVertex + (vertexId * gMesh[meshId].sizeVertex)
pos.x = GetMemblockFloat(gMesh[meshId].memBlock,offVertex + gMesh[meshId].offsetVertexPosition)
pos.y = GetMemblockFloat(gMesh[meshId].memBlock,offVertex + gMesh[meshId].offsetVertexPosition + 4)
pos.z = GetMemblockFloat(gMesh[meshId].memBlock,offVertex + gMesh[meshId].offsetVertexPosition + 8)
endfunction
// ****************************************************
// Set Position of Vertex
// ****************************************************
function setMeshVertexPosition(meshId as integer, vertexId as integer, pos ref as tVector)
offVertex = gMesh[meshId].offsetVertex + (vertexId * gMesh[meshId].sizeVertex)
SetMemblockFloat(gMesh[meshId].memBlock,offVertex + gMesh[meshId].offsetVertexPosition, pos.x)
SetMemblockFloat(gMesh[meshId].memBlock,offVertex + gMesh[meshId].offsetVertexPosition + 4,pos.y)
SetMemblockFloat(gMesh[meshId].memBlock,offVertex + gMesh[meshId].offsetVertexPosition + 8,pos.z)
endfunction
// ****************************************************
// Get Vertex normals
// ****************************************************
function getMeshVertexNormal(meshId as integer, vertexId as integer, normal ref as tVector)
offVertex = gMesh[meshId].offsetVertex + (vertexId * gMesh[meshId].sizeVertex)
normal.x = GetMemblockFloat(gMesh[meshId].memBlock,offVertex + gMesh[meshId].offsetVertexNormal)
normal.y = GetMemblockFloat(gMesh[meshId].memBlock,offVertex + gMesh[meshId].offsetVertexNormal + 4)
normal.z = GetMemblockFloat(gMesh[meshId].memBlock,offVertex + gMesh[meshId].offsetVertexNormal + 8)
endfunction
// ****************************************************
// Set Vertex normals
// ****************************************************
function setMeshVertexNormal(meshId as integer, vertexId as integer, normal ref as tVector)
offVertex = gMesh[meshId].offsetVertex + (vertexId * gMesh[meshId].sizeVertex)
SetMemblockFloat(gMesh[meshId].memBlock,offVertex + gMesh[meshId].offsetVertexNormal, normal.x)
SetMemblockFloat(gMesh[meshId].memBlock,offVertex + gMesh[meshId].offsetVertexNormal + 4, normal.y)
SetMemblockFloat(gMesh[meshId].memBlock,offVertex + gMesh[meshId].offsetVertexNormal + 8, normal.z)
endfunction
// ****************************************************
// Get Vertex UVs
// ****************************************************
function getMeshVertexUV(meshId as integer, vertexId as integer, UV ref as tUV)
offVertex = gMesh[meshId].offsetVertex + (vertexId * gMesh[meshId].sizeVertex)
UV.x = GetMemblockFloat(gMesh[meshId].memBlock,offVertex + gMesh[meshId].offsetVertexUV)
UV.z = GetMemblockFloat(gMesh[meshId].memBlock,offVertex + gMesh[meshId].offsetVertexUV +4)
endfunction
// ****************************************************
// Set Vertex UVs
// ****************************************************
function setMeshVertexUV(meshId as integer, vertexId as integer, UV ref as tUV)
offVertex = gMesh[meshId].offsetVertex + (vertexId * gMesh[meshId].sizeVertex)
SetMemblockFloat(gMesh[meshId].memBlock,offVertex + gMesh[meshId].offsetVertexUV, UV.x)
SetMemblockFloat(gMesh[meshId].memBlock,offVertex + gMesh[meshId].offsetVertexUV +4, UV.z)
endfunction
function logMeshData(id)
local arrPos as tVector
local arrUV as tUV
log("*********************************")
log("*********** Mesh Data **************")
log("*********************************")
log("Mesh " + chr(9) + str(gMesh.length))
log("Memblock " + chr(9) + str(gMesh[id].memblock))
//Create header data
log("Vertices " + chr(9) + str(gMesh[id].numVertices))
log("Indices " + chr(9) + str(gMesh[id].numIndices))
log("Attributes " + chr(9) + str(gMesh[id].numAttributes))
log("Vtx Size " + chr(9) + str(gMesh[id].sizeVertex))
log("Vtx Start " + chr(9) + str(gMesh[id].offsetVertex))
log("Index Start " + chr(9) + str(gMesh[id].offsetIndex))
log("Vtx Offset " + chr(9) + str(gMesh[id].offsetVertexPosition))
log("Norm Offset " + chr(9) + str(gMesh[id].offsetVertexNormal))
log("UV Offset " + chr(9) + str(gMesh[id].offsetVertexUV))
for n = 1 to gMesh[id].numAttributes
log (" *** ATTRIBUTE *** " + str(n))
log("DataType " + chr(9) + str(gMesh[id].attribute[n].dataType))
log("Comp Count " + chr(9) + str(gMesh[id].attribute[n].componentCount))
log("Normalise " + chr(9) + str(gMesh[id].attribute[n].normalise))
log("Str Length " + chr(9) + str(gMesh[id].attribute[n].stringLength))
log("String " + chr(9) + gMesh[id].attribute[n].attributeString)
next n
log("*********************************")
log("********* Vertex positions ************")
log("*********************************")
for n = 0 to getMeshVertexCount(id) - 1
getMeshVertexPosition(id, n, arrPos)
log("Vertex " + str(n) + chr(9) + str(arrPos.x,1)+ chr(9) + str(arrPos.y,1)+ chr(9) + str(arrPos.z,1))
next n
log("*********************************")
log("********* Vertex normals ************")
log("*********************************")
for n = 0 to getMeshVertexCount(id) - 1
getMeshVertexNormal(id, n, arrPos)
log("Vertex " + str(n) + chr(9) + str(arrPos.x,1)+ chr(9) + str(arrPos.y,1)+ chr(9) + str(arrPos.z,1))
next n
log("*********************************")
log("********* Vertex UV ************")
log("*********************************")
for n = 0 to getMeshVertexCount(id) - 1
getMeshVertexUV(id, n, arrUV)
log("Vertex " + str(n) + chr(9) + str(arrUV.x,3)+ chr(9) + str(arrUV.z,3))
next n
endfunction
#constant cMESH_NUM_VERTICES = 0
#constant cMESH_NUM_INDICES = 4
#constant cMESH_NUM_ATTRIBUTES = 8
#constant cMESH_SIZE_VERTEX = 12
#constant cMESH_OFFSET_VERTEX = 16
#constant cMESH_OFFSET_INDEX = 20
#constant cMESH_OFFSET_ATTRIBUTES = 24
#constant cMESH_DATATYPE_FLOAT = 0
#constant cMESH_DATATYPE_BYTE = 1
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt