Skip to content

Material Inject XML

SMG edited this page Jun 9, 2018 · 17 revisions

Material Inject XML

Smash Forge contains functionality to edit materials manually using an XML file, similar to the old Material_Inject scripts. This version has fewer bugs, meaning that NUDs won't be incompatible with Forge after injecting. Anything you can do with Forge's Material Editor can be done with the XML file, but it gives you more manual control. XML is a specially formatted text file, so any text editor will be fine. I recommend Notepad++ or Atom.

Exporting Materials

To export the materials as an XML file, right click the Model 0 in the mesh list and select Material > Export material as XML. Choose a name that makes sense and save the file.

Importing Materials

When you're done editing the XML file, save it and import from XML by right clicking Model 0 and selecting Material > Import from XML.

XML Import errors

Material Inject XML is much more user friendly and stable than previous text-based material editing methods. Smash Forge will warn you of common errors preventing proper injection.

Param Array Length

"PolygonID does not contain 4 valid values for property name."
Each material property should have 4 decimal values. Each value is separated by a space.

Polygon Count

"Expected NUD polygon count polygons but found XML polygon count in the XML file. The last polygon(s) will be ignored."
The XML file should contain the same number of polygons as the NUD. Make sure to double check the polygon IDs when copy pasting materials.

Duplicate Material Property

"PolygonID contains more than 1 instance of property name. Only the first instance will be added."
Each material should not contain duplicate definitions for a material property.

XML Parse Error

"An error occurred reading the XML file." This means some other sort of error occurred while trying to read the XML file. This usually means the XML syntax is wrong, such as forgetting closing tags.

Editing Materials

The XML file can be edited in your text editor of choice. The process is very similar to the other material editing scripts. All material properties use floating point values, meaning that values will be written as 0.0 or 1.0 instead of 0 or 255. The srcFactor, wrapModeS, etc correspond to the numbers used in Forge's material editor. You can find Part 1 and Part 2 of the material editing guide on Gamebanana for more information.

Material Attributes

Attribute Abbreviation Type
Flags flags uint (hex)
Source Factor srcFactor int
Destination Factor dstFactor int
Alpha Function AlphFunc int
Reference Alpha RefAlpha int (0 to 255)

Texture Attributes

Attribute Abbreviation Type
Wrap Mode S wrapmodeS int
Wrap Mode T wrapmodeT int
Min Filter minfilter int
Mag Filter magfilter int

Material XML Structure

<mesh name="Rosetta_FaceM_VIS_O_OBJ_O_NOSORT_FAR">
  <polygon id="2">
    <material flags="9a211067" srcFactor="3" dstFactor="1" AlphaFunc="0" AlphaTest="0" RefAlpha="0" cullmode="405" zbuffoff="0">
      <texture hash="40220003" wrapmodeS="1" wrapmodeT="1" minfilter="3" magfilter="2" mipdetail="6" />
      <texture hash="40220004" wrapmodeS="1" wrapmodeT="1" minfilter="3" magfilter="2" mipdetail="6" />
      <texture hash="40220015" wrapmodeS="3" wrapmodeT="3" minfilter="3" magfilter="2" mipdetail="6" />
      <texture hash="10080000" wrapmodeS="1" wrapmodeT="1" minfilter="3" magfilter="2" mipdetail="2" />
      <param name="NU_colorSamplerUV">1 1 0 0 </param>
      <param name="NU_lightMapColorOffset">0 0 0 0 </param>
      <param name="NU_specularParams">70 0.6 0 0 0 </param>
      <param name="NU_fresnelParams">1.02 0 0 1 0 </param>
      <param name="NU_fresnelColor">0.963 0.568 0.568 0.6 0 </param>
      <param name="NU_specularColor">0.6923077 0.5726193 0.5171539 1 0 </param>
      <param name="NU_aoMinGain">0.605 0.3222533 0.170005 0 0 </param>
      <param name="NU_blinkColor">0 0 0 0 </param>
      <param name="NU_alphaBlendParams">0 0 0 0 </param>
      <param name="NU_materialHash">24f70b3e 0 0 0 </param>
    </material>
  </polygon>
</mesh>
  • NUDMATERIAL
    • mesh
      • polygon 0
        • material & flags
          • textures and material paramaters
      • polygon 1
        • material & flags
          • textures and material paramaters

The model is organized into meshes. Each mesh has a name that will match the name that appears in Forge's mesh list. Under each mesh, you will have 1 or more polygon groups enclosed by the <polygon> </polygon> tags. Each polygon has a polygon id= "x" where "x" is the polygon ID. The polygon ID starts with 0 for the first polygon in a mesh and counts up by 1 for each polygon. Inside the <polygon> </polygon> tags, you will find the values to edit. The texture hash (or texture ID), flags, and material paramaters can all be edited.

Adding or Removing Polygons/Meshes

If you add or remove meshes and don't want to export the materials again, you will have to edit the XML file. New polygons, meshes, etc can be added to the XML. You may need to update the polygon ID if you add or remove a polygon from a mesh with multiple polygons.

Using Default Materials for Partial Imports

The ideal way to use the XML export feature is for copying materials onto a new model. If you reimport the dae, you won't have to manually fix the materials every time. When reimporting the same model, you won't need to edit the XML. Applying default materials to a partial import will require some editing in a text editor, however. The basic process is as follows.

  1. Export the XML file for the default character
  2. Export the XML file for your import
  3. Copy paste the appropriate materials from the default character XML to the XML for the import
  4. Use this new merged XML file to import materials for your import

Copying Materials

You can copy paste materials by copy pasting everything inside the <material> </material> tags. Aftering copying the material, you will need to fix the texture hash to match the appropriate texture in the model.nut or dummy texture. If you are copying a material with more textures than the original material, be sure that you have added these textures to the model.nut.

Common Errors with Material Inject XML

  1. The poly count is incorrect. The easiest way to tell what the correct number should be is to export the materials from your model as XML and read the first line of the file.
  2. The syntax is incorrect. The basic structure is <section start> section attribute </section end>. Don't forget the closing tag!