Documentation/Articles/Overview of Physics Model Editor
From NeoAxis Engine Wiki
| Language: | Status: | Approved |
Contents |
Overview
Physics Model Editor is a part of Resource Editor and it's purpose is to let user create and modify physics components. Later it can be used in your application to implement physical interactions between objects.
Here you can find more general information about NeoAxis physics engines.
Options
To access Options, click on the Options button on the toolbar, or go to Tools -> Options. A window will open, allowing you to change the look of Physics Model Editor.
There are five parameters under General rollout:
| Property name | Description |
|---|---|
| Background Color | Allows you to set a color displayed in the working window's background. You can either enter the RGBA (Red Green Blue Alpha) values (each in range 0-255) or use a color picker.
Note - background color is only visible when skybox is off. |
| Grid Height | This value determines the grid height in space. |
| Show Axes | Set to True if you want to see axes gizmo, which is helpful to determine directions in space. |
| Show Grid | Set to True to see a grid. Helpful to determine model scale. The grid is also a kind of hard floor which stops falling objects. |
| Sky Box | Use this option to load a different skybox, which is displayed in the background. |
Once you have done changes press OK button to save them or Cancel to discard them.
Simulation Mode
The Physics Model Editor gives you the possibility to test your model in Simulation Mode. To start simulation, you must be editing a .physics file. Press the Simulate button in the lower left corner of your screen, on Properties window.
While in Simulation Mode, you can display the number of Contacts. Contact occurs when one shape touches another shape.
Building elements
There are three basic categories of elements from which you build your physics model. These are:
- Bodies
- Joints
- Motors
You will find short tutorial about creating a physics model in the further section on this article.
Bodies
A rigid body is an entity that can be put under influence of one or more forces. A body can constitute of either one shape, or a group of shapes that cannot be pulled apart. Each body can have its own mass and position in space.
Creating a Body
There are two ways to create a body. For both, to create a new body, you must be open a .physics file in Edit mode. (Double click on the file or right click and select Edit). You can right click in the working window and from a rollout list select Create Body.
Alternatively, click on the Browse icon in the Properties window, next to Bodies rollout.
You will see a Body Collection Editor window where you can add a Member. You can also remove an existing Member or change the order of a number of Members.
This Member is effectively the Body, for which you can define useful parameters:
Properties of a Body
| Property name | Description |
|---|---|
| CCD | Enable Continuous Collision Detection method by setting this value to True. |
| EnableGravity | If set to True the body will be influenced by gravity force that pulls it toward the ground. If set to False the body will remain its starting position (if not influenced by another force). |
| Name | Here you can define a unique name for the body, that will distinguish it from other bodies. |
| Shapes | Gives you access to Shape Collection Editor to assign a shape for the body. This will be discussed in detail later in this article. |
| Sleepiness | This option defines the cut-off level, after which forces affecting the body are approximated to 0. |
| AngularDamping | This value defines how much angular velocity is reduced over time. The greater the value the faster reduction. |
| LinearDamping | This value defines how much linear velocity is reduced over time. The greater the value the faster reduction.
Note: Damping in physics models is not the same as friction, because it is independent of other bodies. |
| Mass | This parameter is not directly editable. It displays the total mass of all shapes of the body. |
| Position | Consists of three values for X, Y and Z axis and describes position of the body in the physics model. |
| Rotation | Consists of three values for X, Y and Z axis and describes how the body is rotated in the physics model. |
Adding Shapes to a Body
To quickly add a shape to a body, select it and right click in the working window. Select a shape type you want to add from the list.
Another method of adding shapes to a body is Shape Collection Editor. To open it, click on the Browse icon next to Shapes rollout either in Properties window or Body Collection Editor while creating a body.
By pressing the Add button, you can create a new shape. You can select what kind of shape you want to add by pressing small arrow which is a part of the Add button. Available are:
- BoxShape
- SphereShape
- CapsuleShape
- MeshShape
- PhysXWheelShape (only supported by nVidia PhysX engine)
To use your own mesh as a shape, select MeshShape and go to Mesh Properties -> MeshName to open the Choose Resource window and find the mesh you want. Keep in mind that the more detailed is the mesh structure, the more CPU-expensive it is to calculate physics for it. It is a good idea to prepare a simplified mesh to use with the physics model rather than just use highly detailed model.
Properties of a Shape
There is also a list of properties that can be set for each shape:
| Property name | Description |
|---|---|
| Contact | If set to True, the shape will be able to come into contact with other shapes. Setting this to False will cause the object to pass through other object with no interaction. |
| Name | In this field you can enter a unique name for the shape. |
| ShapeType | Displays the type of shape. Can be either Box, Sphere, Capsule, Mesh or PhysXWheel and is not modifiable. |
| Bounciness | This value defines the shape's bounciness. Value range is from 0 to 1 and the higher it is the more bouncy will the shape be. |
| Density | Density has direct influence on the object's mass. Value range is from 0(least dense) to infinity. |
| DynamicFriction | This parameter describes the dynamic friction of the shape. This type of friction occurs when two objects are moving relatively to each other and influence each other. Values range is from 0 to 1 and the higher the value the greater is the friction. |
| Hardness | This parameter defines how resistant is the object to shape changes when force is applied. Values range is from 0 to 1 and the higher the value the harder the object is. |
| MaterialName | Here you can load one of already defined set of shape's parameters. Available are: Metal, Wood, Rubber and Ice. You can specify new materials in the \Data\Definitions\PhysicsSystem.config. |
| StaticFriction | This parameter describes the static friction of the shape. This type of friction occurs between two objects that do not move relatively to each other. Values range is from 0 to 1 and the higher the value the greater is the friction. |
| SpecialLiquidDensity | This parameter is used in relation to water plane. It defines the object's density when it floats in a liquid and is used to decide whether it should sink or float on the surface. Setting this value to 0 will make the object sink, while 1 will cause it to float. |
| Position | Consists of three values for X, Y and Z axis and describes where the shape is positioned in the body. |
| Rotation | Consists of three values for X, Y and Z axis and describes how the shape is rotated in the body. |
Joints
Joints are used to connect exactly two bodies to make them influence each other. You cannot assign a joint to only one, or a group of more than two bodies.
Creating a Joint
To create a joint, first select two object that you want to connect with this joint, then right click in the working window and select a joint type that you need from the list.
Joint Types
Here is a list of available joints along with description and example:
| Joint type | Description | Example |
|---|---|---|
| Hinge Joint | Objects linked with it can only move in one axis and distance between thise joint and those objects is fixed. | |
| Universal Joint | Allows the linked objects to move in two axes and distance between joint and those objects is fixed. | |
| Ball Joint | Linked objects can move and rotate in all three axes and distance between joint and those objects is fixed. | |
| Slider Joint | Linked objects can move in only one axis with no fixed distance. | |
| Hinge2 Joint | This type of joint is only supported by ODE physics system and requires that both bodies are not static.
Works similarly to Universal Joint, but with different hinge axes. Allows movement in two axes. |
|
| Fixed Joint | Doesn't allow any changes in distance and position between two objects. |
Properties of a Joint
Each joint type has similar properties. The only difference is the number of axes you can configure.
| Property name | Description |
|---|---|
| BreakMaxForce | This field defines the maximum force that needs to be applied for the joint to break. 0 means it is not breakable. |
| BreakMaxTorque | This field defines the maximum torque that needs to be applied for the joint to break. 0 means it is not breakable. |
| Anchor | Position of the joint in the world, consists of three values - X, Y and Z. |
| Axis Direction | Defines bending angle for connected bodies. Values range from 0 to 1 for X, Y or Z axis. If incorrect parameters are entered (i.e. 1 0 1), the editor will inform you once you start a simulation. |
| Axis LimitHigh | Sets the upper limit for movement on this axis. |
| Axis LimitLow | Sets the bottom limit for movement on this axis.
Note: LimitHigh should have greater value than LimitLow. Note: These limits will only work if LimitsEnabled property is set to True |
| Axis LimitsBounciness | Defines the bouncing limit when two joined bodies interact. |
| Axis LimitsEnabled | Enables you to use LimitHigh and LimitLow if set to True. If set to False above limits will not be taken into account. |
| Axis LimitsHardness | Describes stiffness of rebound when reaching the axis limit. |
| Body1 | Displays the first body linked by this joint. This field is not editable. |
| Body2 | Displays the second body linked by this joint. This field is not editable. |
| ContactsEnabled | Setting this to True will allow the joined bodies to contact each other. Setting to False will cause the object to freely intersect without influencing each other. |
| Name | Here you can give a unique name for your joint. |
Motors
Motors are entities that create force. There are three types of Motors:
- Attractor Motor - only type of Motor that can be built between two bodies. It applies attracting force between two bodies, causing them to move toward each other (assuming there are no other, more powerful forces that would prevent them from doing so).
- Geared Motor - this Motor can only be created on a joint. It can produce Torque and Velocity forces and can be used for example to move car wheels.
- Servo Motor - can only be created on a joint. It's purpose is to apply force until defined criteria are met.
Creating a Motor
To create an Attractor Motor, select two bodies and right click in the working window. Select Create Attractor Motor from the context menu. To create a Geared or Servo Motor, select a Joint to which you want to attach the Motor, and right click in the working window. Select the appropriate Motor at one of available Rotation Axes.
Each Motor has it's own set of properties:
Attractor Motor
| Property name | Description |
|---|---|
| Body1 | Displays the name of first influenced body. This field is not editable. |
| Body2 | Displays the name of second influenced body. This field is not editable. |
| Enabled | Set to False if you want to disable this motor. |
| Exponent | This value defines the exponent for interaction strength. |
| Name | Here you can define a unique name for this motor. |
| Strength | This value defines the strength of interaction. The higher the value, the stronger the attraction between connected bodies. |
Geared Motor
| Property name | Description |
|---|---|
| Enabled | Set to False if you want to disable this motor. |
| Joint | Displays name of the joint that the motor is attached to. This field is not editable. |
| JointAxis | Displays the kind of axis that the motor works on. This field is not editable. |
| MaxTorque | Defines maximum torque that can be given to influenced joint. |
| MaxVelocity | Defines maximum velocity that can be given to influenced joint. |
| Name | Here you can define a unique name for this motor. |
| Throttle | This value defines the direction and starting strength of force. Range values are from -1 to 1. 1 is clockwise, -1 is counterclockwise and 0 is static. |
Servo Motor
| Property name | Description |
|---|---|
| DesiredAngle | Defines the angle to which the motor will try to push the body. Once this angle is reached, a force will be applied only to maintain this angle. |
| Enabled | Set to False if you want to disable this motor. |
| Joint | Displays name of the joint that the motor is attached to. This field is not editable. |
| JointAxis | Displays the kind of axis that the motor works on. This field is not editable. |
| MaxTorque | Defines maximum torque that can be given to influenced joint. |
| Name | Here you can define a unique name for this motor. |
| RestoreMultiplier | This value describes how stiff will be the influenced joint and how much time it takes the motor to return it to the set angle. The closer this value is to 0, the more stiff the joint is. |
How to make a .physics file
This part will teach you how to make your own .physics file and will demonstrate a simple model of a ball hit by a hammer.
To make a new .physics file, right click on a folder in Resources window in which you want this file to be created, and from the context menu select New Resource.
From the New Resource window that appeared, select Physics Model and in the next step give it a name. Now, open this newly created file in Edit mode. You will see that one body is already created. You can keep it or delete it if you wish. For the purpose of this tutorial, let's start with en empty file. Create a body that consists of three boxes, just as on shown in Fig.1 (see Bodies section to read how to create it). Change the body's parameter Static to True, so it doesn't fall on the ground. Notice how it changed color to dark blue.
Now create a new body with a sphere shape and place it on the body made of boxes, and give this sphere parameters just as in Fig.2
Next, create a Static body over your structure - just as the brown box on Fig.3. You can leave it's properties on default. Near it, create another body, that has two box shapes, and make a simple hammer of them (look at green body on Fig.3). Change their density values to 10.
Select both bodies you've just made, and connect them with a Hinge Joint. Open the joint's properties, in in Axis rollout, change direction from 1 0 0 to 0 1 0 (Fig.4)
Now, you can run a simulation to see how the heavy green 'hammer' falls, gains speed and hits the ball, which is shot from its starting position by the hit.
If you would like to see more examples, look in \Data\_Tests\Physics.










