Rasagar/Library/PackageCache/com.unity.visualeffectgraph/Documentation~/Snippets/Operator-SampleMeshOrSkinnedMesh.md
2024-08-26 23:07:20 +03:00

55 lines
12 KiB
Markdown

## Operator settings
| **Property** | **Type** | **Description** |
| ----------------------- | -------- | ------------------------------------------------------------ |
| **Output** | Enum | **(Inspector)** Select the vertex attributes to read from the vertex. |
| **Mode** | Enum | The wrap mode to use for the sequence. The options are:<br/>&#8226; **Clamp**: Clamps the index between the first and last vertices.<br/>&#8226; **Wrap**: Wraps the index around to the other side of the vertex list. <br/>&#8226; **Mirror**: Mirrors the vertex list so out of range indices move back and forth through the list. |
| **Placement mode** | Enum | Specify which primitive part of the mesh to sample from:<br/>&#8226; **Vertex**: Samples positions from all listed vertices.<br/>&#8226; **Edge**: Samples from an interpolation between two consecutives vertices that are part of a triangle on the mesh. <br/>&#8226; **Surface**: Samples from an interpolation between three vertices that define a triangle on the mesh. |
| **Surface coordinates** | Enum | Specify the method this Block uses to sample the surface of a triangle.<br/>&#8226; **Barycentric**: Samples the surface using raw barycentric coordinates. With this method, sampled positions are not constrained by the triangle edges which is useful if you have baked a position outside of the Visual Effect Graph.<br/>&#8226; **Uniform**: Samples the surface uniformly within the triangle area.<br/>This property only appears if you set **Placement mode** to **Surface** and **Spawn Mode** to **Custom**. |
| **Skinned Transform** | Enum | Specify the transform to apply to the sample from the Skinned Mesh Renderer.<br />&#8226; **None**: Apply no transform. The sample is the raw value from the geometry buffer of the Skinned Mesh Renderer.<br/>&#8226; **Apply Local Root Transform**: Apply the transform of the root bone relative to the Skinned Mesh Renderer.<br/>&#8226; **Apply World Root Transform**: Apply the world transform of the root bone. <br/>This property only appears if you set **Source** to **Skinned Mesh Renderer**. |
| **Source** | Enum | **(Inspector)** Specify the kind of geometry to sample from. The options are:<br/>&#8226; **Mesh**: Samples from a mesh asset. The Operator becomes a [Sample Mesh](./Operator-SampleMesh.md) Operator. <br/>&#8226; **Skinned Mesh Renderer**: Samples from a [Skinned Mesh Renderer](https://docs.unity3d.com/Manual/class-SkinnedMeshRenderer.html). The Operator becomes a [Sample Skinned Mesh](./Operator-SampleSkinnedMesh.md) Operator.|
### Operator properties
| **Input** | **Type** | **Description** |
| ------------------------- | --------------------- | ------------------------------------------------------------ |
| **Mesh** | Mesh | The source mesh asset to sample.<br/><br/>This property only appears if you set **Source** to **Mesh** |
| **Skinned Mesh Renderer** | Skinned Mesh Renderer | The source Skinned Mesh Renderer component to sample. This is a reference to a component within the scene. To assign a Skinned Mesh Renderer to this port, create a Skinned Mesh Renderer property in the [Blackboard](Blackboard.md) and expose it.<br/><br/>This property only appears if you set **Source** to **Skinned Mesh Renderer**. |
| **Vertex** | uint | The index of the vertex to sample.<br/><br/>This property only appears if you set **Placement mode** to **Vertex**. |
| **Index** | uint | The start index of the edge to sample from. The Block uses this index and the following index to select the line to sample from.<br/>This property only appears if you set **Placement mode** to **Edge** and **Spawn Mode** to **Custom**. |
| **Triangle** | uint | The index of triangle to sample, assuming the index buffer contains a triangle list.<br/>This property only appears if you set **Placement mode** to **Surface**, **Spawn Mode** to **Custom**, and **Spawn Mode** to **Custom**. |
| **Edge** | float | The interpolation value the Block uses to sample along the edge. This is the percentage along the edge, from start position to end position, that the sample position is taken.<br/>This property only appears if you set **Placement mode** to **Edge** and **Spawn Mode** to **Custom**. |
| **Barycentric** | Vector2 | The raw barycentric coordinate to sample from the triangle at. The input is two-dimensional (**X** and **Y**) and the block calculates the **Z** value with the values you input: **Z** = **1** - **X** - **Y**. This sampling method does not constrain the sampled position inside the triangle edges.<br/>This property only appears if you set **Placement mode** to **Surface**, **Surface coordinates** to **Barycentric**, and **Spawn Mode** to **Custom**. |
| **Square** | Vector2 | The uniform coordinate to sample the triangle at. The Block takes this value and maps it from a square coordinate to triangle space. To do this, it uses the method outlined in the paper [A Low-Distortion Map Between Triangle and Square](https://hal.archives-ouvertes.fr/hal-02073696v2) (Heitz 2019).<br/>This property only appears if you set **Placement mode** to **Surface**, **Surface coordinates** to **Uniform**, and **Spawn Mode** to **Custom**. |
| **Transform** | Transform | The transform to apply after sampling. If you set **Source** to **Skinned Mesh Renderer** and **Skinned Transfrom** to a setting other than **None**, Visual Effect Graph applies the transform after the root bone transform. If you set **Skinned Transform** to **Apply World Root Transform**, the Visual Effect Graph converts the transform to world space. |
| **Output** | **Type** | **Description** |
| ---------------------- | --------- | ------------------------------------------------------------ |
| **Position** | Position | The [position attribute of the vertex](https://docs.unity3d.com/ScriptReference/Rendering.VertexAttribute.Position.html). This property only appears if you select **Position** in **Output**. |
| **Normal** | Direction | The normalized [normal attribute of the vertex](https://docs.unity3d.com/ScriptReference/Rendering.VertexAttribute.Normal.html). This property only appears if you select **Normal** in **Output**. |
| **Tangent** | Vector | The x, y, and z components of the [tangent attribute of the vertex](https://docs.unity3d.com/ScriptReference/Rendering.VertexAttribute.Tangent.html). This property only appears if you select **Tangent** in **Output**. |
| **Bitangent** | Vector | The cross product of **Normal** and **Tangent**, multiplied by **Bitangent Sign**. This property only appears if you select **Bitangent** in **Output** |
| **Bitangent Sign** | Float | The w component of the [tangent attribute of the vertex](https://docs.unity3d.com/ScriptReference/Rendering.VertexAttribute.Tangent.html). This property only appears if you select **Bitangent Sign** in **Output**. |
| **Color** | Vector4 | The [color attribute of the vertex](https://docs.unity3d.com/ScriptReference/Rendering.VertexAttribute.Color.html). This property only appears if you select **Color** in **Output**. |
| **Tex Coord0-7** | Vector4 | The vertex attribute [TexCoord 0 to 7](https://docs.unity3d.com/ScriptReference/Rendering.VertexAttribute.TexCoord0.html). For unspecified dimensions, this is **0**. This property only appears if you select **TexCoord0-7** in **Output**. |
| **Blend Weight** | Vector4 | The [bone blend weight attribute of the vertex](https://docs.unity3d.com/ScriptReference/Rendering.VertexAttribute.BlendWeight.html). This property only appears if you select **BlendWeight** in **Output**. |
| **Blend Indices** | Vector4 | The [bone indices attribute of the vertex](https://docs.unity3d.com/ScriptReference/Rendering.VertexAttribute.BlendIndices.html). This property only appears if you select **BlendIndices** in **Output**. |
| **Transform** | Transform | The orthonormal basis, where the three vectors are perpendicular to each other and normalized. Visual Effect Graph calculates **Transform** using **Normal**, **Tangent** and **Position**. This property only appears if you select **Transform** in **Output**. |
| **Previous Position** | Position | The position of the vertex from the previous frame. To make this value more accurate, Visual Effect Graph considers the root transform of the previous frame. This property only appears if you select **Previous Position** in **Output**. |
| **Previous Normal** | Direction | The normalized normal of the vertex from the previous frame. To make this value more accurate, Visual Effect Graph considers the root transform of the previous frame. You must enable [SkinnedMeshRenderer.skinnedMotionVectors](https://docs.unity3d.com/ScriptReference/SkinnedMeshRenderer-skinnedMotionVectors.html) or Visual Effect Graph falls back to the current frame. This property only appears if you select **Previous Normal** in **Output**. |
| **Previous Tangent** | Vector | The x, y, and z components of the tangent of the vertex from the previous frame. To make this value more accurate, Visual Effect Graph considers the root transform of the previous frame. You must enable [SkinnedMeshRenderer.skinnedMotionVectors](https://docs.unity3d.com/ScriptReference/SkinnedMeshRenderer-skinnedMotionVectors.html) or Visual Effect Graph falls back to the current frame. This property only appears if you select **Previous Tangent** in **Output**. |
| **Previous Bitangent** | Vector | The cross product of **Normal** and **Tangent**, multiplied by **Bitangent Sign**, from the previous frame. You must enable [SkinnedMeshRenderer.skinnedMotionVectors](https://docs.unity3d.com/ScriptReference/SkinnedMeshRenderer-skinnedMotionVectors.html) or Visual Effect Graph falls back to the current frame. This property only appears if you select **Previous Bitangent** in **Output**. |
| **Velocity** | Vector | The difference between **Position** and **Previous Position**, divided by [Time.deltaTime](https://docs.unity3d.com/ScriptReference/Time-deltaTime.html). This property only appears if you select **Velocity** in **Output**. |
| **Previous Transform** | Transform | The orthonormal basis, where the three vectors are perpendicular to each other and normalized. Visual Effect Graph calculates **Transform** using **Previous Normal**, **Previous Tangent** and **Previous Position**. This property only appears if you select **Transform** in **Output**. |
#### Limitations
The Mesh sampling feature has the following limitations:
- It only supports [VertexAttributeFormat.Float32](https://docs.unity3d.com/ScriptReference/Rendering.VertexAttributeFormat.Float32.html) for all [VertexAttributes](https://docs.unity3d.com/ScriptReference/Rendering.VertexAttribute.html) except [Color](https://docs.unity3d.com/ScriptReference/Rendering.VertexAttribute.Color.html), which has to be a four component attribute using either [VertexAttributeFormat.UInt8](https://docs.unity3d.com/ScriptReference/Rendering.VertexAttributeFormat.UInt8.html) or [VertexAttributeFormat.Float32](https://docs.unity3d.com/ScriptReference/Rendering.VertexAttributeFormat.Float32.html) format.
- If the mesh isn't [readable](https://docs.unity3d.com/ScriptReference/Mesh-isReadable.html), the Operator returns 0. For information on how to make a mesh readable in the Editor, refer to the [Import Settings for a model file](https://docs.unity3d.com/Manual/FBXImporter-Model.html).
- Visual Effect Graph can't sample the current Skinned Mesh Renderer if you disable **Update When Offscreen** in a [Skinned Mesh Renderer](https://docs.unity3d.com/Manual/class-SkinnedMeshRenderer.html) and the mesh bounds aren't visible. Visual Effect Graph uses the position, normal and tangent of the last visible frame.
## Reference list
* Heitz, Eric. 2019. "A Low-Distortion Map Between Triangle and Square". [hal-02073696v2](https://hal.archives-ouvertes.fr/hal-02073696v2)