Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » How can I load 3d models?

This thread is locked; no one can reply to it. rss feed Print
 1   2 
How can I load 3d models?
tommy tinpo
Member #4,827
July 2004

I don't know how can I load 3d models, and if I can make them whith a specific program such as: 3d studio etc....

tnx a lot at all!
and excuse me for my poor English!:'(

X-G
Member #856
December 2000
avatar

Find file format somewhere. Read it and parse into your mesh structure. Where is the problem here? You need to ask a more specific question.

--
Since 2008-Jun-18, democracy in Sweden is dead. | 悪霊退散!悪霊退散!怨霊、物の怪、困った時は ドーマン!セーマン!ドーマン!セーマン! 直ぐに呼びましょう陰陽師レッツゴー!

23yrold3yrold
Member #1,134
March 2001
avatar

Right. Just create the data structure to load the data into, then load the file into it, and you're done.

--
Software Development == Church Development
Step 1. Build it.
Step 2. Pray.

gnolam
Member #2,030
March 2002
avatar

I agree with Secretary of State X-G.

Anyway, for a file format to implement I suggest the Wavefront OBJ format - it's an ASCII format, and about as simple as a 3d model format can be (at least if you ignore the NURBS stuff). And as a bonus, most decent modelers can export to .obj so you won't have to write your own converters.

--
Move to the Democratic People's Republic of Vivendi Universal (formerly known as Sweden) - officially democracy- and privacy-free since 2008-06-18!

Thomas Harte
Member #33
April 2000
avatar

Grrrr, and I wasted my life on a 3ds importer!

tommy tinpo
Member #4,827
July 2004

I understand what you say, but now, can you suggest me some tutorials of allegro opengl or something about 3d programming with allegro?

FMC
Member #4,431
March 2004
avatar

tutorials about OpenGL: NEHE
allegrogl version of nehes tutorials: http://www.allegrodeveloper.org/

also have a look at the redbook(programming guide for opengl) and at the bluebook(reference for opengl)

[FMC Studios] - [Caries Field] - [Ctris] - [Pman] - [Chess for allegroites]
Written laws are like spiders' webs, and will, like them, only entangle and hold the poor and weak, while the rich and powerful will easily break through them. -Anacharsis
Twenty years from now you will be more disappointed by the things that you didn't do than by the ones you did do. So throw off the bowlines. Sail away from the safe harbor. Catch the trade winds in your sails. Explore. Dream. Discover. -Mark Twain

tommy tinpo
Member #4,827
July 2004

Somebody can suggest me a program to convert 3d models into file to parse into mesh structure.

thanks a lot at all!

X-G
Member #856
December 2000
avatar

3D models ARE files you can parse into a mesh structure. What do you need?

--
Since 2008-Jun-18, democracy in Sweden is dead. | 悪霊退散!悪霊退散!怨霊、物の怪、困った時は ドーマン!セーマン!ドーマン!セーマン! 直ぐに呼びましょう陰陽師レッツゴー!

FMC
Member #4,431
March 2004
avatar

Game Tutorials scroll down the page, you will find tutorials on how to load some 3d models format in your prog

[FMC Studios] - [Caries Field] - [Ctris] - [Pman] - [Chess for allegroites]
Written laws are like spiders' webs, and will, like them, only entangle and hold the poor and weak, while the rich and powerful will easily break through them. -Anacharsis
Twenty years from now you will be more disappointed by the things that you didn't do than by the ones you did do. So throw off the bowlines. Sail away from the safe harbor. Catch the trade winds in your sails. Explore. Dream. Discover. -Mark Twain

tommy tinpo
Member #4,827
July 2004

I have another problem... I have a 3d model with 2 animations, how can I use the animations of the model?:P

X-G
Member #856
December 2000
avatar

Load both and display them at the appropriate time, of course.

Ask more specific questions, damn it. :P

--
Since 2008-Jun-18, democracy in Sweden is dead. | 悪霊退散!悪霊退散!怨霊、物の怪、困った時は ドーマン!セーマン!ドーマン!セーマン! 直ぐに呼びましょう陰陽師レッツゴー!

tommy tinpo
Member #4,827
July 2004

Mithrandir I have sent you a private message!

Rampage
Member #3,035
December 2002
avatar

Quote:

Mithrandir I have sent you a private message!

Ah, the irony...

-R

Archon
Member #4,195
January 2004
avatar

Ive been trying to load 3D models but I just use someone elses ;). But the code to load a MD2 format (or MDL or MD3) are like 5 pages long :-\

deps
Member #3,858
September 2003
avatar

So? Start typing! :)

---
Layers are good, all good things have layers, like onions. Good things also stink. - Trezker
I now have a page and a blog!

Archon
Member #4,195
January 2004
avatar

I WOULD but, I like stuff to be easy but with control. Thats why I wanna dissect the MD2 Loader and make it a header that I can use in any AllegroGL project... Instead of full on DirectX

pantz
Member #3,387
March 2003

MD2 is actually a pretty easy format to load and display. The downside is that it's pretty aged and still uses frames and not a skeletal animation system. I hacked up a small MD2 loader last weekend for my game, to see how hard it actually is to load/display them. (see attached file) It uses C++, Allegro and AllegroGL, and it's not 5 pages long ;) It could be even shorter by using a single fread to load the data. Anyway, maybe it gets you started.

Some things to note:
- the animation is hard-coded to the single "stand" animation of the model. There's a list with the different animations and how many frames they use somewhere

- the animation is a bit bumpy, that's because only the key frames are displayed, there is no interpolation done

- it's my first try at MD2 and 3d models in general, so it's not perfect ;)

Archon
Member #4,195
January 2004
avatar

Hmm, I envy your ability to learn something Im TRYING to learn pantz. I downloaded your MD2 example but I am having problems with Allegro.h for some reason... Never done this before

--------- EDIT -----------
BTW, any other stuff youve integrated into Allegro / AllegroGL that might be useful for me? :D

--------- UPDATE ------------
Ok, I fixed the problem by removing the includes to stdio.h and string.h.
And it says the FPS is 100 - 130, but I see what you mean by its jumpy. Would you know how to fix it?

pantz
Member #3,387
March 2003

Do you have vsync on? I get like 1400fps without vsync. To get smooth movement you have to interpolate between the current frame and the next frame. That means computing the vertices of the triangles on your own, depending on the display duration between the single keyframes.

Archon
Member #4,195
January 2004
avatar

You didnt do that? :(

And NFI whether I do :-\

--------- EDIT ---------
Ok, I think Im having troubles with the fread stuff but thats coz i skipped a chapter in my ironically correct book "Complete Idiots Guide to C++" :P

--------- EDIT 2 ---------
Ok, It is starting to make sense as I am using a hex editor + reading the code...

pantz
Member #3,387
March 2003

I didn't implement it because it was just a test and my game will only need few (if any at all) animations, it's a space shooter :)

But it shouldn't be that hard to implement it. I think all you have to do is to get the difference between each current vertex and the next vertex, divide this distance by the number of steps (smoothness) and add this number to the current vertex position.

steps = 10
distance = new_x - old_x
amount = distance / steps
vertex_x = old_x + amount

for x, y and z. Maybe it's easier to use vectors though.

Archon
Member #4,195
January 2004
avatar

Its all making sense now!!! But since I havent read all of MD2.cpp, which function would that go in?
Also I dont know what the 'status' is of vsync.

-------- EDIT --------
OK, I am getting the hang of this... Are all models loaded like this (but different ways). I mean like they all have structs of vertices, triangles etc and rendered a similar way?

Tobias Dammers
Member #2,604
August 2002
avatar

No, some do also feature NURBS and other mathematical surfaces that can either be passed to the GL or transformed into poly's at run-time.
There are also a few games (very few, actually) that use some kind of voxel models, especially for terrain.

---
Me make music: Triofobie
---
"We need Tobias and his awesome trombone, too." - Johan Halmén

Archon
Member #4,195
January 2004
avatar

I think I mightve hijacked the thread... :-/

tommy tinpo: Did you try out pantz's MD2 (Quake 2 Models) loader?

 1   2 


Go to: