Class MassFromVolume
Script to calculate mass from mesh volume and material density. Removes need for guessing mass and ensures that all objects of same density are submerged equally.
Namespace: NWH.DWP2.WaterObjects
Assembly: NWH.DWP2.dll
Syntax
[RequireComponent(typeof(WaterObject))]
public class MassFromVolume : MonoBehaviour
Fields
| Edit this page View Sourcedensity
Calculated density of the material in kg/m³.
Declaration
public float density
Field Value
| Type | Description |
|---|---|
| float |
mass
Calculated mass of the object in kg.
Declaration
public float mass
Field Value
| Type | Description |
|---|---|
| float |
material
Material preset containing density value.
Declaration
public WaterObjectMaterial material
Field Value
| Type | Description |
|---|---|
| WaterObjectMaterial |
volume
Calculated volume of the simulation mesh in m³.
Declaration
public float volume
Field Value
| Type | Description |
|---|---|
| float |
Methods
| Edit this page View SourceCalculateAndApplyFromDensity(float)
Calculates mass from the given density and applies it to the Rigidbody.
Declaration
public float CalculateAndApplyFromDensity(float density)
Parameters
| Type | Name | Description |
|---|---|---|
| float | density | Material density in kg/m³. |
Returns
| Type | Description |
|---|---|
| float | Calculated mass value. |
CalculateAndApplyFromMaterial()
Calculates mass from the assigned material's density and applies it to the Rigidbody.
Declaration
public float CalculateAndApplyFromMaterial()
Returns
| Type | Description |
|---|---|
| float | Calculated mass value. |
CalculateSimulationMeshVolume()
Gets volume of the simulation mesh. Scale-sensitive.
Declaration
public void CalculateSimulationMeshVolume()
SetDefaultAsMaterial()
Sets the default WaterObjectMaterial from Resources.
Declaration
public void SetDefaultAsMaterial()