|
77 | 77 |
|
78 | 78 | document.addEventListener('DOMContentLoaded', function () {
|
79 | 79 | document.body.appendChild(rootContainer);
|
80 |
| - interactor.bindEvents(document.body); |
81 | 80 | });
|
82 | 81 |
|
83 | 82 | function updateViewPort(element, renderer) {
|
|
114 | 113 |
|
115 | 114 |
|
116 | 115 | function enterCurrentRenderer(e) {
|
| 116 | + interactor.bindEvents(document.body); |
117 | 117 | interact_style.setEnabled(true);
|
118 | 118 | interactor.setCurrentRenderer(RENDERERS[e.target.id]);
|
119 | 119 | }
|
120 | 120 |
|
121 | 121 | function exitCurrentRenderer(e) {
|
122 | 122 | interactor.setCurrentRenderer(null);
|
123 | 123 | interact_style.setEnabled(false);
|
| 124 | + interactor.unbindEvents(); |
124 | 125 | }
|
125 | 126 |
|
126 | 127 |
|
|
136 | 137 | window.addEventListener('load', resize);
|
137 | 138 |
|
138 | 139 | function render(data, parent_element, ratio){
|
139 |
| - |
| 140 | +
|
140 | 141 | // Initial setup
|
141 | 142 | const renderer = vtk.Rendering.Core.vtkRenderer.newInstance({ background: [1, 1, 1 ] });
|
142 |
| - |
| 143 | +
|
143 | 144 | // iterate over all children children
|
144 | 145 | for (var el of data){
|
145 | 146 | var trans = el.position;
|
146 | 147 | var rot = el.orientation;
|
147 | 148 | var rgba = el.color;
|
148 | 149 | var shape = el.shape;
|
149 |
| - |
| 150 | +
|
150 | 151 | // load the inline data
|
151 | 152 | var reader = vtk.IO.XML.vtkXMLPolyDataReader.newInstance();
|
152 | 153 | const textEncoder = new TextEncoder();
|
|
162 | 163 | // set color and position
|
163 | 164 | actor.getProperty().setColor(rgba.slice(0,3));
|
164 | 165 | actor.getProperty().setOpacity(rgba[3]);
|
165 |
| - |
| 166 | +
|
166 | 167 | actor.rotateZ(rot[2]*180/Math.PI);
|
167 | 168 | actor.rotateY(rot[1]*180/Math.PI);
|
168 | 169 | actor.rotateX(rot[0]*180/Math.PI);
|
169 |
| - |
| 170 | +
|
170 | 171 | actor.setPosition(trans);
|
171 | 172 |
|
172 | 173 | renderer.addActor(actor);
|
173 | 174 |
|
174 | 175 | };
|
175 |
| - |
| 176 | +
|
176 | 177 | //add the container
|
177 | 178 | const container = applyStyle(document.createElement("div"));
|
178 | 179 | parent_element.appendChild(container);
|
179 | 180 | container.addEventListener('mouseenter', enterCurrentRenderer);
|
180 | 181 | container.addEventListener('mouseleave', exitCurrentRenderer);
|
181 | 182 | container.id = ID;
|
182 |
| - |
| 183 | +
|
183 | 184 | renderWindow.addRenderer(renderer);
|
184 | 185 | updateViewPort(container, renderer);
|
185 | 186 | renderer.resetCamera();
|
186 |
| - |
| 187 | +
|
187 | 188 | RENDERERS[ID] = renderer;
|
188 |
| - ID++; |
| 189 | + ID++; |
189 | 190 | };
|
190 | 191 | """
|
191 | 192 |
|
|
0 commit comments