TerraForge3D  2.3.1
3D Terrain And Landscape Generator
MinValNode.cpp
1#include "Generators/CPUNodeEditor/Nodes/MinValNode.h"
2#include "Base/ImGuiShapes.h"
3#include "Generators/CPUNodeEditor/CPUNodeEditor.h"
4#include <iostream>
5
6#include <mutex>
7#include "Base/ImGuiCurveEditor.h"
8
9NodeOutput MinValNode::Evaluate(NodeInputParam input, NodeEditorPin *pin)
10{
11 float x = inputf;
12
13 if (inputPins[0]->IsLinked())
14 {
15 x = inputPins[0]->other->Evaluate(input).value;
16 }
17
18 float t = thresholdf;
19
20 if (inputPins[1]->IsLinked())
21 {
22 t = inputPins[1]->other->Evaluate(input).value;
23 }
24
25 if(x > t)
26 {
27 if(inputPins[3]->IsLinked())
28 return NodeOutput({ inputPins[3]->Evaluate(input) });
29 else
30 return NodeOutput({ outputr });
31 }
32
33 else
34 {
35 if(inputPins[2]->IsLinked())
36 return NodeOutput({ inputPins[2]->Evaluate(input) });
37 else
38 return NodeOutput({ outputf });
39 }
40}
41
42void MinValNode::Load(nlohmann::json data)
43{
44 inputf = data["inputf"];
45 outputf = data["outputf"];
46 outputr = data["outputr"];
47 thresholdf = data["thresholdf"];
48}
49
50nlohmann::json MinValNode::Save()
51{
52 nlohmann::json data;
53 data["type"] = MeshNodeEditor::MeshNodeType::MinVal;
54 data["inputf"] = inputf;
55 data["outputf"] = outputf;
56 data["outputr"] = outputr;
57 data["thresholdf"] = thresholdf;
58 return data;
59}
60
61void MinValNode::OnRender()
62{
63 DrawHeader("Min Val");
64 inputPins[0]->Render();
65
66 if (inputPins[0]->IsLinked())
67 {
68 ImGui::Text("Input");
69 }
70
71 else
72 {
73 ImGui::PushItemWidth(100);
74 ImGui::DragFloat(("##" + std::to_string(inputPins[0]->id)).c_str(), &inputf, 0.01f);
75 ImGui::PopItemWidth();
76 }
77
78 ImGui::SameLine();
79 ImGui::Text("Output");
80 outputPins[0]->Render();
81 inputPins[1]->Render();
82
83 if (inputPins[1]->IsLinked())
84 {
85 ImGui::Text("Threshold");
86 }
87
88 else
89 {
90 ImGui::PushItemWidth(100);
91 ImGui::DragFloat(("##" + std::to_string(inputPins[1]->id)).c_str(), &thresholdf, 0.01f);
92 ImGui::PopItemWidth();
93 }
94
95 inputPins[2]->Render();
96
97 if(inputPins[2]->IsLinked())
98 {
99 ImGui::Text("Output F");
100 }
101
102 else
103 {
104 ImGui::PushItemWidth(100);
105 ImGui::DragFloat(("##" + std::to_string(inputPins[2]->id)).c_str(), &outputf, 0.01f);
106 ImGui::PopItemWidth();
107 }
108
109 inputPins[3]->Render();
110
111 if(inputPins[3]->IsLinked())
112 {
113 ImGui::Text("Output R");
114 }
115
116 else
117 {
118 ImGui::PushItemWidth(100);
119 ImGui::DragFloat(("##" + std::to_string(inputPins[3]->id)).c_str(), &outputr, 0.01f);
120 ImGui::PopItemWidth();
121 }
122}
123
124MinValNode::MinValNode()
125{
126 inputPins.push_back(new NodeEditorPin());
127 inputPins.push_back(new NodeEditorPin());
128 inputPins.push_back(new NodeEditorPin()); // FOR FUTURE
129 inputPins.push_back(new NodeEditorPin()); // FOR FUTURE
130 outputPins.push_back(new NodeEditorPin(NodeEditorPinType::Output));
131 headerColor = ImColor(OP_NODE_COLOR);
132 outputf = inputf = outputr = thresholdf = 0.0f;
133 thresholdf = 0.5f;
134}
a class to store JSON values
Definition: json.hpp:17860