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