|
Post by xteraco not logged on Jan 25, 2006 7:33:13 GMT -5
i come to visit here every now and then... just to see whats up..and if toms got that sound emplemented yet anyhoo, seems like everytiime i come here, i see a question about how to load up a 3d model... so heres my answer to that THERE IS NO SYNTAX FOR LOADING A 3D MODEL, IT IS NOT AS EASY AS LOADING A TEXTURE, OR WAV SAMPLE!! it will take some brainpower (i can here the crowds gasping in disgust already) there is nno function called load3d where you can just type load3d(modelname.3ds) or anything l ke that, unless tom has added newe features he didnt mention for 06 there.. i said it... that makes me feel a lot bettter... telling people that there is no all simple load3d command feels like i'm telling children that there is no santa.... oh well if your looking for a language that is a bit easyer to work with as far as 3d models goes, you might try darkBASIC, i'm not sure how to load a model with it, but i'm fairly sure it does have a command for loading .x files... and you can convert just about any 3d file into .x but like i said, dont ask me cause its been eons sinse i've coded in DB i would be remiss if i didnt come and say outrighht... You'll make yourself a better coder if you learn to load models w/ b4gl instead of running and hiding behind DB's cushy features... loading models can be donen with b4gl, it just takes brainpower... if you look around this forum... i did an example with my logo rotating around and stuff... well the 3d coordinates for that came from a 3d model i made... so i know first hand that it CAN be dont... jus takes time welp, i've horrified the children enough i think.. . it was nice to come on here and tatlk at everybody and to tom... pleeease Subs' and Functions and bass lib to
|
|
stu
Posts a bit
Posts: 150
|
Post by stu on Jan 25, 2006 12:07:08 GMT -5
If I had just seen a similar response to previous threads about it, I wouldn't have asked. I didn't specifically ask for a simple command, I asked for the simplest way. But, I won't trouble you all any longer. It's better for one to learn by themselves anyway
|
|
|
Post by STT on Jan 26, 2006 5:29:16 GMT -5
There's no santa? You lie!
*cry*
I agree with both of you completly, it takes brain power to make basic4gl load 3d models, and the rewards are so much better when you do it yourself. I, myself, have created my own 3D system which uses two different files to create a many frame animation. I'm telling you all, it ain't hard.
|
|
stu
Posts a bit
Posts: 150
|
Post by stu on Feb 5, 2006 1:58:05 GMT -5
Heh, well I know I said the whole "learn by one's self" thing, but I was looking at MD2 Viewers and Wavefront viewers, does anyone have an actual .bgm viewer? Is the concept the same? I don't know, I feel like I just need a little point in the right direction to get me going on this.
|
|
|
Post by Tom Mulgrew on Feb 5, 2006 17:25:16 GMT -5
Have a look on the demos page for a game called "Beams". The top part of that program is a bgm loader and renderer. Copy the lines from the top down to (and including) this part: Start: '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Into your own program. You can now add your own code to load and draw bgm models. To load a model: ' Allocate models dim BGM_Model &myModel dir$ = "files\" filename$ = "modelname.bgm": gosub LoadBGM &myModel = &model To draw a model: &model = &myModel: gosub DrawBGM For example, this code (when appended to the bgm loading part and saved in the same directory as the Beams game) will load and display the spaceship: ' Allocate models dim BGM_Model &shipModel ' Load models dir$ = "files\" ' Load ship model filename$ = "brship.bgm": gosub LoadBGM &shipModel = &model ' Enable OpenGL lighting so we can see the shape glEnable(GL_LIGHTING) glEnable(GL_LIGHT0) glEnable (GL_COLOR_MATERIAL)
' Animation loop dim ang# while true glClear(GL_DEPTH_BUFFER_BIT or GL_COLOR_BUFFER_BIT) glLoadIdentity() glTranslatef(0, 0, -4) glRotatef(25, 1, 0, 0) glRotatef(ang#, 0, 1, 0)
' Draw the model glColor3f(.5, .5, 1) &model = &shipModel: gosub DrawBGM SwapBuffers() while SyncTimer(10) ang# = ang# + 1 wend wend I should point out that there's nothing special about the bgm format. It's just something I made up for the beams game, because my .wav loading code was a bit too slow. -Tom
|
|
stu
Posts a bit
Posts: 150
|
Post by stu on Feb 6, 2006 21:05:27 GMT -5
Thanks a lot! I'll have to study this one over, but it works great!
|
|
|
Post by Supermonkey on Feb 7, 2006 13:08:34 GMT -5
I'll sticky this, since although you may not have expressed your frustrations in the best way it was needed, there are way too many posts about this ;D.
|
|
|
Post by Nicky Peter Hollyoake on Dec 24, 2006 17:33:32 GMT -5
A few questions
1. if you make a model do you have to make one for walk, climbing, pick up items for whatever you want?
2. do you have to use different codes for different model file types?
3. do you thik you could put a step-by-step tutorial for people that don't know how to do this? I know it will take a while for a tutorial to be made on this but it wold come in very handy I wana learn how to load models.
4. if people are going on about making a 'LoadModel' and 'DrawModel' then how does the collision work on it? when theres no X, Y or Z on it? probaly dumb question but I don't how how these models work.
[glow=red,2,300]Nicky[/glow]
|
|
|
Post by davy on Dec 24, 2006 18:08:12 GMT -5
Models still have an X,Y,Z even though they get translated and rotated to where they are.
Model loading can be quite complex... Possibly the easiest to load is the wavefront ".obj" models. Unfortunately... It isn't a very standardized format (some modeling programs don't save to the same format). But, typically, the file looks like this...
v 0 1 0 v 1 0 0 v 0 0 1 f 1 2 3
Now, any line that starts with a "v" means that it is defining a vertex, so it will be followed by an x, y, z value for that vertex. Any line that begins with an "f" means that it's a face, and will be followed by 3 or 4 numbers which represent the vertices that face it connecting. That model above would make a triangle connecting the points (0,1,0)-(1,0,0)-(0,0,1)
The easiest way to read these files is with the ReadText command. You will want a loop that looks like this...
do x = readtext if x="v" then vertcount = vertcount + 1 vert(vertcount)(0)=val(readtext) vert(vertcount)(1)=val(readtext) vert(vertcount)(2)=val(readtext) endif
if x = "f" then facecount = facecount + 1 face(facecount)(0)=val(readtext) face(facecount)(1)=val(readtext) face(facecount)(2)=val(readtext) endif
loop until EndOfFile
Naturally, that's not real code, but it should give you an outline of how the model loader works. You will first read token (which is basically what the readtext command does) if that token equals "v", then the next three tokens will be the X,Y,Z of that vertex... If it reads "f" then the next three will be the index of the connecting vertices. That psuedocode example assumes that each face only has three vertices in it, no quads. It's easier to do things this way. Hopefully that clears things up a little...
Now, the different position thing... For most model formats you will need the model in separate poses in order to animate them. Then there is a simple process of mathematically interpolating the vertices between the poses. I would worry about learning to load and render them first.
And, yes... You need different code for all different model types. Although, you could make a pointer to an array and use the compilefile command to execute code from one of several external files (one for each model format you want to support). That way it could be more modular and out of your way.
Another thing... When you are loading a model you will need two arrays, one for the vertices, and one for the faces. The vertex array will have to be floating point (it's name must end with a "#") and the face should be integer (no "#" at end of array name). You will either have to give them a lot of room to start with (dim them both to a really high number) or load the file first without the arrays counting how many verts and faces there are, then dim the arrays to those counts.
I can post some example code if you'd like. BTW, what modeling program are you using? I advise blender (it outputs to one of the good wavefront ".obj" formats too, the one I just explained... And it's free)
|
|
stu
Posts a bit
Posts: 150
|
Post by stu on Dec 24, 2006 18:45:01 GMT -5
Maybe this should be posted in the wiki. It might make it easier for people to find what they need. Currently there's nothing on there explaining 3D model loading. I might be able to do a little something for it, but it would basically be what davy has here (since he taught me what I know of model loading )
|
|
|
Post by Nicky Peter Hollyoake on Dec 24, 2006 18:52:09 GMT -5
I have none now I use to have 1 but I uninstalled it 'case I didn't now how to do it anyways, but i'll use the one youuse what site is it? Oh yeah can you do some more axampls ill love that thanks.
|
|
|
Post by nerd321 on Jun 23, 2007 2:17:20 GMT -5
anim8or (www.anim8or.com) imports and exports .an8, .3ds, .obj and .lwo models. I am making a simple program where you walk around in a world made in Anim8or. I got the camera movement from the demos and now all I need is a code that will import .obj models....
|
|
|
Post by matthew on Jun 23, 2007 2:33:19 GMT -5
^^ Look in this Thread.
|
|
|
Post by smc44 on Feb 24, 2008 14:48:03 GMT -5
hey tom that code to load a model wont work for me it says this expected ',' and wont compile somone plz tell me why
|
|
|
Post by smc44 on Feb 24, 2008 14:50:46 GMT -5
also could u help me produce a game tom mulgrew im new im only 14 but i really want to make a video game if u have time can u help me learn basic4GL language i also have a story for a game and am ready to make one i need somone like u to help me actually make a game if u have time thanx
|
|