예제 #1
0
 public void ApplyChanges(MeshCombiner meshCombiner)
 {
     for (int i = 0; i < changedMeshObjectsHolders.Count; i++)
     {
         MeshObjectsHolder meshObjectHolder = changedMeshObjectsHolders.items[i];
         meshObjectHolder.hasChanged = false;
     }
     changedMeshObjectsHolders.Clear();
 }
예제 #2
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);
            }
예제 #3
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);
            }
예제 #4
0
            public int GetSortMeshIndex(Material mat, bool shadowCastingModeTwoSided, int lightmapIndex)
            {
                int matInstanceID = mat.GetInstanceID();

                for (int i = 0; i < meshObjectsHolders.Count; i++)
                {
                    MeshObjectsHolder meshObjectHolder = meshObjectsHolders[i];
                    // if (mat == null) Debug.Log("Material null");
                    if (meshObjectHolder.mat == null)
                    {
                        continue;
                    }                                              // Debug.Log("Sorted mat null");

                    if (meshObjectHolder.mat.GetInstanceID() == matInstanceID && meshObjectHolder.shadowCastingModeTwoSided == shadowCastingModeTwoSided && meshObjectHolder.lightmapIndex == lightmapIndex)
                    {
                        return(i);
                    }

                    // if (meshObjectHolder.mat.name == mat.name && meshObjectHolder.mat.shader == mat.shader && meshObjectHolder.shadowCastingModeTwoSided == shadowCastingModeTwoSided && meshObjectHolder.lightmapIndex == lightmapIndex &&
                    // (!mat.HasProperty("_MainTex") || (mat.HasProperty("_MainTex") && meshObjectHolder.mat.GetTexture("_MainTex") == mat.GetTexture("_MainTex")))) return i;
                }
                return(-1);
            }
예제 #5
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);
            }
예제 #6
0
            public void CombineMeshes(MeshCombiner meshCombiner, int lodParentIndex)
            {
                if (level == maxLevels)
                {
                    MaxCell thisCell = (MaxCell)this;

                    LODParent lodParent = thisCell.lodParents[lodParentIndex];
                    if (lodParent == null)
                    {
                        return;
                    }

                    lodParent.cellGO         = new GameObject(meshCombiner.useCells ? "Cell " + bounds.center : "Combined Objects");
                    lodParent.cellT          = lodParent.cellGO.transform;
                    lodParent.cellT.position = bounds.center;
                    lodParent.cellT.parent   = meshCombiner.lodParentHolders[lodParentIndex].t;

                    if (lodParentIndex > 0)
                    {
                        lodParent.lodGroup = lodParent.cellGO.AddComponent <LODGroup>();
                        lodParent.lodGroup.localReferencePoint = lodParent.cellT.position = bounds.center;
                    }

                    LODLevel[] lods = lodParent.lodLevels;
                    for (int i = 0; i < lods.Length; i++)
                    {
                        LODLevel lod = lodParent.lodLevels[i];
                        if (lod == null || lod.meshObjectsHolders == null)
                        {
                            return;
                        }

                        GameObject lodGO;
                        Transform  lodT = null;

                        if (lodParentIndex > 0)
                        {
                            lodGO       = new GameObject("LOD" + i);
                            lodT        = lodGO.transform;
                            lodT.parent = lodParent.cellT;
                        }

                        for (int k = 0; k < lod.meshObjectsHolders.Count; ++k)
                        {
                            MeshObjectsHolder sortedMeshes = lod.meshObjectsHolders[k];
                            sortedMeshes.lodParent = lodParent;
                            sortedMeshes.lodLevel  = i;
                            MeshCombineJobManager.instance.AddJob(meshCombiner, sortedMeshes, lodParentIndex > 0 ? lodT : lodParent.cellT, bounds.center);
                        }
                    }
                }
                else
                {
                    for (int i = 0; i < 8; ++i)
                    {
                        if (cellsUsed[i])
                        {
                            cells[i].CombineMeshes(meshCombiner, lodParentIndex);
                        }
                    }
                }
            }