Skip to content

Commit 3061fe8

Browse files
committed
Update to version 1.1
1 parent 270ec3d commit 3061fe8

File tree

3 files changed

+62
-10
lines changed

3 files changed

+62
-10
lines changed

QuickOutline/Readme.txt

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ Developed by Chris Nolet (c) 2018
77
Instructions
88
------------
99

10-
To add an outline to an object, drag-and-drop the Outline.cs script onto the
11-
object. The outline materials will be loaded at runtime.
10+
To add an outline to an object, drag-and-drop the Outline.cs
11+
script onto the object. The outline materials will be loaded
12+
at runtime.
1213

1314
You can also add outlines programmatically with:
1415

@@ -18,9 +19,19 @@ You can also add outlines programmatically with:
1819
outline.OutlineColor = Color.yellow;
1920
outline.OutlineWidth = 5f;
2021

21-
The outline script does a small amount of work in Awake(). For best results,
22-
use outline.enabled to toggle the outline. Avoid removing and re-adding the
23-
component if possible.
22+
The outline script does a small amount of work in Awake().
23+
For best results, use outline.enabled to toggle the outline.
24+
Avoid removing and re-adding the component if possible.
2425

25-
For large meshes, you may also like to enable 'Precompute Outline' in the
26-
editor. This will reduce the amount of work performed in Awake().
26+
For large meshes, you may also like to enable 'Precompute
27+
Outline' in the editor. This will reduce the amount of work
28+
performed in Awake().
29+
30+
31+
Troubleshooting
32+
---------------
33+
34+
If the outline appears off-center, please try the following:
35+
36+
1. Set 'Read/Write Enabled' on each model's import settings.
37+
2. Disable 'Optimize Mesh Data' in the player settings.

QuickOutline/Scripts/Outline.cs

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,13 +193,28 @@ void LoadSmoothNormals() {
193193

194194
// Store smooth normals in UV3
195195
meshFilter.sharedMesh.SetUVs(3, smoothNormals);
196+
197+
// Combine submeshes
198+
var renderer = meshFilter.GetComponent<Renderer>();
199+
200+
if (renderer != null) {
201+
CombineSubmeshes(meshFilter.sharedMesh, renderer.sharedMaterials);
202+
}
196203
}
197204

198205
// Clear UV3 on skinned mesh renderers
199206
foreach (var skinnedMeshRenderer in GetComponentsInChildren<SkinnedMeshRenderer>()) {
200-
if (registeredMeshes.Add(skinnedMeshRenderer.sharedMesh)) {
201-
skinnedMeshRenderer.sharedMesh.uv4 = new Vector2[skinnedMeshRenderer.sharedMesh.vertexCount];
207+
208+
// Skip if UV3 has already been reset
209+
if (!registeredMeshes.Add(skinnedMeshRenderer.sharedMesh)) {
210+
continue;
202211
}
212+
213+
// Clear UV3
214+
skinnedMeshRenderer.sharedMesh.uv4 = new Vector2[skinnedMeshRenderer.sharedMesh.vertexCount];
215+
216+
// Combine submeshes
217+
CombineSubmeshes(skinnedMeshRenderer.sharedMesh, skinnedMeshRenderer.sharedMaterials);
203218
}
204219
}
205220

@@ -223,7 +238,7 @@ List<Vector3> SmoothNormals(Mesh mesh) {
223238
var smoothNormal = Vector3.zero;
224239

225240
foreach (var pair in group) {
226-
smoothNormal += mesh.normals[pair.Value];
241+
smoothNormal += smoothNormals[pair.Value];
227242
}
228243

229244
smoothNormal.Normalize();
@@ -237,6 +252,23 @@ List<Vector3> SmoothNormals(Mesh mesh) {
237252
return smoothNormals;
238253
}
239254

255+
void CombineSubmeshes(Mesh mesh, Material[] materials) {
256+
257+
// Skip meshes with a single submesh
258+
if (mesh.subMeshCount == 1) {
259+
return;
260+
}
261+
262+
// Skip if submesh count exceeds material count
263+
if (mesh.subMeshCount > materials.Length) {
264+
return;
265+
}
266+
267+
// Append combined submesh
268+
mesh.subMeshCount++;
269+
mesh.SetTriangles(mesh.triangles, mesh.subMeshCount - 1);
270+
}
271+
240272
void UpdateMaterialProperties() {
241273

242274
// Apply properties according to mode

Readme.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,12 @@ You can also add outlines programmatically with:
3838
The outline script does a small amount of work in Awake(). For best results, use outline.enabled to toggle the outline. Avoid removing and re-adding the component if possible.
3939

4040
For large meshes, you may also like to enable 'Precompute Outline' in the editor. This will reduce the amount of work performed in Awake().
41+
42+
43+
Troubleshooting
44+
---------------
45+
46+
If the outline appears off-center, please try the following:
47+
48+
1. Set 'Read/Write Enabled' on each model's import settings.
49+
2. Disable 'Optimize Mesh Data' in the player settings.

0 commit comments

Comments
 (0)