// ========================================================================================================================== 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); }
// ========================================================================================================================== 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); }