1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
|
/*
* Copyright 1996-2008 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*
*/
package javax.media.j3d;
import java.util.ArrayList;
import java.util.Vector;
/**
* The Node class provides an abstract class for all Group and Leaf
* Nodes. It provides a common framework for constructing a Java 3D
* scene graph, including bounding volumes and parent pointers.
*/
abstract class NodeRetained extends SceneGraphObjectRetained implements NnuId {
// All the node types in the scene graph
static final int BACKGROUND = 1;
static final int CLIP = 2;
static final int LINEARFOG = 3;
static final int EXPONENTIALFOG = 4;
static final int AMBIENTLIGHT = 5;
static final int DIRECTIONALLIGHT = 6;
static final int POINTLIGHT = 7;
static final int SPOTLIGHT = 8;
static final int LINK = 9;
static final int MORPH = 10;
static final int SHAPE = 11;
static final int BACKGROUNDSOUND = 12;
static final int POINTSOUND = 13;
static final int CONESOUND = 14;
static final int SOUNDSCAPE = 15;
static final int VIEWPLATFORM = 16;
static final int BEHAVIOR = 17;
static final int SWITCH = 18;
static final int BRANCHGROUP = 19;
static final int ORDEREDGROUP = 20;
static final int DECALGROUP = 21;
static final int SHAREDGROUP = 22;
static final int GROUP = 23;
static final int TRANSFORMGROUP = 24;
static final int BOUNDINGLEAF = 25;
static final int MODELCLIP = 26;
static final int ALTERNATEAPPEARANCE= 27;
static final int ORIENTEDSHAPE3D = 28;
static final int VIEWSPECIFICGROUP = 29;
static final int NUMNODES = 29;
// traverse flags
static final int CONTAINS_VIEWPLATFORM = 0x1;
/**
* The universe that we are in
*/
VirtualUniverse universe = null;
/**
* The locale that this node is attatched to. This is only non-null
* if this instance is directly linked into a locale.
*/
Locale locale = null;
/**
* The node's parent.
*/
NodeRetained parent = null;
/**
* The node's internal identifier.
*/
String nodeId = null;
/**
* An int that represents the nodes type. Used for quick if tests
* in the traverser.
*/
int nodeType;
// This keeps track of how many times this Node is refernced, refCount > 1
// if node is in a shared group
int refCount = 0;
/**
* This is the index for the child, as seen by its parent.
*/
int childIndex = -1;
/**
* This boolean is true when the node is in a sharedGroup
*/
boolean inSharedGroup = false;
/**
* This indicates if the node is pickable. If this node is not
* pickable then neither are any children
*/
boolean pickable = true;
/**
* The collidable setting; see getCollidable and setCollidable.
*/
boolean collidable = true;
// A list of localToVworld transforms. If inSharedGroup is false,
// then only localToVworld[0][] is valid.
// Note: this contains reference to the actual transforms in the
// TransformGroupRetained
Transform3D localToVworld[][] = null;
int localToVworldIndex[][] = null;
static final int LAST_LOCAL_TO_VWORLD = 0;
static final int CURRENT_LOCAL_TO_VWORLD = 1;
// A parallel array to localToVworld. This is the keys for
// localToVworld transforms in shared groups.
HashKey localToVworldKeys[] = null;
/**
* This boolean is true when the geometric bounds for the node is
* automatically updated
*/
boolean boundsAutoCompute = true;
// "effective" bounds in local coordinate if boundsAutoCompute == F,
// used for internal operations, not used if boundsAutoCompute == T
Bounds localBounds;
// Bounds set by the API
Bounds apiBounds;
protected Bounds cachedBounds=null; // Cached auto compute bounds, could we use localBounds ?
protected boolean validCachedBounds = false; // Fix to Issue 514
/**
* Each element, p, of branchGroupPaths is a list of BranchGroup from
* root of the tree to this.
* For BranchGroup under a non-shared group this size of
* branchGroupPaths is always 1. Otherwise, the size is equal to
* the number of possible paths to reach this node.
* This variable is used to cached BranchGroup for fast picking.
* For non BranchGroupRetained class this is a reference to
* the previous BranchGroupRetained branchGroupPaths.
*/
ArrayList<BranchGroupRetained[]> branchGroupPaths = new ArrayList<BranchGroupRetained[]>(1);
// background node whose geometry branch contains this node
BackgroundRetained geometryBackground = null;
// closest parent which is a TransformGroupRetained or sharedGroupRetained
GroupRetained parentTransformLink = null;
// closest parent which is a SwitchRetained or sharedGroupRetained
GroupRetained parentSwitchLink = null;
// static transform if a parent transform group is merged during compile.
TransformGroupRetained staticTransform = null;
// orderedId assigned by OrderedGroup parent
Integer orderedId = null;
// Id use for quick search.
int nnuId;
NodeRetained() {
// Get a not necessary unique Id.
nnuId = NnuIdManager.getId();
localBounds = new BoundingBox((Bounds)null);
}
@Override
public int getId() {
return nnuId;
}
@Override
public int equal(NnuId obj) {
int keyId = obj.getId();
if(nnuId < keyId) {
return -1;
}
else if(nnuId > keyId) {
return 1;
}
else { // Found it!
return 0;
}
}
Bounds getLocalBounds(Bounds bounds) {
return (Bounds)bounds.clone();
}
/**
* Sets the geometric bounds of a node.
* @param bounds the bounding object for the node
*/
void setBounds(Bounds bounds) {
apiBounds = bounds;
if (source.isLive()) {
if (!boundsAutoCompute) {
if (bounds != null) {
localBounds = getLocalBounds(bounds);
if (staticTransform != null) {
localBounds.transform(staticTransform.transform);
}
} else {
if(localBounds != null) {
localBounds.set((Bounds)null);
}
else {
localBounds = new BoundingBox((Bounds)null);
}
}
}
} else {
if (bounds != null) {
localBounds = getLocalBounds(bounds);
if (staticTransform != null) {
localBounds.transform(staticTransform.transform);
}
} else {
if(localBounds != null) {
localBounds.set((Bounds)null);
}
else {
localBounds = new BoundingBox((Bounds)null);
}
}
}
}
/**
* Gets the bounding object of a node.
* @return the node's bounding object
*/
Bounds getEffectiveBounds() {
Bounds b = null;
if (localBounds != null && !localBounds.isEmpty()) {
b = (Bounds) localBounds.clone();
if (staticTransform != null) {
Transform3D invTransform = staticTransform.getInvTransform();
b.transform(invTransform);
}
}
return b;
}
Bounds getBounds() {
return apiBounds;
}
/**
* ONLY needed for SHAPE, MORPH, and LINK node type.
* Compute the combine bounds of bounds and its localBounds.
*/
void computeCombineBounds(Bounds bounds) {
// Do nothing except for Group, Shape3D, Morph, and Link node.
}
/**
* Sets the automatic calcuation of geometric bounds of a node.
* @param autoCompute is a boolean value indicating if automatic calcuation
* of bounds
*/
void setBoundsAutoCompute(boolean autoCompute) {
if (this.boundsAutoCompute==autoCompute) {
return;
}
this.boundsAutoCompute = autoCompute;
dirtyBoundsCache();
}
/**
* Gets the auto Compute flag for the geometric bounds.
* @return the node's auto Compute flag for the geometric bounding object
*/
boolean getBoundsAutoCompute() {
return boundsAutoCompute;
}
/**
* Replaces the specified parent by a new parent.
* @param parent the new parent
*/
void setParent(NodeRetained parent) {
this.parent = parent;
}
/**
* Returns the parent of the node.
* @return the parent.
*/
NodeRetained getParent() {
return parent;
}
// Transform the input bound by the current LocalToVWorld
void transformBounds(SceneGraphPath path, Bounds bound) {
if (!((NodeRetained) path.item.retained).inSharedGroup) {
bound.transform(getCurrentLocalToVworld());
} else {
HashKey key = new HashKey("");
path.getHashKey(key);
bound.transform(getCurrentLocalToVworld(key));
}
}
// Note : key will get modified in this method.
private void computeLocalToVworld( NodeRetained caller, NodeRetained nodeR,
HashKey key, Transform3D l2Vw) {
int i;
// To handle localToVworld under a SG.
if(nodeR instanceof SharedGroupRetained) {
// Get the immediate parent's id and remove last id from key.
String nodeId = key.getLastNodeId();
SharedGroupRetained sgRetained = (SharedGroupRetained) nodeR;
// Search for the right parent.
for(i=0; i<sgRetained.parents.size(); i++) {
if (nodeId.equals(sgRetained.parents.get(i).nodeId)) {
// Found the right link. Now traverse upward.
computeLocalToVworld(caller, sgRetained.parents.get(i), key, l2Vw);
return;
}
}
// Problem !
throw new RuntimeException(J3dI18N.getString("NodeRetained4"));
}
else {
NodeRetained nodeParentR = nodeR.getParent();
if(nodeParentR == null) {
// Base case. It has to be a BG attached to a locale.
if(((BranchGroupRetained)(nodeR)).locale != null) {
l2Vw.setIdentity();
}
else {
throw new RuntimeException(J3dI18N.getString("NodeRetained5"));
}
}
else {
computeLocalToVworld(caller, nodeParentR, key, l2Vw);
}
}
if((nodeR instanceof TransformGroupRetained) && (nodeR != caller)) {
Transform3D t1 = new Transform3D();
((TransformGroupRetained)(nodeR)).transform.getWithLock(t1);
l2Vw.mul(t1);
} else if ((nodeR == caller) && (staticTransform != null)) {
l2Vw.mul(staticTransform.transform);
}
return;
}
/**
* Compute the LocalToVworld of this node even though it is not live. We
* assume the graph is attached at the origin of a locale
*/
void computeNonLiveLocalToVworld(Transform3D t, Node caller) {
NodeRetained n = getParent();
if (n==null)
t.setIdentity();
else
n.computeNonLiveLocalToVworld(t, caller);
if (this instanceof TransformGroupRetained && this.source!=caller) {
Transform3D trans = new Transform3D();
((TransformGroupRetained)this).getTransform(trans);
t.mul(trans);
}
}
/**
* Get the localToVworld transform for a node.
*/
void getLocalToVworld(Transform3D t) {
if (inSharedGroup) {
throw new IllegalSharingException(J3dI18N.getString("NodeRetained0"));
}
// Lock the object while writing into t.
if (localToVworld == null) {
t.setIdentity();
} else {
computeLocalToVworld(this, this, null, t);
}
}
/**
* Get the localToVworld transform for a node.
*/
void getLocalToVworld(SceneGraphPath path, Transform3D t) {
HashKey key = new HashKey("");
if (inSharedGroup == false) {
throw new IllegalSharingException(J3dI18N.getString("NodeRetained1"));
}
path.validate(key);
computeLocalToVworld(this, this, key, t);
}
/**
* Get the localToVworld transform for a node
*/
void getLocalToVworld(Transform3D t, HashKey key) {
HashKey newKey = new HashKey(key);
computeLocalToVworld(this, this, newKey, t);
}
/**
* Get the Locale to which the node is attached
*/
Locale getLocale() {
if (inSharedGroup) {
throw new IllegalSharingException(J3dI18N.getString("NodeRetained0"));
}
return locale;
}
/**
* Get the current localToVworld transform for a node
*/
Transform3D getCurrentLocalToVworld() {
if (localToVworld != null) {
return localToVworld[0][localToVworldIndex[0][CURRENT_LOCAL_TO_VWORLD]];
} else {
return new Transform3D();
}
}
// this method expects that localToVworld is not null
Transform3D getCurrentLocalToVworld(int index) {
return localToVworld[index][localToVworldIndex[index][CURRENT_LOCAL_TO_VWORLD]];
}
Transform3D getCurrentLocalToVworld(HashKey key) {
if (localToVworld != null) {
if (!inSharedGroup) {
return localToVworld[0][localToVworldIndex[0][CURRENT_LOCAL_TO_VWORLD]];
} else {
int i = key.equals(localToVworldKeys, 0, localToVworldKeys.length);
if(i>= 0) {
return localToVworld[i][localToVworldIndex[i][CURRENT_LOCAL_TO_VWORLD]];
}
}
}
return new Transform3D();
}
/**
* Get the last localToVworld transform for a node
*/
Transform3D getLastLocalToVworld() {
if (localToVworld != null) {
return localToVworld[0][localToVworldIndex[0][LAST_LOCAL_TO_VWORLD]];
} else {
return new Transform3D();
}
}
Transform3D getLastLocalToVworld(int index) {
return localToVworld[index][localToVworldIndex[index][LAST_LOCAL_TO_VWORLD]];
}
Transform3D getLastLocalToVworld(HashKey key) {
if (localToVworld != null) {
if (!inSharedGroup) {
return localToVworld[0][localToVworldIndex[0][LAST_LOCAL_TO_VWORLD]];
} else {
int i = key.equals(localToVworldKeys, 0, localToVworldKeys.length);
if(i>= 0) {
return localToVworld[i][localToVworldIndex[i][LAST_LOCAL_TO_VWORLD]];
}
}
}
return new Transform3D();
}
// Do nothing for NodeRetained.
void setAuxData(SetLiveState s, int index, int hkIndex) {
}
void setNodeData(SetLiveState s) {
localToVworld = s.localToVworld;
localToVworldIndex = s.localToVworldIndex;
localToVworldKeys = s.localToVworldKeys;
// reference to the last branchGroupPaths
branchGroupPaths = s.parentBranchGroupPaths;
parentTransformLink = s.parentTransformLink;
parentSwitchLink = s.parentSwitchLink;
}
// set pickable, recursively update cache result
void setPickable(boolean pickable) {
if (this.pickable == pickable)
return;
this.pickable = pickable;
if (source.isLive()) {
synchronized(universe.sceneGraphLock) {
boolean pick[];
if (!inSharedGroup) {
pick = new boolean[1];
} else {
pick = new boolean[localToVworldKeys.length];
}
findPickableFlags(pick);
updatePickable(localToVworldKeys, pick);
}
}
}
void updatePickable(HashKey pickKeys[], boolean pick[]) {
for (int i=0; i < pick.length; i++) {
if (!pickable) {
pick[i] = false;
}
}
}
// get pickable
boolean getPickable() {
return pickable;
}
// set collidable, recursively update cache result
void setCollidable(boolean collidable) {
if (this.collidable == collidable)
return;
this.collidable = collidable;
if (source.isLive()) {
synchronized(universe.sceneGraphLock) {
boolean collide[];
if (!inSharedGroup) {
collide = new boolean[1];
} else {
collide = new boolean[localToVworldKeys.length];
}
findCollidableFlags(collide);
updateCollidable(localToVworldKeys, collide);
}
}
}
// get collidable
boolean getCollidable() {
return collidable;
}
void updateCollidable(HashKey keys[], boolean collide[]) {
for (int i=0; i < collide.length; i++) {
if (!collidable) {
collide[i] = false;
}
}
}
/**
* For the default, just pass up to parent
*/
void notifySceneGraphChanged(boolean globalTraverse){}
void recombineAbove() {}
@Override
void setLive(SetLiveState s) {
int oldrefCount = refCount;
doSetLive(s);
if (oldrefCount <= 0)
super.markAsLive();
}
// The default set of setLive actions.
@Override
void doSetLive(SetLiveState s) {
int i;
int oldrefCount = refCount;
refCount += s.refCount;
if(!(locale == null || universe == s.universe))
throw new IllegalSharingException(J3dI18N.getString("NodeRetained3"));
if(s.locale == null)
System.err.println("NodeRetained.setLive() locale is null");
locale = s.locale;
inSharedGroup = s.inSharedGroup;
if (oldrefCount <= 0) {
if (listIdx == null) {
universe = s.universe;
} else {
// sync with getIdxUsed()
if (s.universe != universe) {
synchronized (this) {
universe = s.universe;
incIdxUsed();
}
}
}
}
s.universe.numNodes++;
// pickable & collidable array have the same length
for (i=0; i < s.pickable.length; i++) {
if (!pickable) {
s.pickable[i] = false;
}
if (!collidable) {
s.collidable[i] = false;
}
}
if (oldrefCount <= 0)
super.doSetLive(s);
if (inBackgroundGroup) {
geometryBackground = s.geometryBackground;
}
setNodeData(s);
}
/**
* remove the localToVworld transform for this node.
*/
void removeNodeData(SetLiveState s) {
if (refCount <= 0) {
localToVworld = null;
localToVworldIndex = null;
localToVworldKeys = null;
// restore to default and avoid calling clear()
// that may clear parent reference branchGroupPaths
branchGroupPaths = new ArrayList<BranchGroupRetained[]>(1);
parentTransformLink = null;
parentSwitchLink = null;
}
else {
// Set it back to its parent localToVworld data. This is b/c the parent has
// changed it localToVworld data arrays.
localToVworld = s.localToVworld;
localToVworldIndex = s.localToVworldIndex;
localToVworldKeys = s.localToVworldKeys;
// Reference of parent branchGroupPaths will not change
// no need to reset parentSwitchLink or parentTransformLink
// because there are not per path data
}
}
// The default set of clearLive actions
void clearLive(SetLiveState s) {
refCount-=s.refCount;
if (refCount <= 0) {
super.clearLive();
// don't remove the nodeId unless there are no more references
if (nodeId != null) {
universe.nodeIdFreeList.addElement(nodeId);
nodeId = null;
}
}
universe.numNodes--;
removeNodeData(s);
if(refCount <= 0) {
locale = null;
geometryBackground = null;
}
}
// search up the parent to determine if this node is pickable
void findPickableFlags(boolean pick[]) {
NodeRetained nodeR = this;
if (!inSharedGroup) {
pick[0] = true;
nodeR = nodeR.parent;
while (nodeR != null) {
if (!nodeR.pickable) {
pick[0] = false;
break;
}
nodeR = nodeR.parent;
}
} else {
HashKey key;
for (int i=0; i < pick.length; i++) {
nodeR = this;
pick[i] = true;
key = new HashKey(localToVworldKeys[i]);
do {
if (nodeR instanceof SharedGroupRetained) {
String nodeId = key.getLastNodeId();
Vector<NodeRetained> parents = ((SharedGroupRetained)nodeR).parents;
int sz = parents.size();
NodeRetained prevNodeR = nodeR;
for(int j=0; j< sz; j++) {
NodeRetained linkR = parents.get(j);
if (linkR.nodeId.equals(nodeId)) {
nodeR = linkR;
break;
}
}
if (prevNodeR == nodeR) {
// branch is already detach
return;
}
} else {
nodeR = nodeR.parent;
}
if (nodeR == null)
break;
if (!nodeR.pickable) {
pick[i] = false;
break;
}
} while (true);
}
}
}
// search up the parent to determine if this node is collidable
void findCollidableFlags(boolean collide[]) {
NodeRetained nodeR = this;
if (!inSharedGroup) {
collide[0] = true;
nodeR = nodeR.parent;
while (nodeR != null) {
if (!nodeR.collidable) {
collide[0] = false;
break;
}
nodeR = nodeR.parent;
}
} else {
HashKey key;
for (int i=0; i < collide.length; i++) {
nodeR = this;
collide[i] = true;
key = new HashKey(localToVworldKeys[i]);
do {
if (nodeR instanceof SharedGroupRetained) {
String nodeId = key.getLastNodeId();
Vector<NodeRetained> parents = ((SharedGroupRetained)nodeR).parents;
int sz = parents.size();
NodeRetained prevNodeR = nodeR;
for(int j=0; j< sz; j++) {
NodeRetained linkR = parents.get(j);
if (linkR.nodeId.equals(nodeId)) {
nodeR = linkR;
break;
}
}
if (nodeR == prevNodeR) {
return;
}
} else {
nodeR = nodeR.parent;
}
if (nodeR == null)
break;
if (!nodeR.collidable) {
collide[i] = false;
break;
}
} while (true);
}
}
}
void findTransformLevels(int transformLevels[]) {
NodeRetained nodeR = this;
TransformGroupRetained tg;
if (!inSharedGroup) {
transformLevels[0] = -1;
while (nodeR != null) {
if (nodeR.nodeType == NodeRetained.TRANSFORMGROUP) {
tg = (TransformGroupRetained)nodeR;
transformLevels[0] = tg.transformLevels[0];
break;
}
nodeR = nodeR.parent;
}
} else {
HashKey key;
int i,j;
for (i=0; i < transformLevels.length; i++) {
nodeR = this;
transformLevels[i] = -1;
key = new HashKey(localToVworldKeys[i]);
do {
if (nodeR == null)
break;
else if (nodeR instanceof SharedGroupRetained) {
// note that key is truncated after getLastNodeId
String nodeId = key.getLastNodeId();
Vector<NodeRetained> parents = ((SharedGroupRetained)nodeR).parents;
int sz = parents.size();
NodeRetained prevNodeR = nodeR;
for (j=0; j< sz; j++) {
NodeRetained linkR = parents.get(j);
if (linkR.nodeId.equals(nodeId)) {
nodeR = linkR;
break;
}
}
if (prevNodeR == nodeR) {
// branch is already detach
return;
}
}
else if (nodeR.nodeType == NodeRetained.TRANSFORMGROUP) {
tg = (TransformGroupRetained)nodeR;
if (tg.inSharedGroup) {
j = key.equals(tg.localToVworldKeys, 0,
tg.localToVworldKeys.length);
transformLevels[i] = tg.transformLevels[j];
} else {
transformLevels[i] = tg.transformLevels[0];
}
break;
}
nodeR = nodeR.parent;
} while (true);
}
}
}
@Override
boolean isStatic() {
if (source.getCapability(Node.ALLOW_LOCAL_TO_VWORLD_READ) ||
source.getCapability(Node.ALLOW_PARENT_READ) ||
source.getCapability(Node.ENABLE_PICK_REPORTING) ||
source.getCapability(Node.ENABLE_COLLISION_REPORTING) ||
source.getCapability(Node.ALLOW_BOUNDS_READ) ||
source.getCapability(Node.ALLOW_BOUNDS_WRITE) ||
source.getCapability(Node.ALLOW_PICKABLE_READ) ||
source.getCapability(Node.ALLOW_PICKABLE_WRITE) ||
source.getCapability(Node.ALLOW_COLLIDABLE_READ) ||
source.getCapability(Node.ALLOW_COLLIDABLE_WRITE) ||
source.getCapability(Node.ALLOW_AUTO_COMPUTE_BOUNDS_READ) ||
source.getCapability(Node.ALLOW_AUTO_COMPUTE_BOUNDS_WRITE)) {
return false;
}
return true;
}
@Override
void merge(CompileState compState) {
staticTransform = compState.staticTransform;
if (compState.parentGroup != null) {
compState.parentGroup.compiledChildrenList.add(this);
}
parent = compState.parentGroup;
if (staticTransform != null) {
mergeTransform(staticTransform);
}
}
@Override
void mergeTransform(TransformGroupRetained xform) {
if (localBounds != null) {
localBounds.transform(xform.transform);
}
}
int[] processViewSpecificInfo(int mode, HashKey k, View v, ArrayList vsgList, int[] keyList,
ArrayList leafList) {
return keyList;
}
@Override
VirtualUniverse getVirtualUniverse() {
return universe;
}
void searchGeometryAtoms(UnorderList list) {}
/**
* Make the boundsCache of this node and all its parents dirty
*/
void dirtyBoundsCache() {
// Possible optimisation is to not traverse up the tree
// if the cachedBounds==null. However this is not the case
// if the node is the child of a SharedGroup
if (VirtualUniverse.mc.cacheAutoComputedBounds) {
// Issue 514 : NPE in Wonderland : triggered in cached bounds computation
validCachedBounds = false;
if (parent!=null) {
parent.dirtyBoundsCache();
}
}
}
}
|