|
139 | 139 |
|
140 | 140 | }
|
141 | 141 |
|
142 |
| - function createWindow() { |
| 142 | + async function createWindow() { |
143 | 143 |
|
144 | 144 | let texture = textureLoader.load('./textures/brick-wall.jpg');
|
145 | 145 |
|
|
166 | 166 | horizontalWallMesh3.position.y = 9;
|
167 | 167 | horizontalWallMesh4.position.y = 19;
|
168 | 168 |
|
169 |
| - let resultPolytree = Polytree.uniteArray([verticalWallMesh, verticalWallMesh2, verticalWallMesh3, horizontalWallMesh, horizontalWallMesh2, horizontalWallMesh3, horizontalWallMesh4], 0); |
| 169 | + let resultPolytree = await Polytree.async.uniteArray([verticalWallMesh, verticalWallMesh2, verticalWallMesh3, horizontalWallMesh, horizontalWallMesh2, horizontalWallMesh3, horizontalWallMesh4], 0); |
170 | 170 |
|
171 | 171 | return Polytree.toMesh(resultPolytree, baseMaterial);
|
172 | 172 |
|
|
209 | 209 | scene.add(titan1, titan2);
|
210 | 210 | });
|
211 | 211 |
|
212 |
| - let windowMesh = createWindow(); |
213 |
| - let windowDimensions = getDimensions(windowMesh.geometry); |
214 |
| - let hollowWindowGeometry = new THREE.BoxGeometry(windowDimensions.width - 0.1, windowDimensions.height - 0.1, windowDimensions.depth + 2); |
215 |
| - let baseWindowMaterial = new THREE.MeshStandardMaterial({ color: 0x3c3c3c }); |
216 |
| - let hollowWindowMesh = new THREE.Mesh(hollowWindowGeometry, baseWindowMaterial); |
217 |
| - |
218 |
| - windowMesh.geometry.clearGroups(); |
219 |
| - hollowWindowMesh.geometry.clearGroups(); |
220 |
| - |
221 |
| - windowMesh.position.set(90, 29, 17.5); |
222 |
| - hollowWindowMesh.position.copy(windowMesh.position); |
223 |
| - |
224 |
| - let towerPolytree = Polytree.fromMesh(wall, 0); |
225 |
| - let windowPolytree = Polytree.fromMesh(windowMesh, 1); |
226 |
| - let hollowWindowPolytree = Polytree.fromMesh(hollowWindowMesh, 0); |
227 |
| - let originalMatrix = windowMesh.matrix.clone(); |
228 |
| - |
229 |
| - var towerWithWindowMesh; |
230 |
| - Polytree.async.operation({ |
231 |
| - op: "unite", |
232 |
| - material: [wall.material, windowMesh.material], |
233 |
| - objA: { |
234 |
| - op: "subtract", |
235 |
| - objA: towerPolytree.clone(), |
236 |
| - objB: hollowWindowPolytree.clone() |
237 |
| - }, |
238 |
| - objB: windowPolytree.clone() |
239 |
| - }).then(mesh => { |
240 |
| - scene.remove(wall); |
241 |
| - towerWithWindowMesh = mesh; |
242 |
| - scene.add(towerWithWindowMesh); |
243 |
| - }); |
| 212 | + createWindow().then(windowMesh => { |
| 213 | + let windowDimensions = getDimensions(windowMesh.geometry); |
| 214 | + let hollowWindowGeometry = new THREE.BoxGeometry(windowDimensions.width - 0.1, windowDimensions.height - 0.1, windowDimensions.depth + 2); |
| 215 | + let baseWindowMaterial = new THREE.MeshStandardMaterial({ color: 0x3c3c3c }); |
| 216 | + let hollowWindowMesh = new THREE.Mesh(hollowWindowGeometry, baseWindowMaterial); |
| 217 | + |
| 218 | + windowMesh.geometry.clearGroups(); |
| 219 | + hollowWindowMesh.geometry.clearGroups(); |
| 220 | + |
| 221 | + windowMesh.position.set(90, 29, 17.5); |
| 222 | + hollowWindowMesh.position.copy(windowMesh.position); |
| 223 | + |
| 224 | + let towerPolytree = Polytree.fromMesh(wall, 0); |
| 225 | + let windowPolytree = Polytree.fromMesh(windowMesh, 1); |
| 226 | + let hollowWindowPolytree = Polytree.fromMesh(hollowWindowMesh, 0); |
| 227 | + let originalMatrix = windowMesh.matrix.clone(); |
| 228 | + |
| 229 | + var towerWithWindowMesh; |
| 230 | + Polytree.async.operation({ |
| 231 | + op: "unite", |
| 232 | + material: [wall.material, windowMesh.material], |
| 233 | + objA: { |
| 234 | + op: "subtract", |
| 235 | + objA: towerPolytree.clone(), |
| 236 | + objB: hollowWindowPolytree.clone() |
| 237 | + }, |
| 238 | + objB: windowPolytree.clone() |
| 239 | + }).then(mesh => { |
| 240 | + scene.remove(wall); |
| 241 | + towerWithWindowMesh = mesh; |
| 242 | + scene.add(towerWithWindowMesh); |
| 243 | + }); |
244 | 244 |
|
245 |
| - windowMesh.visible = false; |
246 |
| - scene.add(windowMesh); |
| 245 | + windowMesh.visible = false; |
| 246 | + scene.add(windowMesh); |
247 | 247 |
|
248 |
| - transformControls.showZ = false; |
249 |
| - transformControls.setSize(0.5); |
| 248 | + transformControls.showZ = false; |
| 249 | + transformControls.setSize(0.5); |
250 | 250 |
|
251 |
| - transformControls.addEventListener('dragging-changed', e => { |
252 |
| - controls.enabled = !e.value; |
253 |
| - }); |
| 251 | + transformControls.addEventListener('dragging-changed', e => { |
| 252 | + controls.enabled = !e.value; |
| 253 | + }); |
254 | 254 |
|
255 |
| - transformControls.addEventListener('objectChange', () => { |
256 |
| - objectMoved = true; |
257 |
| - }); |
| 255 | + transformControls.addEventListener('objectChange', () => { |
| 256 | + objectMoved = true; |
| 257 | + }); |
258 | 258 |
|
259 |
| - transformControls.attach(windowMesh); |
| 259 | + transformControls.attach(windowMesh); |
260 | 260 |
|
261 |
| - scene.add(transformControls); |
| 261 | + scene.add(transformControls); |
262 | 262 |
|
263 |
| - render(); |
| 263 | + render(); |
264 | 264 |
|
265 |
| - function render() { |
| 265 | + function render() { |
266 | 266 |
|
267 |
| - stats.begin(); |
| 267 | + stats.begin(); |
268 | 268 |
|
269 |
| - if (!isRendering) { |
270 |
| - isRendering = true; |
| 269 | + if (!isRendering) { |
| 270 | + isRendering = true; |
271 | 271 |
|
272 |
| - if (objectMoved) { |
| 272 | + if (objectMoved) { |
273 | 273 |
|
274 |
| - objectMoved = false; |
| 274 | + objectMoved = false; |
275 | 275 |
|
276 |
| - windowMesh.updateMatrix(); |
| 276 | + windowMesh.updateMatrix(); |
277 | 277 |
|
278 |
| - let newTransformedMatrix = calcTransformMatrix(originalMatrix, windowMesh.matrix); |
| 278 | + let newTransformedMatrix = calcTransformMatrix(originalMatrix, windowMesh.matrix); |
279 | 279 |
|
280 |
| - windowPolytree.applyMatrix(newTransformedMatrix); |
281 |
| - hollowWindowPolytree.applyMatrix(newTransformedMatrix); |
282 |
| - originalMatrix.copy(windowMesh.matrix); |
| 280 | + windowPolytree.applyMatrix(newTransformedMatrix); |
| 281 | + hollowWindowPolytree.applyMatrix(newTransformedMatrix); |
| 282 | + originalMatrix.copy(windowMesh.matrix); |
283 | 283 |
|
284 |
| - Polytree.async.operation({ |
285 |
| - op: "unite", |
286 |
| - material: [wall.material, windowMesh.material], |
287 |
| - objA: { |
288 |
| - op: "subtract", |
289 |
| - objA: towerPolytree.clone(), |
290 |
| - objB: hollowWindowPolytree.clone() |
291 |
| - }, |
292 |
| - objB: windowPolytree.clone() |
293 |
| - }).then(mesh => { |
| 284 | + Polytree.async.operation({ |
| 285 | + op: "unite", |
| 286 | + material: [wall.material, windowMesh.material], |
| 287 | + objA: { |
| 288 | + op: "subtract", |
| 289 | + objA: towerPolytree.clone(), |
| 290 | + objB: hollowWindowPolytree.clone() |
| 291 | + }, |
| 292 | + objB: windowPolytree.clone() |
| 293 | + }).then(mesh => { |
294 | 294 |
|
295 |
| - towerWithWindowMesh.geometry.dispose(); |
296 |
| - towerWithWindowMesh.geometry = mesh.geometry; |
| 295 | + towerWithWindowMesh.geometry.dispose(); |
| 296 | + towerWithWindowMesh.geometry = mesh.geometry; |
297 | 297 |
|
298 |
| - }); |
| 298 | + }); |
299 | 299 |
|
300 |
| - } |
| 300 | + } |
301 | 301 |
|
302 |
| - renderer.render(scene, camera); |
303 |
| - isRendering = false; |
| 302 | + renderer.render(scene, camera); |
| 303 | + isRendering = false; |
304 | 304 |
|
305 |
| - } |
| 305 | + } |
306 | 306 |
|
307 |
| - stats.end(); |
308 |
| - requestAnimationFrame(render); |
| 307 | + stats.end(); |
| 308 | + requestAnimationFrame(render); |
309 | 309 |
|
310 |
| - } |
| 310 | + } |
| 311 | + }); |
311 | 312 |
|
312 | 313 | </script>
|
313 | 314 |
|
|
0 commit comments