0001: /*
0002: * $RCSfile: Appearance.java,v $
0003: *
0004: * Copyright 1996-2008 Sun Microsystems, Inc. All Rights Reserved.
0005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0006: *
0007: * This code is free software; you can redistribute it and/or modify it
0008: * under the terms of the GNU General Public License version 2 only, as
0009: * published by the Free Software Foundation. Sun designates this
0010: * particular file as subject to the "Classpath" exception as provided
0011: * by Sun in the LICENSE file that accompanied this code.
0012: *
0013: * This code is distributed in the hope that it will be useful, but WITHOUT
0014: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0015: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0016: * version 2 for more details (a copy is included in the LICENSE file that
0017: * accompanied this code).
0018: *
0019: * You should have received a copy of the GNU General Public License version
0020: * 2 along with this work; if not, write to the Free Software Foundation,
0021: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0022: *
0023: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
0024: * CA 95054 USA or visit www.sun.com if you need additional information or
0025: * have any questions.
0026: *
0027: * $Revision: 1.9 $
0028: * $Date: 2008/02/28 20:17:19 $
0029: * $State: Exp $
0030: */
0031:
0032: package javax.media.j3d;
0033:
0034: import java.util.Hashtable;
0035:
0036: /**
0037: * The Appearance object defines all rendering state that can be set
0038: * as a component object of a Shape3D node. The rendering state
0039: * consists of the following:<p>
0040: * <ul>
0041: * <li>Coloring attributes - defines attributes used in color selection
0042: * and shading. These attributes are defined in a ColoringAttributes
0043: * object.</li><p>
0044: *
0045: * <li>Line attributes - defines attributes used to define lines, including
0046: * the pattern, width, and whether antialiasing is to be used. These
0047: * attributes are defined in a LineAttributes object.</li><p>
0048: *
0049: * <li>Point attributes - defines attributes used to define points,
0050: * including the size and whether antialiasing is to be used. These
0051: * attributes are defined in a PointAttributes object.</li><p>
0052: *
0053: * <li>Polygon attributes - defines the attributes used to define
0054: * polygons, including culling, rasterization mode (filled, lines,
0055: * or points), constant offset, offset factor, and whether back
0056: * back facing normals are flipped. These attributes are defined
0057: * in a PolygonAttributes object.</li><p>
0058: *
0059: * <li>Rendering attributes - defines rendering operations,
0060: * including the alpha test function and test value, the raster
0061: * operation, whether vertex colors are ignored, whether invisible
0062: * objects are rendered, and whether the depth buffer is enabled.
0063: * These attributes are defined in a RenderingAttributes
0064: * object.</li><p>
0065: *
0066: * <li>Transparency attributes - defines the attributes that affect
0067: * transparency of the object, such as the transparency mode
0068: * (blended, screen-door), blending function (used in transparency
0069: * and antialiasing operations), and a blend value that defines
0070: * the amount of transparency to be applied to this Appearance
0071: * component object.</li><p>
0072: *
0073: * <li>Material - defines the appearance of an object under illumination,
0074: * such as the ambient color, diffuse color, specular color, emissive
0075: * color, and shininess. These attributes are defined in a Material
0076: * object.</li><p>
0077: *
0078: * <li>Texture - defines the texture image and filtering
0079: * parameters used when texture mapping is enabled. These attributes
0080: * are defined in a Texture object.</li><p>
0081: *
0082: * <li>Texture attributes - defines the attributes that apply to
0083: * texture mapping, such as the texture mode, texture transform,
0084: * blend color, and perspective correction mode. These attributes
0085: * are defined in a TextureAttributes object.</li><p>
0086: *
0087: * <li>Texture coordinate generation - defines the attributes
0088: * that apply to texture coordinate generation, such as whether
0089: * texture coordinate generation is enabled, coordinate format
0090: * (2D or 3D coordinates), coordinate generation mode (object
0091: * linear, eye linear, or spherical reflection mapping), and the
0092: * R, S, and T coordinate plane equations. These attributes
0093: * are defined in a TexCoordGeneration object.</li><p>
0094: *
0095: * <li>Texture unit state - array that defines texture state for each
0096: * of <i>N</i> separate texture units. This allows multiple textures
0097: * to be applied to geometry. Each TextureUnitState object contains a
0098: * Texture object, TextureAttributes, and TexCoordGeneration object
0099: * for one texture unit. If the length of the texture unit state
0100: * array is greater than 0, then the array is used for all texture
0101: * state; the individual Texture, TextureAttributes, and
0102: * TexCoordGeneration objects in this Appearance object are not used
0103: * and and must not be set by an application. If the length of the
0104: * texture unit state array is 0, the multi-texture is disabled and
0105: * the Texture, TextureAttributes, and TexCoordGeneration objects
0106: * in the Appearance object are used. If the application sets the
0107: * existing Texture, TextureAttributes, and TexCoordGeneration
0108: * objects to non-null values, they effectively define the state
0109: * for texture unit 0. If the TextureUnitState array is set to a
0110: * non-null, non-empty array, the individual TextureUnitState
0111: * objects define the state for texture units 0 through <i>n</i>
0112: * -1. If both the old and new values are set, an exception is thrown.
0113: *
0114: * </li>
0115: * </ul>
0116: *
0117: * @see ColoringAttributes
0118: * @see LineAttributes
0119: * @see PointAttributes
0120: * @see PolygonAttributes
0121: * @see RenderingAttributes
0122: * @see TransparencyAttributes
0123: * @see Material
0124: * @see Texture
0125: * @see TextureAttributes
0126: * @see TexCoordGeneration
0127: * @see TextureUnitState
0128: */
0129: public class Appearance extends NodeComponent {
0130:
0131: /**
0132: * Specifies that this Appearance object
0133: * allows reading its coloringAttributes component
0134: * information.
0135: */
0136: public static final int ALLOW_COLORING_ATTRIBUTES_READ = CapabilityBits.APPEARANCE_ALLOW_COLORING_ATTRIBUTES_READ;
0137:
0138: /**
0139: * Specifies that this Appearance object
0140: * allows writing its coloringAttributes component
0141: * information.
0142: */
0143: public static final int ALLOW_COLORING_ATTRIBUTES_WRITE = CapabilityBits.APPEARANCE_ALLOW_COLORING_ATTRIBUTES_WRITE;
0144:
0145: /**
0146: * Specifies that this Appearance object
0147: * allows reading its transparency component
0148: * information.
0149: */
0150: public static final int ALLOW_TRANSPARENCY_ATTRIBUTES_READ = CapabilityBits.APPEARANCE_ALLOW_TRANSPARENCY_ATTRIBUTES_READ;
0151:
0152: /**
0153: * Specifies that this Appearance object
0154: * allows writing its transparency component
0155: * information.
0156: */
0157: public static final int ALLOW_TRANSPARENCY_ATTRIBUTES_WRITE = CapabilityBits.APPEARANCE_ALLOW_TRANSPARENCY_ATTRIBUTES_WRITE;
0158:
0159: /**
0160: * Specifies that this Appearance object
0161: * allows reading its rendering/rasterization component
0162: * information.
0163: */
0164: public static final int ALLOW_RENDERING_ATTRIBUTES_READ = CapabilityBits.APPEARANCE_ALLOW_RENDERING_ATTRIBUTES_READ;
0165:
0166: /**
0167: * Specifies that this Appearance object
0168: * allows writing its rendering/rasterization component
0169: * information.
0170: */
0171: public static final int ALLOW_RENDERING_ATTRIBUTES_WRITE = CapabilityBits.APPEARANCE_ALLOW_RENDERING_ATTRIBUTES_WRITE;
0172:
0173: /**
0174: * Specifies that this Appearance object
0175: * allows reading its polygon component
0176: * information.
0177: */
0178: public static final int ALLOW_POLYGON_ATTRIBUTES_READ = CapabilityBits.APPEARANCE_ALLOW_POLYGON_ATTRIBUTES_READ;
0179:
0180: /**
0181: * Specifies that this Appearance object
0182: * allows writing its polygon component
0183: * information.
0184: */
0185: public static final int ALLOW_POLYGON_ATTRIBUTES_WRITE = CapabilityBits.APPEARANCE_ALLOW_POLYGON_ATTRIBUTES_WRITE;
0186:
0187: /**
0188: * Specifies that this Appearance object
0189: * allows reading its line component
0190: * information.
0191: */
0192: public static final int ALLOW_LINE_ATTRIBUTES_READ = CapabilityBits.APPEARANCE_ALLOW_LINE_ATTRIBUTES_READ;
0193:
0194: /**
0195: * Specifies that this Appearance object
0196: * allows writing its line component
0197: * information.
0198: */
0199: public static final int ALLOW_LINE_ATTRIBUTES_WRITE = CapabilityBits.APPEARANCE_ALLOW_LINE_ATTRIBUTES_WRITE;
0200:
0201: /**
0202: * Specifies that this Appearance object
0203: * allows reading its point component
0204: * information.
0205: */
0206: public static final int ALLOW_POINT_ATTRIBUTES_READ = CapabilityBits.APPEARANCE_ALLOW_POINT_ATTRIBUTES_READ;
0207:
0208: /**
0209: * Specifies that this Appearance object
0210: * allows writing its point component
0211: * information.
0212: */
0213: public static final int ALLOW_POINT_ATTRIBUTES_WRITE = CapabilityBits.APPEARANCE_ALLOW_POINT_ATTRIBUTES_WRITE;
0214:
0215: /**
0216: * Specifies that this Appearance object
0217: * allows reading its material component information.
0218: */
0219: public static final int ALLOW_MATERIAL_READ = CapabilityBits.APPEARANCE_ALLOW_MATERIAL_READ;
0220:
0221: /**
0222: * Specifies that this Appearance object
0223: * allows writing its material component information.
0224: */
0225: public static final int ALLOW_MATERIAL_WRITE = CapabilityBits.APPEARANCE_ALLOW_MATERIAL_WRITE;
0226:
0227: /**
0228: * Specifies that this Appearance object
0229: * allows reading its texture component information.
0230: */
0231: public static final int ALLOW_TEXTURE_READ = CapabilityBits.APPEARANCE_ALLOW_TEXTURE_READ;
0232:
0233: /**
0234: * Specifies that this Appearance object
0235: * allows writing its texture component information.
0236: */
0237: public static final int ALLOW_TEXTURE_WRITE = CapabilityBits.APPEARANCE_ALLOW_TEXTURE_WRITE;
0238:
0239: /**
0240: * Specifies that this Appearance object
0241: * allows reading its textureAttributes component
0242: * information.
0243: */
0244: public static final int ALLOW_TEXTURE_ATTRIBUTES_READ = CapabilityBits.APPEARANCE_ALLOW_TEXTURE_ATTRIBUTES_READ;
0245:
0246: /**
0247: * Specifies that this Appearance object
0248: * allows writing its textureAttributes component
0249: * information.
0250: */
0251: public static final int ALLOW_TEXTURE_ATTRIBUTES_WRITE = CapabilityBits.APPEARANCE_ALLOW_TEXTURE_ATTRIBUTES_WRITE;
0252:
0253: /**
0254: * Specifies that this Appearance object
0255: * allows reading its texture coordinate generation component
0256: * information.
0257: */
0258: public static final int ALLOW_TEXGEN_READ = CapabilityBits.APPEARANCE_ALLOW_TEXGEN_READ;
0259:
0260: /**
0261: * Specifies that this Appearance object
0262: * allows writing its texture coordinate generation component
0263: * information.
0264: */
0265: public static final int ALLOW_TEXGEN_WRITE = CapabilityBits.APPEARANCE_ALLOW_TEXGEN_WRITE;
0266:
0267: /**
0268: * Specifies that this Appearance object
0269: * allows reading its texture unit state component
0270: * information.
0271: *
0272: * @since Java 3D 1.2
0273: */
0274: public static final int ALLOW_TEXTURE_UNIT_STATE_READ = CapabilityBits.APPEARANCE_ALLOW_TEXTURE_UNIT_STATE_READ;
0275:
0276: /**
0277: * Specifies that this Appearance object
0278: * allows writing its texture unit state component
0279: * information.
0280: *
0281: * @since Java 3D 1.2
0282: */
0283: public static final int ALLOW_TEXTURE_UNIT_STATE_WRITE = CapabilityBits.APPEARANCE_ALLOW_TEXTURE_UNIT_STATE_WRITE;
0284:
0285: // Array for setting default read capabilities
0286: private static final int[] readCapabilities = {
0287: ALLOW_COLORING_ATTRIBUTES_READ, ALLOW_LINE_ATTRIBUTES_READ,
0288: ALLOW_MATERIAL_READ, ALLOW_POINT_ATTRIBUTES_READ,
0289: ALLOW_POLYGON_ATTRIBUTES_READ,
0290: ALLOW_RENDERING_ATTRIBUTES_READ, ALLOW_TEXGEN_READ,
0291: ALLOW_TEXTURE_ATTRIBUTES_READ, ALLOW_TEXTURE_READ,
0292: ALLOW_TEXTURE_UNIT_STATE_READ,
0293: ALLOW_TRANSPARENCY_ATTRIBUTES_READ };
0294:
0295: /**
0296: * Constructs an Appearance component object using defaults for all
0297: * state variables. All component object references are initialized
0298: * to null.
0299: */
0300: public Appearance() {
0301: // Just use default values
0302: // set default read capabilities
0303: setDefaultReadCapabilities(readCapabilities);
0304: }
0305:
0306: /**
0307: * Creates the retained mode AppearanceRetained object that this
0308: * Appearance component object will point to.
0309: */
0310: void createRetained() {
0311: this .retained = new AppearanceRetained();
0312: this .retained.setSource(this );
0313: }
0314:
0315: /**
0316: * Sets the material object to the specified object.
0317: * Setting it to null disables lighting.
0318: * @param material object that specifies the desired material
0319: * properties
0320: * @exception CapabilityNotSetException if appropriate capability is
0321: * not set and this object is part of live or compiled scene graph
0322: */
0323: public void setMaterial(Material material) {
0324: if (isLiveOrCompiled())
0325: if (!this .getCapability(ALLOW_MATERIAL_WRITE))
0326: throw new CapabilityNotSetException(J3dI18N
0327: .getString("Appearance0"));
0328: ((AppearanceRetained) this .retained).setMaterial(material);
0329: }
0330:
0331: /**
0332: * Retrieves the current material object.
0333: * @return the material object
0334: * @exception CapabilityNotSetException if appropriate capability is
0335: * not set and this object is part of live or compiled scene graph
0336: */
0337: public Material getMaterial() {
0338: if (isLiveOrCompiled())
0339: if (!this .getCapability(ALLOW_MATERIAL_READ))
0340: throw new CapabilityNotSetException(J3dI18N
0341: .getString("Appearance1"));
0342: return ((AppearanceRetained) this .retained).getMaterial();
0343: }
0344:
0345: /**
0346: * Sets the coloringAttributes object to the specified object.
0347: * Setting it to null will result in default attribute usage.
0348: * @param coloringAttributes object that specifies the desired
0349: * coloringAttributes parameters
0350: * @exception CapabilityNotSetException if appropriate capability is
0351: * not set and this object is part of live or compiled scene graph
0352: */
0353: public void setColoringAttributes(
0354: ColoringAttributes coloringAttributes) {
0355: if (isLiveOrCompiled())
0356: if (!this .getCapability(ALLOW_COLORING_ATTRIBUTES_WRITE))
0357: throw new CapabilityNotSetException(J3dI18N
0358: .getString("Appearance6"));
0359: ((AppearanceRetained) this .retained)
0360: .setColoringAttributes(coloringAttributes);
0361: }
0362:
0363: /**
0364: * Retrieves the current coloringAttributes object.
0365: * @return the coloringAttributes object
0366: * @exception CapabilityNotSetException if appropriate capability is
0367: * not set and this object is part of live or compiled scene graph
0368: */
0369: public ColoringAttributes getColoringAttributes() {
0370: if (isLiveOrCompiled())
0371: if (!this .getCapability(ALLOW_COLORING_ATTRIBUTES_READ))
0372: throw new CapabilityNotSetException(J3dI18N
0373: .getString("Appearance7"));
0374: return ((AppearanceRetained) this .retained)
0375: .getColoringAttributes();
0376: }
0377:
0378: /**
0379: * Sets the transparencyAttributes object to the specified object.
0380: * Setting it to null will result in default attribute usage.
0381: * @param transparencyAttributes object that specifies the desired
0382: * transparencyAttributes parameters
0383: * @exception CapabilityNotSetException if appropriate capability is
0384: * not set and this object is part of live or compiled scene graph
0385: */
0386: public void setTransparencyAttributes(
0387: TransparencyAttributes transparencyAttributes) {
0388: if (isLiveOrCompiled())
0389: if (!this
0390: .getCapability(ALLOW_TRANSPARENCY_ATTRIBUTES_WRITE))
0391: throw new CapabilityNotSetException(J3dI18N
0392: .getString("Appearance8"));
0393: ((AppearanceRetained) this .retained)
0394: .setTransparencyAttributes(transparencyAttributes);
0395: }
0396:
0397: /**
0398: * Retrieves the current transparencyAttributes object.
0399: * @return the transparencyAttributes object
0400: * @exception CapabilityNotSetException if appropriate capability is
0401: * not set and this object is part of live or compiled scene graph
0402: */
0403: public TransparencyAttributes getTransparencyAttributes() {
0404: if (isLiveOrCompiled())
0405: if (!this .getCapability(ALLOW_TRANSPARENCY_ATTRIBUTES_READ))
0406: throw new CapabilityNotSetException(J3dI18N
0407: .getString("Appearance9"));
0408: return ((AppearanceRetained) this .retained)
0409: .getTransparencyAttributes();
0410: }
0411:
0412: /**
0413: * Sets the renderingAttributes object to the specified object.
0414: * Setting it to null will result in default attribute usage.
0415: * @param renderingAttributes object that specifies the desired
0416: * renderingAttributes parameters
0417: * @exception CapabilityNotSetException if appropriate capability is
0418: * not set and this object is part of live or compiled scene graph
0419: */
0420: public void setRenderingAttributes(
0421: RenderingAttributes renderingAttributes) {
0422: if (isLiveOrCompiled())
0423: if (!this .getCapability(ALLOW_RENDERING_ATTRIBUTES_WRITE))
0424: throw new CapabilityNotSetException(J3dI18N
0425: .getString("Appearance10"));
0426: ((AppearanceRetained) this .retained)
0427: .setRenderingAttributes(renderingAttributes);
0428: }
0429:
0430: /**
0431: * Retrieves the current renderingAttributes object.
0432: * @return the renderingAttributes object
0433: * @exception CapabilityNotSetException if appropriate capability is
0434: * not set and this object is part of live or compiled scene graph
0435: */
0436: public RenderingAttributes getRenderingAttributes() {
0437: if (isLiveOrCompiled())
0438: if (!this .getCapability(ALLOW_RENDERING_ATTRIBUTES_READ))
0439: throw new CapabilityNotSetException(J3dI18N
0440: .getString("Appearance11"));
0441: return ((AppearanceRetained) this .retained)
0442: .getRenderingAttributes();
0443: }
0444:
0445: /**
0446: * Sets the polygonAttributes object to the specified object.
0447: * Setting it to null will result in default attribute usage.
0448: * @param polygonAttributes object that specifies the desired
0449: * polygonAttributes parameters
0450: * @exception CapabilityNotSetException if appropriate capability is
0451: * not set and this object is part of live or compiled scene graph
0452: */
0453: public void setPolygonAttributes(PolygonAttributes polygonAttributes) {
0454: if (isLiveOrCompiled())
0455: if (!this .getCapability(ALLOW_POLYGON_ATTRIBUTES_WRITE))
0456: throw new CapabilityNotSetException(J3dI18N
0457: .getString("Appearance12"));
0458: ((AppearanceRetained) this .retained)
0459: .setPolygonAttributes(polygonAttributes);
0460: }
0461:
0462: /**
0463: * Retrieves the current polygonAttributes object.
0464: * @return the polygonAttributes object
0465: * @exception CapabilityNotSetException if appropriate capability is
0466: * not set and this object is part of live or compiled scene graph
0467: */
0468: public PolygonAttributes getPolygonAttributes() {
0469: if (isLiveOrCompiled())
0470: if (!this .getCapability(ALLOW_POLYGON_ATTRIBUTES_READ))
0471: throw new CapabilityNotSetException(J3dI18N
0472: .getString("Appearance13"));
0473: return ((AppearanceRetained) this .retained)
0474: .getPolygonAttributes();
0475: }
0476:
0477: /**
0478: * Sets the lineAttributes object to the specified object.
0479: * Setting it to null will result in default attribute usage.
0480: * @param lineAttributes object that specifies the desired
0481: * lineAttributes parameters
0482: * @exception CapabilityNotSetException if appropriate capability is
0483: * not set and this object is part of live or compiled scene graph
0484: */
0485: public void setLineAttributes(LineAttributes lineAttributes) {
0486: if (isLiveOrCompiled())
0487: if (!this .getCapability(ALLOW_LINE_ATTRIBUTES_WRITE))
0488: throw new CapabilityNotSetException(J3dI18N
0489: .getString("Appearance14"));
0490: ((AppearanceRetained) this .retained)
0491: .setLineAttributes(lineAttributes);
0492: }
0493:
0494: /**
0495: * Retrieves the current lineAttributes object.
0496: * @return the lineAttributes object
0497: * @exception CapabilityNotSetException if appropriate capability is
0498: * not set and this object is part of live or compiled scene graph
0499: */
0500: public LineAttributes getLineAttributes() {
0501: if (isLiveOrCompiled())
0502: if (!this .getCapability(ALLOW_LINE_ATTRIBUTES_READ))
0503: throw new CapabilityNotSetException(J3dI18N
0504: .getString("Appearance15"));
0505: return ((AppearanceRetained) this .retained).getLineAttributes();
0506: }
0507:
0508: /**
0509: * Sets the pointAttributes object to the specified object.
0510: * Setting it to null will result in default attribute usage.
0511: * @param pointAttributes object that specifies the desired
0512: * pointAttributes parameters
0513: * @exception CapabilityNotSetException if appropriate capability is
0514: * not set and this object is part of live or compiled scene graph
0515: */
0516: public void setPointAttributes(PointAttributes pointAttributes) {
0517: if (isLiveOrCompiled())
0518: if (!this .getCapability(ALLOW_POINT_ATTRIBUTES_WRITE))
0519: throw new CapabilityNotSetException(J3dI18N
0520: .getString("Appearance16"));
0521: ((AppearanceRetained) this .retained)
0522: .setPointAttributes(pointAttributes);
0523: }
0524:
0525: /**
0526: * Retrieves the current pointAttributes object.
0527: * @return the pointAttributes object
0528: * @exception CapabilityNotSetException if appropriate capability is
0529: * not set and this object is part of live or compiled scene graph
0530: */
0531: public PointAttributes getPointAttributes() {
0532: if (isLiveOrCompiled())
0533: if (!this .getCapability(ALLOW_POINT_ATTRIBUTES_READ))
0534: throw new CapabilityNotSetException(J3dI18N
0535: .getString("Appearance17"));
0536: return ((AppearanceRetained) this .retained)
0537: .getPointAttributes();
0538: }
0539:
0540: /**
0541: * Sets the texture object to the specified object.
0542: * Setting it to null disables texture mapping.
0543: *
0544: * <p>
0545: * Applications must not set individual texture component objects
0546: * (texture, textureAttributes, or texCoordGeneration) and
0547: * the texture unit state array in the same Appearance object.
0548: * Doing so will result in an exception being thrown.
0549: *
0550: * @param texture object that specifies the desired texture
0551: * map and texture parameters
0552: *
0553: * @exception CapabilityNotSetException if appropriate capability is
0554: * not set and this object is part of live or compiled scene graph
0555: *
0556: * @exception IllegalStateException if the specified texture
0557: * object is non-null and the texture unit state array in this
0558: * appearance object is already non-null.
0559: *
0560: * @exception IllegalSharingException if this Appearance is live and
0561: * the specified texture refers to an ImageComponent2D that is being used
0562: * by a Canvas3D as an off-screen buffer.
0563: *
0564: * @exception IllegalSharingException if this Appearance is
0565: * being used by an immediate mode context and
0566: * the specified texture refers to an ImageComponent2D that is being used
0567: * by a Canvas3D as an off-screen buffer.
0568: */
0569: public void setTexture(Texture texture) {
0570: if (isLiveOrCompiled())
0571: if (!this .getCapability(ALLOW_TEXTURE_WRITE))
0572: throw new CapabilityNotSetException(J3dI18N
0573: .getString("Appearance2"));
0574:
0575: // Do illegal sharing check
0576: if (texture != null) {
0577: ImageComponent[] images = ((TextureRetained) (texture.retained))
0578: .getImages();
0579: if (images != null) {
0580: for (int i = 0; i < images.length; i++) {
0581: validateImageIllegalSharing(images[i]);
0582: }
0583: }
0584: }
0585:
0586: ((AppearanceRetained) this .retained).setTexture(texture);
0587: }
0588:
0589: /**
0590: * Retrieves the current texture object.
0591: * @return the texture object
0592: * @exception CapabilityNotSetException if appropriate capability is
0593: * not set and this object is part of live or compiled scene graph
0594: */
0595: public Texture getTexture() {
0596: if (isLiveOrCompiled())
0597: if (!this .getCapability(ALLOW_TEXTURE_READ))
0598: throw new CapabilityNotSetException(J3dI18N
0599: .getString("Appearance3"));
0600: return ((AppearanceRetained) this .retained).getTexture();
0601: }
0602:
0603: /**
0604: * Sets the textureAttributes object to the specified object.
0605: * Setting it to null will result in default attribute usage.
0606: *
0607: * <p>
0608: * Applications must not set individual texture component objects
0609: * (texture, textureAttributes, or texCoordGeneration) and
0610: * the texture unit state array in the same Appearance object.
0611: * Doing so will result in an exception being thrown.
0612: *
0613: * @param textureAttributes object that specifies the desired
0614: * textureAttributes map and textureAttributes parameters
0615: *
0616: * @exception CapabilityNotSetException if appropriate capability is
0617: * not set and this object is part of live or compiled scene graph
0618: *
0619: * @exception IllegalStateException if the specified textureAttributes
0620: * object is non-null and the texture unit state array in this
0621: * appearance object is already non-null.
0622: */
0623: public void setTextureAttributes(TextureAttributes textureAttributes) {
0624: if (isLiveOrCompiled())
0625: if (!this .getCapability(ALLOW_TEXTURE_ATTRIBUTES_WRITE))
0626: throw new CapabilityNotSetException(J3dI18N
0627: .getString("Appearance4"));
0628: ((AppearanceRetained) this .retained)
0629: .setTextureAttributes(textureAttributes);
0630: }
0631:
0632: /**
0633: * Retrieves the current textureAttributes object.
0634: * @return the textureAttributes object
0635: * @exception CapabilityNotSetException if appropriate capability is
0636: * not set and this object is part of live or compiled scene graph
0637: */
0638: public TextureAttributes getTextureAttributes() {
0639: if (isLiveOrCompiled())
0640: if (!this .getCapability(ALLOW_TEXTURE_ATTRIBUTES_READ))
0641: throw new CapabilityNotSetException(J3dI18N
0642: .getString("Appearance5"));
0643: return ((AppearanceRetained) this .retained)
0644: .getTextureAttributes();
0645: }
0646:
0647: /**
0648: * Sets the texCoordGeneration object to the specified object.
0649: * Setting it to null disables texture coordinate generation.
0650: *
0651: * <p>
0652: * Applications must not set individual texture component objects
0653: * (texture, textureAttributes, or texCoordGeneration) and
0654: * the texture unit state array in the same Appearance object.
0655: * Doing so will result in an exception being thrown.
0656: *
0657: * @param texCoordGeneration object that specifies the texture coordinate
0658: * generation parameters
0659: *
0660: * @exception CapabilityNotSetException if appropriate capability is
0661: * not set and this object is part of live or compiled scene graph
0662: *
0663: * @exception IllegalStateException if the specified texCoordGeneration
0664: * object is non-null and the texture unit state array in this
0665: * appearance object is already non-null.
0666: */
0667: public void setTexCoordGeneration(
0668: TexCoordGeneration texCoordGeneration) {
0669: if (isLiveOrCompiled())
0670: if (!this .getCapability(ALLOW_TEXGEN_WRITE))
0671: throw new CapabilityNotSetException(J3dI18N
0672: .getString("Appearance18"));
0673: ((AppearanceRetained) this .retained)
0674: .setTexCoordGeneration(texCoordGeneration);
0675: }
0676:
0677: /**
0678: * Retrieves the current texCoordGeneration object.
0679: * @return the texCoordGeneration object
0680: * @exception CapabilityNotSetException if appropriate capability is
0681: * not set and this object is part of live or compiled scene graph
0682: */
0683: public TexCoordGeneration getTexCoordGeneration() {
0684: if (isLiveOrCompiled())
0685: if (!this .getCapability(ALLOW_TEXGEN_READ))
0686: throw new CapabilityNotSetException(J3dI18N
0687: .getString("Appearance19"));
0688: return ((AppearanceRetained) this .retained)
0689: .getTexCoordGeneration();
0690: }
0691:
0692: /**
0693: * Sets the texture unit state array for this appearance object to the
0694: * specified array. A shallow copy of the array of references to
0695: * the TextureUnitState objects is made. If the specified array
0696: * is null or if the length of the array is 0, multi-texture is
0697: * disabled. Within the array, a null TextureUnitState element
0698: * disables the corresponding texture unit.
0699: *
0700: * <p>
0701: * Applications must not set individual texture component objects
0702: * (texture, textureAttributes, or texCoordGeneration) and
0703: * the texture unit state array in the same Appearance object.
0704: * Doing so will result in an exception being thrown.
0705: *
0706: * @param stateArray array of TextureUnitState objects that
0707: * specify the desired texture state for each unit. The length of
0708: * this array specifies the maximum number of texture units that
0709: * will be used by this appearance object. The texture units are
0710: * numbered from <code>0</code> through
0711: * <code>stateArray.length-1</code>.
0712: *
0713: * @exception CapabilityNotSetException if appropriate capability is
0714: * not set and this object is part of live or compiled scene graph
0715: *
0716: * @exception IllegalStateException if the specified array is
0717: * non-null and any of the texture object, textureAttributes
0718: * object, or texCoordGeneration object in this appearance object
0719: * is already non-null.
0720: *
0721: * @exception IllegalSharingException if this Appearance is live and
0722: * any of the specified textures refers to an ImageComponent2D that is
0723: * being used by a Canvas3D as an off-screen buffer.
0724: *
0725: * @exception IllegalSharingException if this Appearance is
0726: * being used by an immediate mode context and
0727: * any of the specified textures refers to an ImageComponent2D that is
0728: * being used by a Canvas3D as an off-screen buffer.
0729: *
0730: * @since Java 3D 1.2
0731: */
0732: public void setTextureUnitState(TextureUnitState[] stateArray) {
0733: if (isLiveOrCompiled())
0734: if (!this .getCapability(ALLOW_TEXTURE_UNIT_STATE_WRITE))
0735: throw new CapabilityNotSetException(J3dI18N
0736: .getString("Appearance20"));
0737:
0738: // Do illegal sharing check
0739: if (stateArray != null) {
0740: for (int j = 0; j < stateArray.length; j++) {
0741: if (stateArray[j] != null) {
0742: TextureRetained texRetained = ((TextureUnitStateRetained) stateArray[j].retained).texture;
0743: if (texRetained != null) {
0744: ImageComponent[] images = texRetained
0745: .getImages();
0746: if (images != null) {
0747: for (int i = 0; i < images.length; i++) {
0748: validateImageIllegalSharing(images[i]);
0749: }
0750: }
0751: }
0752: }
0753: }
0754: }
0755:
0756: ((AppearanceRetained) this .retained)
0757: .setTextureUnitState(stateArray);
0758: }
0759:
0760: /**
0761: * Sets the texture unit state object at the specified index
0762: * within the texture unit state array to the specified object.
0763: * If the specified object is null, the corresponding texture unit
0764: * is disabled. The index must be within the range
0765: * <code>[0, stateArray.length-1]</code>.
0766: *
0767: * @param index the array index of the object to be set
0768: *
0769: * @param state new texture unit state object
0770: *
0771: * @exception CapabilityNotSetException if appropriate capability is
0772: * not set and this object is part of live or compiled scene graph
0773: * @exception NullPointerException if the texture unit state array is
0774: * null.
0775: * @exception ArrayIndexOutOfBoundsException if <code>index >=
0776: * stateArray.length</code>.
0777: *
0778: * @exception IllegalSharingException if this Appearance is live and
0779: * the specified texture refers to an ImageComponent2D that is being used
0780: * by a Canvas3D as an off-screen buffer.
0781: *
0782: * @exception IllegalSharingException if this Appearance is
0783: * being used by an immediate mode context and
0784: * the specified texture refers to an ImageComponent2D that is being used
0785: * by a Canvas3D as an off-screen buffer.
0786: *
0787: * @since Java 3D 1.2
0788: */
0789: public void setTextureUnitState(int index, TextureUnitState state) {
0790: if (isLiveOrCompiled())
0791: if (!this .getCapability(ALLOW_TEXTURE_UNIT_STATE_WRITE))
0792: throw new CapabilityNotSetException(J3dI18N
0793: .getString("Appearance20"));
0794:
0795: // Do illegal sharing check
0796: if (state != null) {
0797: TextureRetained texRetained = ((TextureUnitStateRetained) state.retained).texture;
0798: if (texRetained != null) {
0799: ImageComponent[] images = texRetained.getImages();
0800: if (images != null) {
0801: for (int i = 0; i < images.length; i++) {
0802: validateImageIllegalSharing(images[i]);
0803: }
0804: }
0805: }
0806: }
0807:
0808: ((AppearanceRetained) this .retained).setTextureUnitState(index,
0809: state);
0810: }
0811:
0812: /**
0813: * Retrieves the array of texture unit state objects from this
0814: * Appearance object. A shallow copy of the array of references to
0815: * the TextureUnitState objects is returned.
0816: *
0817: * @return the array of texture unit state objects
0818: *
0819: * @exception CapabilityNotSetException if appropriate capability is
0820: * not set and this object is part of live or compiled scene graph
0821: *
0822: * @since Java 3D 1.2
0823: */
0824: public TextureUnitState[] getTextureUnitState() {
0825: if (isLiveOrCompiled())
0826: if (!this .getCapability(ALLOW_TEXTURE_UNIT_STATE_READ))
0827: throw new CapabilityNotSetException(J3dI18N
0828: .getString("Appearance21"));
0829:
0830: return ((AppearanceRetained) this .retained)
0831: .getTextureUnitState();
0832: }
0833:
0834: /**
0835: * Retrieves the texture unit state object at the specified
0836: * index within the texture unit state array. The index must be
0837: * within the range <code>[0, stateArray.length-1]</code>.
0838: *
0839: * @param index the array index of the object to be retrieved
0840: *
0841: * @return the texture unit state object at the specified index
0842: *
0843: * @exception CapabilityNotSetException if appropriate capability is
0844: * not set and this object is part of live or compiled scene graph
0845: *
0846: * @since Java 3D 1.2
0847: */
0848: public TextureUnitState getTextureUnitState(int index) {
0849: if (isLiveOrCompiled())
0850: if (!this .getCapability(ALLOW_TEXTURE_UNIT_STATE_READ))
0851: throw new CapabilityNotSetException(J3dI18N
0852: .getString("Appearance21"));
0853:
0854: return ((AppearanceRetained) this .retained)
0855: .getTextureUnitState(index);
0856: }
0857:
0858: /**
0859: * Retrieves the length of the texture unit state array from
0860: * this appearance object. The length of this array specifies the
0861: * maximum number of texture units that will be used by this
0862: * appearance object. If the array is null, a count of 0 is
0863: * returned.
0864: *
0865: * @return the length of the texture unit state array
0866: *
0867: * @exception CapabilityNotSetException if appropriate capability is
0868: * not set and this object is part of live or compiled scene graph
0869: *
0870: * @since Java 3D 1.2
0871: */
0872: public int getTextureUnitCount() {
0873: if (isLiveOrCompiled())
0874: if (!this .getCapability(ALLOW_TEXTURE_UNIT_STATE_READ))
0875: throw new CapabilityNotSetException(J3dI18N
0876: .getString("Appearance21"));
0877:
0878: return ((AppearanceRetained) this .retained)
0879: .getTextureUnitCount();
0880: }
0881:
0882: /**
0883: * @deprecated replaced with cloneNodeComponent(boolean forceDuplicate)
0884: */
0885: public NodeComponent cloneNodeComponent() {
0886: Appearance a = new Appearance();
0887: a.duplicateNodeComponent(this );
0888: return a;
0889: }
0890:
0891: /**
0892: * NOTE: Applications should <i>not</i> call this method directly.
0893: * It should only be called by the cloneNode method.
0894: *
0895: * @deprecated replaced with duplicateNodeComponent(
0896: * NodeComponent originalNodeComponent, boolean forceDuplicate)
0897: */
0898: public void duplicateNodeComponent(
0899: NodeComponent originalNodeComponent) {
0900: checkDuplicateNodeComponent(originalNodeComponent);
0901: }
0902:
0903: /**
0904: * Copies all Appearance information from
0905: * <code>originalNodeComponent</code> into
0906: * the current node. This method is called from the
0907: * <code>cloneNode</code> method which is, in turn, called by the
0908: * <code>cloneTree</code> method.<P>
0909: *
0910: * @param originalNodeComponent the original node to duplicate.
0911: * @param forceDuplicate when set to <code>true</code>, causes the
0912: * <code>duplicateOnCloneTree</code> flag to be ignored. When
0913: * <code>false</code>, the value of each node's
0914: * <code>duplicateOnCloneTree</code> variable determines whether
0915: * NodeComponent data is duplicated or copied.
0916: *
0917: * @exception RestrictedAccessException if this object is part of a live
0918: * or compiled scenegraph.
0919: *
0920: * @see Node#cloneTree
0921: * @see NodeComponent#setDuplicateOnCloneTree
0922: */
0923: void duplicateAttributes(NodeComponent originalNodeComponent,
0924: boolean forceDuplicate) {
0925: super
0926: .duplicateAttributes(originalNodeComponent,
0927: forceDuplicate);
0928:
0929: Hashtable hashtable = originalNodeComponent.nodeHashtable;
0930:
0931: AppearanceRetained app = (AppearanceRetained) originalNodeComponent.retained;
0932:
0933: AppearanceRetained rt = (AppearanceRetained) retained;
0934:
0935: rt.setMaterial((Material) getNodeComponent(app.getMaterial(),
0936: forceDuplicate, hashtable));
0937:
0938: rt
0939: .setColoringAttributes((ColoringAttributes) getNodeComponent(
0940: app.getColoringAttributes(), forceDuplicate,
0941: hashtable));
0942:
0943: rt
0944: .setTransparencyAttributes((TransparencyAttributes) getNodeComponent(
0945: app.getTransparencyAttributes(),
0946: forceDuplicate, hashtable));
0947:
0948: rt
0949: .setRenderingAttributes((RenderingAttributes) getNodeComponent(
0950: app.getRenderingAttributes(), forceDuplicate,
0951: hashtable));
0952:
0953: rt.setPolygonAttributes((PolygonAttributes) getNodeComponent(
0954: app.getPolygonAttributes(), forceDuplicate, hashtable));
0955:
0956: rt.setLineAttributes((LineAttributes) getNodeComponent(app
0957: .getLineAttributes(), forceDuplicate, hashtable));
0958:
0959: rt.setPointAttributes((PointAttributes) getNodeComponent(app
0960: .getPointAttributes(), forceDuplicate, hashtable));
0961:
0962: rt.setTexture((Texture) getNodeComponent(app.getTexture(),
0963: forceDuplicate, hashtable));
0964:
0965: rt.setTextureAttributes((TextureAttributes) getNodeComponent(
0966: app.getTextureAttributes(), forceDuplicate, hashtable));
0967:
0968: rt
0969: .setTexCoordGeneration((TexCoordGeneration) getNodeComponent(
0970: app.getTexCoordGeneration(), forceDuplicate,
0971: hashtable));
0972:
0973: TextureUnitState state[] = app.getTextureUnitState();
0974: if (state != null) {
0975: rt.setTextureUnitState(state);
0976: for (int i = 0; i < state.length; i++) {
0977: rt.setTextureUnitState(i,
0978: (TextureUnitState) getNodeComponent(state[i],
0979: forceDuplicate, hashtable));
0980: }
0981: }
0982:
0983: }
0984:
0985: /**
0986: * This function is called from getNodeComponent() to see if any of
0987: * the sub-NodeComponents duplicateOnCloneTree flag is true.
0988: * If it is the case, current NodeComponent needs to
0989: * duplicate also even though current duplicateOnCloneTree flag is false.
0990: * This should be overwrite by NodeComponent which contains sub-NodeComponent.
0991: */
0992: boolean duplicateChild() {
0993: if (getDuplicateOnCloneTree())
0994: return true;
0995:
0996: AppearanceRetained rt = (AppearanceRetained) retained;
0997:
0998: NodeComponent nc;
0999:
1000: nc = rt.getMaterial();
1001: if ((nc != null) && nc.getDuplicateOnCloneTree())
1002: return true;
1003:
1004: nc = rt.getColoringAttributes();
1005: if ((nc != null) && nc.getDuplicateOnCloneTree())
1006: return true;
1007:
1008: nc = rt.getTransparencyAttributes();
1009: if ((nc != null) && nc.getDuplicateOnCloneTree())
1010: return true;
1011:
1012: nc = rt.getPolygonAttributes();
1013: if ((nc != null) && nc.getDuplicateOnCloneTree())
1014: return true;
1015:
1016: nc = rt.getLineAttributes();
1017: if ((nc != null) && nc.getDuplicateOnCloneTree())
1018: return true;
1019:
1020: nc = rt.getPointAttributes();
1021: if ((nc != null) && nc.getDuplicateOnCloneTree())
1022: return true;
1023:
1024: nc = rt.getTexture();
1025: if ((nc != null) && nc.duplicateChild())
1026: return true;
1027:
1028: nc = rt.getTextureAttributes();
1029: if ((nc != null) && nc.getDuplicateOnCloneTree())
1030: return true;
1031:
1032: nc = rt.getTexCoordGeneration();
1033: if ((nc != null) && nc.getDuplicateOnCloneTree())
1034: return true;
1035:
1036: // XXXX: TextureUnitState
1037:
1038: return false;
1039: }
1040:
1041: }
|