Source Code Cross Referenced for Material.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: Material.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:26 $
029:         * $State: Exp $
030:         */
031:
032:        package javax.media.j3d;
033:
034:        import javax.vecmath.Color3f;
035:
036:        /**
037:         * The Material object defines the appearance of an object under
038:         * illumination.
039:         * If the Material object in an Appearance object is <code>null</code>,
040:         * lighting is disabled for all nodes that use that Appearance object.
041:         * <P>
042:         * The properties that can be set for a Material object are:
043:         * <P><UL>
044:         * <LI>Ambient color - the ambient RGB color reflected off the surface
045:         * of the material. The range of values is 0.0 to 1.0. The default ambient
046:         * color is (0.2, 0.2, 0.2).<p></LI>
047:         * <LI>Diffuse color - the RGB color of the material when illuminated.
048:         * The range of values is 0.0 to 1.0. The default diffuse color is
049:         * (1.0, 1.0, 1.0).<p></LI>
050:         * <LI>Specular color - the RGB specular color of the material (highlights).
051:         * The range of values is 0.0 to 1.0. The default specular color
052:         * is (1.0, 1.0, 1.0).<p></LI>
053:         * <LI>Emissive color - the RGB color of the light the material emits, if 
054:         * any. The range of values is 0.0 to 1.0. The default emissive
055:         * color is (0.0, 0.0, 0.0).<p></LI>
056:         * <LI>Shininess - the material's shininess, in the range [1.0, 128.0] 
057:         * with 1.0 being not shiny and 128.0 being very shiny. Values outside
058:         * this range are clamped. The default value for the material's
059:         * shininess is 64.<p></LI>
060:         * <LI>Color target - the material color target for per-vertex colors,
061:         * one of: AMBIENT, EMISSIVE, DIFFUSE, SPECULAR, or AMBIENT_AND_DIFFUSE.
062:         * The default target is DIFFUSE.<p></LI>
063:         * </UL>
064:         *
065:         * The Material object also enables or disables lighting.
066:         */
067:        public class Material extends NodeComponent {
068:
069:            /**
070:             * For material object, specifies that Material allows reading
071:             * individual component field information.
072:             */
073:            public static final int ALLOW_COMPONENT_READ = CapabilityBits.MATERIAL_ALLOW_COMPONENT_READ;
074:
075:            /**
076:             * For material object, specifies that Material allows reading
077:             * individual component field information.
078:             */
079:            public static final int ALLOW_COMPONENT_WRITE = CapabilityBits.MATERIAL_ALLOW_COMPONENT_WRITE;
080:
081:            /**
082:             * Specifies that per-vertex colors replace the ambient material color.
083:             * @see #setColorTarget
084:             *
085:             * @since Java 3D 1.3
086:             */
087:            public static final int AMBIENT = 0;
088:
089:            /**
090:             * Specifies that per-vertex colors replace the emissive material color.
091:             * @see #setColorTarget
092:             *
093:             * @since Java 3D 1.3
094:             */
095:            public static final int EMISSIVE = 1;
096:
097:            /**
098:             * Specifies that per-vertex colors replace the diffuse material color.
099:             * This is the default target.
100:             * @see #setColorTarget
101:             *
102:             * @since Java 3D 1.3
103:             */
104:            public static final int DIFFUSE = 2;
105:
106:            /**
107:             * Specifies that per-vertex colors replace the specular material color.
108:             * @see #setColorTarget
109:             *
110:             * @since Java 3D 1.3
111:             */
112:            public static final int SPECULAR = 3;
113:
114:            /**
115:             * Specifies that per-vertex colors replace both the ambient and the
116:             * diffuse material color.
117:             * @see #setColorTarget
118:             *
119:             * @since Java 3D 1.3
120:             */
121:            public static final int AMBIENT_AND_DIFFUSE = 4;
122:
123:            // Array for setting default read capabilities
124:            private static final int[] readCapabilities = { ALLOW_COMPONENT_READ };
125:
126:            /**
127:             * Constructs and initializes a Material object using default parameters.
128:             * The default values are as follows:
129:             * <ul>
130:             * lighting enable : true<br>
131:             * ambient color : (0.2, 0.2, 0.2)<br>
132:             * emmisive color : (0.0, 0.0, 0.0)<br>
133:             * diffuse color : (1.0, 1.0, 1.0)<br>
134:             * specular color : (1.0, 1.0, 1.0)<br>
135:             * shininess : 64<br>
136:             * color target : DIFFUSE
137:             * </ul>
138:             */
139:            public Material() {
140:                // Just use the defaults
141:                // set default read capabilities
142:                setDefaultReadCapabilities(readCapabilities);
143:            }
144:
145:            /**
146:             * Constructs and initializes a new material object using the specified
147:             * parameters. Lighting is enabled by default.
148:             * @param ambientColor the material's ambient color
149:             * @param emissiveColor the material's emissive color
150:             * @param diffuseColor the material's diffuse color when illuminated by a
151:             * light
152:             * @param specularColor the material's specular color when illuminated
153:             * to generate a highlight
154:             * @param shininess the material's shininess in the
155:             * range [1.0, 128.0] with 1.0 being not shiny and 128.0 being very shiny.
156:             * Values outside this range are clamped.
157:             */
158:            public Material(Color3f ambientColor, Color3f emissiveColor,
159:                    Color3f diffuseColor, Color3f specularColor, float shininess) {
160:                // set default read capabilities
161:                setDefaultReadCapabilities(readCapabilities);
162:
163:                ((MaterialRetained) this .retained).createMaterial(ambientColor,
164:                        emissiveColor, diffuseColor, specularColor, shininess);
165:            }
166:
167:            /**
168:             * Creates a retained mode MaterialRetained object that this
169:             * Material component object will point to.
170:             */
171:            void createRetained() {
172:                this .retained = new MaterialRetained();
173:                this .retained.setSource(this );
174:            }
175:
176:            /**
177:             * Sets this material's ambient color.
178:             * This specifies how much ambient light is reflected by
179:             * the surface.
180:             * The ambient color in this Material object may be overridden by
181:             * per-vertex colors in some cases.  If vertex colors are present
182:             * in the geometry, and lighting is enabled, and the colorTarget
183:             * is either AMBIENT or AMBIENT_AND_DIFFUSE, and vertex colors are
184:             * not being ignored, then the vertex colors are used in place of
185:             * this Material's ambient color in the lighting equation.
186:             *
187:             * @param color the material's ambient color
188:             * @exception CapabilityNotSetException if appropriate capability is
189:             * not set and this object is part of live or compiled scene graph
190:             *
191:             * @see RenderingAttributes#setIgnoreVertexColors
192:             * @see #setColorTarget
193:             */
194:            public void setAmbientColor(Color3f color) {
195:                if (isLiveOrCompiled())
196:                    if (!this .getCapability(ALLOW_COMPONENT_WRITE))
197:                        throw new CapabilityNotSetException(J3dI18N
198:                                .getString("Material0"));
199:                if (isLive()) {
200:                    ((MaterialRetained) this .retained).setAmbientColor(color);
201:                } else {
202:                    ((MaterialRetained) this .retained).initAmbientColor(color);
203:                }
204:            }
205:
206:            /**
207:             * Sets this material's ambient color.
208:             * This specifies how much ambient light is reflected by
209:             * the surface.  
210:             * The ambient color in this Material object may be overridden by
211:             * per-vertex colors in some cases.  If vertex colors are present
212:             * in the geometry, and lighting is enabled, and the colorTarget
213:             * is either AMBIENT or AMBIENT_AND_DIFFUSE, and vertex colors are
214:             * not being ignored, then the vertex colors are used in place of
215:             * this Material's ambient color in the lighting equation.
216:             *
217:             * @param r the new ambient color's red component
218:             * @param g the new ambient color's green component
219:             * @param b the new ambient color's blue component
220:             * @exception CapabilityNotSetException if appropriate capability is
221:             * not set and this object is part of live or compiled scene graph
222:             *
223:             * @see RenderingAttributes#setIgnoreVertexColors
224:             * @see #setColorTarget
225:             */
226:            public void setAmbientColor(float r, float g, float b) {
227:                if (isLiveOrCompiled())
228:                    if (!this .getCapability(ALLOW_COMPONENT_WRITE))
229:                        throw new CapabilityNotSetException(J3dI18N
230:                                .getString("Material0"));
231:                if (isLive()) {
232:                    ((MaterialRetained) this .retained).setAmbientColor(r, g, b);
233:                } else {
234:                    ((MaterialRetained) this .retained)
235:                            .initAmbientColor(r, g, b);
236:                }
237:            }
238:
239:            /**
240:             * Retrieves this material's ambient color.
241:             * @param color that will contain the material's ambient color
242:             * @exception CapabilityNotSetException if appropriate capability is
243:             * not set and this object is part of live or compiled scene graph
244:             */
245:            public void getAmbientColor(Color3f color) {
246:                if (isLiveOrCompiled())
247:                    if (!this .getCapability(ALLOW_COMPONENT_READ))
248:                        throw new CapabilityNotSetException(J3dI18N
249:                                .getString("Material2"));
250:
251:                ((MaterialRetained) this .retained).getAmbientColor(color);
252:            }
253:
254:            /**
255:             * Sets this material's emissive color.
256:             * This is the color of light, if any, that the material emits.
257:             * The emissive color in this Material object may be overridden by
258:             * per-vertex colors in some cases.  If vertex colors are present
259:             * in the geometry, and lighting is enabled, and the colorTarget
260:             * is EMISSIVE, and vertex colors are
261:             * not being ignored, then the vertex colors are used in place of
262:             * this Material's emissive color in the lighting equation.
263:             *
264:             * @param color the new emissive color
265:             * @exception CapabilityNotSetException if appropriate capability is
266:             * not set and this object is part of live or compiled scene graph
267:             *
268:             * @see RenderingAttributes#setIgnoreVertexColors
269:             * @see #setColorTarget
270:             */
271:            public void setEmissiveColor(Color3f color) {
272:                if (isLiveOrCompiled())
273:                    if (!this .getCapability(ALLOW_COMPONENT_WRITE))
274:                        throw new CapabilityNotSetException(J3dI18N
275:                                .getString("Material0"));
276:                if (isLive())
277:                    ((MaterialRetained) this .retained).setEmissiveColor(color);
278:                else
279:                    ((MaterialRetained) this .retained).initEmissiveColor(color);
280:
281:            }
282:
283:            /**
284:             * Sets this material's emissive color.
285:             * This is the color of light, if any, that the material emits.
286:             * The emissive color in this Material object may be overridden by
287:             * per-vertex colors in some cases.  If vertex colors are present
288:             * in the geometry, and lighting is enabled, and the colorTarget
289:             * is EMISSIVE, and vertex colors are
290:             * not being ignored, then the vertex colors are used in place of
291:             * this Material's emissive color in the lighting equation.
292:             *
293:             * @param r the new emissive color's red component
294:             * @param g the new emissive color's green component
295:             * @param b the new emissive color's blue component
296:             * @exception CapabilityNotSetException if appropriate capability is
297:             * not set and this object is part of live or compiled scene graph
298:             *
299:             * @see RenderingAttributes#setIgnoreVertexColors
300:             * @see #setColorTarget
301:             */
302:            public void setEmissiveColor(float r, float g, float b) {
303:                if (isLiveOrCompiled())
304:                    if (!this .getCapability(ALLOW_COMPONENT_WRITE))
305:                        throw new CapabilityNotSetException(J3dI18N
306:                                .getString("Material0"));
307:
308:                if (isLive())
309:                    ((MaterialRetained) this .retained)
310:                            .setEmissiveColor(r, g, b);
311:                else
312:                    ((MaterialRetained) this .retained).initEmissiveColor(r, g,
313:                            b);
314:            }
315:
316:            /**
317:             * Retrieves this material's emissive color and stores it in the
318:             * argument provided.
319:             * @param color the vector that will receive this material's emissive color
320:             * @exception CapabilityNotSetException if appropriate capability is
321:             * not set and this object is part of live or compiled scene graph
322:             */
323:            public void getEmissiveColor(Color3f color) {
324:                if (isLiveOrCompiled())
325:                    if (!this .getCapability(ALLOW_COMPONENT_READ))
326:                        throw new CapabilityNotSetException(J3dI18N
327:                                .getString("Material2"));
328:
329:                ((MaterialRetained) this .retained).getEmissiveColor(color);
330:            }
331:
332:            /**
333:             * Sets this material's diffuse color.
334:             * This is the color of the material when illuminated by a light source.
335:             * The diffuse color in this Material object may be overridden by
336:             * per-vertex colors in some cases.  If vertex colors are present
337:             * in the geometry, and lighting is enabled, and the colorTarget
338:             * is either DIFFUSE or AMBIENT_AND_DIFFUSE, and vertex colors are
339:             * not being ignored, then the vertex colors are used in place of
340:             * this Material's diffuse color in the lighting equation.
341:             *
342:             * @param color the new diffuse color
343:             * @exception CapabilityNotSetException if appropriate capability is
344:             * not set and this object is part of live or compiled scene graph
345:             *
346:             * @see RenderingAttributes#setIgnoreVertexColors
347:             * @see #setColorTarget
348:             */
349:            public void setDiffuseColor(Color3f color) {
350:                if (isLiveOrCompiled())
351:                    if (!this .getCapability(ALLOW_COMPONENT_WRITE))
352:                        throw new CapabilityNotSetException(J3dI18N
353:                                .getString("Material0"));
354:
355:                if (isLive())
356:                    ((MaterialRetained) this .retained).setDiffuseColor(color);
357:                else
358:                    ((MaterialRetained) this .retained).initDiffuseColor(color);
359:            }
360:
361:            /**
362:             * Sets this material's diffuse color.
363:             * This is the color of the material when illuminated by a light source.
364:             * The diffuse color in this Material object may be overridden by
365:             * per-vertex colors in some cases.  If vertex colors are present
366:             * in the geometry, and lighting is enabled, and the colorTarget
367:             * is either DIFFUSE or AMBIENT_AND_DIFFUSE, and vertex colors are
368:             * not being ignored, then the vertex colors are used in place of
369:             * this Material's diffuse color in the lighting equation.
370:             *
371:             * @param r the new diffuse color's red component
372:             * @param g the new diffuse color's green component
373:             * @param b the new diffuse color's blue component
374:             * @exception CapabilityNotSetException if appropriate capability is
375:             * not set and this object is part of live or compiled scene graph
376:             *
377:             * @see RenderingAttributes#setIgnoreVertexColors
378:             * @see #setColorTarget
379:             */
380:            public void setDiffuseColor(float r, float g, float b) {
381:                if (isLiveOrCompiled())
382:                    if (!this .getCapability(ALLOW_COMPONENT_WRITE))
383:                        throw new CapabilityNotSetException(J3dI18N
384:                                .getString("Material0"));
385:
386:                if (isLive())
387:                    ((MaterialRetained) this .retained).setDiffuseColor(r, g, b);
388:                else
389:                    ((MaterialRetained) this .retained)
390:                            .initDiffuseColor(r, g, b);
391:            }
392:
393:            /**
394:             * Sets this material's diffuse color plus alpha.
395:             * This is the color of the material when illuminated by a light source.
396:             * The diffuse color in this Material object may be overridden by
397:             * per-vertex colors in some cases.  If vertex colors are present
398:             * in the geometry, and lighting is enabled, and the colorTarget
399:             * is either DIFFUSE or AMBIENT_AND_DIFFUSE, and vertex colors are
400:             * not being ignored, then the vertex colors are used in place of
401:             * this Material's diffuse color in the lighting equation.
402:             *
403:             * @param r the new diffuse color's red component
404:             * @param g the new diffuse color's green component
405:             * @param b the new diffuse color's blue component
406:             * @param a the alpha component used to set transparency
407:             * @exception CapabilityNotSetException if appropriate capability is
408:             * not set and this object is part of live or compiled scene graph
409:             *
410:             * @see RenderingAttributes#setIgnoreVertexColors
411:             * @see #setColorTarget
412:             */
413:            public void setDiffuseColor(float r, float g, float b, float a) {
414:                if (isLiveOrCompiled())
415:                    if (!this .getCapability(ALLOW_COMPONENT_WRITE))
416:                        throw new CapabilityNotSetException(J3dI18N
417:                                .getString("Material0"));
418:
419:                if (isLive())
420:                    ((MaterialRetained) this .retained).setDiffuseColor(r, g, b,
421:                            a);
422:                else
423:                    ((MaterialRetained) this .retained).initDiffuseColor(r, g,
424:                            b, a);
425:            }
426:
427:            /**
428:             * Retrieves this material's diffuse color.
429:             * @param color the vector that will receive this material's diffuse color
430:             * @exception CapabilityNotSetException if appropriate capability is
431:             * not set and this object is part of live or compiled scene graph
432:             */
433:            public void getDiffuseColor(Color3f color) {
434:                if (isLiveOrCompiled())
435:                    if (!this .getCapability(ALLOW_COMPONENT_READ))
436:                        throw new CapabilityNotSetException(J3dI18N
437:                                .getString("Material2"));
438:
439:                ((MaterialRetained) this .retained).getDiffuseColor(color);
440:            }
441:
442:            /**
443:             * Sets this material's specular color.
444:             * This is the specular highlight color of the material.
445:             * The specular color in this Material object may be overridden by
446:             * per-vertex colors in some cases.  If vertex colors are present
447:             * in the geometry, and lighting is enabled, and the colorTarget
448:             * is SPECULAR, and vertex colors are
449:             * not being ignored, then the vertex colors are used in place of
450:             * this Material's specular color in the lighting equation.
451:             *
452:             * @param color the new specular color
453:             * @exception CapabilityNotSetException if appropriate capability is
454:             * not set and this object is part of live or compiled scene graph
455:             *
456:             * @see RenderingAttributes#setIgnoreVertexColors
457:             * @see #setColorTarget
458:             */
459:            public void setSpecularColor(Color3f color) {
460:                if (isLiveOrCompiled())
461:                    if (!this .getCapability(ALLOW_COMPONENT_WRITE))
462:                        throw new CapabilityNotSetException(J3dI18N
463:                                .getString("Material0"));
464:
465:                if (isLive())
466:                    ((MaterialRetained) this .retained).setSpecularColor(color);
467:                else
468:                    ((MaterialRetained) this .retained).initSpecularColor(color);
469:            }
470:
471:            /**
472:             * Sets this material's specular color.
473:             * This is the specular highlight color of the material.
474:             * The specular color in this Material object may be overridden by
475:             * per-vertex colors in some cases.  If vertex colors are present
476:             * in the geometry, and lighting is enabled, and the colorTarget
477:             * is SPECULAR, and vertex colors are
478:             * not being ignored, then the vertex colors are used in place of
479:             * this Material's specular color in the lighting equation.
480:             *
481:             * @param r the new specular color's red component
482:             * @param g the new specular color's green component
483:             * @param b the new specular color's blue component
484:             * @exception CapabilityNotSetException if appropriate capability is
485:             * not set and this object is part of live or compiled scene graph
486:             *
487:             * @see RenderingAttributes#setIgnoreVertexColors
488:             * @see #setColorTarget
489:             */
490:            public void setSpecularColor(float r, float g, float b) {
491:                if (isLiveOrCompiled())
492:                    if (!this .getCapability(ALLOW_COMPONENT_WRITE))
493:                        throw new CapabilityNotSetException(J3dI18N
494:                                .getString("Material0"));
495:
496:                if (isLive())
497:                    ((MaterialRetained) this .retained)
498:                            .setSpecularColor(r, g, b);
499:                else
500:                    ((MaterialRetained) this .retained).initSpecularColor(r, g,
501:                            b);
502:            }
503:
504:            /**
505:             * Retrieves this material's specular color.
506:             * @param color the vector that will receive this material's specular color
507:             * @exception CapabilityNotSetException if appropriate capability is
508:             * not set and this object is part of live or compiled scene graph
509:             */
510:            public void getSpecularColor(Color3f color) {
511:                if (isLiveOrCompiled())
512:                    if (!this .getCapability(ALLOW_COMPONENT_READ))
513:                        throw new CapabilityNotSetException(J3dI18N
514:                                .getString("Material2"));
515:
516:                ((MaterialRetained) this .retained).getSpecularColor(color);
517:            }
518:
519:            /**
520:             * Sets this material's shininess.
521:             * This specifies a material specular scattering exponent, or
522:             * shininess.  It takes a floating point number in the range [1.0, 128.0]
523:             * with 1.0 being not shiny and 128.0 being very shiny.
524:             * Values outside this range are clamped.
525:             * @param shininess the material's shininess
526:             * @exception CapabilityNotSetException if appropriate capability is
527:             * not set and this object is part of live or compiled scene graph
528:             */
529:            public void setShininess(float shininess) {
530:                if (isLiveOrCompiled())
531:                    if (!this .getCapability(ALLOW_COMPONENT_WRITE))
532:                        throw new CapabilityNotSetException(J3dI18N
533:                                .getString("Material0"));
534:
535:                if (isLive())
536:                    ((MaterialRetained) this .retained).setShininess(shininess);
537:                else
538:                    ((MaterialRetained) this .retained).initShininess(shininess);
539:            }
540:
541:            /**
542:             * Retrieves this material's shininess.
543:             * @return the material's shininess
544:             * @exception CapabilityNotSetException if appropriate capability is
545:             * not set and this object is part of live or compiled scene graph
546:             */
547:            public float getShininess() {
548:                if (isLiveOrCompiled())
549:                    if (!this .getCapability(ALLOW_COMPONENT_READ))
550:                        throw new CapabilityNotSetException(J3dI18N
551:                                .getString("Material2"));
552:
553:                return ((MaterialRetained) this .retained).getShininess();
554:            }
555:
556:            /**
557:             * Enables or disables lighting for this appearance component object.
558:             * @param state true or false to enable or disable lighting
559:             * @exception CapabilityNotSetException if appropriate capability is 
560:             * not set and this object is part of live or compiled scene graph
561:             */
562:            public void setLightingEnable(boolean state) {
563:                if (isLiveOrCompiled())
564:                    if (!this .getCapability(ALLOW_COMPONENT_WRITE))
565:                        throw new CapabilityNotSetException(J3dI18N
566:                                .getString("Material15"));
567:                if (isLive())
568:                    ((MaterialRetained) this .retained).setLightingEnable(state);
569:                else
570:                    ((MaterialRetained) this .retained)
571:                            .initLightingEnable(state);
572:            }
573:
574:            /**
575:             * Retrieves the state of the lighting enable flag.
576:             * @return true if lighting is enabled, false if lighting is disabled
577:             * @exception CapabilityNotSetException if appropriate capability is 
578:             * not set and this object is part of live or compiled scene graph
579:             */
580:            public boolean getLightingEnable() {
581:                if (isLiveOrCompiled())
582:                    if (!this .getCapability(ALLOW_COMPONENT_READ))
583:                        throw new CapabilityNotSetException(J3dI18N
584:                                .getString("Material16"));
585:                return ((MaterialRetained) this .retained).getLightingEnable();
586:            }
587:
588:            /**
589:             * Sets the color target for per-vertex colors.  When lighting is
590:             * enabled and per-vertex colors are present (and not ignored) in
591:             * the geometry for a given Shape3D node, those per-vertex colors
592:             * are used in place of the specified material color(s) for this
593:             * Material object.  The color target is ignored when lighting is
594:             * disabled or when per-vertex colors are not used.
595:             * The ColorInterpolator behavior also uses the color target to
596:             * determine which color in the associated Material is modified.
597:             * The default target is DIFFUSE.
598:             *
599:             * @param colorTarget one of: AMBIENT, EMISSIVE, DIFFUSE, SPECULAR, or
600:             * AMBIENT_AND_DIFFUSE.
601:             *
602:             * @exception CapabilityNotSetException if appropriate capability is
603:             * not set and this object is part of live or compiled scene graph
604:             *
605:             * @see RenderingAttributes#setIgnoreVertexColors
606:             * @see ColorInterpolator
607:             *
608:             * @since Java 3D 1.3
609:             */
610:            public void setColorTarget(int colorTarget) {
611:                if (isLiveOrCompiled())
612:                    if (!this .getCapability(ALLOW_COMPONENT_WRITE))
613:                        throw new CapabilityNotSetException(J3dI18N
614:                                .getString("Material3"));
615:
616:                if (isLive())
617:                    ((MaterialRetained) this .retained)
618:                            .setColorTarget(colorTarget);
619:                else
620:                    ((MaterialRetained) this .retained)
621:                            .initColorTarget(colorTarget);
622:            }
623:
624:            /**
625:             * Retrieves the current color target for this material.
626:             *
627:             * @return one of: AMBIENT, EMISSIVE, DIFFUSE, SPECULAR, or
628:             * AMBIENT_AND_DIFFUSE.
629:             *
630:             * @exception CapabilityNotSetException if appropriate capability is
631:             * not set and this object is part of live or compiled scene graph
632:             *
633:             * @since Java 3D 1.3
634:             */
635:            public int getColorTarget() {
636:                if (isLiveOrCompiled())
637:                    if (!this .getCapability(ALLOW_COMPONENT_READ))
638:                        throw new CapabilityNotSetException(J3dI18N
639:                                .getString("Material4"));
640:
641:                return ((MaterialRetained) this .retained).getColorTarget();
642:            }
643:
644:            /**
645:             * Returns a String representation of this Materials values.
646:             * If the scene graph is live only those values with their
647:             * Capability read bit set will be displayed.
648:             */
649:            public String toString() {
650:                StringBuffer str = new StringBuffer(getNamePrefix());
651:                str.append("javax.media.j3d.Material: ");
652:                Color3f color = new Color3f();
653:                try {
654:                    getAmbientColor(color);
655:                    str.append("AmbientColor=" + color);
656:                } catch (CapabilityNotSetException e) {
657:                    str.append("AmbientColor=N/A");
658:                }
659:                try {
660:                    getEmissiveColor(color);
661:                    str.append(" EmissiveColor=" + color);
662:                } catch (CapabilityNotSetException ex) {
663:                    str.append(" EmissiveColor=N/A");
664:                }
665:                try {
666:                    getDiffuseColor(color);
667:                    str.append(" DiffuseColor=" + color);
668:                } catch (CapabilityNotSetException exc) {
669:                    str.append(" DiffuseColor=N/A");
670:                }
671:                try {
672:                    getSpecularColor(color);
673:                    str.append(" SpecularColor=" + color);
674:                } catch (CapabilityNotSetException exce) {
675:                    str.append(" SpecularColor=N/A");
676:                }
677:                try {
678:                    float f = getShininess();
679:                    str.append(" Shininess=" + f);
680:                } catch (CapabilityNotSetException excep) {
681:                    str.append(" Shininess=N/A");
682:                }
683:                try {
684:                    boolean b = getLightingEnable();
685:                    str.append(" LightingEnable=" + b);
686:                } catch (CapabilityNotSetException except) {
687:                    str.append(" LightingEnable=N/A");
688:                }
689:                try {
690:                    int i = getColorTarget();
691:                    str.append(" ColorTarget=" + i);
692:                } catch (CapabilityNotSetException except) {
693:                    str.append(" ColorTarget=N/A");
694:                }
695:                return new String(str);
696:            }
697:
698:            /**
699:             * @deprecated replaced with cloneNodeComponent(boolean forceDuplicate)  
700:             */
701:            public NodeComponent cloneNodeComponent() {
702:                Material m = new Material();
703:                m.duplicateNodeComponent(this );
704:                return m;
705:            }
706:
707:            /**
708:             * Copies all node information from <code>originalNodeComponent</code> into
709:             * the current node.  This method is called from the
710:             * <code>duplicateNode</code> method. This routine does
711:             * the actual duplication of all "local data" (any data defined in
712:             * this object). 
713:             *
714:             * @param originalNodeComponent the original node to duplicate.
715:             * @param forceDuplicate when set to <code>true</code>, causes the
716:             *  <code>duplicateOnCloneTree</code> flag to be ignored.  When
717:             *  <code>false</code>, the value of each node's
718:             *  <code>duplicateOnCloneTree</code> variable determines whether
719:             *  NodeComponent data is duplicated or copied.
720:             *
721:             * @see Node#cloneTree
722:             * @see NodeComponent#setDuplicateOnCloneTree
723:             */
724:            void duplicateAttributes(NodeComponent originalNodeComponent,
725:                    boolean forceDuplicate) {
726:                super 
727:                        .duplicateAttributes(originalNodeComponent,
728:                                forceDuplicate);
729:
730:                MaterialRetained mat = (MaterialRetained) originalNodeComponent.retained;
731:                MaterialRetained rt = (MaterialRetained) retained;
732:
733:                Color3f c = new Color3f();
734:                mat.getAmbientColor(c);
735:
736:                rt.initAmbientColor(c);
737:                mat.getEmissiveColor(c);
738:                rt.initEmissiveColor(c);
739:                mat.getDiffuseColor(c);
740:                rt.initDiffuseColor(c);
741:                mat.getSpecularColor(c);
742:                rt.initSpecularColor(c);
743:                rt.initShininess(mat.getShininess());
744:                rt.initLightingEnable(mat.getLightingEnable());
745:                rt.initColorTarget(mat.getColorTarget());
746:            }
747:
748:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.