// ========================================================================================================================== public void CalcOctreeSize(Bounds bounds) { float size; int levels; Methods.SnapBoundsAndPreserveArea(ref bounds, cellSize, useCells ? cellOffset : Vector3.zero); if (useCells) { float areaSize = Mathf.Max(Mathw.GetMax(bounds.size), cellSize); levels = Mathf.CeilToInt(Mathf.Log(areaSize / cellSize, 2)); size = (int)Mathf.Pow(2, levels) * cellSize; } else { size = Mathw.GetMax(bounds.size); levels = 0; } if (levels == 0 && octree is ObjectOctree.Cell) { octree = new ObjectOctree.MaxCell(); } else if (levels > 0 && octree is ObjectOctree.MaxCell) { octree = new ObjectOctree.Cell(); } octree.maxLevels = levels; octree.bounds = new Bounds(bounds.center, new Vector3(size, size, size)); // Debug.Log("size " + size + " levels " + levels); }
static public void SnapBoundsAndPreserveArea(ref Bounds bounds, float snapSize, Vector3 offset) { Vector3 newCenter = Mathw.Snap(bounds.center, snapSize) + offset; bounds.size += Mathw.Abs(newCenter - bounds.center) * 2; bounds.center = newCenter; }
// Token: 0x06003041 RID: 12353 RVA: 0x000CB64C File Offset: 0x000C984C public void AutoLodInternal(CombinedLODManager.LOD[] lods, float lodCulledDistance) { if (this.level == this.maxLevels) { CombinedLODManager.MaxCell maxCell = (CombinedLODManager.MaxCell) this; if (lodCulledDistance != -1f && (this.bounds.center - lods[0].sphere.center).sqrMagnitude > lodCulledDistance * lodCulledDistance) { if (maxCell.currentLod != -1) { for (int i = 0; i < lods.Length; i++) { for (int j = 0; j < maxCell.mrList[i].Count; j++) { maxCell.mrList[i][j].enabled = false; } } maxCell.currentLod = -1; } return; } int k = 0; while (k < lods.Length) { bool flag = k >= lods.Length - 1 || Mathw.IntersectAABB3Sphere3(this.box, lods[k].sphere); if (flag) { if (maxCell.currentLod != k) { for (int l = 0; l < lods.Length; l++) { bool enabled = l == k; for (int m = 0; m < maxCell.mrList[l].Count; m++) { maxCell.mrList[l][m].enabled = enabled; } } maxCell.currentLod = k; return; } return; } else { k++; } } return; } else { for (int n = 0; n < 8; n++) { if (this.cellsUsed[n]) { this.cells[n].AutoLodInternal(lods, lodCulledDistance); } } } }
public SectorGrid3D(Int3 sectorCount, Vector3 sectorSize, Vector3 sectorGridOffset) { sectors = new Sector3D <T> [sectorCount.x, sectorCount.y, sectorCount.z]; this.sectorCount = sectorCount; this.sectorSize = sectorSize; this.sectorGridOffset = sectorGridOffset; invSectorSize = Mathw.Divide(1.0f, sectorSize); halfSectorSize = sectorSize / 2; totalSize = Mathw.Scale(sectorSize, sectorCount); halfTotalSize = totalSize * 0.5f; rect = new Rect(sectorGridOffset - halfTotalSize, totalSize); }
public void AutoLodInternal(LOD[] lods, float lodCulledDistance) { if (level == maxLevels) { MaxCell thisCell = (MaxCell)this; if (lodCulledDistance != -1) { float squareDistance = (bounds.center - lods[0].sphere.center).sqrMagnitude; if (squareDistance > lodCulledDistance * lodCulledDistance) { if (thisCell.currentLod != -1) { for (int i = 0; i < lods.Length; i++) { for (int j = 0; j < thisCell.mrList[i].Count; j++) { thisCell.mrList[i][j].enabled = false; } } thisCell.currentLod = -1; } return; } } for (int lodIndex = 0; lodIndex < lods.Length; lodIndex++) { bool intersect; if (lodIndex < lods.Length - 1) { intersect = Mathw.IntersectAABB3Sphere3(box, lods[lodIndex].sphere); } else { intersect = true; } if (intersect) { if (thisCell.currentLod != lodIndex) { for (int i = 0; i < lods.Length; i++) { bool active = (i == lodIndex); for (int j = 0; j < thisCell.mrList[i].Count; j++) { thisCell.mrList[i][j].enabled = active; } } thisCell.currentLod = lodIndex; } break; } } } else { for (int i = 0; i < 8; ++i) { if (cellsUsed[i]) { cells[i].AutoLodInternal(lods, lodCulledDistance); } } } }
// ========================================================================================================================== int ValidObject(Transform t, ObjectType objectType, bool useSearchOptions, ref CachedGameObject cachedGameObject) { GameObject go = t.gameObject; MeshRenderer mr = null; MeshFilter mf = null; Mesh mesh = null; if (objectType != ObjectType.LodGroup || searchOptions.lodGroupSearchMode == SearchOptions.LODGroupSearchMode.LodRenderers) { mr = t.GetComponent <MeshRenderer>(); if (mr == null || !mr.enabled) { return(-1); } mf = t.GetComponent <MeshFilter>(); if (mf == null) { return(-1); } mesh = mf.sharedMesh; if (mesh == null) { return(-1); } if (!mesh.isReadable) { Debug.LogError("Mesh Combine Studio -> Read/Write is disabled on the mesh on GameObject " + go.name + " and can't be combined. Click the 'Make Meshes Readable' in the MCS Inspector to make it automatically readable in the mesh import settings."); unreadableMeshes.Add(mesh); return(-1); } } if (useSearchOptions) { if (searchOptions.onlyActive && !go.activeInHierarchy) { return(-1); } if (objectType != ObjectType.LodRenderer || searchOptions.lodGroupSearchMode == SearchOptions.LODGroupSearchMode.LodRenderers) { if (searchOptions.useLayerMask) { int layer = 1 << t.gameObject.layer; if ((searchOptions.layerMask.value & layer) != layer) { return(-1); } } if (searchOptions.onlyStatic && !go.isStatic) { return(-1); } if (searchOptions.useTag) { if (!t.CompareTag(searchOptions.tag)) { return(-1); } } if (searchOptions.useComponentsFilter) { if (searchOptions.componentCondition == SearchOptions.ComponentCondition.And) { bool pass = true; for (int j = 0; j < searchOptions.componentNameList.Count; j++) { if (t.GetComponent(searchOptions.componentNameList[j]) == null) { pass = false; break; } } if (!pass) { return(-1); } } else if (searchOptions.componentCondition == SearchOptions.ComponentCondition.Or) { bool pass = false; for (int j = 0; j < searchOptions.componentNameList.Count; j++) { if (t.GetComponent(searchOptions.componentNameList[j]) != null) { pass = true; break; } } if (!pass) { return(-1); } } else { bool pass = true; for (int j = 0; j < searchOptions.componentNameList.Count; j++) { if (t.GetComponent(searchOptions.componentNameList[j]) != null) { pass = false; break; } } if (!pass) { return(-1); } } } if (searchOptions.useNameContains) { bool found = false; for (int k = 0; k < searchOptions.nameContainList.Count; k++) { if (Methods.Contains(t.name, searchOptions.nameContainList[k])) { found = true; break; } } if (!found) { return(-1); } } if (searchOptions.useSearchBox) { if (searchOptions.objectCenter == ObjectCenter.BoundsCenter) { if (!searchOptions.searchBoxBounds.Contains(mr.bounds.center)) { return(-2); } } else if (!searchOptions.searchBoxBounds.Contains(t.position)) { return(-2); } } } if (objectType != ObjectType.LodGroup) { if (searchOptions.useVertexInputLimit && mesh.vertexCount > searchOptions.vertexInputLimit) { return(-2); } if (useVertexOutputLimit && mesh.vertexCount > vertexOutputLimit) { return(-2); } if (searchOptions.useMaxBoundsFactor && useCells) { if (Mathw.GetMax(mr.bounds.size) > cellSize * searchOptions.maxBoundsFactor) { return(-2); } } } } if (objectType != ObjectType.LodGroup) { cachedGameObject = new CachedGameObject(go, t, mr, mf, mesh); } return(1); }
// Token: 0x060025AA RID: 9642 RVA: 0x000BC264 File Offset: 0x000BA464 public static void SnapBoundsAndPreserveArea(ref Bounds bounds, float snapSize, Vector3 offset) { Vector3 vector = Mathw.Snap(bounds.center, snapSize) + offset; bounds.size += Mathw.Abs(vector - bounds.center) * 2f; bounds.center = vector; }
// Token: 0x0600258D RID: 9613 RVA: 0x000BB6F0 File Offset: 0x000B98F0 public static bool IntersectAABB3Triangle3(Vector3 boxCenter, Vector3 boxHalfSize, Triangle3 triangle) { Vector3 vector = triangle.a - boxCenter; Vector3 vector2 = triangle.b - boxCenter; Vector3 vector3 = triangle.c - boxCenter; Vector3 lhs = vector2 - vector; Vector3 rhs = vector3 - vector2; Vector3 vector4 = vector - vector3; float fb = Mathw.Abs(lhs[0]); float num = Mathw.Abs(lhs[1]); float fa = Mathw.Abs(lhs[2]); float num2; float num3; if (!Mathw.AxisTest_X01(vector, vector3, boxHalfSize, lhs[2], lhs[1], fa, num, out num2, out num3)) { return(false); } if (!Mathw.AxisTest_Y02(vector, vector3, boxHalfSize, lhs[2], lhs[0], fa, fb, out num2, out num3)) { return(false); } if (!Mathw.AxisTest_Z12(vector2, vector3, boxHalfSize, lhs[1], lhs[0], num, fb, out num2, out num3)) { return(false); } fb = Mathw.Abs(rhs[0]); num = Mathw.Abs(rhs[1]); fa = Mathw.Abs(rhs[2]); if (!Mathw.AxisTest_X01(vector, vector3, boxHalfSize, rhs[2], rhs[1], fa, num, out num2, out num3)) { return(false); } if (!Mathw.AxisTest_Y02(vector, vector3, boxHalfSize, rhs[2], rhs[0], fa, fb, out num2, out num3)) { return(false); } if (!Mathw.AxisTest_Z0(vector, vector2, boxHalfSize, rhs[1], rhs[0], num, fb, out num2, out num3)) { return(false); } fb = Mathw.Abs(vector4[0]); num = Mathw.Abs(vector4[1]); fa = Mathw.Abs(vector4[2]); if (!Mathw.AxisTest_X2(vector, vector2, boxHalfSize, vector4[2], vector4[1], fa, num, out num2, out num3)) { return(false); } if (!Mathw.AxisTest_Y1(vector, vector2, boxHalfSize, vector4[2], vector4[0], fa, fb, out num2, out num3)) { return(false); } if (!Mathw.AxisTest_Z12(vector2, vector3, boxHalfSize, vector4[1], vector4[0], num, fb, out num2, out num3)) { return(false); } Mathw.GetMinMax(vector[0], vector2[0], vector3[0], out num2, out num3); if (num2 > boxHalfSize[0] || num3 < -boxHalfSize[0]) { return(false); } Mathw.GetMinMax(vector[1], vector2[1], vector3[1], out num2, out num3); if (num2 > boxHalfSize[1] || num3 < -boxHalfSize[1]) { return(false); } Mathw.GetMinMax(vector[2], vector2[2], vector3[2], out num2, out num3); return(num2 <= boxHalfSize[2] && num3 >= -boxHalfSize[2] && Mathw.PlaneBoxOverlap(Vector3.Cross(lhs, rhs), vector, boxHalfSize)); }