Hpl2:Tutorials:model editor:tutorial 2

From Frictional Wiki
Jump to navigation Jump to search

Model Editor - Creating Ragdoll Entities

This tutorial will detail how to import export models from Amnesia, as well as rigging a model in the model editor to create a ragdoll entity.

To import a model from Amnesia to your own 3D modeling program, simply download OpenCollada for your program, available here. 3DS Max, Maya, and Blender are the typical programs to use. For models without animations, simply import the .dae model into your program using the OpenCollada plugin. Unfortunately, models with animations, such as the Grunt and Brute, are a little more complicated. Due to the fact that the game engine uses the Y axis as up, only Maya (and possibly Blender, unconfirmed) will import the animations properly. 3DS Max will NOT do it properly. It may be possible to rotate the model and animations, but would most likely require some complex tweaking or scripting using MaxScript.

Using Maya as an example, the animated model should be imported like any other model. Once the model is loaded and everything seems okay, the next step is to strip all animations from the model. This is because if the bones of the model have animations attached to them, the Model Editor won't be able to attach bodies to their bones; the model will simply stand in place, even if its body entities are moving around.

To strip the animations from the model in Maya, go to Edit, Select All by Type, Joints. This will select the bones/joints. Then go to Edit, Delete All by Type, Channels. This will remove all keyed animations from the model. The next step is then to export the model back into Amnesia. Choose a different name when exporting! Also, make a new folder for the model with the same name.

After it is exported, open it in the Model Viewer to create .msh and .mat files for the model. Then open the Model Editor, go to File, Import Mesh, and pick your exported .dae model. Now the fun part! In order to get a realistic ragdoll effect, we need to emulate biped style joints.

The realism you want with your model depends on how much work you want to do on it. To get the most realistic effect, we need to make a single body for each corresponding joints (some of them might be redundant because they are not on typical joint locations). You will want to make the body so it is close to the joint you want to connect it to, but close to all other joints that you will be using. For example, for the upper leg, the body will extend from the joint in the knee to the joint in the thigh. To create a body, simply pick the shape icon on the left of the screen, and choose a list of shapes from the top right of the screen. There are only 4 types, so pick one that would best fit the body parts of the model; this is most likely a capsule. We then fit in these shapes over body parts; they do not have to fit perfect, they just have to be in the same place, usually smaller than the body part itself. They will most likely extrude from the model in a lot of places, but that's fine.

Of course, the main issue is choosing the right location for each shape. The first thing you should do is decide what the main parent joint of your model will be. This is usually the root joint (it will probably be named this), and is usually located in the stomach or chest. The first thing you should do is create a shape for that root joint. For example, if the root is in the stomach, create a shape above it that fits around the chest. Try to shape it so that it will be close to other joints that you will be using, such as the shoulder joints and neck joint. Once the shape is created, we need to connect it to its corresponding joint. Select the shape, and on the right, pick the shape tap, and then click on Create Body. This will create a body which will emulate the mass and other physics for the model (the model does not do this on its own).

There are two ways to attach the joint(s) to the body. One way is to pick the tab Attachments to the right of Body (which replaces the tab Shape). Then click the type of object you want to connect the body to, in this case Bo for bones. Then click attach. You would then click all of the joints that you want to connect to the body; they will turn from red to green to specify they're connected to that body. Once you've connected them, click on Done (in place of Attach) or just click on an empty space on the screen. The other way is to click the View tab on the top of the screen, then outline. This is the model heirarchy. You can pick a body from here, and then pick from the list of joints to attach. It's a great way to check to make sure everything is attached after you're done. Now the body is attached to the joint!

The next step it to add physics to the body. Highlight the body, and click the Body tab. For a model, choose the right kind of material for it (most likely organic for biped models). Pick a mass for the body; a mass of about 20 is when the body will start to be difficult to pick up. I usually put angular and linear damping to 1, buoyancy to 0 (this is if you want it to float or not), and deselect "Can attach character" and "Pushed by character gravity", though this was following other models from the game, and you can choose other options based on what you want. Now the body has physics!

You need to do this for all the joints that you want to make. Also, remember that a joint can only be connected to one body. For this reason, there is generally a certain way to connect bodies to joints to get the best effect. As mentioned before, pick a root joint, say the stomach. When making the body for the chest, you would connect it to the stomach joint. For the head, you would connect the body to the neck joint. For the upper arms, you would connect the bodies to the shoulder joints. The neck and shoulder joints would all be relatively close to the chest body. If you can picture this, you would see that as the body entities go outward to the extremities, they will only connect to the joint towards the body, not away. Remember, it is best to have the body have close proximity to all the neighbouring joints. This is to create a close rotation between two bodies, as well as creating more space for grabable entities.

NOTE: You can test your entity in a physical environment at any time by pressing the icon with the two cogs at the bottom of the screen.

Now you are done adding bodies and linking them to the joints! But it's not done yet. If you try to test the model, you'll notice (amusingly) that the model will just stretch way out and flop around all weird. This is because the bodies themselves aren't linked in any way; they simply fall to the floor on their own, and drag their corresponding joints with them. We now need to use "Joints", which is the last icon on the left side of the screen. There are 4 types. Most likely, you will only need Hinge and Ball joints. Now we need to place joints in between the bodies. The best place to put the "joints" are on the joints/bones of the body that correspond to where the body will bend. If you set up the model properly, this will be between two bodies that you inserted. Now the question is, which type of "joint" should I pick? You have to visualize how a body part would turn at that point. For example, a knee joint would need a Hinge Joint, since it only rotates in one direction. A shoulder or thigh joint would need a Ball Joint, since they rotate in all directions (imagine a ball in a socket turning around). You should place all the joints you need for each place before you do anything else. Once this is done, we need to link them to the bodies. Again, we need to think what the main parent body would be. This would be the chest body. So when we link the bodies, we click the joint, go to the Joint - Base tab, and then click Set Parent. You then click on the parent body. To decide what the parent should be, think about how the chest is the main parent. The child bodies will then extend outward. For example, for the lower leg and upper leg, the upper leg would be the parent, and the lower leg would be the child, since it is farther away from the chest; it extends outward. Do this for all the joints. Unlike connecting bones to bodies, bodies can be parents or children for multiple joints (this would not work properly if that were not true). So for example, the chest will be the parent for the two shoulder Ball joints, the neck Hinge joint, and the stomach Hinge joint. Connecting parents and children can also be done from the outline menu under the view tab.

Once you connect all bodies to each other, there's one more thing to do; set the direction and amount of rotation. The third tab for joints, Parameters, will set this. For Hinges, there is simply a min and max angle. The Hinge will simply rotate between these angles. For a Ball joint, there is a Cone angle and Twist angle. The Cone angle is the amount the joint can rotate away in any direction from the default direction (xy local plane). The Twist angle is the amount the ball can twist on itself (z local axis). Then there's the direction to take into consideration. The white arrow on each joint shows this direction. The orientation of it compared to the rotation is kind of tricky to work out sometimes, so it can take some trail and error. Ball is pretty simple; the white arrow points in the direction of the default direction, so the ball rotates away from it. Hinge is more tricky; it seems as though the joint will rotate around the arrows axis. This makes it harder to put the proper rotation min and max, as you can't tell how the arrow is oriented on its own axis. Just keep testing it out using the physical test environment. Eventually, you'll be all done and the model will act like a real ragdoll!

There is one more thing to do though, you need to set the entity type. On the top of the screen, click settings, and user defined variables. In the drop down box, choose object. If you just want a regular object with no interaction, pick static in the submenu and you're done. If you want a grabable object, for example, pick Grab. For grabable objects, a few things should be changed. Scroll down to the bottom of the variables list, and change GrabFoceMul to 0.2 and GrabTorqueMul to 0.2. If they are left as 1, most likely when you pick up the body, it will add too much force to the body and it will look like the model is having a seizure (no lie, its very humourous, and usually results in the body being stretched across the whole room). Change GrabMassMul to 2 if you want to make your model seem heavy when you pick it up (you'll only be able to lift the chest about half a meter above the ground usually, almost like you're dragging a real body). And change GrabThrowImpulse to around 6 (which is 6 m/s) to make it throw the model slower.

That's the end of this tutorial, I hope you guys understand it all and make some kickass ragdoll entities or other cool models! =D

Created by: MrBigzy