Skip to content

Commit 267d225

Browse files
adam-urbanczykmarcus7070
authored andcommitted
Bind events on enter
1 parent 4c5816d commit 267d225

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

cadquery/cq_directive.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@
7777
7878
document.addEventListener('DOMContentLoaded', function () {
7979
document.body.appendChild(rootContainer);
80-
interactor.bindEvents(document.body);
8180
});
8281
8382
function updateViewPort(element, renderer) {
@@ -114,13 +113,15 @@
114113
115114
116115
function enterCurrentRenderer(e) {
116+
interactor.bindEvents(document.body);
117117
interact_style.setEnabled(true);
118118
interactor.setCurrentRenderer(RENDERERS[e.target.id]);
119119
}
120120
121121
function exitCurrentRenderer(e) {
122122
interactor.setCurrentRenderer(null);
123123
interact_style.setEnabled(false);
124+
interactor.unbindEvents();
124125
}
125126
126127
@@ -136,17 +137,17 @@
136137
window.addEventListener('load', resize);
137138
138139
function render(data, parent_element, ratio){
139-
140+
140141
// Initial setup
141142
const renderer = vtk.Rendering.Core.vtkRenderer.newInstance({ background: [1, 1, 1 ] });
142-
143+
143144
// iterate over all children children
144145
for (var el of data){
145146
var trans = el.position;
146147
var rot = el.orientation;
147148
var rgba = el.color;
148149
var shape = el.shape;
149-
150+
150151
// load the inline data
151152
var reader = vtk.IO.XML.vtkXMLPolyDataReader.newInstance();
152153
const textEncoder = new TextEncoder();
@@ -162,30 +163,30 @@
162163
// set color and position
163164
actor.getProperty().setColor(rgba.slice(0,3));
164165
actor.getProperty().setOpacity(rgba[3]);
165-
166+
166167
actor.rotateZ(rot[2]*180/Math.PI);
167168
actor.rotateY(rot[1]*180/Math.PI);
168169
actor.rotateX(rot[0]*180/Math.PI);
169-
170+
170171
actor.setPosition(trans);
171172
172173
renderer.addActor(actor);
173174
174175
};
175-
176+
176177
//add the container
177178
const container = applyStyle(document.createElement("div"));
178179
parent_element.appendChild(container);
179180
container.addEventListener('mouseenter', enterCurrentRenderer);
180181
container.addEventListener('mouseleave', exitCurrentRenderer);
181182
container.id = ID;
182-
183+
183184
renderWindow.addRenderer(renderer);
184185
updateViewPort(container, renderer);
185186
renderer.resetCamera();
186-
187+
187188
RENDERERS[ID] = renderer;
188-
ID++;
189+
ID++;
189190
};
190191
"""
191192

0 commit comments

Comments
 (0)