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