Class MeshToSDFBaker
This class allows to bake Signed Distance Fields from Meshes, and holds the necessary data to perform this operation.
Namespace: UnityEngine.VFX.SDF
Syntax
public class MeshToSDFBaker : IDisposable
Constructors
MeshToSDFBaker(Vector3, Vector3, Int32, List<Mesh>, List<Matrix4x4>, Int32, Single, Single, CommandBuffer)
Constructor of the class MeshToSDFBaker.
Declaration
public MeshToSDFBaker(Vector3 sizeBox, Vector3 center, int maxRes, List<Mesh> meshes, List<Matrix4x4> transforms, int signPassesCount = 1, float threshold = 0.5F, float sdfOffset = 0F, CommandBuffer cmd = null)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | sizeBox | The desired size of the baking box |
Vector3 | center | The center of the baking box. |
Int32 | maxRes | The resolution along the largest dimension. |
List<Mesh> | meshes | The list of meshes to be baked into an SDF. |
List<Matrix4x4> | transforms | The list of transforms of the meshes. |
Int32 | signPassesCount | The number of refinement passes on the sign of the SDF. This should stay below 20. |
Single | threshold | The threshold controlling which voxels will be considered inside or outside of the surface. |
Single | sdfOffset | The Offset to add to the SDF. It can be used to make the SDF more bulky or skinny. |
CommandBuffer | cmd | The CommandBuffer on which the baking process will be added. |
MeshToSDFBaker(Vector3, Vector3, Int32, Mesh, Int32, Single, Single, CommandBuffer)
Constructor of the class MeshToSDFBaker.
Declaration
public MeshToSDFBaker(Vector3 sizeBox, Vector3 center, int maxRes, Mesh mesh, int signPassesCount = 1, float threshold = 0.5F, float sdfOffset = 0F, CommandBuffer cmd = null)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | sizeBox | The desired size of the baking box. |
Vector3 | center | The center of the baking box. |
Int32 | maxRes | The resolution along the largest dimension. |
Mesh | mesh | The Mesh to be baked into an SDF. |
Int32 | signPassesCount | The number of refinement passes on the sign of the SDF. This should stay below 20. |
Single | threshold | The threshold controlling which voxels will be considered inside or outside of the surface. |
Single | sdfOffset | The Offset to add to the SDF. It can be used to make the SDF more bulky or skinny. |
CommandBuffer | cmd | The CommandBuffer on which the baking process will be added. |
Properties
SdfTexture
Returns the texture containing the baked Signed Distance Field
Declaration
public RenderTexture SdfTexture { get; }
Property Value
Type | Description |
---|---|
RenderTexture |
Methods
BakeSDF()
Performs the baking operation. After this function is called, the resulting SDF is accessible via the property MeshToSDFBaker.SdfTexture.
Declaration
public void BakeSDF()
Dispose()
Release all the buffers and textures created by the object. This must be called you are finished using the object.
Declaration
public void Dispose()
Finalize()
This finalizer should never be called. Dispose() should be called explicitly when an MeshToSDFBaker instance is finished being used.
Declaration
protected void Finalize()
GetActualBoxSize()
Gets the size of the baking box used.
Declaration
public Vector3 GetActualBoxSize()
Returns
Type | Description |
---|---|
Vector3 | A Vector3 containing the size of the box along the three directions of space |
GetGridSize()
Gets the dimensions of the baked texture.
Declaration
public Vector3Int GetGridSize()
Returns
Type | Description |
---|---|
Vector3Int | A Vector3Int containing the height, width and depth of the texture. |
Reinit(Vector3, Vector3, Int32, List<Mesh>, List<Matrix4x4>, Int32, Single, Single)
Reinitialize the baker with the new lists of meshes and transforms, and provided parameters.
Declaration
public void Reinit(Vector3 sizeBox, Vector3 center, int maxRes, List<Mesh> meshes, List<Matrix4x4> transforms, int signPassesCount = 1, float threshold = 0.5F, float sdfOffset = 0F)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | sizeBox | The desired size of the baking box |
Vector3 | center | The center of the baking box. |
Int32 | maxRes | The resolution along the largest dimension. |
List<Mesh> | meshes | The list of meshes to be baked into an SDF. |
List<Matrix4x4> | transforms | The list of transforms of the meshes. |
Int32 | signPassesCount | The number of refinement passes on the sign of the SDF. This should stay below 20. |
Single | threshold | The threshold controlling which voxels will be considered inside or outside of the surface. |
Single | sdfOffset | The Offset to add to the SDF. It can be used to make the SDF more bulky or skinny. |
Reinit(Vector3, Vector3, Int32, Mesh, Int32, Single, Single)
Reinitialize the baker with the new mesh and provided parameters.
Declaration
public void Reinit(Vector3 sizeBox, Vector3 center, int maxRes, Mesh mesh, int signPassesCount = 1, float threshold = 0.5F, float sdfOffset = 0F)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | sizeBox | The desired size of the baking box. |
Vector3 | center | The center of the baking box. |
Int32 | maxRes | The resolution along the largest dimension. |
Mesh | mesh | The Mesh to be baked into an SDF. |
Int32 | signPassesCount | The number of refinement passes on the sign of the SDF. This should stay below 20. |
Single | threshold | The threshold controlling which voxels will be considered inside or outside of the surface. |
Single | sdfOffset | The Offset to add to the SDF. It can be used to make the SDF more bulky or skinny. |