Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,34 @@ private void Awake()
}
}

/// <summary>
/// Enables all child mesh outlines.
/// </summary>
private void OnEnable()
{
foreach (var meshOutline in meshOutlines)
{
if (meshOutline != null)
{
meshOutline.enabled = true;
}
}
}

/// <summary>
/// Disables all child mesh outlines.
/// </summary>
private void OnDisable()
{
foreach (var meshOutline in meshOutlines)
{
if (meshOutline != null)
{
meshOutline.enabled = false;
}
}
}

/// <summary>
/// Removes any components this component has created.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,10 @@ private void Awake()
/// </summary>
private void OnDestroy()
{
meshFilter.sharedMesh = originalMesh;
if (originalMesh != null)
{
meshFilter.sharedMesh = originalMesh;
}

MeshReference meshReference;
var sharedMesh = meshFilter.sharedMesh;
Expand Down Expand Up @@ -160,44 +163,51 @@ private bool AcquirePreprocessedMesh(out UnityEngine.Mesh mesh)
meshFilter = GetComponent<MeshFilter>();
}

var sharedMesh = meshFilter.sharedMesh;
// No mesh filter, mesh cannot be processed, so return a null mesh.
if (meshFilter == null)
{
mesh = null;

MeshReference meshReference;
return true;
}

originalMesh = meshFilter.sharedMesh;

if (sharedMesh != null)
// No mesh , mesh cannot be processed, so return a null mesh.
if (originalMesh == null)
{
// A non-readable mesh cannot be processed, so return a null mesh.
if (sharedMesh.isReadable == false)
{
Debug.LogWarning($"Mesh smoothing failed because {sharedMesh.name} is not readable. Check \"Read/Write Enabled\" in the mesh's import settings.");
mesh = null;

mesh = null;
return true;
}

return true;
}
// A non-readable mesh cannot be processed, so return a null mesh.
if (originalMesh.isReadable == false)
{
Debug.LogWarning($"Mesh smoothing failed because {originalMesh.name} is not readable. Check \"Read/Write Enabled\" in the mesh's import settings.");

// If this mesh has already been processed, apply the preprocessed mesh and increment the reference count.
if (processedMeshes.TryGetValue(sharedMesh, out meshReference))
{
meshReference.Increment();
mesh = meshReference.Mesh;
meshFilter.mesh = mesh;
mesh = null;

return true;
}
return true;
}

originalMesh = meshFilter.sharedMesh;
MeshReference meshReference;

// If this mesh has already been processed, apply the preprocessed mesh and increment the reference count.
if (processedMeshes.TryGetValue(originalMesh, out meshReference))
{
meshReference.Increment();
mesh = meshReference.Mesh;
meshFilter.mesh = mesh;

return true;
}

// Clone the mesh, and create a mesh reference which can be keyed off either the original mesh or cloned mesh.
mesh = meshFilter.mesh;
meshReference = new MeshReference(mesh);
processedMeshes[mesh] = meshReference;

if (sharedMesh != null)
{
processedMeshes[sharedMesh] = meshReference;
}
processedMeshes[originalMesh] = meshReference;

return false;
}
Expand Down
2 changes: 1 addition & 1 deletion com.microsoft.mrtk.graphicstools.unity/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "com.microsoft.mrtk.graphicstools.unity",
"version": "0.4.16",
"version": "0.4.17",
"displayName": "MRTK Graphics Tools",
"description": "Graphics tools and components for developing Mixed Reality applications in Unity.",
"msftFeatureCategory": "MRTK3",
Expand Down