Reply To: [Discussion} Modding the industry

Home Forums Modding [Discussion} Modding the industry Reply To: [Discussion} Modding the industry

#8065
douglas
Participant

This is a guide from GWINDA. The autor of the Cargo Mod. The guide might not be up to date, was made in beta.

 

[HOW-TO] Design your own industry prefabs. (tutorial)

In this tutorial I will show, step-by-step, how to assemble a new industry prefab like this one:

 

http://cloud-4.steampowered.com/ugc/576776903191918631/F50825C439ACB47FEF4B18A3C7471D4EA5B14AC1/2048×1152.resizedimage

http://cloud-4.steampowered.com/ugc/576776903194271396/63DFBD539052CBFAFF00745B204A502D64EFAD33/2048×1152.resizedimage

 

The factory building, ovens and coal box comes from the steel mill industry meshes.

The cranes, steel pipes and crates from the asset meshes.

 

The coal box has been retextured to show only coal.

 

Background

It is easier if you start with a copy of an industry in about the same size you want to create.

For example \res\models\model\industry\forest_1850.mdl

Open the copy with a text editor or any other suitable software, I use Programmer’s Notepad because it gives me Lua syntax highlight.

 

I will briefly explain what I think it does.

 

boundingInfo

My guess is that this is the collision box when placing roads/tracks. You don’t need to change this.

 

collider

This is empty so I guess it isn’t used, leave it as it is.

 

lods

Now here is the interesting part and we will focus on the children table.

For each mesh you add, it needs to be a node inside the children table.

 

id

The filename of the mesh you want to add, including a relative path from \res\models\mesh

 

transf

This is a 4 by 4 transformation matrix that will be applied to the mesh. If you aren’t familiar with transformation matrixes, here is a layman crash course:

 

1, 0, 0, 0,

0, 1, 0, 0,

0, 0, 1, 0,

0, 0, 0, 1

 

This transformation places the mesh at position 0,0,0 at scale 1:1 no rotation. The bottom row shifts the mesh in x,y and z direction (moving it in 3D space).

 

To place a mesh at X10, Y3 and Z-0.1 the transformation looks like this:

 

1, 0, 0, 0,

0, 1, 0, 0,

0, 0, 1, 0,

10, 3, -0.1, 1

 

To scale a mesh we multiply the diagonal row of 1:s (except the last one) with the scale factor. The first row scale in X, second in Y and the third in Z direction. To scale a mesh double wide, half the height and same depth:

 

2, 0, 0, 0,

0, 1, 0, 0,

0, 0, 0.5, 0,

0, 0, 0, 1

 

Rotation is a bit more tricky, I will explain how to rotate around the Z axle since this is the most common use of it.

 

You need to calculate the COS and SIN of the angle you want to rotate, then insert them in the matrix like this:

 

COS,-SIN,0,0

SIN,COS,0,0

0, 0, 1, 0,

0, 0, 0, 1

 

Replace the COS and SIN with their resp value. Observe that the SIN value is negated on the first row. To rotate the mesh 35 degrees we get SIN 35 = 0.5735764336 and COS 35 = 0.819152044. The matrix will look like this:

 

0.819152044,-0.5735764336,0,0

0.5735764336,0.819152044,0,0

0, 0, 1, 0,

0, 0, 0, 1

 

So what if we want to shift, rotate and scale at the same time?

The last row is not interfering with anything, so just enter the X,Y and Z coords there. The rotation and Scaling are using the same rows, but this isn’t a problem. Just multiply the COS value with the scale for that axle and the 1 in on the third row.

 

To place the mesh at X10,Y3,Z-0.1, rotate it 35 degrees and scale all axes with 2:

 

1.638304089,-0.5735764336,0,0

0.5735764336,1.638304089,0,0

0, 0, 2, 0,

10, 3, -0.1, 1

 

Easy! 🙂

 

type

This has to be “MESH” if the id is a mesh file or “GROUP” if it is a group file. We will only work with mesh files here.

 

events

This doesn’t seems to be implemented yet. I have seen some depo doors using events, but the never move in the game.

 

matConfig

My first thought was that this is the child’s material index, but it crash if I set it to anything else than 0. There has to be one 0 for each child table +1. So if you have 3 meshes, there must be 3+1 zeros here.

 

static

Haven’t tested this one yet.

 

visibleFrom

This is the near clip range, how near can the object be. leave it by 0.

 

visibleTo

Now, this is an interesting one. This is the far clip distance. If you want to see this model from far away, like maxed zoom out, increase this value. Also remember that it will put extra load on game performance.

 

metadata

This is where you define what goods you need for the production and the goods produced.

 

requiredTypes

This is an array of all needed goods. In this example it is empty because a forest only produce without any required input.

productionType

Here we can specify ONE goods that will be produced, in this case “WOOD”.

 

Set up the base

First we add the ground texture. Change the child node to:

{

id = “refinery/oil_old_lod_0_floor.msh”,

transf = {

1, 0, 0, 0,

0, 1, 0, 0,

0, 0, 1, 0,

0, 0, 0, 1,

},

type = “MESH”,

},

 

Before we can test this we need to be sure we have enough 0 in the matConfig section:

matConfigs = {

{

0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ,0, 0, 0, 0, 0, 0

},

I added all the 0 we will need for this model at once, 17 meshes +1.

 

If you save and generate a new map you should spot some “empty” industries.

Lets add the factory building rotated 90 degrees; COS 90 = 0 and SIN 90 = 1, scale 1:1.

{

id = “industry/steel_mill_1850_lod_0_fabric.msh”,

transf = {

0, -1, 0, 0,

1, 0, 0, 0,

0, 0, 1, 0,

-11, 8, 0, 1,

},

type = “MESH”,

},

Now place 2 ovens, no rotation scale 1:1.

{

id = “industry/steel_mill_1850_lod_0_oven.msh”,

transf = {

1, 0, 0, 0,

0, 1, 0, 0,

0, 0, 1, 0,

8, 5.5, 0, 1,

},

type = “MESH”,

}, {

id = “industry/steel_mill_1850_lod_0_oven.msh”,

transf = {

1, 0, 0, 0,

0, 1, 0, 0,

0, 0, 1, 0,

15, 11, 0, 1,

},

type = “MESH”,

},

 

The coal box has been both rotated 90 degrees and scaled down to 50% on X,Y and to 40% on Z.

Remember that COS 90 and SIN 90 are 0 resp 1 multiplied with the scale:

{

id = “industry/steel_mill_1850_lod_0_mat.msh”,

transf = {

0, 0.5, 0, 0,

-0.5, 0, 0, 0,

0, 0, .4, 0,

-15, 1.9, 0, 1,

},

type = “MESH”,

},

On my picture it has also been retextured to contain only coal. I will explain how to do this in another post.

Now add in some clutter like steel pipes, crates and steel beams:

{

id = “asset/industry/steal_pipes_01_lod_0_steal_pipes_01.msh”,

transf = {

1, 0, 0, 0,

0, 1, 0, 0,

0, 0, 1, 0,

2.4, -13, 0, 1,

},

type = “MESH”,

}, {

id = “asset/industry/steal_pipes_01_lod_0_steal_pipes_01.msh”,

transf = {

1, 0, 0, 0,

0, 1, 0, 0,

0, 0, 1, 0,

1.2, -12.23, 0, 1,

},

type = “MESH”,

}, {

id = “asset/industry/steal_pipes_01_lod_0_steal_pipes_01.msh”,

transf = {

1, 0, 0, 0,

0, 1, 0, 0,

0, 0, 1, 0,

0, -13.01, 0, 1,

},

type = “MESH”,

}, {

id = “asset/industry/wooden_box_03_lod_0_wooden_box_03.msh”,

transf = {

1, 0, 0, 0,

0, 1, 0, 0,

0, 0, 1, 0,

10, 0, 0, 1,

},

type = “MESH”,

}, {

id = “asset/industry/wooden_box_03_lod_0_wooden_box_03.msh”,

transf = {

1, 0, 0, 0,

0, 1, 0, 0,

0, 0, 1, 0,

11, -0.1, 0, 1,

},

type = “MESH”,

}, {

id = “asset/industry/wooden_box_03_lod_0_wooden_box_03.msh”,

transf = {

1, 0, 0, 0,

0, 1, 0, 0,

0, 0, 1, 0,

12.3, 0, 0, 1,

},

type = “MESH”,

}, {

id = “asset/industry/wooden_box_03_lod_0_wooden_box_03.msh”,

transf = {

1, 0, 0, 0,

0, 1, 0, 0,

0, 0, 1, 0,

13.4, 0.2, 0, 1,

},

type = “MESH”,

},  {

id = “asset/industry/metal_beam_01_lod_0_metal_beam_01.msh”,

transf = {

0.984807753, -0.173648177, 0, 0,

0.173648177, 0.984807753, 0, 0,

0, 0, 1, 0,

12.6, -6, 0, 1,

},

type = “MESH”,

},  {

id = “asset/industry/metal_beam_01_lod_0_metal_beam_01.msh”,

transf = {

0.866025403, -0.5, 0, 0,

0.5, 0.866025403, 0, 0,

0, 0, 1, 0,

13.4, -8, 0, 1,

},

type = “MESH”,

},

 

Now we only need to add the two last cranes. There are one base and one crane mesh for each crane.

{

id = “asset/crane_old_lod_0_cube.msh”,

transf = {

0.707106781, -0.707106781, 0, 0,

0.707106781, 0.707106781, 0, 0,

0, 0, 1, 0,

-6, -8, 0, 1,

},

type = “MESH”,

}, {

id = “asset/crane_old_lod_0_polymsh.msh”,

transf = {

0.707106781, -0.707106781, 0, 0,

0.707106781, 0.707106781, 0, 0,

0, 0, 1, 0,

-6, -8, 0, 1,

},

type = “MESH”,

}, {

id = “asset/crane_old_lod_0_cube.msh”,

transf = {

-0.707106781, -0.707106781, 0, 0,

0.707106781, -0.707106781, 0, 0,

0, 0, 1, 0,

16, -2, 0, 1,

},

type = “MESH”,

}, {

id = “asset/crane_old_lod_0_polymsh.msh”,

transf = {

-0.707106781, -0.707106781, 0, 0,

0.707106781, -0.707106781, 0, 0,

0, 0, 1, 0,

16, -2, 0, 1,

},

type = “MESH”,

},

 

If you save and test you will have this model producing wood. Let us change it to accept coal and wood to produce goods.

In the metadata section we set up the requirements:

metadata = {

industry = {

requiredTypes = { “COAL”,”WOOD” },

productionType = “GOODS”

}

},

 

That’s it folks.

I will make a new tutorial on how to re-texture and create new goods types.