-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathnode-editor.cpp
More file actions
818 lines (626 loc) · 23.1 KB
/
Copy pathnode-editor.cpp
File metadata and controls
818 lines (626 loc) · 23.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
// Based on https://gist.github.com/emoon/b8ff4b4ce4f1b43e79f2
#include <iostream>
#include "sre/SDLRenderer.hpp"
#include "sre/SpriteAtlas.hpp"
#include "sre/Texture.hpp"
#include "sre/Material.hpp"
#include "sre/Inspector.hpp"
#include "glm/gtc/random.hpp"
#include "glm/ext.hpp"
using namespace sre;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define sizeof_array(t) (sizeof(t) / sizeof(t[0]))
const float NODE_SLOT_RADIUS = 5.0f;
const ImVec2 NODE_WINDOW_PADDING(8.0f, 8.0f);
#define MAX_CONNECTION_COUNT 32
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
static inline ImVec2 operator+(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(lhs.x+rhs.x, lhs.y+rhs.y); }
static inline ImVec2 operator-(const ImVec2& lhs, const ImVec2& rhs) { return ImVec2(lhs.x-rhs.x, lhs.y-rhs.y); }
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
static void error_callback(int error, const char* description)
{
fprintf(stderr, "Error %d: %s\n", error, description);
}
static uint32_t s_id = 0;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
enum ConnectionType
{
ConnectionType_Color,
ConnectionType_Vec3,
ConnectionType_Float,
ConnectionType_Int,
};
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
struct ConnectionDesc
{
const char* name;
ConnectionType type;
};
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
struct NodeType
{
const char* name;
ConnectionDesc inputConnections[MAX_CONNECTION_COUNT];
ConnectionDesc outputConnections[MAX_CONNECTION_COUNT];
};
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
struct Connection
{
ImVec2 pos;
ConnectionDesc desc;
inline Connection()
{
pos.x = pos.y = 0.0f;
input = 0;
}
union {
float v3[3];
float v;
int i;
};
struct Connection* input;
std::vector<Connection*> output;
};
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Node types
static struct NodeType s_nodeTypes[] =
{
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Math
{
"Multiply",
// Input connections
{
{ "Input1", ConnectionType_Float },
{ "Input2", ConnectionType_Float },
},
// Output
{
{ "Out", ConnectionType_Float },
},
},
{
"Add",
// Input connections
{
{ "Input1", ConnectionType_Float },
{ "Input2", ConnectionType_Float },
},
// Output
{
{ "Out", ConnectionType_Float },
},
},
};
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
struct Node
{
ImVec2 pos;
ImVec2 size;
int id;
const char* name;
std::vector<Connection*> inputConnections;
std::vector<Connection*> outputConnections;
};
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
static void setupConnections(std::vector<Connection*>& connections, ConnectionDesc* connectionDescs)
{
for (int i = 0; i < MAX_CONNECTION_COUNT; ++i)
{
const ConnectionDesc& desc = connectionDescs[i];
if (!desc.name)
break;
Connection* con = new Connection;
con->desc = desc;
connections.push_back(con);
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
static Node* createNodeFromType(ImVec2 pos, NodeType* nodeType)
{
Node* node = new Node;
node->id = s_id++;
node->name = nodeType->name;
ImVec2 titleSize = ImGui::CalcTextSize(node->name);
titleSize.y *= 3;
setupConnections(node->inputConnections, nodeType->inputConnections);
setupConnections(node->outputConnections, nodeType->outputConnections);
// Calculate the size needed for the whole box
ImVec2 inputTextSize(0.0f, 0.0f);
ImVec2 outputText(0.0f, 0.0f);
for (Connection* c : node->inputConnections)
{
ImVec2 textSize = ImGui::CalcTextSize(c->desc.name);
inputTextSize.x = std::max<float>(textSize.x, inputTextSize.x);
c->pos = ImVec2(0.0f, titleSize.y + inputTextSize.y + textSize.y / 2.0f);
inputTextSize.y += textSize.y;
inputTextSize.y += 4.0f; // size between text entries
}
inputTextSize.x += 40.0f;
// max text size + 40 pixels in between
float xStart = inputTextSize.x;
// Calculate for the outputs
for (Connection* c : node->outputConnections)
{
ImVec2 textSize = ImGui::CalcTextSize(c->desc.name);
inputTextSize.x = std::max<float>(xStart + textSize.x, inputTextSize.x);
}
node->pos = pos;
node->size.x = inputTextSize.x;
node->size.y = inputTextSize.y + titleSize.y;
inputTextSize.y = 0.0f;
// set the positions for the output nodes when we know where the place them
for (Connection* c : node->outputConnections)
{
ImVec2 textSize = ImGui::CalcTextSize(c->desc.name);
c->pos = ImVec2(node->size.x, titleSize.y + inputTextSize.y + textSize.y / 2.0f);
inputTextSize.y += textSize.y;
inputTextSize.y += 4.0f; // size between text entries
}
// calculate the size of the node depending on nuber of connections
return node;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Node* createNodeFromName(ImVec2 pos, const char* name)
{
for (int i = 0; i < (int)sizeof_array(s_nodeTypes); ++i)
{
if (!strcmp(s_nodeTypes[i].name, name))
return createNodeFromType(pos, &s_nodeTypes[i]);
}
return 0;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
enum DragState
{
DragState_Default,
DragState_Hover,
DragState_BeginDrag,
DragState_Draging,
DragState_Connect,
};
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
struct DragNode
{
ImVec2 pos;
Connection* con;
};
static DragNode s_dragNode;
static DragState s_dragState = DragState_Default;
static std::vector<Node*> s_nodes;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/*
static void saveNodes(const char* filename)
{
json_t* root = json_object();
json_t* nodes = json_array();
for (Node* node : s_nodes)
{
json_t* item = json_object();
json_object_set_new(item, "type", json_string(node->name));
json_object_set_new(item, "id", json_integer(node->id));
json_object_set_new(item, "pos", json_pack("{s:f, s:f}", "x", node->pos.x, "y", node->pos.y));
json_array_append_new(nodes, item);
}
// save the nodes
json_object_set_new(root, "nodes", nodes);
if (json_dump_file(root, filename, JSON_INDENT(4) | JSON_PRESERVE_ORDER) != 0)
printf("JSON: Unable to open %s for write\n", filename);
}
*/
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void drawHermite(ImDrawList* drawList, ImVec2 p1, ImVec2 p2, int STEPS)
{
ImVec2 t1 = ImVec2(+80.0f, 0.0f);
ImVec2 t2 = ImVec2(+80.0f, 0.0f);
for (int step = 0; step <= STEPS; step++)
{
float t = (float)step / (float)STEPS;
float h1 = +2*t*t*t - 3*t*t + 1.0f;
float h2 = -2*t*t*t + 3*t*t;
float h3 = t*t*t - 2*t*t + t;
float h4 = t*t*t - t*t;
drawList->PathLineTo(ImVec2(h1*p1.x + h2*p2.x + h3*t1.x + h4*t2.x, h1*p1.y + h2*p2.y + h3*t1.y + h4*t2.y));
}
drawList->PathStroke(ImColor(200,200,100), false, 3.0f);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
static bool isConnectorHovered(Connection* c, ImVec2 offset)
{
ImVec2 mousePos = ImGui::GetIO().MousePos;
ImVec2 conPos = offset + c->pos;
float xd = mousePos.x - conPos.x;
float yd = mousePos.y - conPos.y;
return ((xd * xd) + (yd *yd)) < (NODE_SLOT_RADIUS * NODE_SLOT_RADIUS);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
static Connection* getHoverCon(ImVec2 offset, ImVec2* pos)
{
for (Node* node : s_nodes)
{
ImVec2 nodePos = node->pos + offset;
for (Connection* con : node->inputConnections)
{
if (isConnectorHovered(con, nodePos))
{
*pos = nodePos + con->pos;
return con;
}
}
for (Connection* con : node->outputConnections)
{
if (isConnectorHovered(con, nodePos))
{
*pos = nodePos + con->pos;
return con;
}
}
}
s_dragNode.con = 0;
return 0;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void updateDraging(ImVec2 offset)
{
switch (s_dragState)
{
case DragState_Default:
{
ImVec2 pos;
Connection* con = getHoverCon(offset, &pos);
if (con)
{
s_dragNode.con = con;
s_dragNode.pos = pos;
s_dragState = DragState_Hover;
return;
}
break;
}
case DragState_Hover:
{
ImVec2 pos;
Connection* con = getHoverCon(offset, &pos);
// Make sure we are still hovering the same node
if (con != s_dragNode.con)
{
s_dragNode.con = 0;
s_dragState = DragState_Default;
return;
}
if (ImGui::IsMouseClicked(0) && s_dragNode.con)
s_dragState = DragState_Draging;
break;
}
case DragState_BeginDrag:
{
break;
}
case DragState_Draging:
{
ImDrawList* drawList = ImGui::GetWindowDrawList();
drawList->ChannelsSetCurrent(0); // Background
drawHermite(drawList, s_dragNode.pos, ImGui::GetIO().MousePos, 12);
if (!ImGui::IsMouseDown(0))
{
ImVec2 pos;
Connection* con = getHoverCon(offset, &pos);
// Make sure we are still hovering the same node
if (con == s_dragNode.con)
{
s_dragNode.con = 0;
s_dragState = DragState_Default;
return;
}
// Lets connect the nodes.
// TODO: Make sure we connect stuff in the correct way!
con->input = s_dragNode.con;
s_dragNode.con = 0;
s_dragState = DragState_Default;
}
break;
}
case DragState_Connect:
{
break;
}
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
static void displayNode(ImDrawList* drawList, ImVec2 offset, Node* node, int& node_selected)
{
int node_hovered_in_scene = -1;
bool open_context_menu = false;
ImGui::PushID(node->id);
ImVec2 node_rect_min = offset + node->pos;
// Display node contents first
drawList->ChannelsSetCurrent(1); // Foreground
bool old_any_active = ImGui::IsAnyItemActive();
// Draw title in center
ImVec2 textSize = ImGui::CalcTextSize(node->name);
ImVec2 pos = node_rect_min + NODE_WINDOW_PADDING;
pos.x = node_rect_min.x + (node->size.x / 2) - textSize.x / 2;
ImGui::SetCursorScreenPos(pos);
//ImGui::BeginGroup(); // Lock horizontal position
ImGui::Text("%s", node->name);
//ImGui::SliderFloat("##value", &node->Value, 0.0f, 1.0f, "Alpha %.2f");
//float dummy_color[3] = { node->Pos.x / ImGui::GetWindowWidth(), node->Pos.y / ImGui::GetWindowHeight(), fmodf((float)node->ID * 0.5f, 1.0f) };
//ImGui::ColorEdit3("##color", &dummy_color[0]);
// Save the size of what we have emitted and weither any of the widgets are being used
bool node_widgets_active = (!old_any_active && ImGui::IsAnyItemActive());
//node->size = ImGui::GetItemRectSize() + NODE_WINDOW_PADDING + NODE_WINDOW_PADDING;
ImVec2 node_rect_max = node_rect_min + node->size;
// Display node box
drawList->ChannelsSetCurrent(0); // Background
ImGui::SetCursorScreenPos(node_rect_min);
ImGui::InvisibleButton("node", node->size);
if (ImGui::IsItemHovered())
{
node_hovered_in_scene = node->id;
open_context_menu |= ImGui::IsMouseClicked(1);
}
bool node_moving_active = false;
if (ImGui::IsItemActive() && !s_dragNode.con)
node_moving_active = true;
ImU32 node_bg_color = node_hovered_in_scene == node->id ? ImColor(75,75,75) : ImColor(60,60,60);
drawList->AddRectFilled(node_rect_min, node_rect_max, node_bg_color, 4.0f);
ImVec2 titleArea = node_rect_max;
titleArea.y = node_rect_min.y + 30.0f;
// Draw text bg area
drawList->AddRectFilled(node_rect_min + ImVec2(1,1), titleArea, ImColor(100,0,0), 4.0f);
drawList->AddRect(node_rect_min, node_rect_max, ImColor(100,100,100), 4.0f);
ImVec2 off;
offset.y += 40.0f;
offset = offset + node_rect_min;
off.x = node_rect_min.x;
off.y = node_rect_min.y;
for (Connection* con : node->inputConnections)
{
ImGui::SetCursorScreenPos(offset + ImVec2(10.0f, 0));
ImGui::Text("%s", con->desc.name);
ImColor conColor = ImColor(150, 150, 150);
if (isConnectorHovered(con, node_rect_min))
conColor = ImColor(200, 200, 200);
drawList->AddCircleFilled(node_rect_min + con->pos, NODE_SLOT_RADIUS, conColor);
offset.y += textSize.y + 2.0f;
}
offset = node_rect_min;
offset.y += 40.0f;
for (Connection* con : node->outputConnections)
{
textSize = ImGui::CalcTextSize(con->desc.name);
ImGui::SetCursorScreenPos(offset + ImVec2(con->pos.x - (textSize.x + 10.0f), 0));
ImGui::Text("%s", con->desc.name);
ImColor conColor = ImColor(150, 150, 150);
if (isConnectorHovered(con, node_rect_min))
conColor = ImColor(200, 200, 200);
drawList->AddCircleFilled(node_rect_min + con->pos, NODE_SLOT_RADIUS, conColor);
offset.y += textSize.y + 2.0f;
}
//for (int i = 0; i < node->outputConnections.size(); ++i)
// drawList->AddCircleFilled(offset + node->outputSlotPos(i), NODE_SLOT_RADIUS, ImColor(150,150,150,150));
if (node_widgets_active || node_moving_active)
node_selected = node->id;
if (node_moving_active && ImGui::IsMouseDragging(0))
node->pos = node->pos + ImGui::GetIO().MouseDelta;
//ImGui::EndGroup();
ImGui::PopID();
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// TODO: Ugly fix: me
Node* findNodeByCon(Connection* findCon)
{
for (Node* node : s_nodes)
{
for (Connection* con : node->inputConnections)
{
if (con == findCon)
return node;
}
for (Connection* con : node->outputConnections)
{
if (con == findCon)
return node;
}
}
return 0;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void renderLines(ImDrawList* drawList, ImVec2 offset)
{
for (Node* node : s_nodes)
{
for (Connection* con : node->inputConnections)
{
if (!con->input)
continue;
Node* targetNode = findNodeByCon(con->input);
if (!targetNode)
continue;
drawHermite(drawList,
offset + targetNode->pos + con->input->pos,
offset + node->pos + con->pos,
12);
}
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
static void ShowExampleAppCustomNodeGraph(bool* opened)
{
ImGui::SetNextWindowSize(ImVec2(700,600), ImGuiCond_FirstUseEver);
if (!ImGui::Begin("Example: Custom Node Graph", opened))
{
ImGui::End();
return;
}
bool open_context_menu = false;
int node_hovered_in_list = -1;
int node_hovered_in_scene = -1;
static int node_selected = -1;
static ImVec2 scrolling = ImVec2(0.0f, 0.0f);
#if 0
static ImVector<Node> nodes;
static ImVector<NodeLink> links;
static bool inited = false;
static ImVec2 scrolling = ImVec2(0.0f, 0.0f);
static int node_selected = -1;
if (!inited)
{
nodes.push_back(Node(0, "MainTex", ImVec2(40,50), 0.5f, 1, 1));
nodes.push_back(Node(1, "BumpMap", ImVec2(40,150), 0.42f, 1, 1));
nodes.push_back(Node(2, "Combine", ImVec2(270,80), 1.0f, 2, 2));
links.push_back(NodeLink(0, 0, 2, 0));
links.push_back(NodeLink(1, 0, 2, 1));
inited = true;
}
// Draw a list of nodes on the left side
ImGui::BeginChild("node_list", ImVec2(100,0));
ImGui::Text("Nodes");
ImGui::Separator();
for (int node_idx = 0; node_idx < nodes.Size; node_idx++)
{
Node* node = &nodes[node_idx];
ImGui::PushID(node->ID);
if (ImGui::Selectable(node->Name, node->ID == node_selected))
node_selected = node->ID;
if (ImGui::IsItemHovered())
{
node_hovered_in_list = node->ID;
open_context_menu |= ImGui::IsMouseClicked(1);
}
ImGui::PopID();
}
ImGui::EndChild();
#endif
ImGui::SameLine();
ImGui::BeginGroup();
// Create our child canvas
//ImGui::Text("Hold middle mouse button to scroll (%.2f,%.2f)", scrolling.x, scrolling.y);
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(1,1));
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0,0));
ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(40,40,40,200));
ImGui::BeginChild("scrolling_region", ImVec2(0,0), true, ImGuiWindowFlags_NoScrollbar|ImGuiWindowFlags_NoMove);
ImGui::PushItemWidth(120.0f);
ImDrawList* draw_list = ImGui::GetWindowDrawList();
draw_list->ChannelsSplit(2);
//ImVec2 offset = ImGui::GetCursorScreenPos() - scrolling;
//displayNode(draw_list, scrolling, s_emittable, node_selected);
//displayNode(draw_list, scrolling, s_emitter, node_selected);
for (Node* node : s_nodes)
displayNode(draw_list, scrolling, node, node_selected);
updateDraging(scrolling);
renderLines(draw_list, scrolling);
draw_list->ChannelsMerge();
// Open context menu
auto mouseHovering = ImGui::IsWindowHovered(ImGuiHoveredFlags_AllowWhenBlockedByPopup | ImGuiHoveredFlags_AllowWhenBlockedByActiveItem);
if (!ImGui::IsAnyItemHovered() && mouseHovering && ImGui::IsMouseClicked(1))
{
node_selected = node_hovered_in_list = node_hovered_in_scene = -1;
open_context_menu = true;
}
if (open_context_menu)
{
ImGui::OpenPopup("context_menu");
if (node_hovered_in_list != -1)
node_selected = node_hovered_in_list;
if (node_hovered_in_scene != -1)
node_selected = node_hovered_in_scene;
}
// Draw context menu
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(8,8));
if (ImGui::BeginPopup("context_menu"))
{
if (ImGui::MenuItem("Load graph..."))
{
/*
char path[1024];
if (Dialog_open(path))
{
printf("file to load %s\n", path);
}
*/
}
if (ImGui::MenuItem("Save graph..."))
{
/*
char path[1024];
if (Dialog_save(path))
{
saveNodes(path);
}
*/
}
/*
Node* node = node_selected != -1 ? &nodes[node_selected] : NULL;
ImVec2 scene_pos = ImGui::GetMousePosOnOpeningCurrentPopup() - offset;
if (node)
{
ImGui::Text("Node '%s'", node->Name);
ImGui::Separator();
if (ImGui::MenuItem("Rename..", NULL, false, false)) {}
if (ImGui::MenuItem("Delete", NULL, false, false)) {}
if (ImGui::MenuItem("Copy", NULL, false, false)) {}
}
*/
//else
for (int i = 0; i < (int)sizeof_array(s_nodeTypes); ++i)
{
if (ImGui::MenuItem(s_nodeTypes[i].name))
{
Node* node = createNodeFromType(ImGui::GetIO().MousePos, &s_nodeTypes[i]);
s_nodes.push_back(node);
}
}
ImGui::EndPopup();
}
ImGui::PopStyleVar();
// Scrolling
if (ImGui::IsWindowHovered() && !ImGui::IsAnyItemActive() && ImGui::IsMouseDragging(2, 0.0f))
scrolling = scrolling - ImGui::GetIO().MouseDelta;
ImGui::PopItemWidth();
ImGui::EndChild();
ImGui::PopStyleColor();
ImGui::PopStyleVar(2);
ImGui::EndGroup();
ImGui::End();
}
class NodeEditor {
public:
NodeEditor()
{
r.init();
r.setWindowTitle("Lua example");
l.addLight(Light::create().withDirectionalLight({1,1,1}).withColor({1,1,1}).build());
auto mat = Shader::getStandardPhong()->createMaterial();
mat->setColor({1,0,0,1});
auto sphere = Mesh::create().withSphere().build();
camera.setPerspectiveProjection(45,0.1,100);
camera.lookAt({0,15,-20},{0,0,0},{0,1,0});
r.frameUpdate = [&](float deltaTime){
update(deltaTime);
};
r.frameRender = [&](){
render();
};
r.startEventLoop();
}
void update(float deltaTime){
}
void render(){
RenderPass rp = RenderPass::create()
.withCamera(camera)
.withWorldLights(&l)
.build();
static bool show_test_window = true;
ShowExampleAppCustomNodeGraph(&show_test_window);
}
private:
SDLRenderer r;
WorldLights l;
Camera camera;
};
int main() {
std::cout << "https://github.com/mortennobel/SimpleRenderEngineProject" << std::endl;
new NodeEditor();
return 0;
}