Jump to content

  • Log In with Google      Sign In   
  • Create Account

Loading 3ds Model (MultiObjects)


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 FlyingDutchman   Members   -  Reputation: 207

Like
0Likes
Like

Posted 19 August 2011 - 06:30 PM

EDIT: SOLUTION ONE POST FURTHER!!!!
Hello everybody..

for my 3d engine i've written a loader for 3ds models based on some tutorial i found on the net called spacesimulator or s.th. like this .-). It works perfectly fine when i import a model which consists out of one mesh.. texture and model will be displayed correctly. But when i load in an object which consists of multiple meshes, lets say a car.. which consists out of the main part and 4 weels, only one wheel gets rendered and the rest of the 4 parts not. i probably think that this is because i need to read out the other meshes as well and displaying them.

the 3ds file looks like this:
[size=2]|  +--EDIT_OBJECT   (0x4000)[/size]

[size=2]              	|  |  |[/size]

[size=2]              	|  | +--OBJ_TRIMESH   (0x4100)  	[/size]

[size=2]              	|  | |  |[/size]

[size=2]              	|  | |  +--TRI_VERTEXL      	(0x4110) [/size]

[size=2]              	|  | |  +--TRI_VERTEXOPTIONS	(0x4111)[/size]

[size=2]              	|  | |  +--TRI_MAPPINGCOORS 	(0x4140) [/size]

[size=2]
[/size]

and i read out 4110 to 4140 like this:

a

[/size][/font]

[font="'Courier New"][size="2"]while blabla: switch (chunk_id)

		case 0x4100:			// Object Trimesh

			break;

		case 0x4110:			// Tri Vertex (Vertices List)

			fread(&l_qty, sizeof(unsigned short), 1, l_file);

			this->vertices_qty = l_qty;

			

			for (i = 0; i < l_qty; i++)

			{

				fread(&this->vertex[i].x, sizeof(float), 1, l_file);

				fread(&this->vertex[i].y, sizeof(float), 1, l_file);

				fread(&this->vertex[i].z, sizeof(float), 1, l_file);

			}

			break;

		case 0x4120:

			fread(&l_qty, sizeof(unsigned short), 1, l_file);

			this->polygons_qty = l_qty;

			

			for (i = 0; i < l_qty; i++)

			{

				fread(&this->polygon[i].a, sizeof(unsigned short), 1, l_file);

				fread(&this->polygon[i].b, sizeof(unsigned short), 1, l_file);

				fread(&this->polygon[i].c, sizeof(unsigned short), 1, l_file);

				fread(&l_face_flags, sizeof(unsigned short), 1, l_file);

			}

			break;

		case 0x4140:

			fread(&l_qty, sizeof(unsigned short), 1, l_file);

			for (i = 0; i < l_qty; i++)

			{

				fread(&this->mapcoord[i].u, sizeof(float), 1, l_file);

				fread(&this->mapcoord[i].v, sizeof(float), 1, l_file);

			}

			break;

		default:

			fseek(l_file, l_chunk_length-6, SEEK_CUR);

		}

	}

	fclose(l_file);






It wonders me that i skip through the different vertices, polygons and tex coordinates but not through the object. where in the 3ds files are they defined then? so where is the point where the next objects begins...

Hope someone can help me.. it would really like to understand the concept ..
For completeness: Thats how i draw them:



[size="2"]	glBindTexture(GL_TEXTURE_2D, this->texture->get_texture());[/size]
[size="2"]
[/size]
[size="2"]	glBegin(GL_TRIANGLES);[/size]
[size="2"]	for (unsigned int i = 0; i < this->polygons_qty; i++)[/size]
[size="2"]	{[/size]
[size="2"]		glTexCoord2f(this->mapcoord[this->polygon[i].a].u,[/size]
[size="2"]	                 this->mapcoord[this->polygon[i].a].v);[/size]
[size="2"]		glVertex3f(this->vertex[this->polygon[i].a].x,[/size]
[size="2"]                   this->vertex[this->polygon[i].a].y,[/size]
[size="2"]                   this->vertex[this->polygon[i].a].z);[/size]
[size="2"]
[/size]
[size="2"]		glTexCoord2f(this->mapcoord[this->polygon[i].b].u,[/size]
[size="2"]	                 this->mapcoord[this->polygon[i].b].v);[/size]
[size="2"]		glVertex3f(this->vertex[this->polygon[i].b].x,[/size]
[size="2"]                   this->vertex[this->polygon[i].b].y,[/size]
[size="2"]                   this->vertex[this->polygon[i].b].z);[/size]
[size="2"]
[/size]
[size="2"]		glTexCoord2f(this->mapcoord[this->polygon[i].c].u,[/size]
[size="2"]	                 this->mapcoord[this->polygon[i].c].v);[/size]
[size="2"]		glVertex3f(this->vertex[this->polygon[i].c].x,[/size]
[size="2"]                   this->vertex[this->polygon[i].c].y,[/size]
[size="2"]                   this->vertex[this->polygon[i].c].z);[/size]
[size="2"]	}[/size]
[size="2"]	glEnd();[/size]
[size="2"]
[/size]
Regards

Markus


I open sourced my C++/iOS OpenGL 2D RPG engine :-)


See my blog: (Tutorials and GameDev)

http://howtomakeitin....wordpress.com/


Sponsor:

#2 FlyingDutchman   Members   -  Reputation: 207

Like
0Likes
Like

Posted 20 August 2011 - 06:34 AM

Hello.. I just wanted to let you guys know that i solved the problems!!!!

the solution was actually pretty simple.. everytime when the parser goes through 0x4100 -> OBJECT TRIMESH

it begins to read a new Object.. so the chain is

object 1
0x4000 -> 0x4100 -> vertices, polygon, faces

object 2
0x4000 -> 0x4100 -> vertices, polygon, faces

and so on...

now everytime when i am in 0x4000 i increase my object counter and write all the future information in Objects[object_counter]..

Objects is a struct which containts vertices, polygons & tex coordinates..

by drawing i do the same!!

here is part of the code:



case 0x4000:			// Edit_Object
			i = 0;
			do
			{
				fread(&l_char, 1, 1, l_file);
				this->object[offset].name[i]=l_char;
				i++;
			} while(l_char != '\0' && i < 20);

			break;
		case 0x4100:			// Object Trimesh
			offset = this->objects_qty;
			this->objects_qty+=1;					// by car we go in here 5 times
			
			break;
		case 0x4110:			// Tri Vertex (Vertices List)
			fread(&l_qty, sizeof(unsigned short), 1, l_file);

			for (i = 0; i < l_qty; i++)
			{
				fread(&this->object[offset].vertex[i].x, sizeof(float), 1, l_file);
				fread(&this->object[offset].vertex[i].y, sizeof(float), 1, l_file);
				fread(&this->object[offset].vertex[i].z, sizeof(float), 1, l_file);
			}

			this->object[offset].vertices_qty = l_qty;
			

and for drawing:



glBegin(GL_TRIANGLES);
	for (unsigned int j = 0; j < this->objects_qty; j++)
	{
		for (unsigned int i = 0; i < this->object[j].polygons_qty; i++)
		{
			glTexCoord2f(this->object[j].mapcoord[this->object[j].polygon[i].a].u,
						 this->object[j].mapcoord[this->object[j].polygon[i].a].v);
			glVertex3f(this->object[j].vertex[this->object[j].polygon[i].a].x,
					   this->object[j].vertex[this->object[j].polygon[i].a].y,
					   this->object[j].vertex[this->object[j].polygon[i].a].z);

			glTexCoord2f(this->object[j].mapcoord[this->object[j].polygon[i].b].u,
						 this->object[j].mapcoord[this->object[j].polygon[i].b].v);
			glVertex3f(this->object[j].vertex[this->object[j].polygon[i].b].x,
					   this->object[j].vertex[this->object[j].polygon[i].b].y,
					   this->object[j].vertex[this->object[j].polygon[i].b].z);

			glTexCoord2f(this->object[j].mapcoord[this->object[j].polygon[i].c].u,
						 this->object[j].mapcoord[this->object[j].polygon[i].c].v);
			glVertex3f(this->object[j].vertex[this->object[j].polygon[i].c].x,
					   this->object[j].vertex[this->object[j].polygon[i].c].y,
					   this->object[j].vertex[this->object[j].polygon[i].c].z);

		}
	}
	glEnd();


and this is how the class looks like:


class Object3ds : public Mesh
{
private:
	typedef struct 
	{
		float x;
		float y;
		float z;
	} vertex_type;

	typedef struct 
	{
		unsigned short a;
		unsigned short b;
		unsigned short c;
	} polygon_type;

	typedef struct 
	{
		float u;
		float v;
	} mapcoord_type;

	float scalex;
	float scaley;
	float scalez;

	struct tObject
	{
		vertex_type vertex[MAX_VERTICES];
		mapcoord_type mapcoord[MAX_VERTICES];
		polygon_type polygon[MAX_POLYGONS];
		unsigned int vertices_qty;
		unsigned int polygons_qty;
		char name[20];
	}; 

	tObject object[30];
	unsigned int objects_qty;


public:
	Object3ds(char *filename, char *_texture);
	Object3ds(char *filename, char *_texture, float _scalex, float _scaley, float _scalez);

	bool Load3DS(char *filename);
	void draw();
};

THANKS TO THE HOLY DEBUGGER OF VISUAL C++ ;-) I spent ours of analyizing this f**** parser structure..

regards
Markus

I open sourced my C++/iOS OpenGL 2D RPG engine :-)


See my blog: (Tutorials and GameDev)

http://howtomakeitin....wordpress.com/


#3 luckyyyyyy   Members   -  Reputation: 144

Like
0Likes
Like

Posted 13 October 2012 - 10:09 AM

.

Edited by luckyyyyyy, 13 October 2012 - 12:31 PM.


#4 luckyyyyyy   Members   -  Reputation: 144

Like
0Likes
Like

Posted 13 October 2012 - 12:29 PM

I can successfully read and load the objects like ur code. But I am unable to read Color info.. means color of objects that we reading from the file.
actually there are many ways to read 3DS chunks on the internet but in our way how can we read color info ?
U can see my code here..
//OBJ_TRIMESH
//TRI_VERTEXL
//TRI_FACEL1
//TRI_MAPPINGCOORS
case 0xa020: // diffuse color
if(1)
{
case 0×0010: // Color F
fread (&red, sizeof(float), 1, l_file);
fread (&green, sizeof(float), 1, l_file);
fread (&blue, sizeof(float), 1, l_file);
//if (!ReadFloat(fp, red)) return FALSE;
//if (!ReadFloat(fp, green)) return FALSE;
//if (!ReadFloat(fp, blue)) return FALSE;
break;
case 0×0011: // Color 24
fread (&red, sizeof(float), 1, l_file);
fread (&green, sizeof(float), 1, l_file);
fread (&blue, sizeof(float), 1, l_file);
//if (!ReadUByte(fp, tmp)) return FALSE;
//red = (float) tmp / (float) 255.0;
//if (!ReadUByte(fp, tmp)) return FALSE;
//green = (float) tmp / (float) 255.0;
//if (!ReadUByte(fp, tmp)) return FALSE;
//blue = (float) tmp / (float) 255.0;
break;
}
break;



Think of Design with Dimensions
http://real3d.pk






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS