Jump to content
  • Advertisement
Sign in to follow this  
MrPickle

3DS Vertex List Chunk

This topic is 3668 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm having problems reading the Vertex List chunk of the 3DS model format. I keep getting numbers like: -1.#QNAN which I understand means "quiet not a number" and then numbers like 2.0345E-041, I think that's standard form? I followed this tutorial, http://www.spacesimulator.net/tut4_3dsloader.html, but I'm using C++ and i'm converting everything to little endian. Here's my code:
template <typename T> union Buffer {
	unsigned char bytes[sizeof(T)];
	T value;
};

bool isLittleEndian() {
	Buffer<unsigned short> b;
	b.value = 1;
	return (b.bytes[0] == 1);
}

template<typename T> void Read(T& value, std::ifstream& in) {
	Buffer<T> e;
	in.read(reinterpret_cast<char*>(&e.bytes[0]), sizeof(T));

	if(isLittleEndian()) {
		value = e.value;
		return;
	}
	
	char t;
	for(int i = 0, j = sizeof(T); i < j--; i++) {
		t = e.bytes;
		e.bytes = e.bytes[j];
		e.bytes[j] = t;
	}

	value = e.value;
}
while(in.tellg() < size) {
	Read<unsigned short>(info.ID, in);
	Read<int>(info.Size, in);
	info.Offset = in.tellg();

	switch(info.ID) {
		//...

		case VERTEX_LIST:
			int numVertices;
			Read<int>(numVertices, in);
			for(i = 0; i < numVertices; i++) {
				Read<FLOAT>(v.x, in);
				Read<FLOAT>(v.y, in);
				Read<FLOAT>(v.z, in);
				
				mesh.Vertices.push_back(v);
				v.x = v.y = v.z = 0.0f;
			}
			in.seekg(info.Offset + info.Size - 6);
			break;
		//...

		default:
			in.seekg(info.Size -6, std::ios_base::cur);
			break;
	}
}

Share this post


Link to post
Share on other sites
Advertisement
It's worth noting that 3DS is a pretty horrid and antiquated format, so you should avoid it if you can get your data in any other more modern form.

Share this post


Link to post
Share on other sites
Quote:
Original post by jpetrie
It's worth noting that 3DS is a pretty horrid and antiquated format, so you should avoid it if you can get your data in any other more modern form.


It was more of a test on loading files that aren't in human readable format. Thanks for the concern though.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!