Source Code Cross Referenced for Shape3D.java in  » 6.0-JDK-Modules » java-3d » javax » media » j3d » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » 6.0 JDK Modules » java 3d » javax.media.j3d 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $RCSfile: Shape3D.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:30 $
029:         * $State: Exp $
030:         */
031:
032:        package javax.media.j3d;
033:
034:        import java.util.Enumeration;
035:
036:        /**
037:         * The Shape3D leaf node specifies all geometric objects.  It contains
038:         * a list of one or more Geometry component objects and a single
039:         * Appearance component object.  The geometry objects define the shape
040:         * node's geometric data.  The appearance object specifies that
041:         * object's appearance attributes, including color, material, texture,
042:         * and so on.
043:         * <p>
044:         * The list of geometry objects must all be of the same equivalence
045:         * class, that is, the same basic type of primitive.  For subclasses
046:         * of GeometryArray, all point objects are equivalent, all line
047:         * objects are equivalent, and all polygon objects are equivalent.
048:         * For other subclasses of Geometry, only objects of the same
049:         * subclass are equivalent.  The equivalence classes are as follows:
050:         * <ul>
051:         * <li>GeometryArray (point): [Indexed]PointArray</li>
052:         * <li>GeometryArray (line): [Indexed]{LineArray, LineStripArray}</li>
053:         * <li>GeometryArray (polygon): [Indexed]{TriangleArray, TriangleStripArray,
054:         * TriangleFanArray, QuadArray}</li>
055:         * <li>CompressedGeometry</li>
056:         * <li>Raster</li>
057:         * <li>Text3D</li>
058:         * </ul>
059:         * <p>
060:         * When Shape3D is used with multiple geometry components, Java 3D may
061:         * choose to use individual geometry bounds instead of the shape's
062:         * bounds for region of influence operations, such as lighting.
063:         * For example, the individual characters of a Text3D shape object
064:         * may be rendered with a different light set.
065:         */
066:
067:        public class Shape3D extends Leaf {
068:
069:            /**
070:             * Id used in the compile optimization to determine
071:             * how to get to the geometry in the case of read
072:             * or picking ..
073:             */
074:            int id;
075:
076:            /**
077:             * Specifies that the node allows read access to its geometry information.
078:             */
079:            public static final int ALLOW_GEOMETRY_READ = CapabilityBits.SHAPE3D_ALLOW_GEOMETRY_READ;
080:
081:            /**
082:             * Specifies that the node allows write access to its geometry information.
083:             */
084:            public static final int ALLOW_GEOMETRY_WRITE = CapabilityBits.SHAPE3D_ALLOW_GEOMETRY_WRITE;
085:
086:            /**
087:             * Specifies that the node allows read access to its appearance
088:             * information.
089:             */
090:            public static final int ALLOW_APPEARANCE_READ = CapabilityBits.SHAPE3D_ALLOW_APPEARANCE_READ;
091:
092:            /**
093:             * Specifies that the node allows write access to its appearance
094:             * information.
095:             */
096:            public static final int ALLOW_APPEARANCE_WRITE = CapabilityBits.SHAPE3D_ALLOW_APPEARANCE_WRITE;
097:
098:            /**
099:             * Specifies that the node allows reading its collision Bounds
100:             */
101:            public static final int ALLOW_COLLISION_BOUNDS_READ = CapabilityBits.SHAPE3D_ALLOW_COLLISION_BOUNDS_READ;
102:
103:            /**
104:             * Specifies the node allows writing its collision Bounds
105:             */
106:            public static final int ALLOW_COLLISION_BOUNDS_WRITE = CapabilityBits.SHAPE3D_ALLOW_COLLISION_BOUNDS_WRITE;
107:
108:            /**
109:             * Specifies that this node allows reading its appearance override
110:             * enable flag.
111:             *
112:             * @since Java 3D 1.2
113:             */
114:            public static final int ALLOW_APPEARANCE_OVERRIDE_READ = CapabilityBits.SHAPE3D_ALLOW_APPEARANCE_OVERRIDE_READ;
115:
116:            /**
117:             * Specifies that this node allows writing its appearance override
118:             * enable flag.
119:             *
120:             * @since Java 3D 1.2
121:             */
122:            public static final int ALLOW_APPEARANCE_OVERRIDE_WRITE = CapabilityBits.SHAPE3D_ALLOW_APPEARANCE_OVERRIDE_WRITE;
123:
124:            // Array for setting default read capabilities
125:            private static final int[] readCapabilities = {
126:                    ALLOW_GEOMETRY_READ, ALLOW_APPEARANCE_READ,
127:                    ALLOW_COLLISION_BOUNDS_READ, ALLOW_APPEARANCE_OVERRIDE_READ };
128:
129:            /**
130:             * Constructs a Shape3D node with default parameters.  The default
131:             * values are as follows:
132:             * <ul>
133:             * appearance : null<br>
134:             * geometry : { null }<br>
135:             * collision bounds : null<br>
136:             * appearance override enable : false<br>
137:             * </ul>
138:             * The list of geometry components is initialized with a null
139:             * geometry component as the single element with an index of 0.
140:             * A null geometry component specifies
141:             * that no geometry is drawn. A null appearance component specifies
142:             * that default values are used for all appearance attributes.
143:             */
144:            public Shape3D() {
145:                // set default read capabilities
146:                setDefaultReadCapabilities(readCapabilities);
147:            }
148:
149:            /**
150:             * Constructs and initializes a Shape3D node with the specified
151:             * geometry component and a null appearance component.
152:             * The list of geometry components is initialized with the
153:             * specified geometry component as the single element with an
154:             * index of 0.
155:             * A null appearance component specifies that default values are
156:             * used for all appearance attributes.
157:             * @param geometry the geometry component with which to initialize
158:             * this shape node.
159:             */
160:            public Shape3D(Geometry geometry) {
161:                // set default read capabilities
162:                setDefaultReadCapabilities(readCapabilities);
163:
164:                ((Shape3DRetained) retained).setGeometry(geometry, 0);
165:            }
166:
167:            /**
168:             * Constructs and initializes a Shape3D node with the specified
169:             * geometry and appearance components.
170:             * The list of geometry components is initialized with the
171:             * specified geometry component as the single element with an
172:             * index of 0.
173:             * @param geometry the geometry component with which to initialize
174:             * this shape node
175:             * @param appearance the appearance component of the shape node
176:             */
177:            public Shape3D(Geometry geometry, Appearance appearance) {
178:                // set default read capabilities
179:                setDefaultReadCapabilities(readCapabilities);
180:
181:                ((Shape3DRetained) retained).setGeometry(geometry, 0);
182:                ((Shape3DRetained) retained).setAppearance(appearance);
183:            }
184:
185:            /**
186:             * Creates the retained mode Shape3DRetained object that this
187:             * Shape3D object will point to.
188:             */
189:            void createRetained() {
190:                retained = new Shape3DRetained();
191:                retained.setSource(this );
192:            }
193:
194:            /**
195:             * Sets the collision bounds of a node.
196:             * @param bounds the collision bounding object for a node
197:             * @exception CapabilityNotSetException if appropriate capability is
198:             * not set and this object is part of live or compiled scene graph
199:             */
200:            public void setCollisionBounds(Bounds bounds) {
201:
202:                if (isLiveOrCompiled())
203:                    if (!this .getCapability(ALLOW_COLLISION_BOUNDS_WRITE))
204:                        throw new CapabilityNotSetException(J3dI18N
205:                                .getString("Shape3D0"));
206:
207:                ((Shape3DRetained) this .retained).setCollisionBounds(bounds);
208:            }
209:
210:            /**
211:             * Returns the collision bounding object of this node.
212:             * @return the node's collision bounding object
213:             * @exception CapabilityNotSetException if appropriate capability is
214:             * not set and this object is part of live or compiled scene graph
215:             */
216:            public Bounds getCollisionBounds() {
217:
218:                if (isLiveOrCompiled())
219:                    if (!this .getCapability(ALLOW_COLLISION_BOUNDS_READ))
220:                        throw new CapabilityNotSetException(J3dI18N
221:                                .getString("Shape3D1"));
222:
223:                return ((Shape3DRetained) this .retained).getCollisionBounds(id);
224:            }
225:
226:            /**
227:             * Replaces the geometry component at index 0 in this Shape3D node's
228:             * list of geometry components with the specified geometry component.
229:             * If there are existing geometry components in the list (besides
230:             * the one being replaced), the new geometry component must be of
231:             * the same equivalence class (point, line, polygon, CompressedGeometry,
232:             * Raster, Text3D) as the others.
233:             * @param geometry the geometry component to be stored at index 0.
234:             * @exception IllegalArgumentException if the new geometry
235:             * component is not of of the same equivalence class as the
236:             * existing geometry components.
237:             * @exception CapabilityNotSetException if appropriate capability is
238:             * not set and this object is part of live or compiled scene graph
239:             */
240:            public void setGeometry(Geometry geometry) {
241:
242:                if (isLiveOrCompiled())
243:                    if (!this .getCapability(ALLOW_GEOMETRY_WRITE))
244:                        throw new CapabilityNotSetException(J3dI18N
245:                                .getString("Shape3D2"));
246:
247:                ((Shape3DRetained) retained).setGeometry(geometry, 0);
248:            }
249:
250:            /**
251:             * Retrieves the geometry component at index 0 from this Shape3D node's
252:             * list of geometry components.
253:             * @return the geometry component at index 0.
254:             * @exception CapabilityNotSetException if appropriate capability is
255:             * not set and this object is part of live or compiled scene graph
256:             */
257:            public Geometry getGeometry() {
258:
259:                if (isLiveOrCompiled())
260:                    if (!this .getCapability(ALLOW_GEOMETRY_READ))
261:                        throw new CapabilityNotSetException(J3dI18N
262:                                .getString("Shape3D3"));
263:
264:                return ((Shape3DRetained) retained).getGeometry(0, id);
265:            }
266:
267:            /**
268:             * Replaces the geometry component at the specified index in this
269:             * Shape3D node's list of geometry components with the specified
270:             * geometry component.
271:             * If there are existing geometry components in the list (besides
272:             * the one being replaced), the new geometry component must be of
273:             * the same equivalence class (point, line, polygon, CompressedGeometry,
274:             * Raster, Text3D) as the others.
275:             * @param geometry the geometry component to be stored at the
276:             * specified index.
277:             * @param index the index of the geometry component to be replaced.
278:             * @exception IllegalArgumentException if the new geometry
279:             * component is not of of the same equivalence class as the
280:             * existing geometry components.
281:             * @exception CapabilityNotSetException if appropriate capability is
282:             * not set and this object is part of live or compiled scene graph
283:             *
284:             * @since Java 3D 1.2
285:             */
286:            public void setGeometry(Geometry geometry, int index) {
287:
288:                if (isLiveOrCompiled())
289:                    if (!this .getCapability(ALLOW_GEOMETRY_WRITE))
290:                        throw new CapabilityNotSetException(J3dI18N
291:                                .getString("Shape3D2"));
292:
293:                ((Shape3DRetained) retained).setGeometry(geometry, index);
294:            }
295:
296:            /**
297:             * Retrieves the geometry component at the specified index from
298:             * this Shape3D node's list of geometry components.
299:             * @param index the index of the geometry component to be returned.
300:             * @return the geometry component at the specified index.
301:             * @exception CapabilityNotSetException if appropriate capability is
302:             * not set and this object is part of live or compiled scene graph
303:             *
304:             * @since Java 3D 1.2
305:             */
306:            public Geometry getGeometry(int index) {
307:
308:                if (isLiveOrCompiled())
309:                    if (!this .getCapability(ALLOW_GEOMETRY_READ))
310:                        throw new CapabilityNotSetException(J3dI18N
311:                                .getString("Shape3D3"));
312:
313:                return ((Shape3DRetained) retained).getGeometry(index, id);
314:            }
315:
316:            /**
317:             * Inserts the specified geometry component into this Shape3D
318:             * node's list of geometry components at the specified index.
319:             * If there are existing geometry components in the list, the new
320:             * geometry component must be of the same equivalence class
321:             * (point, line, polygon, CompressedGeometry, Raster, Text3D) as
322:             * the others.
323:             * @param geometry the geometry component to be inserted at the
324:             * specified index.
325:             * @param index the index at which the geometry component is inserted.
326:             * @exception IllegalArgumentException if the new geometry
327:             * component is not of of the same equivalence class as the
328:             * existing geometry components.
329:             * @exception CapabilityNotSetException if appropriate capability is
330:             * not set and this object is part of live or compiled scene graph
331:             *
332:             * @since Java 3D 1.2
333:             */
334:            public void insertGeometry(Geometry geometry, int index) {
335:
336:                if (isLiveOrCompiled())
337:                    if (!this .getCapability(ALLOW_GEOMETRY_WRITE))
338:                        throw new CapabilityNotSetException(J3dI18N
339:                                .getString("Shape3D2"));
340:
341:                ((Shape3DRetained) retained).insertGeometry(geometry, index);
342:            }
343:
344:            /**
345:             * Removes the geometry component at the specified index from
346:             * this Shape3D node's list of geometry components.
347:             * @param index the index of the geometry component to be removed.
348:             * @exception CapabilityNotSetException if appropriate capability is
349:             * not set and this object is part of live or compiled scene graph
350:             *
351:             * @since Java 3D 1.2
352:             */
353:            public void removeGeometry(int index) {
354:
355:                if (isLiveOrCompiled())
356:                    if (!this .getCapability(ALLOW_GEOMETRY_WRITE))
357:                        throw new CapabilityNotSetException(J3dI18N
358:                                .getString("Shape3D2"));
359:
360:                ((Shape3DRetained) retained).removeGeometry(index);
361:            }
362:
363:            /**
364:             * Returns an enumeration of this Shape3D node's list of geometry
365:             * components.
366:             * @return an Enumeration object containing all geometry components in
367:             * this Shape3D node's list of geometry components.
368:             * @exception CapabilityNotSetException if appropriate capability is
369:             * not set and this object is part of live or compiled scene graph
370:             *
371:             * @since Java 3D 1.2
372:             */
373:            public Enumeration getAllGeometries() {
374:
375:                if (isLiveOrCompiled())
376:                    if (!this .getCapability(ALLOW_GEOMETRY_READ))
377:                        throw new CapabilityNotSetException(J3dI18N
378:                                .getString("Shape3D3"));
379:
380:                return ((Shape3DRetained) retained).getAllGeometries(id);
381:            }
382:
383:            /**
384:             * Appends the specified geometry component to this Shape3D
385:             * node's list of geometry components.
386:             * If there are existing geometry components in the list, the new
387:             * geometry component must be of the same equivalence class
388:             * (point, line, polygon, CompressedGeometry, Raster, Text3D) as
389:             * the others.
390:             * @param geometry the geometry component to be appended.
391:             * @exception IllegalArgumentException if the new geometry
392:             * component is not of of the same equivalence class as the
393:             * existing geometry components.
394:             * @exception CapabilityNotSetException if appropriate capability is
395:             * not set and this object is part of live or compiled scene graph
396:             *
397:             * @since Java 3D 1.2
398:             */
399:            public void addGeometry(Geometry geometry) {
400:
401:                if (isLiveOrCompiled())
402:                    if (!this .getCapability(ALLOW_GEOMETRY_WRITE))
403:                        throw new CapabilityNotSetException(J3dI18N
404:                                .getString("Shape3D2"));
405:
406:                ((Shape3DRetained) retained).addGeometry(geometry);
407:            }
408:
409:            /**
410:             * Returns the number of geometry components in this Shape3D node's
411:             * list of geometry components.
412:             * @return the number of geometry components in this Shape3D node's
413:             * list of geometry components.
414:             * @exception CapabilityNotSetException if appropriate capability is
415:             * not set and this object is part of live or compiled scene graph
416:             *
417:             * @since Java 3D 1.2
418:             */
419:            public int numGeometries() {
420:
421:                if (isLiveOrCompiled())
422:                    if (!this .getCapability(ALLOW_GEOMETRY_READ))
423:                        throw new CapabilityNotSetException(J3dI18N
424:                                .getString("Shape3D3"));
425:                return ((Shape3DRetained) retained).numGeometries(id);
426:            }
427:
428:            /**
429:             * Retrieves the index of the specified geometry component in
430:             * this Shape3D node's list of geometry components.
431:             *
432:             * @param geometry the geometry component to be looked up.
433:             * @return the index of the specified geometry component;
434:             * returns -1 if the object is not in the list.
435:             * @exception CapabilityNotSetException if appropriate capability is
436:             * not set and this object is part of live or compiled scene graph
437:             *
438:             * @since Java 3D 1.3
439:             */
440:            public int indexOfGeometry(Geometry geometry) {
441:
442:                if (isLiveOrCompiled())
443:                    if (!this .getCapability(ALLOW_GEOMETRY_READ))
444:                        throw new CapabilityNotSetException(J3dI18N
445:                                .getString("Shape3D3"));
446:                return ((Shape3DRetained) retained).indexOfGeometry(geometry);
447:            }
448:
449:            /**
450:             * Removes the specified geometry component from this
451:             * Shape3D node's list of geometry components.
452:             * If the specified object is not in the list, the list is not modified.
453:             *
454:             * @param geometry the geometry component to be removed.
455:             * @exception CapabilityNotSetException if appropriate capability is
456:             * not set and this object is part of live or compiled scene graph
457:             *
458:             * @since Java 3D 1.3
459:             */
460:            public void removeGeometry(Geometry geometry) {
461:
462:                if (isLiveOrCompiled())
463:                    if (!this .getCapability(ALLOW_GEOMETRY_WRITE))
464:                        throw new CapabilityNotSetException(J3dI18N
465:                                .getString("Shape3D2"));
466:                ((Shape3DRetained) retained).removeGeometry(geometry);
467:            }
468:
469:            /**
470:             * Removes all geometry components from this Shape3D node.
471:             *
472:             * @exception CapabilityNotSetException if appropriate capability is
473:             * not set and this object is part of live or compiled scene graph
474:             *
475:             * @since Java 3D 1.3
476:             */
477:            public void removeAllGeometries() {
478:
479:                if (isLiveOrCompiled())
480:                    if (!this .getCapability(ALLOW_GEOMETRY_WRITE))
481:                        throw new CapabilityNotSetException(J3dI18N
482:                                .getString("Shape3D2"));
483:                ((Shape3DRetained) retained).removeAllGeometries();
484:            }
485:
486:            /**
487:             * Sets the appearance component of this Shape3D node.  Setting it to null
488:             * specifies that default values are used for all appearance attributes.
489:             * @param appearance the new appearance component for this shape node
490:             * @exception CapabilityNotSetException if appropriate capability is
491:             * not set and this object is part of live or compiled scene graph
492:             */
493:            public void setAppearance(Appearance appearance) {
494:
495:                if (isLiveOrCompiled())
496:                    if (!this .getCapability(ALLOW_APPEARANCE_WRITE))
497:                        throw new CapabilityNotSetException(J3dI18N
498:                                .getString("Shape3D4"));
499:
500:                ((Shape3DRetained) this .retained).setAppearance(appearance);
501:            }
502:
503:            /**
504:             * Retrieves the appearance component of this shape node.
505:             * @return the appearance component of this shape node
506:             * @exception CapabilityNotSetException if appropriate capability is
507:             * not set and this object is part of live or compiled scene graph
508:             */
509:            public Appearance getAppearance() {
510:
511:                if (isLiveOrCompiled())
512:                    if (!this .getCapability(ALLOW_APPEARANCE_READ))
513:                        throw new CapabilityNotSetException(J3dI18N
514:                                .getString("Shape3D5"));
515:
516:                return ((Shape3DRetained) this .retained).getAppearance();
517:            }
518:
519:            /**
520:             * Checks whether the geometry in this shape node intersects with
521:             * the specified pickShape.
522:             *
523:             * @param path the SceneGraphPath to this shape node
524:             * @param pickShape the PickShape to be intersected
525:             *
526:             * @return true if the pick shape intersects this node; false
527:             * otherwise.
528:             *
529:             * @exception IllegalArgumentException if pickShape is a PickPoint.
530:             * Java 3D doesn't have spatial information of the surface.
531:             * Use PickBounds with BoundingSphere and a small radius, instead.
532:             *
533:             * @exception CapabilityNotSetException if the Geometry.ALLOW_INTERSECT
534:             * capability bit is not set in all of the Geometry objects
535:             * referred to by this shape node.
536:             */
537:            public boolean intersect(SceneGraphPath path, PickShape pickShape) {
538:                return intersect(path, pickShape, null);
539:            }
540:
541:            /**
542:             * Checks whether the geometry in this shape node intersects with
543:             * the specified pickRay.
544:             *
545:             * @param path the SceneGraphPath to this shape node
546:             * @param pickRay the PickRay to be intersected
547:             * @param dist the closest distance of the intersection
548:             *
549:             * @return true if the pick shape intersects this node; false
550:             * otherwise.  If true, dist contains the closest distance of
551:             * intersection.
552:             *
553:             * @exception CapabilityNotSetException if the Geometry.ALLOW_INTERSECT
554:             * capability bit is not set in all of the Geometry objects
555:             * referred to by this shape node.
556:             */
557:            public boolean intersect(SceneGraphPath path, PickRay pickRay,
558:                    double[] dist) {
559:
560:                if (isLiveOrCompiled()) {
561:                    if (!((Shape3DRetained) retained).allowIntersect())
562:                        throw new CapabilityNotSetException(J3dI18N
563:                                .getString("Shape3D6"));
564:                }
565:                return ((Shape3DRetained) this .retained).intersect(path,
566:                        pickRay, dist);
567:
568:            }
569:
570:            /**
571:             * Checks whether the geometry in this shape node intersects with
572:             * the specified pickShape.
573:             *
574:             * @param path the SceneGraphPath to this shape node
575:             * @param pickShape the PickShape to be intersected
576:             * @param dist the closest distance of the intersection
577:             *
578:             * @return true if the pick shape intersects this node; false
579:             * otherwise.  If true, dist contains the closest distance of
580:             * intersection.
581:             *
582:             * @exception IllegalArgumentException if pickShape is a PickPoint.
583:             * Java 3D doesn't have spatial information of the surface.
584:             * Use PickBounds with BoundingSphere and a small radius, instead.
585:             *
586:             * @exception CapabilityNotSetException if the Geometry.ALLOW_INTERSECT
587:             * capability bit is not set in all of the Geometry objects
588:             * referred to by this shape node.
589:             *
590:             * @since Java 3D 1.3
591:             */
592:            public boolean intersect(SceneGraphPath path, PickShape pickShape,
593:                    double[] dist) {
594:
595:                if (isLiveOrCompiled()) {
596:                    if (!((Shape3DRetained) retained).allowIntersect())
597:                        throw new CapabilityNotSetException(J3dI18N
598:                                .getString("Shape3D6"));
599:                }
600:
601:                if (pickShape instanceof  PickPoint) {
602:                    throw new IllegalArgumentException(J3dI18N
603:                            .getString("Shape3D7"));
604:                }
605:
606:                return ((Shape3DRetained) this .retained).intersect(path,
607:                        pickShape, dist);
608:            }
609:
610:            /**
611:             * Sets a flag that indicates whether this node's appearance can
612:             * be overridden.  If the flag is true, then this node's
613:             * appearance may be overridden by an AlternateAppearance leaf
614:             * node, regardless of the value of the ALLOW_APPEARANCE_WRITE
615:             * capability bit.
616:             * The default value is false.
617:             *
618:             * @param flag the apperance override enable flag.
619:             * @exception CapabilityNotSetException if appropriate capability is 
620:             * not set and this object is part of live or compiled scene graph
621:             *
622:             * @see AlternateAppearance
623:             *
624:             * @since Java 3D 1.2
625:             */
626:            public void setAppearanceOverrideEnable(boolean flag) {
627:
628:                if (isLiveOrCompiled())
629:                    if (!this .getCapability(ALLOW_APPEARANCE_OVERRIDE_WRITE))
630:                        throw new CapabilityNotSetException(J3dI18N
631:                                .getString("Shape3D8"));
632:
633:                ((Shape3DRetained) this .retained)
634:                        .setAppearanceOverrideEnable(flag);
635:            }
636:
637:            /**
638:             * Retrieves the appearanceOverrideEnable flag for this node.
639:             * @return true if the appearance can be overridden; false
640:             * otherwise.
641:             * @exception CapabilityNotSetException if appropriate capability is 
642:             * not set and this object is part of live or compiled scene graph
643:             *
644:             * @since Java 3D 1.2
645:             */
646:            public boolean getAppearanceOverrideEnable() {
647:
648:                if (isLiveOrCompiled())
649:                    if (!this .getCapability(ALLOW_APPEARANCE_OVERRIDE_READ))
650:                        throw new CapabilityNotSetException(J3dI18N
651:                                .getString("Shape3D9"));
652:
653:                return ((Shape3DRetained) this .retained)
654:                        .getAppearanceOverrideEnable();
655:            }
656:
657:            /**
658:             * Used to create a new instance of the node.  This routine is called
659:             * by <code>cloneTree</code> to duplicate the current node.
660:             * <code>cloneNode</code> should be overridden by any user subclassed
661:             * objects.  All subclasses must have their <code>cloneNode</code>
662:             * method consist of the following lines:
663:             * <P><blockquote><pre>
664:             *     public Node cloneNode(boolean forceDuplicate) {
665:             *         UserSubClass usc = new UserSubClass();
666:             *         usc.duplicateNode(this, forceDuplicate);
667:             *         return usc;
668:             *     }
669:             * </pre></blockquote>
670:             * @param forceDuplicate when set to <code>true</code>, causes the
671:             *  <code>duplicateOnCloneTree</code> flag to be ignored.  When
672:             *  <code>false</code>, the value of each node's
673:             *  <code>duplicateOnCloneTree</code> variable determines whether
674:             *  NodeComponent data is duplicated or copied.
675:             *
676:             * @see Node#cloneTree
677:             * @see Node#duplicateNode
678:             * @see NodeComponent#setDuplicateOnCloneTree
679:             */
680:            public Node cloneNode(boolean forceDuplicate) {
681:                Shape3D s = new Shape3D();
682:                s.duplicateNode(this , forceDuplicate);
683:                return s;
684:            }
685:
686:            /**
687:             * Copies all node information from <code>originalNode</code> into
688:             * the current node.  This method is called from the
689:             * <code>cloneNode</code> method which is, in turn, called by the
690:             * <code>cloneTree</code> method.
691:             * <P>
692:             * For any <code>NodeComponent</code> objects
693:             * contained by the object being duplicated, each <code>NodeComponent</code>
694:             * object's <code>duplicateOnCloneTree</code> value is used to determine
695:             * whether the <code>NodeComponent</code> should be duplicated in the new node
696:             * or if just a reference to the current node should be placed in the
697:             * new node.  This flag can be overridden by setting the
698:             * <code>forceDuplicate</code> parameter in the <code>cloneTree</code>
699:             * method to <code>true</code>.
700:             * <br>
701:             * NOTE: Applications should <i>not</i> call this method directly.
702:             * It should only be called by the cloneNode method.
703:             *
704:             * @param originalNode the original node to duplicate.
705:             * @param forceDuplicate when set to <code>true</code>, causes the
706:             *  <code>duplicateOnCloneTree</code> flag to be ignored.  When
707:             *  <code>false</code>, the value of each node's
708:             *  <code>duplicateOnCloneTree</code> variable determines whether
709:             *  NodeComponent data is duplicated or copied.
710:             * @exception ClassCastException if originalNode is not an instance of 
711:             *  <code>Shape3D</code>
712:             *
713:             * @see Node#cloneTree
714:             * @see Node#cloneNode
715:             * @see NodeComponent#setDuplicateOnCloneTree
716:             */
717:            public void duplicateNode(Node originalNode, boolean forceDuplicate) {
718:                checkDuplicateNode(originalNode, forceDuplicate);
719:            }
720:
721:            /**
722:             * Copies all Shape3D information from
723:             * <code>originalNode</code> into
724:             * the current node.  This method is called from the
725:             * <code>cloneNode</code> method which is, in turn, called by the
726:             * <code>cloneTree</code> method.<P>
727:             *
728:             * @param originalNode the original node to duplicate.
729:             * @param forceDuplicate when set to <code>true</code>, causes the
730:             *  <code>duplicateOnCloneTree</code> flag to be ignored.  When
731:             *  <code>false</code>, the value of each node's
732:             *  <code>duplicateOnCloneTree</code> variable determines whether
733:             *  NodeComponent data is duplicated or copied.
734:             *
735:             * @exception RestrictedAccessException if this object is part of a live
736:             *  or compiled scenegraph.
737:             *
738:             * @see Node#duplicateNode
739:             * @see Node#cloneTree
740:             * @see NodeComponent#setDuplicateOnCloneTree
741:             */
742:            void duplicateAttributes(Node originalNode, boolean forceDuplicate) {
743:
744:                super .duplicateAttributes(originalNode, forceDuplicate);
745:
746:                Shape3DRetained attr = (Shape3DRetained) originalNode.retained;
747:                Shape3DRetained rt = (Shape3DRetained) retained;
748:
749:                rt.setAppearance((Appearance) getNodeComponent(attr
750:                        .getAppearance(), forceDuplicate,
751:                        originalNode.nodeHashtable));
752:                int num = attr.numGeometries(id);
753:                if (num > 0) {
754:                    rt.setGeometry((Geometry) getNodeComponent(attr
755:                            .getGeometry(0, id), forceDuplicate,
756:                            originalNode.nodeHashtable), 0);
757:                    for (int i = 1; i < num; i++) {
758:                        rt.addGeometry((Geometry) getNodeComponent(attr
759:                                .getGeometry(i, id), forceDuplicate,
760:                                originalNode.nodeHashtable));
761:                    }
762:                }
763:
764:                rt.setCollisionBounds(attr.getCollisionBounds(id));
765:            }
766:
767:            /**
768:             * See parent class for the documentation on getBounds().
769:             */
770:            public Bounds getBounds() {
771:                if (isLiveOrCompiled()) {
772:                    if (!this .getCapability(ALLOW_BOUNDS_READ)) {
773:                        throw new CapabilityNotSetException(J3dI18N
774:                                .getString("Node2"));
775:                    }
776:                } else {
777:                    // this will throw a SceneGraphCycleException if there is
778:                    // a cycle
779:                    checkForCycle();
780:                }
781:
782:                return ((Shape3DRetained) this.retained).getBounds();
783:            }
784:
785:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.