blob: 4b941b99610ae3cf1ff6c379fac7b62c085b68a1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
using System.Collections.Generic;
using UnityEngine;
namespace NGS.MeshFusionPro;
public class LODMeshFusionSource : MeshFusionSource
{
[SerializeField]
[HideInInspector]
private LODGroup _group;
private LODGroupCombineSource _source;
private CombinedLODGroupPart _part;
private Bounds? _savedBounds;
public override bool TryGetBounds(ref Bounds bounds)
{
if (_source != null)
{
bounds = _source.Bounds;
return true;
}
if (_part != null)
{
bounds = _part.Bounds;
return true;
}
if (_savedBounds.HasValue)
{
bounds = _savedBounds.Value;
return true;
}
if (base.IsIncompatible)
{
return false;
}
LOD[] lODs = _group.GetLODs();
bounds = new Bounds(base.transform.position, Vector3.zero);
for (int i = 0; i < lODs.Length; i++)
{
Renderer[] renderers = lODs[i].renderers;
for (int j = 0; j < renderers.Length; j++)
{
if (!(renderers[j] == null))
{
bounds.Encapsulate(renderers[j].bounds);
}
}
}
_savedBounds = bounds;
return true;
}
protected override void OnSourceCombinedInternal(ICombinedObject root, ICombinedObjectPart part)
{
_part = (CombinedLODGroupPart)part;
}
protected override bool CheckCompatibilityAndGetComponents(out string incompatibilityReason)
{
if (_group == null)
{
_group = GetComponent<LODGroup>();
}
if (_group == null)
{
incompatibilityReason = "LODGroup not found";
return false;
}
incompatibilityReason = "";
MeshFilter filter = null;
Mesh mesh = null;
LOD[] lODs = _group.GetLODs();
for (int i = 0; i < lODs.Length; i++)
{
Renderer[] renderers = lODs[i].renderers;
for (int j = 0; j < renderers.Length; j++)
{
MeshRenderer renderer = renderers[j] as MeshRenderer;
if (!(renderer == null) && !CanCreateCombineSource(renderer.gameObject, ref incompatibilityReason, ref renderer, ref filter, ref mesh))
{
return false;
}
}
}
return true;
}
protected override void CreateSources()
{
_source = new LODGroupCombineSource(_group);
}
protected override IEnumerable<ICombineSource> GetCombineSources()
{
if (_source != null)
{
yield return _source;
}
}
protected override IEnumerable<ICombinedObjectPart> GetCombinedParts()
{
if (_part != null)
{
yield return _part;
}
}
protected override void ClearSources()
{
if (_source != null)
{
_source = null;
}
}
protected override void ClearParts()
{
if (_part != null)
{
_part = null;
}
}
protected override void ToggleComponents(bool enabled)
{
LOD[] lODs = _group.GetLODs();
for (int i = 0; i < lODs.Length; i++)
{
Renderer[] renderers = lODs[i].renderers;
for (int j = 0; j < renderers.Length; j++)
{
renderers[j].enabled = enabled;
}
}
_group.enabled = enabled;
}
}
|