Optimizing 27 Slicer
27 Slicer has multiple layers of optimizations depending on the use case that your game requires.
How 27 Slicer Is Optimized
Calculating the slicing of meshes and uploading the results to the GPU can be an intensive process. 27 Slicer reduces this workload by hashing the properties of the objects that are being sliced.
An example of common properties include the position, rotation and scale of the sliced Game Object.
27 Slicers default behavior is to 'Gather Details' on all slices every frame. While it does so a hash is built up for each Slicer Controller. If this hash changes from the previous frame it will then proceed to Slicing, otherwise Slicing will be skipped for this frame.
Optimization Scenarios
The following sections list out common use cases for 27 Slicer and how to optimize for each one.
Slice On Demand (Default)
This is the default behavior of 27 Slicer. It will only re-calculate slices when properties of the sliced Game Object like the position, rotation and scale of the sliced Game Object is modified. Subsequently calling RefreshSlice()
on the applicable SlicerController
sets up the slicing to run on the next frame.
To Enable
- Window -> 27 Slicer -> Configuration
- Click
Disable Custom Configuration
(If not already disabled).
- Click
Call RefreshSlice()
on the applicable SlicerController
when a change has been made that requires the slicer to update. During the next the next frame the slices will be updated.
If the slices must be updated immediately RefreshSliceImmediate()
can be called instead.
Slice After A Component Is Modified
This scenario will re-calculate slices when common properties such as the position, rotation and scale of the sliced Game Object is modified. Without requiring RefreshSlice()
to be called.
To Enable
- Window -> 27 Slicer -> Configuration
- Click
Enable Custom Configuration
(If not already enabled). - Enable
Skip Unmodified Slices
. - Enable
Refresh Slices On Update
.
- Click
Slice On Start (Slice Finalization)
This scenario will only do an initial slice immediately after the Game Object is initialized. It will then destroy all slicing components, leaving the sliced meshes behind.
To Enable For Selected Scenes
Sometimes you may want select scenes to Slice only on start, while other scenes can slice in real time.
For example, A 'house builder' scene would allow you to change window sizes in real time, while the 'house simulation' scene only needs the initial slice after loading to setup the scene.
Here is a simple example of how to achieve this.
using Slicer;
using UnityEngine;
public class FinalizeSlicingExample : MonoBehaviour
{
...
private void FinalizeSlicing(Vector3 size)
{
// Get the Slicer controller on this object.
var slicerController = GetComponent<SlicerController>();
// Set what ever parameters are needed for this slice.
slicerController.Size = size;
// Force the controller to re-slice everything immediately.
slicerController.RefreshSliceImmediate();
// Finalize the slicing.
slicerController.FinalizeSlicing();
// sometimes it may be necessary to delay the destruction of the slicer controller, so use this instead.
//slicerController.FinalizeSlicing(deferDestroy: true);
}
...
}
The default configuration will optimize and manage the lifecycle of the sliced meshes for you. These setting include enabling all of the Sliced Mesh Finalization
settings except for Finalize On Start
.
To Enable For All Scenes
- Window -> 27 Slicer -> Configuration
- Click
Enable Custom Configuration
(If not already enabled). - Enable
Finalize On Start
- Enable
Use Finalized Sliced Mesh Component
- Enable
Set Finalized Sliced Mesh To Be No Longer Readable
- Enable
Optimize Finalized Sliced Mesh
- Click
Not using 27 Slicer at runtime
Of course the most optimal code is code that is not run at all. In this spirit, sliced meshes can be exported as Unity Meshes via the Sliced Mesh Exporter. The exported meshes can then be assigned to a mesh filter just like any other mesh.
This can be achieved in two ways:
With a dedicated scene that is setup for slicing, but not included with the build. In this scene you can setup your Game Objects and slices.
OR
With individual prefabs that are opened and then exported. This option is useful if you want to permanently set (Finalize) the slicing of the prefab. Check out the 'Permanently Set Slicing (Finalize Slicing)' section of the Sliced Mesh Exporter page.
Slice Every Frame
This scenario bypasses most of the optimizations used by 27 Slicer and is useful only in very limited cases.
Every frame 27 Slicer will recalculate slices where any tracked properties have changed.
Use Cases
Video recording
If the whole project is dedicated to non-real time applications such as video recording, this option can be useful to ensure all slices are kept up to date.
Debugging meshes that are not consistently sliced
Sometimes the optimizations employed by 27 Slicer can result in slices not updating.
This most often happens when a property of the sliced object changes but is not tracked (i.e. hashed) by 27 Slicer.
To Enable
- Window -> 27 Slicer -> Configuration
- Click
Enable Custom Configuration
(If not already enabled). - Disable
Skip Unmodified Slices
. - Enable
Refresh Slices On Update
.
- Click