Unigine.BodyFracture Class
Inherits from: | Body |
This class is used to simulate destructable fracture bodies.
New surfces that are created when fracturing occurs are assigned their own material and properties.
Fracture body is, per se, a rigid body and moves according to the rigid bodies dynamics.
Shattering Example#
Shattering is a fracture pattern randomly dividing the mesh volume into the specified number of convex chunks.
public class Shattering : Component
{
// declare a parameter that specifies an object to be shattered
[ShowInEditor]
[Parameter(Tooltip = "Object to be shattered")]
private ObjectMeshDynamic dynamicObject = null;
// declare a parameter that specifies a material to be applied to the shattered pieces
[ShowInEditor]
[Parameter(Tooltip = "Shattered object material")]
private Material shatteredObjectMaterial = null;
// a fracture body for the object to be shattered
BodyFracture bf;
private void Init()
{
// create a fracture body for the object to be shattered
bf = new BodyFracture(dynamicObject);
// specify the minimum threshold for shattering
bf.Threshold = 0.01f;
// set the material for the shattered pieces
bf.Material = shatteredObjectMaterial;
// break the object into shattered pieces
bf.CreateShatterPieces(2);
// change the broken flag
bf.Broken = true;
}
}
Slicing Example#
Slicing is a fracture pattern separating the mesh volume into two pieces by a plane at a specified point of the body. The slicing angle is determined by a specified normal.
public class Slicing : Component
{
// declare a parameter that specifies an object to be sliced
[ShowInEditor]
[Parameter(Tooltip = "Object to be sliced")]
private ObjectMeshDynamic dynamicObject = null;
// declare a parameter that specifies a material to be applied to the slices
[ShowInEditor]
[Parameter(Tooltip = "Sliced object material")]
private Material slicedObjectMaterial = null;
BodyFracture bf;
private void Init()
{
// create a fracture body for the object to be sliced
bf = new BodyFracture(dynamicObject);
// specify the minimum threshold for slicing
bf.Threshold = 0.01f;
// set the material for the slices
bf.Material = slicedObjectMaterial;
// cut the body at the specified point
Vec3 point = bf.Transform * vec3.ZERO;
bf.CreateSlicePieces(point, vec3.ONE);
// change the broken flag
bf.Broken = true;
}
}
Cracking Example#
Cracking is a fracture pattern involving formation of radial cracks from the point of collision.
public class Cracking : Component
{
// declare a parameter that specifies an object to be cracked
[ShowInEditor]
[Parameter(Tooltip = "Object to be cracked")]
private ObjectMeshDynamic dynamicObject = null;
// declare a parameter that specifies a material to be applied to the pieces
[ShowInEditor]
[Parameter(Tooltip = "Cracked object material")]
private Material crackedObjectMaterial = null;
BodyFracture bf;
private void Init()
{
// create a fracture body for the object to be cracked
bf = new BodyFracture(dynamicObject);
// specify the minimum threshold for cracking
bf.Threshold = 0.01f;
// set the material for the pieces
bf.Material = crackedObjectMaterial;
// crack the body at the specified point
Vec3 point = bf.Transform * vec3.ZERO;
bf.CreateCrackPieces(point, vec3.ONE, 7,3,0.1f);
// change the broken flag
bf.Broken = true;
}
}
See Also#
- A set of UnigineScript API samples located in the <UnigineSDK>/data/samples/physics/ folder:
- fracture_00
- fracture_01
- fracture_02
- fracture_03
- fracture_04
- fracture_05
- fracture_06
BodyFracture Class
Properties
bool Broken#
int CollisionMask#
float Density#
float Error#
int ExclusionMask#
float Friction#
float Threshold#
float Restitution#
int PhysicsIntersectionMask#
float MaxAngularVelocity#
float MaxLinearVelocity#
float FrozenAngularVelocity#
float FrozenLinearVelocity#
float Mass#
BodyRigid BodyRigid#
float LinearDamping#
float AngularDamping#
Material Material#
string SurfaceProperty#
UGUID MaterialGUID#
string MaterialFilePath#
Members
BodyFracture ( ) #
Constructor. Creates a fracture body with default properties.BodyFracture ( Object object ) #
Constructor. Creates a fracture body with default properties for a given object.Arguments
- Object object - Object represented with the new fracture body.
vec3 GetVelocity ( vec3 radius ) #
Returns the total linear velocity in the point determined by a given radius vector, specified in the local coordinates.Arguments
- vec3 radius - Radius vector starting in the body's center of mass.
Return value
Total linear velocity in the given point.vec3 GetWorldVelocity ( vec3 point ) #
Returns the total linear velocity in the point specified in world coordinates.Arguments
- vec3 point - Point of the body in world coordinates.
Return value
Total linear velocity in the given point.void AddForce ( vec3 force ) #
Applies a force to the center of mass of the body.
Unlike impulses, all forces are accumulated first, then the resulting force is calculated and applied to the body (during the physics simulation stage, when the body update() function is called).
Arguments
- vec3 force - Force to be applied, in world coordinates.
void AddForce ( vec3 radius, vec3 force ) #
Applies a force to a point determined by a given radius vector, specified in the local coordinates. This function calculates the cross product of the radius vector and the force vector. It acts like a lever arm that changes both linear and angular velocities of the body.
Unlike impulses, all forces are accumulated first, then the resulting force is calculated and applied to the body (during the physics simulation stage, when the body update() function is called).
Arguments
- vec3 radius - Radius vector, traced from the center of mass of the body to the point where the force is applied, in local coordinates.
- vec3 force - Force to be applied, in world coordinates.
void AddImpulse ( vec3 radius, vec3 impulse ) #
Applies an impulse to a point determined by a given radius vector, specified in the local coordinates.
Unlike forces, impulses immediately affect both linear and angular velocities of the body.
Arguments
- vec3 radius - Radius vector, traced from the center of mass to the point where the impulse is applied, in local coordinates.
- vec3 impulse - Impulse to be applied, in world coordinates.
void AddTorque ( vec3 torque ) #
Applies a torque with a pivot point at the center of mass of the body, specified in the local coordinates.
All torque values are accumulated first, then the resulting torque is calculated and applied to the body (during the physics simulation stage, when the body update is called).
Arguments
- vec3 torque - Torque to be applied, in world coordinates.
void AddTorque ( vec3 radius, vec3 torque ) #
Applies a torque with a pivot point, determined by a given radius vector, specified in the local coordinates.
This function calculates the cross product of the radius vector and the force vector.
It acts like a lever arm that changes both angular and linear velocities of the body.
All torque values are accumulated first, then the resulting torque is calculated and applied to the body (during the physics simulation stage, when the body update is called).
Arguments
- vec3 radius - Radius vector starting at the body's center of mass, in local coordinates. Its end is the pivot point for the torque to be applied.
- vec3 torque - Torque to be applied, in world coordinates.
void AddWorldForce ( vec3 point, vec3 force ) #
Applies a force to a given point of the body that is specified in world coordinates. This function calculates the cross product of the radius vector (a vector from the center of mass to the point where force is applied) and the force vector. It acts like a lever arm that changes both linear and angular velocities of the body.
Unlike impulses, all forces are accumulated first, then the resulting force is calculated and applied to the body (during the physics simulation stage, when the body update is called).
Arguments
- vec3 point - Point of the body in world coordinates.
- vec3 force - Force to be applied, in world coordinates.
void AddWorldImpulse ( vec3 point, vec3 impulse ) #
Applies an impulse to a given point of the body, that is specified in world coordinates. Unlike forces, impulses immediately affect both linear and angular velocities of the body.Arguments
- vec3 point - Point of the body in world coordinates.
- vec3 impulse - Impulse to be applied, in world coordinates.
void AddWorldTorque ( vec3 point, vec3 torque ) #
Applies a torque with a pivot point at a given point of the body, that is specified in world coordinates. This function calculates the cross product of the radius vector (a vector from the center of mass to the pivot point) and the torque vector. It acts like a lever arm that changes both angular and linear velocities of the body.
All torque values are accumulated first, then the resulting torque is calculated and applied to the body (during the physics simulation stage, when the body update is called).
Arguments
- vec3 point - Point of the body in world coordinates.
- vec3 torque - Torque to be applied, in world coordinates.
int CreateCrackPieces ( vec3 point, vec3 normal, int num_cuts, int num_rings, float step ) #
Breaks the object into radial cracks combined with concentric splits. If the first concentric split is rendered further than the specified step distance, decrease the volume threshold value.Arguments
- vec3 point - Point of contact.
- vec3 normal - Normal of the contact point.
- int num_cuts - Number of radial cuts that are represented as rays coming from the center of contact point.
- int num_rings - Number of rings that form concentric splits. The number of rings that is will be actually rendered depends on the step value.
- float step - Distance between concentric splits.
Return value
Positive number if the object was successfully broken; otherwise, 0.int CreateShatterPieces ( int num_pieces ) #
Breaks the object into arbitrary shattered pieces.Arguments
- int num_pieces - The number of shattered pieces.