Game Development Community

How to program Torque 3D models

by Bendik Stang · in Torque Game Engine · 08/31/2002 (4:16 am) · 35 replies

I'm making a openGL/C++ program that creates L-system based trees, and then drastically optimizes them with various Levels of Detail.

The idea is to make a plugin of some sort that will not take up much space, but once run, create as many trees as you like inside the game world.

I'm about to have the first part under control, but now I need to make it Torque compatible.
I have started to look at the 3DMax2DTS exporter code, but I have no clue about the 3DMax format either. So I figured that I might ask you guys if some one had a better alternative for me.
How do I learn how to create a map or dts like object inside the Troque code. Or should I totally circumvent those formats, and just make the models in openGL and stick them right into the game? If so, have anyone some code samples on this, that I could study?

(Eg, create an openGL CUBE in Troque, that is possible to manipulate using the ingame world editor....)

Any help here is appreciated! (You can read more about the project under my project page...)

:)
-Bendik
Page«First 1 2 Next»
#21
10/01/2002 (11:54 pm)
I have a problem with the vertex coloring.

glEnable(GL_COLOR_MATERIAL);
does not seem to enable the colors.
(I want the trunks to be darker at the bottom.)

Is there somthing else I have forgotten?
[EDIT]
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

Did it!
[/EDIT]

Melv (or any other genious):
How will Level of Detail work with fxRenderObject ?
How do enable automatic mipmap?

-Bendik
#22
10/02/2002 (7:34 am)
I figured out the multiple textures. And voila I have some better looking trees.

Mipmapping is the next essencial thing....and LOD.

On the forest image, I'm getting a rather drastic reduction in framerate. This is because the texture is 256x256 and there is no mipmap or LOD. (Fill limited)

www.student.dtu.dk/~c958608/ForestT.jpgLarge Version

www.student.dtu.dk/~c958608/mTreeT.jpgLarge Version

-B
#23
10/02/2002 (7:40 am)
Wow, that looks amazing!! Much better than I ever could model them... :P
Will you release this to the Torque community once you're done?
Keep it up!! :D
#24
10/02/2002 (10:27 am)
Bendik,

Sorry I've not been as responsive as I would normally be on the forums but I've been hyper-super-mega busy.

Just want to start by saying that your work so far is very impressive and has great potential. Creating real-world objects like trees using systems like these can be difficult and hard to get right. If you were to use this system to create alien-plants then you could really let creativity fly!

To answer your questions though ...

Quote:How will Level of Detail work with fxRenderObject?

I assume you mean how do you select which LOD to use when you are within the render function? If so, then all you need to do is reference the eye position with respect to the object position and select your LOD. You can see an example of this within my fxFoliageReplicator or in the water rendering code.

Quote:How do enable automatic mipmap?

Lookup the usage of gluBuild2DMipmaps in any OpenGL reference on the net to see how to build mipmaps., it's dead easy. You may also want to look at the texture parameters for trilinear options ...

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
else
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);

If you're dealing with GBitmaps then you will find the ability to allocate these from the constructor. You can then also extrude your base bitmap into the mip levels using something like bmp->extrudeMipLevels which will call the appropriate extrusion function. Note that the only supported image formats are RGB5551, RGB, RGBA & Palettized.

Hope this helps.

All the best,

- Melv.
#25
10/03/2002 (1:45 am)
I'm banging my head against a wall here.

mTextureHandle = NULL;    
mTextureHandle2 = NULL; 
// Load the texture (if we've got one)
if (*mTextureName) mTextureHandle = TextureHandle(mTextureName, BitmapTexture, true);

if (*mTextureName2) mTextureHandle2 = TextureHandle(mTextureName2, BitmapTexture, true);
		
GBitmap* tmpPtr;
tmpPtr = mTextureHandle.getBitmap();
tmpPtr->extrudeMipLevels();

This causes a crash upon game start.
I'm not very good with pointers, so I guess it's an obvious answer to this.

[Edit]
It was even easier than I thought. After looking at the waterblock code I tried this and it worked:

if (*mTextureName) mTextureHandle = TextureHandle(mTextureName, MeshTexture, true);

Obviously MeshTexture is automatically MipMapped, while the BitmapTexture is not.

[/edit]

-Bendik
#26
10/03/2002 (2:51 am)
Just saw your post. Is everything okay now?

- Melv.
#27
10/04/2002 (6:30 am)
Yes, and then no :)

I've come across another problem. The distance fog seme to be drawn before the xfRenderObjects.
So my trees don't fade into the fog, they instead stick out like a clown in a bootcamp.

:)

Any suggestions?

-Bendik
#28
10/04/2002 (6:39 am)
Bendik,

When you are inside the rendering function you need to deal with the rendering yourself. The Torque engine doesn't provide much in terms of support, simply the tools from which you get things done.

If you want fogging then you do it yourself by whatever means you require. If you want LOD then again, you do it yourself, unless of course you are talking about MIPMAPS.

Essentially, the fxRenderObject/Torque doesn't provide this level of support, in nearly all cases you do it yourself.

The open-ended approach to custom-object rendering may seem poor but it does allow you to do pretty much anything you require and can be very powerful. Combined with the SceneGraph and it's transform portals, it's *very* powerful.

Have a look at the render functions of various Torque objects to see how fogging/LOD is done. There are many different ways.

If you require specific help on getting your object fogged then drop me an email and I'll be sure to help out.

- Melv.
#29
10/04/2002 (7:21 am)
Thanks, that was all I needed. I'll be looking around in the code then. (Wich also have the nice side effect of making me familiar with it :)

I'm off to Huston for 14 days, and doubt I'll get time off to work on my project during that time. So if I'm not answering for the next 14 days you know why.

-Bendik
#30
10/25/2002 (4:08 am)
hmm

I have tried to use the glFog, but it turns out really weird.

Take a look:
www.student.dtu.dk/~c958608/weirdFog.jpg
The unfogged area moves with the camera.
Most of the code that I could find in Troque that handles fog, is a manual addition of the fog colors to the various vertecies.
If there is no way around, I guess I would have to do it that way, but it really complicates a lot.

The code below resulted in the image above.
GLfloat FogColor2[4] = {0.5, 0.5, 0.5, 1.0}; 
glClearColor(0.5f,0.5f,0.5f,1.0f);		
glFogi(GL_FOG_MODE, GL_EXP); // Fog Mode
glFogfv(GL_FOG_COLOR, FogColor2); // Set Fog Color
glFogf(GL_FOG_DENSITY, 0.35f); // How Dense Will The Fog Be
glHint(GL_FOG_HINT, GL_DONT_CARE); // Fog Hint Value
glFogf(GL_FOG_START, 100.0f); // Fog Start Depth
glFogf(GL_FOG_END, 500.0f); // Fog End Depth
glEnable(GL_FOG); // Enables GL_FOG

Getting the variuos fog vaules is not a problem, I just use this simplified code to debug.

-B
#31
11/11/2002 (2:26 pm)
Hi Bendik,

Your trees rock !

Same as You, i'm trying to graduate on computer science studies. I'm writing thesis about modern computer games graphics techniques based on my own made game (with Torque). Lately we got lectures about L-systems on computer graphics and I catched illness about puting procedural trees into my sample game.

I spend my whole weekend trying to get some procedural trees on Torque with Melv's basic object for rendering.

This is what I got after few hours digging into Torque.
pingu.ii.uj.edu.pl/~ono/3signs/sgTreeAlpha.jpg (18 faces ;P)

I made some textures from real photos I made and tried to make them trees.

I didn't know that you're making them and you're so advanced... until I stucked with translucent textures rendering and face depth sorting, I can't find it anywhere how to do it in Torque. How can I do that ????
I know that I must do that sorting them in order to distance to camera.. but how ???

I don't wont be rude, but I wish to look into your code... (even dream about putting it into my build).

Cheers,
Adam
#32
11/12/2002 (6:45 am)
Don't bother about depth sorting. Just enable alpha check.

glEnable (GL_ALPHA_TEST);

Please ask me questions about anything related to this, and I will elaborate. This way I can both write some good chapters for my report and contribute to the GG community at the same time.

I'm reluctant to giving my code away - atleast before it's completed.

:)
Bendik
#33
12/04/2002 (12:48 pm)
And this is what I'm playing currently with:
pingu.ii.uj.edu.pl/~ono/sgTree2.jpg
Not L-systems... but made proceduraly with random seed and some extra parameters.

Cheers,
#34
12/05/2002 (1:43 am)
That looks great!

Have you considered adding vertex coloring?

As you draw the branches up the trunk, you can vary the colors by just adding in a line with eg.


glColor3f(Redf, Greenf, Bluef);
//(float values between 0 and 1)

You will probably have to enable GL_COLOR or somthing, look at the fxGrassReplicator for reference.

:)
Bendik
#35
12/05/2002 (7:02 am)
Thanks,

Most of the job are branch textures I've digitized from real pine trees shots. And I'm simply making 2 faces for a branch. That makes avg 100 - 150 faces per one tree.

Yea.. vertex coloring is very good idea, would be useful for working with day-nite system.

Now I'm adding some wave branch animation.. that will be windy sim.
Next I'll playing with deciduous trees.. that looks harder for me.

Cheers,
Page«First 1 2 Next»