Point Cloud Library (PCL)  1.10.0-dev
opennurbs_material.h
1 /* $NoKeywords: $ */
2 /*
3 //
4 // Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
5 // OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
6 // McNeel & Associates.
7 //
8 // THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
9 // ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
10 // MERCHANTABILITY ARE HEREBY DISCLAIMED.
11 //
12 // For complete openNURBS copyright information see <http://www.opennurbs.org>.
13 //
14 ////////////////////////////////////////////////////////////////
15 */
16 
17 #if !defined(OPENNURBS_MATERIAL_INC_)
18 #define OPENNURBS_MATERIAL_INC_
19 
20 
21 ///////////////////////////////////////////////////////////////////////////////
22 //
23 // Class ON_Material
24 //
25 class ON_CLASS ON_Material : public ON_Object
26 {
27  ON_OBJECT_DECLARE(ON_Material);
28 
29 public:
30  static double MaxShine(); // maximum value of shine exponent
31 
32  ON_Material(); // Default grey color
33  ~ON_Material(); // destructor
34  // C++ default copy construction and operator= work fine.
35 
36  bool operator==(const ON_Material&) const; // ignores m_material_index
37  bool operator!=(const ON_Material&) const; // ignores m_material_index
38 
39  void Default();
40 
41  /////////////////////////////////////////////////////////////////
42  // ON_Object overrides
43 
44  /*
45  Description:
46  Tests an object to see if its data members are correctly
47  initialized.
48  Parameters:
49  text_log - [in] if the object is not valid and text_log
50  is not NULL, then a brief englis description of the
51  reason the object is not valid is appened to the log.
52  The information appended to text_log is suitable for
53  low-level debugging purposes by programmers and is
54  not intended to be useful as a high level user
55  interface tool.
56  Returns:
57  @untitled table
58  true object is valid
59  false object is invalid, uninitialized, etc.
60  Remarks:
61  Overrides virtual ON_Object::IsValid
62  */
63  ON_BOOL32 IsValid( ON_TextLog* text_log = NULL ) const;
64 
65  void Dump( ON_TextLog& ) const; // for debugging
66 
67  ON_BOOL32 Write(
68  ON_BinaryArchive& // open binary file
69  ) const;
70 
71  ON_BOOL32 Read(
72  ON_BinaryArchive& // open binary file
73  );
74 
75  ON::object_type ObjectType() const;
76 
77  // virtual
78  ON_UUID ModelObjectId() const;
79 
80 
81  /////////////////////////////////////////////////////////////////
82  // Interface
83 
84  // ignores m_material_index
85  int Compare( const ON_Material& other ) const;
86 
87  // OBSOLETE - use m_ambient
88  ON_Color Ambient() const;
89  // OBSOLETE - use m_diffuse
90  ON_Color Diffuse() const;
91  // OBSOLETE - use m_emission
92  ON_Color Emission() const;
93  // OBSOLETE - use m_specular
94  ON_Color Specular() const;
95 
96  // OBSOLETE - use m_ambient
97  void SetAmbient( ON_Color );
98  // OBSOLETE - use m_diffuse
99  void SetDiffuse( ON_Color );
100  // OBSOLETE - use m_emission
101  void SetEmission( ON_Color );
102  // OBSOLETE - use m_specular
103  void SetSpecular( ON_Color );
104 
105  // Shine values are in range 0.0 to ON_Material::MaxShine()
106  double Shine() const;
107  void SetShine( double ); // 0 to ON_Material::MaxShine()
108 
109  // Transparency values are in range 0.0 = opaque to 1.0 = transparent
110  double Transparency() const;
111  void SetTransparency( double ); // 0.0 = opaque, 1.0 = transparent
112 
113  // OBSOLETE - use m_material_index
114  int MaterialIndex() const;
115  // OBSOLETE - use m_material_index
116  void SetMaterialIndex( int );
117 
118  // OBSOLETE - just use m_plugin_id
119  ON_UUID MaterialPlugInUuid() const;
120 
121  // OBSOLETE - just use m_plugin_id
122  void SetMaterialPlugInUuid( ON_UUID );
123 
124  // OBSOLETE - just use m_material_name
125  const wchar_t* MaterialName() const;
126 
127  // OBSOLETE - just use m_material_name
128  void SetMaterialName( const wchar_t* );
129 
130  // The only reliable and persistent way to reference
131  // materials is by the material_id.
133 
134  // Runtime material table index. This value is constant
135  // for each runtim instance of Rhino, but can change
136  // each time a model is loaded or saved. Once a material
137  // is in the CRhinoDoc material table, its id and index
138  // never change in that instance of Rhino.
140 
141  //
142  ON_wString m_material_name; // For user comfort - duplicates permitted
143 
144  ON_wString m_flamingo_library; // Legacy information from V3.
145  // Will vanish in V5.
146 
153  double m_index_of_refraction; // generally >= 1.0 (speed of light in vacum)/(speed of light in material)
154  double m_reflectivity; // 0.0 = none, 1.0 = 100%
155  double m_shine; // 0.0 = none to GetMaxShine()=maximum
156  double m_transparency; // 0.0 = opaque to 1.0 = transparent (1.0-alpha)
157 
158  bool m_bShared; // default = false.
159  // True means this material can be shared. When an
160  // object that uses this material is copied,
161  // the new object will share the material.
162  // False means this material is not shared.
163  // When an object that uses this material is
164  // duplicated.
165 
166  bool m_bDisableLighting; // default = false.
167  // True means render this object without
168  // applying any modulation based on lights.
169  // Basically, the diffuse, ambient, specular and
170  // emissive channels get combined additively, clamped,
171  // and then get treated as an emissive channel.
172  // Another way to think about it is when
173  // m_bDisableLighting is true, render the same way
174  // OpenGL does when ::glDisable( GL_LIGHTING ) is called.
175 
176 private:
177  unsigned char m_reserved1[2];
178 #if defined(ON_64BIT_POINTER)
179  unsigned char m_reserved2[4];
180 #endif
181 public:
182 
183  /*
184  Description:
185  Searches for a texure with matching texture_id.
186  If more than one texture matches, the first match
187  is returned.
188  Parameters:
189  texture_id - [in]
190  Returns:
191  >=0 m_textures[] index of matching texture
192  -1 if no match is found.
193  */
194  int FindTexture(
195  ON_UUID texture_id
196  ) const;
197 
198  /*
199  Description:
200  Searches for a texure with matching filename and type.
201  If more than one texture matches, the first match
202  is returned.
203  Parameters:
204  filename - [in] If NULL, then any filename matches.
205  type - [in] If ON_Texture::no_texture_type, then
206  any texture type matches.
207  i0 - [in] If i0 is < 0, the search begins at
208  m_textures[0], if i0 >= m_textures.Count(),
209  -1 is returnd, otherwise, the search begins
210  at m_textures[i0+1].
211  Example:
212  Iterate through all the the bitmap textures on
213  a material.
214 
215  ON_Material& mat = ...;
216  int ti = -1;
217  int bitmap_texture_count = 0;
218  for(;;)
219  {
220  ti = mat.FindTexture(
221  NULL,
222  ON_Texture::bitmap_texture,
223  ti );
224 
225  if ( ti < 0 )
226  {
227  // no more bitmap textures
228  break;
229  }
230 
231  // we have a bitmap texture
232  bitmap_texture_count++;
233  const ON_Texture& bitmap_texture = mat.m_textures[ti];
234  ...
235  }
236 
237  Returns:
238  >=0 m_textures[] index of matching texture
239  -1 if no match is found.
240  */
241  int FindTexture(
242  const wchar_t* filename,
243  ON_Texture::TYPE type,
244  int i0 = -1
245  ) const;
246 
247  /*
248  Description:
249  If there is already a texture with the same file name and
250  type, then that texture is modified, otherwise a new texture
251  is added. If tx has user data, the user data is copied
252  to the m_textures[] element.
253  Parameters:
254  tx - [in]
255  Returns:
256  Index of the added texture in the m_textures[] array.
257  Remarks:
258  This is intended to be a quick and simple way to add
259  textures to the material. If you need to do something
260  different, then just work on the m_textures[] array.
261  */
262  int AddTexture(
263  const ON_Texture& tx
264  );
265 
266  /*
267  Description:
268  If there is a texture with a matching type, that texture's
269  filename is modified, otherwise a new texture is added.
270  Parameters:
271  filename - [in] new filename
272  type - [in]
273  Returns:
274  Index of the added texture in the m_textures[] array.
275  Remarks:
276  This is intended to be a quick and simple way to add
277  textures to the material. If you need to do something
278  different, then just work on the m_textures[] array.
279  */
280  int AddTexture(
281  const wchar_t* filename,
282  ON_Texture::TYPE type
283  );
284 
285  /*
286  Description:
287  Deletes all texures with matching filenames and types.
288  Parameters:
289  filename - [in] If NULL, then any filename matches.
290  type - [in] If ON_Texture::no_texture_type, then
291  any texture type matches.
292  Returns:
293  Number of textures deleted.
294  */
295  int DeleteTexture(
296  const wchar_t* filename,
297  ON_Texture::TYPE type
298  );
299 
301 
302  /*
303  Description:
304  Used to provide per face material support.
305  The parent object reference a basic material.
306  When a brep face or mesh facet wants to use
307  a material besides the base material, it specifies
308  a channelSupports material channel. The default
309  material channel is 0 and that indicates the base
310  material. A channel of n > 0 means that face
311  used the material with id m_material_channel[n-1].
312  If (n-1) >= m_material_channel.Count(), then the base
313  material is used. The value of
314  m_material_channel[n].m_id is persistent. The
315  value of m_material_channel[n].m_i is a runtime
316  index in the CRhinoDoc::m_material_table[]. If
317  CRhinoDoc::m_material_table[m_i].m_uuid != m_id,
318  then m_id is assumed to be correct.
319  */
321 
322  ON_UUID m_plugin_id; // ID of the last plug-in to modify this material
323 
324 private:
325  static double m_max_shine;
326  bool ReadV3Helper( ON_BinaryArchive& file, int minor_version );
327  bool WriteV3Helper( ON_BinaryArchive& file ) const;
328 };
329 
330 #if defined(ON_DLL_TEMPLATE)
331 // This stuff is here because of a limitation in the way Microsoft
332 // handles templates and DLLs. See Microsoft's knowledge base
333 // article ID Q168958 for details.
334 #pragma warning( push )
335 #pragma warning( disable : 4231 )
336 ON_DLL_TEMPLATE template class ON_CLASS ON_ClassArray<ON_Material>;
337 ON_DLL_TEMPLATE template class ON_CLASS ON_ObjectArray<ON_Material>;
338 #pragma warning( pop )
339 #endif
340 
341 #endif
342 
virtual ON_BOOL32 IsValid(ON_TextLog *text_log=NULL) const =0
ON_Color m_reflection
double m_index_of_refraction
ON_wString m_material_name
virtual ON_BOOL32 Write(ON_BinaryArchive &binary_archive) const
virtual ON::object_type ObjectType() const
ON_SimpleArray< ON_UuidIndex > m_material_channel
ON_wString m_flamingo_library
virtual ON_BOOL32 Read(ON_BinaryArchive &binary_archive)
ON_Color m_transparent
virtual void Dump(ON_TextLog &) const
ON_ObjectArray< ON_Texture > m_textures
virtual ON_UUID ModelObjectId() const