ui基本完毕,修了一大把的bug
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
# Fracture
|
||||
|
||||
## Overview
|
||||
|
||||
The `Fracture` script allows you to fracture meshes during runtime.
|
||||
|
||||
## Prerequisites
|
||||
|
||||
An object should have the following components added to it. The first three are required components for the script (i.e. they are added automatically) while the Collider is not a required component since you are allowed to use any type of collider.
|
||||
|
||||
* `MeshFilter`
|
||||
* `MeshRenderer`
|
||||
* `RigidBody`
|
||||
* `Collider` (any type)
|
||||
|
||||
## Properties
|
||||
|
||||

|
||||
|
||||
### Trigger Options
|
||||
|
||||
- **Trigger Type**: The method by which the fracture will be triggered
|
||||
- **Collision**: Physics-based colliders
|
||||
- **Trigger**: Trigger-based colliders
|
||||
- **Keyboard**: User presses a key
|
||||
- **Minimum Collision Force**: The minimum collision force required to trigger the fracture. If the collision force is equal to or greater than this value, the fracture will be triggered. To ignore this setting, set the minimum force to 0. This option is available for the **Collision** trigger type only.
|
||||
- **Limit collisions to selected tags?**: By enabling this option, you can limit which object tags will trigger the collision. When a collision is detected, the colliding object's tag will be compared against the list of **Included Tags**. If it is contained within that list (and the other collision criteria are met), the fracture will be triggered. This option is available for the **Collision** and **Trigger** trigger types only.
|
||||
- **Included Tags**: The set of GameObject tags that can trigger a fracture. This option is available for the **Collision** and **Trigger** trigger types only.
|
||||
- **Trigger Key**: The key that will trigger the fracture when press. This option is available for the **Keyboard** trigger type only.
|
||||
|
||||
### Fracture Options
|
||||
- **Fragment Count**: The number of fragments to break the object into. *Note:* If **Detect Floating Fragments** is set to true, the final number of fragments may be higher than **Fragment Count**. This is because floating fragment detection is performed after the fracturing stage is complete.
|
||||
- **Asynchronous**: If enable, the mesh will be fractured asynchronously via use of coroutines. The fracture steps are spread out over many frames rather than one to prevent stuttering. If **Fragment Count** is large, the delay between the triggering of the fracture and the fracturing actually occurring can be significant. If performance is an issue, it is recommended to use `*Prefracture` to fracture the mesh in the editor rather than runtime.
|
||||
- **Detect Floating Fragments**: If enable, a pass will be made on the resulting fragments after the fracture algorithm has executed to determine if any of the fragments contain unconnected geometry. This can occur when fracturing non-convex meshes. Since the geometry of each fragment must be searched to identify these disconnected sets of vertices/faces, this option will significantly reduce the performance of the fracturing. Once again, if performance is an issue, it is recommended that you use the `Prefracture` script.
|
||||
- **Fracture Along X/Y/Z Plane**: Each fracture line can be specified by a vector. For some objects, it is desirable to keep this vector locked to specific planes. For example, assume you have a model of a pane of glass with the width along the X-axis, the height along the Y-axis and the thickness along the Z-axis. The fracture lines should be constrained to the face of the glass (X-Y plane) and not split the glass along its thickness. In this case you would set **Fracture Along X Plane** and **Fracture Along Y Plane** to true and **Fracture Along Z Plane** to false.
|
||||
- **Inside Material**: The material to use for the newly fractured faces.
|
||||
- **Texture Scale**: Scale factor applied to the UV coordinates for the fractured faces.
|
||||
- **Texture Offset**: Constant offset applied to the UV coordinates for the fractured faces.
|
||||
|
||||
### Refracture Options
|
||||
- **Enabled**: Set to true to enable refracturing of fragments.
|
||||
- **Invoke Callbacks**: If enabled, refracturing fragments will also trigger the callbacks. This option can be useful if you only want to trigger an action the first time an object is fractured but not when the fragments are refractured (in this case, you would set this option to false).
|
||||
- **Max # of Refractures**: The maximum number of times a fragment can be refractured. **WARNING: Refracturing results in an exponential growth in fragments. It is recommended to keep fragment count low if you enable refracturing.**
|
||||
|
||||
## Callback Options
|
||||
- **OnCompleted()**: This callback is triggered when the fracturing has been completed. Use this to play a sound, turn on a light or any other in-game logic you require.
|
||||
@@ -0,0 +1,32 @@
|
||||
# Getting Started
|
||||
|
||||
There are three separate components included in this package. Click on the links below to see documentation for that specific script.
|
||||
|
||||
- [Fracture](/Documentation~/Fracture.md) - Break meshes into pieces during runtime.
|
||||
- [Prefracture](/Documentation~/Prefracture.md) - Used for pre-fracturing meshes in the editor. The generated fragments can either be saved directly in the scene or saved to disk if you would like to create a prefab.
|
||||
- [Slice](/Documentation~/Slice.md) - Runtime slicing of meshes
|
||||
|
||||
## Tips
|
||||
Before using the scripts, there are a few limitations and considerations to be aware of.
|
||||
|
||||
### 1. If you are importing a custom mesh, you must set "Read/Write Enabled" to true in the Import settings. Otherwise you will get an error.
|
||||
|
||||

|
||||
|
||||
### 2. Meshes must be be non-intersecting and closed. If not, the re-triangulation will fail.
|
||||
|
||||

|
||||
|
||||
Depicted above is the wireframe model of a stool. Notice how the crossbars intersect the legs of the stool. Intersecting geometry will cause the triangulation algorithm (which fills in the newly cut faces) to fail and will result in artifacts like you see below. The triangulation algorithm I implemented does not handle self-intersecting polygons. Detecting self-intersecting geometry is a non-trivial problem and is not something I plan on adding.
|
||||
|
||||

|
||||
|
||||
### 3. Optimizing Performance
|
||||
|
||||
The fracturing process is a computationally intensive process. Simple models (several hundred vertices) can be fractured into dozens of pieces without much of a hitch. The performance of fracturing complex models consisting of several thousands vertices during runtime will likely be quite slow on older, less capable machines.
|
||||
|
||||
Here are some tips for optimizing performance
|
||||
1. Reduce number of fragments
|
||||
2. Disable or reduce the number of refracturing interations
|
||||
3. Prefracture models in the editor rather than fracturing during runtime
|
||||
4. Bring your model into a 3D modeling program like Blender and use the Decimation tool to simplify the mesh geometry
|
||||
@@ -0,0 +1,47 @@
|
||||
# Prefracture
|
||||
|
||||
## Overview
|
||||
|
||||
The `Prefracture` script allows meshes to be fractured in the editor. When a mesh is prefractured, the fragments are added to the scene and the original object is set to an inactive state. Each fragment has a RigidBody attached to it which is frozen. Fragments can be unfrozen based on several trigger conditions (listed below). When the trigger condition is satisfied, the fragment is unfrozen. Optionally, all fragments can be unfrozen if a single fragment's trigger conditions are satisfied. This allows prefractured meshes to be broken apart one piece at a time or shatter all at once.
|
||||
|
||||
## Prerequisites
|
||||
|
||||
An object should have the following components added to it. The first three are required components for the script (i.e. they are added automatically) while the Collider is not a required component since you are allowed to use any type of collider.
|
||||
|
||||
* `MeshFilter`
|
||||
* `MeshRenderer`
|
||||
* `RigidBody`
|
||||
* `Collider` (any type)
|
||||
|
||||
## Properties
|
||||
|
||||

|
||||
|
||||
### Trigger Options
|
||||
|
||||
- **Trigger Type**: The method that triggers the fragments to "wake up" and become active physics objects.
|
||||
- **Collision**: Physics-based colliders
|
||||
- **Trigger**: Trigger-based colliders
|
||||
- **Keyboard**: User presses a key
|
||||
- **Minimum Collision Force**: The minimum collision force required to trigger the fracture. If the collision force is equal to or greater than this value, the fracture will be triggered. To ignore this setting, set the minimum force to 0. This option is available for the **Collision** trigger type only.
|
||||
- **Limit collisions to selected tags?**: By enabling this option, you can limit which object tags will trigger the collision. When a collision is detected, the colliding object's tag will be compared against the list of **Included Tags**. If it is contained within that list (and the other collision criteria are met), the fracture will be triggered. This option is available for the **Collision** and **Trigger** trigger types only.
|
||||
- **Included Tags**: The set of GameObject tags that can trigger a fracture. This option is available for the **Collision** and **Trigger** trigger types only.
|
||||
- **Trigger Key**: The key that will trigger the fracture when press. This option is available for the **Keyboard** trigger type only.
|
||||
|
||||
### Fracture Options
|
||||
- **Fragment Count**: The number of fragments to break the object into. *Note:* If **Detect Floating Fragments** is set to true, the final number of fragments may be higher than **Fragment Count**. This is because floating fragment detection is performed after the fracturing stage is complete.
|
||||
- **Asynchronous**: Has no effect for prefracturing
|
||||
- **Detect Floating Fragments**: If enable, a pass will be made on the resulting fragments after the fracture algorithm has executed to determine if any of the fragments contain unconnected geometry. This can occur when fracturing non-convex meshes. Since the geometry of each fragment must be searched to identify these disconnected sets of vertices/faces, this option will significantly reduce the performance of the fracturing. Once again, if performance is an issue, it is recommended that you use the `Prefracture` script.
|
||||
- **Fracture Along X/Y/Z Plane**: Each fracture line can be specified by a vector. For some objects, it is desirable to keep this vector locked to specific planes. For example, assume you have a model of a pane of glass with the width along the X-axis, the height along the Y-axis and the thickness along the Z-axis. The fracture lines should be constrained to the face of the glass (X-Y plane) and not split the glass along its thickness. In this case you would set **Fracture Along X Plane** and **Fracture Along Y Plane** to true and **Fracture Along Z Plane** to false.
|
||||
- **Inside Material**: The material to use for the newly fractured faces.
|
||||
- **Texture Scale**: Scale factor applied to the UV coordinates for the fractured faces.
|
||||
- **Texture Offset**: Constant offset applied to the UV coordinates for the fractured faces.
|
||||
|
||||
### Callback Options
|
||||
- **OnCompleted()**: This callback is triggered when the fracturing has been completed. Use this to play a sound, turn on a light or any other in-game logic you require.
|
||||
|
||||
### Prefracture Options
|
||||
- **Unfreeze All**: If one fragment is triggered, unfreeze all fragments.
|
||||
- **Save Fragments to Disk**: Saves the fragment meshes to disk. Required if the prefractured mesh will be used in a prefab. Optional if the prefractured mesh will not be used as a prefab and will be embedded in the scene.
|
||||
- **Save Location**: Location to save the fragments to relative to the project root directory.
|
||||
- **Prefracture**: This button will fracture the mesh and generate the fragments. After the fragments have been generated, the object containing the base mesh is set to inactive but remains in the scene.
|
||||
@@ -0,0 +1,46 @@
|
||||
# Slice
|
||||
|
||||
## Overview
|
||||
|
||||
The `Slice` script allows meshes to be sliced into two pieces during runtime. Fragments can resliced into smaller fragments if desired.
|
||||
|
||||
## Prerequisites
|
||||
|
||||
An object should have the following components added to it. The first three are required components for the script (i.e. they are added automatically) while the Collider is not a required component since you are allowed to use any type of collider.
|
||||
|
||||
* `MeshFilter`
|
||||
* `MeshRenderer`
|
||||
* `RigidBody`
|
||||
* `Collider` (any type)
|
||||
|
||||
## Properties
|
||||
|
||||

|
||||
|
||||
### Slice Options
|
||||
|
||||
- **Enable Reslicing**: Set to true to enable reslicing of fragments.
|
||||
- **Max Reslice Count**: The maximum number of times a fragment can be resliced.
|
||||
- **Detect Floating Fragments**: If enable, a pass will be made on the resulting fragments after the slicing algorithm has executed to determine if any of the fragments contain unconnected geometry. This can occur when slicing non-convex meshes. Since the geometry of each fragment must be searched to identify these disconnected sets of vertices/faces, this option will significantly reduce the performance of the slicing.
|
||||
- **Inside Material**: The material to use for the newly sliced faces.
|
||||
- **Texture Scale**: Scale factor applied to the UV coordinates for the sliced faces.
|
||||
- **Texture Offset**: Constant offset applied to the UV coordinates for the sliced faces.
|
||||
- **Invoke Callbacks**: If enabled, slicing fragments will also trigger the callback functions. This option can be useful if you only want to trigger an action the first time an object is sliced but not when the fragments are resliced (in this case, you would set this option to false).
|
||||
|
||||
### Callback Options
|
||||
- **OnCompleted()**: This callback is triggered when the slicing has been completed. Use this to play a sound, turn on a light or any other in-game logic you require.
|
||||
|
||||
## How to Use
|
||||
|
||||
### Call from Script
|
||||
Unlike `Fracture` and `Prefracture`, `Slice` requires scripting since you must pass in the normal and origin of the slice plane during runtime.
|
||||
|
||||
If `obj` is the object to be sliced, execute the following code to slice `obj` into two fragments. `sliceNormal` and `sliceOrigin` are the normal and origin of the slice plane in world coordinates, respectively.
|
||||
|
||||
```csharp
|
||||
var slicer = obj.GetComponent<Slice>();
|
||||
var sliceNormal = Vector3.up;
|
||||
var sliceOrigin = obj.transform.position;
|
||||
|
||||
slicer.ComputeSlice(sliceNormal, sliceOrigin);
|
||||
```
|
||||
Reference in New Issue
Block a user