Documentation/Tutorials/Creating a complex dynamic object

From NeoAxis 3D Engine Wiki

Jump to: navigation, search
Go to higher level


This tutorial demonstrates creation of dynamic object types. Unlike static objects, dynamic ones can change their properties over time. Aside from a 3D model shaping the visual appearance of the object, the dynamic object is also linked with a physics model used to compute object interaction with the environment.

The object type (.type file) is created in the Object Type Editor, and a physics model is created in the Physics Model Editor.

Before reading this tutorial we recommend taking a look at the following sections:

CreatingDynamicObject 027.jpg


This tutorial describes creation of an entrance swinging door. In the end of this lesson we will place our door to the test map and will try to enter the house through it in the simulation mode.

First, run the Resource Editor.

First of all, let's create a folder for our object. To do this, right-click the Types\Dynamic folder and choose New -> Folder in the context menu.

CreatingDynamicObject 001.jpg

Enter the name for the folder: MyDoor.

Now, let's prepare resources. For the purpose of this tutorial, we will use a ready-made 3D-model of a door already existing in the SDK. Copy a 3D model file from the Maps\VillageDemo\Types\VillageDoor2 folder. In that folder, right-click the meshU3D_012.mesh file and select Copy in the context menu.

CreatingDynamicObject 002.jpg

Now, let's get back to the MyDoor folder we have created earlier in the Types\Dynamic folder. Right-click it and select Paste in the context menu.

CreatingDynamicObject 003.jpg

It's time to create an object type. Right-click our folder again and select New -> Entity Type in the context menu.

CreatingDynamicObject 004.jpg

In the appeared window specify the name of our type — MyDoor and its class — MapObject (basic map object). Click Next.

CreatingDynamicObject 005.jpg

Switch to the type editing mode. To do this, select the MyDoor.type file and click the Edit button on the toolbar.

Another way to open a file for editing is to double-click it with the left mouse button.

Now, we add a 3D model to the type. Right-click anywhere in the work space and select Attach Object -> 3D Model in the context menu.

CreatingDynamicObject 006.jpg

In the appeared window select a file with the model.

CreatingDynamicObject 007.jpg

We need to scale the door a bit to make it better fit doorways on the demo map. To do this, select the attached model in the object window and type the values of 1 1.05 0.97 in the Scale field of the properties window.

CreatingDynamicObject 008.jpg

Save the type file. To do this, click the Save button on the toolbar.

The next step of creating a dynamic object type is building a physics model. Physics models are created in the special editor that is a part of the Resource Editor.

Let's create a physics model. Right-click the MyDoor folder and select New -> Physics Model in the context menu.

CreatingDynamicObject 009.jpg

In the opened window specify the name of a physics model — MyDoor and click the Next button.

CreatingDynamicObject 010.jpg

Editing of a physics model is more convenient when you open it in the type editor, because in this case you can see 3D models attached to physics bodies. At fist, we need to attach a physics model to the type.

Open our .type file again for editing and in the properties window click the "..." button next to the Physics Model field.

CreatingDynamicObject 011.jpg

In the appeared window select the recently created MyDoor.physics.

CreatingDynamicObject 012.jpg

Now, click the Edit Physics Model button below the properties window.

CreatingDynamicObject 013.jpg

We switched to the editing mode of our physics model MyDoor.physics.

The physics model of a door requires two bodies and one joint. The first body represents the door itself. The second body works as a door buck. And the joint becomes door butts to allow the door open and close.

Upon creation, the physics model contains only one cube-shaped body. Let's turn it to the body of the door. To change body parameters, expand the Body: body1 list in the properties window.

CreatingDynamicObject 014.jpg

First of all, rename the body. Enter bodyDoor to the Name field. Also, change the following body parameters:

  • AngularDamping = 0.7 (angular velocity damping factor)
  • LinearDamping = 0.7 (linear velocity damping factor)
  • Position = -0.02561985 -0.4537934 0 (coordinates)
  • Mass = 70 (mass)
  • MassMethod = Manually (manually)
The above and other properties of a physics body are described in details in the description of the Physics Model Editor.

Then, expand the Shapes list, and the 0 list inside it to change parameters of our body's primitives. Another way is to click the cube twice. First click selects the body, second click selects the form.

Specify coordinates and dimensions of the box:

  • Dimensions = 0.07563129 1.058791 2.082091 (dimensions)
  • Position = 0.001697881 0 0 (coordinates)
Detailed description of these and other properties of primitives can be found in the description of the Physics Model Editor.

We have set the dimensions of the primitive a bit smaller than the dimensions of the 3D model of the door. This way we define the doorway.

After all changes are done, save the physics model by clicking the Save button on the toolbar.

CreatingDynamicObject 015.jpg

Let's get back to object type editing. In the properties window, select the attached 3D model and select the bodyDoor body in the Body field of the properties window. To view a physics model in the type editor, set the checkmark in the Show Physics checkbox.

CreatingDynamicObject 016.jpg

Now, get back to the physics model editing. Don't forget to save our .type file. Click the Edit Physics Model button.

Time to create one more body for our physics model to work as a door buck. Right-click anywhere in the workspace of the editor and click Create Body in the context menu.

CreatingDynamicObject 017.jpg

Specify the following properties of the new body:

  • Name = bodyStock (name)
  • Static = True (static body)
  • Position = -0.02565728 0.1403132 0 (coordinates)

Now, right-click the sphere depicting the new body and select Create Box Shape in the context menu.

CreatingDynamicObject 018.jpg

Specify the following parameters of the created box:

  • Contact = False (does not contact with other bodies)
  • Dimensions = 0.1131822 0.1131822 1.909913 (dimensions)

To finish the physics body of our door, we need to equip it with door butts. The Hinge Joint joint assumes the role of door butts. A joint of such type allows bodies to rotate relative to each other around the specified axis.

In the workspace of the editor select both bodies with a frame, then right-click them and select Create Hinge Joint in the context menu.

CreatingDynamicObject 019.jpg

Set the following parameters of the joint:

  • Anchor = -0.06984536 0.1219251 0.1340412 (joint coordinates)
  • ContactsEnabled = False (body contacts are disabled)

In the Axis list set the following properties:

  • Direction = 0 0 1 (rotation axis direction)
  • LimitHigh = 90 (maximum rotation angle)
  • LimitLow = -90 (minimum rotation angle)
  • LimitsEnabled = True (limits are on)
These and other properties of joints are described in details here.
CreatingDynamicObject 020.jpg

At this moment we have finished creating a physics model of the door and now we only need to save our .physics file. You can test the physics model directly in the editor by clicking the Test button below the properties window.

When you test the door, drag it with the left mouse button and if the physics model is configured properly, the door opens in the direction of the arrow. To stop testing, click the Stop button.

CreatingDynamicObject 021.jpg

Now, we add a final chord to our type object and enable shadows for the object. Open the .type file for editing. In the object window select the attached 3D model and set the value of the CastDynamicShadows property in the properties window to True.

CreatingDynamicObject 022.jpg

Save the file by clicking the Save button on the toolbar.

CreatingDynamicObject 027.jpg

The dynamic object type is ready and we can test it in action. To do this, run the Map Editor.

Create a new map or open one of the existing ones.

To learn more about map creation, read the lesson on creating a simple map.

Add a house to the map (static mesh) using the meshU3D_000.mesh 3D model from the Maps\VillageDemo\FarmModels\Meshes folder.

Then, add a door to the map. Select our MyDoor type in the Object Creation window, the Types\Dynamic folder and place the door in the doorway of the house.

CreatingDynamicObject 023.jpg

Use the transform tool to precisely place the door.

For easier placement of the door, use the Draw Dynamic Physics option from the Profiling menu.
CreatingDynamicObject 024.jpg

Save the map by clicking Save on the toolbar. Then, click the simulation button.

CreatingDynamicObject 025.jpg

Now, a character can get inside the house by pushing the door. The lesson on creating a complex dynamic object type is over. You've learned to create dynamic object types, to attach 3D and physics models to them and to place such objects on the map.

CreatingDynamicObject 026.jpg