Views: 18,487,118 Home | Forums | Uploader | Wiki | Object databases | IRC
Rules/FAQ | Memberlist | Calendar | Stats | Online users | Last posts | Search
06-02-23 08:44 AM

0 users reading Model formats - A better understanding | 1 bot

Main - Archived forums - SMG documentations and tutorials - Model formats - A better understanding Hide post layouts | New reply

Pages: 1 2 3
Posted on 04-13-13 11:05 AM Link | #19986
Sounds like a good start. I figured out a partially correct way to set up the 2x4 texture matrices. If you're familiar with Thakis' bmdviewer2 then this might look familiar:

TexMtxInfo mtx
{ mtx.scaleU, 0, 0, mtx.scaleCenterX,
0, mtex.scaleV, 0, mtx.scaleCenterY };

This produces correct results for WW Link's eyes and other models in that .rarc.

I think/know there are more parameters that models are going to use. At least one model in that rarc wants a 3x4 matrix. With the info we have now it would be exactly the same as a 2x4, so there must be more!

Posted on 04-13-13 04:12 PM Link | #20052
struct TexMtxInfo
u8 projection;
u8 type;
u16 paddding0; // 0xFFFF

f32 center_s,center_t;
f32 unknown0;
f32 scale_s,scale_t;

u16 rotate; // -32768 = -180 deg, 32768 = 180 deg
u16 padding1; // 0xFFFF

f32 translate_s,translate_t;

f32 prematrix[4][4];

The projection field can be either GX_TG_MTX3x4 and GX_TG_MTX2x4.

The type field specifies which texture matrix type to use. I've found 6 different types in SMG2:

Always combined with projection=GX_TG_MTX2x4 and has regular texture coordinates as source. This is the simplest and most common type. The texture coordinates is first rotated and scaled about (center_s,center_t) and then translated.

Always combined with projection=GX_TG_MTX2x4 and has transformed normals as source. The normals are first projected with the matrix [[0.5, 0, 0, 0.5], [0, 0.5, 0, 0.5]] and then the same transformations as for type=0x00 are applied.

NOTE: It is possible that the matrix prematrix is applied to the normals before they are projected.

Always combined with projection=GX_TG_MTX3x4 and has transformed normals as source. Same as for type=0x06 except the projection matrix is [[0.5, 0, -0.5, 0], [0, 0.5, -0.5, 0], [0, 0, -1, 0]].

Always combined with projection=GX_TG_MTX3x4 and has untransformed position coordinates as source. First the matrix prematrix is applied to the coordinates, then the coordinates is projected by the matrix [[0.5, 0, 0.5, 0], [0, -0.5, 0.5, 0], [0, 0, 1, 0]] and then the same transformations as for type=0x00 are applied.

Always combined with projection=GX_TG_MTX3x4 and has transformed position coordinates as source. I don't know how this works, but I think it's just like type=0x08 but with transformed position coordinates.

Always combined with projection=GX_TG_MTX2x4 and has regular texture coordinates as source. I don't know how this works either, but it seems to be like type=0x00 except it uses unknown0 in some way.

Posted on 04-13-13 10:46 PM Link | #20101
Awesome. Thank you blank.

How can you generate a single texture matrix that can rotate a point around a center point? It seems like we would need at least two matrices to do it. Do they make use of the premultiply matrix in this way? Can you share any code on how to convert the TexMtxInfo structure to a matrix? I'm having trouble.

Posted on 04-14-13 04:25 AM Link | #20293
This is the python code I use to generate texture matrix commands for the MDL3 section

def SetTexMatrix(self,slot,args):
c = cos(args.rotate)
s = sin(args.rotate)
R = numpy.matrix([[c,-s,0],[s,c,0],[0,0,1]])
S = numpy.matrix([[args.scale_s,0,0],[0,args.scale_t,0],[0,0,1]])
C = numpy.matrix([[1,0,args.center_s],[0,1,args.center_t],[0,0,1]])
T = numpy.matrix([[1,0,args.translate_s],[0,1,args.translate_t],[0,0,1]])

if args.type == 0 or args.type == 0x80:
P = numpy.matrix([[1,0,0,0],[0,1,0,0],[0,0,0,1]])
elif args.type == 6:
P = numpy.matrix([[0.5,0,0,0.5],[0,0.5,0,0.5],[0,0,0,1]])
elif args.type == 7:
P = numpy.matrix([[0.5,0,-0.5,0],[0,0.5,-0.5,0],[0,0,-1,0]])
elif args.type == 8 or args.type == 9:
P = numpy.matrix([[0.5,0,0.5,0],[0,-0.5,0.5,0],[0,0,1,0]])

M = T*C*S*R*C.I*P*numpy.matrix(args.premtx)

if args.projection == gx.TG_MTX2x4:
self.texmatrix[slot][:] = (M[i,j] for j in range(4) for i in range(2))
elif args.projection == gx.TG_MTX3x4:
self.texmatrix[slot][:] = (M[i,j] for j in range(4) for i in range(3))

C.I is the inverse of the C matrix. As you can see, I have chosen to apply the prematrix for all types, but I am not sure this is correct. It will need some more testing.

Posted on 04-14-13 05:15 AM Link | #20298
Excellent, thanks again blank! I'm working on Link's eyes, and I'm realllly close, but not quite there. The eyes are drawn three times. One pass has blending disabled, and lays down 0's for all 3 color channels and 1.0 for the alpha channel where the eye should be drawn (like an alpha mask). The second pass seems to do exactly the same thing, but with blending enabled. But since the first pass wrote 0's to the color channels, it blends with the 0's (which is how you get Zorro link). The third pass has blending enabled but the srcFactor is dstAlpha, so it uses the alpha mask laid down by the first two passes.

So I believe that the first pass is supposed to have color writes disabled, ala GxSetColorUpdate(false). I've been hunting for that boolean (and it's brother, the boolean for GxSetAlphaUpdate) in the .bdl/.bmd file but I haven't had any luck. Is it in there? Am I barking up the wrong tree?

Posted on 04-14-13 07:06 AM Link | #20299
I'm pretty sure those values aren't there. They definitely aren't in the MDL3 section and I haven't found anything that looks like them in the MAT3 section.

Posted on 04-14-13 07:09 AM Link | #20300
Hmmm. Has anyone figured out how his eyes work? Maybe thakis is grabbing some incorrect blending information?

Posted on 04-14-13 07:40 AM Link | #20301
I don't have the Link model from Wind Waker, so I don't even know what the exact problem is. How does his eyes look as it is now?

Posted on 04-16-13 03:06 PM (rev. 6 of 04-17-13 07:43 AM) Link | #20633
Hi guys,
Vaguely off-topic, but I made this command-line tool for patching single files to a RARC file which can be
found here: http://www.sendspace.com/file/q37gv4

The main reason for doing this is that I haven't been able to get Wiimm's tools working on my Linux computer
(I run the windows port of tcc in wine to make my programs for windows computers), because apparently
it can't find libpng14 even though I installed correctly. I also wanted to get a better understanding of how
the RARC format works, and also this program fits nicely with the set of tools that Thakis and Shevious made,
which is how I've been testing new models in Super Mario Galaxy.

Finally, I just want to say, even if you don't really care what I'm posting on this thread, I'm still going
to go ahead and make my own BDL to BMD converter, because despite the time it's taking to make, I'd rather make
my own converter than try to set up a python environment that requires some external libraries just to convert
a level file from a Nintendo game, which I concede would be much easier, but again, I like to know how these things work.
No offense, blank, your tools are awesome and you know so much more than I do
about this stuff, but I feel that for the average user it might be simpler just to drag a level file on top of
an exe that only uses core Windows DLLs found in System32. Also, a 1.6MB exe from a 5KB python script is slightly
ridiculous :P

Posted on 04-18-13 04:55 AM Link | #20761
Blank, which tools did you develop?

Posted on 04-18-13 06:07 AM Link | #20763
A BMD to BDL converter and a OBJ to BDL converter.

Posted on 04-18-13 07:52 AM Link | #20764
Are they publicly available? I'd really like to get a look at the source. I'd like to tackle indirect texturing soon, and I don't think Thakis really solved it.

Posted on 04-18-13 09:50 AM Link | #20765
The OBJ to BDL converter is here and the BMD to BDL converter you can get here (it's some pretty crappy code, though).

As for indirect texturing, thakis almost had it. Here is how it should be:

struct IndTexOrder
u8 texcoord;
u8 texmap;
u16 padding0;

struct IndTexMatrix
f32 offset_matrix[2][3];
s8 scale_exponent;
u8 padding0[3];

struct IndTexCoordScale
u8 scale_s;
u8 scale_t;
u16 padding0;

struct TevIndirect
u8 indtex;
u8 format;
u8 bias;
u8 mtx;
u8 wrap_s;
u8 wrap_t;
u8 addprev;
u8 utclod;
u8 a;
u8 padding0[3];

struct IndirectEntry
u8 unknown0; // always 0 or 1
u8 unknown1; // unknown1 = unknown0, one of these is the argument to GXSetNumIndStages
u16 padding0;

IndTexOrder indtexorder[4]; // arguments to GXSetIndTexOrder
IndTexMatrix indtexmatrix[3]; // arguments to GXSetIndTexMatrix
IndTexCoordScale indtexcoordscale[4]; // arguments to GXSetIndTexCoordScale
TevIndirect tevindirect[16]; // arguments to GXSetTevIndirect
Pages: 1 2 3

Main - Archived forums - SMG documentations and tutorials - Model formats - A better understanding Hide post layouts | New reply

Page rendered in 0.026 seconds. (2048KB of memory used)
MySQL - queries: 25, rows: 127/127, time: 0.010 seconds.
[powered by Acmlm] Acmlmboard 2.064 (2018-07-20)
© 2005-2008 Acmlm, Xkeeper, blackhole89 et al.