Ejemplo n.º 1
0
 public void CombinePaintedMeshes(bool autoSelect, MeshFilter[] meshFilters)
 {
     if (meshFilters == null || meshFilters.Length == 0)
     {
         Debug.LogError((object)"MeshBrush: The meshFilters array you passed as an argument to the CombinePaintedMeshes function is empty or null... Combining action cancelled!");
     }
     else
     {
         this.localTransformationMatrix = ((Component)this).get_transform().get_worldToLocalMatrix();
         this.materialToMesh            = new Hashtable();
         int num = 0;
         for (long index = 0; index < meshFilters.LongLength; ++index)
         {
             this.currentMeshFilter = meshFilters[index];
             num += this.currentMeshFilter.get_sharedMesh().get_vertexCount();
             if (num > 64000)
             {
                 return;
             }
         }
         for (long index = 0; index < meshFilters.LongLength; ++index)
         {
             this.currentMeshFilter = meshFilters[index];
             this.currentRenderer   = (Renderer)((Component)meshFilters[index]).GetComponent <Renderer>();
             this.instance          = new CombineUtility.MeshInstance();
             this.instance.mesh     = this.currentMeshFilter.get_sharedMesh();
             if (Object.op_Inequality((Object)this.currentRenderer, (Object)null) && this.currentRenderer.get_enabled() && Object.op_Inequality((Object)this.instance.mesh, (Object)null))
             {
                 this.instance.transform = Matrix4x4.op_Multiply(this.localTransformationMatrix, ((Component)this.currentMeshFilter).get_transform().get_localToWorldMatrix());
                 this.materials          = this.currentRenderer.get_sharedMaterials();
                 for (int val1 = 0; val1 < this.materials.Length; ++val1)
                 {
                     this.instance.subMeshIndex = Math.Min(val1, this.instance.mesh.get_subMeshCount() - 1);
                     this.objects = (ArrayList)this.materialToMesh[(object)this.materials[val1]];
                     if (this.objects != null)
                     {
                         this.objects.Add((object)this.instance);
                     }
                     else
                     {
                         this.objects = new ArrayList();
                         this.objects.Add((object)this.instance);
                         this.materialToMesh.Add((object)this.materials[val1], (object)this.objects);
                     }
                 }
                 Object.DestroyImmediate((Object)((Component)this.currentRenderer).get_gameObject());
             }
         }
         foreach (DictionaryEntry dictionaryEntry in this.materialToMesh)
         {
             this.elements  = (ArrayList)dictionaryEntry.Value;
             this.instances = (CombineUtility.MeshInstance[]) this.elements.ToArray(typeof(CombineUtility.MeshInstance));
             GameObject gameObject = new GameObject("Combined mesh");
             gameObject.get_transform().set_parent(((Component)this).get_transform());
             gameObject.get_transform().set_localScale(Vector3.get_one());
             gameObject.get_transform().set_localRotation(Quaternion.get_identity());
             gameObject.get_transform().set_localPosition(Vector3.get_zero());
             gameObject.AddComponent <MeshFilter>();
             gameObject.AddComponent <MeshRenderer>();
             gameObject.AddComponent <SaveCombinedMesh>();
             ((Renderer)gameObject.GetComponent <Renderer>()).set_material((Material)dictionaryEntry.Key);
             gameObject.set_isStatic(true);
             this.currentMeshFilter = (MeshFilter)gameObject.GetComponent <MeshFilter>();
             this.currentMeshFilter.set_mesh(CombineUtility.Combine(this.instances, false));
         }
         ((Component)this).get_gameObject().set_isStatic(true);
     }
 }
Ejemplo n.º 2
0
        public void CombinePaintedMeshes(bool autoSelect, MeshFilter[] meshFilters)
        {
            if (meshFilters == null || meshFilters.Length == 0)
            {
                Debug.LogError("MeshBrush: The meshFilters array you passed as an argument to the CombinePaintedMeshes function is empty or null... Combining action cancelled!");
                return;
            }

            localTransformationMatrix = transform.worldToLocalMatrix;
            materialToMesh            = new Hashtable();

            int totalVertCount = 0;

            for (long i = 0; i < meshFilters.LongLength; i++)
            {
                currentMeshFilter = (MeshFilter)meshFilters[i];

                totalVertCount += currentMeshFilter.sharedMesh.vertexCount;

                if (totalVertCount > 64000)
                {
#if UNITY_EDITOR
                    if (UnityEditor.EditorUtility.DisplayDialog("Warning!", "You are trying to combine a group of meshes whose total vertex count exceeds Unity's built-in limit.\n\nThe process has been aborted to prevent the accidental deletion of all painted meshes and numerous disturbing error messages printed to the console.\n\nConsider splitting your meshes into smaller groups and combining them separately.\n\n=> You can do that for example based on the circle brush's area (press the combine meshes key in the scene view), or via multiple MeshBrush instances to form various painting sets and combine them individually; see the help section in the inspector for more detailed infos!", "Okay"))
                    {
                        return;
                    }
#endif
                    return;
                }
            }

            for (long i = 0; i < meshFilters.LongLength; i++)
            {
                currentMeshFilter = (MeshFilter)meshFilters[i];
                currentRenderer   = meshFilters[i].GetComponent <Renderer>();

                instance      = new CombineUtility.MeshInstance();
                instance.mesh = currentMeshFilter.sharedMesh;

                if (currentRenderer != null && currentRenderer.enabled && instance.mesh != null)
                {
                    instance.transform = localTransformationMatrix * currentMeshFilter.transform.localToWorldMatrix;

                    materials = currentRenderer.sharedMaterials;
                    for (int m = 0; m < materials.Length; m++)
                    {
                        instance.subMeshIndex = System.Math.Min(m, instance.mesh.subMeshCount - 1);

                        objects = (ArrayList)materialToMesh[materials[m]];
                        if (objects != null)
                        {
                            objects.Add(instance);
                        }
                        else
                        {
                            objects = new ArrayList();
                            objects.Add(instance);
                            materialToMesh.Add(materials[m], objects);
                        }
                    }

                    DestroyImmediate(currentRenderer.gameObject);
                }
            }

            foreach (DictionaryEntry de in materialToMesh)
            {
                elements  = (ArrayList)de.Value;
                instances = (CombineUtility.MeshInstance[])elements.ToArray(typeof(CombineUtility.MeshInstance));

                var go = new GameObject("Combined mesh");

                go.transform.parent        = transform;
                go.transform.localScale    = Vector3.one;
                go.transform.localRotation = Quaternion.identity;
                go.transform.localPosition = Vector3.zero;
                go.AddComponent <MeshFilter>();
                go.AddComponent <MeshRenderer>();
                go.AddComponent <SaveCombinedMesh>();
                go.GetComponent <Renderer>().material = (Material)de.Key;
                go.isStatic = true;

                currentMeshFilter      = go.GetComponent <MeshFilter>();
                currentMeshFilter.mesh = CombineUtility.Combine(instances, false);

#if UNITY_EDITOR
                if (autoSelect)
                {
                    UnityEditor.Selection.activeObject = go;
                }
#endif
            }
            gameObject.isStatic = true;
        }
Ejemplo n.º 3
0
        public void CombinePaintedMeshes(bool autoSelect)
        {
            meshFilters = GetComponentsInChildren<MeshFilter>();
            myTransform = transform.worldToLocalMatrix;
            materialToMesh = new Hashtable();

            int totalVertCount = 0;
            for (long i = 0 ; i < meshFilters.LongLength ; i++)
            {
                filter = (MeshFilter)meshFilters[i];

                totalVertCount += filter.sharedMesh.vertexCount;

                if (totalVertCount > 64000)
                {
                    #if UNITY_EDITOR
                    if (UnityEditor.EditorUtility.DisplayDialog("Warning!", "You are trying to combine a group of meshes whose total vertex count exceeds Unity's built-in limit.\n\nThe process has been aborted to prevent the accidental deletion of all painted meshes and numerous disturbing error messages printed to the console.\n\nConsider splitting your meshes into smaller groups and combining them separately.", "Okay"))
                    {
                        return;
                    }
                    #endif
                }
            }

            for (long i = 0 ; i < meshFilters.LongLength ; i++)
            {
                filter = (MeshFilter)meshFilters[i];
                curRenderer = meshFilters[i].GetComponent<Renderer>();

                instance = new CombineUtility.MeshInstance();
                instance.mesh = filter.sharedMesh;

                if (curRenderer != null && curRenderer.enabled && instance.mesh != null)
                {
                    instance.transform = myTransform * filter.transform.localToWorldMatrix;

                    materials = curRenderer.sharedMaterials;
                    for (int m = 0 ; m < materials.Length ; m++)
                    {
                        instance.subMeshIndex = System.Math.Min(m, instance.mesh.subMeshCount - 1);

                        objects = (ArrayList)materialToMesh[materials[m]];
                        if (objects != null)
                        {
                            objects.Add(instance);
                        }
                        else
                        {
                            objects = new ArrayList();
                            objects.Add(instance);
                            materialToMesh.Add(materials[m], objects);
                        }
                    }

                    DestroyImmediate(curRenderer.gameObject);
                }
            }

            foreach (DictionaryEntry de in materialToMesh)
            {
                elements = (ArrayList)de.Value;
                instances = (CombineUtility.MeshInstance[])elements.ToArray(typeof(CombineUtility.MeshInstance));

                GameObject go = new GameObject("Combined mesh");
                go.transform.parent = transform;
                go.transform.localScale = Vector3.one;
                go.transform.localRotation = Quaternion.identity;
                go.transform.localPosition = Vector3.zero;
                go.AddComponent<MeshFilter>();
                go.AddComponent<MeshRenderer>();
                go.AddComponent<SaveCombinedMesh>();
                go.GetComponent<Renderer>().material = (Material)de.Key;
                go.isStatic = true;

                filter = go.GetComponent<MeshFilter>();
                filter.mesh = CombineUtility.Combine(instances, false);

                #if UNITY_EDITOR
                if (autoSelect)
                    UnityEditor.Selection.activeObject = go;
                #endif
            }
            gameObject.isStatic = true;
        }
Ejemplo n.º 4
0
        public void CombinePaintedMeshes(bool autoSelect)
        {
            meshFilters    = GetComponentsInChildren <MeshFilter>();
            myTransform    = transform.worldToLocalMatrix;
            materialToMesh = new Hashtable();

            int totalVertCount = 0;

            for (long i = 0; i < meshFilters.LongLength; i++)
            {
                filter = (MeshFilter)meshFilters[i];

                totalVertCount += filter.sharedMesh.vertexCount;

                if (totalVertCount > 64000)
                {
                    #if UNITY_EDITOR
                    if (UnityEditor.EditorUtility.DisplayDialog("Warning!", "You are trying to combine a group of meshes whose total vertex count exceeds Unity's built-in limit.\n\nThe process has been aborted to prevent the accidental deletion of all painted meshes and numerous disturbing error messages printed to the console.\n\nConsider splitting your meshes into smaller groups and combining them separately.", "Okay"))
                    {
                        return;
                    }
                    #endif
                }
            }

            for (long i = 0; i < meshFilters.LongLength; i++)
            {
                filter      = (MeshFilter)meshFilters[i];
                curRenderer = meshFilters[i].GetComponent <Renderer>();

                instance      = new CombineUtility.MeshInstance();
                instance.mesh = filter.sharedMesh;

                if (curRenderer != null && curRenderer.enabled && instance.mesh != null)
                {
                    instance.transform = myTransform * filter.transform.localToWorldMatrix;

                    materials = curRenderer.sharedMaterials;
                    for (int m = 0; m < materials.Length; m++)
                    {
                        instance.subMeshIndex = System.Math.Min(m, instance.mesh.subMeshCount - 1);

                        objects = (ArrayList)materialToMesh[materials[m]];
                        if (objects != null)
                        {
                            objects.Add(instance);
                        }
                        else
                        {
                            objects = new ArrayList();
                            objects.Add(instance);
                            materialToMesh.Add(materials[m], objects);
                        }
                    }

                    DestroyImmediate(curRenderer.gameObject);
                }
            }

            foreach (DictionaryEntry de in materialToMesh)
            {
                elements  = (ArrayList)de.Value;
                instances = (CombineUtility.MeshInstance[])elements.ToArray(typeof(CombineUtility.MeshInstance));

                GameObject go = new GameObject("Combined mesh");
                go.transform.parent        = transform;
                go.transform.localScale    = Vector3.one;
                go.transform.localRotation = Quaternion.identity;
                go.transform.localPosition = Vector3.zero;
                go.AddComponent <MeshFilter>();
                go.AddComponent <MeshRenderer>();
                go.AddComponent <SaveCombinedMesh>();
                go.GetComponent <Renderer>().material = (Material)de.Key;
                go.isStatic = true;

                filter      = go.GetComponent <MeshFilter>();
                filter.mesh = CombineUtility.Combine(instances, false);

                #if UNITY_EDITOR
                if (autoSelect)
                {
                    UnityEditor.Selection.activeObject = go;
                }
                #endif
            }
            gameObject.isStatic = true;
        }
Ejemplo n.º 5
0
        public void CombinePaintedMeshes(bool autoSelect, MeshFilter[] meshFilters)
        {
            if (meshFilters == null || meshFilters.Length == 0)
            {
                Debug.LogError("MeshBrush: The meshFilters array you passed in as a parameter to the CombinePaintedMeshes function is empty or null... Combining action cancelled!");
                return;
            }

            myTransform = transform.worldToLocalMatrix;
            materialToMesh = new Hashtable();

            int totalVertCount = 0;
            for (long i = 0 ; i < meshFilters.LongLength ; i++)
            {
                filter = (MeshFilter)meshFilters[i];

                totalVertCount += filter.sharedMesh.vertexCount;

                if (totalVertCount > 64000)
                {
                    if (UnityEditor.EditorUtility.DisplayDialog("Warning!", "You are trying to combine a group of meshes whose total vertex count exceeds Unity's built-in limit.\n\nThe process has been aborted to prevent the accidental deletion of all painted meshes and numerous disturbing error messages printed to the console.\n\nConsider splitting your meshes into smaller groups and combining them separately.\n\n=> You can do that for example based on the circle brush's area (press the combine meshes key in the scene view), or via multiple MeshBrush instances to form various painting sets and combine them individually; see the help section in the inspector for more detailed infos!", "Okay"))
                    {
                        return;
                    }
                }
            }

            for (long i = 0 ; i < meshFilters.LongLength ; i++)
            {
                filter = (MeshFilter)meshFilters[i];
                curRenderer = meshFilters[i].GetComponent<Renderer>();

                instance = new CombineUtility.MeshInstance();
                instance.mesh = filter.sharedMesh;

                if (curRenderer != null && curRenderer.enabled && instance.mesh != null)
                {
                    instance.transform = myTransform * filter.transform.localToWorldMatrix;

                    materials = curRenderer.sharedMaterials;
                    for (int m = 0 ; m < materials.Length ; m++)
                    {
                        instance.subMeshIndex = System.Math.Min(m, instance.mesh.subMeshCount - 1);

                        objects = (ArrayList)materialToMesh[materials[m]];
                        if (objects != null)
                        {
                            objects.Add(instance);
                        }
                        else
                        {
                            objects = new ArrayList();
                            objects.Add(instance);
                            materialToMesh.Add(materials[m], objects);
                        }
                    }

                    DestroyImmediate(curRenderer.gameObject);
                }
            }

            foreach (DictionaryEntry de in materialToMesh)
            {
                elements = (ArrayList)de.Value;
                instances = (CombineUtility.MeshInstance[])elements.ToArray(typeof(CombineUtility.MeshInstance));

                GameObject go = new GameObject("Combined mesh");
                go.transform.parent = transform;
                go.transform.localScale = Vector3.one;
                go.transform.localRotation = Quaternion.identity;
                go.transform.localPosition = Vector3.zero;
                go.AddComponent<MeshFilter>();
                go.AddComponent<MeshRenderer>();
                go.AddComponent<SaveCombinedMesh>();
                go.GetComponent<Renderer>().material = (Material)de.Key;
                go.isStatic = true;

                filter = go.GetComponent<MeshFilter>();
                filter.mesh = CombineUtility.Combine(instances, false);

                if (autoSelect)
                    UnityEditor.Selection.activeObject = go;
            }
            gameObject.isStatic = true;
        }