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