Author Topic: Creating a 3d model house in blender and making it available in game  (Read 5237 times)

0 Members and 1 Guest are viewing this topic.

Offline Discrepancy

  • Modders
  • Architect
  • *****
  • Posts: 591
Hello,

I thought I would try to make a (hopefully) straight forward tutorial for anyone wanting to get a model into banished.

I'm using Blender 2.76, this a free open source program, updated often  you can download lastest version for free here.

First up I'll give a list of the my most used keyboard shortcuts for blender when 3d modelling (these are very handy, and enable quicker and less tiresome 3d modelling):
tab = change between Edit / Object mode.
shift + A = Add a mesh / a shape predefined or adjustable.
A = toggle between Select all / Select none
L + hovering cursor over vertex/edge/face = Select Linked, selects vertices attached.
shift + D = adds a duplicate of the selected vertices
E = extrudes face/edge/vertex
S = Scale, adjust the scale, size of the selected vertices
R = Rotate
Also using the numpad buttons 1-9,
most important is:
1 = front view
3 = side view
7 = top down view

alternatively many of these can be accessed through a menu (bottom left of my screen [View | Select | Add | Object/Mesh] in the pictures below)


links to sites that I have used to learn from:

The Blender Manual
Blender Keyboard shortcuts
and a good printable quick access for most used shortcuts: BlenderHotkeysCheatsheet.pdf

and a tutorial that helped me a lot:
Creating a Low Poly Medieval House in Blender: Part 1
& mostly Part 2

I will post the full tutorial over the next few days...


I will also upload all code and source code, as well as a .pkm version for those who just want to play :) I hope to inspire a lot of would-be modders.
« Last Edit: June 26, 2016, 09:49:28 AM by Discrepancy »

Offline Discrepancy

  • Modders
  • Architect
  • *****
  • Posts: 591
Re: Creating a 3d model house in blender and making it available in game
« Reply #1 on: June 26, 2016, 09:25:11 AM »
Creating a 3d model house in blender and making it available in game
Part 1

Open up Blender, start a New project,
delete everything (press the A key to select all, press del and then enter key),
In the Properties window panel, click on 'Metric'(1), and ensure that the scale is set to 1.000 (2)
It should look like this:

http://i.imgur.com/0TfMtb2.jpg
Creating a 3d model house in blender and making it available in game


Setting the measurement system and scale to metric will mean that a square in Blender will represent a game tile square in Banished.
Orientate your view so that the Y-axis travels away from you (3) – this is your North point in the game.
Also ensure you are in 'Object Mode'.

Press shift + A then click on  Add – Mesh – Cube

http://i.imgur.com/X7nJBpX.jpg
Creating a 3d model house in blender and making it available in game


Press Tab to enter into 'Edit Mode' (4).
Click on 'Face Select' (5), and then click on the icon next to it 'Limit Selection to Visible', this will allow you to see through the now semi-transparent faces for easier editing.

http://i.imgur.com/RGYsmFe.jpg
Creating a 3d model house in blender and making it available in game


Press A key to deselect the cube.
Now select only the lowest face, and in the 'Transform' window pane, change the Median  Z: to 0m (6), this will bring the bottom of the cube up to ground height.

http://i.imgur.com/KMZFJaz.jpg
Creating a 3d model house in blender and making it available in game


We are going to make a house with a footprint of width 4 x height 3 + road, to sit in a 4x4 plot.
In blender, from point 0,0,0 (the 0 point at which the x,y,z – axis points meet) we will make our model fit within the 2 squares to either side to that point...

By selecting faces one at a time, move the cube and adjust shape and size so it looks like this:

http://i.imgur.com/s1FTxnN.jpg
Creating a 3d model house in blender and making it available in game


This will be the stone foundation.

http://i.imgur.com/SBcvTt5.jpg
Creating a 3d model house in blender and making it available in game


Using a selection of 'Edge Select' (7) to adjust the edges of the mesh, and then using the E key to extrude faces, create the houses stone foundation to look like this:

http://i.imgur.com/zNohnbQ.jpg
Creating a 3d model house in blender and making it available in game


rotating your view , and holding shift while selecting the individual faces of the underside of the foundation, press delete, and press Delete – Faces.

http://i.imgur.com/AN43Zse.jpg
Creating a 3d model house in blender and making it available in game


Press A key to select all. Then press ctrl + E to bring up Edges menu, click on 'Mark Seam' and this should have marked all of the surrounds of the foundation faces in red:

http://i.imgur.com/d7HnOQR.jpg
Creating a 3d model house in blender and making it available in game


Press A to select all again, then press U to bring up the UV mapping menu and click on 'Unwrap'.

Now we need to bring up another view with the UV map on it.
Top Right of the screen (8) drag the little angle lines to the left, hide away the new duplicate menus that appear, then load up the UV/Image Editor view:

http://i.imgur.com/AoPbzPW.jpg
Creating a 3d model house in blender and making it available in game


Now in this new view you will see the UV mapping that will call up the textures. I'm going to give a quick basic tutorial, textures will be basic. In this new view, press S key and scale down the foundation faces on the UV square, and we will later create a basic texture.
http://i.imgur.com/mj0MUux.jpg
Creating a 3d model house in blender and making it available in game


Now, back to the 3d view, we will be making the wooden frame. We will add a new mesh cube by pressing shift + A to add a new mesh-cube.
Use the arrows to move it around, then press S to scale it smaller, adjust the faces to make an upright next to the doorway.

http://i.imgur.com/byHVSUW.jpg
Creating a 3d model house in blender and making it available in game


Now select only the top face, the bottom face and only one of the side edges, press ctrl = E, 'Mark Seam', hover over mesh, press L to select all connected vertices, press U, select 'Unwrap'.

http://i.imgur.com/EfdEWjt.jpg
Creating a 3d model house in blender and making it available in game


Scale down the UV map of the wooden frame upright, and place away from the area you put the stone foundation UV map

http://i.imgur.com/1eaQk9q.jpg
Creating a 3d model house in blender and making it available in game


Now back to the 3d view, we will deselect all, then only select the wooden frame upright we just created (hover over press L to select all connected vertices).
Press shift + D to duplicate, move each duplicate around the foundation to create the houses uprights for its frame.

http://i.imgur.com/loPBgTk.jpg
Creating a 3d model house in blender and making it available in game


Now duplicating one of the uprights again, press 1 on your keyboard's numpad to bring up front view, press R key to rotate and create a horizontal piece and using what we've learned, and utilise brining up the front, side and top views, duplicate, rotate and adjust pieces until you have a frame like this:

http://i.imgur.com/BHuc86a.jpg
Creating a 3d model house in blender and making it available in game

http://i.imgur.com/HxEO0b3.jpg
Creating a 3d model house in blender and making it available in game

In side view (press 3 on the numpad), use the 'Loop Cut and Slide' tool (10),
And with new edges in each roof truss, adjust so they are more 'rounded':

http://i.imgur.com/usjZNrd.jpg
Creating a 3d model house in blender and making it available in game


Create a duplicate of one of the trusses, move to the centre of your frame, to create a centre truss.
Press tab to exit to 'Object mode',
Your model should  loosely resemble this:

http://i.imgur.com/18du1FV.jpg
Creating a 3d model house in blender and making it available in game


Next, click on 'Object' (11), then 'Apply' (12), then 'Location' (13), again: Object, Apply and then this time 'Rotation & Scale' (14).

http://i.imgur.com/ggReyKC.jpg
Creating a 3d model house in blender and making it available in game


Save your project as a blender file.


« Last Edit: June 26, 2016, 10:37:54 PM by Discrepancy »

Offline Discrepancy

  • Modders
  • Architect
  • *****
  • Posts: 591
Re: Creating a 3d model house in blender and making it available in game
« Reply #2 on: June 26, 2016, 09:25:44 AM »
Part 2


Keyboard shortcus for working in UV mapping view:
S = Scale
G = Move
R = Rotate
W = Weld/Align tools
L = Select connected vertices




In part 2 we will finalise the 3d model.
First we will add the roof and walls.

Back into 'Edit Mode', add a new plane (press Shift + A, select Plane), move it into place over the centre of the house frame.
By selecting the planes face, click on 'Subdivide' (13) this will split the face into 4 planes, the using the 'Knife' tool, cut a new edge line from the centre of the roof to the outer corners. Pull down the edges and and make slight adjustments to create a roof like this:

http://i.imgur.com/1zEVw8j.jpg
Creating a 3d model house in blender and making it available in game


Select all the edge lines of the roof piece we just made.
Press ctrl + E to mark the seams, then by hovering over only a section of the roof plane, press L to highlight the rest of the roof,
Press U and unwrap the roof, it should have shown up in the UV window like this:

http://i.imgur.com/bAdkB4x.jpg
Creating a 3d model house in blender and making it available in game


Adjust the UV layout do the roof fits into the top right,
Your house and UV should look like this when you select all:

http://i.imgur.com/yvJpYp3.jpg
Creating a 3d model house in blender and making it available in game


Now we will add a front wall, by adding another plane and moving it into the frame and adjusting so it sits just back from the wooden frame,
It will look like this:

http://i.imgur.com/Qldy9co.jpg
Creating a 3d model house in blender and making it available in game


Now mark the seam of this wall and unwrap like we have done before scale and move the wall in the UV view to the bottom right.

Continue duplicating (shift + D) this front wall and fill up all the sides of the house.
By doing this, like we did with the Wooden frame, all of the walls will grab the same texture.

http://i.imgur.com/BXjQ7E6.jpg
Creating a 3d model house in blender and making it available in game


Fill up most of the holes between the walls and roof by using all you've learned.
Utilising the 'Loop Cut and Slide' tool (10), as well as the 'Knife' tool (13) will help you to split faces and then move edges around to fill in the gaps.

Once done we will add a chimney to the building.

I have pressed shift + A, added a new cube and moved it next to the wall and altered the shape like this:

http://i.imgur.com/dHzWLz8.jpg
Creating a 3d model house in blender and making it available in game


Next click on the top face of this cube and press E to extrude the face, pull this new section up over the roof, and click. With the top face still selected, press S to scale it slightly smaller than the base:

http://i.imgur.com/OKSlw89.jpg
Creating a 3d model house in blender and making it available in game


Now using the extrude and scale tools I made a 'lip' on the top of the chimney, and then made it go back down into the chimney a bit to create a 'hollow':

http://i.imgur.com/wXagJOH.jpg
Creating a 3d model house in blender and making it available in game


Delete the ground face on the chimney, deleting faces that are not visible is good practice to keep the poly count low.

Select all of the chimney (press L to select all connected vertices), move it back away from the house so we can UV unwrap it easier.

With 'Edge Select' active, highlight all of the bottom edges, then highlight one side of the rear chimney edge:

http://i.imgur.com/b7hUpPM.jpg
Creating a 3d model house in blender and making it available in game


Now zoom in and only select the edges that run around the bottom of the chimney 'lip'.

http://i.imgur.com/rLUQsPy.jpg
Creating a 3d model house in blender and making it available in game


Press ctrl + E to mark the seam you just highlighted, then deselecting, mark out the chimney 'lip' seam lines like this:

http://i.imgur.com/Isz0zgE.jpg
Creating a 3d model house in blender and making it available in game


Mark the seam, and then select all of the chimney, and press U to Unwrap the chimney.

In the UV window it'll look like this:

http://i.imgur.com/CSILBPC.jpg
Creating a 3d model house in blender and making it available in game


Using the tools for the UV map (see top of this post), scale, rotate and align edges to fit within the whole UV map:

http://i.imgur.com/Jg7ZaG8.jpg
Creating a 3d model house in blender and making it available in game


I have moved the chimney lip to a place that overlaps with what will be the foundation texture.

Back into the 3d view, select only the chimney and bring it back next to the house.

Now add a new plane, and adjust it so that it sits back within the door frame:

http://i.imgur.com/1wNH2Xj.jpg
Creating a 3d model house in blender and making it available in game


Mark the seams on this, and then Unwrap to bring it up on the UV map. Adjust so that is fits between everything:

http://i.imgur.com/p4YyDHD.jpg
Creating a 3d model house in blender and making it available in game


Now add in a new cube, this time scale and adjust, we will make a window, delete the back face, and then mark the seams like this:

http://i.imgur.com/dryeuWK.jpg
Creating a 3d model house in blender and making it available in game


Unwrap, and adjust on the UV map. I have moved the sides of the window to the same spot as the wooden frame to share the same wood texture. Select the window and then move it into the wall next to the door, I also duplicated it and added another window on the side wall.

http://i.imgur.com/seZUJcy.jpg
Creating a 3d model house in blender and making it available in game


So that is going to be our basic house model.
Exit to 'Object Mode' (press tab key), and it will look like this:
Ensure the model is still located at 0,0,0, click on 'Object' – 'Apply' – 'Location' and then 'Apply' - 'Rotation & Scale'

http://i.imgur.com/tlEoeCc.jpg
Creating a 3d model house in blender and making it available in game


Save your work :)
« Last Edit: June 26, 2016, 07:38:07 PM by Discrepancy »

Offline Discrepancy

  • Modders
  • Architect
  • *****
  • Posts: 591
Re: Creating a 3d model house in blender and making it available in game
« Reply #3 on: June 26, 2016, 09:26:06 AM »
Part 3


In part 3 we will be adding the (AO) Ambient Occlusion, creating the texture file, the build models and adding the points.



.... baking the AO

In 'Object Mode', add a new plane, align it to 0,0,0. Scale it so that it is larger than the house:

http://i.imgur.com/8So8IYl.jpg
Creating a 3d model house in blender and making it available in game


We add this to stop light shining through the bottom of the house when new bake the AO.

Select the house model, and in the properties window select 'World' (15), then activate 'Ambient Occlusion' (16), adjust the 'Gather' sample count to 10 (17).

http://i.imgur.com/L6nG5L2.jpg
Creating a 3d model house in blender and making it available in game


Now click on the 'Render' tab (18), scroll down until you find the 'Bake' section, change the Bake mode to Ambient Occlusion (19), change the margin to 10px (20)

http://i.imgur.com/xFEs4iw.jpg
Creating a 3d model house in blender and making it available in game


Now in the houses 'Edit mode', select all, and then in the UV view, click on 'Image' – 'New Image', keep all the default settings, and size of 1024x1024. Press okay.
Now click on the 'Bake' button (21).

http://i.imgur.com/Uho8iUf.jpg
Creating a 3d model house in blender and making it available in game


The ambient occlusion will have been 'baked' on this new image, you will see the effects in the UV view.
Press 'Image' – 'Invert' – 'Invert Image Colors' this will make the AO image have a predominantly white appearance, need to work with Banished.
Press 'Image' – 'Save as Image', save as an RGB (22) .png file, I named mine SmallTownHomeAO.png
Click on 'Save as image' (23)

http://i.imgur.com/cVliZ9i.jpg
Creating a 3d model house in blender and making it available in game


Back in the UV view, click on 'UVs'  - 'Export UV Layout' – change the 'Fill Opacity' to 0.000 (24).

I named my file SmallTownHomeUV.png, ensure it is saving as .png, click on 'Export UV Layout' (25)

http://i.imgur.com/iAmAnzx.jpg
Creating a 3d model house in blender and making it available in game


Enter into 'Object mode', select the plane we made just prior to baking the AO, and delete it as it is no longer needed.

Save your file.



.... Texturing

Now open up your SmallTownHomeUV.png image in a Image Editing program, I am using Adobe Photoshop, but there are plenty of others (and free ones) that can be used.

We want to now start adding textures to fit within the UV lines,

Put your textures into separate 'Layers' for easier editing..

All sorts of textures can be found on the internet for free use (I got all of these textures from Textures.com – requires setting up a free account)

This is what I have done for the textures:

http://i.imgur.com/o0Z3R5R.jpg
Creating a 3d model house in blender and making it available in game


Before saving I hide the UV lines, then I save the image as a .png format (SmallTownHome.png).



.... creating the Build models

Back into Blender.

Load up your .blend model of the house if not already.

Then 'File' – 'Export' – 'FBX'  keep all settings as is, make sure  scale is set to 1.00 , pick a file name, I saved mine as SmallTownHome_nopoints.fbx

Save your file.

Back into 'Edit mode',

and now for what I think the fun part is.... making the build models.

Before you start it is a good idea to firstly save this file again but as a different save – call it something like SmallTownHome_build02.blend

Now, in 'Edit mode' start deleting parts and moving sections of the mesh as if you were dismantling the house in reverse to someone building it...

For example I deleted the roof first, then I deleted the door and windows and all the walls. (depending on your design you could incorporate more build models, but in this tutorial I'm trying to keep it pretty simple)

http://i.imgur.com/7mKlCk1.jpg
Creating a 3d model house in blender and making it available in game


From here I save again (as SmallTownHome_build02.blend), then I export this an .fbx like we did earlier.


Now save a new .blend save – build01

Delete more, or move things around like they have just gotten to building site. Build 01 is what you see after the resources have been taken to the houses footprint.

http://i.imgur.com/ReBe218.jpg
Creating a 3d model house in blender and making it available in game


Build 01, saved and exported as an .fbx file also.


Now that all of our models are made, we can reopen up the complete house .blend save.

We now need to add 'points' for the game to interact with the building.

In 'Object mode', press shift + A and 'Add' – 'Empty' – 'Plain Axes'

Using the 'Transform' properties menu window, orientate this so it is at 0,0,0 (26).
Then change the name of this to 'points' (27)

http://i.imgur.com/uERlETw.jpg
Creating a 3d model house in blender and making it available in game


Add in more points in the same manner, this time, keep them all at ground level (z-axis=0), name them:
build_001
build_002
use_001

by clicking on the little icons next to the names of the points, drag them all onto the 'points' to 'Drop to Select Parent'
it should look like this:

http://i.imgur.com/9OLmls9.jpg
Creating a 3d model house in blender and making it available in game


Now add in a new point, this time it will be called 'smoke', move it so that it is sitting within the chimney slightly, set it's parent to 'points'.

Save the file.

Now delete the house mesh object, so you will only have the points.

Export this as an FBX, (SmallTownHome_points.fbx)

http://i.imgur.com/eVIbSni.jpg
Creating a 3d model house in blender and making it available in game



Now you can close blender (don't save when prompted otherwise you will loose you model


… in part 4 we will be creating all the code. We are getting close to finishing :)
« Last Edit: June 26, 2016, 10:35:53 PM by Discrepancy »

Offline Discrepancy

  • Modders
  • Architect
  • *****
  • Posts: 591
Re: Creating a 3d model house in blender and making it available in game
« Reply #4 on: June 26, 2016, 09:26:29 AM »
Part 4


It is a good idea to try to familiarize yourself with the basic ways in which a mod needs to be put together.
Taking a look at the examples in the mod kit and within the resource folder to see how elements of the game works.
Download and install your Banished modKit, (install to main drive and with no '.,-' symbols in the folder paths)

My modkit, and path to this mod is installed on my main hard drive like this:

C:\BanishedKit106\MyMods\SmallTownHome

Within this 'SmallTownHome' folder I will create more folders and copy files from the example mods as well as from the resource folder.

Create folders called: Dialog / Models / Template / Texture / UI all within the 'SmallTownHome' folder

Into the Dialog folder, make a copy of 'SharedElements.rsc' no need to change the name or anything within the file, but it will be required when compiling. (can be found in modkit folder/resource/Dialog)

Out of the Apiary/Models example folder, copy all the .rsc files named with Apiary.... leave the one named honeyMesh, this is not needed. Copy these into your own Modles folder.

Time to start altering these files so they will link to what we're making.

I start by changing the filenames first, substituting 'Apiary' with 'SmallTownHome',
Then open up each file in notepad, and do the same for all the instances that it says 'Apiary'.

Create a folder within this Models folder, and name it 'MaterialInstance'
In it put the .png files we created – the texture rile and the AO image. Don't need the UV image.

Again from the Apiary example folder, copy the .rsc files from this folder that are concerned with the Apiary only, except for the one concerning the ApiaryFootprint, we don't need these.

Back in our own folder, rename the file names and substitute 'Apiary' for 'SmallTownHome', do the same inside all the files, but with the Build01 and Build02AO files, link the images all to the same .png file – 'SmallTownHomeAO.png' This is because we only made the one AO image in this tutorial (if wanted, they can be easily made though by baking a new AO in the 2 build saves and exporting the image like before)

After this your Models folder, and Models/MaterialInstance folder should look like:

http://i.imgur.com/jRVkaMg.jpg
Creating a 3d model house in blender and making it available in game


From the resource/Template folder, copy the 'Woodhouse.rsc' file, put it into your own template folder.

Change the file name to 'SmallTownHome.rsc'

in it scroll down until you find this section:

Code: [Select]
ToolbarDescription toolbar
{
SpriteSheet _spriteSheet = "Dialog/SpriteSheet.rsc";
String _spriteName = "BuildHouse";

StringTable _stringTable = "Dialog/StringTable.rsc:objects";
String _stringName = "WoodHome";
String _stringNameLwr = "WoodHomeLwr";
String _toolTip = "WoodHomeTip";

String _statusStrings
[
"CreateOk",
"CreateBlocked",
]

int _group = 3;
}

This is the section that makes all the connections for the menu button, icons and text regarding the house.
Change it to:
Code: [Select]
ToolbarDescription toolbar
{
SpriteSheet _spriteSheet = "UI/SmallTownHomeSpriteSheet.rsc";
String _spriteName = "BuildSmallTownHome";

StringTable _stringTable = "UI/SmallTownHomeStringTable.rsc";
String _stringName = "SmallTownHome";
String _stringNameLwr = "SmallTownHomeLwr";
String _toolTip = "SmallTownHomeTip";

String _statusStrings
[
"CreateOk",
"CreateBlocked",
]

int _group = 3;
}

Under this code you will find:

Code: [Select]
CreatePlacedDescription createplaced
{
PathBits _placeBits = Normal | Obstacle;

int _width = 4;
int _height = 5;
int _footprintRotation = 0;

PathBits _placeBitArray
[
Normal | Obstacle,
Normal | Obstacle | Fast | Faster,
]
String _placeBitmap =
"0000
0000
0000
0000
1111";

ComponentDescription _allowAndRemove = "Template/Clear.rsc";
}

MapDescription map
{
PathType _pathType = Immovable;
String _pathBitmap =
"####
####
####
###_
....";

bool _addToOverhead = true;
Color _mapColor = 0xFF545454;
}

This is the section that controls how the house sits on the game tiles.
In Blender we have made our house to sit on a footprint of 4x3 + road tiles (4x4)

So we need to change the createplaced to:

Code: [Select]
CreatePlacedDescription createplaced
{
PathBits _placeBits = Normal | Obstacle;

int _width = 4;
int _height = 4;
int _footprintRotation = 0;

PathBits _placeBitArray
[
Normal | Obstacle,
Normal | Obstacle | Fast | Faster,
]
String _placeBitmap =
"0000
0000
0000
1111";

ComponentDescription _allowAndRemove = "Template/Clear.rsc";
}

the placeBitArray, is what the placeBitmap is calling up info from.
The first line ' Normal | Obstacle,' = 0 in the placeBitmap,
so when we have the 0's listed, it is saying it is an Obstacle (building) that can be placed on Normal (level) terrain.
While the 1's mean it can have a road travel on the tiles, though it is still an obstacle so cannot have another building built there.

Now we change the next part the map description.
Our building will look like this:
Code: [Select]
MapDescription map
{
PathType _pathType = Immovable;
String _pathBitmap =
"####
####
##_#
....";

bool _addToOverhead = true;
Color _mapColor = 0xFF545454;
}

The #'s mean that it is a solid building, the _ (underscore) is passage that citizens can take 'inside' a building, and the .'s (dots) are the part that  assigns a road to be built on the front tiles? I think
The other section is what for the display on the overhead game map.

Thanks goes to Kralyerg for giving me insight into how the placeBitArray and placeBits work.


Next we will change the rest of the template file to link up to the model and materials.
A fair bit will need to be deleted from the woodhouse.rsc as it has many F-key variants.
It should look like this:
Code: [Select]
DecalDescription decal
{
MaterialInstance _materials
[
"Terrain/TiledDecals/BuildingFootprint8Material.rsc"
"Terrain/TiledDecals/BuildingFootprint8DamageMaterial.rsc"
]
bool _tiled = false;
float _initialAlpha = 0.5;
float _mapWidth = 2048.0;

DecalLocation _decalLocations
[
{
float _x0 = 0.0;
float _y0 = 0.0;
float _x1 = 256.0;
float _y1 = 320.0;
}
]
}

PickingDescription picking
{
MaterialInstance _selectMaterial = "Material/SelectionMask/SelectionMask.rsc";
PickingGroup _meshes
[
{
PickingMesh _mesh
[
"Models\SmallTownHomeBuild01Picking.rsc",
"Models\SmallTownHomeBuild02Picking.rsc",
"Models\SmallTownHomePicking.rsc"
]
}
]
}

ModelDescription model
{
MeshGroup _meshes
[
{
GraphicsMesh _mesh
[
"Models\SmallTownHomeBuild01Mesh.rsc",
"Models\SmallTownHomeBuild02Mesh.rsc",
"Models\SmallTownHomeMesh.rsc"
]
}
]

int _displayIndex = 0;
int _subIndex = 0;
bool _randomIndex = false;
}

HighlightDescription highlight
{
EdgeGroup _meshes
[
{
EdgeMesh _mesh
[
"Models\SmallTownHomeBuild01Mesh.rsc:edge"
"Models\SmallTownHomeBuild02Mesh.rsc:edge"
"Models\SmallTownHomeMesh.rsc:edge"
]
}
]

// materials for drawing selection with no mesh
MaterialInstance _maskMaterial = "Material/SelectionMask/SelectionMask.rsc";
MaterialInstance _edgeMaterial = "Material/SelectionEdge/SelectionEdge.rsc";
}


InteractDescription interact
{
PointList _pointList = "Models\SmallTownHomePoints.rsc";
}


at the bottom of the file, delete this from the UI section:
Code: [Select]
{
ObjectType _type = UpgradeUI;
ElementDescription _element = "Dialog/Upgrade.rsc:upgradeButton";
String _insertAt = "pageTabGroup";
DialogControllerConfig _config = "upgradeConfig";
}

and then right at the bottom, delete:
Code: [Select]
UpgradeUIConfig upgradeConfig
{
ComponentDescription _upgradeTo = "Template/StoneHouse.rsc";
}

These are the sections that handles the stone house upgrade, not needed for this house.
« Last Edit: June 27, 2016, 01:21:08 AM by Discrepancy »

Offline Discrepancy

  • Modders
  • Architect
  • *****
  • Posts: 591
Re: Creating a 3d model house in blender and making it available in game
« Reply #5 on: June 26, 2016, 09:47:43 AM »
Part 5


From the Apiary example folder, copy the 4 .rsc files in the Texture folder, put them into your own. Done.

Now again from the Apiary example folder, copy the 4 .rsc files in the UI folder, put them into your own and then alter the filenames, again substituting 'Apiary' for 'SmallTownHome'.

SmallTownHomeSpriteSheet.rsc will look like this:
Code: [Select]
SpriteSheet resource
{
String _materialName = "SmallTownHomeSpriteSheetMaterial.rsc";
String _imageName = "Build/SmallTownHomeSpriteSheet.png";
int _imageWidth = 128;
int _imageHeight = 128;
bool _padForFiltering = true;

Sprite _sprites
[
{ String _name = "BuildSmallTownHome"; String _source = "UI/Sprite/BuildSmallTownHome.png"; }
]
}

This is what calls up the individual toolbar icon for the house.

Now in SmallTownHomeSpriteSheetMaterial.rsc and SmallTownHomeSpriteSheetTexture.rsc
Alter the sections where it says 'Apiary', replace with 'SmallTownHome'

The SmallTownHomeStringTable.rsc file controls the text that is written in the game (display names/toolbar tips etc)
I changed mine to be:
Code: [Select]
StringTable resource
{
Entry _strings
[
{ String _name = "SmallTownHome"; String _text = "Small Town Home"; }
{ String _name = "SmallTownHomeLwr"; String _text = "small town home"; }
{ String _name = "SmallTownHomeTip"; String _text = "A small home with same costs and same numbers as the Wood house."; }
]
}

Now we need to create the Toolbar icon, it needs to be a 32x32 png image with a transparent background to match the other icons.
Name it 'BuildSmallTownHome.png'
Once made it needs to go into a folder called 'Sprite' within the UI folder.


Back into the main folder (MyMods/SmallTownHome)
we will need to add in copies from the Apiary example folder:
copy: Apiary.rsc, apiaryResources.rsc and Package.rsc

Rename Apiary.rsc to SmallTownHome.rsc,
This file is the toolbar file- it controls where the houses icon will be.
We want it to sit with the other houses, so I have changed it to:
Code: [Select]
Toolbar SmallTownHome
{
Toolbar _parent = "Game\Toolbar.rsc:housing";
int _sortPriority = 111;

Action _action = Tool;
ComponentDescription _tool = "Template/SmallTownHome.rsc";

bool _autoHotKey = true; 
}

Now change apiaryResources.rsc to SmallTownHomeResources.rsc
this is the mod kit’s 'call up' sheet for when compiling the mod.
Inside it should look like this:
Code: [Select]
ExternalList resource
{
External _resources
[
// toolbar - references building and everything else - nothing else need be listed here
"SmallTownHome.rsc:SmallTownHome"
]
}


Now  edit the Package file, this is what controls the information that is shown in the game mod menu and in the steam workshop.
I made my Package file look like this:
Code: [Select]
PackageFile SmallTownHome
{
String _name = "Small Town Home";
String _author = "Discrepancy";
String _description = "This is small home with the same numbers of the Wooden House.
    This was made for a tutorial, you can find it at www.worldofbanished.com";
String _icon = "icon.png";
String _preview = "preview.jpg";
int _userVersion = 1;

// all files in resource directory
String _includeList
[
"*"
]

// exclude package files, mod files, file used for building packages
String _excludeList
[
"Package_*.crs"
"*.pkg"
"*.pkm"
]
}

Next make the icon.png file it is asking for. This needs to be 48x48. I just resize the toolbar build icon.

Don't worry about the preview.jpg, as we haven’t got an in game shot yet.

Now to make the bat files to compile the mod:
In the main folder (MyMods/SmallTownHome), we will now create 3 text files,
they will be named as:
'1 Build.bat'
'2 Run.bat'
3 Package.bat'

inside '1 Build.bat' put this:
Code: [Select]
..\..\bin\x64\Tools-x64.exe /build SmallTownHomeResources.rsc:resource /pathres ../MyMods/SmallTownHome /pathdat ../MyMods/SmallTownHome/bin
pause

inside '2 Run.bat' put this:
Code: [Select]
..\..\bin\x64\Application-x64-profile.exe /ref SmallTownHomeResources.rsc:resource /pathres ../MyMods/SmallTownHome /pathdat ../MyMods/SmallTownHome/bin
pause

inside '3 Package.bat'' put this:
Code: [Select]
..\..\bin\x64\Tools-x64.exe /mod Package.rsc:SmallTownHome /pathres ../MyMods/SmallTownHome /pathdat ../MyMods/SmallTownHome/bin
pause



… Compiling all the 3d models

Now we must make the single .fbx file that the game will read from.

Open Blender and with a new blank project, press 'File' – 'Import' – 'FBX'
Change the scale to 0.01 (28), and then import the main house model we exported to .fbx (29)

http://i.imgur.com/VgZRcnf.jpg
Creating a 3d model house in blender and making it available in game


The house should have been imported and you will have to zoom in a long way to see it.

Change the name of the model to 'mesh' (30) (*NOTE: pictures are wrongly displaying 'Mesh', this I later changed to 'mesh' – sorry couldn't take new screenshots)

http://i.imgur.com/LVcJm9g.jpg
Creating a 3d model house in blender and making it available in game


Import the point.fbx file, keep it all the same at scale of 0.01, it should fall directly into the model at 0,0,0

Import the build models one at a time in the same way, they should also fall directly into the centre of the house, if not they were not exported properly at 0,0,0.
With the build models, while still in 'Object mode', move them sideways away from he main house model, and rename them 'build01' and 'build02'

http://i.imgur.com/fnPIQar.jpg
Creating a 3d model house in blender and making it available in game


Now select the main mesh, and click on the 'Material' property tab (31), then click 'New' (32)

http://i.imgur.com/JRocYYQ.jpg
Creating a 3d model house in blender and making it available in game


Rename the new material to 'SmallTownHome'

Next to the 'Material' tab, click on the 'Texture' tab (33), click 'New' to add a texture place-holder, rename this also to 'SmallTownHome' (34)

http://i.imgur.com/RaMvRA6.jpg
Creating a 3d model house in blender and making it available in game


Press 'Open' (35), and link to the SmallTownHome.png file in the MaterialInstance folder.

Now click on each of the build models and call up the same texture, only this time you only need to click on the 'Material' tab, and instead of adding a new material, just click on the 'SmallTownHome' material we had just made. Just click on the little globe/circle, and select the material.

Now it is ready to export again, this time as a single .fbx file.

Export to the 'Models' folder we made, named as 'SmallTownHome.fbx'

Now we can build the model!

Double click on the '1 Build.bat' file we created, and if all was followed it should build...
You will be prompted if there is an issue.

My build went fine,

I then double click on the 2 Run.bat file and the game loads up. Start a new game.

The model loads up fine in game, but it is too big !

http://i.imgur.com/rSJOHrn.jpg
Creating a 3d model house in blender and making it available in game







.... In Part 6 we will resize the models and make it fit on a smaller footprint.
« Last Edit: June 27, 2016, 01:21:50 AM by Discrepancy »

Offline Discrepancy

  • Modders
  • Architect
  • *****
  • Posts: 591
Re: Creating a 3d model house in blender and making it available in game
« Reply #6 on: June 27, 2016, 01:22:28 AM »
Part 6


So our house model is way too large inside the game, looking at the picture in game, we could easily take one square off the side, so it will be a smaller house sitting on a smaller footprint of 3x3 instead of 4x4.

Open up Blender and load up the save you have for the completed house (SmallTownHome.blend):

http://i.imgur.com/7hImRD7.jpg
Creating a 3d model house in blender and making it available in game


In 'Object mode',
Select the house, and in the Transform window panel, change the scale to 0.650 for all axis points (36)
Do the same for the points holder (it will resize all points).
We now have a house scaled to 65% of what it was.
It takes up approx. 1.5 squares either side of the Y-axis.

http://i.imgur.com/LP2AxwJ.jpg
Creating a 3d model house in blender and making it available in game


Important, we now need to 'Apply' these changes to the scale.

Like we did earlier in the tutorial, click on 'Object' – 'Apply' – 'Rotation & Scale', repeat with the 'point' holder. (you will see that the 'Transform' scale will have changed to 1.000) (37)

Save file.

http://i.imgur.com/19xt0rK.jpg
Creating a 3d model house in blender and making it available in game


Now like we did earlier, delete the house mesh, and export only the points as an .fbx file (at scale 1.000).

Reload the house save, this time delete all the points (all points can quickly be deleted by 'right-clicking' on the 'points' holder in the Outliner window pane [top right of my blender view], and click on 'Delete Hierarchy').
Now export the house only as an .fbx.

Now load up the build01 & build02.blend saves we made earlier, and make the same changes in scale that we made to the complete house, apply the scale, and save and export as .fbx's.

And again following the same method we did in Part 5, we will start a new empty Blender project and import the .fbx files one at a time at 0.01 scale.

And add the 'Material/Texture' to each of the mesh, build 02 & build 01 like we did earlier. (they all call up the same Material holder)
If you want, you can press on the 'Object mode'  button (38), press 'Texture Paint' and it will show up the house with the texture you just assigned.

http://i.imgur.com/48IyuET.jpg
Creating a 3d model house in blender and making it available in game


Once you've assigned the materials, export all as an .fbx, and replace the SmallTownHome.fbx you created in the Models folder.

Open up the SmallTownHome.rsc file in the Templete folder.

Change the following:
Code: [Select]
CreatePlacedDescription createplaced
{
PathBits _placeBits = Normal | Obstacle;

int _width = 4;
int _height = 4;
int _footprintRotation = 0;

PathBits _placeBitArray
[
Normal | Obstacle,
Normal | Obstacle | Fast | Faster,
]
String _placeBitmap =
"0000
0000
0000
1111";

ComponentDescription _allowAndRemove = "Template/Clear.rsc";
}

MapDescription map
{
PathType _pathType = Immovable;
String _pathBitmap =
"####
####
##_#
....";

bool _addToOverhead = true;
Color _mapColor = 0xFF545454;
}

to:
Code: [Select]
CreatePlacedDescription createplaced
{
PathBits _placeBits = Normal | Obstacle;

int _width = 3;
int _height = 3;
int _footprintRotation = 0;

PathBits _placeBitArray
[
Normal | Obstacle,
Normal | Obstacle | Fast | Faster,
]
String _placeBitmap =
"000
000
111";

ComponentDescription _allowAndRemove = "Template/Clear.rsc";
}

MapDescription map
{
PathType _pathType = Immovable;
String _pathBitmap =
"###
#_#
...";

bool _addToOverhead = true;
Color _mapColor = 0xFF545454;
}

We have now changed the house to sit on a 3x3 footprint including the road.

Now recompile the mod (delete the 'bin' and 'Build' folders first) by clicking on the '1 Build.bat' file. Run the mod by clicking '2 Run.bat'.


More issues:

The size is better in game, but a problem! although hard to see... our roof is on fire! Smoke is billowing out from the centre of the roof! (I recall this coming up before: http://worldofbanished.com/index.php?topic=1112.0 but how it was solved?...)

http://i.imgur.com/1t7wWWh.jpg
Creating a 3d model house in blender and making it available in game


I guess we will find out in Part 7! … I was hoping to have this finished by now. But problem solving is the best way to learn.
« Last Edit: June 27, 2016, 04:02:17 AM by Discrepancy »

Offline Discrepancy

  • Modders
  • Architect
  • *****
  • Posts: 591
Re: Creating a 3d model house in blender and making it available in game
« Reply #7 on: June 27, 2016, 04:03:29 AM »
Part 7

So thankfully this issue isn't anything major, and it wasn't really our fault considering it isn't in the wooden house file...


Within the SmallTownHome.rsc file in the Template folder is this code:

Code: [Select]
InteractDescription interact
{
PointList _pointList = "Models\SmallTownHomePoints.rsc";
}

ParticleDescription particle
{
ParticleAttachment _systems
[
{
Time _fadeInOutTime = 2.0;
bool _addOnCreate = false;
bool _addOnNotify = false;
Particle _particle = "ParticleSystems\Fire\FireSmall.rsc";
}
{
bool _addOnCreate = false;
Particle _particle = "ParticleSystems\ChimneySmoke\ChimneySmoke.rsc";
String _attachNode = "smoke";
}
]
}

Thanks to @kid1293 , we now know that the particle system needs to call up the points.rsc file directly from its code in the template file.
Change the section above to:

Code: [Select]
InteractDescription interact
{
PointList _pointList = "Models\SmallTownHomePoints.rsc";
}

ParticleDescription particle
{
PointList _pointList = "Models\SmallTownHomePoints.rsc";

ParticleAttachment _systems
[
{
Time _fadeInOutTime = 2.0;
bool _addOnCreate = false;
bool _addOnNotify = false;
Particle _particle = "ParticleSystems\Fire\FireSmall.rsc";
}
{
bool _addOnCreate = false;
Particle _particle = "ParticleSystems\ChimneySmoke\ChimneySmoke.rsc";
String _attachNode = "smoke";
}
]
}

just that added 'PointList _pointList = "Models\SmallTownHomePoints.rsc";' line will make the chimney point act as it should.

:) It is now complete.

Almost.

To properly add a mod to the steam workshop you need a preview picture...
using this...
http://i.imgur.com/84LLOw7.jpg
Creating a 3d model house in blender and making it available in game


I edit and crop it so that it is a 360x360px image, save it as 'preview.jpg'

Now rebuild the mod with these added changes, and lastly package the mod.

The SmallTownHome.pkm file is found in my C:\BanishedKit106\bin\WinData/ folder

Test the mod in the normal Banished environment.

All done.



Thanks for reading, any questions? happy to help.



http://i.imgur.com/zv8wIlw.jpg
Creating a 3d model house in blender and making it available in game




If you want to use this house in your game,
Download the SmallTownHome.pkm file here

See how it is made? Download the source code here: (all code, textures and .fbx models)
SmallTownHome_SourceCode

here you can download the original Blender files, .psd texture file etc, etc SmallTownHome_SourceWorkFiles.zip
« Last Edit: June 27, 2016, 08:45:41 AM by Discrepancy »

Offline Discrepancy

  • Modders
  • Architect
  • *****
  • Posts: 591
Re: Creating a 3d model house in blender and making it available in game
« Reply #8 on: June 27, 2016, 04:44:48 AM »
... I'm sorry that I have titled this as a tutorial when I myself am having problems...

but I still hope, going through all of this might allow others to venture into the 3d modelling and Banished modding world.

Keep checking back above, as we will solve the issue.

I will also upload all the source files once it is operating as required.

Offline Discrepancy

  • Modders
  • Architect
  • *****
  • Posts: 591
Re: Creating a 3d model house in blender and making it available in game
« Reply #9 on: June 27, 2016, 07:41:26 AM »
This tutorial is now complete.

I hope that some of you will find it helpful.

:) happy modding.

Offline RedKetchup

  • Champion
  • Banished Expert
  • *****
  • Posts: 6985
Re: Creating a 3d model house in blender and making it available in game
« Reply #10 on: June 27, 2016, 10:12:48 AM »
THANKS YOU ALOT @Discrepancy  for this nice tuto :)
sure it will help some people :)
> > > Support Mods Creation developments with Paypal Donations < < <
Click here to PayPal Donate.

Offline Ogedei

  • Laborer
  • **
  • Posts: 19
Re: Creating a 3d model house in blender and making it available in game
« Reply #11 on: July 03, 2016, 06:26:57 PM »
Great tutorial. This is actually a lot better than most Blender tutorials out there - the others tend to be so needlessly complicated. :)

Offline mellowtraumatic

  • Vendor
  • ***
  • Posts: 60
Re: Creating a 3d model house in blender and making it available in game
« Reply #12 on: August 07, 2016, 06:42:40 AM »
Thank you for this! It makes me want to break out Blender again. I tried it once and got hopelessly frustrated with it.