Пример #1
0
 // Called when the mouse begins hovering an editable object.
 public override void OnBrushEnter(z_EditableObject target, z_BrushSettings settings)
 {
     base.OnBrushEnter(target, settings);
 }
Пример #2
0
 // Called when the mouse exits hovering an editable object.
 public override void OnBrushExit(z_EditableObject target)
 {
     base.OnBrushExit(target);
 }
Пример #3
0
        /**
         * Calculate the weights for this ray.
         */
        bool DoMeshRaycast(Ray mouseRay, z_BrushTarget target)
        {
            if (!z_Util.IsValid(target))
            {
                return(false);
            }

            target.ClearRaycasts();

            z_EditableObject editable = target.editableObject;

            rays.Clear();
            rays.Add(mouseRay);

            if (brushMirror != z_BrushMirror.None)
            {
                for (int i = 0; i < 3; i++)
                {
                    if (((uint)brushMirror & (1u << i)) < 1)
                    {
                        continue;
                    }

                    int len = rays.Count;

                    for (int n = 0; n < len; n++)
                    {
                        Vector3 flipVec = ((z_BrushMirror)(1u << i)).ToVector3();

                        if (mirrorSpace == z_MirrorCoordinateSpace.World)
                        {
                            Vector3 cen = editable.gameObject.GetComponent <Renderer>().bounds.center;
                            rays.Add(new Ray(Vector3.Scale(rays[n].origin - cen, flipVec) + cen,
                                             Vector3.Scale(rays[n].direction, flipVec)));
                        }
                        else
                        {
                            Transform t = SceneView.lastActiveSceneView.camera.transform;
                            Vector3   o = t.InverseTransformPoint(rays[n].origin);
                            Vector3   d = t.InverseTransformDirection(rays[n].direction);
                            rays.Add(new Ray(t.TransformPoint(Vector3.Scale(o, flipVec)),
                                             t.TransformDirection(Vector3.Scale(d, flipVec))));
                        }
                    }
                }
            }

            bool hitMesh = false;

            int[] triangles = editable.editMesh.GetTriangles();

            foreach (Ray ray in rays)
            {
                z_RaycastHit hit;

                if (z_SceneUtility.WorldRaycast(ray, editable.transform, editable.editMesh.vertices, triangles, out hit))
                {
                    target.raycastHits.Add(hit);
                    hitMesh = true;
                }
            }

            z_SceneUtility.CalculateWeightedVertices(target, brushSettings);

            return(hitMesh);
        }
Пример #4
0
 public override void OnBrushEnter(z_EditableObject target, z_BrushSettings settings)
 {
     base.OnBrushEnter(target, settings);
     nonManifoldIndices = z_MeshUtility.GetNonManifoldIndices(target.editMesh);
 }
Пример #5
0
        void OnGUI()
        {
            Event e = Event.current;

            z_GUI.PushGUISkin(z_GUI.PolybrushSkin);

            if (e.type == EventType.ContextClick)
            {
                OpenContextMenu();
            }

            GUILayout.Space(8);

            EditorGUI.BeginChangeCheck();

            int toolbarIndex = (int)tool - 1;

            toolbarIndex = GUILayout.Toolbar(toolbarIndex, modeIcons, "Mode");

            if (EditorGUI.EndChangeCheck())
            {
                z_BrushTool newTool = (z_BrushTool)(toolbarIndex + 1);
                SetTool(newTool == tool ? z_BrushTool.None : (z_BrushTool)toolbarIndex + 1);
            }

            // Call current mode GUI
            if (mode != null && tool != z_BrushTool.Settings)
            {
                if (!z_Pref.GetBool(z_Pref.lockBrushSettings))
                {
                    z_GUI.PopGUISkin();
                    scroll = EditorGUILayout.BeginScrollView(scroll);
                    z_GUI.PushGUISkin(z_GUI.PolybrushSkin);
                }

                // Show the settings header in z_Editor so that the preset selector can be included in the block.
                // Can't move preset selector to z_BrushSettingsEditor because it's a CustomEditor for z_BrushSettings,
                // along with other issues.
                if (z_GUILayout.HeaderWithDocsLink(z_GUI.TempContent("Brush Settings")))
                {
                    Application.OpenURL("http://procore3d.github.io/polybrush/brushSettings/");
                }

                /**
                 * Brush preset selector
                 */
                GUILayout.BeginHorizontal();
                EditorGUI.BeginChangeCheck();

                currentBrushIndex = EditorGUILayout.Popup(currentBrushIndex, availableBrushes_str, "Popup");

                if (EditorGUI.EndChangeCheck())
                {
                    if (currentBrushIndex >= availableBrushes.Count)
                    {
                        SetBrushSettings(z_BrushSettingsEditor.AddNew());
                    }
                    else
                    {
                        SetBrushSettings(availableBrushes[currentBrushIndex]);
                    }
                }

                if (GUILayout.Button(gc_SaveBrushSettings))
                {
                    if (brushSettings != null && brushSettingsAsset != null)
                    {
                        // integer 0, 1 or 2 corresponding to ok, cancel and alt buttons
                        int res = EditorUtility.DisplayDialogComplex("Save Brush Settings", "Overwrite brush preset or save as a new preset? ", "Save", "Save As", "Cancel");

                        if (res == 0)
                        {
                            brushSettings.CopyTo(brushSettingsAsset);
                            EditorGUIUtility.PingObject(brushSettingsAsset);
                        }
                        else if (res == 1)
                        {
                            z_BrushSettings dup  = z_BrushSettingsEditor.AddNew();
                            string          name = dup.name;
                            brushSettings.CopyTo(dup);
                            dup.name = name;                                            // want to retain the unique name generated by AddNew()
                            SetBrushSettings(dup);
                            EditorGUIUtility.PingObject(brushSettingsAsset);
                        }
                    }
                    else
                    {
                        Debug.LogWarning("Something went wrong saving brush settings.");
                    }
                }
                GUILayout.EndHorizontal();

                EditorGUI.BeginChangeCheck();

                brushEditor.OnInspectorGUI();

                if (z_Pref.GetBool(z_Pref.lockBrushSettings))
                {
                    z_GUI.PopGUISkin();
                    scroll = EditorGUILayout.BeginScrollView(scroll);
                    z_GUI.PushGUISkin(z_GUI.PolybrushSkin);
                }

                /**
                 * Mirroring
                 */
                if (z_GUILayout.HeaderWithDocsLink(z_GUI.TempContent("Brush Mirroring")))
                {
                    Application.OpenURL("http://procore3d.github.io/polybrush/brushMirroring/");
                }

                GUILayout.BeginHorizontal();
                brushMirror = (z_BrushMirror)z_GUILayout.BitMaskField((uint)brushMirror, System.Enum.GetNames(typeof(z_BrushMirror)), "Set Brush Mirroring");
                mirrorSpace = (z_MirrorCoordinateSpace)GUILayout.Toolbar((int)mirrorSpace, mirrorSpaceGuiContent, "Command");
                GUILayout.EndHorizontal();

                mode.DrawGUI(brushSettings);

                // When using non-conforming heights in a GUIStyle the GUI will sometimes
                // clip the content too early - this pads the size so that doesn't happen.
                GUILayout.Space(16);

                if (EditorGUI.EndChangeCheck())
                {
                    mode.OnBrushSettingsChanged(brushTarget, brushSettings);
                }

                EditorGUILayout.EndScrollView();
            }
            else
            {
                if (tool == z_BrushTool.Settings)
                {
                    z_GlobalSettingsEditor.OnGUI();
                }
                else
                {
                    // ...yo dawg, heard you like FlexibleSpace
                    GUILayout.BeginVertical();
                    GUILayout.FlexibleSpace();
                    GUILayout.BeginHorizontal();
                    GUILayout.FlexibleSpace();
                    GUILayout.Label("Select an Edit Mode", z_GUI.headerTextStyle);
                    GUILayout.FlexibleSpace();
                    GUILayout.EndHorizontal();
                    GUILayout.FlexibleSpace();
                    GUILayout.EndVertical();
                }
            }

#if POLYBRUSH_DEBUG
            z_GUI.PushUnitySkin();
            GUILayout.Label("DEBUG", EditorStyles.boldLabel);

            GUILayout.Label("target: " + (z_Util.IsValid(brushTarget) ? brushTarget.editableObject.gameObject.name : "null"));
            GUILayout.Label("vertex: " + (z_Util.IsValid(brushTarget) ? brushTarget.editableObject.vertexCount : 0));
            GUILayout.Label("applying: " + applyingBrush);
            GUILayout.Label("lockBrushToFirst: " + lockBrushToFirst);
            GUILayout.Label("lastHoveredGameObject: " + lastHoveredGameObject);

            GUILayout.Space(6);

            foreach (var kvp in hovering)
            {
                z_BrushTarget    t            = kvp.Value;
                z_EditableObject dbg_editable = t.editableObject;
                GUILayout.Label("Vertex Streams: " + dbg_editable.usingVertexStreams);
                GUILayout.Label("Original: " + (dbg_editable.originalMesh == null ? "null" : dbg_editable.originalMesh.name));
                GUILayout.Label("Active: " + (dbg_editable.editMesh == null ? "null" : dbg_editable.editMesh.name));
                GUILayout.Label("Graphics: " + (dbg_editable.graphicsMesh == null ? "null" : dbg_editable.graphicsMesh.name));
            }
            z_GUI.PopGUISkin();
#endif

            z_GUI.PopGUISkin();

            if (wantsRepaint)
            {
                wantsRepaint = false;
                Repaint();
            }
        }