// OnSceneGUI doesnt seem to be called for ScriptableObjects, so we need to tap onto the (undocumented) SceneView class.
        public void OnSceneGUI(SceneView sceneView)
        {
            if (!paintMode || sceneView.camera == null)
            {
                return;
            }

            Vector3[] wsPositions  = null;
            bool[]    facingCamera = null;

            // get positions and camera facing flags for source object, if it is selected:
            if (sourceObject != null && Selection.activeGameObject == sourceObject)
            {
                wsPositions  = new Vector3[skinMap.masterFlags.Length];
                facingCamera = new bool[skinMap.masterFlags.Length];

                Vector3[] vertices = skinMap.SourceTopology.InputMesh.vertices;
                Vector3[] normals  = skinMap.SourceTopology.InputMesh.normals;

                for (int i = 0; i < skinMap.masterFlags.Length; ++i)
                {
                    wsPositions[i] = sourceObject.transform.TransformPoint(vertices[i]);

                    Vector3 meshNormal    = normals[i];
                    Vector3 camToParticle = sceneView.camera.transform.position - wsPositions[i];
                    facingCamera[i] = (Vector3.Dot(sourceObject.transform.TransformVector(meshNormal), camToParticle) > 0);
                }
            }

            // get positions and camera facing flags for target object, if it is selected:
            if (targetObject != null && Selection.activeGameObject == targetObject)
            {
                wsPositions  = new Vector3[skinMap.slaveFlags.Length];
                facingCamera = new bool[skinMap.slaveFlags.Length];

                Vector3[] vertices = skinMap.TargetMesh.vertices;
                Vector3[] normals  = skinMap.TargetMesh.normals;

                for (int i = 0; i < skinMap.slaveFlags.Length; ++i)
                {
                    wsPositions[i] = targetObject.transform.TransformPoint(vertices[i]);

                    Vector3 camToParticle = sceneView.camera.transform.position - wsPositions[i];
                    facingCamera[i] = (Vector3.Dot(sourceObject.transform.TransformVector(normals[i]), camToParticle) > 0);
                }
            }

            if (wsPositions == null)
            {
                return;
            }

            // Update paintbrush:
            ObiClothParticleHandles.ParticleBrush(wsPositions, ObiParticleActorEditor.ParticleCulling.Back, facingCamera, brushRadius,
                                                  () => {
                // As RecordObject diffs with the end of the current frame,
                // and this is a multi-frame operation, we need to use RegisterCompleteObjectUndo instead.
                Undo.RegisterCompleteObjectUndo(skinMap, "Paint skin channels");
            },
                                                  PaintbrushStampCallback,
                                                  () => {
                EditorUtility.SetDirty(skinMap);
            },
                                                  Resources.Load <Texture2D>("BrushHandle"));
        }
Example #2
0
        public void OnSceneGUI()
        {
            if (!editMode)
            {
                return;
            }

            CreateParticleMaterials();

            ResizeParticleArrays();

            if (!actor.Initialized)
            {
                return;
            }

            if (Camera.current != null)
            {
                camup      = Camera.current.transform.up;
                camright   = Camera.current.transform.right;
                camforward = Camera.current.transform.forward;
            }

            if (Event.current.type == EventType.Repaint)
            {
                // Update camera facing status and world space positions array:
                UpdateParticleEditorInformation();

                // Generate sorted indices for back-to-front rendering:
                for (int i = 0; i < sortedIndices.Length; i++)
                {
                    sortedIndices[i] = i;
                }

                Array.Sort <int>(sortedIndices, (a, b) => sqrDistanceToCamera[b].CompareTo(sqrDistanceToCamera[a]));

                // Draw custom actor stuff.
                DrawActorInfo();
            }

            // Draw tool handles:
            if (Camera.current != null)
            {
                if (paintBrush)
                {
                    if (ObiClothParticleHandles.ParticleBrush(wsPositions, faceCulling, facingCamera, brushRadius,
                                                              () => {
                        // As RecordObject diffs with the end of the current frame,
                        // and this is a multi-frame operation, we need to use RegisterCompleteObjectUndo instead.
                        Undo.RegisterCompleteObjectUndo(actor, "Paint particles");
                    },
                                                              PaintbrushStampCallback,
                                                              () => {
                        EditorUtility.SetDirty(actor);
                    },
                                                              Resources.Load <Texture2D>("BrushHandle")))
                    {
                        ParticlePropertyChanged();
                    }
                }
                else if (selectionBrush)
                {
                    if (ObiClothParticleHandles.ParticleBrush(wsPositions, faceCulling, facingCamera, brushRadius, null,
                                                              (List <ParticleStampInfo> stampInfo, bool modified) => {
                        foreach (ParticleStampInfo info in stampInfo)
                        {
                            if (actor.active[info.index])
                            {
                                selectionStatus[info.index] = !modified;
                            }
                        }
                    }, null,
                                                              Resources.Load <Texture2D>("BrushHandle")))
                    {
                        SelectionChanged();
                    }
                }
                else
                {
                    if (ObiClothParticleHandles.ParticleSelector(wsPositions, selectionStatus, faceCulling, facingCamera))
                    {
                        SelectionChanged();
                    }
                }
            }

            // Sceneview GUI:
            Handles.BeginGUI();

            GUI.skin = EditorGUIUtility.GetBuiltinSkin(EditorSkin.Scene);

            if (Event.current.type == EventType.Repaint)
            {
                uirect   = GUILayout.Window(0, uirect, DrawUIWindow, "Particle editor");
                uirect.x = Screen.width / EditorGUIUtility.pixelsPerPoint - uirect.width - 10;               //10 and 28 are magic values, since Screen size is not exactly right.
                uirect.y = Screen.height / EditorGUIUtility.pixelsPerPoint - uirect.height - 28;
            }

            GUILayout.Window(0, uirect, DrawUIWindow, "Particle editor");

            Handles.EndGUI();
        }
Example #3
0
        public void OnSceneGUI()
        {
            if (!editMode)
            {
                return;
            }

            CreateParticleMaterial();
            particleMaterial.SetPass(0);

            ResizeParticleArrays();

            if (!actor.Initialized)
            {
                return;
            }

            if (Camera.current != null)
            {
                camup      = Camera.current.transform.up;
                camright   = Camera.current.transform.right;
                camforward = Camera.current.transform.forward;
            }

            if (Event.current.type == EventType.Repaint)
            {
                // Update camera facing status and world space positions array:
                UpdateParticleEditorInformation();

                // Draw 3D stuff: particles, constraints, grid, etc.
                DrawParticles();
            }

            // Draw tool handles:
            if (Camera.current != null)
            {
                switch (tool)
                {
                case EditionTool.SELECT:
                    if (ObiClothParticleHandles.ParticleSelector(wsPositions, selectionStatus, backfaces, facingCamera))
                    {
                        SelectionChanged();
                    }
                    break;

                case EditionTool.SELECTBRUSH:
                    if (ObiClothParticleHandles.ParticleBrush(wsPositions, backfaces, facingCamera, brushRadius, null,
                                                              (List <ParticleStampInfo> stampInfo, bool modified) => {
                        foreach (ParticleStampInfo info in stampInfo)
                        {
                            if (actor.active[info.index])
                            {
                                selectionStatus[info.index] = !modified;
                            }
                        }
                    }, null,
                                                              EditorGUIUtility.Load("BrushHandle.psd") as Texture2D))
                    {
                        SelectionChanged();
                    }
                    break;

                case EditionTool.PAINT:                 //TODO: select mask (paint on selected)
                    if (ObiClothParticleHandles.ParticleBrush(wsPositions, backfaces, facingCamera, brushRadius,
                                                              () => {
                        // As RecordObject diffs with the end of the current frame,
                        // and this is a multi-frame operation, we need to use RegisterCompleteObjectUndo instead.
                        Undo.RegisterCompleteObjectUndo(actor, "Paint particles");
                    },
                                                              PaintbrushStampCallback,
                                                              () => {
                        EditorUtility.SetDirty(actor);
                    },
                                                              EditorGUIUtility.Load("BrushHandle.psd") as Texture2D))
                    {
                        ParticlePropertyChanged();
                    }
                    break;
                }
            }

            // Sceneview GUI:
            Handles.BeginGUI();

            GUI.skin = EditorGUIUtility.GetBuiltinSkin(EditorSkin.Scene);

            if (Event.current.type == EventType.Repaint)
            {
                uirect   = GUILayout.Window(0, uirect, DrawUIWindow, "Particle editor");
                uirect.x = Screen.width - uirect.width - 10;                 //10 and 28 are magic values, since Screen size is not exactly right.
                uirect.y = Screen.height - uirect.height - 28;
            }

            GUILayout.Window(0, uirect, DrawUIWindow, "Particle editor");

            Handles.EndGUI();
        }