Game Development Community

dev|Pro Game Development Curriculum

Quake Brush Primitive support for Map2Dif Plus

by Ryan Nunn · 10/23/2005 (4:50 pm) · 3 comments

Now that QERadient has been released under the GPL, getting Quake 3 Brush Primitives format map files to work with Map2Dif Plus would be a very nice thing to have. Since it took me a while to figure it all out, here is the list of changes required.

Firstly modifiy the file "engine\interior\interiorMapRes.h"
Change the line:
bool parseQuakeNew(Tokenizer* toker, U32& tdx, PlaneF* texGens, F32* scale);
into
bool parseQuakeNew(Tokenizer* toker, VectorF normal, U32& tdx, PlaneF* texGens, F32* scale);

Next you need to make many changes to "engine\interior\interiorMapRes.cc". Here is the functions and changes needed

In "InteriorMapResource::parseMap()" remove :
// Unable to support the newest Quake 3 format
      if (mBrushFormat == QuakeNew)
      {
         Con::errorf("The latest Quake 3 format is incompatible with this version of map2dif. Please use an older format.");
         return false;
      }
In "InteriorMapResource::parseBrush()" remove:
// Unable to support the newest Quake 3 format
      if (mBrushFormat == QuakeNew)
         return false;
In "InteriorMapResource::parseEntity()" remove:
// Unable to support the newest Quake 3 format
            if (mBrushFormat == QuakeNew)
               return false;

In "InteriorMapResource::parsePlane()" change the following code
if (mBrushFormat == QuakeNew)
   {
      // The newest Quake 3 format is not supported at this time
      // b/c its texgens are incompatible with map2dif's
      return false;

      //parseQuakeNew(toker, texIndex, texGens);
   }
   else
      parseQuakeValve(toker, normal, texIndex, texGens, scale);
to
if (mBrushFormat == QuakeNew)
      parseQuakeNew(toker, normal, texIndex, texGens, scale);
   else
      parseQuakeValve(toker, normal, texIndex, texGens, scale);

Lastly, replace the entire InteriorMapResource::parseQuakeNew() method with:
bool InteriorMapResource::parseQuakeNew(Tokenizer* toker, VectorF normal, U32& tdx, PlaneF* texGens, F32* scale)
{
   MatrixF brushPrimMatrix(true);

   // Brings us to the beginning of the outer ()
   toker->advanceToken(false);

   // Brings us to the beginning of the next ()
   toker->advanceToken(false);

   toker->advanceToken(false);
   brushPrimMatrix(0,0) = dAtof(toker->getToken());
   toker->advanceToken(false);
   brushPrimMatrix(0,1) = dAtof(toker->getToken());
   toker->advanceToken(false);
   texGens[0].d = dAtof(toker->getToken());

   // Brings us to the end of ()
   toker->advanceToken(false);

   // Brings us to the beginning of the next ()
   toker->advanceToken(false);

   toker->advanceToken(false);
   brushPrimMatrix(1,0) = dAtof(toker->getToken());
   toker->advanceToken(false);
   brushPrimMatrix(1,1) = dAtof(toker->getToken());
   toker->advanceToken(false);
   texGens[1].d = dAtof(toker->getToken());

   // Brings us to the end of ()
   toker->advanceToken(false);

   // Brings us to the end of the outer ()
   toker->advanceToken(false);

   // Compute texturing Axis
   VectorF t1(-normal[1],normal[0],0);
   if (!t1[0] && !t1[1]) t1[1] = 1;
   else t1.normalize();

   VectorF t2;
   mCross(t1,normal,t2);

   MatrixF axis(true);
   axis.setRow(0,t1);
   axis.setRow(1,t2);
   axis.setRow(2,normal);

   // Multiply Brush Primitive matrix by texturing axis
   brushPrimMatrix.mul(axis);

   texGens[0].x = brushPrimMatrix(0,0);
   texGens[0].y = brushPrimMatrix(0,1);
   texGens[0].z = brushPrimMatrix(0,2);

   texGens[1].x = brushPrimMatrix(1,0);
   texGens[1].y = brushPrimMatrix(1,1);
   texGens[1].z = brushPrimMatrix(1,2);

   // Brings us to the texture
   toker->advanceToken(false);

   tdx = addTexture((char*)toker->getToken());

   // MDFFIX:: figure out what these are
   toker->advanceToken(false);
   toker->advanceToken(false);
   toker->advanceToken(false);

   return true;
}

And that is it. Brush primitives should now work when using Map2Dif Plus.

About the author

Recent Blogs


#1
10/23/2005 (8:00 pm)
Nice. Good to see such an implementation.

I take it that this does not use any of the GPL'd code or derivatives which would cause a license conflict.
#2
10/25/2005 (2:51 am)
Awesome! I had been putting off tackling this even though I stubbed it out. Thanks for saving me a bit of time and trouble =) I'll get this into the official map2dif plus really soon!
#3
10/28/2005 (6:48 pm)
Yeah I know about the GPL code problem. This code is clean, written by me from scratch.