[TUTORIAL] Making Custom CSG and Features

Discussion in 'Mod Discussions' started by allister, March 24, 2018.

  1. allister

    allister Active Member

    Messages:
    115
    Likes Received:
    175
    Sincere apologies for the disappearance. Don't ask what happened to me or where I've been. I was able to get features working, but it wasn't until today I got CSGs working with textures after a million and a half attempts. Figured I owed you guys, better late than never. Look below! The massive flowers are CSG and the small flowers and mushrooms are features.

    [​IMG]

    Tools used: papatran.exe, papadump.exe, Blender

    Making CSG

    I used Blender to make my CSG and features so you'll have to adapt to use your own program. My custom planet is named meadow, which is made up of two biomes: field1 and field2. It's pretty primitive, I'm not a designer. You should be familiar with custom planets, biomes, and using papatran.exe/papadump.exe.

    You should have your model and textures finalized. To avoid confusion and problems, you want to pick one name for your model and stick with it. The name of my CSG is "field1_lotus_01" (I kind of stuck with the naming convention Uber went with). That's what you will call your Object in blender, your .fbx file, your .papa file, and all the references in your files.

    Your model will need TWO UV maps. The first one will map your textures onto your model, and the second one is the lightmap. The lightmap is required for your model to receive shadows (I believe). Create a second UV map, select all of your geometry, press U to access the UV map menu, and select "Lightmap Pack".
    Adding this second UV map is what FINALLY made my CSGs work right. I'm lucky I learned about them when I was learning UE4.

    [​IMG]

    Your model should have one material, which is made up of two image textures: diffuse and normal. Link to the appropriate files for your diffuse and normal textures. Those texture files should be named <model name>_diffuse.png, etc. Mine are named field1_lotus_01_diffuse.png and field1_lotus_01_normal.png. I recommend having the textures already in your pa/terrain/<biome>/textures folder. For both textures, go to the Mapping tab, and make sure Coordinates are set to UV and Map is set to UVMap (not your lightmap).

    Now you need to tell Blender/FBX-exporter how these textures are used. Go down to the Influence tab.

    For your diffuse texture, only the Color checkbox should be checked (and set to 1.000). See here
    For your normal texture, only the Normal checkbox should be checked (and set to 1.000). See here
    Doing this correctly tells papatran that your model will use a diffuse texture and a normal texture. CSGs don't use material textures, those are typically used to show team colors on units.

    Your model should be ready to export to FBX, so go ahead and do so. Default settings will work, but check "selected objects only". My file is named field1_lotus_01.fbx. I recommend putting it in your pa/terrain/<biome>/fbx folder. Now you need to convert it to the games papa file format with papatran.exe, with this command:

    papatran.exe --texture-mode reference -o field1_lotus_01.papa field1_lotus_01.fbx
    Review this thread to learn how to use tran and dump: Link. Double check your new papa file by running it through papadump.exe. Make sure the name attribute of your textures is correct. All too often you'll have one too many or one too few slashes in there, and it wont work. It should look something like this: Link. You can run papadump.exe over Uber's files for more examples. Your papa model file will only reference the names of your two textures, it should not have them embedded within. Run your textures through papatran.exe with this command:

    papatran.exe --texture-mode include -o field1_lotus_01_diffuse.papa field1_lotus_01_diffuse.png
    The papa textures should look something like this: Link. When running the textures, a file named default.settings should be in the same folder as your textures, with these lines in it: Link. Papatran.exe will combine the resource-root line with the texture name to make the "name: " line as shown in the second previous link. As with everything else in this tutorial, swap out the names of my files and directories to your own.

    Making Features

    Features are made the same way, but you do not need the second UV map and they don't typically use normal maps. Most likely to save on memory/gpu usage as thousands of them may spawn on a planet at a time.

    The process can be an elite pain in the behind, don't panic if you can't get it to work the first dozen or two times. This tutorial is a first draft, I'm sure some of these things can be done differently, but I'm showing you how I got everything to work. Let me know if you got it to work or need help.

    [​IMG]
    Last edited: March 26, 2018
  2. stuart98

    stuart98 Post Master General

    Messages:
    6,020
    Likes Received:
    3,902
    Quitch and Nicb1 like this.
  3. sardaukar666

    sardaukar666 Well-Known Member

    Messages:
    128
    Likes Received:
    286
    I don't think I can like this op enough
    Nicb1 likes this.
  4. acesoyster

    acesoyster Active Member

    Messages:
    114
    Likes Received:
    179
    For reference, any chance we can get an ascii version of one of your .fbx files? Would be helpful in trying to replicate the process in 3DS max
    okeanos likes this.
  5. allister

    allister Active Member

    Messages:
    115
    Likes Received:
    175
    I'm uploading the files for the custom planet you see in the screenshots, to be used for learning or to add on to. It has some source files in it too: my blend file (some image links will be broken), the lotus ascii fbx file, another feature file.

    You can enable the planet in game by dragging 'field1', 'field2', 'meadow.json' into media\pa\terrain. Then go to media\ui\main\game\system_editor\system_editor.js and add 'meadow' to the line self.biomes = ko.observableArray([......

    Attached Files:

  6. wpmarshall

    wpmarshall Planetary Moderator

    Messages:
    1,833
    Likes Received:
    2,938
    Now this is great!
    All I need to do is learn how to use blender..... any takers of being a mentor? ;)
  7. acesoyster

    acesoyster Active Member

    Messages:
    114
    Likes Received:
    179
    In a move that can only be described as inconvenient, blender's ascii FBX export doesn't include texture references, making its use as a comparison tool significantly diminished :(

    [Edit] Turns out, importing a blender binary FBX that works into 3ds then re-exporting it is fine, so I now have a workign ascii FBX. I am now inspecting for differences.
    Last edited: March 26, 2018
    okeanos and Quitch like this.
  8. mikeyh

    mikeyh Post Master General

    Messages:
    1,954
    Likes Received:
    1,670
    fbxdump field1_lotus_01.fbx > field1_lotus_01.fbxdump.txt

    Attached Files:

    Quitch likes this.
  9. acesoyster

    acesoyster Active Member

    Messages:
    114
    Likes Received:
    179
    I don't believe that fbx dump contains the texture referencing either, which from the testing I've done so far, is critical to papatran's success in identifying the correct vertex format. I'm very close to having this work with 3DS max. Once I've got past a final oddity I will post my discoveries here along with a rundown of the comparison between the two applications' fbx files.
    okeanos and Quitch like this.
  10. acesoyster

    acesoyster Active Member

    Messages:
    114
    Likes Received:
    179
    [EDIT] For prosperity, I've corrected some errors in the information below. I'll be releasing a full guide once i get round to making the necessary screenshots.

    Apologies for the double-reply, but I got 3DS working before anyone else replied. For the really small images I have larger copies saved should anyone request them.

    I’d previously reached the point where texture referencing was working for 3DS exports, but only for diffuse maps. Below shows a comparison of papadump output between my model and a base-game CSG papa (unusually, moon_ruin contains a material texture. Most CSG only have Diffuse and Normal textures).

    [​IMG]

    My 3DS material was set up as shown below.

    [​IMG]

    I had wrongly assumed that the bump map slot would be translated to a normal map. Upon inspecting the .fbx ASCII files, we can see that this is not the case. Apologies for the horrible comparison formatting. Relevant parts marked with purple.

    [​IMG]

    A working file is shown on the right, and my original is shown on the left. The two top boxes link an image file reference to a texture object, with a unique name that is underlined. Those texture objects’ names are then referenced in the bottom boxes to link the texture to a material attribute. In the case of the working example, the attribute linked is “NormalMap”, whereas in my previous attempt, it was “Bump”.

    [EDIT] I have now discovered that the 3DS material editor provides a block called "Normal Bump" that is inserted between the texture and the bump attribute. Using this corrects the FBX export.

    After making this change, papatran produces an appropriate CSG file, shown below. Note that the vertex buffer now has the correct format, and that the material lists a normal texture.

    [​IMG]

    Additionally, the 3DS Max file requires a second UV map channel, [EDIT] which is used to map the texture outside of the CSG edit mode. I generate this by adding an additional UVW Map modifier to the mesh, and set its map channel to 2 (as the Unwrap UVW modifier should have defaulted to channel 1). I'm not sure why one would ever want those mappings to be different, so there may be more to this than I have worked out.

    [​IMG]

    And finally, with a beautiful placeholder texture and a noise image used for normal, a proof of success:

    [​IMG]

    I write this up as an actual guide at some point soon.
    Last edited: March 29, 2018
    okeanos, lulamae and Quitch like this.
  11. mikeyh

    mikeyh Post Master General

    Messages:
    1,954
    Likes Received:
    1,670
    PA also uses a normal bump map.
  12. acesoyster

    acesoyster Active Member

    Messages:
    114
    Likes Received:
    179

Share This Page