Game Development Community

Multiple geometry files in a Atlas file

by Bill Vee · in Torque Game Engine Advanced · 01/13/2009 (10:35 am) · 11 replies

I would like to be able to load more than one geometry file from a single atlas file and I am running into some trouble.

I setup a custom console function to create the atlas file similar to atlasGenerateBlenderTerrain like so

Con::printf("   o Opening '%s' for geometry...", argv[2]);
   inGeometryFile = AtlasFile::load(argv[2]);
   if(inGeometryFile.isNull())
   {
      Con::errorf("atlasGenerateMultiBlenderTerrain - unable to open '%s' for input!", argv[2]);
      return false;
   }

   /*   Con::printf("   o Opening '%s' for geometry...", argv[3]);
   inGeometryFile2 = AtlasFile::load(argv[3]);
   if(inGeometryFile2.isNull())
   {
      Con::errorf("atlasGenerateMultiBlenderTerrain - unable to open '%s' for input!", argv[3]);
      return false;
   }*/

........
........

   // First Geometry .
   AtlasResourceGeomTOC *originalArgtoc = NULL;
   if(!inGeometryFile->getTocBySlot(0, originalArgtoc))
   {
      Con::errorf("atlasGenerateMultiBlenderTerrain - inGeometryFile does not have a Geometry TOC.");
      return false;
   }

   AtlasResourceGeomTOC *argtoc = new AtlasResourceGeomTOC;
   argtoc->copyFromTOC(originalArgtoc);
   outFile.registerTOC(argtoc);

   // Second Geometry .
   AtlasResourceGeomTOC *originalArgtoc2 = NULL;
   if(!inGeometryFile2->getTocBySlot(0, originalArgtoc2))
   {
      Con::errorf("atlasGenerateMultiBlenderTerrain - inGeometryFile does not have a Geometry TOC.");
      return false;
   }

   AtlasResourceGeomTOC *argtoc2 = new AtlasResourceGeomTOC;
   argtoc2->copyFromTOC(originalArgtoc2);
   outFile.registerTOC(argtoc2);

This is not all the code but it is the part that was added.
It basically loads a second atlas file containing the additional set of data I want to use and uses outFile.registerTOC to add it to the atlas file.
The function goes on to add the lightmap and opacity data as well , just like a regular blended atlas file.

The problem I run into is when I try to load the atlas file like AtlasInstance::onAdd() loads the first geometry and it fails to read the second one correctly and errors out.

This is the relevent code in AtlasInstance::onAdd()

//first geom
   AtlasResourceGeomTOC   *argtoc=NULL;
   mAtlasFile->getTocBySlot(0, argtoc);
   mGeomTOC = new AtlasInstanceGeomTOC;
   mGeomTOC->initializeTOC(argtoc);

//second geom
   AtlasResourceGeomTOC   *argtoc2=NULL;
   mAtlasFile->getTocBySlot(1, argtoc2);
   mGeomTOC2 = new AtlasInstanceGeomTOC;
   mGeomTOC2->initializeTOC(argtoc2);

It fails at mGeomTOC2->initializeTOC(argtoc2); and says that it got an invalid sentinal chunk.
After a debug session it appears it is loading data from the wrong part of the atlas file and spits out an error.
The odd thing is if I change the loading of the second geom file in the onAdd function to load from a seperate atlas file it works fine.

So my question is , Am I simple doing it wrong or is this not possible with the atlas system right now.

#1
01/13/2009 (12:16 pm)
You should be able to store any combination of resource TOCs in an Atlas file. Have you tried looking at the list of TOCs in the AtlasFile to see what it thinks it has?

PS - why do you need a second geometry TOC?
#2
01/13/2009 (1:18 pm)
My bad. Tried to post from memory. Pulled and SVN copy to my laptop and looked at it better.
It is not failing at mGeomTOC2->initializeTOC(argtoc2); but rather it is failing at

mGeomTOC2->loadCollisionLeafChunks();
on line 58 of atlaschunk.cpp
AssertISV(sent1 == MakeFourCC('A', 'T', 'S', 'P'), "AtlasChunk::readFromStream - (sent1) invalid chunk master sentinel!");

The value of sent1 is 1868908292.
A quick hex search of the atlas file shows only one place that occurs.
Within the first 20 bytes of the file.

4154 4C53 0104 4765 6F6D in hex. Or
AT LS .. Ge om. In text.

So it seems it is moving the file pointer back to the start of the file when it tries to run loadCollisionLeafChunks the second time.

Need to investigate more.

Quote:
PS - why do you need a second geometry TOC?

Ben , since we have you to thank for Atlas in TGEA/TSE I can send you a link to download , soon hopefully ,a demo I think you will like.
For now lets just say Atlas gave birth to something else.
#3
01/13/2009 (1:24 pm)
Hmm, strange issue. Maybe the TOC doesn't have its chunk positions filled in properly? Could be an issue with how the TOC is begin written.

I look forward to seeing what you have come up with. :)
#4
01/13/2009 (1:56 pm)
Just tried to load only the second geometry and it failed the same way.
I will look at the TOC closer and see whats going on.
#5
01/13/2009 (7:59 pm)
Ok I figured it out.
.....
Totally my fault.
Forgot to add originalArgtoc2->copyChunksToTOC(argtoc2).

Huh.....New site design?
Must have messed a memo :)

Anyway...
Now the problem I have is getting projectiles to collide with the secondary terrain.

I have changed buildConvex and buildPolyList and duplicated what mGeomTOC is doing in each function.

The player collides and interacts with no problem but not projectiles.

In case you were going to ask. Yes both terrain geometries are visible at the same time.
Actually all of them are.
#6
01/13/2009 (8:34 pm)
It seems like it would be easier to just have two AtlasInstances in the game world? What's the benefit of cramming everything into one file when you're going to have to duplicate a ton of code to make everything work with multiple TOCs?
#7
01/14/2009 (6:05 am)
Lets just say it is a matter of precision.
Aligning two or more instances of an atlas terrain in code is a little trick at best. As you know each atlas terrain is unique in regards to its object boxes min and max extents.
Two terrains that are suppose to be side by side have to be tweaked into place. You run into a similar problem with megaterrains now but you solve that by making sure the border areas exactly match it's neighbor by adjusting the vertexes along them "seem" to match in height.
Not exactly something you can do with Atlas. Or at least easily accomplish.

To get a better idea of the problems I face read this blog I posted a while back.

I was surprised at how many issues with my project this approach fixes.
#8
01/14/2009 (12:14 pm)
This new site is starting to get on my nerves.
I forgot to bookmark this thread and it took me a little while just now to find it again.

Anyway.....I fixed the collision issues I had and now I am much happier with this new derived atlas system I have been working on.

Teaser.....overhangs,caves and arches. :)
#9
01/14/2009 (1:16 pm)
Cool... :)
#10
01/14/2009 (1:36 pm)
I've been a big fan of the spherical terrains that you showed earlier this year. Now reading this and your mention of "overhangs, caves, and arches" only saddens me further hearing that Atlas is going away in the future.

But holey buttered onions! Do you really mean overhangs, caves, and arches? That's more than cool!
#11
01/14/2009 (2:11 pm)
I think I am still in denial about atlas being removed.
It has kinda made me refocus on getting this out before the plug is pulled on it forever in order to see if GG may at least consider keeping it as an add-on option for Torque3D.

:(