001: /*
002: * $RCSfile: SetLiveState.java,v $
003: *
004: * Copyright 1998-2008 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
006: *
007: * This code is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU General Public License version 2 only, as
009: * published by the Free Software Foundation. Sun designates this
010: * particular file as subject to the "Classpath" exception as provided
011: * by Sun in the LICENSE file that accompanied this code.
012: *
013: * This code is distributed in the hope that it will be useful, but WITHOUT
014: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
015: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
016: * version 2 for more details (a copy is included in the LICENSE file that
017: * accompanied this code).
018: *
019: * You should have received a copy of the GNU General Public License version
020: * 2 along with this work; if not, write to the Free Software Foundation,
021: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
022: *
023: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
024: * CA 95054 USA or visit www.sun.com if you need additional information or
025: * have any questions.
026: *
027: * $Revision: 1.7 $
028: * $Date: 2008/02/28 20:17:29 $
029: * $State: Exp $
030: */
031:
032: package javax.media.j3d;
033:
034: import java.util.ArrayList;
035:
036: /**
037: * SetLiveState is used to encapsulate all state needed when a branch
038: * group is added to the scene graph
039: */
040:
041: class SetLiveState extends Object {
042: // The VirtualUniverse for this branch group
043: VirtualUniverse universe = null;
044:
045: // The Locale for this Branch Graph
046: Locale locale = null;
047:
048: // The transforms used to update state
049: Transform3D[][] currentTransforms = new Transform3D[1][];
050: int[][] currentTransformsIndex = new int[1][];
051:
052: // The keys used when dealing with SharedGroups
053: HashKey[] keys = null;
054:
055: // flags for detecting what we are under
056: boolean inSharedGroup = false;
057: boolean inBackgroundGroup = false;
058: boolean inViewSpecificGroup = false;
059:
060: /**
061: * The list of nodes added/removed during setLive/clearLive
062: */
063: ArrayList nodeList = new ArrayList();
064:
065: /**
066: * List of nodes that are viewScoped. Note that all nodes
067: * except Shape3D nodes can be in viewScopedNodeList, shape3D
068: * nodes will always be in the nodeList regardless of scoped
069: * or not. Also, only renderbin and renderingEnv structure is
070: * interested in viewScopedNodeList
071: */
072: ArrayList viewScopedNodeList = null;
073:
074: /**
075: * Parallel list to viewScopedNodeList containing a list of views
076: * that the viewScopedNode is scoped to
077: */
078: ArrayList scopedNodesViewList = null;
079:
080: // Threads to notify after setLive/clearLive
081: int notifyThreads = 0;
082:
083: // The current list of leaf nodes for transform targets
084: Targets[] transformTargets = null;
085:
086: // List of transform level, one per shared path
087: int transformLevels[] = new int[] { -1 };
088:
089: // List of scoped lights
090: ArrayList lights = null;
091:
092: // List of scoped fogs
093: ArrayList fogs = null;
094:
095: // List of scoped modelClips
096: ArrayList modelClips = null;
097:
098: // List of scoped alt app
099: ArrayList altAppearances = null;
100:
101: // List of viewes scoped to this Group, for all subclasses
102: // of group, except ViewSpecificGroup its a pointer to closest
103: // ViewSpecificGroup parent
104: // viewList for this node, if inSharedGroup is
105: // false then only viewList(0) is valid
106: ArrayList viewLists = null;
107: ArrayList changedViewGroup = null;
108: ArrayList changedViewList = null;
109: int[] keyList = null;
110:
111: // The current bitmask of types in transformTragets
112: //int transformTargetThreads = 0;
113:
114: ArrayList orderedPaths = null;
115:
116: ArrayList ogList = new ArrayList(5);
117: ArrayList ogChildIdList = new ArrayList(5);
118: ArrayList ogOrderedIdList = new ArrayList(5);
119: // ogCIOList contains a list of OG with affected child index order.
120: ArrayList ogCIOList = new ArrayList(5);
121: // ogCIOTableList contains a list of affected child index order.
122: ArrayList ogCIOTableList = new ArrayList(5);
123:
124: /**
125: * List of BranchGroup from this node to the root of tree
126: * This is used by BranchGroupRetained to construct
127: * BranchGroup lists for picking.
128: *
129: * @see NodeRetained.branchGroupPaths
130: */
131: ArrayList branchGroupPaths = null;
132: ArrayList parentBranchGroupPaths = null;
133:
134: /**
135: * List of Pickable flags, one for each share path.
136: * This flag is true when all the NodeRetained.pickable is true
137: * along the path except current node.
138: */
139: boolean pickable[] = new boolean[] { true };
140:
141: /**
142: * List of collidable flags, one for each share path.
143: * This flag is true when all the NodeRetained.pickable is true
144: * along the path except current node.
145: */
146: boolean collidable[] = new boolean[] { true };
147:
148: // reference count use in set/clear Live to remember how
149: // many references of the original branch that attach()/detach()
150: int refCount = 1;
151:
152: // background node whose geometry branch contains this node
153: BackgroundRetained geometryBackground = null;
154:
155: // behavior nodes
156: ArrayList behaviorNodes = new ArrayList(1);
157:
158: // The current list of child transform group nodes or link nodes
159: // under a transform group
160: ArrayList childTransformLinks = null;
161:
162: // closest parent which is a TransformGroupRetained or sharedGroupRetained
163: GroupRetained parentTransformLink = null;
164:
165: // switch Level, start from -1, increment by one for each SwitchNode
166: // encounter in a branch, one per key
167: int switchLevels[] = new int[] { -1 };
168:
169: // closest switch parent, one per key
170: SwitchRetained closestSwitchParents[] = new SwitchRetained[] { null };
171:
172: // the child id from the closest switch parent, one per key
173: int closestSwitchIndices[] = new int[] { -1 };
174:
175: // The current list of leaf nodes for switch targets
176: Targets[] switchTargets = null;
177:
178: // The current list of closest child switch nodes or
179: // link nodes under a switch node
180: ArrayList childSwitchLinks = null;
181:
182: // closest parent which is a SwitchRetained or sharedGroupRetained
183: GroupRetained parentSwitchLink = null;
184:
185: SharedGroupRetained lastSharedGroup = null;
186:
187: int traverseFlags = 0;
188:
189: // Use for set live.
190: Transform3D[][] localToVworld = null;
191: int[][] localToVworldIndex = null;
192: HashKey[] localToVworldKeys = null;
193:
194: // cached hashkey index to eliminate duplicate hash key index search
195: // currently used by Switch, can be extended for other node types
196: int[] hashkeyIndex = null;
197:
198: ArrayList switchStates = null;
199:
200: SetLiveState(VirtualUniverse u) {
201: universe = u;
202: }
203:
204: void reset(Locale l) {
205: locale = l;
206: clear();
207: }
208:
209: void clear() {
210: inSharedGroup = false;
211: inBackgroundGroup = false;
212: inViewSpecificGroup = false;
213: nodeList.clear();
214: viewScopedNodeList = null;
215: scopedNodesViewList = null;
216:
217: notifyThreads = 0;
218: transformTargets = null;
219: lights = null;
220: fogs = null;
221: modelClips = null;
222: altAppearances = null;
223: viewLists = null;
224: changedViewGroup = null;
225: changedViewList = null;
226: keyList = null;
227:
228: behaviorNodes.clear();
229: traverseFlags = 0;
230:
231: ogList.clear();
232: ogChildIdList.clear();
233: ogOrderedIdList.clear();
234: ogCIOList.clear();
235: ogCIOTableList.clear();
236:
237: pickable = new boolean[] { true };
238: collidable = new boolean[] { true };
239: refCount = 1;
240: geometryBackground = null;
241: transformLevels = new int[] { -1 };
242: childTransformLinks = null;
243: parentTransformLink = null;
244:
245: switchTargets = null;
246: switchLevels = new int[] { -1 };
247: switchStates = null;
248: closestSwitchIndices = new int[] { -1 };
249: closestSwitchParents = new SwitchRetained[] { null };
250: childSwitchLinks = null;
251: parentSwitchLink = null;
252:
253: lastSharedGroup = null;
254:
255: keys = null;
256: currentTransforms = new Transform3D[1][];
257: currentTransformsIndex = new int[1][];
258:
259: localToVworld = null;
260: localToVworldIndex = null;
261: localToVworldKeys = null;
262:
263: // XXXX: optimization for targetThreads computation, require
264: // cleanup in GroupRetained.doSetLive()
265: //transformTargetThreads = 0;
266:
267: hashkeyIndex = null;
268:
269: // Fix for issue 75
270: parentBranchGroupPaths = null;
271: branchGroupPaths = null;
272: orderedPaths = null;
273: }
274: }
|