RayFire Rigid

It's main purpose is Advanced Physics Control and Runtime Demolitions. Using Rigid component you can demolish 3d objects into thousands fragments and every fragment can be demolished further deeper and deeper.

Initialization: Defines when object will be initialized. Initialization adds all necessary components to object, setup them accordingly to properties and start necessary coroutines.
https://youtu.be/-wW9OfnhIh0

·	By Method: Object will be initialized by Initialize() method. This is default initialization type. In this way you can add Rigid component to objects in your code and they will not be initialized unless you will Initialize them as well. Object with ByMethod type can be initialized in Editor using Initialize button on top of Rigid component.
·	At Start: Object will be initialized at Start.

Object can be initialized using method:
public void Initialize()
	
	Main

Simulation Type: Defines behavior of object during simulation.
https://youtu.be/KZ8h9F45lkM

·	Dynamic: Object will be affected by gravity, will start fall down and it will be possible to affect on it by other simulated objects. 
·	Sleeping: Object will freeze in air until first collision with any other object, then it will start behave as Dynamic object.
·	Inactive: Object will freeze in air and will not be affected by gravity, it can be affected by other simulated objects but it will not start fall down until it will be activated. After activation object will start behave like Dynamic object.
·	Kinematic: Object will use it's animation to affect to other objects but it will not be affected anyhow by any other object. Can use actual mesh as collider.
·	Static: Object will not be moved from it's position, it will interact with Dynamic objects but it will not be affected anyhow by any other object. Can use actual mesh as collider.

***

Object Type: Rigid component can simulate single object using it's mesh for simulation, but also it can simulate multiple objects as one concave object using all children meshes.
https://youtu.be/fbVG1Y0RoBY

·	Mesh: Simulate object using it's Meshfilter's mesh in Mesh Collider.
·	Mesh Root: Should be added to empty root with children with meshes. Add same Rigid component to all children and simulate them as Mesh type. Root itself is not going to be simulated. Using this type you don't need to select every children to add Rigid components or to edit them later, you only need to edit all properties for Root.
·	Skinned Mesh: Demolishes Skinned mesh object.
·	Nested Cluster: Simulated object using all it's children Meshfilter's meshes as one solid concave object. In this case root will get Mesh Collider for every child with it's mesh. To Create such object you need to add Rigid component to root which has all objects which you want to simulate as solid object as it's children. In case of demolition Cluster will detach every child and start simulate them on their own. If child is also just a root for other children with meshes after demolition it will be considered as Nested Cluster as well. In this way you can demolish object in your own way.
·	Connected Cluster: Simulated object using all it's children Meshfilter's meshes as one solid concave object like Nested Cluster. It uses only children from first layer, nesting is not allowed.  During demolition it will detach fragments at contact point while the rest of the fragments will stay as solid cluster. At every demolition cluster checks itself for connectivity and if it detects that some groups of fragments are not connected together anymore they will start simulate as separate Connected Clusters.

***

Demolition Type: Define when and how object will be demolished during Play mode. 
https://youtu.be/_aO08dcqBOQ

·	None: Object will not be demolished.
·	Runtime: Object will be demolished in Runtime. Fragments will be created at collision contact moment. It is better to use this type for low poly objects with low Fragments Amount value. Slowest speed among other types.
·	Awake Precache: Object will precached all fragments mesh data in Awake and store all mesh data info in Rigid component. At collision contact gameobjects with all necessary components will be created and mesh will be assigned. 
·	Awake Prefragment: Object will be prefragmented in Awake. All fragments will be disabled and waiting for demolition. 
·	Reference Demolition: Allows to swap demolished object to predefined reference and demolish instance of this reference instead. Reference object could be FBX asset, prefab or other scene object.

	Simulation

	Physics
https://youtu.be/MxMaPZLpLto

	Physic Material

Material Type: Material preset with predefined density, friction, elasticity and solidity. Can be edited in Rayfire Man component.

Material: Allows to define define own Physic Material. Keep in mind that it still will use define Material Type for Solidity and Mass.

	Mass

Mass By: Allows to choose the way Mass will be applied to RigidBody component.
·	Material Density: Object will get mass accordingly to defined Material Type and mesh volume.
·	Mass Property: Object will get mass by Mass property
Mass: RigidBody component will get this value if Mass By set to Mass Property.

	Other

Collider Type: Allows to choose automatic collider type for object if object has no custom collider applied.
·	Mesh: Object will get Mesh Collider.
·	Sphere: Object will Sphere Collider.
·	Box: Object will get Box Collider.
·	None: Object will not get automatic collider.

Use Gravity: Object will be affectd by Gravity force. 

	Fragments
Dampening: Decrease velocity of demolished fragments.

	Activation
https://youtu.be/t8JbxKyP91Y

Inactive object can be activated using public method:
public void Activate()

By Velocity: Inactive object will be activated when it's velocity will be higher than By Velocity value when it was pushed by other dynamic objects. Turned Off when set to 0.

By Offset: Inactive object will be activated if will be pushed from it's original position farther than By Offset value. Turned Off when set to 0.

By Damage: Inactive object will be activated if it's Current Damage will be higher than By Damage value. Turned Off when set to 0.

By Activator: Inactive object will be activated by overlapping with object with RayFire Activator component.

By Impact: Inactive object will be activated when it will be shot by RayFire Gun component.

By Connectivity: Inactive object will be activated if it won't be able to reach any Inactive object with Unyielding property On through other Inactive objects. RayFire Connectivity components has to be used to establish connectivity between Inactive objects and activate them if they loose connection with other Inactive objects.

	Connectivity

Unyielding: Allows to define Inactive/Kinematic object as Unyielding to check fo connection with  other Inactive/Kinematic objects with enabled By Connectivity activation type.

Activatable: Unyielding object can not be activate by default. When On allows to activate Unyielding objects as well.
	
	Demolition
Demolition can be initiated using method:
public void DemolishObject()

Slicing by planes can be initiated by method:
public void AddSlicePlane(Vector3[] slicePlane)
Vector3[] slicePlane is array with slicing planes info: 
(plane position, plane normal, plane position, plane normal, etc...)

	Limitations
https://youtu.be/ITYShtaF5cQ

Solidity: Local Object solidity multiplier for object. Low Solidity makes object more fragile. Keep in mind that every Material Type in Physics group also has it's own Solidity. Set to 0 if you want object to be demolished at first contact.

Depth: Defines how deep object can be demolished. Depth is limitless if set to 0.
	Example: Max Depth set to 1, it means that object can be demolished one time and 	new fragments (Depth level 1 fragments) will not be possible to demolish anymore. 
	If Max Depth set to 2, it means that object can be demolished one time and new 	fragments (Depth level 1 fragments) will possible to demolish one time, but new 	fragments (Depth level 2 fragments) will not be possible to demolish anymore. Etc

Time: Safe time. Measures in seconds and allows to prevent fragments from being demolished right after they were just initialized.
	Example: Time set to 3 seconds, it means that object can be demolished and 	new 	fragments will not be demolished for sure during next 3 seconds.

Size: Prevent objects with bounding box size less than defined value to be demolished. Measures in units.

Visible: Prevent object from being demolished if they are not visible by main camera..

Slice by Blade: Allows object to be sliced by object with RayFire Blade component.

	Mesh Demolition
	
	Fragments

https://youtu.be/TpTHstzzvRU

Amount: Defines amount of new fragments after demolition.

Variation: Defines additional amount variation for object in percents. Final amount always will be higher than Amount value.
	Example: Amount set to 50, Variation set to 10 %. Final amount will be randomly picked 	in range from 50 to 55. 

Depth Fade: Amount multiplier for next Depth level. Allows to decrease fragments amount of every next demolition level.
	Example: Amount set to 100. Depth Fade set to 0.5. Object demolishes to 100 	fragments. For every fragment it's Amount for next demolition will be set to 50 (100 * 	0.5). Let's say some fragment demolishes to 50 fragments. For every fragment among 	these 50 fragments it's Amount for next demolition will be set to 25 (50 * 0.5). 

Contact Bias: Higher value allows to create more tiny fragments closer to collision contact point and bigger fragments far from it. This is the property which makes player understand that Runtime demolition happened right now and nothing was prefragmented before.

Seed: Defines Seed for fragmentation algorithm. Same Seed will produce same fragments for same object every time.

Use Shatter: Allows to use RayFire Shatter properties for fragmentation. Works only if object has RayFire Shatter component. This is the only way to create other Fragmentation types in runtime because default demolition fragmentation type produce only regular Voronoi fragments.

	Advanced

Mesh Input: Allows to choose when demolished mesh should be processed for fragmentation. Processing takes about 10% - 15% of total fragmentation time. 
·	At Start: Mesh will be processed at Start.
·	At Initialization: Mesh will be processed at Initialization.
·	At Demolition: Mesh will be processed at Demolition.

	Properties

	Collider

Collider Type: Defines Collider type for mesh fragments if they bounding box size is less than Size Filter value. Useful in case you want to apply simple colliders for a lot of small fragments. 

Size Filter: Defines Bounding Box size value for Collider Type property. Turned Off if set to 0.

	Mesh Ops

Decompose: Decompose output fragment's mesh to several meshes if they are not connected with each other.

Remove Collinear: Remove collinear vertices on output fragment's mesh.

	Custom Layer

Layer: Set custom Layer to fragments.

	Runtime Caching
https://youtu.be/RF-srUHcy0g

Type: Defines Runtime Caching type. Disabled by default.
·	By Frames: Cache fragment's meshes over defined amount of frames.
·	By Fragments per Frame: Cache defined amount of fragment's meshes every frame.

Frames: Defines amount of frames for By Frames type.

Fragments: Defines amount of fragments for By Fragments per Frame type.

Skip First Demolition: Do not demolish object when all meshes were cached and wait for next demolition. Allows to use first Demolition to initiate caching and demolish object only at second demolition.

	Cluster Demolition
https://youtu.be/fNFG4SGWuQQ
https://youtu.be/ZuHq1OFylnM

	Properties

Connectivity: Define the the way connections among Shards will be calculated. 
·	By Bounding Box: Shards will be considered as connected if their bound boxes interpenetrates with each other. This is the fastest way to establish connectivity and can be used in Runtime, but calculated shared are value will not be precise and will be based on shard's size.
·	By Mesh: Shards will be considered as connected if triangle of one Shard fits triangle of neighbor shard. This is the slowest way to establish connectivity and should be used only in Editor with Setup Cluster button, but it precisely calculates shared area value which provides realistic Collapse By Area.
·	By Bounding Box and Mesh: Shards will be considered as connected if their bound boxes interpenetrates with each other. If Shards also share triangles then Shared area will be calculated using By Mesh method, if shards do not share triangles then By Bounding Box method will be used.

	Filters

Filters allows you to decrease amount of connections. There are three filters and they are turned off by default.

Minimum Area: Two shards will have connection if their shared area is bigger than this value.
Minimum Size: Two shards will have connection if their size is bigger than this value.
Percentage: Random percentage of connections will be discarded.
Seed: Seed for random percentage filter and for Random Collapse.

	Demolition Distance

When Connected Cluster collides with something or get Impact from Gun and should be demolished at contact point it has to decided how much Shards should be detached into separate fragments, all Shards in Demolition Distance radius from contact point will be detached. 
Then the rest of the Shards will check for connectivity with each other and if there are several groups of Shards which connected only with each other then such groups will be simulated as separate Connected Clusters.

Type: Defines the way Demolition Distance will be measured. 
·	Ratio To Size: Measured in percentage relative to initial cluster size. 
For instance, if cluster size is 50 units and Ratio To Size value is 20% then Demolition Distance radius will be 10 units and all Shards in 10 Units radius around contact point will be detached from cluster.
·	World Units: Measured in world Units.

Ratio: Percentage value for Demolition Distnace.

Units: World Units value for Demolition Distance.

	Shards

All detached Shards in Demolition Distance area will get RayFire Rigid Component with Mesh object type and will be simulated separately. All such Shards will inherit Mesh Demolition properties from initial Connected Cluster Rigid. But it is possible to clusterize these detached Shards into small Connected Clusters, thanks to this you can create smooth transition between Initial demolished Connected Cluster to separate detached SHards so between them there will be small groups of Connected Clusters. 

Shard Area: Defines percentage relative to Demolition Distance. 
For instance, Cluster size is 50 units, Demolition Distance is 20 units, so all Shards in 20 units radius around contact point will be detached from demolished connected cluster. If Shard Area value is 100% then all Shards will be simulated separately as Rigid with Mesh object type, if Shards Area value is 25% then only Shards in 5 units radius around contact point will be simulated separately and the rest of the Shards from 5 to 20 units radius will be divided into groups and every group will be simulated as small Connected Cluster. Amount of such groups can be defined using Min and Max Amount properties in Cluster section.

Shard Demolition: Set Runtime demolition type for detached Shards with Mesh object type.

	Clusters

Min Amout: Defines minimum amount of Connected Clusters which will be created inside Demolition Distance radius.

Max Amount: Defines maximum amount of Connected Clusters which will be created inside Demolition Distance radius. Final value will be picked randomly between Min and Max range.

Demolishable: Set Runtime demolition type for created Connected Clusters so it will be possible to demolish them as well.

	Collapse

Type: There are three ways to break connections among Shards. You should try in Editor all of them to find the one which looks better for your structure and your goal.  
·	By Area: Shard will loose it's connections if it's shared area surface is less then defined value.
·	By Size: Shard will loose it's connections if it's Size is less then defined value.
·	Random: Shard will loose it's connections if it's random value in range from 0 to 100 is less then defined value.

Start: Defines start value in percentage relative to whole range of picked type. For instance, Type set to By Size, you have 200 shards with the smallest shard size equal to 0.1 unit and biggest shard size equal to 50 units. If you set Start value to 50% it will start collapse by setting By Size threshold value to 25 units and all shards with size less than 25 units will loose their connections. Increase this value if you want to Start Collapse quickly so a lot of shards will loose connections and will be activated right from the beginning. Set it to 0 if you want to start collapse slowly activating shards one by one.

End: Defines end value in percentage relative to whole range of picked type. Set tp 100 if you want to break all connections or set it lower if you want to keep some connections.

Steps: Amount of times when defined threshold value will be set during Duration period. 

Duration: Time which it will take Start value to be increased to End value.

	Reference Demolition
Using Reference Demolition type you can swap demolished object to another Gameobject in scene, Prefab asset, FBX asset or even custom Particle System with your own scripts. This demolition type can be used for fragments which you just created using Shatter component or for FBX asset with fragments which you imported from another 3d package.
If Reference is just one object than at demolition it will be demolished instead of original object. 
If Reference is empty root with children then these children will be simulated as fragments.
It is also possible to keep Reference field empty so original demolished object will disappear without leaving anything instead. 

https://youtu.be/CtY4w16357Q

	Source

Reference: Defines reference for demolition. Reference will be instantiated and demolished instead of original object.

Random List: Allows to define several references and pick for demolition one random.

	Properties

Add Rigid: All references without Rigid Component will get it automatically. Single Object will get Mesh Object Type, Roots with group of mesh objects will get Mesh Root object type.

Inherit Scale: Instantiated reference will inherit original object scale.

	Materials
https://youtu.be/2Aqdzt58xw0

	Inner surface

Inner material: Defines material for fragment's inner surface. If not applied RayFire will use original object material for inner surface.

Mapping Scale: Defines mapping scale for inner surface. Using this property you can increase or decrease size of texture for inner surface.
	
	Outer surface

Outer material: Defines material for fragment's.

	Damage
https://youtu.be/WfoaziBQiGU

Enable: Allows to demolish object by it's own floating Damage value. Object will be demolished when Current Damage value will be more or equal Max Damage value. Current Damage value can be increased by RayFireBomb and RayFireGun components, by Collision or by public method:

	public bool ApplyDamage(float damageValue, Vector3 damagePosition)

damagePosition: Position in world space. In this case damage position will be used by Contact Bias to create more tiny fragments at damaged area. 
True boolean return value means than object was demolished because of applied damage.

Max Damage: Defines maximum allowed damage for object before it will be demolished.

Current Damage: Shows current damage value.

	Collisions

Collect : Allows to accumulate damage value by collisions during dynamic simulation.

Multiplier: Multiply collected collision damage.
	
	Fading
https://youtu.be/wYFPii-pAuY

Fade Type: Fading let you keep your scene clean and optimize dynamic simulation by destroying fragments  or excluding  them from simulation. 
·	None: Fragments will stay in scene with no limitation and they always will be simulated.
·	Sim Exclude: Fragments will be simulated for Life Time period after their birth, then  their Colliders and RigidBody components will be destroyed. 
·	Move Down: Fragments will be simulated for Life Time period after their birth, then they will fall through the ground and will be destroyed after Fade Time period. 
·	Scale Down: Fragments will be simulated for Life Time period after their birth, then they will start slowly scaling to nothing during Fade Time period and destroyed after all.
·	Destroy: Fragments will be simulated for Life Time period after their birth and destroyed instantly.

Size FIlter: Prevent object for fading if it's size bigger than defined value. Turned Off if 0.

Life Time: Minimum  period of time in seconds during which fragments created by demolition or slicing will be simulated.

Life Variation: Add random period of time in seconds to final Life Time.

Fade Time: Period of time in seconds during which object slowly moves through the ground or scales down to nothing.

	Reset WIP
https://www.youtube.com/watch?v=6h94gd_gDrY

	Events
https://youtu.be/lRlqcHGA1sI

RayFire Rigid component provides subscription to Demolition and Activation events.

Subscription to Global event will invoke subscribed method when any demolition happens.

Global Demolition event subscription reference:  
	RFDemolitionEvent.GlobalEvent += MyMethod;

Global Activation event subscription reference:  
	RFActivationEvent.GlobalEvent += MyMethod;

Subscription to Local event will invoke subscribed method when demolition of specific Rigid script happens and because of this you need to have reference to Rigid component you want to track. 

Local Demolition event subscription reference:  
	GameObject myGameObject = GameObject.Find("MyObjectWithRigidComponent");
	RayfireRigid rigid = myGameObject.GetComponent<RayfireRigid>();
	rigid.demolitionEvent.LocalEvent += MyMethod;

Local Activation event subscription reference:  
	GameObject myGameObject = GameObject.Find("MyObjectWithRigidComponent");
	RayfireRigid rigid = myGameObject.GetComponent<RayfireRigid>();
	rigid.activationEvent.LocalEvent += MyMethod;

Keep in mind that MyMethod should have RayFireRigid component as input, in this way you can get access to all public variables of Rigid component, for instance:
void MyMethod(RayfireRigid rigid)
{
    Debug.Log(rigid.fragments.Count);
}
will show in console amount of fragments which were created as a result of demolition.