1 /* 2 * $RCSfile: TexCoordGeneration.java,v $ 3 * 4 * Copyright 1996-2008 Sun Microsystems, Inc. All Rights Reserved. 5 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 6 * 7 * This code is free software; you can redistribute it and/or modify it 8 * under the terms of the GNU General Public License version 2 only, as 9 * published by the Free Software Foundation. Sun designates this 10 * particular file as subject to the "Classpath" exception as provided 11 * by Sun in the LICENSE file that accompanied this code. 12 * 13 * This code is distributed in the hope that it will be useful, but WITHOUT 14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 16 * version 2 for more details (a copy is included in the LICENSE file that 17 * accompanied this code). 18 * 19 * You should have received a copy of the GNU General Public License version 20 * 2 along with this work; if not, write to the Free Software Foundation, 21 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 22 * 23 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 24 * CA 95054 USA or visit www.sun.com if you need additional information or 25 * have any questions. 26 * 27 * $Revision: 1.6 $ 28 * $Date: 2008/02/28 20:17:31 $ 29 * $State: Exp $ 30 */ 31 32 package javax.media.j3d; 33 34 import javax.vecmath.Vector4f; 35 36 /** 37 * The TexCoordGeneration object contains all parameters needed for 38 * automatic texture coordinate generation. It is included as part 39 * of an Appearance component object. 40 * <p> 41 * Texture coordinates determine which texel in the texture map is 42 * assigned to a given vertex. Texture coordinates are interpolated 43 * between vertices, similarly to how colors are interpolated between 44 * two vertices of lines and polygons. 45 * <p> 46 * Texture coordinates consist of two, three or four coordinates. 47 * These coordinates 48 * are referred to as the <i>S</i>, <i>T</i>, <i>R</i>, and <i>Q</i> 49 * coordinates. 50 * 2D textures use the <i>S</i> and <i>T</i> coordinates. 3D textures 51 * use the <i>S</i>, <i>T</i> and <i>R</i> coordinates. The <i>Q</i> 52 * coordinate, similar to the <i>w</i> coordinate of the <i>(x, y, z, w)</i> 53 * object coordinates, is used to create homogeneous coordinates. 54 * <p> 55 * Rather than the programmer having to explicitly assign texture 56 * coordinates, Java 3D can automatically generate the texture 57 * coordinates to achieve texture mapping onto contours. 58 * The TexCoordGeneration attributes specify the functions for automatically 59 * generating texture coordinates. The texture attributes that can be 60 * defined are: 61 * <p><ul> 62 * <li>Texture format - defines whether the generated texture 63 * coordinates are 2D, 3D, or 4D:<p> 64 * <ul> 65 * <li>TEXTURE_COORDINATE_2 - generates 2D texture coordinates 66 * (S and T).<p> 67 * <li>TEXTURE_COORDINATE_3 - generates 3D texture coordinates 68 * (S, T, and R).<p> 69 * <li>TEXTURE_COORDINATE_4 - generates 4D texture coordinates 70 * (S, T, R, and Q).<p> 71 * </ul> 72 * <li>Texture generation mode - defines how the texture coordinates 73 * are generated:<p> 74 * <ul> 75 * <li>OBJECT_LINEAR - texture coordinates are generated as a linear 76 * function in object coordinates. The function used is:<p> 77 * <ul> 78 * <code>g = p<sub>1</sub>x<sub>o</sub> + p<sub>2</sub>y<sub>o</sub> + p<sub>3</sub>z<sub>o</sub> + p<sub>4</sub>w<sub>o</sub></code> 79 * <p> 80 * where<br> 81 * <ul><code>g</code> is the value computed for the coordinate.<br> 82 * <code>p<sub>1</sub></code>, <code>p<sub>2</sub></code>, 83 * <code>p<sub>3</sub></code>, and <code>p<sub>4</sub></code> 84 * are the plane equation coefficients (described below).<br> 85 * x<sub>o</sub>, y<sub>o</sub>, z<sub>o</sub>, and w<sub>o</sub> are 86 * the object coordinates of the vertex.<p> 87 * </ul></ul> 88 * <li>EYE_LINEAR - texture coordinates are generated as a linear 89 * function in eye coordinates. The function used is:<p> 90 * <ul> 91 * <code>g = p<sub>1</sub>'x<sub>e</sub> + p<sub>2</sub>'y<sub>e</sub> + p<sub>3</sub>'z<sub>e</sub> + p<sub>4</sub>'w<sub>e</sub></code> 92 * <p> 93 * where<br> 94 * <ul><code>x<sub>e</sub></code>, <code>y<sub>e</sub></code>, 95 * <code>z<sub>e</sub></code>, and w<sub>e</sub></code> are the eye 96 * coordinates of the vertex.<br> 97 * <code>p<sub>1</sub>'</code>, <code>p<sub>2</sub>'</code>, 98 * <code>p<sub>3</sub>'</code>, and <code>p<sub>4</sub>'</code> 99 * are the plane equation coefficients transformed into eye 100 * coordinates.<p> 101 * </ul></ul> 102 * 103 * <li>SPHERE_MAP - texture coordinates are generated using 104 * spherical reflection mapping in eye coordinates. Used to simulate 105 * the reflected image of a spherical environment onto a polygon.<p> 106 * 107 * <li>NORMAL_MAP - texture coordinates are generated to match 108 * vertices' normals in eye coordinates. This is only available if 109 * TextureCubeMap is available. 110 * </li><p> 111 * 112 * <li>REFLECTION_MAP - texture coordinates are generated to match 113 * vertices' reflection vectors in eye coordinates. This is only available 114 * if TextureCubeMap is available. 115 * </li><p> 116 * </ul> 117 * <li>Plane equation coefficients - defines the coefficients for the 118 * plane equations used to generate the coordinates in the 119 * OBJECT_LINEAR and EYE_LINEAR texture generation modes. 120 * The coefficients define a reference plane in either object coordinates 121 * or in eye coordinates, depending on the texture generation mode. 122 * <p> 123 * The equation coefficients are set by the <code>setPlaneS</code>, 124 * <code>setPlaneT</code>, <code>setPlaneR</code>, and <code>setPlaneQ</code> 125 * methods for each of the S, T, R, and Q coordinate functions, respectively. 126 * By default the equation coefficients are set as follows:<p> 127 * <ul> 128 * plane S = (1.0, 0.0, 0.0, 0.0)<br> 129 * plane T = (0.0, 1.0, 0.0, 0.0)<br> 130 * plane R = (0.0, 0.0, 0.0, 0.0)<br> 131 * plane Q = (0.0, 0.0, 0.0, 0.0)<p> 132 * </ul></ul> 133 * Texture coordinate generation is enabled or disabled by the 134 * <code>setEnable</code> method. When enabled, the specified 135 * texture coordinate is computed according to the generating function 136 * associated with the coordinate. When disabled, subsequent vertices 137 * take the specified texture coordinate from the current set of 138 * texture coordinates.<p> 139 * 140 * @see Canvas3D#queryProperties 141 */ 142 public class TexCoordGeneration extends NodeComponent { 143 144 /** 145 * Specifies that this TexCoordGeneration object allows reading its 146 * enable flag. 147 */ 148 public static final int 149 ALLOW_ENABLE_READ = CapabilityBits.TEX_COORD_GENERATION_ALLOW_ENABLE_READ; 150 151 /** 152 * Specifies that this TexCoordGeneration object allows writing its 153 * enable flag. 154 */ 155 public static final int 156 ALLOW_ENABLE_WRITE = CapabilityBits.TEX_COORD_GENERATION_ALLOW_ENABLE_WRITE; 157 158 /** 159 * Specifies that this TexCoordGeneration object allows reading its 160 * format information. 161 */ 162 public static final int 163 ALLOW_FORMAT_READ = CapabilityBits.TEX_COORD_GENERATION_ALLOW_FORMAT_READ; 164 165 /** 166 * Specifies that this TexCoordGeneration object allows reading its 167 * mode information. 168 */ 169 public static final int 170 ALLOW_MODE_READ = CapabilityBits.TEX_COORD_GENERATION_ALLOW_MODE_READ; 171 172 /** 173 * Specifies that this TexCoordGeneration object allows reading its 174 * planeS, planeR, and planeT component information. 175 */ 176 public static final int 177 ALLOW_PLANE_READ = CapabilityBits.TEX_COORD_GENERATION_ALLOW_PLANE_READ; 178 179 /** 180 * Specifies that this TexCoordGeneration object allows writing its 181 * planeS, planeR, and planeT component information. 182 * 183 * @since Java 3D 1.3 184 */ 185 public static final int ALLOW_PLANE_WRITE = 186 CapabilityBits.TEX_COORD_GENERATION_ALLOW_PLANE_WRITE; 187 188 /** 189 * Generates texture coordinates as a linear function in 190 * object coordinates. 191 * 192 * @see #setGenMode 193 */ 194 public static final int OBJECT_LINEAR = 0; 195 /** 196 * Generates texture coordinates as a linear function in 197 * eye coordinates. 198 * 199 * @see #setGenMode 200 */ 201 public static final int EYE_LINEAR = 1; 202 /** 203 * Generates texture coordinates using a spherical reflection 204 * mapping in eye coordinates. 205 * 206 * @see #setGenMode 207 */ 208 public static final int SPHERE_MAP = 2; 209 /** 210 * Generates texture coordinates that match vertices' normals in 211 * eye coordinates. 212 * 213 * @see #setGenMode 214 * @see Canvas3D#queryProperties 215 * 216 * @since Java 3D 1.3 217 */ 218 public static final int NORMAL_MAP = 3; 219 /** 220 * Generates texture coordinates that match vertices' reflection 221 * vectors in eye coordinates. 222 * 223 * @see #setGenMode 224 * @see Canvas3D#queryProperties 225 * 226 * @since Java 3D 1.3 227 */ 228 public static final int REFLECTION_MAP = 4; 229 230 // Definitions for format 231 /** 232 * Generates 2D texture coordinates (S and T). 233 * 234 * @see #setFormat 235 */ 236 public static final int TEXTURE_COORDINATE_2 = 0; 237 /** 238 * Generates 3D texture coordinates (S, T, and R). 239 * 240 * @see #setFormat 241 */ 242 public static final int TEXTURE_COORDINATE_3 = 1; 243 /** 244 * Generates 4D texture coordinates (S, T, R, and Q). 245 * 246 * @see #setFormat 247 * 248 * @since Java 3D 1.3 249 */ 250 public static final int TEXTURE_COORDINATE_4 = 2; 251 252 // Array for setting default read capabilities 253 private static final int[] readCapabilities = { 254 ALLOW_ENABLE_READ, 255 ALLOW_FORMAT_READ, 256 ALLOW_MODE_READ, 257 ALLOW_PLANE_READ 258 }; 259 260 /** 261 * Constructs a TexCoordGeneration object with default parameters. 262 * The default values are as follows: 263 * <ul> 264 * enable flag : true<br> 265 * texture generation mode : OBJECT_LINEAR<br> 266 * format : TEXTURE_COORDINATE_2<br> 267 * plane S : (1,0,0,0)<br> 268 * plane T : (0,1,0,0)<br> 269 * plane R : (0,0,0,0)<br> 270 * plane Q : (0,0,0,0)<br> 271 * </ul> 272 */ TexCoordGeneration()273 public TexCoordGeneration() { 274 // Just use the defaults 275 // set default read capabilities 276 setDefaultReadCapabilities(readCapabilities); 277 } 278 279 /** 280 * Constructs a TexCoordGeneration object with the specified genMode and 281 * format. 282 * Defaults will be used for the rest of the state variables. 283 * @param genMode texture generation mode, one of: OBJECT_LINEAR, 284 * EYE_LINEAR, SPHERE_MAP, NORMAL_MAP, or REFLECTION_MAP 285 * @param format texture format, one of: TEXTURE_COORDINATE_2, 286 * TEXTURE_COORDINATE_3, or TEXTURE_COORDINATE_4 287 * 288 * @see Canvas3D#queryProperties 289 */ TexCoordGeneration(int genMode, int format)290 public TexCoordGeneration(int genMode, int format) { 291 // set default read capabilities 292 setDefaultReadCapabilities(readCapabilities); 293 294 ((TexCoordGenerationRetained)this.retained).initGenMode(genMode); 295 ((TexCoordGenerationRetained)this.retained).initFormat(format); 296 } 297 298 /** 299 * Constructs a TexCoordGeneration object with the specified genMode, 300 * format, and the S coordinate plane equation. 301 * Defaults will be used for the rest of the state variables. 302 * @param genMode texture generation mode, one of: OBJECT_LINEAR, 303 * EYE_LINEAR, SPHERE_MAP, NORMAL_MAP, or REFLECTION_MAP 304 * @param format texture format, one of: TEXTURE_COORDINATE_2, 305 * TEXTURE_COORDINATE_3 or TEXTURE_COORDINATE_4 306 * @param planeS plane equation for the S coordinate 307 * 308 * @see Canvas3D#queryProperties 309 */ TexCoordGeneration(int genMode, int format, Vector4f planeS)310 public TexCoordGeneration(int genMode, int format, Vector4f planeS) { 311 // set default read capabilities 312 setDefaultReadCapabilities(readCapabilities); 313 314 ((TexCoordGenerationRetained)this.retained).initGenMode(genMode); 315 ((TexCoordGenerationRetained)this.retained).initFormat(format); 316 ((TexCoordGenerationRetained)this.retained).initPlaneS(planeS); 317 } 318 319 /** 320 * Constructs a TexCoordGeneration object with the specified genMode, 321 * format, and the S and T coordinate plane equations. 322 * Defaults will be used for the rest of the state variables. 323 * @param genMode texture generation mode, one of: OBJECT_LINEAR, 324 * EYE_LINEAR, SPHERE_MAP, NORMAL_MAP, or REFLECTION_MAP 325 * @param format texture format, one of: TEXTURE_COORDINATE_2, 326 * TEXTURE_COORDINATE_3 or TEXTURE_COORDINATE_4 327 * @param planeS plane equation for the S coordinate 328 * @param planeT plane equation for the T coordinate 329 * 330 * @see Canvas3D#queryProperties 331 */ TexCoordGeneration(int genMode, int format, Vector4f planeS, Vector4f planeT)332 public TexCoordGeneration(int genMode, int format, Vector4f planeS, 333 Vector4f planeT) { 334 // set default read capabilities 335 setDefaultReadCapabilities(readCapabilities); 336 337 ((TexCoordGenerationRetained)this.retained).initGenMode(genMode); 338 ((TexCoordGenerationRetained)this.retained).initFormat(format); 339 ((TexCoordGenerationRetained)this.retained).initPlaneS(planeS); 340 ((TexCoordGenerationRetained)this.retained).initPlaneT(planeT); 341 } 342 343 /** 344 * Constructs a TexCoordGeneration object with the specified genMode, 345 * format, and the S, T, and R coordinate plane equations. 346 * @param genMode texture generation mode, one of: OBJECT_LINEAR, 347 * EYE_LINEAR, SPHERE_MAP, NORMAL_MAP, or REFLECTION_MAP 348 * @param format texture format, one of: TEXTURE_COORDINATE_2, 349 * TEXTURE_COORDINATE_3 or TEXTURE_COORDINATE_4 350 * @param planeS plane equation for the S coordinate 351 * @param planeT plane equation for the T coordinate 352 * @param planeR plane equation for the R coordinate 353 * 354 * @see Canvas3D#queryProperties 355 */ TexCoordGeneration(int genMode, int format, Vector4f planeS, Vector4f planeT, Vector4f planeR)356 public TexCoordGeneration(int genMode, int format, Vector4f planeS, 357 Vector4f planeT, Vector4f planeR) { 358 // set default read capabilities 359 setDefaultReadCapabilities(readCapabilities); 360 361 ((TexCoordGenerationRetained)this.retained).initGenMode(genMode); 362 ((TexCoordGenerationRetained)this.retained).initFormat(format); 363 ((TexCoordGenerationRetained)this.retained).initPlaneS(planeS); 364 ((TexCoordGenerationRetained)this.retained).initPlaneT(planeT); 365 ((TexCoordGenerationRetained)this.retained).initPlaneR(planeR); 366 } 367 368 /** 369 * Constructs a TexCoordGeneration object with the specified genMode, 370 * format, and the S, T, R, and Q coordinate plane equations. 371 * @param genMode texture generation mode, one of: OBJECT_LINEAR, 372 * EYE_LINEAR, SPHERE_MAP, NORMAL_MAP, or REFLECTION_MAP 373 * @param format texture format, one of: TEXTURE_COORDINATE_2, 374 * TEXTURE_COORDINATE_3 or TEXTURE_COORDINATE_4 375 * @param planeS plane equation for the S coordinate 376 * @param planeT plane equation for the T coordinate 377 * @param planeR plane equation for the R coordinate 378 * @param planeQ plane equation for the Q coordinate 379 * 380 * @see Canvas3D#queryProperties 381 * 382 * @since Java 3D 1.3 383 */ TexCoordGeneration(int genMode, int format, Vector4f planeS, Vector4f planeT, Vector4f planeR, Vector4f planeQ)384 public TexCoordGeneration(int genMode, int format, Vector4f planeS, 385 Vector4f planeT, Vector4f planeR, 386 Vector4f planeQ) { 387 // set default read capabilities 388 setDefaultReadCapabilities(readCapabilities); 389 390 ((TexCoordGenerationRetained)this.retained).initGenMode(genMode); 391 ((TexCoordGenerationRetained)this.retained).initFormat(format); 392 ((TexCoordGenerationRetained)this.retained).initPlaneS(planeS); 393 ((TexCoordGenerationRetained)this.retained).initPlaneT(planeT); 394 ((TexCoordGenerationRetained)this.retained).initPlaneR(planeR); 395 ((TexCoordGenerationRetained)this.retained).initPlaneQ(planeQ); 396 } 397 398 /** 399 * Enables or disables texture coordinate generation for this 400 * appearance component object. 401 * @param state true or false to enable or disable texture coordinate 402 * generation 403 * @exception CapabilityNotSetException if appropriate capability is 404 * not set and this object is part of live or compiled scene graph 405 */ setEnable(boolean state)406 public void setEnable(boolean state) { 407 if (isLiveOrCompiled()) 408 if(!this.getCapability(ALLOW_ENABLE_WRITE)) 409 throw new CapabilityNotSetException(J3dI18N.getString("TexCoordGeneration0")); 410 if (isLive()) 411 ((TexCoordGenerationRetained)this.retained).setEnable(state); 412 else 413 ((TexCoordGenerationRetained)this.retained).initEnable(state); 414 } 415 416 /** 417 * Retrieves the state of the texCoordGeneration enable flag. 418 * @return true if texture coordinate generation is enabled, 419 * false if texture coordinate generation is disabled 420 * @exception CapabilityNotSetException if appropriate capability is 421 * not set and this object is part of live or compiled scene graph 422 */ getEnable()423 public boolean getEnable() { 424 if (isLiveOrCompiled()) 425 if(!this.getCapability(ALLOW_ENABLE_READ)) 426 throw new CapabilityNotSetException(J3dI18N.getString("TexCoordGeneration1")); 427 return ((TexCoordGenerationRetained)this.retained).getEnable(); 428 } 429 /** 430 * Sets the TexCoordGeneration format to the specified value. 431 * @param format texture format, one of: TEXTURE_COORDINATE_2, 432 * TEXTURE_COORDINATE_3 or TEXTURE_COORDINATE_4 433 * @exception RestrictedAccessException if the method is called 434 * when this object is part of live or compiled scene graph. 435 */ setFormat(int format)436 public void setFormat(int format) { 437 checkForLiveOrCompiled(); 438 ((TexCoordGenerationRetained)this.retained).initFormat(format); 439 440 } 441 442 /** 443 * Retrieves the current TexCoordGeneration format. 444 * @return the texture format 445 * @exception CapabilityNotSetException if appropriate capability is 446 * not set and this object is part of live or compiled scene graph 447 */ getFormat()448 public int getFormat() { 449 if (isLiveOrCompiled()) 450 if(!this.getCapability(ALLOW_FORMAT_READ)) 451 throw new CapabilityNotSetException(J3dI18N.getString("TexCoordGeneration2")); 452 return ((TexCoordGenerationRetained)this.retained).getFormat(); 453 } 454 455 /** 456 * Sets the TexCoordGeneration generation mode to the specified value. 457 * @param genMode texture generation mode, one of: OBJECT_LINEAR, 458 * EYE_LINEAR, SPHERE_MAP, NORMAL_MAP, or REFLECTION_MAP. 459 * @exception RestrictedAccessException if the method is called 460 * when this object is part of live or compiled scene graph. 461 * 462 * @exception IllegalArgumentException if <code>genMode</code> is 463 * a value other than <code>OBJECT_LINEAR</code>, <code>EYE_LINEAR</code>, 464 * <code>SPHERE_MAP</code>, <code>NORMAL_MAP</code>, or 465 * <code>REFLECTION_MAP</code>. 466 * 467 * @see Canvas3D#queryProperties 468 */ setGenMode(int genMode)469 public void setGenMode(int genMode) { 470 checkForLiveOrCompiled(); 471 472 if ((genMode < OBJECT_LINEAR) || (genMode > REFLECTION_MAP)) { 473 throw new IllegalArgumentException( 474 J3dI18N.getString("TexCoordGeneration5")); 475 } 476 ((TexCoordGenerationRetained)this.retained).initGenMode(genMode); 477 } 478 479 /** 480 * Retrieves the current TexCoordGeneration generation mode. 481 * @return the texture generation mode 482 * @exception CapabilityNotSetException if appropriate capability is 483 * not set and this object is part of live or compiled scene graph 484 */ getGenMode()485 public int getGenMode() { 486 if (isLiveOrCompiled()) 487 if(!this.getCapability(ALLOW_MODE_READ)) 488 throw new CapabilityNotSetException(J3dI18N.getString("TexCoordGeneration3")); 489 return ((TexCoordGenerationRetained)this.retained).getGenMode(); 490 } 491 492 /** 493 * Sets the S coordinate plane equation. This plane equation 494 * is used to generate the S coordinate in OBJECT_LINEAR and EYE_LINEAR 495 * texture generation modes. 496 * @param planeS plane equation for the S coordinate 497 * @exception CapabilityNotSetException if appropriate capability is 498 * not set and this object is part of live or compiled scene graph 499 */ setPlaneS(Vector4f planeS)500 public void setPlaneS(Vector4f planeS) { 501 if (isLiveOrCompiled()) 502 if(!this.getCapability(ALLOW_PLANE_WRITE)) 503 throw new CapabilityNotSetException(J3dI18N.getString("TexCoordGeneration6")); 504 505 if (isLive()) 506 ((TexCoordGenerationRetained)this.retained).setPlaneS(planeS); 507 else 508 ((TexCoordGenerationRetained)this.retained).initPlaneS(planeS); 509 } 510 511 /** 512 * Retrieves a copy of the plane equation used to 513 * generate the S coordinate. 514 * @param planeS the S coordinate plane equation 515 * @exception CapabilityNotSetException if appropriate capability is 516 * not set and this object is part of live or compiled scene graph 517 */ getPlaneS(Vector4f planeS)518 public void getPlaneS(Vector4f planeS) { 519 if (isLiveOrCompiled()) 520 if(!this.getCapability(ALLOW_PLANE_READ)) 521 throw new CapabilityNotSetException(J3dI18N.getString("TexCoordGeneration4")); 522 ((TexCoordGenerationRetained)this.retained).getPlaneS(planeS); 523 } 524 525 /** 526 * Sets the T coordinate plane equation. This plane equation 527 * is used to generate the T coordinate in OBJECT_LINEAR and EYE_LINEAR 528 * texture generation modes. 529 * @param planeT plane equation for the T coordinate 530 * @exception CapabilityNotSetException if appropriate capability is 531 * not set and this object is part of live or compiled scene graph 532 */ setPlaneT(Vector4f planeT)533 public void setPlaneT(Vector4f planeT) { 534 if (isLiveOrCompiled()) 535 if(!this.getCapability(ALLOW_PLANE_WRITE)) 536 throw new CapabilityNotSetException(J3dI18N.getString("TexCoordGeneration6")); 537 538 if (isLive()) 539 ((TexCoordGenerationRetained)this.retained).setPlaneT(planeT); 540 else 541 ((TexCoordGenerationRetained)this.retained).initPlaneT(planeT); 542 } 543 544 /** 545 * Retrieves a copy of the plane equation used to 546 * generate the T coordinate. 547 * @param planeT the T coordinate plane equation 548 * @exception CapabilityNotSetException if appropriate capability is 549 * not set and this object is part of live or compiled scene graph 550 */ getPlaneT(Vector4f planeT)551 public void getPlaneT(Vector4f planeT) { 552 if (isLiveOrCompiled()) 553 if(!this.getCapability(ALLOW_PLANE_READ)) 554 throw new CapabilityNotSetException(J3dI18N.getString("TexCoordGeneration4")); 555 ((TexCoordGenerationRetained)this.retained).getPlaneT(planeT); 556 } 557 558 /** 559 * Sets the R coordinate plane equation. This plane equation 560 * is used to generate the R coordinate in OBJECT_LINEAR and EYE_LINEAR 561 * texture generation modes. 562 * @param planeR plane equation for the R coordinate 563 * @exception CapabilityNotSetException if appropriate capability is 564 * not set and this object is part of live or compiled scene graph 565 */ setPlaneR(Vector4f planeR)566 public void setPlaneR(Vector4f planeR) { 567 if (isLiveOrCompiled()) 568 if(!this.getCapability(ALLOW_PLANE_WRITE)) 569 throw new CapabilityNotSetException(J3dI18N.getString("TexCoordGeneration6")); 570 571 if (isLive()) 572 ((TexCoordGenerationRetained)this.retained).setPlaneR(planeR); 573 else 574 ((TexCoordGenerationRetained)this.retained).initPlaneR(planeR); 575 } 576 577 /** 578 * Retrieves a copy of the plane equation used to 579 * generate the R coordinate. 580 * @param planeR the R coordinate plane equation 581 * @exception CapabilityNotSetException if appropriate capability is 582 * not set and this object is part of live or compiled scene graph 583 */ getPlaneR(Vector4f planeR)584 public void getPlaneR(Vector4f planeR) { 585 if (isLiveOrCompiled()) 586 if(!this.getCapability(ALLOW_PLANE_READ)) 587 throw new CapabilityNotSetException(J3dI18N.getString("TexCoordGeneration4")); 588 ((TexCoordGenerationRetained)this.retained).getPlaneR(planeR); 589 } 590 591 /** 592 * Sets the Q coordinate plane equation. This plane equation 593 * is used to generate the Q coordinate in OBJECT_LINEAR and EYE_LINEAR 594 * texture generation modes. 595 * @param planeQ plane equation for the Q coordinate 596 * @exception CapabilityNotSetException if appropriate capability is 597 * not set and this object is part of live or compiled scene graph 598 * 599 * @since Java 3D 1.3 600 */ setPlaneQ(Vector4f planeQ)601 public void setPlaneQ(Vector4f planeQ) { 602 if (isLiveOrCompiled()) 603 if(!this.getCapability(ALLOW_PLANE_WRITE)) 604 throw new CapabilityNotSetException(J3dI18N.getString("TexCoordGeneration6")); 605 606 if (isLive()) 607 ((TexCoordGenerationRetained)this.retained).setPlaneQ(planeQ); 608 else 609 ((TexCoordGenerationRetained)this.retained).initPlaneQ(planeQ); 610 } 611 612 /** 613 * Retrieves a copy of the plane equation used to 614 * generate the Q coordinate. 615 * @param planeQ the Q coordinate plane equation 616 * @exception CapabilityNotSetException if appropriate capability is 617 * not set and this object is part of live or compiled scene graph 618 * 619 * @since Java 3D 1.3 620 */ getPlaneQ(Vector4f planeQ)621 public void getPlaneQ(Vector4f planeQ) { 622 if (isLiveOrCompiled()) 623 if(!this.getCapability(ALLOW_PLANE_READ)) 624 throw new CapabilityNotSetException(J3dI18N.getString("TexCoordGeneration4")); 625 ((TexCoordGenerationRetained)this.retained).getPlaneQ(planeQ); 626 } 627 628 /** 629 * Creates a retained mode TexCoordGenerationRetained object that this 630 * TexCoordGeneration component object will point to. 631 */ createRetained()632 void createRetained() { 633 this.retained = new TexCoordGenerationRetained(); 634 this.retained.setSource(this); 635 } 636 637 /** 638 * @deprecated replaced with cloneNodeComponent(boolean forceDuplicate) 639 */ cloneNodeComponent()640 public NodeComponent cloneNodeComponent() { 641 TexCoordGeneration tga = new TexCoordGeneration(); 642 tga.duplicateNodeComponent(this); 643 return tga; 644 } 645 646 647 /** 648 * Copies all node information from <code>originalNodeComponent</code> into 649 * the current node. This method is called from the 650 * <code>duplicateNode</code> method. This routine does 651 * the actual duplication of all "local data" (any data defined in 652 * this object). 653 * 654 * @param originalNodeComponent the original node to duplicate. 655 * @param forceDuplicate when set to <code>true</code>, causes the 656 * <code>duplicateOnCloneTree</code> flag to be ignored. When 657 * <code>false</code>, the value of each node's 658 * <code>duplicateOnCloneTree</code> variable determines whether 659 * NodeComponent data is duplicated or copied. 660 * 661 * @see Node#cloneTree 662 * @see NodeComponent#setDuplicateOnCloneTree 663 */ 664 duplicateAttributes(NodeComponent originalNodeComponent, boolean forceDuplicate)665 void duplicateAttributes(NodeComponent originalNodeComponent, 666 boolean forceDuplicate) { 667 668 super.duplicateAttributes(originalNodeComponent, forceDuplicate); 669 670 TexCoordGenerationRetained tex = (TexCoordGenerationRetained) 671 originalNodeComponent.retained; 672 TexCoordGenerationRetained rt = (TexCoordGenerationRetained) retained; 673 674 Vector4f v = new Vector4f(); 675 676 rt.initGenMode(tex.getGenMode()); 677 tex.getPlaneS(v); 678 rt.initPlaneS(v); 679 tex.getPlaneT(v); 680 rt.initPlaneT(v); 681 tex.getPlaneR(v); 682 rt.initPlaneR(v); 683 tex.getPlaneQ(v); 684 rt.initPlaneQ(v); 685 rt.initFormat(tex.getFormat()); 686 rt.initEnable(tex.getEnable()); 687 } 688 } 689