Author Topic: Extension Tutorial - Making Scenes and Scene props (using wings3d)  (Read 7570 times)

Yoshiboy

  • Guest
This tutorial is going to take you through the surprisingly simple process of creating new scenes and scene props for M&B.

If you haven't followed my other tutorial in adding a new weapon to mount and blade you will want to look at that one first. Or you're not going to understand much of this one. The link is in my sig.

Essentially scenes and scene props are exactly the same as a normal standard mesh but with one extra element - the "collision mesh" or "collision manifold"

Chapter 1 - Collision Meshes

What this does, and why we need it is that it tells the computer which parts of a mesh the player, and other troops can walk over or are blocked out by. It tells the computer where the walls are and where you cant quite get past. You might hear all kind of things about "hitboxes" and these are more or less the equivalent for troops/horses. When something clips, or passes into them, the computer tells the game how to react. "But why use collision meshes, why not use the visual mesh" i hear you ask. Well collision meshes are purely for optimization. The computer works by checking, probably around 5 times every second, to see if something has passed through any of the faces that are defined as collision meshes. Now, lets say there are 30 people in a battle, and for some reason we are using the visual mesh as the collision mesh for all the troops. The visual mesh for troops is around 2000 pollies, so thats 300,000 checks per second. The computer would probably explode if it had to do something like that.

In reality the collision meshes for players are probably boxes, to reduce checks to a complete minimum, as it slows the computer down so much.

So, take this into mind when making collision meshes for your rooms and scene props.

Unfortunately there is one more little gimic to the collision meshes in M&B that makes them really a pain to work with. The collision meshes in M&B are also what is used for casting shadows over when you move near them, although this may sound alright, what it means is that you have to get the collision fitting pretty closely to the mesh unless you want to get some really nasty effects like pictured below.



so, now thats all out the way lets see how we actually make our collision mesh, because the process needs to be slightly different to how we would make standard meshes and import them. Remember when making a collision mesh that you can chop off the parts of the model that you dont need, but also remember to try and make it fit the visual mesh closely for shadows. Its all a balance between these two.

Thanks to Thorgrim, who is amazing. Creating collision meshes is now oh so easy.

You will need the newest version (and i stress this, make sure you have the newest version) of BRF edit. It can be found here.

Simply export the file you want to act as a collision mesh as .obj file and make sure you name it with bo_ ( for example "bo_my_new_collision.obj" ) first to make sure you don't forget its a collision mesh. Open up Thorgrim's BRFedit and look at the top for the tab marked "col". This is your collision mesh tab. Click on it and press import. Browse to the folder with your collision mesh ( in .obj format) in and press the "open" button or double click on it.

This will of course import the collision manifold into your new .BRF . Save this brf in your mod resource folder as "collision_meshes" or something similar and add the relevant line to "module_info" e.g
Code: [Select]
load_module_resource = collision_meshes
    import all of your other collision meshes into this same BRF file using the same method, and thats it. Your done with making collision meshes. To learn how to referance to collision meshes in the Python scripts scroll down to the chapter: "setting up in python"

A few final notes about what can and cannot be done with collision meshes:

  • First of all you CANT have one face directly on top of another. This includes two sided polygons and where one face is pressed up to another yet not attached..
  • Collision meshes DO have to be triangulated, otherwise you will get an error and it will not work.
  • Collision meshes DO NOT NEED any UV coordinates or anything like that, although they will work fine if you export them with UV coordinates..
  • Collision meshes DO NOT NEED to be closed geometry, you can have them as open as you like....saying this, exporting with open geometry in some apps can cause problems.

(closed/open geometry simply means if you have "deleted" polygons or not. It isnt really supported in wings3d, the equivalent is to set faces to the "_hole_" material.)

[/list]

for more information on collision meshes (and where i got most of my information from) check out fisheye's post here.

Chapter 2 - Multi-Mesh

Multi-mesh is essentially the process used when you want to import a mesh that uses more than one material. This is commonly used in larger meshes and scenes because it is essential when you are tiling textures.

but what is tiling textures?

Tiling textures is pretty simple, M&B uses it alot. What it is is that you make the UV pieces much bigger than the UV area show, this will make the texture tile over the mesh.



In this example, look how much bigger the UV pieces are than the standard texture size displayed, this has given me a great tiled effect that has stopped the texture from being really low resolution on the model.

So thats tiling textures. Using tiling textures make it so that you have to use different materials, assigned to different faces on a model.

If you need help with UV mapping or using the outliner and materials check out my tutorial on UV mapping in wings 3d here

look at this example image:

http://www.theorangeduck.co.uk/modding_stuff/tut_pics/colmesh/collisiontut3.jpg

There, on the outliner is a list of materials and each one has the correct texture applied to it. Originally I selected the faces i wanted to be of each material, UV mapped them and assigned them the right material. We can more or less see instantly the effect in wings3d. This is exactly what we want.

Now again, thanks to the brilliant Thorgrim, using multi-mesh has become all so easy. Simply select the object with more than one material on it and export as an .obj file just like you would normally. When you import into BRFedit it will break down the mesh automatically for you into separate pieces depending on the materials assigned.

It will have named them in the typical multi-mesh naming standard to show that they are in fact all part of one mesh and should be displayed together.

Code: [Select]
tannerymesh.1
tannerymesh.2
tannerymesh.3
tannerymesh.4

(note, the first mesh may not have the naming .1 on it. It is usually better to change it to this to avoid confusion)

Then all you need to do is select the relevant one, and set its material to whatever it is that fits that part and your done. Thats it. Save the BRF!

In BRFedit, it will automatically display multi-meshes as one whole mesh in the viewpoint window, but if you are finding this confusing you can turn it off simply by pressing the little "Multi Mesh" button in the bottom corner. Now we just have to see how to reference to these meshes in the python scripts.

Chapter 3 - Setting up in python

For this chapter you will need to be using the official python scripts to make your mod. All the information you can find about them should be here:

http://forums.taleworlds.net/index.php/board,12.0.html

So, once you have all the scripts set up and working the process becomes relatively easy.

Making a scene

open up module_scenes.py

this lists all of the scenes that you have in tha game. Browse down right to the bottom and copy the entry for the last scene, making sure that you keep above the final "]" of the file

Code: [Select]
  ("castle_2_interior",sf_indoors, "thirsty_lion", "bo_thirsty_lion", (-100,-100),(100,100),-100,"0",
    ["exit"],[]),

Now, the first string "castle_2_interior" is the name of the scene, so you want to change this to "my_new_scene" or whatever you want to call it. The next is a tag that shows the scene is inside. obviously keep this on if your scene is inside. Then we have the two things we want. First of all is the visual mesh name. We simply put in here the name of the visual mesh we want our scene to be made up of. If you are using multi-mesh you use the name of the mesh without any ending. In my example above i had the names:
Code: [Select]
tannerymesh.1
tannerymesh.2
tannerymesh.3
tannerymesh.4

which means that in this part i simply put "tannerymesh"

In the next box is of course the collision mesh. So i put the name of that in there. The next set of 4 values are to do with the positioning of the collision mesh and visual mesh. Change these to the following:  (-200,-200),(200,200) . I don't know why you have to do this, it seems you just do for it to work....otherwise the collision is placed off the visual mesh.

the last two values at the top are to do with water level and terrain code, we don't have to mess with these.

After that we have the list of preset passages in the scene. Best to leave this as it is, and then we have a list of all the chests in the scene. If you want to add a chest to the scene check out how the Zendar chest is made using the Zendar chest troop.

So there we have it, your new scene :)

Making a scene prop

This again is extremely simple.
 
Open up "module_scene_props.py"

and scroll down to the bottom. Copy and paste the last active entry, being
Code: [Select]
  ("hook_a",0,"hook_a","0", []), and put it at the bottom, making sure your above the final "]"

The first value is the name of the scene prop, change this to whatever you want. Secondly is a 0...leave this as it is. Then we have the two we want. Mesh name, followed by collision mesh name (in the example above there is no collision mesh so it is set to "0", simply change the 0 to the collision mesh name, leaving the "" marks)

If you are using multi-mesh you use the name of the visual mesh without any ending. In my example above i had the names:
Code: [Select]
tannerymesh.1
tannerymesh.2
tannerymesh.3
tannerymesh.4

which means that in this part for visual mesh i simply put "tannerymesh"

and there you have it, your new scene prop, go into edit mode and have fun placing it.

Chapter 4 - Using Water

Now that you've looked at all that, here i can teach you how to use water in your scene. When you use water in your scene you should be away that there are two parts to making water. First you have to tell M&B at which level you want to slow the players movement and create the extra splash effects. Then, you need to visually create water yourself for the scene.

The best way to do this is simply, when making your scene create a 2D plain (2 sided flat face) to represent your water and make sure this is in line with the center of the scene.



In my example picture here you can see i have lined up the water in my cave with the grid in the center of the scene as closely as possible. This is to make sure that we know where the water is when we tell M&B at what level for it to create the water effects and slow down the player.

Now that we have that done and exported fine into our scene we want to take a look at the scene entry we created in the python scripts for our scene:

Code: [Select]
  ("my_new_scene",sf_indoors, "my_new_scene_mesh", "bo_my_new_scene_mesh", (-200,-200),(200,200),-100,"0",
    ["exit"],[]),

here is an example of a scene entry. Like i said above, we have the name, the scene tags, the mesh and collision mesh name, the collision mesh and visual mesh offset, the water level and the terrain code. Currently the water level in this scene is set to -100. This means, that currently the M&B water is 100 meters below the center plain of the scene. When we made out new mesh, we made sure that the water was lined up correctly with the center of the scene, so to get water to work simply what we need to do is change the "-100" to a "0". That will put the coded water level to match the visual mesh we created.

Now, before you run off to place water on all of your scenes there are a few things you should know. If you use M&B's native material "river" (which is the one used for all of the rivers in random terrains) it will not appear semi-transparent like it does in the battle terrains. This may lead you to wanting to create your own material and texture that is semi-transparent. In M&B there is no easy way to do this :( . In basic you have to copy the material "particle_blend" and re-name it  and point it to your new texture. It can be a complicated process, if you are having trouble there is more information on that in this thread.

Anyway, i think that about covers it for water. Post if you are having trouble.

Finishing notes

First of all a Massive thank to fisheye who was the first to start playing with collision meshes and dug up all the info. Not only that but he made the collision mesh converter so we seriously owe him.

If there are any problems, mistakes or info i have missed please PM me or post in this thread. Do the same if you are having trouble with the tut.

Thanks

Yoshiboy
« Last Edit: September 23, 2007, 03:15:23 am by Yoshiboy »