Doom3world

The world is yours! Doom 3 - Quake 4 - ET:QW - Prey - Rage
It is currently Fri Jul 30, 2010 10:07 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 12 posts ] 
Author Message
 Post subject: .map Format texture specification.
PostPosted: Wed Jun 28, 2006 2:47 am 
Offline
The first 10 posts have been the best...

Joined: Wed Jun 28, 2006 1:38 am
Posts: 10
Greetings. First post.

I'm experimenting with generating map files from custom software. I was working on it with Q3A and finally sussed the old block format which was something like this:

Quote:
{
( 112 128 128 ) ( 112 128 1152 ) ( 128 128 1152 ) common/caulk 0 0 0.000000 0.062500 0.062500
( 128 1152 128 ) ( 128 1152 1152 ) ( 112 1152 1152 ) common/caulk 0 0 0.000000 -0.062500 0.062500
( 112 1152 128 ) ( 112 1152 1152 ) ( 112 128 1152 ) common/caulk 0 0 0.000000 -0.062500 0.062500
( 128 128 128 ) ( 128 128 1152 ) ( 128 1152 1152 ) metal_512x512 0 0 0.000000 0.062500 0.062500
( 112 1152 128 ) ( 112 128 128 ) ( 128 128 128 ) common/caulk 0 0 0.000000 -0.062500 0.062500
( 112 128 1152 ) ( 112 1152 1152 ) ( 128 1152 1152 ) common/caulk 0 0 0.000000 0.062500 0.062500
}


The new Doom3 Brush Primitives format is something like this:

Quote:
// primitive 5
{
brushDef3
{
( 0 -1 0 384 ) ( ( 0.0625 0 0 ) ( 0 0.0625 0 ) ) "textures/common/caulk" 0 0 0
( 0 1 0 -896 ) ( ( -0.0625 0 0 ) ( 0 0.0625 0 ) ) "textures/common/caulk" 0 0 0
( -1 0 0 384 ) ( ( -0.0625 0 0 ) ( 0 0.0625 0 ) ) "textures/common/caulk" 0 0 0
( 1 0 0 -896 ) ( ( 0.0625 0 0 ) ( 0 0.0625 0 ) ) "textures/common/caulk" 0 0 0
( 0 0 -1 896 ) ( ( -0.0625 0 0 ) ( 0 0.0625 0 ) ) "textures/archatron/arch_down_512x512" 0 0 0
( 0 0 1 -912 ) ( ( 0.0625 0 0 ) ( 0 0.0625 0 ) ) "textures/common/caulk" 0 0 0
}
}


The above two are not for the same block, BTW, just examples.

I understand the way the three sets of { 3 points } defining a plane of the Q3A map format have been change to a normal and a distance in the Doom3 brush primitives map format, and can output that geometry fine.

However texture mapping is another story. It took me ages to get the offsetX, offsetY, rotation, scaleX, scaleY system of Q3A sorted. Now it has been changed to some nighmarish system where the two sets of three numbers represent the first two rows of a matrix that operates on the plane to translate into texture coordinates... or something. Arrr! :shock:

I've looked at some of the old Radiant code regarding brush primitives but don't really understand it much. I pulled out this snippet:

Quote:
// compute back the texture matrix from fake shift scale rot
// the matrix returned must be understood as a qtexture_t with width=2 height=2 ( the default one )
void FakeTexCoordsToTexMat( float shift[2], float rot, float scale[2], vec_t texMat[2][3] )
{
texMat[0][0] = scale[0] * cos( DEG2RAD( rot ) );
texMat[1][0] = scale[0] * sin( DEG2RAD( rot ) );
texMat[0][1] = -1.0f * scale[1] * sin( DEG2RAD( rot ) );
texMat[1][1] = scale[1] * cos( DEG2RAD( rot ) );
texMat[0][2] = -shift[0];
texMat[1][2] = shift[1];
}


And found it converted some of the simpler texture mapping fine, but got other bits back to front, and made a total mess of anything involving rotations or anything complex.

The only hard info I've found is from https://adidas.servegame.org/projects/buildutils/wiki/BrushPrimitives
where it says, amongst other things:
Quote:
After the three points that define the face follow the first two rows of a homogeneous 3x3 matrix A_ij, in the format:

( ( a11 a12 a13 ) ( a21 a22 a23 ) )

Where the a_ij are decimal values. (Homogeneous matrices have the bottom row as [0 0 1]).

Let n = (nx, ny, nz) be a unit vector normal to the face.

theta_y = arctan(nz / sqrt(ny^2 + nx^2))
theta_z = arctan(ny / nx)

theta_y is the angle between n and the XY plane. theta_z is the angle between n and the XZ plane. N.b. these results depend on division by zero returning Inf (IEEE floating point).

Let Bij be the matrix such that:

b11 = -sin(theta_z) b21 = sin(theta_y) * cos(theta_z) b31 = 0
b12 = cos(theta_z) b22 = sin(theta_y) * sin(theta_z) b32 = 0
b13 = 0 b23 = -cos(theta_y) b33 = 0

Note that there are many ways of finding a suitable matrix for transforming from world coordinates to face coordinates, but this is the particular one used by the Brush Primitives file format.

Let A be the homogeneous matrix from the texture definition.

Let r = (x, y, z) be a point in 3D space. Let t be the texture coordinates corresponding to r. Clearly, t = A * B * r

The BSP file requires two vectors u and v, and offsets in the u and v directions (k1 and k2), so that t1 = u . r + k1 and t2 = v . r + k2 -- in vector notation, this could be written as t = Mr where Mij is a 3x3 matrix such that M = AB.


I can barely make heads or tails of that, plus there's some code that seems irrelevant. I may have to get my hands dirty with that stuff, but first I thought I'd check if anyone already knew if this problem had been worked out for Doom3 Brush Primitives map format, and could point me to some handy information about how to create those 6 magic texture mapping numbers.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 28, 2006 3:23 am 
Offline
The first 10 posts have been the best...

Joined: Wed Jun 28, 2006 1:38 am
Posts: 10
Thought I'd add some other info I've found, for anyone else searching for this kind of info. This is from http://quark.planetquake.gamespy.com/infobase/src.topics.face.html#bp
Quote:
Brush Primitives
tiglari - 11 May 2002 [ Top ]

'Brush primitives' is the new brush format used by GtkRadiant. Other than some extra braces and a 'Brushdef' in the text of the format, its main new feature (for now at any rate) is an improved method of expressing the texture-mapping over the 5 'shift scale rotate' numbers that come after the texture name in the old representation.

In BP format, you get something that looks like this coming after the threeponts info, and before the texture name:

( ( 0.007813 0 0 ) ( 0 0.007813 0 ) )

What these are is the top two rows of the 'homogeneous matrix' mapping the plane of the face, under a special coordinate system we will get to in a moment, into the texture plane (so it's sort of the reverse of how QuArK etp and tv6 work, since these most directly represent the mapping from the texture plane onto the face). Erm, what's a homogeneous matrix you might ask.

It is 3x3 matrix whose bottom row is (0 0 1). If you multiply a homogeneous matrix by a column vector whose z coordinate is 1, you'll see that the equations are exactly those for a linear mapping followed by a translation: the first two numbers of the top two rows give a 2x2 matrix describing the linear transformation, and the last number give a column vector to be added (to the a column 2-vector) to give the translation. So what about this coordinate system?

It is one whose axis directions are gotten by rotating the Y and Z coordinates of map space so that they lie in the plane. These direction vectors are computed by function GetAxisBase in QkMapPoly.pas. It's essential that q3map and the editor compute them in the same way; hopefully the GtkRadiant/Q3map developers won't change it without telling us. Then of course for a coordinate system you need an origin, this is gotten by scaling the face's normal vector by its Dist (-ance from the origin).

So what goes on in GetPXPY is that the (texture-scaled, etc.) threepoints are converted to the Axis Base coordiante system, and then these equations are solved for the coefficients aij making up the matrix (I used Maple V to get the solution):

a11*p0x+a12*p0y+a13 = 0
a21*p0x+a22*p0y+a23 = 0

a11*p1x+a12*p1y+a13 = 1
a21*p1x+a22*p1y+a23 = 0

a11*p2x+a12*p2y+a13 = 0
a21*p2x+a22*p2y+a23 = -1

The conversions from Brush Primitives to QuArK (once etp, now tv6) are made in the procedure ReadQ3BrushDef in QkMap.pas.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 28, 2006 3:26 am 
Offline
fired 300 rounds
User avatar

Joined: Thu Nov 03, 2005 10:32 am
Posts: 344
Location: Victoria , Australia
i have no idea what all that means , probly because i didnt read it properly... :wink:

_________________
You learn something new everyday.........at Doom3World.org :)


Top
 Profile E-mail  
 
 Post subject:
PostPosted: Wed Jun 28, 2006 3:49 am 
Offline
The first 10 posts have been the best...

Joined: Wed Jun 28, 2006 1:38 am
Posts: 10
I mostly don't know what it means either. Thus the problem.

In a nutshell: How do you automate the conversion of Q3A texturing to D3 texturing at the level of outputting .map files?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 28, 2006 8:09 am 
Offline
fired 300 rounds
User avatar

Joined: Thu Nov 03, 2005 10:32 am
Posts: 344
Location: Victoria , Australia
rename the map format .... just a stab in the dark, i probly dont even know what im talkin bout :D

_________________
You learn something new everyday.........at Doom3World.org :)


Top
 Profile E-mail  
 
 Post subject:
PostPosted: Wed Jun 28, 2006 4:13 pm 
Offline
Quad Damage!
User avatar

Joined: Tue Jun 22, 2004 6:57 pm
Posts: 4771
Location: Green Bay, WI
this thread might help a little: http://www.doom3world.org/phpbb2/viewto ... map+format

_________________
Don't take the swine flu shot!


Top
 Profile E-mail  
 
 Post subject:
PostPosted: Wed Jun 28, 2006 8:40 pm 
Offline
The first 10 posts have been the best...

Joined: Wed Jun 28, 2006 1:38 am
Posts: 10
Thanks pbmax. I've already read that one, that's where I saw that the first four numbers are a normal and a distance, and that the format is called "brush primitives."

No help on the textures though. I'll have to do some experiments and hope I can cook up something.

[I notice it was your post, so I guess you have some interest in manipulating .map files too.]


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 28, 2006 11:24 pm 
Offline
Plasma Spammer
User avatar

Joined: Fri Jun 27, 2003 11:24 pm
Posts: 2709
Location: Munich, Germany
Here is another bit of info:
http://www.doom3world.org/phpbb2/viewtopic.php?t=11101

_________________
Image Staff
Modelviewer | 3DSMax<->MD5 | Blender<->MD5


Top
 Profile E-mail  
 
 Post subject:
PostPosted: Thu Jun 29, 2006 9:14 am 
Offline
found a secret

Joined: Wed Sep 08, 2004 8:48 am
Posts: 562
GtkRadiant is open source, right? Why don't you look at it's sourcecode to determine what the fields mean?

_________________
Project Lead and lead coder The Dark Mod http://www.thedarkmod.com


Top
 Profile E-mail  
 
 Post subject:
PostPosted: Fri Jun 30, 2006 2:21 am 
Offline
The first 10 posts have been the best...

Joined: Wed Jun 28, 2006 1:38 am
Posts: 10
I've been doing exactly that, but understanding other people's code is not a straight-forward task, because it can be hard to understand other people's data structures and logic. Especially if they're clever and you're not. :wink:


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 31, 2006 11:25 am 
Offline
respawned 1350 times
User avatar

Joined: Thu Dec 05, 2002 2:08 pm
Posts: 1416
vash669 wrote:
rename the map format .... just a stab in the dark, i probly dont even know what im talkin bout :D


Yes, you can just rename a .mp3 file to .avi and bam! You got a movie! :roll:

_________________
theRev is coming...


Top
 Profile E-mail  
 
 Post subject:
PostPosted: Fri Sep 01, 2006 9:31 am 
Offline
picked up 100 armour
User avatar

Joined: Sat Jul 08, 2006 4:38 pm
Posts: 141
Rayne wrote:
vash669 wrote:
rename the map format .... just a stab in the dark, i probly dont even know what im talkin bout :D


Yes, you can just rename a .mp3 file to .avi and bam! You got a movie! :roll:

Lol, works, until you try and open it.. :lol:


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group