TerraForge3D  2.3.1
3D Terrain And Landscape Generator
ShaderNodeEditor.cpp
1#include "Shading/ShaderNodeEditor.h"
2
3// ------------------ SNEPin ------------------
4
5SNEPin::SNEPin(NodeEditorPinType type, SNEPinType var)
6 : NodeEditorPin(type)
7{
8 SetType(var);
9}
10
11SNEPin::~SNEPin()
12{
13}
14
15SNEPinType SNEPin::GetType()
16{
17 return static_cast<SNEPinType>(userData);
18}
19
20void SNEPin::SetType(SNEPinType type)
21{
22 userData = type;
23
24 switch(type)
25 {
26 case SNEPinType_Float:
27 color = ImColor(FLOAT_PIN_COLOR);
28 break;
29
30 case SNEPinType_Float2:
31 color = ImColor(FLOAT2_PIN_COLOR);
32 break;
33
34 case SNEPinType_Float3:
35 color = ImColor(FLOAT3_PIN_COLOR);
36 break;
37
38 case SNEPinType_Bool:
39 color = ImColor(BOOL_PIN_COLOR);
40 break;
41 }
42}
43
44// ------------------ SNENode ------------------
45
46SNENode::SNENode(GLSLHandler *handler)
47 :handler(handler)
48{
49}
50
51SNENode::~SNENode()
52{
53}
54
55NodeOutput SNENode::Evaluate(NodeInputParam input, NodeEditorPin *pin)
56{
57 if(pin)
58 callerPinId = pin->id;
59 GLSLFunction *function = static_cast<GLSLFunction *>(input.userData1);
60 GLSLLine *line = static_cast<GLSLLine *>(input.userData2);
61 OnEvaluate(function, line);
62 return NodeOutput({0.0f});
63}
64
65bool SNENode::OnLink(NodeEditorPin *pin, NodeEditorLink *link)
66{
67 SNEPin *selfPin = static_cast<SNEPin *>(pin);
68 SNEPin *otherPin = nullptr;
69
70 if(selfPin->type == NodeEditorPinType::Input)
71 {
72 otherPin = static_cast<SNEPin *>(link->to);
73 }
74
75 else
76 {
77 otherPin = static_cast<SNEPin *>(link->from);
78 }
79
80 return (selfPin->GetType() == otherPin->GetType());
81}