001: /*
002: * $RCSfile: Light.java,v $
003: *
004: * Copyright 1996-2008 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
006: *
007: * This code is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU General Public License version 2 only, as
009: * published by the Free Software Foundation. Sun designates this
010: * particular file as subject to the "Classpath" exception as provided
011: * by Sun in the LICENSE file that accompanied this code.
012: *
013: * This code is distributed in the hope that it will be useful, but WITHOUT
014: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
015: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
016: * version 2 for more details (a copy is included in the LICENSE file that
017: * accompanied this code).
018: *
019: * You should have received a copy of the GNU General Public License version
020: * 2 along with this work; if not, write to the Free Software Foundation,
021: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
022: *
023: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
024: * CA 95054 USA or visit www.sun.com if you need additional information or
025: * have any questions.
026: *
027: * $Revision: 1.6 $
028: * $Date: 2008/02/28 20:17:25 $
029: * $State: Exp $
030: */
031:
032: package javax.media.j3d;
033:
034: import javax.vecmath.Color3f;
035: import java.util.Enumeration;
036:
037: /**
038: * The Light leaf node is an abstract class that defines a set of
039: * parameters common to all
040: * types of light. These parameters include the light color, an enable
041: * flag, and a region of influence in which this Light node is active.
042: * A Light node also contains a list of Group nodes that specifies the
043: * hierarchical scope of this Light. If the scope list is empty,
044: * the Light node has universe scope: all nodes within the region of
045: * influence are affected by this Light node. If the scope list is
046: * non-empty, only those Leaf nodes under the Group nodes in the
047: * scope list are affected by this Light node (subject to the
048: * influencing bounds).
049: * <p>
050: * The light in a scene may come from several light sources that can
051: * be individually defined. Some of the light in a scene may
052: * come from a specific direction, known as a directional light,
053: * from a specific position, known as a point light, or
054: * from no particular direction or source as with ambient light.
055: * <p>
056: * Java 3D supports an arbitrary number of lights. However, the number
057: * of lights that can be active within the region of influence is
058: * implementation-dependent and cannot be defined here.
059: * <p>
060: * <b>Light Color</b>
061: * <p>
062: * The Java 3D lighting model approximates the way light works in
063: * the real world. Light is defined in terms of the red, green, and
064: * blue components that combine to create the light color. The
065: * three color components represent the amount of light emitted
066: * by the source.
067: * <p>
068: * Each of the three colors is represented by a
069: * floating point value that ranges from 0.0 to 1.0. A combination
070: * of the three colors such as (1.0, 1.0, 1.0), representing
071: * the red, green, and blue color values respectively, creates a white
072: * light with maximum brightness. A combination such as (0.0, 0.0,
073: * 0.0) creates no light (black). Values between the minimum and
074: * maximum values of the range produce corresponding brightness
075: * and colors. For example, a combination of (0.5, 0.5, 0.5)
076: * produces a 50% grey light. A combination of (1.0, 1.0, 0.0),
077: * red and green but no blue, produces a yellow light.
078: * <p>
079: * If a scene has multiple lights and all lights illuminate an object,
080: * the effect of the light on the object is the sum of the
081: * lights. For example, in a scene with two lights, if the first
082: * light emits (R<sub>1</sub>, G<sub>1</sub>, B<sub>1</sub>) and
083: * the second light emits (R<sub>2</sub>, G<sub>2</sub>,
084: * B<sub>2</sub>), the components are added together giving
085: * (R<sub>1</sub>+R<sub>2</sub>, G<sub>1</sub>+G<sub>2</sub>,
086: * B<sub>1</sub>+B<sub>2</sub>).
087: * If the sums of any of the color values is greater than 1.0,
088: * brighter than the maximum brightness permitted, the color value is
089: * clamped to 1.0.
090: * <p>
091: * <b>Material Colors</b>
092: * <p>
093: * In the Java 3D lighting model, the light sources have an effect
094: * on the scene only when there are object surfaces to absorb or
095: * reflect the light. Java 3D approximates an object's color
096: * by calculating the percentage of red, green, and blue light
097: * the object reflects. An object with a surface color of pure green
098: * absorbs all of the red and blue light that strikes it and
099: * reflects all of the green light. Viewing the object in a
100: * white light, the green color is reflected and you see a green
101: * object. However, if the green object is viewed in a red light,
102: * all of the red light is absorbed and the object appears black.
103: * <p>
104: * The surface of each object in the scene has
105: * certain material properties that define how light affects its
106: * appearance. The object might reflect light in various ways,
107: * depending on the object's surface type. The object
108: * might even emit its own light. The Java 3D lighting model specifies
109: * these material properties as five independent components: emitted
110: * color, ambient color, diffuse color, specular color, and shininess.
111: * All of these properties are computed independently, then added
112: * together to define how the surface of the object appears under
113: * light (an exception is Ambient light, which does not contribute
114: * to specular reflection). The material properties are defined
115: * in the Material class.
116: * <p>
117: * <b>Influencing Bounds</b>
118: * <p>
119: * Since a scene may be quite large, as large as the universe for
120: * example, it is often reasonable to limit the influence of lighting
121: * to a region that is within viewing range. There is no reason
122: * to waste all that computing power on illuminating objects that
123: * are too far away to be viewed. In Java 3D, the influencing bounds
124: * is defined by a Bounds object or a BoundingLeaf object. It should
125: * be noted that a BoundingLeaf object overrides a Bounds object,
126: * should both objects be set.
127: * <p>
128: * A Bounds object represents a convex, closed volume. Bounds
129: * defines three different types of containing
130: * volumes: an axis-aligned-box volume, a spherical volume, and a
131: * bounding polytope. A BoundingLeaf object also specifies a region
132: * of influence, but allows an application to specify a bounding
133: * region in one coordinate system (the local coordinate system of
134: * the BoundingLeaf node) other than the local coordinate
135: * system of the node that references the bounds (the Light).
136: * <p>
137: * <b>Limiting the Scope</b>
138: * <p>
139: * In addition to limiting the lighting calculations to a given
140: * region of a scene, lighting can also be limited to groups of
141: * nodes, defined by a Group object. This is known as "scoping."
142: * All nodes attached to a Group node define a <i>list of scopes</i>.
143: * Methods in the Light class permit the setting, addition, insertion,
144: * removal, and enumeration of nodes in the list of scopes.
145: * <p>
146: * <b>Two-sided Lighting of Polygons</b>
147: * <p>
148: * Java 3D performs lighting calculations for all polygons, whether
149: * they are front-facing or back-facing. Since most polygon objects
150: * are constructed with the front face in mind, the back-facing
151: * portion may not be correctly illuminated. For example, a sphere
152: * with part of the face cut away so you can see its inside.
153: * You might want to have the inside surface lit as well as the
154: * outside surface and you mught also want to define a different
155: * Material description to reduce shininess, specular color, etc.
156: * <p>
157: * For more information, see the "Face culling" and "Back-facing
158: * normal flip" descriptions in the PolygonAttributes class
159: * description.
160: * <p>
161: * <b>Turning on the Lights</b>
162: * <p>
163: * Lighting needs to be explicitly enabled with the setEnable method
164: * or with the lightOn parameter in the constructor
165: * before any of the child light sources have any effect on illuminating
166: * the scene. The child lights may also be enabled or disabled individually.
167: * <p>
168: * If lighting is not enabled, the current color of an
169: * object in the scene is simply mapped onto the object, and none of
170: * the lighting equations regarding Material properties, such as ambient
171: * color, diffuse color, specular color, and shininess, are performed.
172: * However, an object's emitted color, if specified and enabled, will
173: * still affect that object's appearance.
174: * <p>
175: * To disable lighting, call setEnable with <code>false</code> as
176: * the argument.
177: *
178: * @see Material
179: * @see Bounds
180: * @see BoundingLeaf
181: * @see Group
182: * @see PolygonAttributes
183: */
184:
185: public abstract class Light extends Leaf {
186: /**
187: * Specifies that this Light allows read access to its current state
188: * information at runtime.
189: */
190: public static final int ALLOW_STATE_READ = CapabilityBits.LIGHT_ALLOW_STATE_READ;
191:
192: /**
193: * Specifies that this Light allows write access to its current state
194: * information at runtime.
195: */
196: public static final int ALLOW_STATE_WRITE = CapabilityBits.LIGHT_ALLOW_STATE_WRITE;
197:
198: /**
199: * Specifies that this Light allows read access to its color
200: * information at runtime.
201: */
202: public static final int ALLOW_COLOR_READ = CapabilityBits.LIGHT_ALLOW_COLOR_READ;
203:
204: /**
205: * Specifies that this Light allows write access to its color
206: * information at runtime.
207: */
208: public static final int ALLOW_COLOR_WRITE = CapabilityBits.LIGHT_ALLOW_COLOR_WRITE;
209:
210: /**
211: * Specifies that this Light allows read access to its
212: * influencing bounds and bounds leaf information.
213: */
214: public static final int ALLOW_INFLUENCING_BOUNDS_READ = CapabilityBits.LIGHT_ALLOW_INFLUENCING_BOUNDS_READ;
215:
216: /**
217: * Specifies that this Light allows write access to its
218: * influencing bounds and bounds leaf information.
219: */
220: public static final int ALLOW_INFLUENCING_BOUNDS_WRITE = CapabilityBits.LIGHT_ALLOW_INFLUENCING_BOUNDS_WRITE;
221:
222: /**
223: * Specifies that this Light allows read access to its scope
224: * information at runtime.
225: */
226: public static final int ALLOW_SCOPE_READ = CapabilityBits.LIGHT_ALLOW_SCOPE_READ;
227:
228: /**
229: * Specifies that this Light allows write access to its scope
230: * information at runtime.
231: */
232: public static final int ALLOW_SCOPE_WRITE = CapabilityBits.LIGHT_ALLOW_SCOPE_WRITE;
233:
234: // Array for setting default read capabilities
235: private static final int[] readCapabilities = { ALLOW_STATE_READ,
236: ALLOW_COLOR_READ, ALLOW_INFLUENCING_BOUNDS_READ,
237: ALLOW_SCOPE_READ };
238:
239: /**
240: * Constructs a Light node with default parameters. The default
241: * values are as follows:
242: * <ul>
243: * enable flag : true<br>
244: * color : white (1,1,1)<br>
245: * scope : empty (universe scope)<br>
246: * influencing bounds : null<br>
247: * influencing bounding leaf : null<br>
248: * </ul>
249: */
250: public Light() {
251: // set default read capabilities
252: setDefaultReadCapabilities(readCapabilities);
253: }
254:
255: /**
256: * Constructs and initializes a Light node using the specified color.
257: * @param color the color of the light source
258: */
259: public Light(Color3f color) {
260: // set default read capabilities
261: setDefaultReadCapabilities(readCapabilities);
262:
263: ((LightRetained) this .retained).initColor(color);
264: }
265:
266: /**
267: * Constructs and initializes a Light node using the specified enable
268: * flag and color.
269: * @param lightOn flag indicating whether this light is on or off
270: * @param color the color of the light source
271: */
272: public Light(boolean lightOn, Color3f color) {
273: // set default read capabilities
274: setDefaultReadCapabilities(readCapabilities);
275:
276: ((LightRetained) this .retained).initEnable(lightOn);
277: ((LightRetained) this .retained).initColor(color);
278: }
279:
280: /**
281: * Turns the light on or off.
282: * @param state true or false to set light on or off
283: * @exception CapabilityNotSetException if appropriate capability is
284: * not set and this object is part of live or compiled scene graph
285: */
286: public void setEnable(boolean state) {
287: if (isLiveOrCompiled())
288: if (!this .getCapability(ALLOW_STATE_WRITE))
289: throw new CapabilityNotSetException(J3dI18N
290: .getString("Light0"));
291:
292: if (isLive())
293: ((LightRetained) this .retained).setEnable(state);
294: else
295: ((LightRetained) this .retained).initEnable(state);
296: }
297:
298: /**
299: * Retrieves this Light's current state (on/off).
300: * @return this node's current state (on/off)
301: * @exception CapabilityNotSetException if appropriate capability is
302: * not set and this object is part of live or compiled scene graph
303: */
304: public boolean getEnable() {
305: if (isLiveOrCompiled())
306: if (!this .getCapability(ALLOW_STATE_READ))
307: throw new CapabilityNotSetException(J3dI18N
308: .getString("Light1"));
309:
310: return ((LightRetained) this .retained).getEnable();
311: }
312:
313: /**
314: * Sets the Light's current color.
315: * @param color the value of this node's new color
316: * @exception CapabilityNotSetException if appropriate capability is
317: * not set and this object is part of live or compiled scene graph
318: */
319: public void setColor(Color3f color) {
320: if (isLiveOrCompiled())
321: if (!this .getCapability(ALLOW_COLOR_WRITE))
322: throw new CapabilityNotSetException(J3dI18N
323: .getString("Light2"));
324:
325: if (isLive())
326: ((LightRetained) this .retained).setColor(color);
327: else
328: ((LightRetained) this .retained).initColor(color);
329: }
330:
331: /**
332: * Gets this Light's current color and places it in the parameter specified.
333: * @param color the vector that will receive this node's color
334: * @exception CapabilityNotSetException if appropriate capability is
335: * not set and this object is part of live or compiled scene graph
336: */
337: public void getColor(Color3f color) {
338: if (isLiveOrCompiled())
339: if (!this .getCapability(ALLOW_COLOR_READ))
340: throw new CapabilityNotSetException(J3dI18N
341: .getString("Light3"));
342:
343: ((LightRetained) this .retained).getColor(color);
344: }
345:
346: /**
347: * Replaces the node at the specified index in this Light node's
348: * list of scopes with the specified Group node.
349: * By default, Light nodes are scoped only by their influencing
350: * bounds. This allows them to be further scoped by a list of
351: * nodes in the hierarchy.
352: * @param scope the Group node to be stored at the specified index.
353: * @param index the index of the Group node to be replaced.
354: * @exception CapabilityNotSetException if appropriate capability is
355: * not set and this object is part of live or compiled scene graph
356: * @exception RestrictedAccessException if the specified group node
357: * is part of a compiled scene graph
358: */
359: public void setScope(Group scope, int index) {
360: if (isLiveOrCompiled())
361: if (!this .getCapability(ALLOW_SCOPE_WRITE))
362: throw new CapabilityNotSetException(J3dI18N
363: .getString("Light4"));
364:
365: if (isLive())
366: ((LightRetained) this .retained).setScope(scope, index);
367: else
368: ((LightRetained) this .retained).initScope(scope, index);
369: }
370:
371: /**
372: * Retrieves the Group node at the specified index from this Light node's
373: * list of scopes.
374: * @param index the index of the Group node to be returned.
375: * @return the Group node at the specified index.
376: * @exception CapabilityNotSetException if appropriate capability is
377: * not set and this object is part of live or compiled scene graph
378: */
379: public Group getScope(int index) {
380: if (isLiveOrCompiled())
381: if (!this .getCapability(ALLOW_SCOPE_READ))
382: throw new CapabilityNotSetException(J3dI18N
383: .getString("Light5"));
384:
385: return ((LightRetained) this .retained).getScope(index);
386: }
387:
388: /**
389: * Inserts the specified Group node into this Light node's
390: * list of scopes at the specified index.
391: * By default, Light nodes are scoped only by their influencing
392: * bounds. This allows them to be further scoped by a list of
393: * nodes in the hierarchy.
394: * @param scope the Group node to be inserted at the specified index.
395: * @param index the index at which the Group node is inserted.
396: * @exception CapabilityNotSetException if appropriate capability is
397: * not set and this object is part of live or compiled scene graph
398: * @exception RestrictedAccessException if the specified group node
399: * is part of a compiled scene graph
400: */
401: public void insertScope(Group scope, int index) {
402: if (isLiveOrCompiled())
403: if (!this .getCapability(ALLOW_SCOPE_WRITE))
404: throw new CapabilityNotSetException(J3dI18N
405: .getString("Light6"));
406:
407: if (isLive())
408: ((LightRetained) this .retained).insertScope(scope, index);
409: else
410: ((LightRetained) this .retained).initInsertScope(scope,
411: index);
412: }
413:
414: /**
415: * Removes the node at the specified index from this Light node's
416: * list of scopes. If this operation causes the list of scopes to
417: * become empty, then this Light will have universe scope: all nodes
418: * within the region of influence will be affected by this Light node.
419: * @param index the index of the Group node to be removed.
420: * @exception CapabilityNotSetException if appropriate capability is
421: * not set and this object is part of live or compiled scene graph
422: * @exception RestrictedAccessException if the group node at the
423: * specified index is part of a compiled scene graph
424: */
425: public void removeScope(int index) {
426: if (isLiveOrCompiled())
427: if (!this .getCapability(ALLOW_SCOPE_WRITE))
428: throw new CapabilityNotSetException(J3dI18N
429: .getString("Light7"));
430:
431: if (isLive())
432: ((LightRetained) this .retained).removeScope(index);
433: else
434: ((LightRetained) this .retained).initRemoveScope(index);
435: }
436:
437: /**
438: * Returns an enumeration of this Light node's list of scopes.
439: * @return an Enumeration object containing all nodes in this Light node's
440: * list of scopes.
441: * @exception CapabilityNotSetException if appropriate capability is
442: * not set and this object is part of live or compiled scene graph
443: */
444: public Enumeration getAllScopes() {
445: if (isLiveOrCompiled())
446: if (!this .getCapability(ALLOW_SCOPE_READ))
447: throw new CapabilityNotSetException(J3dI18N
448: .getString("Light8"));
449:
450: return (Enumeration) ((LightRetained) this .retained)
451: .getAllScopes();
452: }
453:
454: /**
455: * Appends the specified Group node to this Light node's list of scopes.
456: * By default, Light nodes are scoped only by their influencing
457: * bounds. This allows them to be further scoped by a list of
458: * nodes in the hierarchy.
459: * @param scope the Group node to be appended.
460: * @exception CapabilityNotSetException if appropriate capability is
461: * not set and this object is part of live or compiled scene graph
462: * @exception RestrictedAccessException if the specified group node
463: * is part of a compiled scene graph
464: */
465: public void addScope(Group scope) {
466: if (isLiveOrCompiled())
467: if (!this .getCapability(ALLOW_SCOPE_WRITE))
468: throw new CapabilityNotSetException(J3dI18N
469: .getString("Light9"));
470:
471: if (isLive())
472: ((LightRetained) this .retained).addScope(scope);
473: else
474: ((LightRetained) this .retained).initAddScope(scope);
475: }
476:
477: /**
478: * Returns the number of nodes in this Light node's list of scopes.
479: * If this number is 0, then the list of scopes is empty and this
480: * Light node has universe scope: all nodes within the region of
481: * influence are affected by this Light node.
482: * @return the number of nodes in this Light node's list of scopes.
483: * @exception CapabilityNotSetException if appropriate capability is
484: * not set and this object is part of live or compiled scene graph
485: */
486: public int numScopes() {
487: if (isLiveOrCompiled())
488: if (!this .getCapability(ALLOW_SCOPE_READ))
489: throw new CapabilityNotSetException(J3dI18N
490: .getString("Light8"));
491:
492: return ((LightRetained) this .retained).numScopes();
493: }
494:
495: /**
496: * Retrieves the index of the specified Group node in this
497: * Light node's list of scopes.
498: *
499: * @param scope the Group node to be looked up.
500: * @return the index of the specified Group node;
501: * returns -1 if the object is not in the list.
502: * @exception CapabilityNotSetException if appropriate capability is
503: * not set and this object is part of live or compiled scene graph
504: *
505: * @since Java 3D 1.3
506: */
507: public int indexOfScope(Group scope) {
508: if (isLiveOrCompiled())
509: if (!this .getCapability(ALLOW_SCOPE_READ))
510: throw new CapabilityNotSetException(J3dI18N
511: .getString("Light8"));
512:
513: return ((LightRetained) this .retained).indexOfScope(scope);
514: }
515:
516: /**
517: * Removes the specified Group node from this Light
518: * node's list of scopes. If the specified object is not in the
519: * list, the list is not modified. If this operation causes the
520: * list of scopes to become empty, then this Light
521: * will have universe scope: all nodes within the region of
522: * influence will be affected by this Light node.
523: *
524: * @param scope the Group node to be removed.
525: * @exception CapabilityNotSetException if appropriate capability is
526: * not set and this object is part of live or compiled scene graph
527: * @exception RestrictedAccessException if the specified group node
528: * is part of a compiled scene graph
529: *
530: * @since Java 3D 1.3
531: */
532: public void removeScope(Group scope) {
533: if (isLiveOrCompiled())
534: if (!this .getCapability(ALLOW_SCOPE_WRITE))
535: throw new CapabilityNotSetException(J3dI18N
536: .getString("Light7"));
537:
538: if (isLive())
539: ((LightRetained) this .retained).removeScope(scope);
540: else
541: ((LightRetained) this .retained).initRemoveScope(scope);
542: }
543:
544: /**
545: * Removes all Group nodes from this Light node's
546: * list of scopes. The Light node will then have
547: * universe scope: all nodes within the region of influence will
548: * be affected by this Light node.
549: *
550: * @exception CapabilityNotSetException if appropriate capability is
551: * not set and this object is part of live or compiled scene graph
552: * @exception RestrictedAccessException if any group node in this
553: * node's list of scopes is part of a compiled scene graph
554: *
555: * @since Java 3D 1.3
556: */
557: public void removeAllScopes() {
558: if (isLiveOrCompiled())
559: if (!this .getCapability(ALLOW_SCOPE_WRITE))
560: throw new CapabilityNotSetException(J3dI18N
561: .getString("Light7"));
562:
563: if (isLive())
564: ((LightRetained) this .retained).removeAllScopes();
565: else
566: ((LightRetained) this .retained).initRemoveAllScopes();
567: }
568:
569: /**
570: * Sets the Light's influencing region to the specified bounds.
571: * This is used when the influencing bounding leaf is set to null.
572: * @param region the bounds that contains the Light's new influencing
573: * region.
574: * @exception CapabilityNotSetException if appropriate capability is
575: * not set and this object is part of live or compiled scene graph
576: */
577: public void setInfluencingBounds(Bounds region) {
578: if (isLiveOrCompiled())
579: if (!this .getCapability(ALLOW_INFLUENCING_BOUNDS_WRITE))
580: throw new CapabilityNotSetException(J3dI18N
581: .getString("Light11"));
582:
583: if (isLive())
584: ((LightRetained) this .retained)
585: .setInfluencingBounds(region);
586: else
587: ((LightRetained) this .retained)
588: .initInfluencingBounds(region);
589: }
590:
591: /**
592: * Retrieves the Light node's influencing bounds.
593: * @return this Light's influencing bounds information
594: * @exception CapabilityNotSetException if appropriate capability is
595: * not set and this object is part of live or compiled scene graph
596: */
597: public Bounds getInfluencingBounds() {
598: if (isLiveOrCompiled())
599: if (!this .getCapability(ALLOW_INFLUENCING_BOUNDS_READ))
600: throw new CapabilityNotSetException(J3dI18N
601: .getString("Light12"));
602:
603: return ((LightRetained) this .retained).getInfluencingBounds();
604: }
605:
606: /**
607: * Sets the Light's influencing region to the specified bounding leaf.
608: * When set to a value other than null, this overrides the influencing
609: * bounds object.
610: * @param region the bounding leaf node used to specify the Light
611: * node's new influencing region.
612: * @exception CapabilityNotSetException if appropriate capability is
613: * not set and this object is part of live or compiled scene graph
614: */
615: public void setInfluencingBoundingLeaf(BoundingLeaf region) {
616: if (isLiveOrCompiled())
617: if (!this .getCapability(ALLOW_INFLUENCING_BOUNDS_WRITE))
618: throw new CapabilityNotSetException(J3dI18N
619: .getString("Light11"));
620:
621: if (isLive())
622: ((LightRetained) this .retained)
623: .setInfluencingBoundingLeaf(region);
624: else
625: ((LightRetained) this .retained)
626: .initInfluencingBoundingLeaf(region);
627: }
628:
629: /**
630: * Retrieves the Light node's influencing bounding leaf.
631: * @return this Light's influencing bounding leaf information
632: * @exception CapabilityNotSetException if appropriate capability is
633: * not set and this object is part of live or compiled scene graph
634: */
635: public BoundingLeaf getInfluencingBoundingLeaf() {
636: if (isLiveOrCompiled())
637: if (!this .getCapability(ALLOW_INFLUENCING_BOUNDS_READ))
638: throw new CapabilityNotSetException(J3dI18N
639: .getString("Light12"));
640:
641: return ((LightRetained) this .retained)
642: .getInfluencingBoundingLeaf();
643: }
644:
645: /**
646: * Copies all Light information from
647: * <code>originalNode</code> into
648: * the current node. This method is called from the
649: * <code>cloneNode</code> method which is, in turn, called by the
650: * <code>cloneTree</code> method.<P>
651: *
652: * @param originalNode the original node to duplicate.
653: * @param forceDuplicate when set to <code>true</code>, causes the
654: * <code>duplicateOnCloneTree</code> flag to be ignored. When
655: * <code>false</code>, the value of each node's
656: * <code>duplicateOnCloneTree</code> variable determines whether
657: * NodeComponent data is duplicated or copied.
658: *
659: * @exception RestrictedAccessException if this object is part of a live
660: * or compiled scenegraph.
661: *
662: * @see Node#duplicateNode
663: * @see Node#cloneTree
664: * @see NodeComponent#setDuplicateOnCloneTree
665: */
666: void duplicateAttributes(Node originalNode, boolean forceDuplicate) {
667: super .duplicateAttributes(originalNode, forceDuplicate);
668:
669: LightRetained attr = (LightRetained) originalNode.retained;
670: LightRetained rt = (LightRetained) retained;
671:
672: Color3f c = new Color3f();
673: attr.getColor(c);
674: rt.initColor(c);
675: rt.initInfluencingBounds(attr.getInfluencingBounds());
676:
677: Enumeration elm = attr.getAllScopes();
678: while (elm.hasMoreElements()) {
679: // this reference will set correctly in updateNodeReferences() callback
680: rt.initAddScope((Group) elm.nextElement());
681: }
682:
683: // this reference will set correctly in updateNodeReferences() callback
684: rt.initInfluencingBoundingLeaf(attr
685: .getInfluencingBoundingLeaf());
686:
687: rt.initEnable(attr.getEnable());
688: }
689:
690: /**
691: * Callback used to allow a node to check if any scene graph objects
692: * referenced
693: * by that node have been duplicated via a call to <code>cloneTree</code>.
694: * This method is called by <code>cloneTree</code> after all nodes in
695: * the sub-graph have been duplicated. The cloned Leaf node's method
696: * will be called and the Leaf node can then look up any object references
697: * by using the <code>getNewObjectReference</code> method found in the
698: * <code>NodeReferenceTable</code> object. If a match is found, a
699: * reference to the corresponding object in the newly cloned sub-graph
700: * is returned. If no corresponding reference is found, either a
701: * DanglingReferenceException is thrown or a reference to the original
702: * object is returned depending on the value of the
703: * <code>allowDanglingReferences</code> parameter passed in the
704: * <code>cloneTree</code> call.
705: * <p>
706: * NOTE: Applications should <i>not</i> call this method directly.
707: * It should only be called by the cloneTree method.
708: *
709: * @param referenceTable a NodeReferenceTableObject that contains the
710: * <code>getNewObjectReference</code> method needed to search for
711: * new object instances.
712: * @see NodeReferenceTable
713: * @see Node#cloneTree
714: * @see DanglingReferenceException
715: */
716: public void updateNodeReferences(NodeReferenceTable referenceTable) {
717:
718: LightRetained rt = (LightRetained) retained;
719: BoundingLeaf bl = rt.getInfluencingBoundingLeaf();
720:
721: if (bl != null) {
722: Object o = referenceTable.getNewObjectReference(bl);
723: rt.initInfluencingBoundingLeaf((BoundingLeaf) o);
724: }
725:
726: int num = rt.numScopes();
727: for (int i = 0; i < num; i++) {
728: rt.initScope((Group) referenceTable
729: .getNewObjectReference(rt.getScope(i)), i);
730: }
731: }
732:
733: }
|