📄 switchretained.java
字号:
switch(whichChild) { case Switch.CHILD_ALL: for (i=0; i<nchildren; i++) { renderChildMask.set(i); } break; case Switch.CHILD_NONE: for (i=0; i<nchildren; i++) { renderChildMask.clear(i); } break; case Switch.CHILD_MASK: for (i=0; i<nchildren; i++) { if (childMask.get(i) == true) { renderChildMask.set(i); } else { renderChildMask.clear(i); } } break; default: for (i=0; i<nchildren; i++) { if (i == whichChild) { renderChildMask.set(i); } else { renderChildMask.clear(i); } } } } void traverseSwitchChild(int child, HashKey key, int index, SwitchRetained switchRoot, boolean init, boolean swChanged, boolean switchOn, int switchLevel, ArrayList updateList) { int i,j,k; SwitchRetained sw; LinkRetained ln; Object obj; ArrayList childSwitchLinks; boolean newSwChanged = false; ArrayList childSwitchStates = (ArrayList)childrenSwitchStates.get(child); SwitchState switchState = (SwitchState)childSwitchStates.get(index); switchState.updateCompositeSwitchMask(switchLevel, switchOn); if (switchRoot != null) { if (init) { if (!switchState.initialized) { switchState.initSwitchOn(); } } else { boolean compositeSwitchOn = switchState.evalCompositeSwitchOn(); if (switchState.cachedSwitchOn != compositeSwitchOn) { switchState.updateCachedSwitchOn(); switchRoot.updateTargets.addCachedTargets( switchState.cachedTargets); newSwChanged = true; updateList.add(switchState); } } } childSwitchLinks = (ArrayList)childrenSwitchLinks.get(child); int cslSize =childSwitchLinks.size(); for (i=0; i<cslSize; i++) { obj = childSwitchLinks.get(i); if (obj instanceof SwitchRetained) { sw = (SwitchRetained)obj; int swSize = sw.children.size(); for(j=0; j<swSize; j++) { sw.traverseSwitchChild(j, key, index, switchRoot, init, newSwChanged, switchOn, switchLevel, updateList); } } else { // LinkRetained ln = (LinkRetained)obj; if (key == null) { switchKey.reset(); switchKey.append(locale.nodeId); } else { switchKey.set(key); } switchKey.append(LinkRetained.plus).append(ln.nodeId); if ((ln.sharedGroup != null) && (ln.sharedGroup.localToVworldKeys != null)) { j = switchKey.equals(ln.sharedGroup.localToVworldKeys,0, ln.sharedGroup.localToVworldKeys.length); if(j < 0) { System.err.println("SwitchRetained : Can't find hashKey"); } if (j<ln.sharedGroup.localToVworldKeys.length) { int lscSize = ln.sharedGroup.children.size(); for(k=0; k<lscSize; k++) { ln.sharedGroup.traverseSwitchChild(k, ln.sharedGroup. localToVworldKeys[j], j, switchRoot, init, newSwChanged, switchOn, switchLevel, updateList); } } } } } } void traverseSwitchParent() { boolean switchOn; int switchLevel; SwitchRetained switchRoot; int i,j; int size; // first traverse this node's child if (inSharedGroup) { for (j=0; j<localToVworldKeys.length; j++) { switchLevel = ((Integer)switchLevels.get(j)).intValue(); switchRoot = (switchLevel == 0)? this : null; size = children.size(); for (i=0; i<size; i++) { switchOn = renderChildMask.get(i); traverseSwitchChild(i, localToVworldKeys[j], j, switchRoot, true, false, switchOn, switchLevel, null); } } } else { switchLevel = ((Integer)switchLevels.get(0)).intValue(); switchRoot = (switchLevel == 0)? this : null; size = children.size(); for (i=0; i<size; i++) { switchOn = renderChildMask.get(i); traverseSwitchChild(i, null, 0, switchRoot, true, false, switchOn, switchLevel, null); } } // now traverse this node's parent if (parentSwitchLink != null) { if (parentSwitchLink instanceof SwitchRetained) { ((SwitchRetained)parentSwitchLink).traverseSwitchParent(); } else if (parentSwitchLink instanceof SharedGroupRetained) { ((SharedGroupRetained)parentSwitchLink).traverseSwitchParent(); } } } void computeCombineBounds(Bounds bounds) { int i; NodeRetained child; if(boundsAutoCompute) { if (!VirtualUniverse.mc.cacheAutoComputedBounds) { if(whichChild == Switch.CHILD_ALL) { for(i=0; i<children.size(); i++) { child = (NodeRetained)children.get(i); if(child != null) child.computeCombineBounds(bounds); } } else if(whichChild == Switch.CHILD_MASK) { for(i=0; i<children.size(); i++) { if(childMask.get(i)) { child = (NodeRetained)children.get(i); if(child != null) child.computeCombineBounds(bounds); } } } else if(whichChild != Switch.CHILD_NONE) { if (whichChild < children.size()) { child = (NodeRetained)children.get(whichChild); if(child != null) child.computeCombineBounds(bounds); } } } else { if (cachedBounds==null) { cachedBounds = new BoundingSphere(); ((BoundingSphere)cachedBounds).setRadius(-1); if(whichChild == Switch.CHILD_ALL) { for(i=0; i<children.size(); i++) { child = (NodeRetained)children.get(i); if(child != null) child.computeCombineBounds(cachedBounds); } } else if(whichChild == Switch.CHILD_MASK) { for(i=0; i<children.size(); i++) { if(childMask.get(i)) { child = (NodeRetained)children.get(i); if(child != null) child.computeCombineBounds(cachedBounds); } } } else if(whichChild != Switch.CHILD_NONE) { if (whichChild < children.size()) { child = (NodeRetained)children.get(whichChild); if(child != null) child.computeCombineBounds(cachedBounds); } } } bounds.combine(cachedBounds); } } else { // Should this be lock too ? ( MT safe ? ) synchronized(localBounds) { bounds.combine(localBounds); } } } /** * Gets the bounding object of a node. * @return the node's bounding object */ Bounds getBounds() { int i; NodeRetained child; if(boundsAutoCompute) { if (cachedBounds!=null) { return (Bounds) cachedBounds.clone(); } BoundingSphere boundingSphere = new BoundingSphere(); boundingSphere.setRadius(-1.0); if(whichChild == Switch.CHILD_ALL) { for(i=0; i<children.size(); i++) { child = (NodeRetained)children.get(i); if(child != null) child.computeCombineBounds((Bounds) boundingSphere); } } else if(whichChild == Switch.CHILD_MASK) { for(i=0; i<children.size(); i++) { if(childMask.get(i)) { child = (NodeRetained)children.get(i); if(child != null) child.computeCombineBounds((Bounds) boundingSphere); } } } else if(whichChild != Switch.CHILD_NONE && whichChild >= 0 && whichChild < children.size()) { child = (NodeRetained)children.get(whichChild); if(child != null) child.computeCombineBounds((Bounds) boundingSphere); } return (Bounds) boundingSphere; } else return super.getBounds(); } /* void compile(CompileState compState) { setCompiled(); compState.startGroup(null); // don't merge at this level compileChildren(compState); compState.endGroup(); } */ /** * Compiles the children of the switch, preventing shape merging at * this level or above */ void compile(CompileState compState) { super.compile(compState); // don't remove this group node mergeFlag = SceneGraphObjectRetained.DONT_MERGE; if (J3dDebug.devPhase && J3dDebug.debug) { compState.numSwitches++; } } void insertChildrenData(int index) { if (childrenSwitchStates == null) { childrenSwitchStates = new ArrayList(1); childrenSwitchLinks = new ArrayList(1); } childrenSwitchLinks.add(index, new ArrayList(1)); ArrayList switchStates = new ArrayList(1); childrenSwitchStates.add(index, switchStates); if (source != null && source.isLive()) { for (int i=0; i<localToVworld.length; i++) { switchStates.add(new SwitchState(true)); } } } void appendChildrenData() { if (childrenSwitchStates == null) { childrenSwitchStates = new ArrayList(1); childrenSwitchLinks = new ArrayList(1); } childrenSwitchLinks.add(new ArrayList(1)); ArrayList switchStates = new ArrayList(1); childrenSwitchStates.add(switchStates); if (source != null && source.isLive()) { for (int i=0; i<localToVworld.length; i++) { switchStates.add(new SwitchState(true)); } } } void removeChildrenData(int index) { ArrayList oldSwitchStates = (ArrayList)childrenSwitchStates.get(index); oldSwitchStates.clear(); childrenSwitchStates.remove(index); ArrayList oldSwitchLinks = (ArrayList)childrenSwitchLinks.get(index); oldSwitchLinks.clear(); childrenSwitchLinks.remove(index); } void childDoSetLive(NodeRetained child, int childIndex, SetLiveState s) { int numPaths = (inSharedGroup)? s.keys.length : 1; s.childSwitchLinks = (ArrayList)childrenSwitchLinks.get(childIndex); for (int j=0; j< numPaths; j++) { s.closestSwitchIndices[j] = switchIndexCount; s.closestSwitchParents[j] = this; } // use switchIndexCount instead of child index to avoid // reordering due to add/remove child later switchIndexCount++; Targets[] newTargets = new Targets[numPaths]; for(int i=0; i<numPaths; i++) { newTargets[i] = new Targets(); } s.switchTargets = newTargets; s.switchStates = (ArrayList)childrenSwitchStates.get(childIndex); if(child!=null) child.setLive(s); CachedTargets cachedTargets; SwitchState switchState; if (! inSharedGroup) { cachedTargets = s.switchTargets[0].snapShotInit(); switchState = (SwitchState) s.switchStates.get(0); switchState.cachedTargets = cachedTargets; } else { for(int i=0; i<numPaths; i++) { cachedTargets = s.switchTargets[i].snapShotInit(); switchState = (SwitchState)s.switchStates.get( s.hashkeyIndex[i]); switchState.cachedTargets = cachedTargets; } } } // *************************** // TargetsInterface methods // *************************** TargetsInterface getClosestTargetsInterface(int type) { return (type == TargetsInterface.SWITCH_TARGETS)? (TargetsInterface)this: (TargetsInterface)parentTransformLink; } public CachedTargets getCachedTargets(int type, int index, int child) { if (type == TargetsInterface.SWITCH_TARGETS) { ArrayList switchStates = (ArrayList)childrenSwitchStates.get(child); if (index < switchStates.size()) { SwitchState switchState = (SwitchState)switchStates.get(index); return switchState.cachedTargets; } else { return null; } } else { System.err.println("getCachedTargets: wrong arguments"); return null; } } public void resetCachedTargets(int type, CachedTargets[] newCtArr, int child) { if (type == TargetsInterface.SWITCH_TARGETS) { ArrayList switchStates = (ArrayList)childrenSwitchStates.get( child); if (newCtArr.length != switchStates.size()) { System.err.println("resetCachedTargets: unmatched length!" + newCtArr.length + " " + switchStates.size()); System.err.println(" resetCachedTargets: " + this); } SwitchState switchState; for (int i=0; i<newCtArr.length; i++) { switchState = (SwitchState)switchStates.get(i); switchState.cachedTargets = newCtArr[i]; } } else { System.err.println("resetCachedTargets: wrong arguments"); } } public ArrayList getTargetsData(int type, int child) { if (type == TargetsInterface.SWITCH_TARGETS) { return (ArrayList)childrenSwitchStates.get(child); } else { System.err.println("getTargetsData: wrong arguments"); return null; } } public int getTargetThreads(int type) { System.err.println("getTargetsThreads: wrong arguments"); return -1; } public void updateCachedTargets(int type, CachedTargets[] newCt) { System.err.println("updateCachedTarget: wrong arguments"); } public void computeTargetThreads(int type, CachedTargets[] newCt) { System.err.println("computeTargetThreads: wrong arguments"); } public void updateTargetThreads(int type, CachedTargets[] newCt) { System.err.println("updateTargetThreads: wrong arguments"); } public void propagateTargetThreads(int type, int newTargetThreads) { System.err.println("propagateTargetThreads: wrong arguments"); } public void copyCachedTargets(int type, CachedTargets[] newCt) { System.err.println("copyCachedTarget: wrong arguments"); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -