[TUTORIAL] Using Blender to create building art: From scratch to ingame buildings

merijn_v1

Black Belt
Joined
Dec 29, 2008
Messages
5,939
Location
The city of the original vlaai
Some introduction text that I still have to write.

Requirements
- Blender (make sure you download 2.79. The niftools plugin doesn't work on newer versions)
- niftools blender plugin
- Nifskope
- GIMP with DDS plugin (Or any other image editor which can edit dds files)

0. Installation
- Blender: Follow the Installation instructions
- Niftools blender plugin: You have 2 options, use the auto unpack in Blender tool or unpack manually. (I recommend doing it manually. For me, the auto unpack tool unpacked the file in the roaming appdata instead of in the program files)

Auto unpack
  • In blender, go to file -> user preferences (ctrl-alt-U)
  • Go to add-ons and click the "Install Add-ons from file" button (bottom of the screen)
  • Navigate to the zip package and select it (usually in you downloads section)
  • After installation, don't forget to make sure the checkbox is checked. Save the user preferences.
Manual installation
  • Unzip the package in BLENDER_INSTALLATION_LOCATION/Blender/2.79b/Scripts/AddOns (you might need administrator rights for this) My location is: C:\Program Files\Blender Foundation\Blender\2.79\scripts\addons
  • In Blender, go to file -> user preferences (ctrl-alt-U)
  • Goto Add-Ons and find "Import-Export NetImmerse/Gamebryo nif format" and select the checkbox
  • Save user preferences
Required fix
If you don't do this, you get an error when you want to export.
  • Goto the location you installed the nif export tool files.
  • Goto FILES_LOCATION\Addons\io_scene_nif\\modules\property\texture\
  • Open "texture_export.py" (use a text editor. I use Notepad++ for editing python files.)
  • Add the return statement like this (line 225-230)
  • Code:
        def add_shader_integer_extra_datas(self, trishape):
            """Add extra data blocks for shader indices."""
            return
            for shaderindex in self.USED_EXTRA_SHADER_TEXTURES[NifOp.props.game]:
                shadername = self.EXTRA_SHADER_TEXTURES[shaderindex]
                trishape.add_integer_extra_data(shadername, shaderindex)
Optional (but very convenient)
Set the default game to Civ IV.
  • Goto the location you installed the nif export tool files.
  • Goto FILES_LOCATION\Addons\io_scene_nif\operators and open "nif_export_op.py".
  • Search for the code below (lines 71-82)
  • Code:
        #: For which game to export.
        game = bpy.props.EnumProperty(
            items=[
                (_game_to_enum(game), game, "Export for " + game)
                # implementation note: reversed makes it show alphabetically
                # (at least with the current blender)
                for game in reversed(sorted(
                    [x for x in NifFormat.games.keys() if x != '?']))
                ],
            name="Game",
            description="For which game to export.",
            default='CIVILIZATION_IV')

  • Change
    Code:
    default='OBLIVION')
    to
    Code:
    default='CIVILIZATION_IV')
    and save the file.
- Nifskope: Unzip the package at a location you want.
- GIMP: Follow the installation instructions.

If you have everything set up, we can start working on the art itself.

1. Create mesh
The first thing we will create is a mesh. The mesh is the shape of the building. The best way of learning is to experiment yourself. There are several blender tutorials that explain what the basic functions of blender are. I used this youtube video to get some understanding of the basics in creating a mesh. You can also use my tutorial example to get some basic understanding of the functions of Blender and what comments you should use.

Tutorial example
When you start up Blender, you get a default preplaced object (a cube). Your can remove it by pressing the "delete" key. But we will use it as a part of our new building, so we don't do that.

You can rotate the camera by holding the middle-mouse button and move the mouse. If you want to move the camera, press the shift-key and hold the middle-mouse button while moving your mouse.

Using only the default cube isn't very interesting. So we will create some more elements. First, go to the "edit menu". Make sure you are always in this "edit menu" when you create new objects. You can add new objects in the "objects menu", but if you do that, you will get errors when you export to the nif format.
Spoiler :


First, deselect the cube by pressing the A key. (The A key deselects all if you have something selected. If you have nothing selected, it will select everything. A selected object will turn orange.)

Let's add a simple cylinder. Click the create -> cylinder button. (Red circle in image below) This will create a cylinder at the cursor point. The cursor point is the circle thingy in the blue circle of the image. You can place the cursor point anywhere by left clicking in the main screen. If you want to reset the cursor point to the origin, press shift+s and select "cursor to center".

Spoiler :


If you have created a circle, you see a small menu in the bottom left of the screen. You can set certain parameters of the cylinder, such as the radius and the depth. The value "vertices" determines how many points the circle has. You can try some a values and see what happens.

If you set "vertices" to 3, you get a prism. If you set it to 4, you get a cube. The higher the value, the "rounder" the circle becomes. I recommend to use a value that is not too high as that will create more faces. Let's set it to 16 for now.

Spoiler :


Let's move the cylinder. There are several methods of moving the cylinder. The first one is by dragging the red, green and blue arrows that appear at the center of the cylinder.

You can also move the cylinder by pressing the G key. After pressing the "G" key, you can move it around with the mouse. If you want to move it only in X, Y or Z direction, press the X, Y or Z key after pressing the G key.

If you want to move the cylinder over a defined distance, you can use the numpad to define the distance. For example, if you press G, X and type 2, the cylinder will move 2 units in the positive X direction.

A third method is by moving the object to a defined location directly. Press N to get the properties menu. You can set the X, Y and Z coordinates at the top of that menu.

For the tutorial, move the cylinder to a place where you want. It doesn't matter if it is connected to the cube or not. I recommend playing a little with it to get an understanding what happens.



You can rescale the cylinder by pressing the S key. Similar to moving around, you can use your mouse to scale the cylinder or use the numpad to define the scale. If you use the numpad, a value of 2 doubles the size and a value of 0.5 halves the size. By pressing the X, Y or Z key you can rescale only 1 axis.

For the tutorial, you can rescale if you want. Play with it a little to see what happens.


One important thing is that nif files can only deal with faces that have 3 or 4 vertices. The top and bottom of the cylinder have 16 vertices. So we have to make sure this face is split into several smaller faces, all with 3 or for edges. The easiest way is by creating a point in the center and connect all vertices with that one.

First, select the wireframe display.
Spoiler :


Now you see the wireframe of the objects. We need to select all vertices of the top of the cylinder. Press B to enable a selection box. Drag the box around all vertices to select all vertices of the top of the cylinder. If all vertices are selected, press the E key to extrude and press the Enter key immediately afterwards. (If you move your mouse you move the extruded vertices, which is undesired)

Now we need to merge the extruded vertices. Click the merge button in the tools menu and select "at center". Deselect all (A key) and repeat the proces for the bottom.

Spoiler :


Let's add a final element, a simple plane. First, deselect the cylinder by pressing A. You can add a plane similarly like you added the cylinder, but then with the Plane button ofcourse.

You can resize and move the plane similarly like you did with the cylinder. By default, the plane is horizontal. You can rotate the plane by pressing R and move the mouse around. You can use the X, Y or Z key to rotate around a specific axis. Instead of using the mouse, you can use the numpad to determine the angle. The angle is in degrees.

For the tutorial, let's turn the plane 90 degrees around the y-axis. Press R, Y and type 90. Move and rescale the plane as you like.

The final result should be something like this.

Spoiler :


This is the shape of our new "building". This tutorial explains only some basic functions. I recommend watching this video for some other simple technics and how Blender works in general.

2. Create texture
The texture is an image file with the texture of the building. It defines which colors the objects has. The format for the texture files Civ IV uses is the dds format. There are several programs which can edit dds file. I use the free program GIMP with a dds plugin.

The texture files of buildings usually have 256x256 pixels. Some have 512x256. It is possible to use larger files, but that is not recommended. Smaller files like 128x128 or 64x64 are also possible, but will result in a less detailed texture.

In general not all parts of the texture file will be used. Only certain parts of the texture files will be used. In general, the texture file has a black background to indicate all unused parts of the texture file.

Tutorial Example
Let's say that we want the cube to have 2 blue sides, 2 yellow sides and 2 red sides. The cylinder will have a green top and bottom and red wall. The plane will get some transparent parts and some colored parts, so it will look like a fence.

In GIMP, create a new image. Give it a size of 256x256 pixels. Create some areas with the colors, like in the image below. (Use the pencil to (N key)) Add an alpha channel to enable transparency. (Layer->Transparency->Add alpha channel) You can turn some black into transparent area by using the eraser tool or by selecting a rectangle and delete that area.

I created the image below. As you can see, the sizes of colored squares are not equal. I will use this to show that the UV mapping (see next section) can distort the image. The grey chess-pattern is the alpha channel. I painted a small purple fence on it.

Export your image as dds file. (file-> export or ctrl+E) I usually use the "BC2/DXT3" compression. Set the mipmaps option to "Generate Mipmaps".

Spoiler :


3. Apply UV mapping
UV mapping is telling the object to uses which part of the texture file for what parts of the object.

Tutorial example
First, we create a new window. This can be done by clicking the lines in the top-right of the main window (red circle) and drag it to the left. Then set the window to UV/Image editor (blue circle)

Open your newly created texture file. (green circle) This will help you determining where you should place the UV maps.

Spoiler :


Open the texture menu (red arrow). Select movie or image as texture option (blue arrow). Select the newly created texture file (yellow arrow). Set coordinates to "UV" and map to "UVMap" (green arrow).

This makes sure that the nif files uses the correct texture file.

Spoiler :


Now we can place the UV map. First, the the display to "face select" (red circle, blue arrow image below) You can select a face by right clicking on one of the points in the middle of the face. Unwrap is by pressing the U key and select "unwrap". You will see the a transparent overlay appearing in the right window. The face will get the texture of the transparent area. We want to make this face blue, so we have to edit the transparent area so it covers only the blue part.

Hover your mouse over the transparent area on the right window and press the L key. This way, you select the area. You can resize the area by pressing the S key and moving your mouse. Also here you can use the X and Y keys and numpad. You can move the area by pressing the G key and moving your mouse. Again, the X and Y key and numpad can be used. The value of the numpad moves the transparent area determines the amount of pixels the transparent area moves.

Alternatively, you can move the vertices of the area. Right-click on the points of the edges of the transparent area to select it. Hold the right mouse button and move your mouse to move the vertices to the desired place. (you can release the right-mouse button when the vertice moves) Left click to select the location of the vertice.

Edit the area so it covers the blue part, like in the image below. In this example, it doesn't matter if the outlines of the transparent area exactly matches the image, because it is a plain area. But if you have a more detailed texture this could matter.

Spoiler :


Repeat the proces until all UV maps have been layed down. You can speed up the proces by selecting multiple faces at the same time. Hold shift and right-click. You can also press the B key and select multiple faces in within the box. It is possible that you have to reload the image underlay. This is the green circle of the first image of this section.

Tutorial continues in next post.
 

Attachments

  • Edit_Mode.png
    Edit_Mode.png
    284.6 KB · Views: 1,384
  • Add_Cylinder.png
    Add_Cylinder.png
    259.1 KB · Views: 1,275
  • Edit_Cylinder.png
    Edit_Cylinder.png
    264 KB · Views: 1,348
  • GIMP.png
    GIMP.png
    132.8 KB · Views: 1,449
  • Wireframe.png
    Wireframe.png
    257.6 KB · Views: 1,422
  • Merge.png
    Merge.png
    291.6 KB · Views: 1,339
  • Mesh.png
    Mesh.png
    269.1 KB · Views: 1,311
  • UVmap.png
    UVmap.png
    291.7 KB · Views: 1,396
  • UV_Mapping.png
    UV_Mapping.png
    261.7 KB · Views: 1,291
  • Blue.png
    Blue.png
    278.3 KB · Views: 1,280
Last edited:
The image below shows my UV map.

Spoiler :


We are using a transparent alpha channel, so we have to tell Blender we are using one. Goto the material menu (red arrow) an enable the transparency checkbox (yellow arrow). If you create a model without transparency, skip this step.

Spoiler :


If you are have a plane that can be viewed from both sides, you should make sure that the texture is applied to both sides of the plane. Goto the object data menu (yellow arrow of image below) and enable the "both sides" checkbox. (red arrow)

Spoiler :


Now were are ready to export the model to a nif file. First, save your project. (If you haven't done this before.) Go to the Object menu. Select all objects in the left window by clicking on the window and press the A key. (Press the A key again if it deselects your current selection) Now goto to file->export->netImmerse/Gamebrio (.nif)

Spoiler :


In the bottom left, you see a menu in the bottom left. Make sure the option "Game" is set to "Civilization IV" to export to the correct version of nif. (If you have done the optional setting during the installation the game setting is automatically set to "Civilization IV".) Give your model a nice name and hit the export button.

4. View your model in Nifskope
Now you can view your model in nifskope. Make sure that the texture file (dds) and the nif file are in the same folder. Now, open your nif file.

If you have the transparency option enabled, you will see nothing. Don't worry, your model is there. It is only completely transparent. You can check that by clicking on NiTriShapeData. You will see a green wireframe in the display window.

Spoiler :


To remove the transparency, click NiMaterialProperty. In the bottom left, you can see a small menu. Set the value of "alpha" from 0 to 1 and your model appears.

As you can see, the black swirl of the yellow side of the cube is stretched out compared to the texture file. The plane with the purple fence is transparent on all parts it is not purple.

Spoiler :


Optional (But useful)
Go to the NiTriShapeData. In the bottom left menu, you see the option "Vector Flags". You see that this option has 2 value: UV_1 and Has_Triangles. Double click on the them and deselect Has_Triangles. Then save the file. Doing this reduces the size of the nif file by 30-45%. (On average)

Go to NiMaterialProperty. There is an option "Diffuse Color". Set all values to 1 to get the ingame colors mathing with the colors in the DDS file.

5. Using the model in Civilization IV
Now copy both your nif file and the texture file to civ. Building art is usually located in the Assets/Art/Structures/Buildings (or Wonders) folder of a mod. I recommend creating a new folder in the buildings or wonders folder and pasting your nif and dds file in that folder.

There is only 1 step left: XML. Goto Assets/XML/Art and open "Civ4ArtDefines_Buildings.xml". Create a new entry. (The easiest way is to copy an existing entry and modify that.) Below you see an example.

Code:
        <BuildingArtInfo>
            <Type>ART_DEF_BUILDING_TUTORIAL_BUILDING</Type>
            <LSystem>LSYSTEM_2x3</LSystem>
            <bAnimated>0</bAnimated>
            <fScale>2.25</fScale>
            <fInterfaceScale>4</fInterfaceScale>
            <NIF>Art/Structures/Buildings/Tutorial/Tutorial.nif</NIF>
            <KFM/>
            <Button>Art/Structures/Buildings/Tutorial/Tutorial_btn.dds</Button>
        </BuildingArtInfo>

  • <Type> This is the tag that you should use in BuildingInfos.xml
  • <Lsystem> This is for the game to determine where in the city it will place the building. As a rule of thumb, you can say that the smaller the values at the end, the closer it is to the center of the city.
  • <bAnimated> Ingore this.
  • <fScale> This determines the size of the model ingame. By trial and error you determine the desired size.
  • <fInterfaceScale> This determines the size of the model in the pedia. Hint: The size of the model in the pedia uses both <fScale> and <fInterfaceScale>. I recommend to determine the final <fScale> first before you adjust the <fInterfaceScale>.
  • <NIF> The path to your nif file.
  • <KFM> Not used.
  • <Button> The path to the button. Hint: Do NOT start the path of the button with a comma. (Unless you are using a button atlas) It will cause the game to crash if you try to build your new building.
With the XML done, you can enjoy your new building.
Spoiler :
 

Attachments

  • UVmap_Done.png
    UVmap_Done.png
    279.4 KB · Views: 1,216
  • Transparency.png
    Transparency.png
    266.5 KB · Views: 1,224
  • ExportNif.png
    ExportNif.png
    322.2 KB · Views: 1,171
  • ModelExists.png
    ModelExists.png
    147.8 KB · Views: 1,278
  • Nif.png
    Nif.png
    144.3 KB · Views: 1,285
  • BothSides.png
    BothSides.png
    236.1 KB · Views: 1,282
  • Civ4ScreenShot0146.JPG
    Civ4ScreenShot0146.JPG
    286.3 KB · Views: 1,309
Last edited:
Thanks, Merjin! I will be using some of these skills to make buildings later on for my Middle-earth mod. :)
 
Sorry, I don’t understand how to fix export error. I wrote the word return as in the instructions, but the export does not work. I will be grateful if someone will explain to me how to do this!
 
It is basic python code. I can't put it more simply than just adding a return statement so the function does not execute. Make sure the indentation is correct.

Do you get an error message? If yes, what is the error message?
 
I try to export and this error appears:
(1 image)
I found the lines in this form:
(2 image)
And I wrote like this:
(3 image)
 

Attachments

  • 2.png
    298.8 KB · Views: 343
  • 3.png
    300.6 KB · Views: 337
  • 1.png
    5.9 MB · Views: 388
This tutorial is for creating buildings. You are create LH art. Maybe that the function you disabled is required for LH, but not for buildings. You could try enabling it again by removing the return statement. I have never created/edited LH art myself, so if this doesn't work, I have no clue what you can do else if this doesn't work.
 
Hi do you think the importing of nif files is the same for unit art?

Is it possible to upload your blender with nif files all set up to either download or purchase?

So I can save the hassle of doing this myself?
 
Hi do you think the importing of nif files is the same for unit art?

If you have the nif plugin for blender, you can import any nif file.

Is it possible to upload your blender with nif files all set up to either download or purchase?

So I can save the hassle of doing this myself?

No. It is way easier to just download blender yourself and install the nif plugin.
 
If you have the nif plugin for blender, you can import any nif file.
if I get stuck if that's ok?


No. It is way easier to just download blender yourself and install the nif plugin.

Aah ok thanks any help is most appreciated.

I may call on your help later if I get stuck if that's ok?
 
I am trying to locate the Texturesys folder inside the io_scene_nif.....it's not there but the operator subfolder is here, can somebody help?
 
I see that the nif plugin has now a slightly different file structure. I haven't noticed this before. Thanks for notifying me. I tried to update the guide to reflect the latest plugin, but it might still be wrong in some places. Please inform me if that is the case so I can update it.

The file that used to be in the Texturesys folder should now be in the io_scene_nif\\modules\property\texture\ folder.
 
I see that the nif plugin has now a slightly different file structure. I haven't noticed this before. Thanks for notifying me. I tried to update the guide to reflect the latest plugin, but it might still be wrong in some places. Please inform me if that is the case so I can update it.

The file that used to be in the Texturesys folder should now be in the io_scene_nif\\modules\property\texture\ folder.

The file that used to be in the Texturesys folder should now be in the io_scene_nif\\modules\property\texture\ folder.[/QUOTE]

Thank you!
For the time being I have decided to use an older version of Blender, 2.49b; everything is working fine with the old version of the gamebryo scripts...I'll see how it goes
 
The problem is same for 2.79. In fact, there are some pre-release versions targeted for 2.8+ versions.
 
FILES_LOCATION\Addons\io_scene_nif\\modules\property\texture\ does not exist, so I cannot do the req fix.
 
Top Bottom