@@ -71,6 +71,7 @@ export default class Scene {
71
71
private animationHelper : AnimationHelper ;
72
72
private tiling : any ;
73
73
private maxTiling : any ;
74
+ private arrayOfTileRoots : any ;
74
75
75
76
private cacheMountBBox ( mountNode : Element ) {
76
77
this . cachedMountNodeSize = { width : mountNode . clientWidth , height : mountNode . clientHeight } ;
@@ -110,6 +111,36 @@ export default class Scene {
110
111
mountNode . appendChild ( this . renderer . domElement ) ;
111
112
}
112
113
114
+ /*
115
+ this function returns a 3-dimensional empty array based on the tiling array
116
+ e.g. _getTiles([1, 1, 1] === [ [ [[], []], [[], []] ], [ [[], []], [[], []] ] ]
117
+ all of the arrays are unique instances, not copies
118
+ this allows us to create an array that can store the contents of each tiles and
119
+ be accessed with the tile indices. For example:
120
+ arr = _getTiles([2, 2, 2])
121
+ arr[0][1][2].push(scene)
122
+ scene = arr[0][1][2][0]
123
+ */
124
+ private static getEmptyTilesArray ( tiling : number [ ] ) {
125
+ let grid = [ ] ;
126
+ for ( let x = 0 ; x <= tiling [ 2 ] ; x ++ ) {
127
+ let arrX = [ ] ;
128
+ for ( let y = 0 ; y <= tiling [ 1 ] ; y ++ ) {
129
+ let arrY = [ ] ;
130
+ for ( let z = 0 ; z <= tiling [ 0 ] ; z ++ ) {
131
+ let arrZ = [ ] ;
132
+ // @ts -ignore
133
+ arrY . push ( arrZ ) ;
134
+ }
135
+ // @ts -ignore
136
+ arrX . push ( arrY ) ;
137
+ }
138
+ // @ts -ignore
139
+ grid . push ( arrX ) ;
140
+ }
141
+ return grid ;
142
+ }
143
+
113
144
private configureLabelRenderer ( mountNode : Element ) {
114
145
const labelRenderer = new CSS2DRenderer ( ) ;
115
146
this . labelRenderer = labelRenderer ;
@@ -374,7 +405,11 @@ export default class Scene {
374
405
) {
375
406
this . tiling = tiling ;
376
407
this . maxTiling = maxTiling ;
377
-
408
+ this . arrayOfTileRoots = Scene . getEmptyTilesArray ( [
409
+ this . maxTiling ,
410
+ this . maxTiling ,
411
+ this . maxTiling
412
+ ] ) ;
378
413
this . settings = Object . assign ( defaults , settings ) ;
379
414
this . objectBuilder = new ThreeBuilder ( this . settings ) ;
380
415
this . cameraState = cameraState ;
@@ -412,6 +447,23 @@ export default class Scene {
412
447
this . renderInlet ( ) ;
413
448
}
414
449
450
+ /*
451
+ loop through the arrayOfTileRoots and set the visibility of each object.
452
+ In particular, set threeObject.visible = true if the x, y, and z indices
453
+ are all less than the x, y, and z indices in tiling.
454
+ */
455
+ updateTiles ( tiling ) {
456
+ const [ xCut , yCut , zCut ] = tiling ;
457
+ this . arrayOfTileRoots . forEach ( ( arrX , x ) => {
458
+ arrX . forEach ( ( arrY , y ) => {
459
+ arrY . forEach ( ( arrZ , z ) => {
460
+ arrZ [ 0 ] . visible = x <= xCut && y <= yCut && z <= zCut ;
461
+ } ) ;
462
+ } ) ;
463
+ } ) ;
464
+ this . renderScene ( ) ;
465
+ }
466
+
415
467
public resizeRendererToDisplaySize ( ) {
416
468
const canvas = this . renderer . domElement as HTMLCanvasElement ;
417
469
this . cacheMountBBox ( canvas . parentElement as Element ) ;
@@ -512,36 +564,6 @@ export default class Scene {
512
564
return tiles ;
513
565
} ;
514
566
515
- /*
516
- this function returns a 3-dimensional empty array based on the tiling array
517
- e.g. _getTiles([1, 1, 1] === [ [ [[], []], [[], []] ], [ [[], []], [[], []] ] ]
518
- all of the arrays are unique instances, not copies
519
- this allows us to create an array that can store the contents of each tiles and
520
- be accessed with the tile indices. For example:
521
- arr = _getTiles([2, 2, 2])
522
- arr[0][1][2].push(scene)
523
- scene = arr[0][1][2][0]
524
- */
525
- const _getEmptyTilesArray = ( tiling : number [ ] ) => {
526
- let grid = [ ] ;
527
- for ( let x = 0 ; x <= tiling [ 2 ] ; x ++ ) {
528
- let arrX = [ ] ;
529
- for ( let y = 0 ; y <= tiling [ 1 ] ; y ++ ) {
530
- let arrY = [ ] ;
531
- for ( let z = 0 ; z <= tiling [ 0 ] ; z ++ ) {
532
- let arrZ = [ ] ;
533
- // @ts -ignore
534
- arrY . push ( arrZ ) ;
535
- }
536
- // @ts -ignore
537
- arrX . push ( arrY ) ;
538
- }
539
- // @ts -ignore
540
- grid . push ( arrX ) ;
541
- }
542
- return grid ;
543
- } ;
544
-
545
567
const emptyLattice = [
546
568
[ 0 , 0 , 0 ] ,
547
569
[ 0 , 0 , 0 ] ,
@@ -557,8 +579,8 @@ export default class Scene {
557
579
const traverseTiles = (
558
580
o : SceneJsonObject ,
559
581
root : THREE . Object3D ,
560
- tiles : number [ ] [ ] ,
561
- arrayOfTileRoots : number [ ] [ ] [ ] [ ]
582
+ tiles : number [ ] [ ]
583
+ // arrayOfTileRoots: number[][][][]
562
584
) => {
563
585
// @ts -ignore
564
586
let lattice = o . lattice ? o . lattice : emptyLattice ;
@@ -567,10 +589,10 @@ export default class Scene {
567
589
const tileRootObject = new THREE . Object3D ( ) ;
568
590
tileRootObject . name = sceneJson . name ! ;
569
591
sceneJson . visible && ( tileRootObject . visible = sceneJson . visible ) ;
570
-
592
+ console . log ( this . arrayOfTileRoots ) ;
571
593
root . add ( tileRootObject ) ;
572
594
const [ x , y , z ] = tile ;
573
- arrayOfTileRoots [ x ] [ y ] [ z ] . push ( tileRootObject ) ;
595
+ this . arrayOfTileRoots [ x ] [ y ] [ z ] . push ( tileRootObject ) ;
574
596
575
597
let tileOffsets : number [ ] [ ] = lattice . map ( ( vector : number [ ] , index : number ) => {
576
598
return vector . map ( ( x : number ) => x * tile [ index ] ) ;
@@ -642,50 +664,25 @@ export default class Scene {
642
664
} ) ;
643
665
} ;
644
666
645
- /*
646
- loop through the arrayOfTileRoots and set the visibility of each object.
647
- In particular, set threeObject.visible = true if the x, y, and z indices
648
- are all less than the x, y, and z indices in tiling.
649
- */
650
- const updateTiles = ( arrayOfTileRoots , tiling ) => {
651
- const [ xCut , yCut , zCut ] = tiling ;
652
- arrayOfTileRoots . forEach ( ( arrX , x ) => {
653
- arrX . forEach ( ( arrY , y ) => {
654
- arrY . forEach ( ( arrZ , z ) => {
655
- arrZ [ 0 ] . visible = x <= xCut && y <= yCut && z <= zCut ;
656
- } ) ;
657
- } ) ;
658
- } ) ;
659
- } ;
660
-
661
- const updateMaxTiling = ( ) => { } ;
662
-
663
667
// TODO: does it make sense to split this code into two cases?
664
668
// set up the threeObjects and containers
665
- let arrayOfTileRoots : number [ ] [ ] [ ] [ ] ;
666
669
const rootObject = new THREE . Object3D ( ) ;
667
670
if ( this . maxTiling > 0 ) {
668
671
// if needed, create a parent for all Scene objects
669
672
rootObject . name = 'root' ;
670
673
rootObject . visible = true ;
671
674
const maxTilingArray = [ this . maxTiling , this . maxTiling , this . maxTiling ] ;
672
675
let tiles = _getTiles ( maxTilingArray ) ;
673
- arrayOfTileRoots = _getEmptyTilesArray ( maxTilingArray ) ;
674
- traverseTiles ( sceneJson , rootObject , tiles , arrayOfTileRoots ) ;
675
- updateTiles ( arrayOfTileRoots , this . tiling ) ;
676
- console . log ( arrayOfTileRoots ) ;
676
+ traverseTiles ( sceneJson , rootObject , tiles ) ;
677
+ this . updateTiles ( this . tiling ) ;
678
+ console . log ( this . arrayOfTileRoots ) ;
677
679
} else {
678
680
rootObject . name = sceneJson . name ! ;
679
681
sceneJson . visible && ( rootObject . visible = sceneJson . visible ) ;
680
682
traverseScene ( sceneJson , rootObject , emptyLattice , '' ) ;
681
683
} // TODO: take this out, hope things dont break, fix if they do
682
684
683
- // for demonstration purposes TODO: remove next two lines
684
- // arrayOfTileRoots[1][1][1][0].visible = false;
685
- // arrayOfTileRoots[0][0][0][0].visible = false;
686
-
687
685
// can cause memory leak
688
- //console.log('rootObject', rootObject, rootObject);
689
686
this . scene . add ( rootObject ) ;
690
687
this . setupCamera ( rootObject ) ; // TODO: this could introduce issues if the new root is not compatible
691
688
0 commit comments