TerraForge3D  2.3.1
3D Terrain And Landscape Generator

◆ OnRender()

void MathFunctionNode::OnRender ( )
virtual

Implements NodeEditorNode.

Definition at line 82 of file MathFunctionNode.cpp.

83{
84 DrawHeader("Custom Math Function");
85 ImGui::Dummy(ImVec2(mathInputWidth + 20, 10));
86 ImGui::SameLine();
87 ImGui::Text("Out");
88 outputPins[0]->Render();
89 ImGui::NewLine();
90 ImGui::Text("Math Input Size : ");
91 ImGui::SameLine();
92 ImGui::PushItemWidth(100);
93 ImGui::DragInt(MAKE_IMGUI_ID(outputPins[0]->id), &mathInputWidth, 0.5f);
94 ImGui::PopItemWidth();
95 inputPins[0]->Render();
96
97 if (inputPins[0]->IsLinked())
98 {
99 ImGui::Text("Factor");
100 }
101
102 else
103 {
104 ImGui::PushItemWidth(100);
105 ImGui::DragFloat(MAKE_IMGUI_ID(inputPins[0]->id), &factor, 0.01f);
106 ImGui::PopItemWidth();
107 }
108
109 ImGui::NewLine();
110 /*
111 ImGui::Text("Varaibles : ");
112 for (int i = 0;i<vars.size();i++)
113 {
114 ImGui::PushItemWidth(200);
115 ImGui::InputDouble(MAKE_IMGUI_LABEL(i, vars[i].first.c_str()), &vars[i].second, 0.01f);
116 ImGui::PopItemWidth();
117 ImGui::SameLine();
118 if (ImGui::Button("X"))
119 {
120 parser->RemoveVar(s2ws(vars[i].first));
121 vars.erase(vars.begin() + i);
122 break;
123 }
124 }
125
126 ImGui::Text("Add Variable : ");
127 ImGui::SameLine();
128 ImGui::PushItemWidth(100);
129 ImGui::InputTextWithHint(MAKE_IMGUI_ID(tid), "Name", varname, sizeof(varname));
130 ImGui::SameLine();
131 ImGui::PopItemWidth();
132 ImGui::SameLine();
133 if (ImGui::Button("Add") && strlen(varname) >= 1)
134 {
135 vars.push_back(std::make_pair<std::string, double>(varname, 0.0f));
136 parser->DefineVar(s2ws(std::string(varname)), &vars.back().second);
137 memset(varname, 0, sizeof(varname));
138 }
139
140 */
141 ImGui::Text("Expression : ");
142 ImGui::SameLine();
143 ImGui::PushItemWidth(mathInputWidth);
144
145 if (ImGui::InputText(MAKE_IMGUI_ID(id), inputExpression, 1024*4))
146 {
147 compiled = false;
148 }
149
150 ImGui::PopItemWidth();
151
152 if (!compiled)
153 {
154 if (ImGui::Button("Compile"))
155 {
156 std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
157 std::wstring wide = converter.from_bytes(inputExpression);
158
159 try
160 {
161#ifdef TERR3D_WIN32
162 parser->SetExpr(wide);
163#else
164 parser->SetExpr(std::string(inputExpression));
165#endif
166 compiled = true;
167 }
168
169 catch (...)
170 {
171 }
172 }
173 }
174}