コード例 #1
0
 /// <summary>
 /// Organizes all of the objects in the data tree so that DrawCall Minimizer can do its work
 /// </summary>
 /// <param name="filters">An array of MeshFilters that are going to be combined</param>
 /// <param name="myTransform">A Matrix representing the parent object's transform</param>
 /// <param name="allMeshesAndMaterials">The dictionary that all of this information is going to be stored in</param>
 static void OrganizeObjects(MeshFilter[] filters, Matrix4x4 myTransform, IDictionary <string, Dictionary <Material, List <MeshInstance> > > allMeshesAndMaterials)
 {
     for (int i = 0; i < filters.Length; i++)
     {
         Renderer     curRenderer = filters [i].GetComponent <Renderer>();
         MeshInstance instance    = new MeshInstance();
         instance.mesh = filters [i].mesh;
         if (curRenderer != null && curRenderer.enabled && instance.mesh != null)
         {
             instance.transform = myTransform * filters [i].transform.localToWorldMatrix;
             Material[] materials = curRenderer.sharedMaterials;
             for (int m = 0; m < materials.Length; m++)
             {
                 ConfirmDictionaryKeys(allMeshesAndMaterials, materials [m]);
                 instance.subMeshIndex = Mathf.Min(m, instance.mesh.subMeshCount - 1);
                 allMeshesAndMaterials [materials [m].shader.ToString()] [materials [m]].Add(instance);
             }
         }
     }
 }
コード例 #2
0
        /// <summary>
        /// Organizes all of the objects in the data tree so that DrawCall Minimizer can do its work
        /// </summary>
        /// <param name="filters">An array of MeshFilters that are going to be combined</param>
        /// <param name="myTransform">A Matrix representing the parent object's transform</param>
        /// <param name="allMeshesAndMaterials">The dictionary that all of this information is going to be stored in</param>
        static void OrganizeObjects(MeshFilter[] filters, Matrix4x4 myTransform, IDictionary <string, Dictionary <Material, List <MeshInstance> > > allMeshesAndMaterials, bool skipAtlasing)
        {
            for (int i = 0; i < filters.Length; i++)
            {
                Renderer     curRenderer = filters[i].GetComponent <Renderer>();
                MeshInstance instance    = new MeshInstance();
                instance.mesh = filters[i].mesh;
                if (curRenderer != null && curRenderer.enabled && instance.mesh != null)
                {
                    instance.transform = myTransform * filters[i].transform.localToWorldMatrix;
                    Material[] materials = curRenderer.sharedMaterials;
                    for (int m = 0; m < materials.Length; m++)
                    {
                        instance.subMeshIndex = Mathf.Min(m, instance.mesh.subMeshCount - 1);
                        if (skipAtlasing)
                        {
                            Dictionary <Material, List <MeshInstance> > mainList;

                            if (!allMeshesAndMaterials.TryGetValue("", out mainList))
                            {
                                mainList = new Dictionary <Material, List <MeshInstance> >();
                                allMeshesAndMaterials.Add("", mainList);
                            }
                            List <MeshInstance> groupedMeshes;
                            if (!mainList.TryGetValue(materials[m], out groupedMeshes))
                            {
                                groupedMeshes = new List <MeshInstance>();
                                mainList.Add(materials[m], groupedMeshes);
                            }
                            groupedMeshes.Add(instance);
                        }
                        else
                        {
                            ConfirmDictionaryKeys(allMeshesAndMaterials, materials[m]);
                            allMeshesAndMaterials[materials[m].shader.ToString()][materials[m]].Add(instance);
                        }
                    }
                }
            }
        }
コード例 #3
0
ファイル: DCMEditorWindow.cs プロジェクト: satish49/sample124
        /// <summary>
        /// Clears all data and starts things over so everything is funky fresh
        /// </summary>
        private void ResetData()
        {
            _dataTreeNoAtlasing.Clear ();
            _dataTreeWithAtlasing.Clear ();

            _numOfMeshes = 0;
            Matrix4x4 myTransform = _hiddenCombinedObject.transform.worldToLocalMatrix;
            foreach (GameObject go in _combinedObjects) {
                if (go != null) {
                    foreach (MeshFilter mf in go.GetComponentsInChildren<MeshFilter>()) {
                        _numOfMeshes++;
                        Material[] materials = mf.GetComponent<Renderer> ().sharedMaterials;
                        for (int i = 0; i < materials.Length; i++) {
                            MeshInstance currentInstance = new MeshInstance ();
                            currentInstance.mesh = CloneMesh (mf.sharedMesh, i);
                            currentInstance.transform = myTransform * mf.transform.localToWorldMatrix;
                            currentInstance.subMeshIndex = Mathf.Min (i, currentInstance.mesh.subMeshCount - 1);
                            Material currentMaterial = materials [i];

                            FillInUnatlasedDictionary (currentInstance, currentMaterial);
                            FillInAtlasedDictionary (currentInstance, currentMaterial);
                        }
                    }
                }
            }
        }
コード例 #4
0
ファイル: DCMEditorWindow.cs プロジェクト: satish49/sample124
        /// <summary>
        /// Fills the in unatlased dictionary with information gathered from the currently selected meshes
        /// </summary>
        /// <param name="currentInstance">Current MeshInstance to add to the dictionary.</param>
        /// <param name="currentMaterial">Current material to use as a key and possibly add to the dictionary.</param>
        void FillInUnatlasedDictionary(MeshInstance currentInstance, Material currentMaterial)
        {
            Dictionary<Texture, List<MeshInstance>> meshesByTexture;
            if (currentMaterial.mainTexture == null) {
                currentMaterial.mainTexture = TextureCombineUtility.defaultTexture;
            }
            if (_dataTreeNoAtlasing.TryGetValue (currentMaterial, out meshesByTexture)) {
                List<MeshInstance> meshes;

                if (meshesByTexture.TryGetValue (currentMaterial.mainTexture, out meshes)) {
                    meshes.Add (currentInstance);
                } else {
                    meshesByTexture.Add (currentMaterial.mainTexture, new List<MeshInstance> {currentInstance});
                }
            } else {
                _dataTreeNoAtlasing.Add (currentMaterial, new Dictionary<Texture, List<MeshInstance>>{

                    {currentMaterial.mainTexture, new List<MeshInstance> {currentInstance}}
                });
            }
        }
コード例 #5
0
ファイル: DCMEditorWindow.cs プロジェクト: satish49/sample124
 /// <summary>
 /// Fills the in atlased dictionary with information gathered from the currently selected meshes
 /// </summary>
 /// <param name="currentInstance">Current MeshInstance to add to the dictionary.</param>
 /// <param name="currentMaterial">Current material to use as a key and possibly add to the dictionary.</param>
 void FillInAtlasedDictionary(MeshInstance currentInstance, Material currentMaterial)
 {
     Dictionary<Material, List<MeshInstance>> meshesByMaterial;
     if (currentMaterial.mainTexture == null) {
         currentMaterial.mainTexture = TextureCombineUtility.defaultTexture;
     }
     if (_dataTreeWithAtlasing.TryGetValue (currentMaterial.shader.ToString (), out meshesByMaterial)) {
         List<MeshInstance> meshes;
         if (meshesByMaterial.TryGetValue (currentMaterial, out meshes)) {
             meshes.Add (currentInstance);
         } else {
             meshesByMaterial.Add (currentMaterial, new List<MeshInstance>{currentInstance});
         }
     } else {
         _dataTreeWithAtlasing.Add (currentMaterial.shader.ToString (), new Dictionary<Material,  List<MeshInstance>>
                                   {{currentMaterial,new List<MeshInstance>{currentInstance}}});
     }
 }
コード例 #6
0
        /// <summary>
        /// Organizes all of the objects in the data tree so that DrawCall Minimizer can do its work
        /// </summary>
        /// <param name="filters">An array of MeshFilters that are going to be combined</param>
        /// <param name="myTransform">A Matrix representing the parent object's transform</param>
        /// <param name="allMeshesAndMaterials">The dictionary that all of this information is going to be stored in</param>
        static void OrganizeObjects(MeshFilter[] filters, Matrix4x4 myTransform, IDictionary<string, Dictionary<Material, List<MeshInstance>>> allMeshesAndMaterials, bool skipAtlasing)
        {
            for (int i = 0; i < filters.Length; i++) {
                Renderer curRenderer = filters [i].GetComponent<Renderer>();
                MeshInstance instance = new MeshInstance();
                instance.mesh = filters [i].mesh;
                if (curRenderer != null && curRenderer.enabled && instance.mesh != null) {
                    instance.transform = myTransform * filters [i].transform.localToWorldMatrix;
                    Material[] materials = curRenderer.sharedMaterials;
                    for (int m = 0; m < materials.Length; m++) {
                        instance.subMeshIndex = Mathf.Min(m, instance.mesh.subMeshCount - 1);
                        if(skipAtlasing)
                        {
                            Dictionary<Material, List<MeshInstance>> mainList;

                            if(!allMeshesAndMaterials.TryGetValue("", out mainList))
                            {

                                mainList = new Dictionary<Material, List<MeshInstance>>();
                                allMeshesAndMaterials.Add("", mainList);
                            }
                            List<MeshInstance> groupedMeshes;
                            if(!mainList.TryGetValue(materials[m], out groupedMeshes))
                            {
                                groupedMeshes = new List<MeshInstance>();
                                mainList.Add(materials[m], groupedMeshes);
                            }
                            groupedMeshes.Add(instance);
                        }
                        else
                        {
                            ConfirmDictionaryKeys(allMeshesAndMaterials, materials [m]);
                            allMeshesAndMaterials [materials [m].shader.ToString()] [materials [m]].Add(instance);
                        }

                    }
                }
            }
        }
コード例 #7
0
 /// <summary>
 /// Organizes all of the objects in the data tree so that DrawCall Minimizer can do its work
 /// </summary>
 /// <param name="filters">An array of MeshFilters that are going to be combined</param>
 /// <param name="myTransform">A Matrix representing the parent object's transform</param>
 /// <param name="allMeshesAndMaterials">The dictionary that all of this information is going to be stored in</param>
 static void OrganizeObjects(MeshFilter[] filters, Matrix4x4 myTransform, IDictionary<string, Dictionary<Material, List<MeshInstance>>> allMeshesAndMaterials)
 {
     for (int i = 0; i < filters.Length; i++) {
         Renderer curRenderer = filters [i].renderer;
         MeshInstance instance = new MeshInstance();
         instance.mesh = filters [i].mesh;
         if (curRenderer != null && curRenderer.enabled && instance.mesh != null) {
             instance.transform = myTransform * filters [i].transform.localToWorldMatrix;
             Material[] materials = curRenderer.sharedMaterials;
             for (int m = 0; m < materials.Length; m++) {
                 ConfirmDictionaryKeys(allMeshesAndMaterials, materials [m]);
                 instance.subMeshIndex = Mathf.Min(m, instance.mesh.subMeshCount - 1);
                 allMeshesAndMaterials [materials [m].shader.ToString()] [materials [m]].Add(instance);
             }
         }
     }
 }