Space Engineers

Space Engineers

Not enough ratings
Official: Modding of trees for planets
By Simon5 and 3 collaborators
Before you say anything, yes, this is an official guide published by Keen Software House. I work there.

This guide will help you make your own trees for Space Engineers and place them on your own planet!
 
Rate  
Favorite
Favorited
Unfavorite
1. Preface
This guide describes the process of implementing a tree for Space Engineers based on the AlienLeafTree. The default red-ish AlienTree will be changed into a blue-ish version. Additionally, a fancy billboard for distant LOD will be made.



For the sake of simplicity I will not bother to create a mod. I am modifying the vanilla game here. Apply additional steps that are needed for mod creation where it's needed, and don't forget to backup your files in case things go wrong.
1.1. Required Software
  • 3ds Max 2012 with Mental Ray (modelling and rendering the tree)
  • Photoshop (painting textures and automation with actions)
  • xNormal (we will use the dilation filter it provides for Photoshop)
    Link[www.xnormal.net]
  • Blender (Compositing the rendered images together)
    Link[www.blender.org]
  • Havok Content Tools for Game Artists and Designers version 2012.2.0 (creating collisions)
    Link[www.spaceengineersgame.com]
  • DDS Array Creator

You must ensure that your 3d software works together with Havok Content Tools.

Also DOWNLOAD[drive.google.com] the archive with all the work files. You can examine it and take a look in case you get stuck.

2. Tree creation
Set your 3ds max units to centimeters.


















Use the provided FBX file as a reference for the maximum dimensions your tree can have.
This is important for rendering the Billboards later.
Also it needs a clean transform matrix and it's pivot and position at 0,0,0.

Additionally, you must create a plane that will use the billboard texture later. This will be the distant LOD model for the tree.
Look in the 3ds max file for the mesh with the name "AlienLeafTree_LOD2". It has the correct dimensions that we need. Don't change this.


2.1. Textures
Assign your Materials and textures. Separate the canopy (parts with alpha) from the trunk (no alpha) using material IDs.
































The AlienLeafTree_LOD2 mesh also has a Material with the same name and a blank texture node assigned. Basically you can rename this material as whatever you like. You just need to remember that name. For simplicity, I named it after the mesh.








2.2. Vertex Normals
Alpha planes that make up the canopy will get special treatment using custom vertex normals. It will improve the shading of the canopy a lot and will make it look fluffy.
Use Noors Normal Thief[www.scriptspot.com] to "steal" vertex normals from a sphere or a custom shape that resembles the canopy closer to get nice vertex normals.
Consult this guide[wiki.polycount.com] for more information about vertex normals.

Reset XForms before using the script.

The canopy should look like a spiky ball if you check the vertex normals using the Edit Normals modifier.

Left: Before stealing vertex normals, look at the canopy. Wrong vertex normals.
Right: Result after stealing vertex normals. Vertex normals of the alpha planes all point outward like a sphere.

2.3. Collisions
I will refer to parts of the original SE collisions guide here for convenience.
Recreate your tree with the most basic shapes. For better performance choose the best suitable way to model the collision model with as few shapes as possible (5 to 10 shapes or less).

From best to low:
1. Sphere
2. (Havok) Capsule
3. Box
4. Convex Mesh

Left: Sample collision meshes (with(left) and without(right) tree mesh for easier viewing)
Right: How to create Havok capsule
Bottom left: Sample settings for Havok capsule in modify panel
(TAPER SETTING IS NOT SUPPORTED BY SE AND SHOULD BE SET TO 1.0!)



Before continuing, ensure that all your collision meshes have clean transforms and their pivots are at world position 0,0,0 (the same as the tree mesh).

Now select all your collision meshes and create a compound rigid body.












It will ask if it should parent all shapes to create a hierarchy.
Confirm the popup dialogue by clicking "Yes".






It will create a hierarchy.




Havok added some additional modifiers to your collision meshes.
All meshes have a Shape modifier. The parent additionally has a Rigid Body modifier. Adjust the Shape Type in the Shape modifier accordingly. Spheres should be tagged as spheres, capsules as capsules, and so on.
2.4. Broken Tree Model
Also create a destroyed version of your tree. We just cut away the roots for the Space Engineers trees. The pivot stays the same.
It needs to have its collisions and mesh made in a way that it levitates above the ground. Otherwise, it will create problems.
The collision model can be much simpler. In this case it's just a tapered box around the trunk. Apply the same method as above.

Left: broken tree model
Right: broken tree model with collision
3. Tree export
3.1. Mesh
Export your tree mesh, LOD models + broken model to FBX format as usual.

In my case I export:
  • AlienLeafTreeBlue
  • AlienLeafTreeBlue_LOD2
  • AlienLeafTreeBlue_broken
I added the Blue to the name to not overwrite the original model.
3.2. Collision
For exporting Collisions, apply steps 6-13 from this guide.
You still have to change a few things.
Change the Default Convex Radius in the Create Rigid Bodies filter to 0.05.


Change step 10 so that the transformation matrix of the Transform Scene filter looks like this.
Otherwise, the exported collision mesh will be too big.


Adjust the Write to Platform filter to save the HKT file where you want it (the same folder as the tree fbx files).


Hit Run Configuration to export.
4. Rendering the Tree Billboard
4.1. Preparation
Copy the provided *.rps files from the 3dsmaxRenderPresets folder to C:\Users\%username%\Documents\3dsMax\renderpresets
  • TreeAlbedoAlphaRender.rps
  • TreeAORender.rps
  • TreeColormaskRender.rps
  • TreeDepthRender.rps

These presets will be used to simplify the rendering of different passes that we need to create the billboard:
  • Albedo
    * Basically the raw color of the tree
  • Alpha
    * Self explanatory
  • Depth
    * Looks like a gradient projected through the camera (white pixels mean something is close to the camera, black pixels represent that it's far away)
  • Colormask
    * Helps creating color variation
  • Ambient Occlusion
    * For slight self shadowing

Open the provided BillboardRender.max file.
Disable gamma correction (Customize -> Preferences)




















Import your tree into the file and cut away everything below the world grid.
It is already done for the sample tree.








Set up the materials with the Slate Material Editor. Use the example material setup for reference.

In case you use your own materials, set Ambient and Diffuse to black and set Self-Illumination to 100%. Otherwise you will get the wrong colors.



For simplicity I've already gone through these steps and assigned the materials to all the different meshes:
  • AlienLeafTree_ALBEDO
    * rendering the albedo and alpha
  • AlienLeafTree_AO
    * rendering ambient occlusion
  • AlienLeafTree_COLORMASK
    * rendering the colormask
  • AlienLeafTree_DEPTH
    * rendering the depth pass
4.2. Rendering
Example: Rendering Albedo

1. Hide every mesh except AlienLeafTree_ALBEDO

2. Open the Render Setup Window (Rendering -> Render Setup).

3. Choose TreeAlbedoAlphaRender preset (should be in your C:\Users\%username%\Documents\3dsMax\renderpresets directory now) and check your settings (important stuff outlined in red).
But since there are pre-sets, you don't have to worry.


Quick explanation:
We want to render 181 frames in 256x256 resolution and want to save them as TGA files on the hard drive.

4. Just enable the Save File checkbox and save it as a TGA on your hard drive.
There won't be any files saved otherwise.

I save my renders using this convention:
AssetName_LODX_Pass.tga

In this example it works like this:
AlienLeafTreeBlue_LOD2_Albedo.tga

Use these settings for saving your TGA files.


5. Click on the Viewport name, choose the RenderCamera and enable Show Safe Frames.


The viewport should look like this now.
A tree inside a thin yellow square (render area) seen through an orthographic camera without roots.


6. Scrub through the timeline and check if parts of the tree ever leave this yellow frame OR come too close to it. There should be some free space. If the tree doesn't fit in the frame, change your tree to make it fit (move some leaves or something).

If everything fits inside the frame you are ready to render.

7. After all this tedious preparation you can finally render.
Choose RenderCamera from the View dropdown menu at the bottom of the Render Setup window and hit the big Render button.


It will display the Render Window and progress information.



8. Proceed to Render Depth, Colormask, and Ambient Occlusion.

As a reminder.
Choose the correct render preset to render the image sequences and don't forget to name them accordingly, so that you can easily find them after rendering.

  • TreeAlbedoAlphaRender
    * Albedo
  • TreeAORender
    * Ambient Occlusion
  • TreeColormaskRender
    * Colormask
  • TreeDepthRender
    * Depth

9. Check your files after rendering.

After rendering there should be 724 tga files in your folder (181 x 4).
  • AlienLeafTreeBlue_LOD2_Albedo####.tga
  • AlienLeafTreeBlue_LOD2_AO####.tga
  • AlienLeafTreeBlue_LOD2_Depth####.tga
  • AlienLeafTreeBlue_LOD2_Colormask####.tga
(#### stands for 4 digits)

















5. Post-Process
5.1. Compositing and Rendering
NOTE:
I changed the node layout a little bit after creating Blender screenshots, because I realized I made a small mistake. I added some in-between nodes that perform an operation with alpha channels that fixed some issues, and saved steps later on. Nothing you have to worry about. I will update this at a later point. Just continue :-)

All those rendered files need special treatment now. Time for some Compositing with Blender.
You should be familiar with how the program works and how to move around, because I will not explain it here. Refer to the Blender manual.

Open the provided BillboardCompositing.blend file. Everything is already setup there.


Explanation of what happens here:
Albedo gets modified a little to create a little bit of color variation. This is optional.
Depth, colormask, ao (ambient occlusion) and alpha are combined into one image.

You need to adjust a few parameters to make it work.

Set the Source of the image nodes (leftmost nodes).
Assign albedo images to albedo image node, colormask images to colormask image node, etc.
Click the folder icon (highlighted in red) and choose the file that has the 4 zeros in its name. In my case it's for example: AlienLeafTreeBlue_LOD2_Albedo0000.tga


Change the Base path of the File Output node (rightmost node). Choose the folder where you want Blender to save your files to.


Also adjust File subpath to match your tree name.
In my case the File subpaths are:

  • AlienLeafTreeBlue_LOD2_####_tree
  • AlienLeafTreeBlue_LOD2_####_cm

For example: If your tree is called AwesomeTreeOfDoom, adjust accordingly:

  • AwesomeTreeOfDoom_LOD2_####_tree
  • AwesomeTreeOfDoom_LOD2_####_cm

The naming is very important, because your output files will be named based on what you type in there.
It takes the subpath name + tga extension when saving the files to the disk.

When everything is set up, hit the Animation button to start the rendering. Notice the slight highlighting of said button. Don't miss it ;-)


After the rendering is finished, it populates your chosen output folder with exactly 362 images.







5.2. Apply dilation with Photoshop
To not get strange artifacts around the alpha edges of the tree billboards, we need to batch process all those images inside Photoshop.
We need to add dilation. It means extending the border pixels to oblivion.

Example dilation applied to AlienLeafTreeBlue_LOD2_0000_tree.tga
Left: Before dilation
Right: After dilation














Install xNormal and its Photoshop filters.
Install the included Photoshop action DilateBillboard.atn to your Photoshop.
Restart Photoshop and you should have an additional xNormal submenu in your Photoshop Filter menu.

Click File -> Automate -> Batch to open the batch dialogue.


Set it up.
For the sake of simplicity, I did the following:
  • Copy rendered images from Blender to a new folder. In my case "DilatedImages".
  • Choose this folder as the source and just just overwrite the non-dilated rendered images from Blender with the new, dilated ones.


Hit OK and grab a coffee or snack. This will take a while to process.
6. Create the Billboard texture
Now we can finally create the dds array texture that will be used for the billboard.

Open the DDSArrayCreator.exe. This tool packs all the data into one convenient dds file.
It will ask for settings when launched the first time. By default it will save the dds array in its own program folder. Enable Resize in case your source images are bigger than 256x256.

Set up like this and confirm with OK.


Drag and drop the Folder with your dilated textures into the black mystery window of the DDS Array Creator.



After dropping the folder into the window, it immediately starts working.



The generated texture should have the size of either about 30.1 MB (with mipmaps) or 22.6 MB (without mipmaps).

Copy the dds file (AlienLeafTreeBlue_LOD2.DDS in my case) to your mod texture folder. For the vanilla game you find those dds textures here:
SpaceEngineers\Content\Textures\Models\Environment\Trees







7. Build models (MWM files)
I will not go through the whole process of creating MWM files using the ModelBuilder. You should know this. I will only point out some important things that might differ from the standard procedure.

Important changes to

AlienLeafTreeBlue.xml:
<?xml version="1.0"?> <Model Name="Default"> <Parameter Name="Centered">false</Parameter> <Parameter Name="RescaleFactor">0.01</Parameter> <Parameter Name="RescaleToLengthInMeters">false</Parameter> <Parameter Name="SpecularPower">10</Parameter> <Parameter Name="SpecularShininess">0.8</Parameter> <Material Name="AlienBark"> <Parameter Name="SpecularIntensity">0</Parameter> <Parameter Name="SpecularPower">2</Parameter> <Parameter Name="DiffuseColorX">255</Parameter> <Parameter Name="DiffuseColorY">255</Parameter> <Parameter Name="DiffuseColorZ">255</Parameter> <Parameter Name="Technique">MESH</Parameter> <Parameter Name="ColorMetalTexture">Textures\Models\Environment\Trees\AlienCorkBark_blue_cm.dds</Parameter> <Parameter Name="NormalGlossTexture">Textures\Models\Environment\Trees\AlienCorkBark_ng.dds</Parameter> </Material> <Material Name="AlienLeafs"> <Parameter Name="SpecularIntensity">0</Parameter> <Parameter Name="SpecularPower">2</Parameter> <Parameter Name="DiffuseColorX">255</Parameter> <Parameter Name="DiffuseColorY">255</Parameter> <Parameter Name="DiffuseColorZ">255</Parameter> <Parameter Name="Technique">ALPHA_MASKED</Parameter> <Parameter Name="ColorMetalTexture">Textures\Models\Environment\Trees\AlienLeafTreeBranches_blue_cm.dds</Parameter> <Parameter Name="NormalGlossTexture">Textures\Models\Environment\Trees\AlienLeafTreeBranches_ng.dds</Parameter> <Parameter Name="AlphamaskTexture">Textures\Models\Environment\Trees\AlienLeafTreeBranches_alphamask.dds</Parameter> <Parameter Name="WindScale">0.033</Parameter> <Parameter Name="WindFrequency">1.25</Parameter> </Material> <LOD Distance="20"> <Model>Models\Environment\Trees\AlienLeafTree_LOD2</Model> </LOD> </Model>

See the parameters WindScale and WindFrequency?
Those parameters are read by the engine and used to simulate slight wind movements.

At the bottom of this file is the part that deals with LODs.
Set the path to your tree LOD models there and set it at a sane distance.

AlienLeafTreeBlue_broken.xml:
<?xml version="1.0"?> <Model Name="Default"> <Parameter Name="Centered">false</Parameter> <Parameter Name="RescaleFactor">0.01</Parameter> <Parameter Name="RescaleToLengthInMeters">false</Parameter> <Parameter Name="SpecularPower">10</Parameter> <Parameter Name="SpecularShininess">0.8</Parameter> <Material Name="AlienBark"> <Parameter Name="SpecularIntensity">0</Parameter> <Parameter Name="SpecularPower">2</Parameter> <Parameter Name="DiffuseColorX">255</Parameter> <Parameter Name="DiffuseColorY">255</Parameter> <Parameter Name="DiffuseColorZ">255</Parameter> <Parameter Name="Technique">MESH</Parameter> <Parameter Name="ColorMetalTexture">Textures\Models\Environment\Trees\AlienCorkBark_blue_cm.dds</Parameter> <Parameter Name="NormalGlossTexture">Textures\Models\Environment\Trees\AlienCorkBark_ng.dds</Parameter> </Material> <Material Name="AlienLeafs"> <Parameter Name="SpecularIntensity">0</Parameter> <Parameter Name="SpecularPower">2</Parameter> <Parameter Name="DiffuseColorX">255</Parameter> <Parameter Name="DiffuseColorY">255</Parameter> <Parameter Name="DiffuseColorZ">255</Parameter> <Parameter Name="Technique">ALPHA_MASKED</Parameter> <Parameter Name="ColorMetalTexture">Textures\Models\Environment\Trees\AlienLeafTreeBranches_blue_cm.dds</Parameter> <Parameter Name="NormalGlossTexture">Textures\Models\Environment\Trees\AlienLeafTreeBranches_ng.dds</Parameter> <Parameter Name="AlphamaskTexture">Textures\Models\Environment\Trees\AlienLeafTreeBranches_alphamask.dds</Parameter> <Parameter Name="WindScale">0.033</Parameter> <Parameter Name="WindFrequency">1.25</Parameter> </Material> <Material Name="PineLeafBranches"> <Parameter Name="SpecularIntensity">0</Parameter> <Parameter Name="SpecularPower">2</Parameter> <Parameter Name="DiffuseColorX">255</Parameter> <Parameter Name="DiffuseColorY">255</Parameter> <Parameter Name="DiffuseColorZ">255</Parameter> <Parameter Name="Technique">MESH</Parameter> <Parameter Name="ColorMetalTexture">Textures\Models\Environment\Trees\PineLeaf_cm.dds</Parameter> <Parameter Name="NormalGlossTexture">Textures\Models\Environment\Trees\PineLeaf_ng.dds</Parameter> <Parameter Name="AddMapsTexture">Textures\Models\Environment\Trees\PineLeaf_add.dds</Parameter> </Material> </Model>

No special treatment here for the broken tree. Just additional material for the cutoff section.

AlienLeafTreeBlue_LOD2.xml:
<?xml version="1.0" ?> <Model Name="Default"> <Parameter Name="Centered">false</Parameter> <Parameter Name="RescaleFactor">0.01</Parameter> <Parameter Name="RescaleToLengthInMeters">false</Parameter> <Parameter Name="SpecularPower">10</Parameter> <Parameter Name="SpecularShininess">0.8</Parameter> <Material Name="AlienLeafTree_LOD2"> <Parameter Name="SpecularIntensity">0</Parameter> <Parameter Name="SpecularPower">2</Parameter> <Parameter Name="DiffuseColorX">255</Parameter> <Parameter Name="DiffuseColorY">255</Parameter> <Parameter Name="DiffuseColorZ">255</Parameter> <Parameter Name="Technique">ALPHA_MASKED</Parameter> <Parameter Name="ColorMetalTexture">Textures\Models\Environment\Trees\AlienLeafTreeBlue_LOD2.dds</Parameter> <Parameter Name="Facing">Impostor</Parameter> </Material> </Model>

Different from the standard XML file, only one texture is defined here, because those tree billboards get special treatment from the engine. Only define the DDS array here as the ColorMetalTexture. Don't forget to set the Facing to Impostor. Also set the Technique to ALPHA_MASKED.

Save the XML files and build the models.

Move built MWM files and textures to your mod/game folder.
8. Get it in the game
Now to finally get it in the game there are still some small steps involved. We need to add the tree to the definitions.
  • SpaceEngineers\Content\Data\EnvironmentItemClasses.sbc
  • SpaceEngineers\Content\Data\Trees.sbc

In this case I will add a new type of trees that will spawn on the alien planet together with it's red tree buddies.

Open the Trees.sbc file and add an entry:
<EnvironmentItem xsi:type="MyObjectBuilder_TreeDefinition"> <Id> <TypeId>MyObjectBuilder_Tree</TypeId> <SubtypeId>AlienLeafTreeBlue</SubtypeId> </Id> <Model>Models\Environment\Trees\AlienLeafTreeBlue.mwm</Model> <BranchesStartHeight>2.342</BranchesStartHeight> <PhysicalMaterial>Wood</PhysicalMaterial> <HitPoints>50</HitPoints> <CutEffect>ChipOff_Wood</CutEffect> </EnvironmentItem>
I just copy-pasted the existing definition for the regular red AlienLeafTree, changed the name to AlienLeafTreeBlue and changed the path of the mwm file to AlienLeafTreeBlue.mwm.

It looks like this:
<EnvironmentItem xsi:type="MyObjectBuilder_TreeDefinition"> <Id> <TypeId>MyObjectBuilder_Tree</TypeId> <SubtypeId>AlienLeafTree</SubtypeId> </Id> <Model>Models\Environment\Trees\AlienLeafTree.mwm</Model> <BranchesStartHeight>2.342</BranchesStartHeight> <PhysicalMaterial>Wood</PhysicalMaterial> <HitPoints>50</HitPoints> <CutEffect>ChipOff_Wood</CutEffect> </EnvironmentItem> <EnvironmentItem xsi:type="MyObjectBuilder_TreeDefinition"> <Id> <TypeId>MyObjectBuilder_Tree</TypeId> <SubtypeId>AlienLeafTreeBlue</SubtypeId> </Id> <Model>Models\Environment\Trees\AlienLeafTreeBlue.mwm</Model> <BranchesStartHeight>2.342</BranchesStartHeight> <PhysicalMaterial>Wood</PhysicalMaterial> <HitPoints>50</HitPoints> <CutEffect>ChipOff_Wood</CutEffect> </EnvironmentItem>
Now modify the EnvironmentItemClasses.sbc file. Scroll way down until you find the entry:
<Entry Type="MyObjectBuilder_Trees" Subtype="AlienGreenGrassForestMedium" ItemSubtype="AlienLeafTree" Frequency="0.2"/>
The Subtype defines in which kind of biome this tree will spawn. ItemSubtype defines which tree will spawn. Frequency defines how often it spawns.

Remember that we added a new type of tree in the Trees.sbc called AlienLeafTreeBlue? Now it becomes important.

We will just copy this line ...
<Entry Type="MyObjectBuilder_Trees" Subtype="AlienGreenGrassForestMedium" ItemSubtype="AlienLeafTree" Frequency="0.2"/>
... and change it into this:
<Entry Type="MyObjectBuilder_Trees" Subtype="AlienGreenGrassForestMedium" ItemSubtype="AlienLeafTreeBlue" Frequency="0.2"/>
I ended up with the following two lines, because I wanted to spawn the two different trees in the same biome. Feel free to add the tree to different biomes as you see fit and adjust the frequency to your liking. Remember: Higher frequency means more trees, which ultimately leads to worse performance. Try to keep this balanced.
<Entry Type="MyObjectBuilder_Trees" Subtype="AlienGreenGrassForestMedium" ItemSubtype="AlienLeafTree" Frequency="0.2"/> <Entry Type="MyObjectBuilder_Trees" Subtype="AlienGreenGrassForestMedium" ItemSubtype="AlienLeafTreeBlue" Frequency="0.2"/>
This shall conclude this guide.
Start your game and check the results.


< >
1 Comments
Harag Dec 25, 2015 @ 8:23am 
The "Havok Content Tools" listed in section "1.1 Required Software" is unobtainable. Intel has stopped distribution of the free package. This is already reported as a bug on the forum [forums.keenswh.com].