1#include "Generators/CPUNodeEditor/Nodes/MathFunctionNode.h"
2#include "Generators/CPUNodeEditor/CPUNodeEditor.h"
13static void SetupParser(mu::Parser *parser)
27 x = (input.x / input.maxX) * 2 - 1;
28 y = (input.y / input.maxY) * 2 - 1;
29 z = (input.z / input.maxZ) * 2 - 1;
30 return NodeOutput({(float)parser->Eval() * factor});
42 std::string expr = data[
"expr"];
43 memcpy(inputExpression, expr.data(), data.
size());
44 mathInputWidth = data[
"mathInputWidth"];
45 factor = data[
"factor"];
65 data[
"type"] = MeshNodeEditor::MeshNodeType::MathFunction;
66 data[
"expr"] = std::string(inputExpression);
67 data[
"mathInputWidth"] = mathInputWidth;
68 data[
"factor"] = factor;
82void MathFunctionNode::OnRender()
84 DrawHeader(
"Custom Math Function");
85 ImGui::Dummy(ImVec2(mathInputWidth + 20, 10));
88 outputPins[0]->Render();
90 ImGui::Text(
"Math Input Size : ");
92 ImGui::PushItemWidth(100);
93 ImGui::DragInt(MAKE_IMGUI_ID(outputPins[0]->
id), &mathInputWidth, 0.5f);
94 ImGui::PopItemWidth();
95 inputPins[0]->Render();
97 if (inputPins[0]->IsLinked())
99 ImGui::Text(
"Factor");
104 ImGui::PushItemWidth(100);
105 ImGui::DragFloat(MAKE_IMGUI_ID(inputPins[0]->
id), &factor, 0.01f);
106 ImGui::PopItemWidth();
141 ImGui::Text(
"Expression : ");
143 ImGui::PushItemWidth(mathInputWidth);
145 if (ImGui::InputText(MAKE_IMGUI_ID(
id), inputExpression, 1024*4))
150 ImGui::PopItemWidth();
154 if (ImGui::Button(
"Compile"))
156 std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
157 std::wstring wide = converter.from_bytes(inputExpression);
162 parser->SetExpr(wide);
164 parser->SetExpr(std::string(inputExpression));
176MathFunctionNode::MathFunctionNode()
178 headerColor = ImColor(VALUE_NODE_COLOR);
180 outputPins.push_back(
new NodeEditorPin(NodeEditorPinType::Output));
181 parser =
new mu::Parser();
182 memset(inputExpression, 0,
sizeof(inputExpression));
183 memset(varname, 0,
sizeof(varname));
186 mathInputWidth = 150;
190 parser->DefineVar(L
"x", &x);
191 parser->DefineVar(L
"y", &y);
192 parser->DefineVar(L
"z", &z);
194 parser->DefineVar(
"x", &x);
195 parser->DefineVar(
"y", &y);
196 parser->DefineVar(
"z", &z);
size_type size() const noexcept
returns the number of elements
a class to store JSON values