Skip to content

Commit 6c14f12

Browse files
Mesh Outline Hierarchy Improvements (#124)
1 parent c12e037 commit 6c14f12

3 files changed

Lines changed: 64 additions & 26 deletions

File tree

com.microsoft.mrtk.graphicstools.unity/Runtime/MeshOutline/MeshOutlineHierarchy.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,34 @@ private void Awake()
3939
}
4040
}
4141

42+
/// <summary>
43+
/// Enables all child mesh outlines.
44+
/// </summary>
45+
private void OnEnable()
46+
{
47+
foreach (var meshOutline in meshOutlines)
48+
{
49+
if (meshOutline != null)
50+
{
51+
meshOutline.enabled = true;
52+
}
53+
}
54+
}
55+
56+
/// <summary>
57+
/// Disables all child mesh outlines.
58+
/// </summary>
59+
private void OnDisable()
60+
{
61+
foreach (var meshOutline in meshOutlines)
62+
{
63+
if (meshOutline != null)
64+
{
65+
meshOutline.enabled = false;
66+
}
67+
}
68+
}
69+
4270
/// <summary>
4371
/// Removes any components this component has created.
4472
/// </summary>

com.microsoft.mrtk.graphicstools.unity/Runtime/MeshOutline/MeshSmoother.cs

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,10 @@ private void Awake()
128128
/// </summary>
129129
private void OnDestroy()
130130
{
131-
meshFilter.sharedMesh = originalMesh;
131+
if (originalMesh != null)
132+
{
133+
meshFilter.sharedMesh = originalMesh;
134+
}
132135

133136
MeshReference meshReference;
134137
var sharedMesh = meshFilter.sharedMesh;
@@ -160,44 +163,51 @@ private bool AcquirePreprocessedMesh(out UnityEngine.Mesh mesh)
160163
meshFilter = GetComponent<MeshFilter>();
161164
}
162165

163-
var sharedMesh = meshFilter.sharedMesh;
166+
// No mesh filter, mesh cannot be processed, so return a null mesh.
167+
if (meshFilter == null)
168+
{
169+
mesh = null;
164170

165-
MeshReference meshReference;
171+
return true;
172+
}
173+
174+
originalMesh = meshFilter.sharedMesh;
166175

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

174-
mesh = null;
181+
return true;
182+
}
175183

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

179-
// If this mesh has already been processed, apply the preprocessed mesh and increment the reference count.
180-
if (processedMeshes.TryGetValue(sharedMesh, out meshReference))
181-
{
182-
meshReference.Increment();
183-
mesh = meshReference.Mesh;
184-
meshFilter.mesh = mesh;
189+
mesh = null;
185190

186-
return true;
187-
}
191+
return true;
188192
}
189193

190-
originalMesh = meshFilter.sharedMesh;
194+
MeshReference meshReference;
195+
196+
// If this mesh has already been processed, apply the preprocessed mesh and increment the reference count.
197+
if (processedMeshes.TryGetValue(originalMesh, out meshReference))
198+
{
199+
meshReference.Increment();
200+
mesh = meshReference.Mesh;
201+
meshFilter.mesh = mesh;
202+
203+
return true;
204+
}
191205

192206
// Clone the mesh, and create a mesh reference which can be keyed off either the original mesh or cloned mesh.
193207
mesh = meshFilter.mesh;
194208
meshReference = new MeshReference(mesh);
195209
processedMeshes[mesh] = meshReference;
196-
197-
if (sharedMesh != null)
198-
{
199-
processedMeshes[sharedMesh] = meshReference;
200-
}
210+
processedMeshes[originalMesh] = meshReference;
201211

202212
return false;
203213
}

com.microsoft.mrtk.graphicstools.unity/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "com.microsoft.mrtk.graphicstools.unity",
3-
"version": "0.4.16",
3+
"version": "0.4.17",
44
"displayName": "MRTK Graphics Tools",
55
"description": "Graphics tools and components for developing Mixed Reality applications in Unity.",
66
"msftFeatureCategory": "MRTK3",

0 commit comments

Comments
 (0)