QCAD
Open Source 2D CAD
Loading...
Searching...
No Matches
opennurbs_texture.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
17//
18// defines ON_Color and ON_Material
19//
21
22#if !defined(OPENNURBS_TEXTURE_INC_)
23#define OPENNURBS_TEXTURE_INC_
24
26//
27// Class ON_Texture
28//
29
31{
32public:
34
35 ON_Texture();
37
38 // default copy constructor and operator= work fine
39
40
41 // overrides virtual ON_Object::IsValid
42 ON_BOOL32 IsValid( ON_TextLog* text_log = NULL ) const;
43
44 // overrides virtual ON_Object::Dump
45 void Dump( ON_TextLog& ) const;
46
47 // overrides virtual ON_Object::SizeOf
48 unsigned int SizeOf() const;
49
50 // overrides virtual ON_Object::Write
52 ON_BinaryArchive& binary_archive
53 ) const;
54
55 // overrides virtual ON_Object::Read
57 ON_BinaryArchive& binary_archive
58 );
59
60 void Default();
61
62 int Compare( const ON_Texture& other ) const;
63
64 /*
65 Description:
66 Reverses the texture in the specified direction.
67 Parameters:
68 dir - [in] 0 = reverse "u", 1 = reverse "v", 2 = reverse "w".
69 Remarks:
70 Modifes m_uvw so that the spedified direction transforms
71 the texture coordinate t to 1-t.
72 Returns:
73 True if input is valid.
74 */
75 bool ReverseTextureCoordinate( int dir );
76
77 /*
78 Description:
79 Swaps the specified texture coordinates.
80 Parameters:
81 i - [in]
82 j - [in] (0 <= i, j <= 3 and i != j)
83 Remarks:
84 Modifes m_uvw so that the specified texture coordinates are swapped.
85 Returns:
86 True if input is valid.
87 */
88 bool SwapTextureCoordinate( int i, int j );
89
90 /*
91 Description:
92 Tiles the specified texture coordinates.
93 Parameters:
94 dir - [in] 0 = reverse "u", 1 = reverse "v", 2 = reverse "w".
95 count - [in] number of tiles (can be negative)
96 offset - [in] offset of the tile (can be any number)
97 Remarks:
98 Modifes m_uvw so that the specified texture coordinate is
99 tiled.
100 Returns:
101 True if input is valid.
102 */
103 bool TileTextureCoordinate( int dir, double count, double offset );
104
105 /*
106 Description:
107 Examines the m_uvw matrix and harvests tiling constants.
108 Parameters:
109 dir - [in] 0 = reverse "u", 1 = reverse "v", 2 = reverse "w".
110 count - [out] number of tiles
111 offset - [out] offset of the tile
112 Returns:
113 True if if the m_uvw matrix had entries that were compatible
114 with tiling.
115 */
116 bool IsTiled( int dir, double* count, double* offset ) const;
117
118
120
121 // list of pre-defined channel ids
123 {
124 tc_channel = 0, // Use the texture coordinate values
125 // currently on the geometric object.
126 default_channel = 1, // Use either default mapping, or the "Custom"
127 // mapping applied to the object
128 srfp_channel = 0xFFFFFFFE, // Use surface parameterization.
129 emap_channel = (long)0xFFFFFFFF // Environment map the geometric object.
130 };
131
132 // If the m_mapping_channel_id value is one of the built-in
133 // mappings listed in the MAPPING_CHANNEL enum, then that
134 // mapping is used. Otherwise, if an object has rendering
135 // attributes with an ON_MappingChannel entry that has a
136 // matching m_mapping_channel_id value, then the mapping
137 // identified by ON_MappingChannel::m_mapping_id is used.
138 // A value of zero means no mapping is supplied
139 // and the texture coordinates on the mesh are
140 // used.
142
143 // Bitmap filename
144 // During runtime, m_filename is the absolute path to the
145 // file in use. If m_filename_bRelativePath is true, then
146 // the value saved in the 3dm archive will be a relative path.
147 // When m_filename_bRelativePath is true, user interface
148 // should display a relative path.
151
152 // If false, texture is off and should be ignored.
153 // The intended use is to allow people to turn textures
154 // on and off without have to create/destroy or change
155 // other texture settings.
156 bool m_bOn;
157
158 // do not change TYPE enum values - they are saved in 3dm files.
159 // The "TYPE" setting controls how the pixels in the bitmap
160 // are interpreted.
161 enum TYPE
162 {
163 no_texture_type = 0,
164
165 bitmap_texture = 1, // "standard" image texture.
166 bump_texture = 2, // bump map - see m_bump_scale comment
167 transparency_texture = 3, // value = alpha (see m_tranparancy_id)
168
169 // OBSOLETE - set m_mapping_channel_id = ON_MappingChannel::emap_mapping
170 emap_texture = 86, // spherical environment mapping.
171
172 // andrew: case value evaluates to 4294967295, which cannot be narrowed to type 'int' [-Wc++11-narrowing]
173 //force_32bit_texture_type = 0xFFFFFFFF
174 force_32bit_texture_type = 0xFFFFFFF
175 };
176
178
179 // m_mode determines how the texture is
180 // do not change MODE enum values - they are saved in 3dm files.
181 enum MODE
182 {
183 no_texture_mode = 0,
184 modulate_texture = 1, // modulate with material diffuse color
185 decal_texture = 2, // decal
186 blend_texture = 3, // blend texture with others in the material
187 // To "add" a texture, set m_blend_amount = +1
188 // To "subtract" a texture, set m_blend_amount = -1
189
190 force_32bit_texture_mode = 0xFFFFFFF
191 };
192
194
196 {
197 nearest_filter = 0, // nearest texture pixel is used
198 linear_filter = 1, // weighted average of corresponding texture pixels
199
200 force_32bit_texture_filter = 0xFFFFFFF
201 };
202
203 // The value of m_minfilter determines how the color
204 // of the image pixel is calculated when the image pixel
205 // corresponds to multiple texture bitmap pixels.
207
208 // The magfilter setting controls how the color
209 // of the image pixel is calculated when the image pixel
210 // corresponds to a fraction of a texture bitmap pixel.
212
213 enum WRAP
214 {
215 repeat_wrap = 0,
216 clamp_wrap = 1,
217
218 force_32bit_texture_wrap = 0xFFFFFFF
219 };
220
224
225 // Texture coordinate transformation.
226 bool m_bApply_uvw; // true if m_uvw is active.
228
229 // If ON_UNSET_COLOR != m_border_color, then this color
230 // is used when the texture coordinates are <=0 or >=1
231 // and the m_wrap* value is clamp_wrap.
233
234 // This field is used for textures with type
235 // bitmap_texture that reference bitmap files that do
236 // not have an alpha channel and is used to set
237 // runtime alpha values. It needs to be parsed when the
238 // texture is loaded and can be ignored at runtime.
239 //
240 // If ON_UNSET_COLOR != m_transparent_color, then
241 // a pixel in the bitmap file with a matching RGB
242 // value is assigned the alpha value (ON_Color::Alpha)
243 // in m_transparent_color. The intended use is
244 // for non-rectangular decals defined by RGB bitmaps in
245 // files that don't save an alpha channel.
246 //
247 // For example if the decal is a red number 7 with a
248 // white background, then you would set m_transparent_color's
249 // RGB to white and its A to zero.
251
252 // This field is used for textures with type
253 // bitmap_texture that reference bitmap files that do
254 // not have an alpha channel and is used to set
255 // runtime alpha values. It needs to be parsed when the
256 // texture is loaded and can be ignored at runtime.
257 //
258 // If m_transparency_id is not nil, it is the id of another
259 // texture in the ON_Material.m_textures[] array that has
260 // type m_transparency_texture. The runtime bitmap_texture's
261 // alpha is set to (255-max(R,G,B)) (the "value" in the hue,
262 // saturation,value sense) of the correspondeing
263 // transparency_texture pixel.
264 //
265 // For example, if you had a bitmap texuture that was green
266 // with purple dots saved in a RGB .bmp file and you wanted
267 // the purple dots to be semi-transparent, you could create
268 // another bitmap that was black, where the original was green,
269 // and gray, where the original was purple, have an
270 // transparency_texture reference the white/gray bitmap,
271 // and have the bitmap_texture's m_transparency_id
272 // reference the transparency map.
274
275 // If the m_type is bump_texture, the height of the
276 // bump is m_bump_scale.ParameterAt(value), where
277 // value is in the HSV sense and normalized
278 // (black=0, white=1). The interval can be
279 // decreasing.
281
282 // If the m_mode is blend_texture, then m_blend_A[]
283 // and m_blend_RGB[] determine the blending function.
284 // new alpha = m_blend_constant_A
285 // + m_blend_A[0]*(current alpha)
286 // + m_blend_A[1]*(texture alpha)
287 // + m_blend_A[2]*min(current alpha,texture alpha)
288 // + m_blend_A[3]*max(current alpha,texture alpha)
289 // new rgb = m_blend_constant_RGB
290 // + m_blend_RGB[0]*(current RGB)
291 // + m_blend_RGB[1]*(texture RGB)
292 // + m_blend_RGB[2]*min(current RGB,texture RGB)
293 // + m_blend_RGB[3]*max(current RGB,texture RGB)
294 // Results are clamped to handle underflow or overflow.
296 double m_blend_A[4];
298 double m_blend_RGB[4];
299
300 // If an ON_Material m_textures[] array has more than
301 // one texture, the textures are blended, and the textures
302 // have different m_blend_order values, the the texture
303 // with the smaller m_blend_order is first.
305
306 // Applications use the m_runtime_ptr_id and m_runtime_ptr fields
307 // to cached runtime bitmaps. If either the id or the pointer
308 // are non-zero, then you cannot use them. If you hang something
309 // on the pointer, then set the id to something unique to
310 // prevent others from messing with it.
312 const void* m_runtime_ptr;
313
314 static TYPE TypeFromInt( int i );
315 static MODE ModeFromInt( int i );
316 static FILTER FilterFromInt( int i );
317 static WRAP WrapFromInt( int i );
318};
319
320#if defined(ON_DLL_TEMPLATE)
321// This stuff is here because of a limitation in the way Microsoft
322// handles templates and DLLs. See Microsoft's knowledge base
323// article ID Q168958 for details.
324#pragma warning( push )
325#pragma warning( disable : 4231 )
326ON_DLL_TEMPLATE template class ON_CLASS ON_ClassArray<ON_Texture>;
327ON_DLL_TEMPLATE template class ON_CLASS ON_ObjectArray<ON_Texture>;
328#pragma warning( pop )
329#endif
330
331#endif
332
int i
Copyright (c) 2011-2018 by Andrew Mustun.
Definition autostart.js:32
Definition opennurbs_archive.h:152
Definition opennurbs_array.h:760
Definition opennurbs_color.h:24
Definition opennurbs_point.h:46
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 unsigned int SizeOf() const
Definition opennurbs_object.cpp:1677
virtual ON_BOOL32 Write(ON_BinaryArchive &binary_archive) const
Definition opennurbs_object.cpp:1714
Definition opennurbs_textlog.h:20
Definition opennurbs_texture.h:31
double m_blend_constant_A
Definition opennurbs_texture.h:295
MODE
Definition opennurbs_texture.h:182
bool m_bOn
Definition opennurbs_texture.h:156
ON_Color m_border_color
Definition opennurbs_texture.h:232
ON_wString m_filename
Definition opennurbs_texture.h:149
ON_UUID m_transparency_texture_id
Definition opennurbs_texture.h:273
WRAP m_wrapw
Definition opennurbs_texture.h:223
ON_Color m_transparent_color
Definition opennurbs_texture.h:250
WRAP m_wrapu
Definition opennurbs_texture.h:221
ON_UUID m_runtime_ptr_id
Definition opennurbs_texture.h:311
TYPE
Definition opennurbs_texture.h:162
ON_OBJECT_DECLARE(ON_Texture)
ON_Color m_blend_constant_RGB
Definition opennurbs_texture.h:297
int m_blend_order
Definition opennurbs_texture.h:304
WRAP
Definition opennurbs_texture.h:214
bool m_filename_bRelativePath
Definition opennurbs_texture.h:150
FILTER m_magfilter
Definition opennurbs_texture.h:211
bool m_bApply_uvw
Definition opennurbs_texture.h:226
ON_Xform m_uvw
Definition opennurbs_texture.h:227
const void * m_runtime_ptr
Definition opennurbs_texture.h:312
MAPPING_CHANNEL
Definition opennurbs_texture.h:123
FILTER m_minfilter
Definition opennurbs_texture.h:206
int m_mapping_channel_id
Definition opennurbs_texture.h:141
FILTER
Definition opennurbs_texture.h:196
TYPE m_type
Definition opennurbs_texture.h:177
ON_Interval m_bump_scale
Definition opennurbs_texture.h:280
MODE m_mode
Definition opennurbs_texture.h:193
WRAP m_wrapv
Definition opennurbs_texture.h:222
ON_UUID m_texture_id
Definition opennurbs_texture.h:119
Definition opennurbs_uuid.h:31
Definition opennurbs_xform.h:28
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