⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sharedgroupretained.java

📁 JAVA3D矩陈的相关类
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        void clearLive(SetLiveState s) {        int i,j,k, index;        Transform3D savedLocalToVworld[][] = s.localToVworld;        int savedLocalToVworldIndex[][] = s.localToVworldIndex;        HashKey savedLocalToVworldKeys[] = s.localToVworldKeys;        ArrayList savedOrderedPaths = s.orderedPaths;        ArrayList savedViewLists = s.viewLists;	ArrayList savedLights = s.lights;	ArrayList savedFogs = s.fogs;	ArrayList savedMclips = s.modelClips;	ArrayList savedAltApps = s.altAppearances;        Targets[] savedSwitchTargets = s.switchTargets;        Targets[] savedTransformTargets = s.transformTargets;        // no need to gather targets from sg in clear live        s.transformTargets = null;        s.switchTargets = null;	// XXXX: This is a hack since removeNodeData is called before	// children are clearLives	int[] tempIndex = null;	// Don't keep the indices if everything will be cleared	if (s.keys.length != localToVworld.length) {	    tempIndex = new int[s.keys.length];	    for (i = s.keys.length-1; i >= 0; i--) {		tempIndex[i] = s.keys[i].equals(localToVworldKeys, 0, localToVworldKeys.length);	    }	}        super.clearLive(s);	// Do this after children clearlive since part of the viewLists may get cleared	// during removeNodeData        if(refCount <= 0) {	    viewLists.clear();	}	else {	    // Must be in reverse, to preserve right indexing.	    for (i = tempIndex.length-1; i >= 0 ; i--) {		if(tempIndex[i] >= 0) {		    viewLists.remove(tempIndex[i]);		}	    }	}	        // restore setLiveState from it's local variables.        // removeNodeData has altered these variables.        s.localToVworld = savedLocalToVworld;        s.localToVworldIndex = savedLocalToVworldIndex;        s.localToVworldKeys = savedLocalToVworldKeys;        s.orderedPaths = savedOrderedPaths;        s.viewLists = savedViewLists;	s.lights = savedLights;	s.fogs = savedFogs;	s.modelClips = savedMclips;	s.altAppearances = savedAltApps;        s.transformTargets = savedTransformTargets;        s.switchTargets = savedSwitchTargets;    }    void updateChildLocalToVworld(HashKey key, int index,                                        ArrayList dirtyTransformGroups,                                        ArrayList keySet,		                        UpdateTargets targets,                                        ArrayList blUsers) {        LinkRetained ln;        TransformGroupRetained tg;        int i,j;	Object obj;        CachedTargets ct = j3dCTs[index];        if (ct != null) {            targets.addCachedTargets(ct);            if (ct.targetArr[Targets.BLN_TARGETS] != null) {                gatherBlUsers(blUsers, ct.targetArr[Targets.BLN_TARGETS]);            }        }        synchronized(childTransformLinks) {        for (i=0; i<childTransformLinks.size(); i++) {            obj = childTransformLinks.get(i);            if (obj instanceof TransformGroupRetained) {                tg = (TransformGroupRetained)obj;                tg.updateChildLocalToVworld(				tg.localToVworldKeys[index], index,				dirtyTransformGroups, keySet,				targets, blUsers);            } else { // LinkRetained                ln = (LinkRetained)obj;                currentKey.set(key);                currentKey.append(LinkRetained.plus).append(ln.nodeId);                if (ln.sharedGroup.localToVworldKeys != null) {		    j = currentKey.equals(ln.sharedGroup.localToVworldKeys,0,					  ln.sharedGroup.localToVworldKeys.length);		    if(j < 0) {			System.err.println("SharedGroupRetained : Can't find hashKey"); 		    }		                        if (j < ln.sharedGroup.localToVworldKeys.length) {                        ln.sharedGroup.updateChildLocalToVworld(				ln.sharedGroup.localToVworldKeys[j], j,				dirtyTransformGroups, keySet,				targets, blUsers);                    }                }            }        }        }    }    void traverseSwitchChild(int child, HashKey key,			     int index, SwitchRetained switchRoot,			     boolean init, boolean swChanged,			     boolean switchOn, int switchLevel, 			     ArrayList updateList) {        SwitchRetained sw;        LinkRetained ln;        Object obj;        ArrayList childSwitchLinks;	int i,j,k;        childSwitchLinks = (ArrayList)childrenSwitchLinks.get(child);        for (i=0; i<childSwitchLinks.size(); i++) {            obj = childSwitchLinks.get(i);            if (obj instanceof SwitchRetained) {                sw = (SwitchRetained)obj;                for(j=0; j<sw.children.size(); j++) {                    sw.traverseSwitchChild(j, key, index, switchRoot,					   init, swChanged, switchOn, switchLevel, updateList);                }            } else { // LinkRetained                ln = (LinkRetained)obj;                switchKey.set(key);                switchKey.append(LinkRetained.plus).append(ln.nodeId);				if (ln.sharedGroup.localToVworldKeys != null) {		    		    j = switchKey.equals(ln.sharedGroup.localToVworldKeys,0,					 ln.sharedGroup.localToVworldKeys.length);		    if(j < 0) {			System.err.println("SharedGroupRetained : Can't find hashKey"); 		    }		    		    if (j < ln.sharedGroup.localToVworldKeys.length) {			for(k=0; k<ln.sharedGroup.children.size(); k++) {			    ln.sharedGroup.traverseSwitchChild(k,							       ln.sharedGroup.							       localToVworldKeys[j],							       j, switchRoot, init,							       swChanged, switchOn,							       switchLevel, updateList);			}		    }		}            }        }    }    void traverseSwitchParent() {        int i;        NodeRetained ln;        for(i=0; i<parents.size(); i++) {            ln = (NodeRetained) parents.elementAt(i);            if (ln.parentSwitchLink != null) {                if (parentSwitchLink instanceof SwitchRetained) {                    ((SwitchRetained)parentSwitchLink).traverseSwitchParent();                } else if (parentSwitchLink instanceof SharedGroupRetained) {                    ((SharedGroupRetained)parentSwitchLink).traverseSwitchParent();                }            }        }    }    // Top level compile call, same as BranchGroup.compile()    void compile()  {        if (source.isCompiled() || VirtualUniverse.mc.disableCompile)            return;        if (J3dDebug.devPhase && J3dDebug.debug) {            J3dDebug.doDebug(J3dDebug.compileState, J3dDebug.LEVEL_3,                        "SharedGroupRetained.compile()....\n");        }        CompileState compState = new CompileState();        isRoot = true;        compile(compState);        merge(compState);        if (J3dDebug.devPhase && J3dDebug.debug) {            if (J3dDebug.doDebug(J3dDebug.compileState, J3dDebug.LEVEL_3)) {                compState.printStats();            }            if (J3dDebug.doDebug(J3dDebug.compileState, J3dDebug.LEVEL_5)) {                this.traverse(false, 1);                System.err.println();            }        }    }    /**     * Returns the Link nodes that refer to this SharedGroup node     * @return An array of Link nodes     */    Link[] getLinks() {	Link[] links; 	// make sure this method is MT-safe	synchronized(parents) {	    int n = parents.size();	    // allocate new array	    links = new Link[n];	    for(int i = 0; i < n; i++) {		// copy Link nodes from this node's list of parents		links[i] = (Link)((LinkRetained)parents.elementAt(i)).source;	    }	}	return links;    }	    void insertChildrenData(int index) {        if (childrenSwitchLinks == null) {            childrenSwitchLinks = new ArrayList(1);        }        childrenSwitchLinks.add(index, new ArrayList(1));    }    void appendChildrenData() {        if (childrenSwitchLinks == null) {            childrenSwitchLinks = new ArrayList(1);        }        childrenSwitchLinks.add(new ArrayList(1));    }    void removeChildrenData(int index) {        ArrayList oldSwitchLinks = (ArrayList)childrenSwitchLinks.get(index);        oldSwitchLinks.clear();        childrenSwitchLinks.remove(index);    }    // ***************************    // TargetsInterface methods    // ***************************    public int getTargetThreads(int type) {	if (type == TargetsInterface.TRANSFORM_TARGETS) {            return targetThreads;        } else {            System.err.println("getTargetThreads: wrong arguments");	    return -1;        }    }    TargetsInterface getClosestTargetsInterface(int type) {        return this;    }    // re-evalute localTargetThreads using newCachedTargets and    // re-evaluate targetThreads    public void computeTargetThreads(int type, 					CachedTargets[] newCachedTargets) {		localTargetThreads = 0;	if (type == TargetsInterface.TRANSFORM_TARGETS) {	    for(int i=0; i<newCachedTargets.length; i++) {	        if (newCachedTargets[i] != null) {                    localTargetThreads |= newCachedTargets[i].computeTargetThreads();		}	    }	    targetThreads = localTargetThreads;	    int numLinks = childTransformLinks.size();	    TargetsInterface childLink;	    NodeRetained node;	    for(int i=0; i<numLinks; i++) {		node = (NodeRetained)childTransformLinks.get(i);		if (node.nodeType == NodeRetained.LINK) {		    childLink = (TargetsInterface) 			((LinkRetained)node).sharedGroup;		} else {		    childLink = (TargetsInterface) node;		}		if (childLink != null) {		    targetThreads |= 			childLink.getTargetThreads(TargetsInterface.TRANSFORM_TARGETS);		}	    }        } else {            System.err.println("computeTargetsThreads: wrong arguments");        }    }    // re-compute localTargetThread, targetThreads and    // propagate changes to ancestors    public void updateTargetThreads(int type, CachedTargets[] newCachedTargets) {        // type is ignored here, only need for SharedGroup        if (type == TargetsInterface.TRANSFORM_TARGETS) {	    computeTargetThreads(type, newCachedTargets);            if (parentTransformLink != null) {                TargetsInterface pti = (TargetsInterface)parentTransformLink;                pti.propagateTargetThreads(TargetsInterface.TRANSFORM_TARGETS,                                        targetThreads);            }        } else {            System.err.println("updateTargetThreads: wrong arguments");        }    }    // re-evaluate targetThreads using childTargetThreads and     // propagate changes to ancestors    public void propagateTargetThreads(int type, int childTargetThreads) {        if (type == TargetsInterface.TRANSFORM_TARGETS) {            LinkRetained ln;	    // XXXX : For now we'll OR more than exact.            //targetThreads = localTargetThreads | childTargetThreads;	    targetThreads = targetThreads | childTargetThreads;            for(int i=0; i<parents.size(); i++) {                ln = (LinkRetained) parents.elementAt(i);                if (ln.parentTransformLink != null) {                    TargetsInterface pti =                                (TargetsInterface)ln.parentTransformLink;                    pti.propagateTargetThreads(type, targetThreads);                }            }        } else {            System.err.println("propagateTargetThreads: wrong arguments");        }    }    public void updateCachedTargets(int type, CachedTargets[] newCt) {	if (type == TargetsInterface.TRANSFORM_TARGETS) {            j3dCTs = newCt;        } else {            System.err.println("updateCachedTargets: wrong arguments");        }    }    public void copyCachedTargets(int type, CachedTargets[] newCt) {	if (type == TargetsInterface.TRANSFORM_TARGETS) {            int size = cachedTargets.length;            for (int i=0; i<size; i++) {                newCt[i] = cachedTargets[i];                    }	} else {            System.err.println("copyCachedTargets: wrong arguments");        }    }    public CachedTargets getCachedTargets(int type, int index, int child) {	if (type == TargetsInterface.SWITCH_TARGETS) {            // child info is not used, SG does not have per child states            if (index < switchStates.size()) {                SwitchState switchState = (SwitchState)switchStates.get(index);                return switchState.cachedTargets;            } else {                return null;            }        } else {	    // type == TargetsInterface.TRANSFORM_TARGETS            return cachedTargets[index];        }    }    public void resetCachedTargets(int type, 			CachedTargets[] newCtArr,int child) {	if (type == TargetsInterface.SWITCH_TARGETS) {            // child info is not used, SG does not have per child states            SwitchState switchState;            if (newCtArr.length != switchStates.size()) {                System.err.println("resetCachedTargets: unmatched length!" +                                   newCtArr.length + " " + switchStates.size());                System.err.println("  resetCachedTargets: " + this);            }            for (int i=0; i<newCtArr.length; i++) {                switchState = (SwitchState)switchStates.get(i);                switchState.cachedTargets = newCtArr[i];            }        } else {	    // type == TargetsInterface.TRANSFORM_TARGETS            cachedTargets = newCtArr;        }    }    public ArrayList getTargetsData(int type, int index) {        // index is ignores for SharedGroup	if (type == TargetsInterface.SWITCH_TARGETS) {            return switchStates;        } else {            System.err.println("getTargetsData: wrong arguments");	    return null;        }    }    void childDoSetLive(NodeRetained child, int childIndex, SetLiveState s) {	int i;        s.childSwitchLinks = (ArrayList)childrenSwitchLinks.get(childIndex);        s.switchStates = switchStates;        if(child!=null)	    child.setLive(s);    }    void childCheckSetLive(NodeRetained child, int childIndex, SetLiveState s) {        s.childTransformLinks = childTransformLinks;        s.parentTransformLink = this;        child.setLive(s);    }        /**      * 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) {            cachedBounds = null;            synchronized(parents) {                Enumeration e = parents.elements();                while(e.hasMoreElements()) {                    LinkRetained parent = (LinkRetained) e.nextElement();                    if (parent!=null) {                        parent.dirtyBoundsCache();                    }                }            }        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -