public new SFP_Matrix4x4Property Initialize(SF_Node node)
 {
     base.nameType = "Matrix 4x4";
     base.Initialize(node);
     global = true;
     return(this);
 }
Example #2
0
        public static void EnterableTextField(SF_Node n, Rect r, ref string str, GUIStyle style, bool update = true)
        {
            if (style == null)
            {
                style = EditorStyles.textField;
            }
            string field_name = n.GetType().ToString() + "_txt_" + n.id;


            GUI.SetNextControlName(field_name);
            EditorGUI.BeginChangeCheck();
            str = EditorGUI.TextField(r, str, style);

            bool pressedEnter = Event.current.keyCode == KeyCode.Return;

            if (update)
            {
                if (pressedEnter)
                {
                    if (GUI.GetNameOfFocusedControl() == field_name)
                    {
                        n.OnUpdateNode(NodeUpdateType.Hard);
                    }
                    EditorGUI.EndChangeCheck();
                }
                else if (EditorGUI.EndChangeCheck())
                {
                    n.OnUpdateNode(NodeUpdateType.Soft);
                }
            }
            else if (EditorGUI.EndChangeCheck())
            {
                n.editor.ShaderOutdated = UpToDateState.OutdatedSoft;
            }
        }
Example #3
0
        public static void EnterableFloatField(SF_Node n, Rect r, ref float val, GUIStyle style)
        {
            if (style == null)
            {
                style = EditorStyles.textField;
            }
            string field_name = n.GetType().ToString() + "_" + n.id;


            GUI.SetNextControlName(field_name);
            EditorGUI.BeginChangeCheck();
            val = EditorGUI.FloatField(r, val, style);


            bool pressedEnter = Event.current.keyCode == KeyCode.Return && Event.current.type == EventType.KeyDown;

            if (pressedEnter)
            {
                EditorGUI.EndChangeCheck();
                //Debug.Log("Pressed enter with focus on " + GUI.GetNameOfFocusedControl() + ", should have been " + field_name);
                if (GUI.GetNameOfFocusedControl() == field_name)
                {
                    //Debug.Log("Pressed enter!");
                    n.OnUpdateNode(NodeUpdateType.Hard);
                }
            }
            else if (EditorGUI.EndChangeCheck())
            {
                n.OnUpdateNode(NodeUpdateType.Soft);
            }
        }
Example #4
0
        public void StopCutting()
        {
            List <SF_NodeConnector> disconnectors = new List <SF_NodeConnector>();

            for (int i = 0; i < editor.nodes.Count; i++)
            {
                SF_Node n = editor.nodes[i];
                for (int j = 0; j < n.connectors.Length; j++)
                {
                    SF_NodeConnector con = n.connectors[j];
                    if (con.IsConnected() && con.conType == ConType.cInput)
                    {
                        if (con.conLine.aboutToBeDeleted)
                        {
                            disconnectors.Add(con);
                        }
                    }
                }
            }

            if (disconnectors.Count == 0)
            {
                isCutting = false;
                return;
            }

            UnmarkDeleteHighlights();

            //Undo.RecordObject((Object)con, "cut"
            string undoMsg = "cut ";

            if (disconnectors.Count > 1)
            {
                undoMsg += disconnectors.Count + " ";
                undoMsg += "connections";
            }
            else
            {
                undoMsg += "connection: ";
                undoMsg += disconnectors[0].node.nodeName;
                undoMsg += "[" + disconnectors[0].label + "]";
                undoMsg += " <--- ";
                undoMsg += "[" + disconnectors[0].inputCon.label + "]";
                undoMsg += disconnectors[0].inputCon.node.nodeName;
            } // = disconnectors.Count > 1 ? "cut "+disconnectors.Count+" connections" : "cut connection " + disconnectors[i].node.name + "[" +

            foreach (SF_NodeConnector con in disconnectors)
            {
                Undo.RecordObject(con, undoMsg);
            }

            foreach (SF_NodeConnector con in disconnectors)
            {
                con.Disconnect();
            }

            isCutting = false;
        }
Example #5
0
        public void Establish(SF_Editor editor, LinkingMethod linkMethod = LinkingMethod.NoUpdate)
        {
            SF_Node source = editor.GetNodeByID(sNode);
            SF_Node target = editor.GetNodeByID(tNode);

            // Debug.Log( "Linking " + target.nodeName + " <- " + source.nodeName );

            target.GetConnectorByID(tCon).LinkTo(source.GetConnectorByID(sCon), linkMethod);
        }
Example #6
0
        public static SF_ErrorEntry Create(string error, SF_Node target, bool isWarning)
        {
            SF_ErrorEntry entry = ScriptableObject.CreateInstance <SF_ErrorEntry>();

            entry.isWarning = isWarning;
            entry.node      = target;
            entry.error     = error;
            entry.InitializeRows();
            return(entry);
        }
Example #7
0
        public void OnDroppedSubstance(ProceduralMaterial procMat)
        {
            Texture diffuse = TryGetProceduralTexture(procMat, "_MainTex");
            Texture normal  = TryGetProceduralTexture(procMat, "_BumpMap");
            //Texture parallax = TryGetProceduralTexture(procMat, "_ParallaxMap");
            //Texture emission = TryGetProceduralTexture(procMat, "_Illum");
            //TryGetProceduralTexture("_MainTex");

            SF_Node prevNode = TryLinkIfExistsAndOpenSlotAvailable(diffuse, "MainTex", editor.mainNode.diffuse, "RGB");

            TryLinkIfExistsAndOpenSlotAvailable(normal, "BumpMap", editor.mainNode.normal, "RGB", prevNode);
        }
        void InstantiateNodes(string[] serializedNodes, Vector2 posOffset, string undoMsg)
        {
            // Make sure it knows about the editor
            SF_Parser.editor = editor;

            List <SF_Node> newNodes = new List <SF_Node>();             // List of all new nodes
            List <SF_Link> links    = new List <SF_Link>();             // Used for multi-clone

            int[] idOld = new int[serializedNodes.Length];
            int[] idNew = new int[serializedNodes.Length];

            for (int i = 0; i < serializedNodes.Length; i++)
            {
                SF_Node node = SF_Node.Deserialize(serializedNodes[i], ref links);
                if (node.IsProperty())
                {
                    if (editor.PropertyNameTaken(node.property))
                    {
                        node.property.SetName(node.property.GetClonedName());                           // Rename if needed
                        node.variableName = node.property.nameInternal;
                    }
                }

                idOld[i] = node.id;
                node.AssignID();                 // Increment IDs
                if (!node.IsProperty())
                {
                    node.ResetVariableName();
                }
                idNew[i]     = node.id;
                node.rect.x += posOffset.x;
                node.rect.y += posOffset.y;
                newNodes.Add(node);
            }

            // Establish all links
            foreach (SF_Link link in links)
            {
                link.Remap(idOld, idNew);
                link.Establish(editor, LinkingMethod.Default);
            }
            Undo.IncrementCurrentGroup();
            DeselectAll(registerUndo: true, undoMsg: undoMsg);
            Undo.CollapseUndoOperations(Undo.GetCurrentGroup() - 1);
            Event.current.Use();
            foreach (SF_Node n in newNodes)
            {
                n.Select(registerUndo: false);
            }
        }
        public void UndoableEnterableNodeTextField(SF_Node node, Rect r, ref string value, string undoMsg, bool update = true, UnityEngine.Object extra = null)
        {
            string nextValue = value;

            SF_GUI.EnterableTextField(node, r, ref nextValue, EditorStyles.textField, update);
            if (nextValue != value)
            {
                Undo.RecordObject(this, undoMsg);
                if (extra != null)
                {
                    Undo.RecordObject(extra, undoMsg);
                }
                value = nextValue;
            }
        }
        public SF_Node OnStopDrag()
        {
            if (!IsPlacing())
            {
                return(null);
            }
            SF_Node newNode = null;

            if (editor.nodeView.rect.Contains(Event.current.mousePosition))
            {
                newNode = editor.AddNode(dragNode, registerUndo: true);
            }
            dragNode = null;
            return(newNode);
        }
Example #11
0
        public void DeserializeProps(string s)
        {
            //Debug.Log("Deserializing properties = " + s);
            string[] split = s.Split('-');
            propertyList = new System.Collections.Generic.List<SF_Node>();
            for (int i = 0; i < split.Length; i++)
            {
                //Debug.Log("Found " + GetNodeByID( int.Parse( split[i] )).nodeName);
                //Debug.Log ("Attempting deserialization. int parse of ["+split[i]+"]");

                SF_Node foundNode = GetNodeByID(int.Parse(split[i]));
                if (foundNode != null)
                    propertyList.Add(foundNode);

            }
        }
 public void MoveSelection(Vector2 delta, SF_Node ignore)
 {
     foreach (SF_Node n in Selection)
     {
         if (n == ignore)
         {
             continue;
         }
         //if(selection.Count > 1){
         //Debug.Log("Selection count = " + selection.Count + " thus nodes");
         Undo.RecordObject(n, "move nodes");
         //}
         n.rect.x += delta.x;
         n.rect.y += delta.y;
     }
 }
Example #13
0
        public void ReconnectConnectedPending()
        {
            AssignDepthValuesToNodes();

            int maxDepth = 0; // Deepest level

            foreach (SF_Node n in editor.nodes)
            {
                if (maxDepth < n.depth)
                {
                    maxDepth = n.depth;
                }
            }


            int depth = maxDepth;

            while (depth > 0)
            {
                //foreach( SF_Node n in editor.nodes ) {
                for (int i = 0; i < editor.nodes.Count; i++)
                {
                    SF_Node n = editor.nodes[i];
                    if (n.depth == depth)
                    {
                        foreach (SF_NodeConnector con in n.connectors)
                        {
                            if (con.conType == ConType.cOutput)
                            {
                                continue;
                            }
                            if (!con.IsConnectedAndEnabled())
                            {
                                continue;
                            }
                            if (con.valueType != ValueType.VTvPending)
                            {
                                continue;
                            }
                            con.inputCon.LinkTo(con, LinkingMethod.Default);
                        }
                    }
                }
                depth--;
            }
        }
Example #14
0
 void AddDepthToChildrenOf(SF_Node n, int carry)
 {
     carry++;
     n.depth = Mathf.Max(carry, n.depth);;
     for (int i = 0; i < n.connectors.Length; i++)
     {
         if (n.connectors[i].conType == ConType.cOutput) // Ignore outputs, we came from here!
         {
             continue;
         }
         if (!n.connectors[i].IsConnected()) // Ignore unconnected inputs
         {
             continue;
         }
         AddDepthToChildrenOf(n.connectors[i].inputCon.node, carry);
     }
 }
Example #15
0
        public SF_NodeConnector Initialize(SF_Node node, string strID, string label, ConType conType, ValueType valueType, bool outerLabel = false, string unconnectedEvaluationValue = null)
        {
            this.node    = node;
            this.strID   = strID;
            this.label   = label;
            this.conType = conType;

            if (conType == ConType.cInput)
            {
                conLine = ScriptableObject.CreateInstance <SF_NodeConnectionLine>().Initialize(node.editor, this);
            }

            this.valueType  = this.valueTypeDefault = valueType;
            this.outerLabel = outerLabel;
            this.unconnectedEvaluationValue = unconnectedEvaluationValue;
            outputCons = new List <SF_NodeConnector>();
            return(this);
        }
        public SF_Node CreateInstance()
        {
            Type fType = Type.GetType(type);

            // Might be dynamic...
            if (fType == null)
            {
                if (SF_Debug.dynamicNodeLoad)
                {
                    Debug.Log("CreateInstance couldn't use GetType, attempting dynamic load...");
                }
                fType = SF_Editor.GetNodeType(type);
                if (SF_Debug.dynamicNodeLoad && fType == null)
                {
                    Debug.Log("Failed to load dynamic load fType is null");
                }
            }


            SF_Node node = (SF_Node)ScriptableObject.CreateInstance(fType);

            node.Initialize();
            return(node);
        }
Example #17
0
        //public void OnDroppedSubstance(ProceduralMaterial procMat){

        //	Texture diffuse = TryGetProceduralTexture(procMat, "_MainTex");
        //	Texture normal = TryGetProceduralTexture(procMat, "_BumpMap");
        //	//Texture parallax = TryGetProceduralTexture(procMat, "_ParallaxMap");
        //	//Texture emission = TryGetProceduralTexture(procMat, "_Illum");
        //	//TryGetProceduralTexture("_MainTex");

        //	SF_Node prevNode = TryLinkIfExistsAndOpenSlotAvailable(diffuse, "MainTex", editor.mainNode.diffuse, "RGB");
        //	TryLinkIfExistsAndOpenSlotAvailable(normal, "BumpMap", editor.mainNode.normal, "RGB", prevNode);


        //}

        // For connecting procedural materials to the main node
        public SF_Node TryLinkIfExistsAndOpenSlotAvailable(Texture tex, string propertyName, SF_NodeConnector connector, string outChannel, SF_Node prevNode = null)
        {
            if (tex)
            {
                SFN_Tex2d tNode = editor.AddNode <SFN_Tex2d>();
                if (prevNode != null)
                {
                    Rect r = tNode.rect;
                    r          = r.MovedDown(1);
                    r.y       += 64;
                    tNode.rect = r;
                }
                tNode.TextureAsset = tex;
                tNode.property.SetName(propertyName);
                tNode.OnAssignedTexture();
                if (connector.enableState == EnableState.Enabled && connector.availableState == AvailableState.Available && !connector.IsConnected())
                {
                    connector.LinkTo(tNode[outChannel]);
                }
                return(tNode);
            }
            return(null);
        }
Example #18
0
 public SF_SetNodeSource(SF_Node node)
 {
     con = node.connectors[0];
 }
 public SF_NodePreview Initialize(SF_Node node)
 {
     this.node = node;             // Parent
     return(this);
 }
Example #20
0
 public new SFP_Slider Initialize(SF_Node node)
 {
     base.nameType = "Slider";
     base.Initialize(node);
     return(this);
 }
Example #21
0
        //public bool isBumpmap = false; // TODO: Is this even used?

        public new SFP_Tex2d Initialize(SF_Node node)
        {
            base.nameType = "Texture (2D)";
            base.Initialize(node);
            return(this);
        }
Example #22
0
 public SF_NodeStatus Initialize(SF_Node node)
 {
     this.node = node;
     Reset();
     return(this);
 }
Example #23
0
 public void Initialize(SF_Node node)
 {
     this.node = node;
     SetName(node.GetVariableName());
 }
Example #24
0
 public new SFP_SwitchProperty Initialize(SF_Node node)
 {
     base.nameType = "Toggle";
     base.Initialize(node);
     return(this);
 }
Example #25
0
        // Ghost nodes are default values assigned to unconnected node connectors
        // They are instantiated when the shader is being evaluated, and then removed again
        public void DefineGhostIfNeeded(ref List <SF_Node> ghosts)
        {
            // Skip nodes without ghosts
            if (string.IsNullOrEmpty(ghostType))
            {
                return;
            }


            if (IsConnected())              // Skip already connected ones
            {
                return;
            }


            SF_Node ghost = null;

            // Search for existing ghost node
            foreach (SF_Node exisGhost in ghosts)
            {
                if (exisGhost.GetType().FullName == ghostType)                    // TODO: Make sure serialized data matches too!
                // Found!
                {
                    ghost = exisGhost;

                    if (SF_Debug.ghostNodes)
                    {
                        Debug.Log("Found matching existing ghost");
                    }
                    break;
                }
            }

            // If no ghost was found, create one
            if (ghost == null)
            {
                ghost         = node.editor.AddNode(ghostType);
                ghost.isGhost = true;
                ghosts.Add(ghost);
                if (SF_Debug.ghostNodes)
                {
                    Debug.Log("Adding ghost " + ghostType + " with connection count " + ghost.connectors.Length);
                    Debug.Log("Linked to " + node.nodeName + "[" + this.label + "]");
                    Debug.Log("Ghost Count = " + node.editor.shaderEvaluator.ghostNodes.Count);
                }
                //Debug.Log( "Adding ghost of type " + ghostType );
                //Debug.Log( "Ghost in main node list = " + node.editor.nodes.Contains( ghost ) );
            }

            // Just to make sure...
            if (ghost == null)
            {
                Debug.LogError("Ghost is null, this should really not happen. Tried to find type " + ghostType);
            }

            // By this point, ghost is surely an existing node!
            // Link it:

            //Debug.Log( "Linking ghost of type " + ghostType + " on " + this.node.nodeName + " Is COnnected = " + IsConnected());
            ghost.status.leadsToFinal = true;
            ghost[ghostLinkStrId].LinkTo(this, LinkingMethod.NoUpdate);
        }
Example #26
0
 public static SF_NodeConnector Create(SF_Node node, string strID, string label, ConType conType, ValueType valueType, bool outerLabel = false, string unconnectedEvaluationValue = null)
 {
     return(ScriptableObject.CreateInstance <SF_NodeConnector>().Initialize(node, strID, label, conType, valueType, outerLabel, unconnectedEvaluationValue));
 }
 public void Remove(SF_Node n)
 {
     Selection.Remove(n);
 }
Example #28
0
 public new SFP_Cubemap Initialize(SF_Node node)
 {
     base.nameType = "Cubemap";
     base.Initialize(node);
     return(this);
 }
 public void Add(SF_Node n)
 {
     Selection.Add(n);
 }
        public void DeleteSelected()
        {
            if (Selection.Contains(editor.mainNode))
            {
                editor.mainNode.Deselect(registerUndo: false);                // Deselect main node if you press delete
            }

            int selCount = Selection.Count;

//			Debug.Log("Delete selected, count = " + selCount);

            if (selCount == 0)
            {
                return;
            }

            string undoMsg = "";

            if (selCount == 1)
            {
                undoMsg = "delete " + Selection[0].nodeName;
            }
            else
            {
                undoMsg = "delete " + selCount + " nodes";
            }
            //Debug.Log("Selection delete initiated - " + undoMsg );

            Undo.RecordObject(editor, undoMsg);
            Undo.RecordObject(editor.nodeView.treeStatus, undoMsg);

            foreach (SF_Node node in editor.nodes)
            {
                node.UndoRecord(undoMsg);
                // Undo.RecordObject(node, undoMsg);
            }

            Undo.RecordObject(this, undoMsg);



            // Undo recording is weird :(



            for (int i = editor.nodes.Count - 1; i >= 0; i--)
            {
                SF_Node n = editor.nodes[i];
                if (n.selected)
                {
                    if (n is SFN_Relay)
                    {
                        SF_NodeConnector inCon  = n["IN"];
                        SF_NodeConnector outCon = n["OUT"];
                        if (inCon.IsConnected() && outCon.IsConnected())
                        {
                            // Relink all outputs to the incoming connectors
                            for (int ir = outCon.outputCons.Count - 1; ir >= 0; ir--)
                            {
                                outCon.outputCons[ir].LinkTo(inCon.inputCon);
                            }
                            inCon.Disconnect();
                        }
                    }

                    foreach (SF_NodeConnector con in editor.nodes[i].connectors)
                    {
                        if (con.conType == ConType.cOutput)
                        {
                            con.Disconnect();
                        }
                    }
                    if (editor.nodeView.treeStatus.propertyList.Contains(editor.nodes[i]))
                    {
                        editor.nodeView.treeStatus.propertyList.Remove(editor.nodes[i]);
                    }
                    editor.nodes[i].Deselect(registerUndo: false);
                    editor.nodes.RemoveAt(i);


                    //editor.nodes[i].Delete(registerUndo:false, undoMsg:undoMsg);
                }
            }
        }