1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package net.jbeans.j3d.universe;
24
25 /* ------------------ Import classes (packages) ------------------- *//package-summary/html">class="comment"> ------------------ Import classes (packages) ------------------- *//package-summary.html">class="comment">/* ------------------ Import classes (packages) ------------------- *//package-summary.html">class="comment"> ------------------ Import classes (packages) ------------------- */
26 import java.util.*;
27 import javax.media.j3d.*;
28 import net.jbeans.util.debug.*;
29
30
31
32
33 /***
34 * World is the root BranchGroup for the Content branch.
35 *
36 * @version $Revision: 1.3 $
37 * @author Masahiro Takatsuka (masa@jbeans.net)
38 * @see BranchGroup
39 * @see BranchGroupDetachable
40 */
41
42
43
44
45 public class World extends BranchGroup implements BranchGroupDetachable {
46 private static final boolean DEBUG = Debug.getDebugFlag(World.class);
47
48 /***
49 * A world transformGroup
50 */
51 private MultiTransformGroup mtg;
52
53 /***
54 * the last transformGroup all branchgraphs are attached
55 */
56 private TransformGroup lastTG;
57
58 /***
59 * the list of BranchGroup objects so that they can be detached later.
60 */
61
62
63 private Vector detachBG = new Vector();
64
65 /***
66 * Constructs a new World object.
67 */
68 World() {
69 this(1);
70 }
71
72 /***
73 * Constructs a new World object.
74 */
75 World(int i) {
76 setCapability(ALLOW_DETACH);
77 setCapability(ALLOW_CHILDREN_READ);
78 setCapability(ALLOW_CHILDREN_WRITE);
79 setCapability(ALLOW_CHILDREN_EXTEND);
80 if (i < 1) {
81 i = 1;
82 }
83 this.mtg = new MultiTransformGroup(i);
84 TransformGroup transformgroup = this.mtg.getTransformGroup(0);
85 addChild(transformgroup);
86 this.lastTG = this.mtg.getTransformGroup(i - 1);
87 this.lastTG.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
88 this.lastTG.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
89 this.lastTG.setCapability(Node.ALLOW_AUTO_COMPUTE_BOUNDS_READ);
90 this.lastTG.setCapability(Node.ALLOW_AUTO_COMPUTE_BOUNDS_WRITE);
91 }
92
93 /***
94 * Get a list of all the detachable subgraphs.
95 */
96 public final Vector getDetachableBranchGroups() {
97 return this.detachBG;
98 }
99
100 /***
101 // * Returns an index number of the next branch group.
102 // */
103
104
105
106
107 /***
108 // * Sets a new index number of the next branch group.
109 // */
110
111
112
113
114 /***
115 * Returns the MultiTransformGroup object of this World object.
116 */
117 final MultiTransformGroup getMultiTransformGroup() {
118 return this.mtg;
119 }
120
121 /***
122 * Returns the last TransformGroup object in the MultiTransformGroup
123 * object of this World object.
124 */
125 final TransformGroup getWorldTransform() {
126 return this.mtg.getTransformGroup(this.mtg.getNumTransforms() - 1);
127 }
128
129 /***
130 * Adds a new BranchGroup object.
131 */
132 final void addBranchGraph(BranchGroup bg) {
133 if (DEBUG) {
134 System.out.println("World.addBranchGraph() : adding " + bg);
135 }
136 BranchGroup newBG = BranchGroupUtil.addBranchGroup(this, bg);
137 TransformGroup tg = getWorldTransform();
138 tg.addChild(newBG);
139 }
140
141 /***
142 * Detaches the specified BranchGroup object.
143 */
144 final void detachBranchGraph(BranchGroup subRoot) {
145 BranchGroupUtil.detachBranchGroup(this, subRoot);
146 }
147
148 final void detachAllBranchGraph() {
149 for (int i = 0; i < this.detachBG.size(); i++) {
150 BranchGroup bg = (BranchGroup) this.detachBG.get(0);
151 detachBranchGraph((BranchGroup) bg.getChild(0));
152 }
153 }
154 }