1
1
# Async CSG operations for Polytree
2
2
# This module contains all async operations that were moved from polytree.coffee
3
3
4
- handleObjectForOp_async = (obj , returnPolytrees , buildTargetPolytree , options , objIndex ) ->
5
-
6
- new Promise (resolve , reject ) ->
7
-
8
- try
9
-
10
- returnObj = undefined
11
-
12
- if obj .isMesh
13
-
14
- returnObj = Polytree .fromMesh (obj, options .objCounter ++ )
15
-
16
- if returnPolytrees
17
-
18
- returnObj = { result : returnObj, original : returnObj .clone () }
19
-
20
- returnObj .objIndex = objIndex
21
- resolve (returnObj)
22
-
23
- else if obj .isPolytree
24
-
25
- returnObj = obj
26
-
27
- if returnPolytrees
28
-
29
- returnObj = { result : obj, original : obj .clone () }
30
-
31
- returnObj .objIndex = objIndex
32
- resolve (returnObj)
33
-
34
- else if obj .op
35
-
36
- Polytree .async .operation (obj, returnPolytrees, buildTargetPolytree, options, false ).then (returnObj) ->
37
-
38
- if returnPolytrees
39
-
40
- returnObj = { result : returnObj, original : obj }
41
-
42
- returnObj .objIndex = objIndex
43
- resolve (returnObj)
44
-
45
- catch e
46
-
47
- reject (e)
4
+ # Use the unified handleObjectForOp function from polytree.coffee with async=true
48
5
49
6
Polytree .async =
50
7
@@ -493,96 +450,4 @@ Polytree.async =
493
450
494
451
operation : (obj , returnPolytrees = false , buildTargetPolytree = true , options = { objCounter : 0 }, firstRun = true ) ->
495
452
496
- new Promise (resolve , reject ) ->
497
-
498
- try
499
-
500
- polytreeA = undefined
501
- polytreeB = undefined
502
- resultPolytree = undefined
503
- material = undefined
504
-
505
- if obj .material
506
-
507
- material = obj .material
508
-
509
- promises = []
510
-
511
- if obj .objA
512
-
513
- promise = handleObjectForOp_async (obj .objA , returnPolytrees, buildTargetPolytree, options, 0 )
514
- promises .push (promise)
515
-
516
- if obj .objB
517
-
518
- promise = handleObjectForOp_async (obj .objB , returnPolytrees, buildTargetPolytree, options, 1 )
519
- promises .push (promise)
520
-
521
- Promise .allSettled (promises).then (results) ->
522
-
523
- polytrees = []
524
-
525
- results .forEach (r) ->
526
-
527
- if r .status is " fulfilled"
528
-
529
- if r .value .objIndex is 0
530
-
531
- polytreeA = r .value
532
-
533
- else if r .value .objIndex is 1
534
-
535
- polytreeB = r .value
536
-
537
- if returnPolytrees is true
538
-
539
- obj .objA = polytreeA .original
540
- polytreeA = polytreeA .result
541
- obj .objB = polytreeB .original
542
- polytreeB = polytreeB .result
543
-
544
- resultPromise = undefined
545
-
546
- switch obj .op
547
-
548
- when ' unite'
549
-
550
- resultPromise = Polytree .async .unite (polytreeA, polytreeB, buildTargetPolytree)
551
-
552
- when ' subtract'
553
-
554
- resultPromise = Polytree .async .subtract (polytreeA, polytreeB, buildTargetPolytree)
555
-
556
- when ' intersect'
557
-
558
- resultPromise = Polytree .async .intersect (polytreeA, polytreeB, buildTargetPolytree)
559
-
560
- resultPromise .then (resultPolytree) ->
561
-
562
- if firstRun and material
563
-
564
- mesh = Polytree .toMesh (resultPolytree, material)
565
-
566
- unless returnPolytrees
567
-
568
- disposePolytree (resultPolytree)
569
-
570
- resolve (if returnPolytrees then { result : mesh, operationTree : obj } else mesh)
571
-
572
- else if firstRun and returnPolytrees
573
-
574
- resolve ({ result : resultPolytree, operationTree : obj })
575
-
576
- else
577
-
578
- resolve (resultPolytree)
579
-
580
- unless returnPolytrees
581
-
582
- disposePolytree (polytreeA, polytreeB)
583
-
584
- .catch (e) -> reject (e)
585
-
586
- catch e
587
-
588
- reject (e)
453
+ Polytree .operation (obj, returnPolytrees, buildTargetPolytree, options, firstRun, true )
0 commit comments