📄 lightretained.java
字号:
} /** * This gets the mirror light for this light given the key. */ LightRetained getMirrorLight(HashKey key) { int i; LightRetained[] newLights; if (inSharedGroup) { for (i=0; i<numMirrorLights; i++) { if (mirrorLights[i].key.equals(key)) { return(mirrorLights[i]); } } if (numMirrorLights == mirrorLights.length) { newLights = new LightRetained[numMirrorLights*2]; for (i=0; i<numMirrorLights; i++) { newLights[i] = mirrorLights[i]; } mirrorLights = newLights; } // mirrorLights[numMirrorLights] = (LightRetained) // this.clone(true); mirrorLights[numMirrorLights] = (LightRetained) this.clone(); // If the bounding leaf is not null , add this // mirror object as a user if (boundingLeaf != null) { mirrorLights[numMirrorLights].boundingLeaf = this.boundingLeaf.mirrorBoundingLeaf; if (mirrorLights[numMirrorLights].boundingLeaf != null) mirrorLights[numMirrorLights].boundingLeaf.addUser(mirrorLights[numMirrorLights]); } // mirrorLights[numMirrorLights].key = new HashKey(key); mirrorLights[numMirrorLights].key = key; mirrorLights[numMirrorLights].sgLight = this; return(mirrorLights[numMirrorLights++]); } else { if (mirrorLights[0] == null) { //mirrorLights[0] = (LightRetained) this.clone(true); mirrorLights[0] = (LightRetained) this.clone(); // If the bounding leaf is not null , add this // mirror object as a user if (boundingLeaf != null) { mirrorLights[0].boundingLeaf = this.boundingLeaf.mirrorBoundingLeaf; if (mirrorLights[0].boundingLeaf != null) mirrorLights[0].boundingLeaf.addUser(mirrorLights[0]); } mirrorLights[0].sgLight = this; } return(mirrorLights[0]); } } void setLive(SetLiveState s) { LightRetained ml; int i, j; newlyAddedMirrorLights.clear(); if (inImmCtx) { throw new IllegalSharingException(J3dI18N.getString("LightRetained0")); } super.doSetLive(s); if (s.inSharedGroup) { for (i=0; i<s.keys.length; i++) { ml = this.getMirrorLight(s.keys[i]); ml.localToVworld = new Transform3D[1][]; ml.localToVworldIndex = new int[1][]; j = s.keys[i].equals(localToVworldKeys, 0, localToVworldKeys.length); if(j < 0) { System.err.println("LightRetained : Can't find hashKey"); } ml.localToVworld[0] = localToVworld[j]; ml.localToVworldIndex[0] = localToVworldIndex[j]; // If its view Scoped, then add this list // to be sent to Rendering Env if ((s.viewScopedNodeList != null) && (s.viewLists != null)) { s.viewScopedNodeList.add(ml); s.scopedNodesViewList.add(s.viewLists.get(i)); } else { s.nodeList.add(ml); } newlyAddedMirrorLights.add(ml); if (boundingLeaf != null) { boundingLeaf.mirrorBoundingLeaf.addUser(ml); } if (s.transformTargets != null && s.transformTargets[i] != null) { s.transformTargets[i].addNode(ml, Targets.ENV_TARGETS); s.notifyThreads |= J3dThread.UPDATE_TRANSFORM; } if (s.switchTargets != null && s.switchTargets[i] != null) { s.switchTargets[i].addNode(ml, Targets.ENV_TARGETS); } ml.switchState = (SwitchState)s.switchStates.get(j); } } else { ml = this.getMirrorLight(null); ml.localToVworld = new Transform3D[1][]; ml.localToVworldIndex = new int[1][]; ml.localToVworld[0] = this.localToVworld[0]; ml.localToVworldIndex[0] = this.localToVworldIndex[0]; // Initialization of the mirror object // If its view Scoped, then add this list // to be sent to Rendering Env // System.err.println("lightSetLive, s.viewList = "+s.viewLists); if ((s.viewScopedNodeList != null) && (s.viewLists != null)) { s.viewScopedNodeList.add(ml); s.scopedNodesViewList.add(s.viewLists.get(0)); } else { s.nodeList.add(ml); } newlyAddedMirrorLights.add(ml); if (boundingLeaf != null) { boundingLeaf.mirrorBoundingLeaf.addUser(ml); } if (s.transformTargets != null && s.transformTargets[0] != null) { s.transformTargets[0].addNode(ml, Targets.ENV_TARGETS); s.notifyThreads |= J3dThread.UPDATE_TRANSFORM; } if (s.switchTargets != null && s.switchTargets[0] != null) { s.switchTargets[0].addNode(ml, Targets.ENV_TARGETS); } ml.switchState = (SwitchState)s.switchStates.get(0); } s.notifyThreads |= J3dThread.UPDATE_RENDERING_ENVIRONMENT| J3dThread.UPDATE_RENDER; super.markAsLive(); } J3dMessage initMessage(int num) { J3dMessage createMessage = new J3dMessage(); createMessage.threads = J3dThread.UPDATE_RENDERING_ENVIRONMENT; createMessage.universe = universe; createMessage.type = J3dMessage.LIGHT_CHANGED; createMessage.args[0] = this; // a snapshot of all attributes that needs to be initialized // in the mirror object createMessage.args[1]= new Integer(INIT_MIRROR); LightRetained[] mlts = new LightRetained[newlyAddedMirrorLights.size()]; for (int i = 0; i < mlts.length; i++) { mlts[i] = (LightRetained)newlyAddedMirrorLights.get(i); } createMessage.args[2] = new Integer(mlts.length); createMessage.args[3] = mlts; Object[] obj = new Object[num]; obj[0] = boundingLeaf; obj[1] = (regionOfInfluence != null?regionOfInfluence.clone():null); obj[2] = (inBackgroundGroup? Boolean.TRUE:Boolean.FALSE); obj[3] = geometryBackground; obj[4] = (lightOn? Boolean.TRUE:Boolean.FALSE); ArrayList addScopeList = new ArrayList(); for (int i = 0; i < scopes.size(); i++) { GroupRetained group = (GroupRetained)scopes.get(i); tempKey.reset(); group.addAllNodesForScopedLight(mlts.length, mlts, addScopeList, tempKey); } Object[] scopeInfo = new Object[2]; scopeInfo[0] = ((scopes.size() > 0) ? Boolean.TRUE:Boolean.FALSE); scopeInfo[1] = addScopeList; obj[5] = scopeInfo; Color3f clr = new Color3f(color); obj[6] = clr; createMessage.args[4] = obj; return createMessage; } // The default set of clearLive actions void clearLive(SetLiveState s) { LightRetained ml; newlyAddedMirrorLights.clear(); super.clearLive(s); if (inSharedGroup) { for (int i=0; i<s.keys.length; i++) { ml = this.getMirrorLight(s.keys[i]); if (s.transformTargets != null && s.transformTargets[i] != null) { s.transformTargets[i].addNode(ml, Targets.ENV_TARGETS); s.notifyThreads |= J3dThread.UPDATE_TRANSFORM; } newlyAddedMirrorLights.add(ml); // Remove this mirror light as users of the bounding leaf if (ml.boundingLeaf != null) { ml.boundingLeaf.removeUser(ml); ml.boundingLeaf = null; } if (s.switchTargets != null && s.switchTargets[i] != null) { s.switchTargets[i].addNode(ml, Targets.ENV_TARGETS); } if ((s.viewScopedNodeList != null) && (s.viewLists != null)) { s.viewScopedNodeList.add(ml); s.scopedNodesViewList.add(s.viewLists.get(i)); } else { s.nodeList.add(ml); } } } else { ml = this.getMirrorLight(null); // Remove this mirror light as users of the bounding leaf if (ml.boundingLeaf != null) { ml.boundingLeaf.removeUser(ml); ml.boundingLeaf = null; } if (s.switchTargets != null && s.switchTargets[0] != null) { s.switchTargets[0].addNode(ml, Targets.ENV_TARGETS); } if ((s.viewScopedNodeList != null) && (s.viewLists != null)) { s.viewScopedNodeList.add(ml); //System.err.println("s.viewList is " + s.viewLists); s.scopedNodesViewList.add(s.viewLists.get(0)); } else { s.nodeList.add(ml); } if (s.transformTargets != null && s.transformTargets[0] != null) { s.transformTargets[0].addNode(ml, Targets.ENV_TARGETS); s.notifyThreads |= J3dThread.UPDATE_TRANSFORM; } newlyAddedMirrorLights.add(ml); } s.notifyThreads |= J3dThread.UPDATE_RENDERING_ENVIRONMENT| J3dThread.UPDATE_RENDER; if (scopes.size() > 0) { J3dMessage createMessage = new J3dMessage(); LightRetained[] mlts = new LightRetained[newlyAddedMirrorLights.size()]; for (int i = 0; i < mlts.length; i++) { mlts[i] = (LightRetained)newlyAddedMirrorLights.get(i); } createMessage.threads = J3dThread.UPDATE_RENDERING_ENVIRONMENT; createMessage.universe = universe; createMessage.type = J3dMessage.LIGHT_CHANGED; createMessage.args[0] = this; createMessage.args[1]= new Integer(CLEAR_MIRROR); ArrayList removeScopeList = new ArrayList(); for (int i = 0; i < scopes.size(); i++) { GroupRetained group = (GroupRetained)scopes.get(i); tempKey.reset(); group.removeAllNodesForScopedLight(mlts.length, mlts, removeScopeList, tempKey); } createMessage.args[2] = removeScopeList; createMessage.args[3] = new Integer(mlts.length); createMessage.args[4] = mlts; VirtualUniverse.mc.processMessage(createMessage); } } void clearMirrorObject(Object[] args) { Shape3DRetained shape; ArrayList shapeList = (ArrayList)args[2]; ArrayList removeScopeList = new ArrayList(); LightRetained[] mLgts = (LightRetained[]) args[4]; int numLgts = ((Integer)args[3]).intValue(); for (int k = 0; k < numLgts; k++) { for (int i = 0; i < shapeList.size(); i++) { shape = ((GeometryAtom)shapeList.get(i)).source; shape.removeLight(mLgts[k]); } mLgts[k].isScoped = false; } } /** * Clones only the retained side, internal use only */ protected Object clone() { LightRetained lr = (LightRetained)super.clone(); lr.color = new Color3f(color); lr.scopes = (Vector) scopes.clone(); lr.initInfluencingBoundingLeaf(getInfluencingBoundingLeaf()); lr.region = null; lr.lightDirty = 0xffff; lr.sgLightDirty = 0xffff; lr.universe = null; lr.isNeeded = false; lr.inImmCtx = false; lr.sgLight = null; lr.key = null; lr.mirrorLights = new LightRetained[1]; lr.numMirrorLights = 0; lr.environmentSets = new UnorderList(1, EnvironmentSet.class); return lr; } // Called during RenderingEnv object update void updateTransformChange() { } // Called on mirror object and updated when message is received void updateImmediateTransformChange() { // If bounding leaf is null, tranform the bounds object if (boundingLeaf == null) { if (regionOfInfluence != null) { region = regionOfInfluence.copy(region); region.transform(regionOfInfluence, getCurrentLocalToVworld()); } } } void sendMessage(int attrMask, Object attr) { J3dMessage createMessage = new J3dMessage(); createMessage.threads = targetThreads; createMessage.type = J3dMessage.LIGHT_CHANGED; createMessage.universe = universe; createMessage.args[0] = this; createMessage.args[1]= new Integer(attrMask); if (inSharedGroup) createMessage.args[2] = new Integer(numMirrorLights); else createMessage.args[2] = new Integer(1); createMessage.args[3] = mirrorLights.clone(); createMessage.args[4] = attr; VirtualUniverse.mc.processMessage(createMessage); } void mergeTransform(TransformGroupRetained xform) { super.mergeTransform(xform); if (regionOfInfluence != null) { regionOfInfluence.transform(xform.transform); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -