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