This converter converts NIFF data formatted source files to GBI display-list formatted C source files. It has the following features:
When niff2gfx -h is executed from the command line, the following is displayed.
NIFF to N64 GBI format convertor. version 1.3.6 supported format revisions: NIFF 1.0 usage: niff2gfx [option] infile outfile infile ... NIFF format file. outfile ... N64 Displaylist C source file. option: -q quiet mode. -verbose verbose mode. -header fname, -d fname set output header filename. -label str set label string.(label string = str) -scale fval set convert scale.(scale = (float)fval) -niffinfo fname NIFF information onto file fname. -nocomdef common define,typedef block no output. -regmask val prevent RDP register assignment. -vtxshare val vertex share on set minimum match length. -vtxcache val vertex cache size(default 32). -vtxload val vertex cache load limit(default 32). -strictflat flat normal output to 3 vertices at all times. -noalignpad prevent alignment of 8-byte order no padding. -outobj name output object by name.(default: all objects) -outmask val prevent output dataclass assignment. -nogeomclr geometry mode no clear. -preview val preview type value.(default: 0x1c) -binary, -b output gfx in binary file. -rotorder val default rotation order.(default: 0x010203) -vtxseg val Vtx segment number.(default: 5) -imgseg val image data segment number.(default: 6) -tlutseg val TLUT data segment number.(default: 7) -nomodify disable modify vertex. -strictcidx CIDX pixel/bits follow 'tex_type'. -noreduct CIDX no color reduction. -nullanim output null animation data. -?, -h help @fname indirect option file.
-header fname, -d fname set output header filename
This switch outputs definition parts of code such as #define and typedef as a separate header file. Following
-header, above, please specify a file name to hold the header to be output.
-label str set label string. (label string = str)
The converter outputs all objects in the file that is given as the input. These objects are output as a table that becomes an interface to the game machine. The table is also used for the scale value, object total and other define macro names specified at the same time. That base label name is given.
-scale fval set convert scale. (svale = (float)fval)
This specifies the scale value at conversion time. In N64, the vertex value is described in the Vtx table as a signed 16-bit integer. So depending on the original model data, rounding off can destroy the original form. In this case, please specify the option. The default is set at 20x.
Also, because niffdraw.c performs reverse scaling based on the scale value output to the header, use of the N64 Previewer (or other accessory viewer software) does not affect the scale of the displayed shape.
-niffinfo fname NIFF information on to file fname
This outputs information when a NIFF file is read. Specify a hyphen ('-') as the filename to write to standard output.
-nocomdef common define,typedef block no output
The converter outputs a lot of header information at the front of the output file (or to the output header file specified with the -header option), but common information unrelated to the model data is suppressed. This is convenient when using numerous conversion files in a single compiler environment.
-regmask val prevent RDP register assignment
This suppresses output of the RDP register settings in the display list to be output. A 6-bit integer is assigned to the parameter val. Each bit has the following function:
-preview val preview val type (default: 0)
This option was previously used to change the view of the Previewer. However, with the introduction of version 1.30, this option is meaningless - since the Previewer no longer references this value.
-rotorder val set the default rotation order
In NIFF, when there is no animation link, no decision is made about the order of animation. The result is that rotation order can change for every object, and major restrictions are placed on application programming. This option can be used to set the rotation order for objects that do not hold animation. The original default is 0x010203.
-vtxseg val Vtx segment number. (default: 5)
This specifies the segment number of the vertex buffer referenced by the output Gfx. The default is 5.
-imgseg val Image data segment number. (default: 6)
This specifies the segment number of the texture image referenced by the output Gfx. The default value is 6.
-tlutseg val TLUT data segment number. (default: 7)
This specifies the segment number of the texture LUT that is referenced by the output Gfx. The default value is 7.
-nomodify disable modify vertex.
Prevents gsSPModifyVertex from reusing the vertex buffer. This must be specified when deform is enabled.
-strictcidx CIDX pixel/bits follow 'tex_type'.
When converting, if the image specified as an 8-bit color index texture is less than 16 colors, optimization is usually attempted as a 4-bit texture. However, by specifying this option, the optimization is prohibited and the texture pattern is output by the bit width specified by NIFF.
-noreduct CIDX no color reduction.
-nullanim output null animation data.
If there is no effective animation data in the object, NULL is output to the Animation List. Links to the animation will be created by referring the NULL from the object. nullanim can be used when the animation data is taken from different files. However, it can not be used from the nd since it does not support the Animation List NULL.
@fname indirect option file
fname is taken to be an indirect filename and interpreted as something described by a command line parameter. For details concerning indirect filenames, please see the "Indirect Filename Specifications" section below.
-?, -h help
This outputs simple explanations that describe command line settings and options
Example 1 command line: % niff2gfx @ind cube.niff mdl_a.c "ind" file: -header a.h -strictflat converter parsing...: % niff2gfx -header a.h -strictflat cube.niff mdl_a.c Example 2 command line: % niff2gfx @ind "ind" file: # option -header model.h -regmask 0x5 # no CycleMode & CC mode # input file cube.niff # output file model.c converter parsing...: % niff2gfx -header model.h -regmask 0x5 cube.niff model.c Example 3 command line: % niff2gfx @opt @file "opt" file: # option -header model.h -regmask 0x5 # no CycleMode & CC mode "file" file: cube.niff model.c converter parsing...: Same as in Example 2
First, the colors used by the image are reduced to 16-bits (RGBA5551). The colors are then sorted in order from the most-used. either the first 256 colors are set in the palette for an 8-bit CI texture or the first 16 colors are set in the palette for a 4-bit CI texture. Since alpha is effective for only 1 bit, it is transparent when the original data is 0, and opaque when the original data is a value other than 0.
If there is no match for a color in the palette, the sum of the difference of squares is calculated for each RGB component and the smallest is selected.
If -noreduct is specified and there are too many colors, the conversion is aborted.
The converter analyzes NIFF data and uses a number of RDP registers.The RDP register's Primitive Color register is allocated to PrimColor, while the Environment Color register is allocated to TriColor, and color changes are assigned to the registers.
The color combiner mode is determined based on the MAT_SHADE_LIGHT* of mat_shade_type and the following bits of mat_color_type0:MAT_CC_NIFF_VTX = 0x00000001 MAT_CC_NIFF_TRI = 0x00000002 MAT_CC_NIFF_PRIM = 0x00000004 MAT_CC_NIFF_TEX0 = 0x00000008 MAT_CC_NIFF_TEX1 = 0x00000010 MAT_CC_NIFF_TRI_ALPHA = 0x00020000 MAT_CC_NIFF_PRIM_ALPHA = 0x00040000 MAT_CC_NIFF_TEX0_ALPHA = 0x00080000The following bits are not referenced:MAT_CC_NIFF_VTX_ALPHA = 0x00010000 MAT_CC_NIFF_TEX1_ALPHA = 0x00100000Each bit is assigned separately, so there are a variety of modes. These are determined in the following way:First of all, the color combiner expression is evaluated with the following formula:
(Wch - Xch) * Ych + ZchWch, Xch, Ych, and Zch are virtual color channels, and they are determined by different bits in mat_color_type0.Ych is determined by MAT_CC_NIFF_VTX, _TEX0_ALPHA, _PRIM_ALPHA, _TRI_ALPHA, and _VTX_ALPHA.
VTX_A TRI_A PRIM_A TEX0_A VTX Ych 0 0 0 0 0 Shade color 0 0 0 0 1 Vertex color 0 0 0 1 * Texel0 alpha 0 0 1 * * Primitive alpha 0 1 * * * Env alpha 1 * * * 0 Shade alpha 1 * * * 1 Vertex alpha In the above table an asterisk (*) refers to an undefined value. In short, _VTX_ALPHA, _TRI_ALPHA, _PRIM_ALPHA, _TEX0_ALPHA, and _VTX are evaluated in order to set one of the above-mentioned modes.
Shade color expresses the color value inferred from calculating SP from the lighting setting and the model's shade.
When G_LIGHTING is set to off in the GeometryMode settings, Vertex color is extracted from the color value used by the normal of the Vtx structure.
Note: When Ych is Shade Color, and when both LOCAL and GLOBAL are 0 (no lighting) in the MAT_SHADE_LIGHT_* settings of mat_shade_type, then the color combiner expression is changed to the following:
(1.0 - Xch) * Wch + ZchAlso note that this special rule does not apply for the second cycle in 2 cycle mode.Wch, Xch, and Zch are determined from MAT_CC_NIFF_TRI/_PRIM/_TEX0/_TEX1.
TRI T1/PRIM TEX0 Wch Xch Zch 0 0 0 1.0 0.0 0.0 0 0 1 Tex0 0.0 0.0 0 1 0 T1/Prim 0.0 0.0 0 1 1 Tex0 T1/Prim T1/Prim 1 0 0 Env 0.0 0.0 1 0 1 Tex0 Env Env 1 1 0 T1/Prim Env Env 1 1 1 Tex0 T1/Prim Env Tex0 indicates Texel0 color.
Prim indicates the Primitive Color Register.
Env indicates the Environment Color Register.
T1/Prim is determined from the states of TEXEL1/PRIMITIVE according to the following rule:
TEXEL1 PRIM T1/Prim Contents 0 0 0 ---- 0 1 1 Prim 1 * 1 TEXEL1 In 1 cycle mode, the above settings also apply to pipeline 2.
In 2 cycle mode, the above type of evaluation is not performed on mat_color_type1, and the values are substituted and output in the following way:
Shade color is replaced by Combine color
Shade Alpha is replaced by Combine Alpha
Alpha combiner mode is determined based on the following mat_alpha_type0 bits:MAT_CC_NIFF_VTX_ALPHA = 0x00010000 MAT_CC_NIFF_TRI_ALPHA = 0x00020000 MAT_CC_NIFF_PRIM_ALPHA = 0x00040000 MAT_CC_NIFF_TEX0_ALPHA = 0x00080000 MAT_CC_NIFF_TEX1_ALPHA = 0x00100000The following bits are not referenced:MAT_CC_NIFF_VTX = 0x00000001 MAT_CC_NIFF_TRI = 0x00000002 MAT_CC_NIFF_PRIM = 0x00000004 MAT_CC_NIFF_TEX0 = 0x00000008 MAT_CC_NIFF_TEX1 = 0x00000010The alpha combiner expression is defined in the same way as the color combiner expression:(Wch - Xch) * Ych + ZchThe Wch, Xch, Ych, and Zch channels are determined based on the five effective flags described above, and according to the following rule:
VTX_A TRI_A T1/PRIM TEX0_A Wch Xch Ych Zch 0 0 0 0 0.0 0.0 0.0 1.0 0 0 0 1 0.0 0.0 0.0 Tex0 0 0 1 0 0.0 0.0 0.0 T1/Prim 0 0 1 1 Tex0 0.0 T1/Prim 0.0 0 1 0 0 0.0 0.0 Env 0.0 0 1 0 1 Tex0 0.0 Env 0.0 0 1 1 0 T1/Prim 0.0 Env 0.0 0 1 1 1 Tex0 Env T1/Prim Env 1 0 0 0 0.0 0.0 0.0 Shade 1 0 0 1 Shade 0.0 Tex0 0.0 1 0 1 0 Shade 0.0 T1/Prim 0.0 1 0 1 1 Shade T1/Prim Tex0 T1/Prim 1 1 0 0 Shade 0.0 Env 0.0 1 1 0 1 Shade Env Tex0 Env 1 1 1 0 Shade Env T1/Prim Env 1 1 1 1 Shade T1/Prim Tex0 Env VTX_ALPHA becomes a control flag for ShadeColor.
T1/Prim is determined from the states of TEXEL1/PRIMITIVE according to the following rule:
TEXEL1_A PRIM_A T1/Prim Contents 0 0 0 ---- 0 1 1 Prim 1 * 1 TEXEL1 In 1 cycle mode, the above settings also apply to pipeline 2.
In 2 cycle mode, the above type of evaluation is not performed on mat_color_type1, and the output value for Shade Alpha is replaced by Combine alpha and output.
For example:
Copyright 1997-1999 NINTENDO Co., Ltd.
1998-1999 MONEGI CORPORATION
All rights reserved.