What exactly is the materials.cs file?

Discussion in 'Content Creation' started by SouthernPotato, May 21, 2016.

  1. SouthernPotato

    SouthernPotato
    Expand Collapse

    Joined:
    Feb 7, 2016
    Messages:
    123
    Model of a material method in materials.cs (car) for your convenience:
    Code:
    singleton Material(mat)
    {
      mapTo = "mat";
      //textures and properties go here
    
      materialTag0 = "beamng"; materialTag1 = "vehicle";
    };
    

    It would appear to be a C# file, so that would mean that the Material method is...a constructor, I guess (because it never returns)? That returns a singleton? And it takes some sort of nameless or typeless variable (mat) where mapTo has to equal a string with that name in it?
    It also won't work with a for-loop, and I haven't had any success getting method calls to work. For instance, if I wanted to make a convenient method for getting a null texture:
    Code:
    String getNullTexture() {
        return "vehicles/common/null.dds";
    };
    
    The material would fail to load. Interestingly, if I had:
    Code:
    definition of material0 {};
    getNullTexture() {};
    definition of material1 {};
    definition of materialEtc {};
    
    then material0 would load but everything else would fail. So... no idea. Can anyone enlighten me on how these files work? Are they C# files? No?
    Also, I've had no luck getting
    beamngDiffuseColorSlot to work for cars, everything takes from the first color.

    edit: I'm particularly interested in defining many similar materials in one go (like several types of paint where one parameter is different)

    Any help is appreciated.
     
    #1 SouthernPotato, May 21, 2016
    Last edited: May 21, 2016
  2. iheartmods

    iheartmods
    Expand Collapse

    Joined:
    Aug 8, 2012
    Messages:
    1,482
    In a non-code sense: it's a file that essentially maps textures to where they're supposed to go on 3D models in the game.

    Check out one that's working from the game's files as a base.

    Code sense:

    Terrain materials/textures:
    Code:
    new TerrainMaterial()
    {
       diffuseMap = "levels/Desert_Highway/art/terrains/grass1";
       diffuseSize = "4096";
       normalMap = "levels/Desert_Highway/art/terrains/Grass-01-N";
       detailMap = "levels/Desert_Highway/art/terrains/Grass-01-D";
       detailSize = "3.3";
       detailStrength = "0.5";
       detailDistance = "140";
       macroMap = "levels/Desert_Highway/art/terrains/Macro_grass";
       macroSize = "71";
       macroStrength = "0.25";
       macroDistance = "1600";
       internalName = "Grass";
    };
    
    Where:
    • diffuseMap is like a background texture picture file/this is the file location for that.
    • diffuse size is the size of that file (in px)
    • normalMap is the "normal" texture file (i can't explain what it is but it's for details on the texture) also you see the requested file location.
    • detailMap is the detail texture file.
    • macroMap is something detail related, I can't explain it.
    • internalName is for friction properties (I think)

    and everything else is etc. from above

    3D Model materials/textures:
    Code:
    singleton Material(holyshit__0136_Charcoal)
    {
       mapTo = "_0136_Charcoal";
       diffuseColor[0] = "0.137255 0.137255 0.137255 1";
       translucentBlendOp = "None";
    };
    
    Where:
    • singleton Material is the texture the game is recognizing can be used.
    • mapTo is the currently empty material that needs this texture
    • diffuseColor is something you don't have to worry about.
    • translucentBlendOp also nothing you need to worry about.


    Car materials/textures:
    Almost exactly the same as above. On cars, I'm not sure where they put where these are (I only deal with terrains) but they map textures to areas of the cars that are named specifically.

    I hope this helps. Keep in mind, most textures will map automatically if you have the 3D model and textures in the same exact folder.
     
    #2 iheartmods, May 21, 2016
    Last edited: May 21, 2016
  3. SouthernPotato

    SouthernPotato
    Expand Collapse

    Joined:
    Feb 7, 2016
    Messages:
    123
    I should've been more specific. I understand for the most part what they are for an what some of the parameters do (at least for cars). I'm trying to understand what they are as in what type of file they are, how they're interpreted and used by the engine so I can no what I can and can't do with them (like for loops). Thank you though, I wasn't aware terrain materials were defined in the same manner.

    edit: Also in what situation can the Material(name) and mapTo "name" vary? You have an example with holyshit_charcoal and the mapTo string is "_charchoal" (roughly)
     
    #3 SouthernPotato, May 21, 2016
    Last edited: May 21, 2016
  4. B727ClassicFlyer

    B727ClassicFlyer
    Expand Collapse

    Joined:
    Feb 9, 2013
    Messages:
    2,196
    I agree with @iheartmods, however let me explain it in an easier way:

    The materials.cs file is the backbone, the spine, for your mod/terrain. That file is what makes that mod moves. If you don't have that file, then your mod's just a big mushy mess of wasted gigabytes.
     
    • Like Like x 1
  5. iheartmods

    iheartmods
    Expand Collapse

    Joined:
    Aug 8, 2012
    Messages:
    1,482
    Yes lol, charcoal was the color defined by sketchup (it's basically black) so it created a material called that.
    This is the sign (very badly cropped)
    50.jpg

    To answer your question, they can always vary I think, as long as the game can assume that the texture it's mapping is the right one OR if you choose the texture files yourself.
    It's important but quite as important. Without the materials.cs, the map runs ok but everything says "No Texture". A more crucial file is the .TER file or .MIS. A map isn't anything without either of those two.

    In the shortest possible way: the materials.cs file is for texture mapping.
     
    #5 iheartmods, May 21, 2016
    Last edited: May 21, 2016
  6. Scepheo

    Scepheo
    Expand Collapse

    Joined:
    Feb 10, 2015
    Messages:
    601
    It's a TorqueScript (TS) file. TorqueScript looks like C#, but isn't the same. The materials.cs file contains a bunch of named object definitions. Effectively, your example of
    Code:
    singleton Material(mat)
    {
        mapTo = "mat";
        materialTag0 = "beamng";
        materialTag1 = "vehicle";
    };
    is somewhat like the following C# code:
    Code:
    static Material mat = new Material
    {
        mapTo = "mat",
        materialTag0 = "beamng",
        materialTag1 = "vehicle"
    };
    I suggest you read the documentation to learn more, including how to declare functions, write for-loops and how to use the eval function to achieve variable code elements (like object types, or object names).
     
    • Like Like x 1
  7. SouthernPotato

    SouthernPotato
    Expand Collapse

    Joined:
    Feb 7, 2016
    Messages:
    123
    Perfect, thank you
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice