Documentation/Tutorials/Creating a complex dynamic object
From NeoAxis Engine Wiki
| Language: | Status: | Approved |
Introduction
Before reading this article, please familiarize yourself with the following:
Description
This tutorial will demonstrate the creation of a mill. The mill consists of two meshes - tower and wings. Wings will be attached to the tower using a joint allowing spinning.
We will use a model that is delivered in standard distribution of NeoAxis. The files we need are: WindMill.dds, WindMill.highmaterial, WindMill.mesh, WindMillFan.dds, WindMillFan.highmaterial and WindMillFan.mesh - they are located in Bin\Data\Types\Dynamic\WindMill\ folder. This lesson will demonstrate the creation of the following files: WindMill.type and WindMill.physics. You can delete or rename the existing ones, to avoid conflicts during the lesson.
Now, let's create the mill!
First, create a new Entity Type and call it WindMill, selecting MapObject as Class type.
Attach to Windmill.type the model of the tower (Windmill.mesh).
Now, we need to create a physics model. The physics model is needed in order to create dynamic physis structure.
To do this, create a new resource:
Select Physics Model:
And call it WindMill.
We have now created the WindMill.physics file and it can be seen in the Resources list.
Next we need to go into Edit mode (right click -> Edit) and specify the name affixed to the body of the physical model. Let's write bodyMain in the Name parameter.
As we can see, the body is created as a form of a cube. This body will be the main structure of the physical model and will be connected to the tower mill.
Now we need to edit the bodyMain primitive . To do this, open the Shape Collection Editor by clicking "..." in the Shapes' parameter. Remove automatically generated Box primitive.
Let's add a new MeshShape primitive. MeshShape allows you to create a primitive based on the geometry of a model.
In the MeshName point the model of the tower (WindMill.mesh). By clicking OK you will see the silhouette of the tower, built on the basis of the model.
Now we need to make our tower a static object. To do this, change the "Static" property to True.
Creating a physics model for our tower is completed. Now we need to assign the physical model to WindMill.type. Enter edit mode for WindMill.type and in PhysicsModel property specify the one that you just created - WindMill.physics.
Check the radio button Show physics in the lower right corner. Now we see the tower model and physics model together.
Now we need to create the wings of the mill. The wings are a dynamic physics body. They are connected to the body of the tower with a joint.
Continue editing the physics model. Make sure that both the windmill model and the physical model are displayed. To do this, go to Edit mode in WindMill.type and then click Edit Physics Model. Now you are in Edit mode of a physical model, also you can see any attached objects from WindMill.type.
Right-click on the working window and from the shortcut menu select Create Body.
The physics body is created. Select the body and pull it to the free space using Select and Move tool.
Right click on the body and select Create Box Shape from the shortcut menu to make a primitive Box. As you can see, there are two ways to create bodies and entities (through the properties and through the context menu). The are no differences between them.
For the tower we created a primitive physics body using MeshShape. For the wings we will create a physics body in the same way, but based on a Box.
Create two Box primitives and stretch them so that they resemble the wings. In the properties, we can see two Box primitives.
Rename the wings' body to bodyFan. In the future we will use this name to attach the wings to the tower.
Now we need to add wings model to Windmill.type. To do this, start editting the .type file. Open AttachedObjects dialogue window. Add a model by selecting MeshName and pointing the location of the wing model. Next, select bodyFan in the Body drop-down menu. It is necessary so the wings model is attached and moves along with the physics body of the wings. Click OK.
Now you can see that the model of wings is located in the position of the bodyFan physics body.
Now, click to edit the physics model. Finally set up the body of the wings. As a result, we have got six Box primitives.
Now you need to connect the two bodies into one coherent object.
You have to create a connection to the axle, which will rotate the wings. For this purpose it is necessary to use the Hinge connection type. Let's move the body of the wings to where it should be.
Position both tower and wings bodies, and click the right mouse button. In the shortcut menu, select Create Hinge Joint.
Move the created connection to the desired position. The yellow line marks the axis of rotation.
To test the created physical model, as necessary, click Simulate. Alternatively you can just press Space.
You can add additional impetus to the bodies. Press the mouse button on one of the wings and pull it by dragging the mouse.
To make the mill turning without our help, we will use the motors.
Select the joint and click the right mouse button. From the shortcut menu, select Create Geared Motor At RotationAxis1. Motors are designed precisely to give extra strength to the axes of joints.
Now we need to adjust the engine parameters.
Set the parameters MaxTorgue to 1000, MaxVelocity to 20, Throttle to -1.
We can now run the simulation and see wings rotating without our help.
Save your changes and go back to editing WindMill.type. Set AllowEditorCreate property to True.
Congratulations! Your windmill is completed.
Now you can open the map editor and put the object on the map!