Jump to content
  • Advertisement
Sign in to follow this  
sakky

3D Levels for 3D Engines

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

I was thinking about making a 3D level for an upcoming game and I've found that the over all process of processing any binary, quad or oct tree is a wate of time. What I mean is, if the modeling program was already built it, then all you will have to do is reconstruct vis file load with out all those long loading times that are needed to subdivide a complex level. For exmaple, Quake.*'s BSP format. Load the structure from the file and you don't waste time computing where do these polygons go and/or how do I clip them? Because the structure is alread in the file, correct? You just load er up and then you're done. Much more easier and less complex to deal with then loading a level, then computing where it's polygons should be subdivided to. So I figured, I can learn how to load a BSP, because that will give me some experience in what I'm interested in. Also, I would like to find open source on an engine that already does this. I was interested in Q2 levels, but I think Q3 levels may be a little more interesting. Also, because that primary algorithm is BSP, I was hoping to find a program that I could access this information with and build a similar format for a quad tree. So then that levels would be .quad (lame huh?). Any ways, I don't know very many CADs that allow direct access to it's internal data structures such as *various* trees. I'm also to lazy, or not smartt enough to create my own CAD, because I wouldn't know the first place to start. Do you see what I'm asking?

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
No. I dont.

Share this post


Link to post
Share on other sites
Quote:
So I figured, I can learn how to load a BSP, because that will give me some experience in what I'm interested in. Also, I would like to find open source on an engine that already does this. I was interested in Q2 levels,


The quake2 source you mean? It's available somewhere.

Share this post


Link to post
Share on other sites
So you want to know how to read quake 2/3 level files, and also how to create your own?

Well there a link here on reading them : http://www.flipcode.com/articles/article_q2bsp.shtml

As for creating them you need a level editor. Quark is quite popular as is gtkradiant, though i've never used them myself...

http://dynamic.gamespy.com/~quark/
http://www.qeradiant.com/

Hope that helps :D

Share this post


Link to post
Share on other sites
Well, that sort of helps! Because I've already found that stuff and I know how to create my own levels. Well, I haven't found the Q2 source yet, but oh well.

I also know that PVS is the main reason that Q.* was so damn good. I don't know how to make a PVS or use one for that matter. But I'll have to learn.

I was wanting to make my own version of the BSP, so that's why I was looking for source code to a BSP modeler. I was wanting to use a quad tree instead of the BSP, but also use the BSP for collision.

Thanks for the input though!

Share this post


Link to post
Share on other sites
So fat, I've got thus far....


// ---------------------------------------------------------------------------- //
// Name : BSPLoadFromFile( )
// Desc : Loads a Quake 2 BSP level from file
// ---------------------------------------------------------------------------- //
HRESULT __stdcall BSPLoadFromFile( LPCSTR lpszFileName )
{
FILE* pFile = NULL ;
HRESULT hRet = S_OK ;

if ( NULL == ( pFile = fopen( lpszFileName, "rb" ) ) )
{
return ( E_FAIL ) ;
}

fread( &g_BSPHeader, sizeof( BSPHEAD ), 1, pFile ) ;

if ( ( g_BSPHeader.dwMagic != 0x49425350 ) && ( g_BSPHeader.dwBSPvr != 38 ) )
{
fclose ( pFile ) ;
return ( E_FAIL ) ;
}

fread( g_vBSPLumpDirectory, sizeof( BSPLUMP ), 19, pFile ) ;

if ( FAILED( hRet = BSPLoadLump( pFile, BSP_VERTICES, g_vBSPVertices ) ) ) goto Exit ;
if ( FAILED( hRet = BSPLoadLump( pFile, BSP_EDGES, g_vBSPEdges ) ) ) goto Exit ;
if ( FAILED( hRet = BSPLoadLump( pFile, BSP_FACES, g_vBSPFaces ) ) ) goto Exit ;
if ( FAILED( hRet = BSPLoadLump( pFile, BSP_FACEEDGETABLE, g_vBSPFaceEdges ) ) ) goto Exit ;
if ( FAILED( hRet = BSPLoadLump( pFile, BSP_PLANES, g_vBSPPlanes ) ) ) goto Exit ;
if ( FAILED( hRet = BSPLoadLump( pFile, BSP_NODES, g_vBSPNodes ) ) ) goto Exit ;
if ( FAILED( hRet = BSPLoadLump( pFile, BSP_LEAVES, g_vBSPLeaves ) ) ) goto Exit ;
if ( FAILED( hRet = BSPLoadLump( pFile, BSP_LEAFFACETABLE, g_vBSPLeafFaces ) ) ) goto Exit ;
if ( FAILED( hRet = BSPLoadLump( pFile, BSP_TEXTUREINFO, g_vBSPTexInfos ) ) ) goto Exit ;
if ( FAILED( hRet = BSPLoadLump( pFile, BSP_VISIBILITY, g_vBSPVisibles ) ) ) goto Exit ;

Exit:
fclose( pFile ) ;

return ( hRet ) ;
}

// ---------------------------------------------------------------------------- //
// Name : BSPLoadLump( )
// Desc : Loads the data from a BSP lump
// ---------------------------------------------------------------------------- //
HRESULT __stdcall BSPLoadLump( FILE* pFile, UINT uLumpDIR, LPVOID pvOutput )
{
if ( NULL == ( pvOutput = new BYTE[ g_vBSPLumpDirectory[ uLumpDIR ].dwLength ] ) )
{
return ( E_OUTOFMEMORY ) ;
}
else
{
fseek( pFile, SEEK_SET, g_vBSPLumpDirectory[ uLumpDIR ].dwOffset ) ;
fread( pvOutput, g_vBSPLumpDirectory[ uLumpDIR ].dwLength, 1, pFile ) ;
}

return ( S_OK ) ;
}

// ---------------------------------------------------------------------------- //
// Name : BSPRelease( )
// Desc : Releases used BSP resources
// ---------------------------------------------------------------------------- //
HRESULT __stdcall BSPRelease( void )
{
SAFE_DELETE_ARRAY( g_vBSPVertices ) ;
SAFE_DELETE_ARRAY( g_vBSPEdges ) ;
SAFE_DELETE_ARRAY( g_vBSPFaces ) ;
SAFE_DELETE_ARRAY( g_vBSPFaceEdges ) ;
SAFE_DELETE_ARRAY( g_vBSPPlanes ) ;
SAFE_DELETE_ARRAY( g_vBSPNodes ) ;
SAFE_DELETE_ARRAY( g_vBSPLeaves ) ;
SAFE_DELETE_ARRAY( g_vBSPLeafFaces ) ;
SAFE_DELETE_ARRAY( g_vBSPTexInfos ) ;
SAFE_DELETE_ARRAY( g_vBSPVisibles ) ;

return ( S_OK ) ;
}




Not mucn, it just loads a BSP file and deletes it frrom memory. I need to write the conversion fucntions so that I can convert BSP's weird coordinate system and texture matrix to work with Direct3D. Or, if I could, I would just make Direct3D use BSP's. How would I do that? I mean, how do I setup matrices that way? I'm horrible at math!

EDIT: That's pretty small for a level loading routine huuh?

Share this post


Link to post
Share on other sites
It's not really all that small, considering it doesn't really do much apart from grab a lump of binary and copy it to memory, but I suppose that's down to the very raw format.

Share this post


Link to post
Share on other sites
I don't care what ya say, it's still small and that's they way I like em. I guess I sort of over thought the process because the whole ides was big to me. Once seen in source, it looks to be quite easy. Now I just got to figure out how to render it.

Share this post


Link to post
Share on other sites
I just changed over to the Quake 3 BSP version. I couldn't find a suitable soruce for the Quake 2 version. I found some tutorials at GameTutorials but I'm not going to pay for their tutorials. The Q2 source was a little to much for me also. I could't find anything in that really.

Either way, both Q2 & Q3 versions of BSP are similar. When I finda good tutorial (free) that detials the loading and rendering of it, I'll be happy.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!