Jump to content
  • Advertisement
Sign in to follow this  
cemedias

making my own level loader, tips?

This topic is 4050 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

Well, I recently discovered that the Irrlicht Engine doesn't have an level loader that supports entities; so I have to make one myself. Does anyone have any tips on writing an level loader that I could use? Or maybe a tutorial? So far I think I'll be using a .b3d format for my levels, and .x for my entities. I'm using 3d World Studio for to make my levels, so I'm also thinking about using the 3dws format for the levels, but haven't decided which is better (tips on this too?) I'm making a First Person Shooter using the Irrlicht Engine. By entities, I mean the monsters or other characters that I will put into 3dWS. I had another thread discussing this: "Adding people to a game?", but I made a new one because the topic changed. Any help would be appreciated, thanks!

Share this post


Link to post
Share on other sites
Advertisement
Irrlich is Open Source, you can take a look at the code for loading a b3d level and modify it to use 3dws files directly, you'll then add the code to create the entities in-game as well.

.x is ok for entities, you may want to move to more specialized file formats later, for example Md2, Md3 maybe even Md5, or maybe use Cal3D which specializes on characters.

I'd like to note that entities are not only characters, they can also be switches, doors, furniture, etc as well as invisible things like for example area triggers, shop areas (like in CounterStrike), etc. Invisible walls like the ones used to prevent the player from walking into a cliff are usually level geometry specially marked (usually done by giving it a texture or shader named "NULL") so it doesn't get rendered.

Share this post


Link to post
Share on other sites
If you're reading binary files, make sure you are reading them endian-independently, otherwise you will have headaches in the future if you want to move to another platform.

Since Irrlicht supports the PowerPC Mac, this is a distinct (and easy) possibility.

Share this post


Link to post
Share on other sites
Sorry I haven't been able to reply for a while. Thanks for the replies though. I would use Irrlicht's code for loading levels, but I don't really understand how it works. It uses one function called getMesh() that loads 14 different types of mesh formats (which you can view here.

Does anyone know of any tutorials or other source code available online that I could look at? Or even any books that I could buy on the subject of writing level loading formats (though I highly doubt there are any books that specific, but I might be wrong). I did a lot of searching on the Irrlicht Forums to try and find anything related to loading b3d files but I can't find anything. All I did find was something for loading bsp files, but It wasn't complete and could only load certain entities.

Quote:
I'd like to note that entities are not only characters, they can also be switches, doors, furniture, etc as well as invisible things like for example area triggers, shop areas (like in CounterStrike), etc. Invisible walls like the ones used to prevent the player from walking into a cliff are usually level geometry specially marked (usually done by giving it a texture or shader named "NULL") so it doesn't get rendered.


Yes, this I already did know, but thanks for the heads-up.

I searched the internet for tutorials about loading levels, but could find none. I've probably just been overlooking something, but if anyone has some help or tips I would appreciate it. Thanks.

Share this post


Link to post
Share on other sites
loading shouldn't be a problem just find out the file format/ specs
parse out the data based on specs.

for obj you would look at specs and find out what v stands for and create some rule for the loader to follow which would load the partion you data needed. that processes is easy but tricky some time

Share this post


Link to post
Share on other sites
Well, I've never written my own level loader before and thats why I need some type of guidance doing it. Even just an article or a code snippit wold help. But thanks for the replies anyway. For the tech-demo I made to test the features in my game, I just used Irrlicht's built in level loading code. Until I ran into the problem with loading entities, that is.

Any tips / articles / tutorials / code-snippits or the like would be appreciated. Thanks again.

Share this post


Link to post
Share on other sites
heres what im doing, for better or worse. I think ive found a nearly perfect system for a beginer such as myself.

i have an application called ac3d, its quite popular, but not as famous as 3d studio max or anything else for that matter. the key is in the file format. The application can import 3ds files, among others, and convert between them. Its used in a number of open source games, despite being a proprietry app. It does subdivision modelling, but has almost no lighting options. You would have to insert light entities and then build light maps in code.

this is the companies website. they use an activation key system, and give you a 30 day trial period.

Its easy to use, and saves everything in a tree, (with n kids on each node, whats that called again?) Thats important since i dont have to do this myself at loading time.

My loader is a heavily upgraded version of the original file loader code given on the website. While I was doing this i learned alot about geometry and display lists and, well, everything really. You could have the ability to design a scene and load it immediately withina few days of downloading this app. It took me 5 days to get that far.


So lets say i create a landscape with some hills and a bridge across it, and some rocks in the grass.
to optimise the game, i seperate the mesh of the hills into four groups, one for each corner, and each group is split four ways, etc. The tree structure can be as wide as i like. I have the bridge as four seperate meshes. I can have some large boulders in the grass, which will be rigid bodies. I give them the prefix PHY_ to tell my loader that they are physics objects. Then i comnvert all surfaces to triangles, because my collision detection system is optomised for triangles, and save the file into my game folder.

on loading, the loader they give you will load each object into memory. THey also give you functions to render them into opengl display lists. Their code assumes your going to use opengl, but it could be easily modified to use any other API.

My loader will then scan each object. The object will be rendered to a display list, and stored in a struct along with some collision data. if its static geometry, its sent to one list, and if its a physics object its sent to another.
on displaying each object i do a frustum cull, and those ojects which fit are rendered. The tree allows me to display or not display large amounts of geometry quickly. I get little noticeable slowdown with a scene of 10 times as many polygons, although loading times are a little slow at the moment because the way it handles textures is a little primitive.

i intend at some point to write a BSP loader for the file, which strips out the static geometry and sends it to a bsp tree, which should be faster than the frustum culling version. either way, the ease of use of the file format is what made me decide to use this system and i'd reccommend it to any other beginner.

here is the struct for the mesh, taken from the source files provided:

typedef struct ACObject_t
{
ACPoint loc;
char *name;
char *data;
char *url;
ACVertex *vertices;
int num_vert;

ACSurface *surfaces;
int num_surf;
float texture_repeat_x, texture_repeat_y;
float texture_offset_x, texture_offset_y;

int num_kids;
struct ACObject_t **kids;
float matrix[9];
int type;
int texture;
} ACObject;


The file format is a list of these objects.

The original loader simply loads and connects these objects together. My loader adds bounding box data, whereby each object has a bounding box which encompasses all the bounding boxes of its children. My game plan is a sandbox game with a large number of models, some static and some physics. Im currently finishing off my collision detection, it should be done by the end of the month, but I've already got interesecting meshes. Because the code they give you loads the polygon data for you, you can convert it into another, internal format easily using recursive functions.

Ive also experimted with using a flat tree as a database of objects, such as projectiles, or articulated bodies. I used the system to do a prototype graphics engine for a 3D RTS game. I had articulated models of tanks and helicopters launching projectiles at each other, and it looked great after only a few days of coding. That project is on hold in favour of a simpler one, which Im using to practice collision detection, a sandbox game where you fight monsters. milestone one will be characters walking around the level and not falling through the floor. Milestone 2 will be physics interaction.

It wont be fully functional until I re-write the texture code, because the code provided only does basic texture coordinate operations, and re-loads the same file multiple times if different meshes use the same texture file. I will change it for a texture database, and have each object reference entries in that database instead of owning the texture data itself.

To test what I have so far im doing a level that you can walk through, with a human controlled character. (right now he falls right through the floor because collision detection isnt finished) it runs fast enough in "noclip" mode where you directly control the camera.


Share this post


Link to post
Share on other sites
Thanks for the reply. Thats something I'll look into, but I really wasn't wanting to switch to another program, since I already have some of my levels made that I'm going to use. And I know that I can make my own entities in 3d World Studio. Are there any good tutorials or articles on parsing? Or can anyone recommend any good books that might be useful for me?

Share this post


Link to post
Share on other sites
why not have a seperate file, in your own format, which tells you where the entities are? you can use it to store any seperate information.
you could draw a vertex in 3d world studio, use it to choose the position of an entity, then copy / paste into your own file use that as the position of the entity.
You can have any entity type you like, since you design the file. You cna then render things like switches in the correct position. If the file format your loading uses a polygon soup, this is what i would do. I just picked this idea off the top of my head so I cant say I've ever used that particular method.

you could also take a look at the irrlich loader and see if it is loading entities from the file format your using. its possible that support is there in code, but unimplemented. if this is the case, you can put something between the loader and the renderer to extract data on entities.

loaders often have a switch statement somewhere which determines what to do with an object before its loaded. For example, after loading the raw data into the parser, you see something like this:

switch(object_type){
case polygon:
add_polygon_to_BSP_tree();
break;

case light:
add_light_to_light_mapper();
break;
};

you could add something to that code. irrlich is open source. i would patch the code and use a macro to enable / disable it, but i dont know alot about irrlich so i cant say for sure if thats possible.

[Edited by - speciesUnknown on July 19, 2007 7:12:37 PM]

Share this post


Link to post
Share on other sites
also, irrlich supports bsp maps, so can you export your files to that format? bsp map files include entity data. maybe you can do what i suggested above using .bsp files instead?

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!