Extension Tutorial - Making Scenes and Scene props (using wings3d)

Yoshiboy

Count
M&BWB
Best answers
0
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:
load_module_resource = collision_meshes


  • import all of your other collision meshes into this same BRF file using the same method, and that's it. Your done with making collision meshes. To learn how to reference to collision meshes in the Python scripts scroll down to the chapter: "setting up in python"

    In general when making packs of scene props it can be good practice to include the collision meshes for these props into the BRF with all the visual meshes. This makes distribution and sharing between mods easier.

    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.)


    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 that's tiling textures. Using tiling textures makes 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:
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.com/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:
  ("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:
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. It is some kind of weird offset.

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. (This is not in newest versions of M&B but may still be in the code.)

So there we have it, your new scene :smile:

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:
  ("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:
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:
  ("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 or have water effects 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 :sad: . 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
 

Janus

*spicy* *camper*
Administrator
WBWF&SM&BVC
Best answers
0
Very nice. So the collision meshes should be triangulated? I never did get around to messing with collision meshes successfully.

Oh, and thanks on that info on tiling textures; I hadn't realized it was that simple. :smile:
 

Yoshiboy

Count
M&BWB
Best answers
0
Janus said:
Very nice. So the collision meshes should be triangulated? I never did get around to messing with collision meshes successfully.

Oh, and thanks on that info on tiling textures; I hadn't realized it was that simple. :smile:
collision meshes dont need to be trianguated, but it does no harm. Just easier than having to keep changing the export settings :smile:

edit: something about modding that i knew and janus didnt! :O :razz:
 

Janus

*spicy* *camper*
Administrator
WBWF&SM&BVC
Best answers
0
Yoshiboy said:
collision meshes dont need to be trianguated, but it does no harm. Just easier than having to keep changing the export settings :smile:
Ah, cool. I thought I remembered Fisheye saying that you should have them untriangulated to prevent problems or somesuch, but it's been a while since then. Somehow that gave me the idea that they might not work triangulated.

Yoshiboy said:
edit: something about modding that i knew and janus didnt! :O :razz:
Hey now, you've done more mod work than me at this point. :smile:
I'm mainly just good with the scripting part since I enjoy programming. As for 3D modelling, I only recently learned it enough to consider myself a novice when I tried my hand at making a few swords. So my knowledge there is very limited. :razz:


EDIT:
Yoshiboy said:
Anyway, lets stop chatting like old ladies as unforunatly thats not what this thread is for :razz:
Sure thing, Francis. You up for a game of BINGO then?
 

Yoshiboy

Count
M&BWB
Best answers
0
Yeah, fisheye mentioned that they dont have to be triangulated, which i cant see how that woudl work for games....you get non-planar faces, and for collisions...blah blah, i'll start drizzling on. The main point is that they work for me, and this is the method i have been using i guess. Although that does remind me about a few more points that i need to add about collision meshes, i forgot.

heheh, i suppose thats fair, although if you hadnt been waiting on me hand a foot in PMs i dont know how far i would have got. I'm considering writing a final extension tutorial on rigging amour and horses to go with highelfwarrirors one, although my knowledge there is a little limited on the theory, tips and tweaks behind it all so i dont know how useful it would be.

Anyway, lets stop chatting like old ladies as unforunatly thats not what this thread is for :razz:
 

Voutare

Master Knight
Best answers
0
Did you really make this whole tutorial because I wanted to know about it, or have you worked on it before i talked to you about it?

I feel important :grin:
 

Yoshiboy

Count
M&BWB
Best answers
0
Voutare said:
Did you really make this whole tutorial because I wanted to know about it, or have you worked on it before i talked to you about it?

I feel important :grin:
i've been planning to write it for a long time. I would given you a run through in PM but i knew i was going to be writing this soon anyway.
 
Best answers
0
hmm, I have a small question..
Does a collision mesh need to be lowpoly to?
I mean its not visual or anything..but the game reads it though :???:

I mean havind a 1000 poly colishion mesh (example)
will that slow down the performance as a normal object would?.

also.. wouldnt it be easier if I or anyone would just make some ' inivisble walls' In many sizes instead of a custom collision mesh for every mesh.. So you can create a sort of collision mesh ingame (ofcourse only for non-animated objects)
Just wondering ,Would make things slightly easier.. Not?
..

EDIT: BTW great job on the tut, Yoshi  :wink:
 

Yoshiboy

Count
M&BWB
Best answers
0
Highelfwarrior said:
hmm, I have a small question..
Does a collision mesh need to be lowpoly to?
I mean its not visual or anything..but the game reads it though :???:

I mean havind a 1000 poly colishion mesh (example)
will that slow down the performance as a normal object would?.

also.. wouldnt it be easier if I or anyone would just make some ' inivisble walls' In many sizes instead of a custom collision mesh for every mesh.. So you can create a sort of collision mesh ingame (ofcourse only for non-animated objects)
Just wondering ,Would make things slightly easier.. Not?
..

EDIT: BTW great job on the tut, Yoshi  :wink:
like i said near the begining, as the computer reads the collision mesh so often it is essential that you keep it as low polly as possible. 1000 isnt sooo bad....but its not brilliant.

You could make sets of invisible walls but it would be very practical, in places it would go where its not needed and it would take a hell of a long time putting it all together. I suggest you dont do it :wink:
 

Yoshiboy

Count
M&BWB
Best answers
0
Updated - added section on use of water in scenes.

Also I correct myself, collision meshes must be triangulated.
 
Best answers
0
Great addon on the water, Though I always thought there was no way of making a plane (plain?-) in wing3d

How did you do it?
 
Best answers
0
Ok , I always just scaled the cube on Y it up until now, Though I knew it wasn't a real plane then.

Never thought about cleanup , Thanks.
 

Thorgrim

Knight at Arms
Best answers
0
Great tutorial Yoshi, but could I ask anyone who is trying this to try using BRF edit to import the collision meshes?

Just click the col tab, then do import > select the obj, then change the name to bo_whatever if you want (although you dont' have to).

Although some people seem to say it doesn't work, it almost always works for me, and when it doesn't work, fisheyes tool doesn't work either.  Its usually due to a messy mesh which shouldn't be used for collisions anyway.

I have nothing against Fisheyes tool, its great and all, but BRFEdit creates exactly the same collision mesh as his script for every obj I have tried...

If you do find an obj that works with Fisheyes tool, and not with mine, please pm it to me so I can fix BRFEdit!

Edit: Thanks to Fisheye, who gave me a obj file that brok BRFEdit, the collision mesh importing should now be fixed in 0.6.3
 

Thorgrim

Knight at Arms
Best answers
0
Yes,

Click the col tab in BRFEdit then do import > select the obj file.

Or you can use Fisheyes tool.

However the new version (0.6.3) of BRFEdit fixes the problem with Importing Wings obj files, so both should work fine.
 

TakiJap

Sergeant
Best answers
0
Yoshiboy said:
  • Collision meshes DO NOT NEED any UV coordinates or anything like that.
  • Collsion meshes DO NOT NEED to be closed geometry, you can have them as open as you like....
  • Does it hurt if my mesh is already UV'd?
  • Does open geometry mean that the mesh can have messy, strange faces and edges in places your character can't get to?
 

Yoshiboy

Count
M&BWB
Best answers
0
1. Not at all.
2. closed geometry simply means in wings you have no faces set to "hole" materials, in other apps its a little more complex because you can literally delete polygons, althought they don't need to be closed it can still cause some problems. If anything collision meshes have to be as clean as possible, otherwise your likely to get errors.

I'll clean up both these points, thanks :smile: