|
|
|
|
|
|
[RequireComponent(typeof(ARPlaneMeshVisualizer), typeof(MeshRenderer), typeof(ARPlane))] |
|
|
|
public class ARFeatheredPlaneMeshVisualizer : MonoBehaviour |
|
|
|
{ |
|
|
|
float featheringWidth |
|
|
|
{ |
|
|
|
get { return m_FeatheringWidth; } |
|
|
|
set { m_FeatheringWidth = value; } |
|
|
|
} |
|
|
|
|
|
|
|
[Tooltip("The width of the texture feathering (in world units).")] |
|
|
|
[SerializeField] |
|
|
|
float m_FeatheringWidth = 0.2f; |
|
|
|
|
|
|
Material m_FeatheredPlaneMaterial; |
|
|
|
|
|
|
|
private void Awake() |
|
|
|
void Awake() |
|
|
|
{ |
|
|
|
m_PlaneMeshVisualizer = GetComponent<ARPlaneMeshVisualizer>(); |
|
|
|
m_ARPlane = GetComponent<ARPlane>(); |
|
|
|
|
|
|
private void OnEnable() |
|
|
|
void OnEnable() |
|
|
|
private void OnDisable() |
|
|
|
void OnDisable() |
|
|
|
private void ARPlaneMeshVisualizer_meshUpdated(ARPlaneMeshVisualizer planeMeshVisualizer) |
|
|
|
void ARPlaneMeshVisualizer_meshUpdated(ARPlaneMeshVisualizer planeMeshVisualizer) |
|
|
|
{ |
|
|
|
GenerateBoundaryUVs(planeMeshVisualizer.mesh); |
|
|
|
} |
|
|
|
|
|
|
/// is fairly uniform and the center vert is close to the barycentric center.
|
|
|
|
/// </remarks>
|
|
|
|
/// <param name="mesh">The <c>Mesh</c> generated by <c>ARPlaneMeshVisualizer</c></param>
|
|
|
|
public void GenerateBoundaryUVs(Mesh mesh) |
|
|
|
void GenerateBoundaryUVs(Mesh mesh) |
|
|
|
{ |
|
|
|
int vertexCount = mesh.vertexCount; |
|
|
|
|
|
|
|
|
|
|
// Remap the UV so that a UV of "1" marks the feathering boudary.
|
|
|
|
// The ratio of featherBoundaryDistance/edgeDistance is the same as featherUV/edgeUV.
|
|
|
|
// Rearrange to get the edge UV.
|
|
|
|
float uvMapping = vertexDist / (vertexDist - m_FeatheringWidth); |
|
|
|
float uvMapping = vertexDist / (vertexDist - featheringWidth); |
|
|
|
uv.x = uvMapping; |
|
|
|
|
|
|
|
// All the UV mappings will be different. In the shader we need to know the UV value we need to fade out by.
|
|
|
|