Lately, I have been working to resurrect an old open source game. My main problem is it uses a custom format: VW3D. The following code snippet is used to load the model from its File System. Is it possible to reconstruct the model format (and convert it) from the below snippet? I have no idea how I would go about this and would appreciate any pointers. My hope is to be able to construct a script to convert to/from this format (Planning for vw3d to obj and vice versa)
void eModel3D::ReadVW3D(const char *nName)
{
eFILE *file = 0;
file = vw_fopen(nName);
if (file == 0) return;
size_t SizeB = strlen(nName)+1;
Name = new char[SizeB];
strcpy(Name, nName);
// пропускаем заголовок / skip header
file->fread(&DrawObjectCount, 4, 1);
// читаем, сколько объектов read how many objects
file->fread(&DrawObjectCount, sizeof(int), 1);
DrawObjectList = new eObjectBlock[DrawObjectCount];
unsigned int GlobalRangeStart = 0;
// для каждого объекта for each object
for (int i=0; i<DrawObjectCount; i++)
{
DrawObjectList[i].RangeStart = GlobalRangeStart;
// FVF_Format
file->fread(&(DrawObjectList[i].FVF_Format),sizeof(int),1);
// Stride
file->fread(&(DrawObjectList[i].Stride),sizeof(int),1);
// VertexCount на самом деле, это кол-во индексов на объект In fact, this count of the index on an object
file->fread(&(DrawObjectList[i].VertexCount),sizeof(int),1);
GlobalRangeStart += DrawObjectList[i].VertexCount;
// Location
file->fread(&(DrawObjectList[i].Location),sizeof(float)*3,1);
// Rotation
file->fread(&(DrawObjectList[i].Rotation),sizeof(float)*3,1);
// рисуем нормально, не прозрачным draw a fine, not transparent
DrawObjectList[i].DrawType = 0;
// вертексный буфер Vertex Buffer
DrawObjectList[i].VertexBufferDestrType = 0;
DrawObjectList[i].VertexBuffer = 0;
DrawObjectList[i].VertexBufferVBO = 0;
// индексный буфер Index buffer
DrawObjectList[i].IndexBuffer = 0;
DrawObjectList[i].IndexBufferVBO = 0;
}
// получаем сколько всего вертексов get how many verticies
int VCount = 0;
file->fread(&VCount,sizeof(int),1);
// собственно данные actual data
GlobalVertexBuffer = new float[VCount*DrawObjectList[0].Stride];
file->fread(GlobalVertexBuffer, VCount*DrawObjectList[0].Stride*sizeof(float),1);
// индекс буфер I.B.
GlobalIndexBuffer = new unsigned int[GlobalRangeStart];
file->fread(GlobalIndexBuffer, GlobalRangeStart*sizeof(unsigned int),1);
// делаем общее VBO making the total VBO
GlobalVertexBufferVBO = new unsigned int;
if (!vw_BuildVBO(VCount, GlobalVertexBuffer, DrawObjectList[0].Stride, GlobalVertexBufferVBO))
{
delete GlobalVertexBufferVBO; GlobalVertexBufferVBO=0;
}
// делаем общий индекс VBO makes the overall index VBO
GlobalIndexBufferVBO = new unsigned int;
if (!vw_BuildIndexVBO(GlobalRangeStart, GlobalIndexBuffer, GlobalIndexBufferVBO))
{
delete GlobalIndexBufferVBO; GlobalIndexBufferVBO=0;
}
// устанавливаем правильные указатели на массивы establish the correct pointers to arrays
for (int i=0; i<DrawObjectCount; i++)
{
DrawObjectList[i].VertexBuffer = GlobalVertexBuffer;
DrawObjectList[i].VertexBufferVBO = GlobalVertexBufferVBO;
DrawObjectList[i].IndexBuffer = GlobalIndexBuffer;
DrawObjectList[i].IndexBufferVBO = GlobalIndexBufferVBO;
}
vw_fclose(file);
}
The code you've posted is pretty straight-forward. I especially enjoy the Cyrillic/English comment pairs. You probably can't fully convert back and forth between VW3d and Obj formats. It looks like VW3d is exclusively about geometry while the Obj format provides for textures, normals, and material properties too. Furthermore, I think Obj stores one object per file, while VW3d stores multiple objects, potentially re-using the same object geometry multiple times with different translations and rotations.
The functions, vw_BuildVBO and vw_BuildIndexVBO, are doing some key work, although I can guess at what they're doing, it'd be better to have access to them.
The other potential problem is in the 'Rotation' variable. It seems to be an array holding 3 floats. That suggests that they're using Euler rotation, but there are multiple ways to do that. If you wanted to make sure to orient the objects correctly, you'd need to understand a little more about how those three floats are used when drawing the object.