Obi  6.4
Unified particle physics for Unity
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Events Pages
Obi.ObiActor Class Reference
Inheritance diagram for Obi.ObiActor:
Obi.IObiParticleCollection Obi.ObiBone Obi.ObiClothBase Obi.ObiEmitter Obi.ObiPlant Obi.ObiPlant Obi.ObiRopeBase Obi.ObiSoftbody Obi.ObiCloth Obi.ObiSkinnedCloth Obi.ObiTearableCloth Obi.ObiRod Obi.ObiRope

Classes

class  ObiActorSolverArgs
 

Public Member Functions

delegate void ActorCallback (ObiActor actor)
 
delegate void ActorStepCallback (ObiActor actor, float stepTime)
 
delegate void ActorBlueprintCallback (ObiActor actor, ObiActorBlueprint blueprint)
 
void AddToSolver ()
 Adds this actor to its solver, if any. Automatically called by ObiSolver. More...
 
void RemoveFromSolver ()
 Remove this actor from its solver, if any. Automatically called by ObiSolver. More...
 
virtual bool CopyParticle (int actorSourceIndex, int actorDestIndex)
 Copies all data (position, velocity, phase, etc) from one particle to another one. More...
 
void TeleportParticle (int actorIndex, Vector3 position)
 Teleports one actor particle to a certain position in solver space. More...
 
virtual void Teleport (Vector3 position, Quaternion rotation)
 Teleports the entire actor to a new location / orientation. More...
 
bool ActivateParticle (int actorIndex)
 Activates one particle. More...
 
bool DeactivateParticle (int actorIndex)
 Deactivates one particle. More...
 
bool IsParticleActive (int actorIndex)
 Returns whether a given particle is active. More...
 
virtual void SetSelfCollisions (bool selfCollisions)
 Updates particle phases in the solver at runtime, including or removing the self-collision flag. More...
 
virtual void SetOneSided (bool oneSided)
 Updates particle phases in the solver at runtime, including or removing the one-sided flag. More...
 
void SetSimplicesDirty ()
 Marks simplices dirty. More...
 
void SetConstraintsDirty (Oni.ConstraintType constraintType)
 Marks a given constraint type as dirty. More...
 
IObiConstraints GetConstraintsByType (Oni.ConstraintType type)
 Returns the data representation of constraints of a given type being simulated by this solver. More...
 
virtual void UpdateParticleProperties ()
 Call when some particle properties have been modified and need updating. More...
 
int GetParticleRuntimeIndex (int actorIndex)
 Returns the index of this particle in the solver arrays. More...
 
Vector3 GetParticlePosition (int solverIndex)
 Given a solver particle index, returns the position of that particle in world space. More...
 
Quaternion GetParticleOrientation (int solverIndex)
 Given a solver particle index, returns the orientation of that particle in world space. More...
 
void GetParticleAnisotropy (int solverIndex, ref Vector4 b1, ref Vector4 b2, ref Vector4 b3)
 Given a solver particle index, returns the anisotropic frame of that particle in world space. More...
 
float GetParticleMaxRadius (int solverIndex)
 Given a solver particle index, returns the maximum world space radius of that particle, in any axis. More...
 
Color GetParticleColor (int solverIndex)
 Given a solver particle index, returns the color of that particle. More...
 
void SetFilterCategory (int newCategory)
 Sets a given category value for all particles in the actor. More...
 
void SetFilterMask (int newMask)
 Sets a given mask value for all particles in the actor. More...
 
void SetMass (float mass)
 Sets the inverse mass of each particle so that the total actor mass matches the one passed by parameter. More...
 
float GetMass (out Vector3 com)
 Returns the actor's mass (sum of all particle masses), and the position of its center of mass. More...
 
void AddForce (Vector3 force, ForceMode forceMode)
 Adds an external force to all particles in the actor. More...
 
void AddTorque (Vector3 force, ForceMode forceMode)
 Adds a torque to the actor. More...
 
void ResetParticles ()
 Resets the position and velocity of all particles, to the values stored in the blueprint. More...
 
void SaveStateToBlueprint (ObiActorBlueprint bp)
 Resets the position and velocity of all particles, to the values stored in the blueprint. More...
 
void ClearState ()
 
virtual void LoadBlueprint (ObiSolver solver)
 Loads this actor's blueprint into a given solver. Automatically called by ObiSolver. More...
 
virtual void UnloadBlueprint (ObiSolver solver)
 Unloads this actor's blueprint from a given solver. Automatically called by ObiSolver. More...
 
virtual void PrepareFrame ()
 
virtual void PrepareStep (float stepTime)
 
virtual void BeginStep (float stepTime)
 
virtual void Substep (float substepTime)
 
virtual void EndStep (float substepTime)
 
virtual void Interpolate ()
 
virtual void OnSolverVisibilityChanged (bool visible)
 

Public Attributes

int[] solverIndices
 Index of each one of the actor's particles in the solver. More...
 
List< int >[] solverBatchOffsets
 For each of the actor's constraint types, offset of every batch in the solver. More...
 

Protected Member Functions

virtual void Awake ()
 
virtual void OnDestroy ()
 
virtual void OnEnable ()
 
virtual void OnDisable ()
 
virtual void OnValidate ()
 
void SetSolver (ObiSolver newSolver)
 Forcibly changed the solver in charge of this actor More...
 
virtual void OnBlueprintRegenerate (ObiActorBlueprint blueprint)
 
void UpdateCollisionMaterials ()
 
virtual void SwapWithFirstInactiveParticle (int actorIndex)
 
void StoreState ()
 

Protected Attributes

int m_ActiveParticleCount = 0
 
ObiSolver m_Solver
 
bool m_Loaded = false
 
ObiCollisionMaterial m_CollisionMaterial
 
bool m_SurfaceCollisions = false
 

Properties

ObiSolver solver [get]
 The solver in charge of simulating this actor. More...
 
bool isLoaded [get]
 True if the actor blueprint has been loaded into a solver. If true, it guarantees actor.solver, actor.solverIndices and actor.solverBatchOffsets won't be null. More...
 
ObiCollisionMaterial collisionMaterial [get, set]
 The collision material being used by this actor. More...
 
virtual bool surfaceCollisions [get, set]
 Whether to use simplices (triangles, edges) for contact generation. More...
 
int particleCount [get]
 Amount of particles allocated by this actor. More...
 
int activeParticleCount [get]
 Amount of particles in use by this actor. More...
 
bool usesOrientedParticles [get]
 Whether this actors makes use of particle orientations or not. More...
 
virtual bool usesAnisotropicParticles [get]
 If true, it means particles may not be completely spherical, but ellipsoidal. More...
 
virtual bool usesCustomExternalForces [get]
 If true, it means external forces aren't applied to the particles directly. More...
 
Matrix4x4 actorLocalToSolverMatrix [get]
 Matrix that transforms from the actor's local space to the solver's local space. More...
 
Matrix4x4 actorSolverToLocalMatrix [get]
 Matrix that transforms from the solver's local space to the actor's local space. More...
 
abstract ObiActorBlueprint sourceBlueprint [get]
 Reference to the blueprint asset used by this actor. More...
 
ObiActorBlueprint sharedBlueprint [get]
 Reference to the blueprint in use by this actor. More...
 
ObiActorBlueprint blueprint [get]
 Returns a unique instance of this actor's sourceBlueprint. More...
 
- Properties inherited from Obi.IObiParticleCollection
int particleCount [get]
 
int activeParticleCount [get]
 
bool usesOrientedParticles [get]
 

Events

ActorBlueprintCallback OnBlueprintLoaded
 Called when the actor blueprint has been loaded into the solver. More...
 
ActorBlueprintCallback OnBlueprintUnloaded
 Called when the actor blueprint has been unloaded from the solver. More...
 
ActorCallback OnPrepareFrame
 Called at the start of the solver's FixedUpdate (for Fixed and LateFixed updaters) or the solver's Update (for Late updaters) More...
 
ActorStepCallback OnPrepareStep
 Called at the beginning of a time step, before dirty constraints and active particles have been updated. More...
 
ActorStepCallback OnBeginStep
 Called at the beginning of a time step, after dirty constraints and active particles have been updated. More...
 
ActorStepCallback OnSubstep
 Called at the beginning of each substep. More...
 
ActorStepCallback OnEndStep
 Called at the end of a timestep, after external forces have been reset and collision callbacks called. More...
 
ActorCallback OnInterpolate
 Called at the end of each frame. More...
 

Detailed Description

Represents a group of related particles. ObiActor does not make any assumptions about the relationship between these particles, except that they get allocated and released together.

Member Function Documentation

bool Obi.ObiActor.ActivateParticle ( int  actorIndex)

Activates one particle.

Parameters
actorIndexIndex in the actor arrays of the particle we will activate.
Returns
True if the particle was inactive. False if the particle was already active.

This operation preserves the relative order of all particles.

void Obi.ObiActor.AddForce ( Vector3  force,
ForceMode  forceMode 
)

Adds an external force to all particles in the actor.

Parameters
forceValue expressed in solver space.
forceModeType of "force" applied.
void Obi.ObiActor.AddTorque ( Vector3  force,
ForceMode  forceMode 
)

Adds a torque to the actor.

Parameters
forceValue expressed in solver space.
forceModeType of "torque" applied.
void Obi.ObiActor.AddToSolver ( )

Adds this actor to its solver, if any. Automatically called by ObiSolver.

virtual bool Obi.ObiActor.CopyParticle ( int  actorSourceIndex,
int  actorDestIndex 
)
virtual

Copies all data (position, velocity, phase, etc) from one particle to another one.

Parameters
actorSourceIndexIndex in the actor arrays of the particle we will copy data from.
actorDestIndexIndex in the actor arrays of the particle we will copy data to.
Returns
Whether the indices passed are within actor bounds.

Extend this method to implement copying your own custom particle data in custom actors.

bool Obi.ObiActor.DeactivateParticle ( int  actorIndex)

Deactivates one particle.

Parameters
actorIndexIndex in the actor arrays of the particle we will deactivate.
Returns
True if the particle was active. False if the particle was already inactive.

This operation does not preserve the relative order of other particles, because the last active particle will swap positions with the particle being deactivated.

IObiConstraints Obi.ObiActor.GetConstraintsByType ( Oni.ConstraintType  type)

Returns the data representation of constraints of a given type being simulated by this solver.

Parameters
typeType of the constraints that will be returned by this method.
Returns
The runtime constraints of the type speficied. Most constraints are stored in the blueprint, with a couple notable exceptions: pin and stitch constraints are always created at runtime, so they're not stored in the blueprint but in the actor itself.
float Obi.ObiActor.GetMass ( out Vector3  com)

Returns the actor's mass (sum of all particle masses), and the position of its center of mass.

Parameters
comThe actor's center of mass, expressed in solver space.

Particles with infinite mass (invMass = 0) are ignored.

void Obi.ObiActor.GetParticleAnisotropy ( int  solverIndex,
ref Vector4  b1,
ref Vector4  b2,
ref Vector4  b3 
)

Given a solver particle index, returns the anisotropic frame of that particle in world space.

Parameters
solverIndexIndex of the particle in the solver arrays.
solverIndexFirst basis vector of the frame. Contains particle radius along this axis in the 4th position.
solverIndexSecond basis vector of the frame. Contains particle radius along this axis in the 4th position..
solverIndexThird basis vector of the frame. Contains particle radius along this axis in the 4th position.

Implements Obi.IObiParticleCollection.

Color Obi.ObiActor.GetParticleColor ( int  solverIndex)

Given a solver particle index, returns the color of that particle.

Parameters
solverIndexIndex of the particle in the solver arrays.
Returns
The color of the particle.

Implements Obi.IObiParticleCollection.

float Obi.ObiActor.GetParticleMaxRadius ( int  solverIndex)

Given a solver particle index, returns the maximum world space radius of that particle, in any axis.

Parameters
solverIndexIndex of the particle in the solver arrays.
Returns
The maximum radius of a given particle in world space.

Implements Obi.IObiParticleCollection.

Quaternion Obi.ObiActor.GetParticleOrientation ( int  solverIndex)

Given a solver particle index, returns the orientation of that particle in world space.

Parameters
solverIndexIndex of the particle in the solver arrays.
Returns
The orientation of a given particle in world space.

Implements Obi.IObiParticleCollection.

Vector3 Obi.ObiActor.GetParticlePosition ( int  solverIndex)

Given a solver particle index, returns the position of that particle in world space.

Parameters
solverIndexIndex of the particle in the solver arrays.
Returns
The position of a given particle in world space.

Implements Obi.IObiParticleCollection.

int Obi.ObiActor.GetParticleRuntimeIndex ( int  actorIndex)

Returns the index of this particle in the solver arrays.

Parameters
actorIndexIndex of the particle in the actor arrays.
Returns
The index of a given particle in the solver arrays.

At runtime when the blueprint is loaded, this is the same as calling actor.solverIndices[solverIndex]. If the blueprint is not loaded it will return the same index passed to it: actorIndex. Note that this function does not perform any range checking.

Implements Obi.IObiParticleCollection.

bool Obi.ObiActor.IsParticleActive ( int  actorIndex)

Returns whether a given particle is active.

Parameters
actorIndexIndex in the actor arrays of the particle.
Returns
True if the particle is active. False if the particle is inactive.
virtual void Obi.ObiActor.LoadBlueprint ( ObiSolver  solver)
virtual

Loads this actor's blueprint into a given solver. Automatically called by ObiSolver.

Reimplemented in Obi.ObiBone, Obi.ObiRod, Obi.ObiRope, Obi.ObiClothBase, Obi.ObiSoftbody, Obi.ObiEmitter, Obi.ObiSkinnedCloth, and Obi.ObiTearableCloth.

void Obi.ObiActor.RemoveFromSolver ( )

Remove this actor from its solver, if any. Automatically called by ObiSolver.

void Obi.ObiActor.ResetParticles ( )

Resets the position and velocity of all particles, to the values stored in the blueprint.

Note however that this does not affect constraints, so if you've torn a cloth/rope or resized a rope, calling ResetParticles won't restore the initial topology of the actor.

void Obi.ObiActor.SaveStateToBlueprint ( ObiActorBlueprint  bp)

Resets the position and velocity of all particles, to the values stored in the blueprint.

Parameters
bpThe blueprint that we want to fill with current particle data.

Note that this will not resize the blueprint's data arrays, and that it does not perform range checking. For this reason, you must supply a blueprint large enough to store all particles' data.

void Obi.ObiActor.SetConstraintsDirty ( Oni.ConstraintType  constraintType)

Marks a given constraint type as dirty.

Parameters
constraintTypeType of the constraints that need re-creation.

This will cause the solver to perform a constraint re-creation at the start of the next step. Needed when the constraint data in an actor changes at runtime, as a result of changing topology (torn cloth or ropes), or changes in internal constraint parameters such as compliance values. This is a relatively expensive operation, so it's best to amortize as many constraint modification operations as possible in a single step.

void Obi.ObiActor.SetFilterCategory ( int  newCategory)

Sets a given category value for all particles in the actor.

Parameters
newCategoryCategory value.
void Obi.ObiActor.SetFilterMask ( int  newMask)

Sets a given mask value for all particles in the actor.

Parameters
newMaskMask value.
void Obi.ObiActor.SetMass ( float  mass)

Sets the inverse mass of each particle so that the total actor mass matches the one passed by parameter.

Parameters
massThe actor's total mass.
virtual void Obi.ObiActor.SetOneSided ( bool  oneSided)
virtual

Updates particle phases in the solver at runtime, including or removing the one-sided flag.

virtual void Obi.ObiActor.SetSelfCollisions ( bool  selfCollisions)
virtual

Updates particle phases in the solver at runtime, including or removing the self-collision flag.

Reimplemented in Obi.ObiEmitter.

void Obi.ObiActor.SetSimplicesDirty ( )

Marks simplices dirty.

void Obi.ObiActor.SetSolver ( ObiSolver  newSolver)
protected

Forcibly changed the solver in charge of this actor

Parameters
newSolverThe solver we want to put in charge of this actor.

First it removes the actor from its current solver, then changes the actor's current solver and then readds it to this new solver.

virtual void Obi.ObiActor.Teleport ( Vector3  position,
Quaternion  rotation 
)
virtual

Teleports the entire actor to a new location / orientation.

Parameters
positionWorld space position to teleport the actor to.
rotationWorld space rotation to teleport the actor to.

Reimplemented in Obi.ObiSoftbody.

void Obi.ObiActor.TeleportParticle ( int  actorIndex,
Vector3  position 
)

Teleports one actor particle to a certain position in solver space.

Parameters
actorIndexIndex in the actor arrays of the particle we will teeleport.
positionPosition to teleport the particle to, expressed in solver space.
virtual void Obi.ObiActor.UnloadBlueprint ( ObiSolver  solver)
virtual

Unloads this actor's blueprint from a given solver. Automatically called by ObiSolver.

Reimplemented in Obi.ObiBone, Obi.ObiClothBase, Obi.ObiRope, and Obi.ObiTearableCloth.

virtual void Obi.ObiActor.UpdateParticleProperties ( )
virtual

Call when some particle properties have been modified and need updating.

Does not do anything by default. Call when manually modifying particle properties in the solver, should the actor need to do some book keeping. For softbodies, updates their rest state.

Reimplemented in Obi.ObiSoftbody.

Member Data Documentation

List<int> [] Obi.ObiActor.solverBatchOffsets

For each of the actor's constraint types, offset of every batch in the solver.

int [] Obi.ObiActor.solverIndices

Index of each one of the actor's particles in the solver.

Property Documentation

int Obi.ObiActor.activeParticleCount
get

Amount of particles in use by this actor.

This will always be equal to or smaller than particleCount.

Matrix4x4 Obi.ObiActor.actorLocalToSolverMatrix
get

Matrix that transforms from the actor's local space to the solver's local space.

If there's no solver present, this is the same as the actor's local to world matrix.

Matrix4x4 Obi.ObiActor.actorSolverToLocalMatrix
get

Matrix that transforms from the solver's local space to the actor's local space.

If there's no solver present, this is the same as the actor's world to local matrix. This is always the same as the inverse of actorLocalToSolverMatrix.

ObiActorBlueprint Obi.ObiActor.blueprint
get

Returns a unique instance of this actor's sourceBlueprint.

This is mostly used when the actor needs to change some blueprint data at runtime, and you don't want to change the blueprint asset as this would affect all other actors using it. Tearable cloth and ropes make use of this.

ObiCollisionMaterial Obi.ObiActor.collisionMaterial
getset

The collision material being used by this actor.

bool Obi.ObiActor.isLoaded
get

True if the actor blueprint has been loaded into a solver. If true, it guarantees actor.solver, actor.solverIndices and actor.solverBatchOffsets won't be null.

int Obi.ObiActor.particleCount
get

Amount of particles allocated by this actor.

ObiActorBlueprint Obi.ObiActor.sharedBlueprint
get

Reference to the blueprint in use by this actor.

If you haven't called blueprint before, this will be the same as sourceBlueprint. If you have called blueprint before, it will be the same as blueprint.

ObiSolver Obi.ObiActor.solver
get

The solver in charge of simulating this actor.

This is the first ObiSlver component found up the actor's hierarchy.

abstract ObiActorBlueprint Obi.ObiActor.sourceBlueprint
get

Reference to the blueprint asset used by this actor.

virtual bool Obi.ObiActor.surfaceCollisions
getset

Whether to use simplices (triangles, edges) for contact generation.

virtual bool Obi.ObiActor.usesAnisotropicParticles
get

If true, it means particles may not be completely spherical, but ellipsoidal.

virtual bool Obi.ObiActor.usesCustomExternalForces
get

If true, it means external forces aren't applied to the particles directly.

For instance, cloth uses aerodynamic constraints to do so, and fluid uses drag.

bool Obi.ObiActor.usesOrientedParticles
get

Whether this actors makes use of particle orientations or not.

Event Documentation

ActorStepCallback Obi.ObiActor.OnBeginStep

Called at the beginning of a time step, after dirty constraints and active particles have been updated.

ActorBlueprintCallback Obi.ObiActor.OnBlueprintLoaded

Called when the actor blueprint has been loaded into the solver.

ActorBlueprintCallback Obi.ObiActor.OnBlueprintUnloaded

Called when the actor blueprint has been unloaded from the solver.

ActorStepCallback Obi.ObiActor.OnEndStep

Called at the end of a timestep, after external forces have been reset and collision callbacks called.

ActorCallback Obi.ObiActor.OnInterpolate

Called at the end of each frame.

ActorCallback Obi.ObiActor.OnPrepareFrame

Called at the start of the solver's FixedUpdate (for Fixed and LateFixed updaters) or the solver's Update (for Late updaters)

ActorStepCallback Obi.ObiActor.OnPrepareStep

Called at the beginning of a time step, before dirty constraints and active particles have been updated.

ActorStepCallback Obi.ObiActor.OnSubstep

Called at the beginning of each substep.


The documentation for this class was generated from the following file: