View Javadoc

1   /* -------------------------------------------------------------------
2    * Java source file for the class Material
3    * 
4    * Copyright (c), 2003, Masahiro Takatsuka.
5    * All Rights Researved.
6    * 
7    * Original Author: Masahiro Takatsuka (masa@jbeans.net)
8    * $Author: takatsukam $
9    * 
10   * $Date: 2004/03/03 11:53:06 $
11   * 
12   * $Id: Material.java,v 1.3 2004/03/03 11:53:06 takatsukam Exp $
13   * 
14   * Reference:		Document no:
15   * ___				___
16   * 
17   * To Do:
18   * ___
19   * 
20  ------------------------------------------------------------------- */
21  
22  /* --------------------------- Package ---------------------------- */
23  package net.jbeans.j3d.scenegraph;
24  
25  /* ------------------ Import classes (packages) ------------------- *//package-summary/html">class="comment"> ------------------ Import classes (packages) ------------------- *//package-summary.html">class="comment">/* ------------------ Import classes (packages) ------------------- *//package-summary.html">class="comment"> ------------------ Import classes (packages) ------------------- */
26  import java.awt.*;
27  import java.io.*;
28  import java.lang.reflect.*;
29  import java.util.*;
30  import javax.swing.event.*;
31  
32  import javax.vecmath.*;
33  
34  import net.jbeans.lang.*;
35  import net.jbeans.j3d.event.*;
36  import net.jbeans.j3d.light.*;
37  
38  import net.jbeans.util.*;
39  import net.jbeans.util.debug.*;
40  
41  /*====================================================================
42                     Implementation of class Material                   
43  ====================================================================*/
44  /***
45   * generally describe Material in here
46   * 
47   * @version $Revision: 1.3 $
48   * @author Masahiro Takatsuka (masa@jbeans.net)
49   * @see javax.media.j3d.Material
50   * @see Serializable
51   */
52  
53  public class Material extends javax.media.j3d.Material implements Serializable {
54  	private static final boolean DEBUG = Debug.getDebugFlag(Material.class);
55  	
56  	static private Color3f DEFAULT_AMBIENT = new Color3f(0.2f, 0.2f, 0.2f);
57  	static private Color3f DEFAULT_EMMISIVE = new Color3f(0.0f, 0.0f, 0.0f);
58  	static private Color3f DEFAULT_DIFFUSE = new Color3f(1.0f, 1.0f, 1.0f);
59  	static private Color3f DEFAULT_SPECULAR = new Color3f(1.0f, 1.0f, 1.0f);
60  	static private float DEFAULT_SHININESS = 64;
61  	
62  	/* ------------------------ not serialized ------------------------ */
63  	transient private Color3f tmpColor;
64  	
65  	public Material () {
66  		this(DEFAULT_AMBIENT, DEFAULT_EMMISIVE, DEFAULT_DIFFUSE, DEFAULT_SPECULAR, DEFAULT_SHININESS);
67  	}
68  
69  	public Material (Color3f ambientColor, Color3f emissiveColor,
70  					   Color3f diffuseColor, Color3f specularColor,
71  					   float shininess) {
72  		super(ambientColor, emissiveColor, diffuseColor, specularColor,
73  			  shininess);
74  
75  		initialize();
76  	}
77  	
78  	private final void initialize() {
79  		setCapabilities();
80  	}
81  
82  	private final void setCapabilities() {
83  		setCapability(ALLOW_COMPONENT_READ);
84  		setCapability(ALLOW_COMPONENT_WRITE);		
85  	}
86  
87      /***
88       * Serialization methods
89       */
90      private void readObject(ObjectInputStream s) throws ClassNotFoundException, IOException {
91  		initialize();
92      }
93  
94  	public void setAmbientColor(Color color) {
95  		if (this.tmpColor == null) {
96  			this.tmpColor = new Color3f(color);
97  		} else {
98  			this.tmpColor.set(color);
99  		}
100 		setAmbientColor(this.tmpColor);
101 	}
102 
103 	public Color getAmbientColor() {
104 		if (this.tmpColor == null) {
105 			this.tmpColor = new Color3f();
106 		}
107 		getAmbientColor(this.tmpColor);
108 
109 		return new Color(this.tmpColor.x, this.tmpColor.y, this.tmpColor.z);
110 	}
111 
112 	public void setDiffuseColor(Color color) {
113 		if (this.tmpColor == null) {
114 			this.tmpColor = new Color3f(color);
115 		} else {
116 			this.tmpColor.set(color);
117 		}
118 		setDiffuseColor(this.tmpColor);
119 	}
120 
121 	public Color getDiffuseColor() {
122 		if (this.tmpColor == null) {
123 			this.tmpColor = new Color3f();
124 		}
125 		getDiffuseColor(this.tmpColor);
126 
127 		return new Color(this.tmpColor.x, this.tmpColor.y, this.tmpColor.z);
128 	}
129 
130 	public void setEmissiveColor(Color color) {
131 		if (this.tmpColor == null) {
132 			this.tmpColor = new Color3f(color);
133 		} else {
134 			this.tmpColor.set(color);
135 		}
136 		setEmissiveColor(this.tmpColor);
137 	}
138 
139 	public Color getEmissiveColor() {
140 		if (this.tmpColor == null) {
141 			this.tmpColor = new Color3f();
142 		}
143 		getEmissiveColor(this.tmpColor);
144 
145 		return new Color(this.tmpColor.x, this.tmpColor.y, this.tmpColor.z);
146 	}
147 	
148 	public void setSpecularColor(Color color) {
149 		if (this.tmpColor == null) {
150 			this.tmpColor = new Color3f(color);
151 		} else {
152 			this.tmpColor.set(color);
153 		}
154 		setSpecularColor(this.tmpColor);
155 	}
156 
157 	public Color getSpecularColor() {
158 		if (this.tmpColor == null) {
159 			this.tmpColor = new Color3f();
160 		}
161 		getSpecularColor(this.tmpColor);
162 
163 		return new Color(this.tmpColor.x, this.tmpColor.y, this.tmpColor.z);
164 	}
165 }
166