📄 appearanceretained.java
字号:
} } } /** * Retrieves the current pointAttributes object. * @return the pointAttributes object */ PointAttributes getPointAttributes() { return (pointAttributes == null? null : (PointAttributes)pointAttributes.source); } /** * Sets the texCoordGeneration object to the specified object. * @param texCoordGeneration object that specifies the texture coordinate * generation parameters */ void setTexCoordGeneration(TexCoordGeneration texGen) { synchronized(liveStateLock) { if (source.isLive()) { if (this.texCoordGeneration != null) { this.texCoordGeneration.clearLive(refCount); this.texCoordGeneration.removeMirrorUsers(this); } if (texGen != null) { ((TexCoordGenerationRetained)texGen.retained).setLive(inBackgroundGroup, refCount); ((TexCoordGenerationRetained)texGen.retained).copyMirrorUsers(this); } sendMessage(TEXCOORD_GEN, (texGen != null ? ((TexCoordGenerationRetained)texGen.retained).mirror : null), true); } if (texGen == null) { this.texCoordGeneration = null; } else { this.texCoordGeneration = (TexCoordGenerationRetained)texGen.retained; } } } /** * Retrieves the current texCoordGeneration object. * @return the texCoordGeneration object */ TexCoordGeneration getTexCoordGeneration() { return (texCoordGeneration == null ? null : (TexCoordGeneration)texCoordGeneration.source); } /** * Sets the texture unit state array to the specified array. * @param textureUnitState array that specifies the texture unit state */ void setTextureUnitState(TextureUnitState[] stateArray) { int i; synchronized(liveStateLock) { if (source.isLive()) { // remove the existing texture unit states from this appearance if (this.texUnitState != null) { for (i = 0; i < this.texUnitState.length; i++) { if (this.texUnitState[i] != null) { this.texUnitState[i].clearLive(refCount); this.texUnitState[i].removeMirrorUsers(this); } } } // add the specified texture unit states to this appearance // also make a copy of the array of references to the units if (stateArray != null && stateArray.length > 0) { Object [] args = new Object[2]; // -1 index means the entire array is to be set args[0] = new Integer(-1); // make a copy of the array for the message, TextureUnitStateRetained mirrorStateArray[] = new TextureUnitStateRetained[stateArray.length]; args[1] = (Object) mirrorStateArray; for (i = 0; i < stateArray.length; i++) { TextureUnitState tu = stateArray[i]; if (tu != null) { ((TextureUnitStateRetained)tu.retained).setLive( inBackgroundGroup, refCount); ((TextureUnitStateRetained)tu.retained).copyMirrorUsers( this); mirrorStateArray[i] = (TextureUnitStateRetained) ((TextureUnitStateRetained)tu.retained).mirror; } else { mirrorStateArray[i] = null; } } sendMessage(TEXTURE_UNIT_STATE, args, true); } else { sendMessage(TEXTURE_UNIT_STATE, null, true); } } // assign the retained copy of the texture unit state to the // appearance if (stateArray == null) { this.texUnitState = null; } else { // make another copy of the array for the retained object // itself if it doesn't have a copy or the array size is // not the same if ((this.texUnitState == null) || (this.texUnitState.length != stateArray.length)) { this.texUnitState = new TextureUnitStateRetained[ stateArray.length]; } for (i = 0; i < stateArray.length; i++) { if (stateArray[i] != null) { this.texUnitState[i] = (TextureUnitStateRetained)stateArray[i].retained; } else { this.texUnitState[i] = null; } } } } } void setTextureUnitState(int index, TextureUnitState state) { synchronized(liveStateLock) { if (source.isLive()) { // remove the existing texture unit states from this appearance // Note: Let Java throw an exception if texUnitState is null // or index is >= texUnitState.length. if (this.texUnitState[index] != null) { this.texUnitState[index].clearLive(refCount); this.texUnitState[index].removeMirrorUsers(this); } // add the specified texture unit states to this appearance // also make a copy of the array of references to the units Object args[] = new Object[2]; args[0] = new Integer(index); if (state != null) { ((TextureUnitStateRetained)state.retained).setLive( inBackgroundGroup, refCount); ((TextureUnitStateRetained)state.retained).copyMirrorUsers(this); args[1] = ((TextureUnitStateRetained)state.retained).mirror; sendMessage(TEXTURE_UNIT_STATE, args, true); } else { args[1] = null; sendMessage(TEXTURE_UNIT_STATE, args, true); } } // assign the retained copy of the texture unit state to the // appearance if (state != null) { this.texUnitState[index] = (TextureUnitStateRetained)state.retained; } else { this.texUnitState[index] = null; } } } /** * Retrieves the array of texture unit state objects from this * Appearance object. A shallow copy of the array of references to * the TextureUnitState objects is returned. * */ TextureUnitState[] getTextureUnitState() { if (texUnitState == null) { return null; } else { TextureUnitState tus[] = new TextureUnitState[texUnitState.length]; for (int i = 0; i < texUnitState.length; i++) { if (texUnitState[i] != null) { tus[i] = (TextureUnitState) texUnitState[i].source; } else { tus[i] = null; } } return tus; } } /** * Retrieves the texture unit state object at the specified * index within the texture unit state array. */ TextureUnitState getTextureUnitState(int index) { // let Java throw an exception if texUnitState == null or // index is >= length if (texUnitState[index] != null) return (TextureUnitState)texUnitState[index].source; else return null; } /** * Retrieves the length of the texture unit state array from * this appearance object. The length of this array specifies the * maximum number of texture units that will be used by this * appearance object. If the array is null, a count of 0 is * returned. */ int getTextureUnitCount() { if (texUnitState == null) return 0; else return texUnitState.length; } synchronized void createMirrorObject() { if (mirror == null) { // we can't check isStatic() since it sub-NodeComponent // create a new one, we should create a // new AppearanceRetained() even though isStatic() = true. // For simplicity, always create a retained side. mirror = new AppearanceRetained(); } initMirrorObject(); } /** * This routine updates the mirror appearance for this appearance. * It also calls the update method for each node component if it * is not null. */ synchronized void initMirrorObject() { AppearanceRetained mirrorApp = (AppearanceRetained)mirror; mirrorApp.source = source; mirrorApp.sgApp = this; // Fix for Issue 33: copy the changedFrequent mask to mirror mirrorApp.changedFrequent = changedFrequent; if (material != null) { mirrorApp.material = (MaterialRetained)material.mirror; } else { mirrorApp.material = null; } if (texture != null) { mirrorApp.texture = (TextureRetained)texture.mirror; } else { mirrorApp.texture = null; } if (texCoordGeneration != null) { mirrorApp.texCoordGeneration = (TexCoordGenerationRetained)texCoordGeneration.mirror; } else { mirrorApp.texCoordGeneration = null; } if (textureAttributes != null) { mirrorApp.textureAttributes = (TextureAttributesRetained)textureAttributes.mirror; } else { mirrorApp.textureAttributes = null; } // TextureUnitState supercedes the single texture interface if (texUnitState != null && texUnitState.length > 0) { mirrorApp.texUnitState = new TextureUnitStateRetained[texUnitState.length]; for (int i = 0; i < texUnitState.length; i++) { if (texUnitState[i] != null) { mirrorApp.texUnitState[i] = (TextureUnitStateRetained)texUnitState[i].mirror; } } } else if (mirrorApp.texture != null || mirrorApp.textureAttributes != null || mirrorApp.texCoordGeneration != null) { mirrorApp.texUnitState = new TextureUnitStateRetained[1]; mirrorApp.texUnitState[0] = new TextureUnitStateRetained(); mirrorApp.texUnitState[0].set( mirrorApp.texture, mirrorApp.textureAttributes, mirrorApp.texCoordGeneration); } if (coloringAttributes != null) { mirrorApp.coloringAttributes = (ColoringAttributesRetained)coloringAttributes.mirror; } else { mirrorApp.coloringAttributes = null; } if (transparencyAttributes != null) { mirrorApp.transparencyAttributes = (TransparencyAttributesRetained)transparencyAttributes.mirror; } else { mirrorApp.transparencyAttributes = null; } if (renderingAttributes != null) { mirrorApp.renderingAttributes = (RenderingAttributesRetained)renderingAttributes.mirror; } else { mirrorApp.renderingAttributes = null; } if (polygonAttributes != null) { mirrorApp.polygonAttributes = (PolygonAttributesRetained)polygonAttributes.mirror; } else { mirrorApp.polygonAttributes = null; } if (lineAttributes != null) { mirrorApp.lineAttributes = (LineAttributesRetained)lineAttributes.mirror; } else { mirrorApp.lineAttributes = null; } if (pointAttributes != null) { mirrorApp.pointAttributes = (PointAttributesRetained)pointAttributes.mirror; } else { mirrorApp.pointAttributes = null; } } /** * Update the "component" field of the mirror object with the * given "value" */ synchronized void updateMirrorObject(int component, Object value) { AppearanceRetained mirrorApp = (AppearanceRetained)mirror; if ((component & MATERIAL) != 0) { mirrorApp.material = (MaterialRetained)value; } else if ((component & TEXTURE) != 0) { // Issue 435: set mirror texture mirrorApp.texture = (TextureRetained)value; if (mirrorApp.texUnitState == null) { mirrorApp.texUnitState = new TextureUnitStateRetained[1]; mirrorApp.texUnitState[0] = new TextureUnitStateRetained(); } mirrorApp.texUnitState[0].texture = (TextureRetained)value; } else if ((component & TEXCOORD_GEN) != 0) { if (mirrorApp.texUnitState == null) { mirrorApp.texUnitState = new TextureUnitStateRetained[1]; mirrorApp.texUnitState[0] = new TextureUnitStateRetained(); } mirrorApp.texUnitState[0].texGen = (TexCoordGenerationRetained)value; } else if ((component & TEXTURE_ATTR) != 0) { if (mirrorApp.texUnitState == null) { mirrorApp.texUnitState = new TextureUnitStateRetained[1]; mirrorApp.texUnitState[0] = new TextureUnitStateRetained(); } mirrorApp.texUnitState[0].texAttrs = (TextureAttributesRetained)value; } else if ((component & TEXTURE_UNIT_STATE) != 0) { Object [] args = (Object [])value; if (args == null) { mirrorApp.texUnitState = null; } else { int index = ((Integer)args[0]).intValue(); if (index == -1) { mirrorApp.texUnitState = (TextureUnitStateRetained [])args[1]; } else { mirrorApp.texUnitState[index] = (TextureUnitStateRetained)args[1]; } } } else if ((component & COLOR) != 0) { mirrorApp.coloringAttributes = (ColoringAttributesRetained)value; } else if ((component & TRANSPARENCY) != 0) { mirrorApp.transparencyAttributes = (TransparencyAttributesRetained)value; } else if ((component & RENDERING) != 0) { mirrorApp.renderingAttributes = (RenderingAttributesRetained)value; } else if ((component & POLYGON) != 0) { mirrorApp.polygonAttributes = (PolygonAttributesRetained)value; } else if ((component & LINE) != 0) { mirrorApp.lineAttributes = (LineAttributesRetained)value; } else if ((component & POINT) != 0) { mirrorApp.pointAttributes = (PointAttributesRetained)value; } } void setLive(boolean backgroundGroup, int refCount) { // System.err.println("AppearceRetained.setLive()"); doSetLive(backgroundGroup, refCount); markAsLive(); } /** * This method calls the setLive method of all appearance bundle * objects. */ void doSetLive(boolean backgroundGroup, int refCount) { // System.err.println("AppearceRetained.doSetLive()"); if (material != null) { material.setLive(backgroundGroup, refCount); } if (texture != null) { texture.setLive(backgroundGroup, refCount); } if (texCoordGeneration != null) { texCoordGeneration.setLive(backgroundGroup, refCount); } if (textureAttributes != null) { textureAttributes.setLive(backgroundGroup, refCount); } if (texUnitState != null) { for (int i = 0; i < texUnitState.length; i++) { if (texUnitState[i] != null) texUnitState[i].setLive(backgroundGroup, refCount); } } if (coloringAttributes != null) { coloringAttributes.setLive(backgroundGroup, refCount); } if (transparencyAttributes != null) { transparencyAttributes.setLive(backgroundGroup, refCount); } if (renderingAttributes != null) { renderingAttributes.setLive(backgroundGroup, refCount); } if (polygonAttributes != null) { polygonAttributes.setLive(backgroundGroup, refCount); } if (lineAttributes != null) { lineAttributes.setLive(backgroundGroup, refCount);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -