private static void _bakeAllChildMeshBakers(UnityEngine.Object target, ref SerializedObject grouper)
        {
            MB3_MeshBakerGrouper tbg = (MB3_MeshBakerGrouper)target;
            MB3_TextureBaker     tb  = tbg.GetComponent <MB3_TextureBaker>();

            try
            {
                MB3_MeshBakerCommon[] mBakers = tbg.GetComponentsInChildren <MB3_MeshBakerCommon>();
                for (int i = 0; i < mBakers.Length; i++)
                {
                    bool createdDummyMaterialBakeResult;
                    if (grouper.targetObject == tbg)
                    {
                        MB3_MeshBakerEditorFunctions.BakeIntoCombined(mBakers[i], out createdDummyMaterialBakeResult, ref grouper);
                    }
                    else
                    {
                        MB3_MeshBakerEditorFunctions.BakeIntoCombined(mBakers[i], out createdDummyMaterialBakeResult);
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.LogError(ex.Message + "\n" + ex.StackTrace.ToString());
            }
            finally
            {
                EditorUtility.ClearProgressBar();
            }
        }
Ejemplo n.º 2
0
        private static void DoGeneratePrefabsIfNecessary(MB3_MeshBakerGrouper grouper, List <MB3_MeshBakerCommon> newBakers)
        {
            if (!grouper.prefabOptions_autoGeneratePrefabs &&
                !grouper.prefabOptions_mergeOutputIntoSinglePrefab)
            {
                return;
            }
            if (!MB_BatchPrefabBakerEditorFunctions.ValidateFolderIsInProject("Output Folder", grouper.prefabOptions_outputFolder))
            {
                return;
            }

            if (grouper.prefabOptions_autoGeneratePrefabs)
            {
                for (int i = 0; i < newBakers.Count; i++)
                {
                    MB3_MeshBakerCommon baker = newBakers[i];

                    string path = grouper.prefabOptions_outputFolder;
                    // To handle paths with a different root
                    //path = MB_BatchPrefabBakerEditorFunctions.ConvertAnyPathToProjectRelativePath(path);

                    // Generate a new prefab name
                    string prefabName = baker.name.Replace("MeshBaker", "CombinedMesh");
                    prefabName = prefabName.Replace(" ", "_");
                    prefabName = prefabName.Replace(",", "_");
                    prefabName = prefabName.Trim(Path.GetInvalidFileNameChars());
                    prefabName = prefabName.Trim(Path.GetInvalidPathChars());

                    string pathName = AssetDatabase.GenerateUniqueAssetPath(path + "/" + prefabName + ".prefab");
                    if (pathName == null || pathName.Length == 0)
                    {
                        Debug.LogError("Could not generate prefab " + prefabName + " in folder " + path + ". There is something wrong with the path or prefab name.");
                        continue;
                    }

                    // Generate a new prefab
                    GameObject go = new GameObject(baker.name);
                    GameObject pf = MBVersionEditor.PrefabUtility_CreatePrefab(pathName, go);

                    // Configure the baker to bake into the prefab
                    baker.resultPrefab = pf;
                    baker.resultPrefabLeaveInstanceInSceneAfterBake = true;
                    baker.meshCombiner.outputOption = MB2_OutputOptions.bakeIntoPrefab;
                    if (grouper.parentSceneObject != null)
                    {
                        baker.parentSceneObject = grouper.parentSceneObject;
                    }

                    MB_Utility.Destroy(go);
                }
            }
        }
        public static GameObject CreateNewMeshBaker()
        {
            MB3_TextureBaker[] mbs = (MB3_TextureBaker[])GameObject.FindObjectsOfType(typeof(MB3_TextureBaker));
            Regex regex            = new Regex(@"\((\d+)\)$", RegexOptions.Compiled | RegexOptions.CultureInvariant);
            int   largest          = 0;

            try
            {
                for (int i = 0; i < mbs.Length; i++)
                {
                    Match match = regex.Match(mbs[i].name);
                    if (match.Success)
                    {
                        int val = Convert.ToInt32(match.Groups[1].Value);
                        if (val >= largest)
                        {
                            largest = val + 1;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                if (e == null)
                {
                    e = null;            //Do nothing supress compiler warning
                }
            }
            GameObject nmb = new GameObject("TextureBaker (" + largest + ")");

            nmb.transform.position = Vector3.zero;
            MB3_TextureBaker tb = nmb.AddComponent <MB3_TextureBaker>();

            tb.packingAlgorithm = MB2_PackingAlgorithmEnum.MeshBakerTexturePacker;
            MB3_MeshBakerGrouper mbg       = nmb.AddComponent <MB3_MeshBakerGrouper>();
            GameObject           meshBaker = new GameObject("MultiMeshBaker");
            MB3_MultiMeshBaker   mmb       = meshBaker.AddComponent <MB3_MultiMeshBaker>();

            mmb.meshCombiner.settingsHolder = mbg;
            meshBaker.transform.parent      = nmb.transform;

            return(nmb);
        }
Ejemplo n.º 4
0
        private static void _enableDisableRenderers(UnityEngine.Object target, bool enableRenderers)
        {
            MB3_MeshBakerGrouper tbg = (MB3_MeshBakerGrouper)target;

            try
            {
                MB3_MeshBakerCommon[] mBakers = tbg.GetComponentsInChildren <MB3_MeshBakerCommon>();
                for (int i = 0; i < mBakers.Length; i++)
                {
                    mBakers[i].EnableDisableSourceObjectRenderers(enableRenderers);
                }
            }
            catch (Exception ex)
            {
                Debug.LogError(ex.Message + "\n" + ex.StackTrace.ToString());
            }
            finally
            {
                EditorUtility.ClearProgressBar();
            }
        }
Ejemplo n.º 5
0
        MB3_MeshBakerCommon AddMeshBaker(MB3_MeshBakerGrouper grouper, MB3_TextureBaker tb, string key, List <Renderer> gaws)
        {
            int numVerts = 0;

            for (int i = 0; i < gaws.Count; i++)
            {
                Mesh m = MB_Utility.GetMesh(gaws[i].gameObject);
                if (m != null)
                {
                    numVerts += m.vertexCount;
                }
            }

            GameObject nmb = new GameObject("MeshBaker-" + key);

            nmb.transform.position = Vector3.zero;
            MB3_MeshBakerCommon newMeshBaker;

            if (numVerts >= 65535)
            {
                newMeshBaker = nmb.AddComponent <MB3_MultiMeshBaker>();
                newMeshBaker.useObjsToMeshFromTexBaker = false;
            }
            else
            {
                newMeshBaker = nmb.AddComponent <MB3_MeshBaker>();
                newMeshBaker.useObjsToMeshFromTexBaker = false;
            }

            newMeshBaker.textureBakeResults          = tb.textureBakeResults;
            newMeshBaker.transform.parent            = tb.transform;
            newMeshBaker.meshCombiner.settingsHolder = grouper;
            for (int i = 0; i < gaws.Count; i++)
            {
                newMeshBaker.GetObjectsToCombine().Add(gaws[i].gameObject);
            }

            return(newMeshBaker);
        }
        public override void OnInspectorGUI()
        {
            grouper.Update();
            DrawGrouperInspector();
            if (GUILayout.Button("Generate Mesh Bakers"))
            {
                for (int tIdx = 0; tIdx < targets.Length; tIdx++)
                {
                    _generateMeshBakers(targets[tIdx]);
                }
            }

            if (GUILayout.Button("Bake All Child MeshBakers"))
            {
                for (int tIdx = 0; tIdx < targets.Length; tIdx++)
                {
                    _bakeAllChildMeshBakers(targets[tIdx], ref grouper);
                }
            }

            string buttonTextEnableRenderers = "Disable Renderers On All Child MeshBaker Source Objs";
            bool   enableRenderers           = false;

            {
                MB3_MeshBakerGrouper tbg = (MB3_MeshBakerGrouper)target;
                MB3_MeshBakerCommon  bc  = tbg.GetComponentInChildren <MB3_MeshBakerCommon>();
                if (bc != null && bc.GetObjectsToCombine().Count > 0)
                {
                    GameObject go = bc.GetObjectsToCombine()[0];
                    if (go != null && go.GetComponent <Renderer>() != null && go.GetComponent <Renderer>().enabled == false)
                    {
                        buttonTextEnableRenderers = "Enable Renderers On All Child MeshBaker Source Objs";
                        enableRenderers           = true;
                    }
                }
            }

            if (GUILayout.Button(buttonTextEnableRenderers))
            {
                for (int tIdx = 0; tIdx < targets.Length; tIdx++)
                {
                    _enableDisableRenderers(targets[tIdx], enableRenderers);
                }
            }

            if (GUILayout.Button("Delete All Child Mesh Bakers & Combined Meshes"))
            {
                if (EditorUtility.DisplayDialog("Delete Mesh Bakers", "Delete all child mesh bakers", "OK", "Cancel"))
                {
                    for (int i = 0; i < targets.Length; i++)
                    {
                        MB3_MeshBakerGrouper tbg = (MB3_MeshBakerGrouper)targets[i];
                        tbg.DeleteAllChildMeshBakers();
                    }
                }
            }


            if (DateTime.UtcNow.Ticks - lastBoundsCheckRefreshTime > 10000000)
            {
                MB3_TextureBaker tb = ((MB3_MeshBakerGrouper)target).GetComponent <MB3_TextureBaker>();
                if (tb != null)
                {
                    MB3_MeshBakerGrouper tbg = (MB3_MeshBakerGrouper)target;
                    List <GameObject>    gos = tb.GetObjectsToCombine();
                    Bounds b = new Bounds(Vector3.zero, Vector3.one);
                    if (gos.Count > 0 && gos[0] != null && gos[0].GetComponent <Renderer>() != null)
                    {
                        b = gos[0].GetComponent <Renderer>().bounds;
                    }
                    for (int i = 0; i < gos.Count; i++)
                    {
                        if (gos[i] != null && gos[i].GetComponent <Renderer>() != null)
                        {
                            b.Encapsulate(gos[i].GetComponent <Renderer>().bounds);
                        }
                    }

                    tbg.sourceObjectBounds     = b;
                    lastBoundsCheckRefreshTime = DateTime.UtcNow.Ticks;
                }
            }

            grouper.ApplyModifiedProperties();
        }
        private static void _generateMeshBakers(UnityEngine.Object target)
        {
            MB3_MeshBakerGrouper tbg = (MB3_MeshBakerGrouper)target;
            MB3_TextureBaker     tb  = tbg.GetComponent <MB3_TextureBaker>();

            if (tb == null)
            {
                Debug.LogError("There must be an MB3_TextureBaker attached to this game object.");
                return;
            }

            if (tb.GetObjectsToCombine().Count == 0)
            {
                Debug.LogError("The MB3_MeshBakerGrouper creates clusters based on the objects to combine in the MB3_TextureBaker component. There were no objects in this list.");
                return;
            }

            if (tbg.parentSceneObject == null ||
                !MB_Utility.IsSceneInstance(tbg.parentSceneObject.gameObject))
            {
                GameObject g = new GameObject("CombinedMeshes-" + tbg.name);
                tbg.parentSceneObject = g.transform;
            }

            //check if any of the objes that will be added to bakers already exist in child bakers
            List <GameObject> objsWeAreGrouping = tb.GetObjectsToCombine();

            MB3_MeshBakerCommon[] alreadyExistBakers = tbg.GetComponentsInChildren <MB3_MeshBakerCommon>();
            bool foundChildBakersWithObjsToCombine   = false;

            for (int i = 0; i < alreadyExistBakers.Length; i++)
            {
                List <GameObject> childOjs2Combine = alreadyExistBakers[i].GetObjectsToCombine();
                for (int j = 0; j < childOjs2Combine.Count; j++)
                {
                    if (childOjs2Combine[j] != null && objsWeAreGrouping.Contains(childOjs2Combine[j]))
                    {
                        foundChildBakersWithObjsToCombine = true;
                        break;
                    }
                }
            }

            bool proceed = true;

            if (foundChildBakersWithObjsToCombine)
            {
                proceed = EditorUtility.DisplayDialog("Replace Previous Generated Bakers", "Delete child bakers?\n\n" +
                                                      "This grouper has child Mesh Baker objects from a previous clustering. Do you want to delete these and create new ones?", "OK", "Cancel");
            }

            if (tbg.prefabOptions_autoGeneratePrefabs)
            {
                if (!MB_BatchPrefabBakerEditorFunctions.ValidateFolderIsInProject("Output Folder", tbg.prefabOptions_outputFolder))
                {
                    Debug.LogError("If " + gc_prefabOptions_autoGeneratePrefabs.text + " is enabled, you must provide an output folder. Prefabs will be saved in this folder.");
                    proceed = false;
                }
            }

            if (proceed)
            {
                if (foundChildBakersWithObjsToCombine)
                {
                    tbg.DeleteAllChildMeshBakers();
                }
                List <MB3_MeshBakerCommon> newBakers = tbg.grouper.DoClustering(tb, tbg);
                if (newBakers.Count > 0)
                {
                    DoGeneratePrefabsIfNecessary(tbg, newBakers);
                }
            }
        }
        public void DrawGrouperInspector()
        {
            EditorGUILayout.HelpBox("This component helps you group meshes that are close together so they can be combined together." +
                                    " It generates multiple MB3_MeshBaker objects from the List Of Objects to be combined in the MB3_TextureBaker component." +
                                    " Objects that are close together will be grouped together and added to a new child MB3_MeshBaker object.\n\n" +
                                    " TIP: Try the new agglomerative cluster type. It's awsome!", MessageType.Info);
            MB3_MeshBakerGrouper tbg = (MB3_MeshBakerGrouper)target;

            MB3_TextureBaker tb = tbg.GetComponent <MB3_TextureBaker>();

            Transform pgo = (Transform)EditorGUILayout.ObjectField(gc_ParentSceneObject, parentSceneObject.objectReferenceValue, typeof(Transform), true);

            if (pgo != null && MB_Utility.IsSceneInstance(pgo.gameObject))
            {
                parentSceneObject.objectReferenceValue = pgo;
            }
            else
            {
                parentSceneObject.objectReferenceValue = null;
            }

            EditorGUILayout.PropertyField(clusterType, gc_ClusterType);
            MB3_MeshBakerGrouper.ClusterType gg = (MB3_MeshBakerGrouper.ClusterType)clusterType.enumValueIndex;
            if ((gg == MB3_MeshBakerGrouper.ClusterType.none && !(tbg.grouper is MB3_MeshBakerGrouperNone)) ||
                (gg == MB3_MeshBakerGrouper.ClusterType.grid && !(tbg.grouper is MB3_MeshBakerGrouperGrid)) ||
                (gg == MB3_MeshBakerGrouper.ClusterType.pie && !(tbg.grouper is MB3_MeshBakerGrouperPie)) ||
                (gg == MB3_MeshBakerGrouper.ClusterType.agglomerative && !(tbg.grouper is MB3_MeshBakerGrouperCluster))
                )
            {
                tbg.CreateGrouper(gg, tbg.data);
                tbg.clusterType = gg;
            }

            if (clusterType.enumValueIndex == (int)MB3_MeshBakerGrouper.ClusterType.grid)
            {
                EditorGUILayout.PropertyField(gridOrigin, gc_GridOrigin);
                EditorGUILayout.PropertyField(cellSize, gc_CellSize);
            }
            else if (clusterType.enumValueIndex == (int)MB3_MeshBakerGrouper.ClusterType.pie)
            {
                EditorGUILayout.PropertyField(gridOrigin, gc_GridOrigin);
                EditorGUILayout.PropertyField(numSegments, gc_NumSegements);
                EditorGUILayout.PropertyField(pieAxis, gc_PieAxis);
                EditorGUILayout.PropertyField(pieRingSpacing, gc_PieRingSpacing);
                EditorGUILayout.PropertyField(pieCombineAllInCenterRing, gc_PieCombineAllInCenterRing);
            }
            else if (clusterType.enumValueIndex == (int)MB3_MeshBakerGrouper.ClusterType.agglomerative)
            {
                float dist    = clusterDistance.floatValue;
                float maxDist = 100f;
                float minDist = .000001f;
                MB3_MeshBakerGrouperCluster cl = null;
                if (tbg.grouper is MB3_MeshBakerGrouperCluster)
                {
                    cl      = (MB3_MeshBakerGrouperCluster)tbg.grouper;
                    maxDist = cl._ObjsExtents;
                    minDist = cl._minDistBetweenClusters;
                    if (dist < minDist)
                    {
                        dist = Mathf.Lerp(minDist, maxDist, .11f);
                    }
                }

                dist = EditorGUILayout.Slider(gc_ClusterDistance, dist, minDist, maxDist);
                clusterDistance.floatValue = dist;

                string btnName = "Refresh Clusters";
                if (cl.cluster == null || cl.cluster.clusters == null || cl.cluster.clusters.Length == 0)
                {
                    btnName = "Click To Build Clusters";
                }
                if (GUILayout.Button(btnName))
                {
                    if (tbg.grouper is MB3_MeshBakerGrouperCluster)
                    {
                        MB3_MeshBakerGrouperCluster cg = (MB3_MeshBakerGrouperCluster)tbg.grouper;
                        if (tb != null)
                        {
                            cg.BuildClusters(tb.GetObjectsToCombine(), updateProgressBar);
                            EditorUtility.ClearProgressBar();
                            Repaint();
                        }
                    }
                }
            }

            EditorGUILayout.PropertyField(clusterOnLMIndex, gc_ClusterOnLMIndex);
            EditorGUILayout.PropertyField(clusterByLODLevel, gc_ClusterByLODLevel);
            EditorGUILayout.PropertyField(includeCellsWithOnlyOneRenderer, gc_IncludeCellsWithOnlyOneRenderer);
            EditorGUILayout.Space();
            EditorGUILayout.LabelField("Prefab Output Settings", EditorStyles.boldLabel);
            EditorGUILayout.PropertyField(prefabOptions_autoGeneratePrefabs, gc_prefabOptions_autoGeneratePrefabs);
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.PropertyField(prefabOptions_outputFolder, gc_prefabOptions_outputFolder);
            if (GUILayout.Button("Browse"))
            {
                string path = EditorUtility.OpenFolderPanel("Browse For Output Folder", "", "");
                path = MB_BatchPrefabBakerEditorFunctions.ConvertFullPathToProjectRelativePath(path);
                prefabOptions_outputFolder.stringValue = path;
            }
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.Space();
            EditorGUILayout.LabelField("Mesh Baker Settings", EditorStyles.boldLabel);
            EditorGUILayout.HelpBox("These settings will be shared by all created Mesh Bakers.", MessageType.Info);

            UnityEngine.Object oldObjVal = mbSettingsAsset.objectReferenceValue;
            EditorGUILayout.PropertyField(mbSettingsAsset, gc_Settings);

            bool doingTextureArrays = false;

            if (tb != null && tb.textureBakeResults != null)
            {
                doingTextureArrays = tb.textureBakeResults.resultType == MB2_TextureBakeResults.ResultType.textureArray;
            }
            if (mbSettingsAsset.objectReferenceValue == null)
            {
                meshBakerSettingsMe.DrawGUI(tbg.meshBakerSettings, true, doingTextureArrays);
            }
            else
            {
                if (meshBakerSettingsExternal == null || oldObjVal != mbSettingsAsset.objectReferenceValue)
                {
                    UnityEngine.Object targetObj;
                    string             propertyName;
                    ((MB3_MeshCombinerSettings)mbSettingsAsset.objectReferenceValue).GetMeshBakerSettingsAsSerializedProperty(out propertyName, out targetObj);
                    SerializedProperty meshBakerSettings = new SerializedObject(targetObj).FindProperty(propertyName);
                }

                meshBakerSettingsExternal.DrawGUI(((MB3_MeshCombinerSettings)mbSettingsAsset.objectReferenceValue).data, false, doingTextureArrays);
            }
        }
Ejemplo n.º 9
0
        public override void OnInspectorGUI()
        {
            MB3_MeshBakerGrouper tbg = (MB3_MeshBakerGrouper)target;
            MB3_TextureBaker     tb  = ((MB3_MeshBakerGrouper)target).GetComponent <MB3_TextureBaker>();

            grouper.Update();
            DrawGrouperInspector();
            if (GUILayout.Button("Generate Mesh Bakers"))
            {
                if (tb == null)
                {
                    Debug.LogError("There must be an MB3_TextureBaker attached to this game object.");
                    return;
                }

                if (tb.GetObjectsToCombine().Count == 0)
                {
                    Debug.LogError("The MB3_MeshBakerGrouper creates clusters based on the objects to combine in the MB3_TextureBaker component. There were no objects in this list.");
                    return;
                }

                //check if any of the objes that will be added to bakers already exist in child bakers
                List <GameObject>     objsWeAreGrouping  = tb.GetObjectsToCombine();
                MB3_MeshBakerCommon[] alreadyExistBakers = tbg.GetComponentsInChildren <MB3_MeshBakerCommon>();
                bool foundChildBakersWithObjsToCombine   = false;
                for (int i = 0; i < alreadyExistBakers.Length; i++)
                {
                    List <GameObject> childOjs2Combine = alreadyExistBakers[i].GetObjectsToCombine();
                    for (int j = 0; j < childOjs2Combine.Count; j++)
                    {
                        if (childOjs2Combine[j] != null && objsWeAreGrouping.Contains(childOjs2Combine[j]))
                        {
                            foundChildBakersWithObjsToCombine = true;
                            break;
                        }
                    }
                }

                bool proceed = true;
                if (foundChildBakersWithObjsToCombine)
                {
                    proceed = EditorUtility.DisplayDialog("Replace Previous Generated Bakers", "Delete child bakers?\n\n" +
                                                          "This grouper has child Mesh Baker objects from a previous clustering. Do you want to delete these and create new ones?", "OK", "Cancel");
                }

                if (proceed)
                {
                    if (foundChildBakersWithObjsToCombine)
                    {
                        tbg.DeleteAllChildMeshBakers();
                    }
                    ((MB3_MeshBakerGrouper)target).grouper.DoClustering(tb, tbg);
                }
            }
            if (GUILayout.Button("Bake All Child MeshBakers"))
            {
                try
                {
                    MB3_MeshBakerCommon[] mBakers = tbg.GetComponentsInChildren <MB3_MeshBakerCommon>();
                    for (int i = 0; i < mBakers.Length; i++)
                    {
                        bool createdDummyMaterialBakeResult;
                        MB3_MeshBakerEditorFunctions.BakeIntoCombined(mBakers[i], out createdDummyMaterialBakeResult, ref grouper);
                    }
                }
                catch (Exception e)
                {
                    Debug.LogError(e);
                }
                finally
                {
                    EditorUtility.ClearProgressBar();
                }
            }
            string buttonTextEnableRenderers = "Disable Renderers On All Child MeshBaker Source Objs";
            bool   enableRenderers           = false;
            MB3_MeshBakerCommon bc           = tbg.GetComponentInChildren <MB3_MeshBakerCommon>();

            if (bc != null && bc.GetObjectsToCombine().Count > 0)
            {
                GameObject go = bc.GetObjectsToCombine()[0];
                if (go != null && go.GetComponent <Renderer>() != null && go.GetComponent <Renderer>().enabled == false)
                {
                    buttonTextEnableRenderers = "Enable Renderers On All Child MeshBaker Source Objs";
                    enableRenderers           = true;
                }
            }

            if (GUILayout.Button(buttonTextEnableRenderers))
            {
                try
                {
                    MB3_MeshBakerCommon[] mBakers = tbg.GetComponentsInChildren <MB3_MeshBakerCommon>();
                    for (int i = 0; i < mBakers.Length; i++)
                    {
                        mBakers[i].EnableDisableSourceObjectRenderers(enableRenderers);
                    }
                }
                catch (Exception e)
                {
                    Debug.LogError(e);
                }
                finally
                {
                    EditorUtility.ClearProgressBar();
                }
            }

            if (GUILayout.Button("Delete All Child Mesh Bakers & Combined Meshes"))
            {
                if (EditorUtility.DisplayDialog("Delete Mesh Bakers", "Delete all child mesh bakers", "OK", "Cancel"))
                {
                    tbg.DeleteAllChildMeshBakers();
                }
            }


            if (DateTime.UtcNow.Ticks - lastBoundsCheckRefreshTime > 10000000 && tb != null)
            {
                List <GameObject> gos = tb.GetObjectsToCombine();
                Bounds            b   = new Bounds(Vector3.zero, Vector3.one);
                if (gos.Count > 0 && gos[0] != null && gos[0].GetComponent <Renderer>() != null)
                {
                    b = gos[0].GetComponent <Renderer>().bounds;
                }
                for (int i = 0; i < gos.Count; i++)
                {
                    if (gos[i] != null && gos[i].GetComponent <Renderer>() != null)
                    {
                        b.Encapsulate(gos[i].GetComponent <Renderer>().bounds);
                    }
                }
                tbg.sourceObjectBounds     = b;
                lastBoundsCheckRefreshTime = DateTime.UtcNow.Ticks;
            }
            grouper.ApplyModifiedProperties();
        }
Ejemplo n.º 10
0
    public void DrawGrouperInspector()
    {
        EditorGUILayout.HelpBox("This component helps you group meshes that are close together so they can be combined together." +
                                " It generates multiple MB3_MeshBaker objects from the List Of Objects to be combined in the MB3_TextureBaker component." +
                                " Objects that are close together will be grouped together and added to a new child MB3_MeshBaker object.\n\n" +
                                " TIP: Try the new agglomerative cluster type. It's awsome!", MessageType.Info);
        MB3_MeshBakerGrouper grouper = (MB3_MeshBakerGrouper)target;

        EditorGUILayout.PropertyField(clusterType, gc_ClusterType);
        MB3_MeshBakerGrouper.ClusterType gg = (MB3_MeshBakerGrouper.ClusterType)clusterType.enumValueIndex;
        if ((gg == MB3_MeshBakerGrouper.ClusterType.none && !(grouper.grouper is MB3_MeshBakerGrouperNone)) ||
            (gg == MB3_MeshBakerGrouper.ClusterType.grid && !(grouper.grouper is MB3_MeshBakerGrouperGrid)) ||
            (gg == MB3_MeshBakerGrouper.ClusterType.pie && !(grouper.grouper is MB3_MeshBakerGrouperPie)) ||
            (gg == MB3_MeshBakerGrouper.ClusterType.agglomerative && !(grouper.grouper is MB3_MeshBakerGrouperCluster))
            )
        {
            grouper.CreateGrouper(gg, grouper.data);
            grouper.clusterType = gg;
        }

        if (clusterType.enumValueIndex == (int)MB3_MeshBakerGrouper.ClusterType.grid)
        {
            EditorGUILayout.PropertyField(gridOrigin, gc_GridOrigin);
            EditorGUILayout.PropertyField(cellSize, gc_CellSize);
        }
        else if (clusterType.enumValueIndex == (int)MB3_MeshBakerGrouper.ClusterType.pie)
        {
            EditorGUILayout.PropertyField(gridOrigin, gc_GridOrigin);
            EditorGUILayout.PropertyField(numSegments, gc_NumSegements);
            EditorGUILayout.PropertyField(pieAxis, gc_PieAxis);
            EditorGUILayout.PropertyField(pieRingSpacing, gc_PieRingSpacing);
            EditorGUILayout.PropertyField(pieCombineAllInCenterRing, gc_PieCombineAllInCenterRing);
        }
        else if (clusterType.enumValueIndex == (int)MB3_MeshBakerGrouper.ClusterType.agglomerative)
        {
            float dist    = clusterDistance.floatValue;
            float maxDist = 100f;
            float minDist = .000001f;
            MB3_MeshBakerGrouperCluster cl = null;
            if (grouper.grouper is MB3_MeshBakerGrouperCluster)
            {
                cl      = (MB3_MeshBakerGrouperCluster)grouper.grouper;
                maxDist = cl._ObjsExtents;
                minDist = cl._minDistBetweenClusters;
                if (dist < minDist)
                {
                    dist = Mathf.Lerp(minDist, maxDist, .11f);
                }
            }

            dist = EditorGUILayout.Slider(gc_ClusterDistance, dist, minDist, maxDist);
            clusterDistance.floatValue = dist;

            string btnName = "Refresh Clusters";
            if (cl.cluster == null || cl.cluster.clusters == null || cl.cluster.clusters.Length == 0)
            {
                btnName = "Click To Build Clusters";
            }
            if (GUILayout.Button(btnName))
            {
                if (grouper.grouper is MB3_MeshBakerGrouperCluster)
                {
                    MB3_MeshBakerGrouperCluster cg = (MB3_MeshBakerGrouperCluster)grouper.grouper;
                    MB3_TextureBaker            tb = grouper.GetComponent <MB3_TextureBaker>();
                    if (tb != null)
                    {
                        //MB3_EditorMethods em = new MB3_EditorMethods();
                        cg.BuildClusters(tb.GetObjectsToCombine(), updateProgressBar);
                        EditorUtility.ClearProgressBar();
                        Repaint();
                    }
                }
            }
        }

        EditorGUILayout.PropertyField(clusterOnLMIndex, gc_ClusterOnLMIndex);
        EditorGUILayout.PropertyField(clusterByLODLevel, gc_ClusterByLODLevel);
        EditorGUILayout.PropertyField(includeCellsWithOnlyOneRenderer, gc_IncludeCellsWithOnlyOneRenderer);

        EditorGUILayout.Space();
        EditorGUILayout.LabelField("Mesh Baker Settings", EditorStyles.boldLabel);
        EditorGUILayout.HelpBox("These settings will be shared by all created Mesh Bakers.", MessageType.Info);

        UnityEngine.Object oldObjVal = mbSettingsAsset.objectReferenceValue;
        EditorGUILayout.PropertyField(mbSettingsAsset, gc_Settings);

        if (mbSettingsAsset.objectReferenceValue == null)
        {
            meshBakerSettingsMe.DrawGUI(grouper.meshBakerSettings, true);
        }
        else
        {
            if (meshBakerSettingsExternal == null || oldObjVal != mbSettingsAsset.objectReferenceValue)
            {
                meshBakerSettingsExternal = new MB_MeshBakerSettingsEditor();
                meshBakerSettingsExternal.OnEnable(((MB3_MeshCombinerSettings)mbSettingsAsset.objectReferenceValue).GetMeshBakerSettingsAsSerializedProperty());
            }

            meshBakerSettingsExternal.DrawGUI(((MB3_MeshCombinerSettings)mbSettingsAsset.objectReferenceValue).data, false);
        }
    }
Ejemplo n.º 11
0
        public void DoClustering(MB3_TextureBaker tb, MB3_MeshBakerGrouper grouper)
        {
            //todo warn for no objects and no Texture Bake Result
            Dictionary <string, List <Renderer> > cell2objs = FilterIntoGroups(tb.GetObjectsToCombine());

            if (d.clusterOnLMIndex)
            {
                Dictionary <string, List <Renderer> > cell2objsNew = new Dictionary <string, List <Renderer> >();
                foreach (string key in cell2objs.Keys)
                {
                    List <Renderer> gaws = cell2objs[key];
                    Dictionary <int, List <Renderer> > idx2objs = GroupByLightmapIndex(gaws);
                    foreach (int keyIdx in idx2objs.Keys)
                    {
                        string keyNew = key + "-LM-" + keyIdx;
                        cell2objsNew.Add(keyNew, idx2objs[keyIdx]);
                    }
                }
                cell2objs = cell2objsNew;
            }
            if (d.clusterByLODLevel)
            {
                //visit each cell
                //visit each renderer
                //check if that renderer is a child of an LOD group
                //      visit each LOD level check if this renderer is in that list.
                //      if not add it to LOD0 for that cell
                //      otherwise add it to LODX for that cell creating LODs as necessary
                Dictionary <string, List <Renderer> > cell2objsNew = new Dictionary <string, List <Renderer> >();
                foreach (string key in cell2objs.Keys)
                {
                    List <Renderer> gaws = cell2objs[key];
                    foreach (Renderer r in gaws)
                    {
                        if (r == null)
                        {
                            continue;
                        }
                        bool     foundInLOD = false;
                        LODGroup lodg       = r.GetComponentInParent <LODGroup>();
                        if (lodg != null)
                        {
                            LOD[] lods = lodg.GetLODs();
                            for (int i = 0; i < lods.Length; i++)
                            {
                                LOD lod = lods[i];
                                if (Array.Find <Renderer>(lod.renderers, x => x == r) != null)
                                {
                                    foundInLOD = true;
                                    List <Renderer> rs;
                                    string          newKey = String.Format("{0}_LOD{1}", key, i);
                                    if (!cell2objsNew.TryGetValue(newKey, out rs))
                                    {
                                        rs = new List <Renderer>();
                                        cell2objsNew.Add(newKey, rs);
                                    }
                                    if (!rs.Contains(r))
                                    {
                                        rs.Add(r);
                                    }
                                }
                            }
                        }
                        if (!foundInLOD)
                        {
                            List <Renderer> rs;
                            string          newKey = String.Format("{0}_LOD0", key);
                            if (!cell2objsNew.TryGetValue(newKey, out rs))
                            {
                                rs = new List <Renderer>();
                                cell2objsNew.Add(newKey, rs);
                            }
                            if (!rs.Contains(r))
                            {
                                rs.Add(r);
                            }
                        }
                    }
                }
                cell2objs = cell2objsNew;
            }
            int clustersWithOnlyOneRenderer = 0;

            foreach (string key in cell2objs.Keys)
            {
                List <Renderer> gaws = cell2objs[key];
                if (gaws.Count > 1 || grouper.data.includeCellsWithOnlyOneRenderer)
                {
                    AddMeshBaker(grouper, tb, key, gaws);
                }
                else
                {
                    clustersWithOnlyOneRenderer++;
                }
            }
            Debug.Log(String.Format("Found {0} cells with Renderers. Not creating bakers for {1} because there is only one mesh in the cell. Creating {2} bakers.", cell2objs.Count, clustersWithOnlyOneRenderer, cell2objs.Count - clustersWithOnlyOneRenderer));
        }
    public override void OnInspectorGUI()
    {
        MB3_MeshBakerGrouper tbg = (MB3_MeshBakerGrouper)target;
        MB3_TextureBaker     tb  = ((MB3_MeshBakerGrouper)target).GetComponent <MB3_TextureBaker>();

        grouper.Update();
        DrawGrouperInspector();
        EditorGUILayout.PropertyField(includeCellsWithOnlyOneRenderer, gc_IncludeCellsWithOnlyOneRenderer);
        if (GUILayout.Button("Generate Mesh Bakers"))
        {
            if (tb == null)
            {
                Debug.LogError("There must be an MB3_TextureBaker attached to this game object.");
                return;
            }
            if (tb.GetObjectsToCombine().Count == 0)
            {
                Debug.LogError("The MB3_MeshBakerGrouper creates clusters based on the objects to combine in the MB3_TextureBaker component. There were no objects in this list.");
                return;
            }
            //check if any of the objes that will be added to bakers already exist in child bakers
            List <GameObject>     objsWeAreGrouping  = tb.GetObjectsToCombine();
            MB3_MeshBakerCommon[] alreadyExistBakers = tbg.GetComponentsInChildren <MB3_MeshBakerCommon>();
            bool foundChildBakersWithObjsToCombine   = false;
            for (int i = 0; i < alreadyExistBakers.Length; i++)
            {
                List <GameObject> childOjs2Combine = alreadyExistBakers[i].GetObjectsToCombine();
                for (int j = 0; j < childOjs2Combine.Count; j++)
                {
                    if (childOjs2Combine[j] != null && objsWeAreGrouping.Contains(childOjs2Combine[j]))
                    {
                        Debug.LogError("Could not Generate Mesh Bakers. This MeshBakerGrouper already has child MeshBaker's that contain some of the objects to be grouped. Remove these child bakers before trying to Generate Mesh Bakers.");
                        foundChildBakersWithObjsToCombine = true;
                        break;
                    }
                }
                Debug.LogWarning("This MB3_TextureBaker had some existing child objects. You may want to delete these before 'Generating Mesh Bakers' since your source objects may be included in the List Of Objects To Combine of multiple MeshBaker objects.");
            }
            if (!foundChildBakersWithObjsToCombine)
            {
                ((MB3_MeshBakerGrouper)target).grouper.DoClustering(tb, tbg);
            }
        }
        if (GUILayout.Button("Bake All Child MeshBakers"))
        {
            try
            {
                MB3_MeshBakerCommon[] mBakers = tbg.GetComponentsInChildren <MB3_MeshBakerCommon>();
                for (int i = 0; i < mBakers.Length; i++)
                {
                    bool createdDummyMaterialBakeResult;
                    MB3_MeshBakerEditorFunctions.BakeIntoCombined(mBakers[i], out createdDummyMaterialBakeResult);
                }
            }
            catch (Exception e)
            {
                Debug.LogError(e);
            }
            finally
            {
                EditorUtility.ClearProgressBar();
            }
        }
        string buttonTextEnableRenderers = "Disable Renderers On All Child MeshBaker Source Objs";
        bool   enableRenderers           = false;
        MB3_MeshBakerCommon bc           = tbg.GetComponentInChildren <MB3_MeshBakerCommon>();

        if (bc != null && bc.GetObjectsToCombine().Count > 0)
        {
            GameObject go = bc.GetObjectsToCombine()[0];
            if (go != null && go.GetComponent <Renderer>() != null && go.GetComponent <Renderer>().enabled == false)
            {
                buttonTextEnableRenderers = "Enable Renderers On All Child MeshBaker Source Objs";
                enableRenderers           = true;
            }
        }
        if (GUILayout.Button(buttonTextEnableRenderers))
        {
            try
            {
                MB3_MeshBakerCommon[] mBakers = tbg.GetComponentsInChildren <MB3_MeshBakerCommon>();
                for (int i = 0; i < mBakers.Length; i++)
                {
                    mBakers[i].EnableDisableSourceObjectRenderers(enableRenderers);
                }
            }
            catch (Exception e)
            {
                Debug.LogError(e);
            }
            finally
            {
                EditorUtility.ClearProgressBar();
            }
        }
        if (DateTime.UtcNow.Ticks - lastBoundsCheckRefreshTime > 10000000 && tb != null)
        {
            List <GameObject> gos = tb.GetObjectsToCombine();
            Bounds            b   = new Bounds(Vector3.zero, Vector3.one);
            if (gos.Count > 0 && gos[0] != null && gos[0].GetComponent <Renderer>() != null)
            {
                b = gos[0].GetComponent <Renderer>().bounds;
            }
            for (int i = 0; i < gos.Count; i++)
            {
                if (gos[i] != null && gos[i].GetComponent <Renderer>() != null)
                {
                    b.Encapsulate(gos[i].GetComponent <Renderer>().bounds);
                }
            }
            tbg.sourceObjectBounds     = b;
            lastBoundsCheckRefreshTime = DateTime.UtcNow.Ticks;
        }
        grouper.ApplyModifiedProperties();
    }
    public void DrawGrouperInspector()
    {
        EditorGUILayout.HelpBox("This component helps you group meshes that are close together so they can be combined together." +
                                " It generates multiple MB3_MeshBaker objects from the List Of Objects to be combined in the MB3_TextureBaker component." +
                                " Objects that are close together will be grouped together and added to a new child MB3_MeshBaker object.\n\n" +
                                " TIP: Try the new agglomerative cluster type. It's awsome!", MessageType.Info);
        MB3_MeshBakerGrouper grouper = (MB3_MeshBakerGrouper)target;

        EditorGUILayout.PropertyField(clusterType, gc_ClusterType);
        MB3_MeshBakerGrouper.ClusterType gg = (MB3_MeshBakerGrouper.ClusterType)clusterType.enumValueIndex;
        if ((gg == MB3_MeshBakerGrouper.ClusterType.none && !(grouper.grouper is MB3_MeshBakerGrouperNone)) ||
            (gg == MB3_MeshBakerGrouper.ClusterType.grid && !(grouper.grouper is MB3_MeshBakerGrouperGrid)) ||
            (gg == MB3_MeshBakerGrouper.ClusterType.pie && !(grouper.grouper is MB3_MeshBakerGrouperPie)) ||
            (gg == MB3_MeshBakerGrouper.ClusterType.agglomerative && !(grouper.grouper is MB3_MeshBakerGrouperCluster))
            )
        {
            grouper.CreateGrouper(gg, grouper.data);
            grouper.clusterType = gg;
        }
        if (clusterType.enumValueIndex == (int)MB3_MeshBakerGrouper.ClusterType.grid)
        {
            EditorGUILayout.PropertyField(gridOrigin, gc_GridOrigin);
            EditorGUILayout.PropertyField(cellSize, gc_CellSize);
        }
        else if (clusterType.enumValueIndex == (int)MB3_MeshBakerGrouper.ClusterType.pie)
        {
            EditorGUILayout.PropertyField(gridOrigin, gc_GridOrigin);
            EditorGUILayout.PropertyField(numSegments, gc_NumSegements);
            EditorGUILayout.PropertyField(pieAxis, gc_PieAxis);
        }
        else if (clusterType.enumValueIndex == (int)MB3_MeshBakerGrouper.ClusterType.agglomerative)
        {
            float dist    = clusterDistance.floatValue;
            float maxDist = 100f;
            float minDist = .000001f;
            MB3_MeshBakerGrouperCluster cl = null;
            if (grouper.grouper is MB3_MeshBakerGrouperCluster)
            {
                cl      = (MB3_MeshBakerGrouperCluster)grouper.grouper;
                maxDist = cl._ObjsExtents;
                minDist = cl._minDistBetweenClusters;
                if (dist < minDist)
                {
                    dist = Mathf.Lerp(minDist, maxDist, .11f);
                }
            }

            dist = EditorGUILayout.Slider(gc_ClusterDistance, dist, minDist, maxDist);
            clusterDistance.floatValue = dist;

            string btnName = "Refresh Clusters";
            if (cl.cluster == null || cl.cluster.clusters == null || cl.cluster.clusters.Length == 0)
            {
                btnName = "Click To Build Clusters";
            }
            if (GUILayout.Button(btnName))
            {
                if (grouper.grouper is MB3_MeshBakerGrouperCluster)
                {
                    MB3_MeshBakerGrouperCluster cg = (MB3_MeshBakerGrouperCluster)grouper.grouper;
                    MB3_TextureBaker            tb = grouper.GetComponent <MB3_TextureBaker>();
                    if (tb != null)
                    {
                        //MB3_EditorMethods em = new MB3_EditorMethods();
                        cg.BuildClusters(tb.GetObjectsToCombine(), updateProgressBar);
                        EditorUtility.ClearProgressBar();
                        Repaint();
                    }
                }
            }
        }
        EditorGUILayout.PropertyField(clusterOnLMIndex, gc_ClusterOnLMIndex);
        EditorGUILayout.PropertyField(clusterByLODLevel, gc_ClusterByLODLevel);
    }
Ejemplo n.º 14
0
    public override void OnInspectorGUI()
    {
        MB3_MeshBakerGrouper tbg = (MB3_MeshBakerGrouper)target;
        MB3_TextureBaker     tb  = ((MB3_MeshBakerGrouper)target).GetComponent <MB3_TextureBaker>();

        DrawGrouperInspector();
        if (GUILayout.Button("Generate Mesh Bakers"))
        {
            if (tb == null)
            {
                Debug.LogError("There must be an MB3_TextureBaker attached to this game object.");
                return;
            }
            if (tb.GetObjectsToCombine().Count == 0)
            {
                Debug.LogError("The MB3_MeshBakerGrouper creates clusters based on the objects to combine in the MB3_TextureBaker component. There were no objects in this list.");
                return;
            }
            if (tb.transform.childCount > 0)
            {
                Debug.LogWarning("This MB3_TextureBaker had some existing child objects. You may want to delete these before 'Generating Mesh Bakers' since your source objects may be included in the List Of Objects To Combine of multiple MeshBaker objects.");
            }
            if (tb != null)
            {
                ((MB3_MeshBakerGrouper)target).grouper.DoClustering(tb);
            }
            else
            {
                Debug.LogError("MB3_MeshBakerGrouper needs to be attached to an MB3_TextureBaker");
            }
        }
        if (GUILayout.Button("Bake All Child MeshBakers"))
        {
            try
            {
                MB3_MeshBakerCommon[] mBakers = tbg.GetComponentsInChildren <MB3_MeshBakerCommon>();
                for (int i = 0; i < mBakers.Length; i++)
                {
                    if (mBakers[i].textureBakeResults != null)
                    {
                        bool createdDummyMaterialBakeResult;
                        MB3_MeshBakerEditorFunctions.BakeIntoCombined(mBakers[i], out createdDummyMaterialBakeResult);
                    }
                }
            }
            catch (Exception e)
            {
                Debug.LogError(e);
            }
            finally
            {
                EditorUtility.ClearProgressBar();
            }
        }
        string buttonTextEnableRenderers = "Disable Renderers On All Child MeshBaker Source Objs";
        bool   enableRenderers           = false;
        MB3_MeshBakerCommon bc           = tbg.GetComponentInChildren <MB3_MeshBakerCommon>();

        if (bc != null && bc.GetObjectsToCombine().Count > 0)
        {
            GameObject go = bc.GetObjectsToCombine()[0];
            if (go != null && go.GetComponent <Renderer>() != null && go.GetComponent <Renderer>().enabled == false)
            {
                buttonTextEnableRenderers = "Enable Renderers On All Child MeshBaker Source Objs";
                enableRenderers           = true;
            }
        }
        if (GUILayout.Button(buttonTextEnableRenderers))
        {
            try
            {
                MB3_MeshBakerCommon[] mBakers = tbg.GetComponentsInChildren <MB3_MeshBakerCommon>();
                for (int i = 0; i < mBakers.Length; i++)
                {
                    mBakers[i].EnableDisableSourceObjectRenderers(enableRenderers);
                }
            }
            catch (Exception e)
            {
                Debug.LogError(e);
            }
            finally
            {
                EditorUtility.ClearProgressBar();
            }
        }
        if (DateTime.UtcNow.Ticks - lastBoundsCheckRefreshTime > 10000000 && tb != null)
        {
            List <GameObject> gos = tb.GetObjectsToCombine();
            Bounds            b   = new Bounds(Vector3.zero, Vector3.one);
            if (gos.Count > 0 && gos[0] != null && gos[0].GetComponent <Renderer>() != null)
            {
                b = gos[0].GetComponent <Renderer>().bounds;
            }
            for (int i = 0; i < gos.Count; i++)
            {
                if (gos[i] != null && gos[i].GetComponent <Renderer>() != null)
                {
                    b.Encapsulate(gos[i].GetComponent <Renderer>().bounds);
                }
            }
            tbg.sourceObjectBounds     = b;
            lastBoundsCheckRefreshTime = DateTime.UtcNow.Ticks;
        }
        grouper.ApplyModifiedProperties();
    }
Ejemplo n.º 15
0
 private void OnDrawGizmosSelected()
 {
     if (this.grouper == null)
     {
         return;
     }
     if (this.grouper.clusterGrouper == null)
     {
         return;
     }
     if (this.grouper.clusterGrouper.clusterType == MB3_MeshBakerGrouperCore.ClusterType.grid)
     {
         Vector3 cellSize = this.grouper.clusterGrouper.cellSize;
         if (cellSize.x <= 1E-05f || cellSize.y <= 1E-05f || cellSize.z <= 1E-05f)
         {
             return;
         }
         Vector3 vector = this.sourceObjectBounds.center - this.sourceObjectBounds.extents;
         Vector3 origin = this.grouper.clusterGrouper.origin;
         origin.x %= cellSize.x;
         origin.y %= cellSize.y;
         origin.z %= cellSize.z;
         vector.x  = Mathf.Round(vector.x / cellSize.x) * cellSize.x + origin.x;
         vector.y  = Mathf.Round(vector.y / cellSize.y) * cellSize.y + origin.y;
         vector.z  = Mathf.Round(vector.z / cellSize.z) * cellSize.z + origin.z;
         if (vector.x > this.sourceObjectBounds.center.x - this.sourceObjectBounds.extents.x)
         {
             vector.x -= cellSize.x;
         }
         if (vector.y > this.sourceObjectBounds.center.y - this.sourceObjectBounds.extents.y)
         {
             vector.y -= cellSize.y;
         }
         if (vector.z > this.sourceObjectBounds.center.z - this.sourceObjectBounds.extents.z)
         {
             vector.z -= cellSize.z;
         }
         Vector3 vector2 = vector;
         int     num     = Mathf.CeilToInt(this.sourceObjectBounds.size.x / cellSize.x + this.sourceObjectBounds.size.y / cellSize.y + this.sourceObjectBounds.size.z / cellSize.z);
         if (num > 200)
         {
             Gizmos.DrawWireCube(this.grouper.clusterGrouper.origin + cellSize / 2f, cellSize);
         }
         else
         {
             while (vector.x < this.sourceObjectBounds.center.x + this.sourceObjectBounds.extents.x)
             {
                 vector.y = vector2.y;
                 while (vector.y < this.sourceObjectBounds.center.y + this.sourceObjectBounds.extents.y)
                 {
                     vector.z = vector2.z;
                     while (vector.z < this.sourceObjectBounds.center.z + this.sourceObjectBounds.extents.z)
                     {
                         Gizmos.DrawWireCube(vector + cellSize / 2f, cellSize);
                         vector.z += cellSize.z;
                     }
                     vector.y += cellSize.y;
                 }
                 vector.x += cellSize.x;
             }
         }
     }
     if (this.grouper.clusterGrouper.clusterType == MB3_MeshBakerGrouperCore.ClusterType.pie)
     {
         if (this.grouper.clusterGrouper.pieAxis.magnitude < 0.1f)
         {
             return;
         }
         if (this.grouper.clusterGrouper.pieNumSegments < 1)
         {
             return;
         }
         float magnitude = this.sourceObjectBounds.extents.magnitude;
         MB3_MeshBakerGrouper.DrawCircle(this.grouper.clusterGrouper.pieAxis, this.grouper.clusterGrouper.origin, magnitude, 24);
         Quaternion rotation  = Quaternion.FromToRotation(Vector3.up, this.grouper.clusterGrouper.pieAxis);
         Quaternion rotation2 = Quaternion.AngleAxis(180f / (float)this.grouper.clusterGrouper.pieNumSegments, Vector3.up);
         Vector3    point     = rotation2 * Vector3.forward;
         for (int i = 0; i < this.grouper.clusterGrouper.pieNumSegments; i++)
         {
             Vector3 a = rotation * point;
             Gizmos.DrawLine(this.grouper.clusterGrouper.origin, this.grouper.clusterGrouper.origin + a * magnitude);
             point = rotation2 * point;
             point = rotation2 * point;
         }
     }
 }