class MAGES::MeshDeformations::Triangular2PlaneCuttable¶
Overview¶
Component that allows cutting a triangular mesh with two planes, effectively splitting it into three parts: the part below both planes, the part above both planes, and the part in between the planes. The middle part is discarded and the upper part is spawned as a separate GameObject with an optional Rigidbody and Collider. The cut can be performed by calling the Cut method with the desired planes in world space. More…
class Triangular2PlaneCuttable: public MonoBehaviour
{
public:
// structs
struct VertexData;
// classes
class CutEvent;
class MeshBuildData;
class Vec3ApproxComparer;
// properties
Mesh InitialMesh;
Mesh CurrentMesh;
int ModificationCount;
GameObject LastRemovedPart;
CutEvent OnCut;
UnityEvent OnReset;
Material CapMaterial;
Material RemovedCapMaterial;
bool WillAddMeshCollider;
bool WillAddRigidboy;
bool WillAddGrabbable;
// methods
void ResetToInitialMesh();
bool Cut(Plane plane1World, Plane plane2World, out GameObject removedPartObject);
};
Detailed Documentation¶
Component that allows cutting a triangular mesh with two planes, effectively splitting it into three parts: the part below both planes, the part above both planes, and the part in between the planes. The middle part is discarded and the upper part is spawned as a separate GameObject with an optional Rigidbody and Collider. The cut can be performed by calling the Cut method with the desired planes in world space.
Properties¶
Mesh InitialMesh
Gets the initial mesh (shared mesh asset).
Mesh CurrentMesh
Gets the current mesh.
int ModificationCount
Gets the number of cuts performed since the initial mesh.
GameObject LastRemovedPart
Gets the most recently removed part GameObject from a cut.
CutEvent OnCut
Gets the event that is invoked after a successful cut, with the removed part GameObject as a parameter.
UnityEvent OnReset
Gets the event that is invoked after resetting to the initial mesh.
Material CapMaterial
Gets or sets the material used for generated cap faces on the remaining mesh.
Material RemovedCapMaterial
Gets or sets the material used for generated cap faces on the removed part mesh.
bool WillAddMeshCollider
Gets or sets a value indicating whether to add a mesh collider on a newly created part from a cut.
bool WillAddRigidboy
Gets or sets a value indicating whether to add a Rigidbody on a newly created part from a cut.
bool WillAddGrabbable
Gets or sets a value indicating whether to add a grabbable component on a newly created part from a cut.
Methods¶
void ResetToInitialMesh()
Resets the mesh to the initial state it had on Awake. This can be used to undo all cuts and return to the original mesh. Note that this does not affect any spawned cut parts, which will need to be manually destroyed if desired.
bool Cut(Plane plane1World, Plane plane2World, out GameObject removedPartObject)
Cuts the mesh with two planes defined in world space. The part of the mesh below both planes is kept, the part above both planes is removed and spawned as a separate GameObject, and the part in between the planes is discarded. The removed part GameObject will have a MeshFilter and MeshRenderer with the cut mesh, and optionally a MeshCollider and Rigidbody based on the component settings. The onCut event is invoked after a successful cut, with the removed part GameObject as a parameter.
Parameters:
plane1World |
The first plane. |
plane2World |
The 2nd plaen |
removedPartObject |
The removed object. |
Returns:
True if cut.