Documentation/Articles/Overview of Physics Model Editor

From NeoAxis 3D Engine Wiki

Jump to: navigation, search
Go to higher level

Contents

Overview

The Physics Model Editor, used to create and edit physics models, is part of the Resource Editor. Physics models are a physical representation of the objects in the world. Physics model are made of physical bodies, joints and motors.

Physics editor

Test Mode

The editor allows you to test your physic models directly in the editor window. The first thing you need to do is to enter edit mode for your .physics file, by double clicking it in the resource tree. Next, click the Test button in the bottom right corner of the screen (in the properties window).

Button 'Test

In test mode, you can enable contact points display. To do this, use the option Show Contacts. In addition, in the editor, there is a Wireframe mode option, which allows you to display the physics models in wireframe.

Wireframe mode testing mode

Objects Creation

There are three types of objects that can be used to build a physics model:

  • Bodies,
  • Joints,
  • Motors.

Bodies

The body is a solid object which can be affected by forces. The body can consist of one or more primitives (Shapes) that are static relatively to each other within the same body. Every body has a mass and is characterized by it's position in space.

Body Creation

There are two ways to create a body: - Enter edit mode, double-click on the file in the resource tree or right-click on it and select Edit in the context menu. In edit mode you have to press the right button in any place of the working window and choose from the pop-up menu Create Body.

Addition of the body.

- The other way is to press the "..." button in the properties window to open the collection editor.

Addition of the body.

This will bring up the (Body Collection Editor), which will allow you to configure the body.

Addition of the body.

Properties of the Bodies

Parameter Description
_General
CCD Enable/disable continuous tracking of collisions (Continuous Collision Detection).
EnableGravity Enable/disable the effects of gravity on the body.
Name Use this parameter to specifiy a unique name for the physical body, which allows it to be uniquely identified among the other bodies.
Shapes List of primitives of the body. Using the "..." button, you can configure the primitives. Working with primitives and their properties are explained below.
Sleepiness Sensitivity threshold of a body below which it falls into "sleeping" state. In sleeping state, the body completely is not movable and doesn't required physics calculation time.
Static Enable/disable the static state of the object. If this option is enabled, then the object can't be affected by any force. It cannot be moved.
Damping
AngularDamping Coefficient of attenuation of angular speed. The higher the value, the faster the angular speed of a body will fade.
LinearDamping The attenuation of the linear velocity. The higher the value, the faster the attenuation.

Note: physical model damping is not associated with friction, as the attenuation occurs regardless of interactions with external bodies.

Mass
CenterOfMassAuto Enable/disable automatic calculation of the mass center. This parameter is only used in PhysX.
Mass Total mass of the primitives that constitutes the body. See MassMethod parameter to configure the method of weight calculation..
MassMethod Method of calculating the mass of the object. It is proposed to choose between the calculation through the mass density (ByDensity) or manually (Manually). See the Density parameter of the primitives.
PhysX
PhysX_SolverPositionIterations The iterations number of physics engine operations to calculate changes of body position. It is used only in PhysX.
PhysX_SolverVelocityIterations The iterations number of physics engine operations to calculate the velocity change of the body. It is used only in PhysX.
Transform
CenterOfMassPosition The center of mass position of the body.
CenterOfMassRotation The center of mass rotation of the body.
IntertiaTensorFactor Multiplier to calculate the inertia tensor of the body. It is used only in PhysX.
Position The coordinates of the body in this physical model.
Rotation Rotation of the body in this physical model.

Adding Primitivest to the Body

A quick way to add a primitive (shape) to the body is to select the body, right-click in any area of the working window and select the type of shape you want to add in the pop-up menu.

Adding primitives to the body.

Another way to add a primitive is to use the shape collection editor. To open it, click "..." in front of Shapes in the properties window.

Adding primitives to the body.
Adding primitives to the body.

Use the Add button to create a new primitive and select it's type. The following types of primitives are available:

  • The Parallelepiped (BoxShape),
  • Sphere (SphereShape),
  • Capsule (CapsuleShape),
  • Mesh (MeshShape).

To create a primitive that match the 3D model well, you need to choose the MeshShape type of primitive and specify the 3d model file via the MeshName parameter in its properties. The more detailed the 3D model is, the more CPU time is required for physics calculations. In some cases, a good solution is to use low-detailed version of the mesh as a physical model.

Primitives Parameters

General parameters for all the primitives types:

Parameter Description
General
Contact Enable/disable contacts with other primitives. If the option is disabled, the primitive will penetrate other objects.
Name The name of the primitive.
ShapeType A primitive type (not editable). Can have one of the following values: Box, Sphere, Capsule or Mesh.
Material
Density Density.
DynamicFriction The friction coefficient when colliding bodies are moving relatively one to each others. The range of values is from 0 to 1. The higher the value, the higher the friction force.
Hardness Hardness. Determines the energy absorption of the material in the collision. Values range from 0 to 1. The higher the value, the higher the hardness of the object (the less energy absorption).
MaterialName The name of the material. This Option allows you to select one of the predefined materials. Available materials: Metal, Wood, Rubber, Ice, Snow, Grass, Dirt, Tamac and the default material. Material settings are in the file"Data\Definitions\PhysicsSystem.config". You can add new materials by editing the file.
Restitution The coefficient of elasticity of the primitive. Valid values range from "'0"' to "'1"'. The higher the value, the more elastic is the object.
StaticFriction The coefficient of friction when colliding bodies are static relative to each other. Values range from 0 to 1. The higher the value, the higher the friction force.
Special
SpecialLiquidDensity Density in the water. The parameter is used when the object is interacting with water surface.
VehicleDrivableSurface Enable/disable the ability to drive a car on this primitive
Transform
Position Position of the primitive relative to the center of the physical body.
Rotation Rotation of the primitive relative to the center of the physical body.
Parameters of a Parallelepiped
Parallelepiped
Parameter Description
Box
Dimensions Dimensions. Specifies the size of the box.
Parameters of Sphere
Sphere
Parameter Description
Sphere
Radius Radius of the sphere.
Parameters of the Capsule
Capsule
Parameter Description
Capsule
Length Length of the capsule.
Radius The rounding radius of the capsule.
Parameters of the Mesh
Convex hull

Special mesh parameters are divided into two categories: the mesh parameters (Mesh) and the convex hull splitting settings (ConvexHullDecomposition). The breaking of the mesh into convex hull simplifies the calculation of the physical model.

Parameter Description
ConvexHullDecomposition
ConvexHullDecompositionMaxTriangles The maximum total number of triangles in the convex hull. Specifies the number of triangles, which will be used to create the convex hulls representation of the mesh. Parameter is only used with the mesh as ConvexHullDecomposition.
ConvexHullDeoompositionMaxVerticesPerConvexHull The maximum number of vertices in each convex hull. Specifies the number of vertices, which will be used to create the convex hull of the mesh. Parameter is only used with the mesh as ConvexHullDecomposition.
Mesh
MeshName The 3D model file.
MeshScale Scale of the mesh.
MeshType Type of the mesh. You can choose between TriangleMesh (mesh), ConvexHull (convex hull) and ConvexHullDecomposition (convex hull decomposition).TriangleMesh type can only be used for static objects. For dynamic objects, you need to use ConvexHull or ConvexHullDecomposition. In the latter case, the mesh will be automatically divided into a set of convex hulls.

Joints

Joints are used to connect two bodies.

Joints between the bodies.

Creating a Joint

To create a joint you need to choose two connected bodies, then press the right mouse button in the workspace window and choose the type of articulation in the context menu. You can use the Shift button to select two or more bodies.

Adding of a joint between two bodies.

Types of Joints

Type of joint Description Example
Hinge Joint The bodies are connected with one degree of freedom of rotation. The distance between each of the two bodies and the center of the joint is fixed.
PhysicsModelEditor 016.jpg
Universal Joint The bodies are connected with two degree of freedom of rotation. The distance between each of the two bodies and the center of the joint is fixed.
PhysicsModelEditor 017.jpg
Ball Joint The bodies are connected with three degree of freedom of rotation. The distance between each of the two bodies and the center of the joint is fixed.
PhysicsModelEditor 018.jpg
Slider Joint The bodies can move relative to each other along one axis, without rotation
PhysicsModelEditor 019.jpg
Hinge2 Joint This type of joint is supported only in ODE physics engine and requires that both bodies are not static.

It also works as a universal joint, with the difference in the orientation of the same axis. Two degree of freedom of rotation.

PhysicsModelEditor 020.jpg
Fixed Joint Does not allow the bodies to rotate or move relative to each other.
PhysicsModelEditor 021.jpg

Joints Parameters

All the joints types share the same set of parameters except the axes to configure the joint.

Parameters of the joints
Parameter Description
Break
BreakMaxForce The force needed to break the joint. Defines the maximum force the joint can handle before breaking. A value of 0 means the joint is indestructible.
BreakMaxTorque Torque moment of the break. Defines the maximum torque moment the joint can handle before breaking. A value of 0 means the joint is indestructible.
General
Anchor Anchor. The position of a joint in the space that is specified by three coordinates.
Axis1 The first axis.
Axis2 The second axis.
Body1 The first body involved in the joint. The parameter can't be edited.
Body2 The second body involved in the joint. The parameter can't be edited.
ContactsEnabled Enable/disable contacts between the bodies connected by this joint.
Name Unique name for this joint.

Parameter of the axis:

Parameter Description
Direction The direction of the axis. Specifies the direction vector for the axis. Values range from 0 to 1 for X, Y or Z. if you enter an invalid parameter (for example: 1 0 1), the editor will inform you about it at the start of the simulation.
LimitHigh Upper limit of the rotation axis. Limits the maximum rotation angle on this axis.
LimitLow Lower limit of the rotation axis. Limits the minimum rotation angle on this axis.

Note: the Upper limit must exceed the lower. Note: these values will only work if the flag LimitsEnabled is set to True.

LimitsDamping Damping coefficient of elasticity of the axis limits. Only in the case when the coefficient of elasticity (LimitsSpring) is more than 0.
LimitsEnabled Enable/disable limits for the axis. If set to True, then the upper and lower limits for the axis will be considered. If set to False, then LimitHigh and LimitLow parameters are ignored.
LimitsRestitution Determines the rates of impact of the upper or lower limit of bending axis. If the value is 1, then the body bounces back from the limit, keeping its speed. If the value is 0, the body stops tightly.
LimitsSpring Specifies the coefficient of elasticity. If the value is greater than 0, the boundaries become softer. I.e. the spring returns the body to the limit.

Motors

A Motor — is an object that creates a force on a body. There are three types of motors:

  • Attractor Motor: The motor generates power of attraction between two bodies, forcing them to move towards each other.
  • Geared Motor: This type of motor is created for joint and produces power of torque moment.
  • Servo Motor: This type of motor is created for joint. The engine applies a force of corresponding direction to the body, trying to keep the required rotation angle for the selected joint axis.


Creating the Motor

PhysicsModelEditor 023.jpg

To create an attractor motor, you need to choose two bodies and right click in any area of the working window. Then select Create Attractor Motor from the context menu.

PhysicsModelEditor 024.jpg

To create a geared or servo motor, you need to choose the joint and right click in any area of the working window. Then choose the motor type you want in the context menu.

Each motor has its own set of parameters.

Attractor Motor

Parameters of attractor motor
Parameter Description
General
ApplyForceToBody1 Enable/disable applying the force to the first body.
ApplyForceToBody2 Enable/disable applying the force to the second body.
Body1 The name of the first involved body. The option can't be edited.
Body2 The name of the second involved body. The option can't be edited.
Enabled Enable/disable the motor.
Exponent The attenuation coefficient. The lower the value, the higher the force will be at a given distance.
Name Unique name for this motor.
Strength The force of the motor. The higher the value, the greater the force of interaction between the bodies will be.

Geared Motor

Parameters of the geared motor
Property name Description
General
ApplyForceToBody1 Enable/disable applying the force to the first body.
ApplyForceToBody2 Enable/disable applying the force to the second body.
Enabled Enable/disable the motor.
Joint The name of the joint, attached to the motor. The option can't be edited.
JointAxis The name of the axis, which operates the motor. The option can't be edited.
MaxTorque Maximum torque value that the motor can pass to the joint.
MaxVelocity The maximum speed that the engine can pass to the joint.
Name Unique name of the motor.
Throttle Direction and the starting value of the force. Values range from -1 to 1. 1 means clockwise rotation, -1 — counterclockwise rotation, 0 — absence of active force.

Servo Motor

Parameters of the servo motor
Parameter Description
General
ApplyForceToBody1 Enable/disable applying the force to the first body.
ApplyForceToBody2 Enable/disable applying the force to the second body.
Enabled Enable/disable the motor.
Joint The name of the joints, attached to the motor. The option can't be edited.
JointAxis The name of the axis, which operates the motor. The option can't be edited.
Name Unique name of the motor.
Servo
DesiredAngle The angle at which the motor tries to turn the body. When the desired angle is reached, required force will be applied to keep the body in this position.
MaxTorque Maximum value of the torque that the motor can pass to the joint.
MaxVelocity The maximum speed that the engine can pass to the joint.
ThresholdAcceleration Acceleration limit, which requires speed reduction.

Creating and editing .physics file

In this example, we will create a new .physics file with a hammer hitting a ball.

To create the new .physics file, press the right mouse button on the folder in which we want to place the physic model. In the context menu, select New, then select Physics Model.

Creation of a new .physics file.

In the new physics model window, type the name of the physics model and click Next.

Creation of a new .physics file.

In the resources window, go into edit mode by double-clicking on the created file.

New physics model.

The created model contains a body with a box type primitive. You can leave it or delete it. We will start with an empty model in this tutorial. First, we need to create a flat surface with a box type primitve (see Creation of the bodies).

It is convenient to edit the size of the primitive using the scale transformation tool. 

Change the value of the parameter Static to True, to make the body static (ie: so it will not fall).

Basis for a physics model.

Now let's create a new body with a sphere primitive and place it directly above the plane.

Ball on the plane.

Configure the sphere's settings as shown on the following screenshot:

PhysicsModelEditor 033.jpg

Next, place a static body on existing objects. Let this be a Box with the Static option selected.

Static Box above the objects.

Next, create another body with two Box primitives, and make them the shape of a simple hammer. Change the density of each of the primitives in the hammer body for a value of 1000.

Hammer.

Choose the two recently created bodies and connect them using a Hinge Joint — joint with one degree of freedom. In addition, we need to rotate and move the hammer, so it can hit the ball when it will fall. You can select the two bodies by clicking on them with the left mouse button while pressing Shift.

Hammer and joint.

You can now run test mode, to see how the hammer will fall, and gathering speed, strike the ball.

Hammer strikes the ball.

You can see more examples of physics models in the "Data\_ResourceEditorSamples\Physics" folder.

Editor Configuration

To configure the physics editor, you need to click the Options button on the toolbar or select Options' in the Tools tab of the main menu. Then select the Physics Model tab in the settings window that appears.

Physics editor configuration
Parameter Description
General
Background Color Background color of the working window. The background color is visible if a Sky Box is not used.
Grid Height The height of the grid in the space (Y-coordinate of the grid).
Show Axes Enable/disable the display of the coordinate axes. Useful for positioning objects in space.
Show Grid Enable/disable displaying the grid. The grid is useful to scale. In the case of the physics editor, the grid is also acting as the floor that prevent objects from falling.
Sky Box Skybox (sky), displayed on the background of the editor.