-
Notifications
You must be signed in to change notification settings - Fork 2
/
beameditor.ves
117 lines (93 loc) · 2.33 KB
/
beameditor.ves
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
import "blueprint.blueprint" for Blueprint
import "blueprint.nodes.array" for Array
import "blueprint.nodes.subgraph" for Subgraph
import "editor.editor" for Editor
import "editor.node_cache" for NODE_CACHE
import "geograph.brush" for Brush
import "network.edit_op" for EditOP as NetworkEditOP
import "network.vertex" for Vertex
import "beamgraph.beam_frame" for BeamFrame
import "maths.vector" for Vector3
var RENDER_NODE_FILENAME = "9_edit_draw.ves"
class Beameditor is Editor
{
load()
{
super.load()
this.nodes_op = NetworkEditOP(this.camera, this.scene_stack, this.popup_cb)
this.editop = this.nodes_op
this.prepare_nodes()
this.all_geos = Array()
this.bf = BeamFrame()
this.render_node = nil
this.add_node(NODE_CACHE.fetch("../yingzao/99_tools/%(RENDER_NODE_FILENAME)", nil), 0, 0)
this.selected = nil
}
prepare_nodes()
{
this.clear_popup_nodes()
import "beamnodes" for BEAM_NODES
for (var node in BEAM_NODES) {
super.add_popup_node(node)
}
}
rebuild_all_geos()
{
this.all_geos.list.clear()
var scene = this.scene_stack.root()
if (!scene.nodes.isEmpty) {
this.bf.rebuild(scene, this.all_geos.list)
}
}
set_brush_color(val, col)
{
if (val is Brush) {
val.set_color(col.x, col.y, col.z)
} else if (val is List) {
for (var i in val) {
this.set_brush_color(i.value.shape, col)
}
}
}
set_node_color(node, col)
{
if (node is Vertex and node.v_geo) {
this.set_brush_color(node.v_geo.value.shape, col)
}
}
draw_preview()
{
if (this.scene_stack.bp_dirty)
{
this.rebuild_all_geos()
Blueprint.send_pin_dirty_root(this.all_geos.exports[0])
}
var selected = this.preview_op.get_selected()
if (selected != this.selected)
{
this.set_node_color(this.selected, Vector3(255, 255, 255))
this.set_node_color(selected, Vector3(255, 0, 0))
this.selected = selected
Blueprint.send_pin_dirty_root(this.all_geos.exports[0])
}
super.draw_preview()
if (this.render_node) {
this.render_node.render_run()
}
}
add_node(bp_node, x, y)
{
super.add_node(bp_node, x, y)
if (bp_node is Subgraph and bp_node.filepath.contains(RENDER_NODE_FILENAME))
{
this.render_node = bp_node
Blueprint.connect(this.all_geos, 0, this.render_node, 1)
}
}
load_file_imports()
{
return super.load_file_imports() + "
import \"network.network\" for Network
"
}
}