diff options
| author | chai <215380520@qq.com> | 2024-05-19 16:05:58 +0800 |
|---|---|---|
| committer | chai <215380520@qq.com> | 2024-05-19 16:05:58 +0800 |
| commit | 8e13e7e2874adc8982e16d1d2ed2e28d7480b45f (patch) | |
| tree | 63ef85c460288891f5a593d69afeca16cba050b3 /Thronefall_1_57/Decompile/NGS.MeshFusionPro/CombineTree.cs | |
| parent | c5f145786f4c6d2fe4bea831dfc16e52228920a5 (diff) | |
+1.57
Diffstat (limited to 'Thronefall_1_57/Decompile/NGS.MeshFusionPro/CombineTree.cs')
| -rw-r--r-- | Thronefall_1_57/Decompile/NGS.MeshFusionPro/CombineTree.cs | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/Thronefall_1_57/Decompile/NGS.MeshFusionPro/CombineTree.cs b/Thronefall_1_57/Decompile/NGS.MeshFusionPro/CombineTree.cs new file mode 100644 index 0000000..2fd39af --- /dev/null +++ b/Thronefall_1_57/Decompile/NGS.MeshFusionPro/CombineTree.cs @@ -0,0 +1,112 @@ +using System; +using UnityEngine; + +namespace NGS.MeshFusionPro; + +public class CombineTree : BinaryTree<CombineTreeNode, ICombineSource> +{ + private ICombinedMeshFactory _factory; + + private float _leafSize; + + private int _vertexLimit; + + public float LeafSize => _leafSize; + + public int VertexLimit => _vertexLimit; + + public ICombinedMeshFactory CombinedMeshFactory => _factory; + + public event Action<CombinedObject> onStaticCombinedObjectCreated; + + public event Action<DynamicCombinedObject> onDynamicCombinedObjectCreated; + + public event Action<CombinedLODGroup> onCombinedLODGroupCreated; + + public CombineTree(ICombinedMeshFactory factory, float leafSize, int vertexLimit) + { + _factory = factory; + _leafSize = leafSize; + _vertexLimit = vertexLimit; + } + + public void Combine() + { + TreeTraversal(delegate(CombineTreeNode node, int depth) + { + node.Combine(); + return true; + }); + } + + protected override CombineTreeNode CreateRoot(ICombineSource source) + { + return CreateNode(source.Position, Vector3.one * _leafSize, isLeaf: true); + } + + protected override CombineTreeNode CreateNode(Vector3 center, Vector3 size, bool isLeaf) + { + CombineTreeNode combineTreeNode = new CombineTreeNode(this, center, size, isLeaf); + combineTreeNode.onStaticCombinedObjectCreated += this.onStaticCombinedObjectCreated; + combineTreeNode.onDynamicCombinedObjectCreated += this.onDynamicCombinedObjectCreated; + combineTreeNode.onCombinedLODGroupCreated += this.onCombinedLODGroupCreated; + return combineTreeNode; + } + + protected override CombineTreeNode ExpandRoot(CombineTreeNode root, ICombineSource target) + { + Bounds bounds = root.Bounds; + Bounds bounds2 = target.Bounds; + Vector3 center = Vector3.zero; + Vector3 size = Vector3.zero; + Vector3 center2 = Vector3.zero; + bool flag = false; + for (int i = 0; i < 3; i++) + { + if (bounds2.min[i] < bounds.min[i]) + { + size = bounds.size; + size[i] *= 2f; + center = bounds.center; + center[i] -= bounds.size[i] / 2f; + center2 = bounds.center; + center2[i] -= bounds.size[i]; + break; + } + if (bounds2.max[i] > bounds.max[i]) + { + size = bounds.size; + size[i] *= 2f; + center = bounds.center; + center[i] += bounds.size[i] / 2f; + center2 = bounds.center; + center2[i] += bounds.size[i]; + flag = true; + break; + } + } + CombineTreeNode combineTreeNode = CreateNode(center, size, isLeaf: false); + CombineTreeNode combineTreeNode2 = CreateNode(center2, bounds.size, root.IsLeaf); + if (flag) + { + combineTreeNode.SetChilds(base.RootInternal, combineTreeNode2); + } + else + { + combineTreeNode.SetChilds(combineTreeNode2, base.RootInternal); + } + return combineTreeNode; + } + + protected override bool Includes(CombineTreeNode node, ICombineSource source) + { + Bounds bounds = node.Bounds; + Bounds bounds2 = source.Bounds; + return bounds.Contains(bounds2); + } + + protected override bool Intersects(CombineTreeNode node, ICombineSource source) + { + return node.Bounds.Contains(source.Position); + } +} |
