Editing Blender To Zero-K

Jump to navigation Jump to search

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.

Latest revision Your text
Line 25: Line 25:
  
 
=== Importing textures ===
 
=== Importing textures ===
To open a texture you need to set a window to either the Image Editor or UV Editor mode, and then press the Open button in the top menu bar.  This will bring up a file menu where you can select a texture to bring into Blender.  Blender supports .dds textures by default, as well as most other image formats.   
+
To open a texture you need to set a window to either the Image Editor or UV Editor mode, and then press the Open button in the top menu bar.  This will bring up a file menu where you can select a texture to bring into Blender.  Blender supports .dds textures by default, as well as most other image formats.  However, spring uses textures somewhat uniquely and has two separate texture formats.  The first of these, referred to as tex1 or colour texture, uses Red Green Blue (RGB) channels to store colour data, and Alpha (A) to store whether that part of the file is teamcolour or not.  This means that by default a tex1 texture looks mostly blank(transparent) with some odd black bits scattered around.  You can fix this in Blender by scrolling the menu bar (hold middle button with cursor on menu, drag mouse to side) all the way to the right, and clicking the little drop down which says Display Channels [[File:Blender_display_channels.png]].  By default it is set to ''Colour and Alpha'' but you should set it to ''Colour'' when working with tex1 files to ignore the alpha channel.
 
 
You can certainly import any old texture and work with it, but if you are importing textures already used by Spring you should know that they are somewhat unusual.
 
 
 
Spring has two separate texture formats.  The first of these, referred to as tex1 or colour texture, uses Red Green Blue (RGB) channels to store colour data, and Alpha (A) to store whether that part of the file is teamcolour or not.  This means that by default a tex1 texture looks mostly blank(transparent) with some odd black bits scattered around.  You can fix this in Blender by scrolling the menu bar (hold middle button with cursor on menu, drag mouse to side) all the way to the right, and clicking the little drop down which says Display Channels [[File:Blender_display_channels.png]].  By default it is set to ''Colour and Alpha'' but you should set it to ''Colour'' when working with tex1 files to ignore the alpha channel.
 
  
 
Tex2 files are the ones in greenyblue with bits of red.  In those files the Red channel is how much that part of the texture emits light, the Green channel is how rough or smooth that part of the texture is (which determines how it reacts to light), and the Blue channel is how metallic and reflective that part of the texture is.  Areas which are cyan (full green and full blue) are mirror-smooth metal, so reflect the environment perfectly.  These should always have their colourspace set to non-colour data as they use each channel separately.  You can find that option in the right hand popout menu when in an image editor viewing them (shortcut key N by default) under the Image tab.
 
Tex2 files are the ones in greenyblue with bits of red.  In those files the Red channel is how much that part of the texture emits light, the Green channel is how rough or smooth that part of the texture is (which determines how it reacts to light), and the Blue channel is how metallic and reflective that part of the texture is.  Areas which are cyan (full green and full blue) are mirror-smooth metal, so reflect the environment perfectly.  These should always have their colourspace set to non-colour data as they use each channel separately.  You can find that option in the right hand popout menu when in an image editor viewing them (shortcut key N by default) under the Image tab.
Line 38: Line 34:
  
 
Blend files do not by default contain the textures referenced in them, but you 'can' optionally pack the textures into them for easy transfer between users or computers.  Explore the File->External Data menu for those options.
 
Blend files do not by default contain the textures referenced in them, but you 'can' optionally pack the textures into them for easy transfer between users or computers.  Explore the File->External Data menu for those options.
 +
  
 
=== Modelling for Zero-K ===
 
=== Modelling for Zero-K ===
Line 62: Line 59:
 
The core_other.dds is the tex2 file, so it is split into RGB channels and each of these channels appropriately processed and connected to the relevant part of the material.
 
The core_other.dds is the tex2 file, so it is split into RGB channels and each of these channels appropriately processed and connected to the relevant part of the material.
  
Finally the core_normals.dds contains a direct-x formatted normal map, so it is converted to an openGL format by inverting just the Green channel and is then passed through the normal calculation node to convert the image into a vector map, and then the vector map passed to the shader.
+
Finally the core_normals.dds contains a direct-x formatted normal map, so it is converted to an openGL format by inverting just the Red and Green channels and is then passed through the normal calculation node to convert the image into a vector map, and then the vector map passed to the shader.
  
 
TODO: Provide a blend file here that already has this material set up, just need to plug in textures.  Or just include atlas texture.  Airpad_packed.blend is sadly larger than 2mb so the wiki will not host it.
 
TODO: Provide a blend file here that already has this material set up, just need to plug in textures.  Or just include atlas texture.  Airpad_packed.blend is sadly larger than 2mb so the wiki will not host it.
  
 
== Export the model to .dae format ==
 
== Export the model to .dae format ==
Nowadays Spring can read .dae (Collada) files directly via the use of Assimp (Asset Importer).  This means the export process is reasonably simple.
 
 
Either clean your scene of everything you do not want to be exported, or select only the things you want exported.  Go to the File->Export menu and select Collada (.dae) format.  A file browser will open with various export settings on the right hand side.
 
 
You should pick Selection Only from the Main tab of export options if you want to limit it to selection.
 
 
Make sure that the orientation settings are correct.  You want to tell the exporter what axes you've been modelling with, not the axes you're looking for.  These are the default options and should usually be right, Spring/Assimp will then adjust them for use in engine, but if after checking things in Spring your object is oriented wrongly, you can try adjusting these and exporting again.  If all else fails, you can parent the root object(s) to an empty placed at the origin and rotate that. [[File:collada_default_export.png]]
 
 
 
=== A note on animation ===
 
=== A note on animation ===
Although Collada (.dae) files do support exporting animation, you should not do this as Spring cannot read the animation data.  Instead, animations in Zero-K are handled by a lua animation script known as LUS.
 
  
Although you cannot export the animations to Collada, you can still do your animations in Blender and use the Blender2Lus export script linked earlier to export a starting animation script.  It has several limitations, such as only exporting the active action from each object in the scene, but running it several times and tweaking and combining the generated scripts can reduce the amount of work in generating animation scripts immensely.  Further use of this script is, for the moment, outside the scope of this tutorial (because I haven't done it myself yet - feel free to replace this with detailed explanation if you have, though!)
 
  
 
== Set up texture associations and .dae.lua metadata ==
 
== Set up texture associations and .dae.lua metadata ==
Although Spring can read .dae files and the contained UV map, it does not support any sort of material or texture import, so you have to specify these manually.  Since at this point you have already set Blender up with a reasonable approximation of the texture process it should not be especially difficult.
 
  
You will need to provide a .dae.lua file with the same name as your model file, in the same directory, to tell Spring which texture files and associated data to use with the model.
 
 
For example, if your model export is snazzyUnit.dae and it is present under the /objects3d folder of your testing mod, you should make a snazzyUnit.dae.lua file and place that at /objects3d/snazzyUnit.dae.lua .
 
 
The documentation for these metadata files is [https://springrts.com/wiki/3DModels:AssimpMetadata here], but they are reasonably simple and a minimal example file is provided below:
 
 
<pre>
 
return {
 
tex1 = "core_color.dds",
 
tex2 = "core_other.dds",
 
invertteamcolor = false
 
}</pre>
 
 
Obviously if you are not using the atlas textures you will need to replace those names with the actual texture files you intend to use.  There are several other things that may need to be in this file, but as these differ per-unit you will need to decide what, if anything, to provide.  You should probably also decide on a radius to set - leaving it out autogenerates a large radius covering the entire model, but for many reasons it's not always appropriate.  Examine similar units in game (ctrl-alt-B shows collision bounds, radius is the grey sphere) and match them if necessary.
 
  
 
== Set up Zero-K mod that contains and uses your files ==
 
== Set up Zero-K mod that contains and uses your files ==
To get Zero-K to see your files and locally test your units (new or otherwise) you can use a mod, or download all the source and point your original version at it.  I will use a mod.
 
  
This is selectable in local skirmish mode (and theoretically you can distribute them to test in multiplayer) which allows you to check everything works in the engine without requiring any changes to the official repositories or a local development copy of the game - all you need is a working copy of Zero-K.  You should eventually check it works with a properly set up dev copy (and that copy can be used for many changes, if necessary) but for now a mod is simpler.
 
  
=== Making the mod ===
+
== Run Zero-K and point at your mod ==
Inside the Zero-K folder there is a games subfolder.  Inside that are numerous things, but if you make a new subfolder with a name ending in .sdd it will be read by the engine on startup.  A base mod is available to download [File:BaseMod.sdd.zip here] to build from if you would like an example.  More details on mod creation can be found here: [[Mod Creation]]
 
  
Create a mod and fill out the modinfo.lua, making sure to change the name and description so you can tell it apart when you are selecting it.  If the depends tag is listed as <nowiki>[[rapid:/zk:stable]]</nowiki> you will have to manually change it to the latest ZK version in this format:
 
<pre>depend = {
 
[[Zero-K v1.8.10.0]]
 
},</pre>
 
Update the version number appropriately.
 
  
=== File locations ===
+
== Fix whatever isn't right ==
Like many mods, the file structure downwards from the modname.sdd folder should exactly match the Zero-K internal virtual file system, and if there are any files in your mod that match names with base files, Zero-K will use your mod's file instead of the base file.
 
 
 
This allows you to selectively replace any files with whatever changed version you want, which is ideal for our purposes of testing a mod.  Any ''new'' files will also be loaded, allowing you to test entirely new units - although you may have to modify the buildoptions list of an existing factory or constructor to allow them to build your new unit.
 
 
 
<blockquote>AN IMPORTANT NOTE:
 
You should keep all of filenames and folder names lower case, as the virtual file system lowercases everything.  Double check your filenames, it needs to match exactly if you are replacing things.</blockquote>
 
 
 
=== Testing your mod ===
 
Once you have filled out your folders and files, probably (but not exclusively) using /objects3d , /units and /unittextures , you can progress to actually testing it works in-engine.
 
  
Load up Zero-K and go to singleplayer, then Skirmish.  The map and opponents do not especially matter, though if you are testing a lot you probably want to use an inactive AI (check through main lobby options for additional AI types if it's not there by default).
 
 
Go into Adv Options, and pick 'Select Mod'.  If the folder and modinfo are correct you should see your mod on the list.  If you do not, download the base mod, unzip it to the appropriate place and check if that shows up - if it does, the problem is with your mod.  If it does not, then something is probably in the wrong place.
 
 
Once you've selected your mod you should start the skirmish and attempt to test whatever you've actually changed.  At one point while doing this, Zero-K would not load because the interpreter for the mod's unitdef files was more strict than the main game's, so you may wish to follow the format used in the base mod (it overwrites lotus turrets) more exactly if you have this problem.
 
 
== Fix whatever isn't right ==
 
Do not expect everything to be perfect.  This is a very complicated process and something is probably broken somewhere - either way, check everything, and get used to the idea that you may have to edit, re-export, then restart the game a lot to retry with changes quite often.  Although unit definitions and such may be reloaded without quitting the game (TODO: what is the command to do this?  How reliable is it?) you should eventually restart Zero-K to do a round of final testing just to ensure that everything loads correctly from startup.
 
  
 
== The other bits ==
 
== The other bits ==
Line 178: Line 125:
  
 
<pre>
 
<pre>
buildingGroundDecalDecaySpeed = 30, --Seconds decal takes to fade out of existence
+
buildingGroundDecalDecaySpeed = 30, --Seconds decal fades in or out of existence?
buildingGroundDecalSizeX      = 12, --Size of the decal's X axis in footprint units  
+
buildingGroundDecalSizeX      = 12, --Size of decal X axis in footprint units  
buildingGroundDecalSizeY      = 12, --Size of the decal's Y axis in footprint units  
+
buildingGroundDecalSizeY      = 12, --Size of decal Y axis in footprint units  
 
buildingGroundDecalType      = [[unitname_aoplane.dds]], --filename of decal
 
buildingGroundDecalType      = [[unitname_aoplane.dds]], --filename of decal
  
Line 192: Line 139:
  
 
=== unitpic ===
 
=== unitpic ===
Unit pictures in the buildmenu are generated by an automated script.  This script lives as a Lua gadget within the Zero-K base content, so if you have your mod working you can load that up and generate a buildpic.
 
 
First, press F8 to show the debug console, then turn on cheats with /cheat (or !cheats in multiplayer, which will require host permissions.)
 
 
Then run <pre>/luarules buildicon {unitname}</pre>. You can run it with no unit name and instead buildicons if you want to generate buildicons for every unit in the game.  It should output the icons to your Zero-K folder under the /buildicons folder.  You will then have to move it to the /unitpics folder of your mod, name it appropriately, and check it works.
 
 
=== Developer mode test with full file system ===
 
 
Now is the time to test against the full developer mode run - see [[Developing]] for information on how to set that up.  Copy your files to an up to date copy of the latest source files from GitHub and check if they work there. 
 
 
Once they do you should be ready to make a pull request.  If you forked from the development version as the linked instructions suggest, you should be able to use your fork to do this.
 
 
[[category:Development]]
 

Please note that all contributions to Zero-K are considered to be released under the Creative Commons Attribution-ShareAlike (see Zero-K:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!

Cancel Editing help (opens in new window)