Example #1
0
        void AddTransforms(Transform[] transforms, bool useSearchOptions = true)
        {
            int uniqueLodObjectsCount = uniqueLodObjects.Count;

            for (int i = 0; i < transforms.Length; i++)
            {
                Transform t = transforms[i];

                if (uniqueLodObjectsCount > 0 && uniqueLodObjects.Contains(t))
                {
                    continue;
                }

                CachedGameObject cachedGO = null;

                if (ValidObject(t, ObjectType.Normal, useSearchOptions, ref cachedGO) == 1)
                {
                    if (!hasFoundFirstObject)
                    {
                        bounds.center = cachedGO.mr.bounds.center; hasFoundFirstObject = true;
                    }
                    bounds.Encapsulate(cachedGO.mr.bounds);
                    foundObjects.Add(cachedGO);
                    lodParentHolders[0].lods[0]++;
                }
            }

            if (foundObjects.Count > 0)
            {
                lodParentHolders[0].found = true;
            }
            // Debug.Log("Count " + count);
            // Debug.Log(foundObjects.Count);
        }
Example #2
0
        public void AddFoundObjectsToOctree()
        {
            if (foundObjects.Count > 0 || foundLodObjects.Count > 0)
            {
                octreeContainsObjects = true;
            }
            else
            {
                Debug.Log("No matching GameObjects with chosen search options are found for combining.");
                return;
            }

            foundMaterials.Clear();
            CalcOctreeSize(bounds);

            ObjectOctree.MaxCell.maxCellCount = 0;

            for (int i = 0; i < foundObjects.Count; i++)
            {
                CachedGameObject foundObject = foundObjects[i];
                AddFoundMaterials(foundObject.mr);

                Vector3 position = (searchOptions.objectCenter == ObjectCenter.TransformPosition ? foundObject.t.position : foundObject.mr.bounds.center);
                octree.AddObject(position, this, foundObject, 0, 0);
            }
            for (int i = 0; i < foundLodObjects.Count; i++)
            {
                CachedLodGameObject cachedLodGO = foundLodObjects[i];
                AddFoundMaterials(cachedLodGO.mr);
                octree.AddObject(cachedLodGO.center, this, cachedLodGO, cachedLodGO.lodCount, cachedLodGO.lodLevel);
            }

            foundMaterialsCount = foundMaterials.Count;
        }
Example #3
0
 public MeshObjectsHolder(CachedGameObject cachedGO, Material mat, int subMeshIndex, bool shadowCastingModeTwoSided, int lightmapIndex)
 {
     // Debug.Log(useForLightmapping);
     this.mat = mat;
     this.shadowCastingModeTwoSided = shadowCastingModeTwoSided;
     this.lightmapIndex             = lightmapIndex;
     meshObjects.Add(new MeshObject(cachedGO, subMeshIndex));
 }
Example #4
0
            void AddObjectInternal(MeshCombiner meshCombiner, CachedGameObject cachedGO, Vector3 position, int lodParentIndex, int lodLevel, bool isChangeMode)
            {
                if (level == maxLevels)
                {
                    MaxCell thisCell = (MaxCell)this;

                    if (thisCell.lodParents == null)
                    {
                        thisCell.lodParents = new LODParent[10];
                    }
                    if (thisCell.lodParents[lodParentIndex] == null)
                    {
                        thisCell.lodParents[lodParentIndex] = new LODParent(lodParentIndex + 1);
                    }

                    LODParent lodParent = thisCell.lodParents[lodParentIndex];
                    LODLevel  lod       = lodParent.lodLevels[lodLevel];

                    lod.cachedGOs.Add(cachedGO);
                    if (isChangeMode)
                    {
                        if (SortObject(meshCombiner, lod, cachedGO))
                        {
                            if (!thisCell.hasChanged)
                            {
                                thisCell.hasChanged = true;
                                if (meshCombiner.changedCells == null)
                                {
                                    meshCombiner.changedCells = new List <MaxCell>();
                                }
                                meshCombiner.changedCells.Add(thisCell);
                            }
                            if (!lodParent.hasChanged)
                            {
                                lodParent.hasChanged = true;
                                thisCell.changedLodParents.Add(lodParent);
                            }
                        }
                    }

                    lod.objectCount++;

                    lod.vertCount += cachedGO.mesh.vertexCount;
                    return;
                }
                else
                {
                    bool maxCellCreated;
                    int  index = AddCell <Cell, MaxCell>(ref cells, position, out maxCellCreated);
                    if (maxCellCreated)
                    {
                        MaxCell.maxCellCount++;
                    }
                    cells[index].AddObjectInternal(meshCombiner, cachedGO, position, lodParentIndex, lodLevel, isChangeMode);
                }
            }
Example #5
0
        public MeshObject(CachedGameObject cachedGO, int subMeshIndex)
        {
            this.cachedGO     = cachedGO;
            this.subMeshIndex = subMeshIndex;
            Transform t = cachedGO.t;

            position            = t.position;
            rotation            = t.rotation;
            scale               = t.lossyScale;
            lightmapScaleOffset = cachedGO.mr.lightmapScaleOffset;
        }
Example #6
0
            public bool SortObject(MeshCombiner meshCombiner, LODLevel lod, CachedGameObject cachedGO, bool isChangeMode = false)
            {
                if (cachedGO.mr == null)
                {
                    return(false);
                }

                if (lod.meshObjectsHolders == null)
                {
                    lod.meshObjectsHolders = new List <MeshObjectsHolder>();
                }

                Material[] mats = cachedGO.mr.sharedMaterials;

                // TODO check submeshes and material
                int length = Mathf.Min(cachedGO.mesh.subMeshCount, mats.Length);

                for (int l = 0; l < length; l++)
                {
                    Material mat = mats[l];
                    if (mat == null)
                    {
                        continue;
                    }

                    bool shadowCastingModeTwoSided = (cachedGO.mr.shadowCastingMode == UnityEngine.Rendering.ShadowCastingMode.TwoSided);
                    int  lightmapIndex             = meshCombiner.validCopyBakedLighting ? cachedGO.mr.lightmapIndex : -1;

                    int index = lod.GetSortMeshIndex(mat, shadowCastingModeTwoSided, lightmapIndex);

                    MeshObjectsHolder meshObjectHolder;
                    if (index == -1)
                    {
                        meshObjectHolder = new MeshObjectsHolder(cachedGO, mat, l, shadowCastingModeTwoSided, lightmapIndex);
                        lod.meshObjectsHolders.Add(meshObjectHolder);
                    }
                    else
                    {
                        meshObjectHolder = lod.meshObjectsHolders[index];
                        meshObjectHolder.meshObjects.Add(new MeshObject(cachedGO, l));
                    }

                    if (isChangeMode && !meshObjectHolder.hasChanged)
                    {
                        meshObjectHolder.hasChanged = true;
                        lod.changedMeshObjectsHolders.Add(meshObjectHolder);
                    }
                }

                return(true);
            }
Example #7
0
            public void SortObjects(MeshCombiner meshCombiner)
            {
                if (level == maxLevels)
                {
                    MaxCell thisCell = (MaxCell)this;

                    LODParent[] lodParents = thisCell.lodParents;

                    for (int i = 0; i < lodParents.Length; i++)
                    {
                        LODParent lodParent = lodParents[i];
                        if (lodParent == null)
                        {
                            continue;
                        }

                        for (int j = 0; j < lodParent.lodLevels.Length; j++)
                        {
                            LODLevel lod = lodParent.lodLevels[j];

                            if (lod == null || lod.cachedGOs.Count == 0)
                            {
                                return;
                            }

                            for (int k = 0; k < lod.cachedGOs.Count; ++k)
                            {
                                CachedGameObject cachedGO = lod.cachedGOs.items[k];

                                if (!SortObject(meshCombiner, lod, cachedGO))
                                {
                                    lod.cachedGOs.RemoveAt(k--);
                                }
                            }
                        }
                    }
                }
                else
                {
                    for (int i = 0; i < 8; ++i)
                    {
                        if (cellsUsed[i])
                        {
                            cells[i].SortObjects(meshCombiner);
                        }
                    }
                }
            }
Example #8
0
            // Token: 0x0600307D RID: 12413 RVA: 0x000CDCEC File Offset: 0x000CBEEC
            private void AddObjectInternal(MeshCombiner meshCombiner, CachedGameObject cachedGO, Vector3 position, int lodParentIndex, int lodLevel, bool isChangeMode)
            {
                if (this.level == this.maxLevels)
                {
                    ObjectOctree.MaxCell maxCell = (ObjectOctree.MaxCell) this;
                    if (maxCell.lodParents == null)
                    {
                        maxCell.lodParents = new ObjectOctree.LODParent[10];
                    }
                    if (maxCell.lodParents[lodParentIndex] == null)
                    {
                        maxCell.lodParents[lodParentIndex] = new ObjectOctree.LODParent(lodParentIndex + 1);
                    }
                    ObjectOctree.LODParent lodparent = maxCell.lodParents[lodParentIndex];
                    ObjectOctree.LODLevel  lodlevel  = lodparent.lodLevels[lodLevel];
                    lodlevel.cachedGOs.Add(cachedGO);
                    if (isChangeMode && this.SortObject(meshCombiner, lodlevel, cachedGO, false))
                    {
                        if (!maxCell.hasChanged)
                        {
                            maxCell.hasChanged = true;
                            if (meshCombiner.changedCells == null)
                            {
                                meshCombiner.changedCells = new List <ObjectOctree.MaxCell>();
                            }
                            meshCombiner.changedCells.Add(maxCell);
                        }
                        if (!lodparent.hasChanged)
                        {
                            lodparent.hasChanged = true;
                            maxCell.changedLodParents.Add(lodparent);
                        }
                    }
                    lodlevel.objectCount++;
                    lodlevel.vertCount += cachedGO.mesh.vertexCount;
                    return;
                }
                bool flag;
                int  num = base.AddCell <ObjectOctree.Cell, ObjectOctree.MaxCell>(ref this.cells, position, out flag);

                if (flag)
                {
                    ObjectOctree.MaxCell.maxCellCount++;
                }
                this.cells[num].AddObjectInternal(meshCombiner, cachedGO, position, lodParentIndex, lodLevel, isChangeMode);
            }
Example #9
0
 // Token: 0x0600307E RID: 12414 RVA: 0x000CDE1C File Offset: 0x000CC01C
 public void SortObjects(MeshCombiner meshCombiner)
 {
     if (this.level == this.maxLevels)
     {
         foreach (ObjectOctree.LODParent lodparent in ((ObjectOctree.MaxCell) this).lodParents)
         {
             if (lodparent != null)
             {
                 for (int j = 0; j < lodparent.lodLevels.Length; j++)
                 {
                     ObjectOctree.LODLevel lodlevel = lodparent.lodLevels[j];
                     if (lodlevel == null || lodlevel.cachedGOs.Count == 0)
                     {
                         return;
                     }
                     for (int k = 0; k < lodlevel.cachedGOs.Count; k++)
                     {
                         CachedGameObject cachedGO = lodlevel.cachedGOs.items[k];
                         if (!this.SortObject(meshCombiner, lodlevel, cachedGO, false))
                         {
                             lodlevel.cachedGOs.RemoveAt(k--);
                         }
                     }
                 }
             }
         }
         return;
     }
     for (int l = 0; l < 8; l++)
     {
         if (this.cellsUsed[l])
         {
             this.cells[l].SortObjects(meshCombiner);
         }
     }
 }
Example #10
0
            public bool SortObject(MeshCombiner meshCombiner, LODLevel lod, CachedGameObject cachedGO, bool isChangeMode = false)
            {
                if (cachedGO.mr == null)
                {
                    return(false);
                }

                if (lod.meshObjectsHoldersLookup == null)
                {
                    lod.meshObjectsHoldersLookup = new Dictionary <CombineCondition, MeshObjectsHolder>();
                }

                CombineConditionSettings combineConditions = meshCombiner.combineConditionSettings;

                Material[] mats = cachedGO.mr.sharedMaterials;

                // TODO check submeshes and material
                int length = Mathf.Min(cachedGO.mesh.subMeshCount, mats.Length);

                int rootInstanceId = -1;

                if (meshCombiner.combineMode == CombineMode.DynamicObjects)
                {
                    rootInstanceId = cachedGO.rootInstanceId;

                    if (rootInstanceId == -1)
                    {
                        cachedGO.GetRoot();
                        rootInstanceId = cachedGO.rootInstanceId;
                    }
                }

                for (int l = 0; l < length; l++)
                {
                    Material mat;

                    if (combineConditions.sameMaterial)
                    {
                        mat = mats[l];
                        if (mat == null)
                        {
                            continue;
                        }
                    }
                    else
                    {
                        mat = combineConditions.material;
                    }

                    CombineCondition combineCondition = new CombineCondition();
                    combineCondition.ReadFromGameObject(rootInstanceId, combineConditions, meshCombiner.copyBakedLighting && meshCombiner.validCopyBakedLighting, cachedGO.go, cachedGO.t, cachedGO.mr, mat);

                    MeshObjectsHolder meshObjectHolder;
                    if (!lod.meshObjectsHoldersLookup.TryGetValue(combineCondition, out meshObjectHolder))
                    {
                        meshCombiner.foundCombineConditions.combineConditions.Add(combineCondition);
                        meshObjectHolder = new MeshObjectsHolder(ref combineCondition, mat);
                        lod.meshObjectsHoldersLookup.Add(combineCondition, meshObjectHolder);
                    }

                    meshObjectHolder.meshObjects.Add(new MeshObject(cachedGO, l));

                    if (isChangeMode && !meshObjectHolder.hasChanged)
                    {
                        meshObjectHolder.hasChanged = true;
                        lod.changedMeshObjectsHolders.Add(meshObjectHolder);
                    }
                }

                return(true);
            }
Example #11
0
 public CachedGameObject AddObject(Vector3 position, MeshCombiner meshCombiner, CachedGameObject cachedGO, int lodParentIndex, int lodLevel, bool isChangeMode = false)
 {
     if (InsideBounds(position))
     {
         AddObjectInternal(meshCombiner, cachedGO, position, lodParentIndex, lodLevel, isChangeMode);
         return(cachedGO);
     }
     return(null);
 }
        static public void RemoveOverlap(Transform t, MeshCombineJobManager.MeshCombineJob meshCombineJob, MeshCache.SubMeshCache newMeshCache, ref byte[] vertexIsInsideCollider)
        {
            if (vertexIsInsideCollider == null)
            {
                vertexIsInsideCollider = new byte[65534];
            }

            int overlapLayerMask = meshCombineJob.meshCombiner.overlapLayerMask;
            int voxelizeLayer    = meshCombineJob.meshCombiner.voxelizeLayer;

            int voxelizeLayerMask = 1 << voxelizeLayer;
            int lodGroupLayer     = meshCombineJob.meshCombiner.lodGroupLayer;
            int lodGroupLayerMask = 1 << lodGroupLayer;

            int lodLevel = meshCombineJob.meshObjectsHolder.lodLevel;

            Vector3 cellOffset = meshCombineJob.position;

            CreateOverlapColliders.newT.position = -cellOffset;
            t.parent.position -= cellOffset;

#if !UNITY_2017
            if (!Physics.autoSyncTransforms)
            {
                Physics.SyncTransforms();
            }
#endif

            CreateOverlapColliders.EnableLodLevelCollider(lodLevel, lodGroupLayer);

            Vector3[] newVertices  = newMeshCache.vertices;
            int[]     newTriangles = newMeshCache.triangles;

            FastList <MeshObject> meshObjects = meshCombineJob.meshObjectsHolder.meshObjects;

            int startIndex = meshCombineJob.startIndex;
            int endIndex   = meshCombineJob.endIndex;

            bool queriesHitBackfaces = Physics.queriesHitBackfaces;
            Physics.queriesHitBackfaces = true;

            toCombineGos.Clear();
            for (int i = startIndex; i < endIndex; i++)
            {
                toCombineGos.Add(meshObjects.items[i].cachedGO.go);
            }

            for (int a = startIndex; a < endIndex; a++)
            {
                MeshObject       meshObject = meshObjects.items[a];
                CachedGameObject cachedGO   = meshObject.cachedGO;

                GameObject go;
                CreateOverlapColliders.lookupOrigCollider.TryGetValue(cachedGO.go, out go);

                int startTriangleIndex = meshObject.startNewTriangleIndex;
                int endTriangleIndex   = meshObject.newTriangleCount + startTriangleIndex;

                Bounds bounds = cachedGO.mr.bounds;
                bounds.center -= cellOffset;

                int oldLayer = 0;

                if (go)
                {
                    oldLayer = go.layer;
                    go.layer = voxelizeLayer;
                }

                colliders.SetCount(Physics.OverlapBoxNonAlloc(bounds.center, bounds.extents, colliders.items, Quaternion.identity, overlapLayerMask));

                if (go)
                {
                    go.layer = oldLayer;
                }

                // Debug.Log("collider Count " + colliders.Count);

                if (colliders.Count == 0)
                {
                    continue;
                }

                collidersInfo.SetCount(colliders.Count);

                for (int i = 0; i < colliders.Count; i++)
                {
                    GameObject colliderGo = colliders.items[i].gameObject;
                    collidersInfo.items[i] = new ColliderInfo()
                    {
                        layer = colliderGo.layer, go = colliderGo
                    };
                    colliderGo.layer = voxelizeLayer;
                }

                // Debug.Log("start " + startTriangleIndex + " end " + endTriangleIndex);

                for (int i = startTriangleIndex; i < endTriangleIndex; i += 3)
                {
                    int vertIndexA = newTriangles[i];
                    if (vertIndexA == -1)
                    {
                        continue;
                    }

                    byte isInsideVoxel = vertexIsInsideCollider[vertIndexA];

                    if (isInsideVoxel != outsideVoxel)
                    {
                        tri.a = t.TransformPoint(newVertices[vertIndexA]);

                        hitInfos.SetCount(Physics.RaycastNonAlloc(tri.a, Vector3.up, hitInfos.items, Mathf.Infinity, voxelizeLayerMask));

                        if (!AnythingInside())
                        {
                            vertexIsInsideCollider[vertIndexA] = outsideVoxel; continue;
                        }

                        tri.b = t.TransformPoint(newVertices[newTriangles[i + 1]]);
                        tri.c = t.TransformPoint(newVertices[newTriangles[i + 2]]);

                        if (LinecastAll(tri.a, tri.b, voxelizeLayerMask) && IntersectAny())
                        {
                            continue;
                        }
                        if (LinecastAll(tri.b, tri.c, voxelizeLayerMask) && IntersectAny())
                        {
                            continue;
                        }
                        if (LinecastAll(tri.c, tri.a, voxelizeLayerMask) && IntersectAny())
                        {
                            continue;
                        }
                        if (LinecastAll(tri.a, (tri.b + tri.c) * 0.5f, voxelizeLayerMask) && IntersectAny())
                        {
                            continue;
                        }
                        if (LinecastAll(tri.b, (tri.c + tri.a) * 0.5f, voxelizeLayerMask) && IntersectAny())
                        {
                            continue;
                        }
                        if (LinecastAll(tri.c, (tri.a + tri.b) * 0.5f, voxelizeLayerMask) && IntersectAny())
                        {
                            continue;
                        }

                        //tri.Calc();
                        //Vector3 origin = tri.a + (tri.dirAb / 2) + ((tri.c - tri.h1) / 2);

                        //if (Physics.CheckBox(origin, new Vector3(0.05f, tri.h, tri.ab) / 2, Quaternion.LookRotation(tri.dirAb, tri.dirAc), voxelizeLayerMask))
                        //{
                        //    colliderGO.layer = oldLayer;
                        //    continue;
                        //}

                        if (CreateOverlapColliders.foundLodGroup && AreAllHitInfosALodGroup() && !IsOneColliderGOInToCombineGos() && !CheckAnyInsideOfLodGroups(lodGroupLayerMask, lodLevel))
                        {
                            continue;
                        }

                        meshCombineJob.trianglesRemoved += 3;
                        newTriangles[i] = -1;
                    }
                }

                for (int i = 0; i < colliders.Count; i++)
                {
                    ColliderInfo colliderInfo = collidersInfo.items[i];
                    colliderInfo.go.layer = colliderInfo.layer;
                }
            }

            Array.Clear(vertexIsInsideCollider, 0, newVertices.Length);
            // Debug.Log("Removed " + meshCombineJob.trianglesRemoved);

            newMeshCache.triangles      = newTriangles;
            Physics.queriesHitBackfaces = queriesHitBackfaces;

            t.parent.position += cellOffset;
        }
Example #13
0
        // ==========================================================================================================================

        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);
        }
Example #14
0
            // Token: 0x0600307F RID: 12415 RVA: 0x000CDF0C File Offset: 0x000CC10C
            public bool SortObject(MeshCombiner meshCombiner, ObjectOctree.LODLevel lod, CachedGameObject cachedGO, bool isChangeMode = false)
            {
                if (cachedGO.mr == null)
                {
                    return(false);
                }
                if (lod.meshObjectsHoldersLookup == null)
                {
                    lod.meshObjectsHoldersLookup = new Dictionary <CombineCondition, MeshObjectsHolder>();
                }
                CombineConditionSettings combineConditionSettings = meshCombiner.combineConditionSettings;

                Material[] sharedMaterials = cachedGO.mr.sharedMaterials;
                int        num             = Mathf.Min(cachedGO.mesh.subMeshCount, sharedMaterials.Length);
                int        i = 0;

                while (i < num)
                {
                    Material material;
                    if (!combineConditionSettings.sameMaterial)
                    {
                        material = combineConditionSettings.material;
                        goto IL_75;
                    }
                    material = sharedMaterials[i];
                    if (!(material == null))
                    {
                        goto IL_75;
                    }
IL_119:
                    i++;
                    continue;
IL_75:
                    CombineCondition combineCondition = default(CombineCondition);
                    combineCondition.ReadFromGameObject(combineConditionSettings, meshCombiner.copyBakedLighting && meshCombiner.validCopyBakedLighting, cachedGO.go, cachedGO.mr, material);
                    MeshObjectsHolder meshObjectsHolder;
                    if (!lod.meshObjectsHoldersLookup.TryGetValue(combineCondition, out meshObjectsHolder))
                    {
                        meshCombiner.foundCombineConditions.combineConditions.Add(combineCondition);
                        meshObjectsHolder = new MeshObjectsHolder(ref combineCondition, material);
                        lod.meshObjectsHoldersLookup.Add(combineCondition, meshObjectsHolder);
                    }
                    meshObjectsHolder.meshObjects.Add(new MeshObject(cachedGO, i));
                    if (isChangeMode && !meshObjectsHolder.hasChanged)
                    {
                        meshObjectsHolder.hasChanged = true;
                        lod.changedMeshObjectsHolders.Add(meshObjectsHolder);
                        goto IL_119;
                    }
                    goto IL_119;
                }
                return(true);
            }
Example #15
0
        }                              // Dummy constructor

        public MeshObject(CachedGameObject cachedGO, int subMeshIndex)
        {
        }                                                                         // 0x0000000181390260-0x0000000181390330
Example #16
0
        public void ExecuteHandleObjects(bool active, HandleComponent handleOriginalObjects, HandleComponent handleOriginalLodGroups, bool includeColliders = true)
        {
            Methods.SetChildrenActive(transform, !active);

            if (handleOriginalObjects == HandleComponent.Disable)
            {
                if (includeColliders)
                {
                    SetOriginalCollidersActive(active);
                }

                for (int i = 0; i < foundObjects.Count; i++)
                {
                    CachedGameObject cachedGO = foundObjects[i];

                    if (cachedGO.mr)
                    {
                        cachedGO.mr.enabled = active;
                    }
                    else
                    {
                        Methods.ListRemoveAt(foundObjects, i--);
                    }
                }
                for (int i = 0; i < foundLodObjects.Count; i++)
                {
                    CachedLodGameObject cachedLodGO = foundLodObjects[i];

                    if (cachedLodGO.mr)
                    {
                        cachedLodGO.mr.enabled = active;
                    }
                    else
                    {
                        Methods.ListRemoveAt(foundLodObjects, i--);
                    }
                }
            }
            if (handleOriginalObjects == HandleComponent.Destroy)
            {
                for (int i = 0; i < foundColliders.Count; i++)
                {
                    Collider collider = foundColliders[i];
                    if (collider)
                    {
                        Destroy(collider);
                    }
                    else
                    {
                        Methods.ListRemoveAt(foundColliders, i--);
                    }
                }

                for (int i = 0; i < foundObjects.Count; i++)
                {
                    bool             remove   = false;
                    CachedGameObject cachedGO = foundObjects[i];
                    if (cachedGO.mf)
                    {
                        Destroy(cachedGO.mf);
                    }
                    else
                    {
                        remove = true;
                    }

                    if (cachedGO.mr)
                    {
                        Destroy(cachedGO.mr);
                    }
                    else
                    {
                        remove = true;
                    }

                    if (remove)
                    {
                        Methods.ListRemoveAt(foundObjects, i--);
                    }
                }

                for (int i = 0; i < foundLodObjects.Count; i++)
                {
                    bool             remove   = false;
                    CachedGameObject cachedGO = foundLodObjects[i];
                    if (cachedGO.mf)
                    {
                        Destroy(cachedGO.mf);
                    }
                    else
                    {
                        remove = true;
                    }

                    if (cachedGO.mr)
                    {
                        Destroy(cachedGO.mr);
                    }
                    else
                    {
                        remove = true;
                    }

                    if (remove)
                    {
                        Methods.ListRemoveAt(foundLodObjects, i--);
                    }
                }
            }

            if (handleOriginalLodGroups == HandleComponent.Disable)
            {
                for (int i = 0; i < foundLodGroups.Count; i++)
                {
                    LODGroup lodGroup = foundLodGroups[i];
                    if (lodGroup)
                    {
                        lodGroup.enabled = active;
                    }
                }
            }
            else if (handleOriginalLodGroups == HandleComponent.Destroy)
            {
                for (int i = 0; i < foundLodGroups.Count; i++)
                {
                    LODGroup lodGroup = foundLodGroups[i];
                    if (lodGroup != null)
                    {
                        Destroy(lodGroup);
                    }
                }
            }
        }
Example #17
0
        }                                       // Dummy constructor

        public CachedLodGameObject(CachedGameObject cachedGO, int lodCount, int lodLevel)
        {
        }                                                                                            // 0x0000000180BEA560-0x0000000180BEA770
Example #18
0
        public void ExecuteHandleObjects(bool active)
        {
            // DisableRenderes, DisableGameObject, DisableParentGameObject, DeleteRenderers, DeleteGameObject, DeleteParentGameObject
            if (originalObjects == HandleObjects.DisableRenderes)
            {
                for (int i = 0; i < originalObjectList.Count; i++)
                {
                    originalObjectList[i].mr.enabled = active;
                }
            }
            else if (originalObjects == HandleObjects.DisableGameObject)
            {
                for (int i = 0; i < originalObjectList.Count; i++)
                {
                    originalObjectList[i].go.SetActive(active);
                }
            }
            else if (originalObjects == HandleObjects.DisableParentGameObject)
            {
                for (int i = 0; i < originalObjectList.Count; i++)
                {
                    CachedGameObject cachedGO = originalObjectList[i];
                    if (cachedGO.t.parent != null)
                    {
                        cachedGO.t.parent.gameObject.SetActive(active);
                    }
                }
            }
            else if (originalObjects == HandleObjects.DeleteRenderers)
            {
                for (int i = 0; i < originalObjectList.Count; i++)
                {
                    CachedGameObject cachedGO = originalObjectList[i];
                    Destroy(cachedGO.mf);
                    Destroy(cachedGO.mr);
                }
            }
            else if (originalObjects == HandleObjects.DeleteGameObject)
            {
                for (int i = 0; i < originalObjectList.Count; i++)
                {
                    CachedGameObject cachedGO = originalObjectList[i];
                    if (cachedGO.go != null)
                    {
                        Destroy(cachedGO.go);
                    }
                }
            }
            else if (originalObjects == HandleObjects.DeleteParentGameObject)
            {
                for (int i = 0; i < originalObjectList.Count; i++)
                {
                    CachedGameObject cachedGO = originalObjectList[i];
                    if (cachedGO.t != null)
                    {
                        if (cachedGO.t.parent != null)
                        {
                            Destroy(cachedGO.t.parent.gameObject);
                        }
                    }
                }
            }

            if (originalObjectsLODGroups == HandleLODGroups.Disable)
            {
                for (int i = 0; i < originalObjectList.Count; i++)
                {
                    CachedGameObject cachedGO = originalObjectList[i];
                    if (cachedGO.t != null)
                    {
                        LODGroup lodGroup = cachedGO.t.GetComponentInParent <LODGroup>();
                        if (lodGroup != null)
                        {
                            lodGroup.enabled = active;
                        }
                    }
                }
            }
            else if (originalObjectsLODGroups == HandleLODGroups.Delete)
            {
                for (int i = 0; i < originalObjectList.Count; i++)
                {
                    CachedGameObject cachedGO = originalObjectList[i];
                    if (cachedGO.t != null)
                    {
                        LODGroup lodGroup = cachedGO.t.GetComponentInParent <LODGroup>();
                        if (lodGroup != null)
                        {
                            Destroy(lodGroup);
                        }
                    }
                }
            }
        }
Example #19
0
 public CachedLodGameObject(CachedGameObject cachedGO, int lodCount, int lodLevel) : base(cachedGO.searchParentT, cachedGO.go, cachedGO.t, cachedGO.mr, cachedGO.mf, cachedGO.mesh)
 {
     this.lodCount = lodCount;
     this.lodLevel = lodLevel;
 }
Example #20
0
        // ==========================================================================================================================

        void AddLodGroups(LODGroup[] lodGroups, bool useSearchOptions = true)
        {
            List <CachedLodGameObject> cachedLodRenderers = new List <CachedLodGameObject>();

            CachedGameObject cachedGODummy = null;

            for (int i = 0; i < lodGroups.Length; i++)
            {
                LODGroup lodGroup = lodGroups[i];

                bool validLodGroup;

                if (searchOptions.lodGroupSearchMode == SearchOptions.LODGroupSearchMode.LodGroup)
                {
                    validLodGroup = (ValidObject(lodGroup.transform, ObjectType.LodGroup, useSearchOptions, ref cachedGODummy) == 1);
                }
                else
                {
                    if (searchOptions.onlyActive && !lodGroup.gameObject.activeInHierarchy)
                    {
                        continue;
                    }
                    validLodGroup = true;
                }

                LOD[] lods           = lodGroup.GetLODs();
                int   lodParentIndex = lods.Length - 1;

                if (lodParentIndex <= 0)
                {
                    continue;
                }
                // Debug.Log(lods.Length);

                Vector3 center = Vector3.zero;

                int rendererCount = 0;

                for (int j = 0; j < lods.Length; j++)
                {
                    LOD lod = lods[j];

                    for (int k = 0; k < lod.renderers.Length; k++)
                    {
                        Renderer r = lod.renderers[k];

                        if (!r)
                        {
                            continue;
                        }

                        if (validLodGroup)
                        {
                            CachedGameObject cachedGO = null;

                            int result = ValidObject(r.transform, ObjectType.LodRenderer, useSearchOptions, ref cachedGO);

                            if (result == -1)
                            {
                                continue;
                            }
                            else if (result == -2)
                            {
                                cachedLodRenderers.Clear();
                                goto breakLoop;
                            }

                            cachedLodRenderers.Add(new CachedLodGameObject(cachedGO, lodParentIndex, j));
                            if (searchOptions.objectCenter == ObjectCenter.BoundsCenter)
                            {
                                center += cachedGO.mr.bounds.center;
                                rendererCount++;
                            }
                        }
                        uniqueLodObjects.Add(r.transform);
                    }
                }

breakLoop:

                if (cachedLodRenderers.Count > 0)
                {
                    if (searchOptions.objectCenter == ObjectCenter.BoundsCenter)
                    {
                        center /= rendererCount;
                    }
                    else
                    {
                        center = lodGroup.transform.position;
                    }

                    for (int j = 0; j < cachedLodRenderers.Count; j++)
                    {
                        CachedLodGameObject cachedLodGO = cachedLodRenderers[j];
                        cachedLodGO.center = center;
                        if (!hasFoundFirstObject)
                        {
                            bounds.center = cachedLodGO.mr.bounds.center; hasFoundFirstObject = true;
                        }
                        bounds.Encapsulate(cachedLodGO.mr.bounds);
                        foundLodObjects.Add(cachedLodGO);
                        lodParentHolders[lodParentIndex].found = true;
                        lodParentHolders[lodParentIndex].lods[cachedLodGO.lodLevel]++;
                    }

                    uniqueFoundLodGroups.Add(lodGroup);
                    cachedLodRenderers.Clear();
                }
            }

            foundLodGroups = new List <LODGroup>(uniqueFoundLodGroups);
        }