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