浏览代码

[mat graph]Remove implicit node creation now that we have better code generation framework.

/main
Tim Cooper 8 年前
当前提交
47d64c52
共有 4 个文件被更改,包括 8 次插入67 次删除
  1. 32
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Implementation/SerializableGraph.cs
  2. 6
      MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Interfaces/ISlot.cs
  3. 25
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/MaterialSlot.cs
  4. 12
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/TextureNode.cs

32
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Implementation/SerializableGraph.cs


[NonSerialized]
private List<INode> m_Nodes = new List<INode>();
[NonSerialized]
private List<INode> m_VirtualNodes = new List<INode>();
[SerializeField]
List<SerializationHelper.JSONSerializedElement> m_SerializableNodes = new List<SerializationHelper.JSONSerializedElement>();

public INode GetNodeFromGuid(Guid guid)
{
return m_Nodes.Concat(m_VirtualNodes).FirstOrDefault(x => x.guid == guid);
return m_Nodes.FirstOrDefault(x => x.guid == guid);
return m_Nodes.Concat(m_VirtualNodes).Where(x => x.guid == guid).OfType<T>().FirstOrDefault();
return m_Nodes.Where(x => x.guid == guid).OfType<T>().FirstOrDefault();
}
public IEnumerable<IEdge> GetEdges(SlotReference s)

var foundEdges = m_Edges.Where(x =>
return m_Edges.Where(x =>
//If we didn't find any connection, we fallback to GenerateDefaultInput if it's provided, generate a virtual edge to a virtual node (UV input for instance)
if (foundEdges.Count == 0)
{
var slot = GetNodeFromGuid(s.nodeGuid).FindInputSlot<ISlot>(s.slotId);
if (slot is IGenerateDefaultInput)
{
var defaultInputProvider = slot as IGenerateDefaultInput;
var defaultNode = defaultInputProvider.defaultNode;
var node = m_VirtualNodes.FirstOrDefault(o => o != null && defaultNode.GetType() == o.GetType());
if (node == null)
{
defaultNode.owner = this;
m_VirtualNodes.Add(defaultNode);
node = defaultNode;
}
foundEdges.Add(new Edge(new SlotReference(node.guid, defaultInputProvider.defaultSlotID), s));
}
}
return foundEdges;
}
public virtual void OnBeforeSerialize()

m_Edges = SerializationHelper.Deserialize<IEdge>(m_SerializableEdges, null);
m_SerializableEdges = null;
m_VirtualNodes = new List<INode>();
ValidateGraph();
}

6
MaterialGraphProject/Assets/GraphFramework/SerializableGraph/Runtime/Interfaces/ISlot.cs


SlotReference slotReference { get; }
INode owner { get; set; }
}
public interface IGenerateDefaultInput
{
INode defaultNode { get; }
int defaultSlotID { get; }
}
}

25
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/MaterialSlot.cs


return EditorGUI.EndChangeCheck();
}*/
}
public class MaterialSlotDefaultInput : MaterialSlot, IGenerateDefaultInput
{
public MaterialSlotDefaultInput() : base()
{
}
public MaterialSlotDefaultInput(int slotId, string displayName, string shaderOutputName, SlotType slotType, SlotValueType valueType, INode _defaultNode, int _defaultSlotID)
: base(slotId, displayName, shaderOutputName, slotType, valueType, Vector4.zero)
{
defaultNode = _defaultNode;
defaultSlotID = _defaultSlotID;
}
public INode defaultNode
{
get; private set;
}
public int defaultSlotID
{
get; private set;
}
}
}

12
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/TextureNode.cs


if (onModified != null)
{
onModified(this, ModificationScope.Node);
onModified(this, ModificationScope.Node);
}
}
}

AddSlot(new MaterialSlot(OutputSlotGId, kOutputSlotGName, kOutputSlotGName, SlotType.Output, SlotValueType.Vector1, Vector4.zero));
AddSlot(new MaterialSlot(OutputSlotBId, kOutputSlotBName, kOutputSlotBName, SlotType.Output, SlotValueType.Vector1, Vector4.zero));
AddSlot(new MaterialSlot(OutputSlotAId, kOutputSlotAName, kOutputSlotAName, SlotType.Output, SlotValueType.Vector1, Vector4.zero));
AddSlot(new MaterialSlotDefaultInput(UvSlotId, kUVSlotName, kUVSlotName, SlotType.Input, SlotValueType.Vector2, new UVNode(), UVNode.OutputSlotId));
AddSlot(new MaterialSlot(UvSlotId, kUVSlotName, kUVSlotName, SlotType.Input, SlotValueType.Vector2, Vector4.zero));
RemoveSlotsNameNotMatching(validSlots);
}

if (uvSlot == null)
return;
var uvName = "error";
var uvName = string.Format("{0}.xy", ShaderGeneratorNames.UV0);
var edges = owner.GetEdges(uvSlot.slotReference).ToList();
if (edges.Count > 0)

uvName = ShaderGenerator.AdaptNodeOutput(fromNode, edge.outputSlot.slotId, ConcreteSlotValueType.Vector2, true);
}
else
{
Debug.LogError("Default slot behavior should return a virtual edge to virtual node");
}
string body = "tex2D (" + propertyName + ", " + uvName + ")";

return true;
var edges = owner.GetEdges(uvSlot.slotReference).ToList();
return (edges.Count <= 0);
return edges.Count == 0;
}
}
}
正在加载...
取消
保存