DTS Format - primitives
by Leadwerks · in Torque Game Engine · 11/10/2005 (6:43 pm) · 0 replies
I am writing a .dts loading plugin for my editor. I am starting by writing a .dts loader in Blitz3D code, just so I can quickly test and make sure I am loading the files correctly. Everything seems fine, until I get to the meshes chunk, and get down to where the primitives are stored. Here is the section of code just before the primitives:
In DTSMesh.cpp, when this part is encountered, the code says "stream >> primitives ;" which I presume means the file is read directly into the primitives structure. According to DTSMesh.h, the primitives structure is two 16-bit WORD values, one for the first element, one for the number of elements, then a 32-bit DWORD. So 8 bytes total. I would expect the first two values to be something like 0 and 3 for a triangle or 0 and 4 for a quad. But the data looks completely different from anything I am expecting:
Here is the complete loader code. It passes all checkpoints, and gets the correct number of primitives. Copy this to a .bb file, and open it in Blitz. Place rock1.dts in the same directory as this code. Turn the debugger on and run the program:
www.leadwerks.com/post/LoadDTS.txt
Any insight into the primitives format would be greatly appreciated.
For v=1 To numVerts x#=ReadFloat(f) y#=ReadFloat(f) z#=ReadFloat(f) Next numTVerts=ReadInt(f) If numtverts<>numverts RuntimeError "numVerts<>numTVerts" For v=1 To numTVerts tu#=ReadFloat(f) tv#=ReadFloat(f) Next For v=1 To numVerts nx#=ReadFloat(f) ny#=ReadFloat(f) nz#=ReadFloat(f) Next numPrimitives=ReadInt(f) //Everything is fine up to this point, but below it all goes to hell For p=1 To numPrimitives firstElement=ReadShort(f) numElements=ReadShort(f) etype=ReadInt(f) DebugLog "firstElement="+firstElement DebugLog "numElements="+numElements DebugLog "type="+etype DebugLog "" Next
In DTSMesh.cpp, when this part is encountered, the code says "stream >> primitives ;" which I presume means the file is read directly into the primitives structure. According to DTSMesh.h, the primitives structure is two 16-bit WORD values, one for the first element, one for the number of elements, then a 32-bit DWORD. So 8 bytes total. I would expect the first two values to be something like 0 and 3 for a triangle or 0 and 4 for a quad. But the data looks completely different from anything I am expecting:
firstElement=0 numElements=24576 type=1610612736 firstElement=0 numElements=24576 type=1610612736 firstElement=0 numElements=24576 type=1610612736 firstElement=0 numElements=24576 type=1610612736 firstElement=0 numElements=24576 type=1610612736 firstElement=0 numElements=24576 type=1610612736 firstElement=0 numElements=24576 type=1610612736 firstElement=0 numElements=24576 type=1610612736 firstElement=0 numElements=24576 type=1610612736 firstElement=191 numElements=0 type=0 firstElement=94 numElements=0 type=0 firstElement=16 numElements=0 type=4 firstElement=0 numElements=0 type=17 firstElement=1 numElements=0 type=1 firstElement=65535 numElements=65535 type=-1064021205 firstElement=5597 numElements=49311 type=-1078757568 firstElement=22680 numElements=16515 type=1079277134 firstElement=63073 numElements=16429 type=-1098394472
Here is the complete loader code. It passes all checkpoints, and gets the correct number of primitives. Copy this to a .bb file, and open it in Blitz. Place rock1.dts in the same directory as this code. Turn the debugger on and run the program:
www.leadwerks.com/post/LoadDTS.txt
Any insight into the primitives format would be greatly appreciated.