Skip to content

Commit 5dfdc5a

Browse files
Copilotjgphilpott
andcommitted
Change async parameter default to true and fix examples
Co-authored-by: jgphilpott <4128208+jgphilpott@users.noreply.github.com>
1 parent ad218fc commit 5dfdc5a

File tree

2 files changed

+81
-80
lines changed

2 files changed

+81
-80
lines changed

app/polytree.coffee

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,7 +1127,7 @@ splitPolygonArr = (arr) ->
11271127

11281128
Polytree.disposePolytree = true
11291129

1130-
Polytree.operation = (obj, returnPolytrees = false, buildTargetPolytree = true, options = { objCounter: 0 }, firstRun = true, async = false) ->
1130+
Polytree.operation = (obj, returnPolytrees = false, buildTargetPolytree = true, options = { objCounter: 0 }, firstRun = true, async = true) ->
11311131

11321132
if async
11331133

@@ -1307,7 +1307,7 @@ _handleOperation = (obj, returnPolytrees, buildTargetPolytree, options, firstRun
13071307

13081308
return resultPolytree
13091309

1310-
handleObjectForOp = (obj, returnPolytrees, buildTargetPolytree, options, objIndex, async = false) ->
1310+
handleObjectForOp = (obj, returnPolytrees, buildTargetPolytree, options, objIndex, async = true) ->
13111311

13121312
if async
13131313

examples/realtime.html

Lines changed: 79 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@
139139

140140
}
141141

142-
function createWindow() {
142+
async function createWindow() {
143143

144144
let texture = textureLoader.load('./textures/brick-wall.jpg');
145145

@@ -166,7 +166,7 @@
166166
horizontalWallMesh3.position.y = 9;
167167
horizontalWallMesh4.position.y = 19;
168168

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);
170170

171171
return Polytree.toMesh(resultPolytree, baseMaterial);
172172

@@ -209,105 +209,106 @@
209209
scene.add(titan1, titan2);
210210
});
211211

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+
});
244244

245-
windowMesh.visible = false;
246-
scene.add(windowMesh);
245+
windowMesh.visible = false;
246+
scene.add(windowMesh);
247247

248-
transformControls.showZ = false;
249-
transformControls.setSize(0.5);
248+
transformControls.showZ = false;
249+
transformControls.setSize(0.5);
250250

251-
transformControls.addEventListener('dragging-changed', e => {
252-
controls.enabled = !e.value;
253-
});
251+
transformControls.addEventListener('dragging-changed', e => {
252+
controls.enabled = !e.value;
253+
});
254254

255-
transformControls.addEventListener('objectChange', () => {
256-
objectMoved = true;
257-
});
255+
transformControls.addEventListener('objectChange', () => {
256+
objectMoved = true;
257+
});
258258

259-
transformControls.attach(windowMesh);
259+
transformControls.attach(windowMesh);
260260

261-
scene.add(transformControls);
261+
scene.add(transformControls);
262262

263-
render();
263+
render();
264264

265-
function render() {
265+
function render() {
266266

267-
stats.begin();
267+
stats.begin();
268268

269-
if (!isRendering) {
270-
isRendering = true;
269+
if (!isRendering) {
270+
isRendering = true;
271271

272-
if (objectMoved) {
272+
if (objectMoved) {
273273

274-
objectMoved = false;
274+
objectMoved = false;
275275

276-
windowMesh.updateMatrix();
276+
windowMesh.updateMatrix();
277277

278-
let newTransformedMatrix = calcTransformMatrix(originalMatrix, windowMesh.matrix);
278+
let newTransformedMatrix = calcTransformMatrix(originalMatrix, windowMesh.matrix);
279279

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);
283283

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 => {
294294

295-
towerWithWindowMesh.geometry.dispose();
296-
towerWithWindowMesh.geometry = mesh.geometry;
295+
towerWithWindowMesh.geometry.dispose();
296+
towerWithWindowMesh.geometry = mesh.geometry;
297297

298-
});
298+
});
299299

300-
}
300+
}
301301

302-
renderer.render(scene, camera);
303-
isRendering = false;
302+
renderer.render(scene, camera);
303+
isRendering = false;
304304

305-
}
305+
}
306306

307-
stats.end();
308-
requestAnimationFrame(render);
307+
stats.end();
308+
requestAnimationFrame(render);
309309

310-
}
310+
}
311+
});
311312

312313
</script>
313314

0 commit comments

Comments
 (0)