I think the problem is maybe caused by the call to:
Code: Select all
bool Load(scene::IAnimatedMesh* mesh, const SPEVector& Scale=SPEVector(1,1,1))
{
//Get number of vertices
u32 nMeshBuffer;
for( nMeshBuffer = 0 ; nMeshBuffer < mesh->getMeshBufferCount(); ++nMeshBuffer)
{
scene::IMeshBuffer *buffer = mesh->getMeshBuffer(nMeshBuffer);
NumVertices += buffer->getVertexCount();
}
pVertex = new SPEVertex[NumVertices]; // causes bad allocation of memory.
u32 n;
for( n = 0 ; n < mesh->getMeshBufferCount(); ++n)
{
scene::IMeshBuffer *buffer2 = mesh->getMeshBuffer(n);
NumIndices += buffer2->getIndexCount();
}
pIndex = new int[NumIndices];
NumFaces = NumIndices / 3;
for(int i=0; i<NumVertices; i++)
{
pVertex[i].p.x*=Scale.x;
pVertex[i].p.y*=Scale.y;
pVertex[i].p.z*=Scale.z;
}
return true;
}
because I am trying to do in Irrlicht what is done in opengl in the first SPE sample:
Code: Select all
bool Load(char *FileName, const SPEVector& Scale=SPEVector(1,1,1))
{
FILE *fp=0;
fp=fopen(FileName,"rb");
if(!fp)
{
MessageBox(0, "Model file not found!", "GLMesh", 0);
return false;
}
fread(&NumVertices, sizeof(int), 1, fp);
pVertex=new SPEVertex[NumVertices];
fread(pVertex, sizeof(SPEVertex)*NumVertices, 1, fp);
int n;
fread(&n, sizeof(int), 1, fp);
pIndex=new int[n];
fread(pIndex, sizeof(int)*n, 1, fp);
NumFaces=n/3;
fclose(fp);
for(int i=0; i<NumVertices; i++)
{
pVertex[i].p.x*=Scale.x;
pVertex[i].p.y*=Scale.y;
pVertex[i].p.z*=Scale.z;
}
return true;
}
This is done so that one is able to make this call to:
Code: Select all
pShape->Initialize ((BYTE*)Mesh.pVertex, sizeof(SPEVertex), Mesh.pIndex, Mesh.NumFaces );
the documents say that the definition and usage of virtual SPERESULT Initialize is:
Code: Select all
struct ISPEShape
{
virtual SPERESULT Initialize(BYTE *pVertex, int StrideSize, int *pIndex, int NumTriangles) = 0;
Create a shape from tri-mesh data.
Parameters
pVertex
[in] Pointer to vertex buffer.
StrideSize
[in] Stride of one vertex, in bytes.
pIndex
[in] Pointer to index buffer, index must be 32BIT.
NumTriangles
[in] Number of triangles.
Return
SPE_OK if the method succeeds, else return SPE_FAILED.
How would I then correctly write the Load() to get the correct information
for Initialize(), using Irrlicht to abstract this data instead of opengl?