opennurbs_texture.h
Go to the documentation of this file.
00001 /* $NoKeywords: $ */
00002 /*
00003 //
00004 // Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
00005 // OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
00006 // McNeel & Associates.
00007 //
00008 // THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
00009 // ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
00010 // MERCHANTABILITY ARE HEREBY DISCLAIMED.
00011 //                              
00012 // For complete openNURBS copyright information see <http://www.opennurbs.org>.
00013 //
00015 */
00016 
00018 //
00019 //   defines ON_Color and ON_Material
00020 //
00022 
00023 #if !defined(OPENNURBS_TEXTURE_INC_)
00024 #define OPENNURBS_TEXTURE_INC_
00025 
00027 //
00028 // Class ON_Texture
00029 // 
00030 
00031 class ON_CLASS ON_Texture : public ON_Object
00032 {
00033 public:
00034   ON_OBJECT_DECLARE(ON_Texture);
00035 
00036   ON_Texture();
00037   ~ON_Texture();
00038 
00039   // default copy constructor and operator= work fine
00040 
00041 
00042   // overrides virtual ON_Object::IsValid
00043   ON_BOOL32 IsValid( ON_TextLog* text_log = NULL ) const;
00044 
00045   // overrides virtual ON_Object::Dump
00046   void Dump( ON_TextLog& ) const;
00047 
00048   // overrides virtual ON_Object::SizeOf
00049   unsigned int SizeOf() const;
00050 
00051   // overrides virtual ON_Object::Write
00052   ON_BOOL32 Write(
00053          ON_BinaryArchive& binary_archive
00054        ) const;
00055 
00056   // overrides virtual ON_Object::Read
00057   ON_BOOL32 Read(
00058          ON_BinaryArchive& binary_archive
00059        );
00060 
00061   void Default();
00062 
00063   int Compare( const ON_Texture& other ) const; 
00064 
00065   /*
00066   Description:
00067     Reverses the texture in the specified direction.
00068   Parameters:
00069     dir - [in] 0 = reverse "u", 1 = reverse "v", 2 = reverse "w".
00070   Remarks:
00071     Modifes m_uvw so that the spedified direction transforms
00072     the texture coordinate t to 1-t.
00073   Returns:
00074     True if input is valid.
00075   */
00076   bool ReverseTextureCoordinate( int dir );
00077 
00078   /*
00079   Description:
00080     Swaps the specified texture coordinates.
00081   Parameters:
00082     i - [in]
00083     j - [in]  (0 <= i, j <= 3 and i != j)
00084   Remarks:
00085     Modifes m_uvw so that the specified texture coordinates are swapped.
00086   Returns:
00087     True if input is valid.
00088   */
00089   bool SwapTextureCoordinate( int i, int j );
00090 
00091   /*
00092   Description:
00093     Tiles the specified texture coordinates.
00094   Parameters:
00095     dir - [in] 0 = reverse "u", 1 = reverse "v", 2 = reverse "w".
00096     count - [in] number of tiles (can be negative)
00097     offset - [in] offset of the tile (can be any number)
00098   Remarks:
00099     Modifes m_uvw so that the specified texture coordinate is
00100     tiled.
00101   Returns:
00102     True if input is valid.
00103   */
00104   bool TileTextureCoordinate( int dir, double count, double offset );
00105 
00106   /*
00107   Description:
00108     Examines the m_uvw matrix and harvests tiling constants.
00109   Parameters:
00110     dir - [in] 0 = reverse "u", 1 = reverse "v", 2 = reverse "w".
00111     count - [out] number of tiles
00112     offset - [out] offset of the tile
00113   Returns:
00114     True if if the m_uvw matrix had entries that were compatible
00115     with tiling.
00116   */
00117   bool IsTiled( int dir, double* count, double* offset ) const;
00118 
00119 
00120   ON_UUID m_texture_id;
00121 
00122   // list of pre-defined channel ids
00123   enum MAPPING_CHANNEL
00124   {
00125     tc_channel      = 0,     // Use the texture coordinate values
00126                              // currently on the geometric object.
00127     default_channel = 1,           // Use either default mapping, or the "Custom"
00128                                                                        // mapping applied to the object
00129     srfp_channel = 0xFFFFFFFE, // Use surface parameterization.
00130     emap_channel = 0xFFFFFFFF  // Environment map the geometric object.
00131   };
00132 
00133   // If the m_mapping_channel_id value is one of the built-in 
00134   // mappings listed in the MAPPING_CHANNEL enum, then that 
00135   // mapping is used.  Otherwise, if an object has rendering
00136   // attributes with an ON_MappingChannel entry that has a 
00137   // matching m_mapping_channel_id value, then the mapping 
00138   // identified by ON_MappingChannel::m_mapping_id is used.
00139   // A value of zero means no mapping is supplied
00140   // and the texture coordinates on the mesh are
00141   // used.
00142   int m_mapping_channel_id;
00143 
00144   // Bitmap filename  
00145   //   During runtime, m_filename is the absolute path to the
00146   //   file in use.  If m_filename_bRelativePath is true, then
00147   //   the value saved in the 3dm archive will be a relative path.
00148   //   When m_filename_bRelativePath is true, user interface
00149   //   should display a relative path.
00150   ON_wString m_filename;
00151   bool m_filename_bRelativePath;
00152 
00153   // If false, texture is off and should be ignored.
00154   // The intended use is to allow people to turn textures
00155   // on and off without have to create/destroy or change 
00156   // other texture settings.
00157   bool m_bOn;
00158 
00159   // do not change TYPE enum values - they are saved in 3dm files.
00160   // The "TYPE" setting controls how the pixels in the bitmap
00161   // are interpreted.
00162   enum TYPE
00163   {
00164     no_texture_type = 0,
00165 
00166     bitmap_texture       = 1, // "standard" image texture.
00167     bump_texture         = 2, // bump map - see m_bump_scale comment
00168     transparency_texture = 3, // value = alpha (see m_tranparancy_id)
00169 
00170     // OBSOLETE - set m_mapping_channel_id = ON_MappingChannel::emap_mapping
00171     emap_texture = 86, // spherical environment mapping.
00172 
00173     force_32bit_texture_type = 0xFFFFFFFF
00174   };
00175 
00176   TYPE m_type;
00177 
00178   // m_mode determines how the texture is
00179   // do not change MODE enum values - they are saved in 3dm files.
00180   enum MODE
00181   {
00182     no_texture_mode  = 0,
00183     modulate_texture = 1,  // modulate with material diffuse color
00184     decal_texture    = 2,  // decal
00185     blend_texture    = 3,  // blend texture with others in the material
00186                            // To "add" a texture, set m_blend_amount = +1
00187                            // To "subtract" a texture, set m_blend_amount = -1
00188 
00189     force_32bit_texture_mode = 0xFFFFFFFF
00190   };
00191 
00192   MODE m_mode;
00193 
00194   enum FILTER
00195   {
00196     nearest_filter = 0, // nearest texture pixel is used
00197     linear_filter  = 1, // weighted average of corresponding texture pixels
00198 
00199     force_32bit_texture_filter = 0xFFFFFFFF
00200   };
00201   
00202   // The value of m_minfilter determines how the color
00203   // of the image pixel is calculated when the image pixel
00204   // corresponds to multiple texture bitmap pixels.
00205   FILTER m_minfilter;  
00206 
00207   // The magfilter setting controls how the color
00208   // of the image pixel is calculated when the image pixel
00209   // corresponds to a fraction of a texture bitmap pixel.
00210   FILTER m_magfilter;
00211 
00212   enum WRAP
00213   {
00214     repeat_wrap      = 0,
00215     clamp_wrap       = 1,
00216 
00217     force_32bit_texture_wrap = 0xFFFFFFFF
00218   };
00219 
00220   WRAP m_wrapu;
00221   WRAP m_wrapv;
00222   WRAP m_wrapw;
00223 
00224   // Texture coordinate transformation.
00225   bool m_bApply_uvw; // true if m_uvw is active.
00226   ON_Xform m_uvw;
00227 
00228   // If ON_UNSET_COLOR != m_border_color, then this color
00229   // is used when the texture coordinates are <=0 or >=1
00230   // and the m_wrap* value is clamp_wrap.
00231   ON_Color m_border_color;
00232 
00233   // This field is used for textures with type
00234   // bitmap_texture that reference bitmap files that do
00235   // not have an alpha channel and is used to set
00236   // runtime alpha values.  It needs to be parsed when the
00237   // texture is loaded and can be ignored at runtime.
00238   // 
00239   // If ON_UNSET_COLOR != m_transparent_color, then 
00240   // a pixel in the bitmap file with a matching RGB
00241   // value is assigned the alpha value (ON_Color::Alpha)
00242   // in m_transparent_color. The intended use is 
00243   // for non-rectangular decals defined by RGB bitmaps in
00244   // files that don't save an alpha channel.
00245   //
00246   // For example if the decal is a red number 7 with a 
00247   // white background, then you would set m_transparent_color's
00248   // RGB to white and its A to zero.
00249   ON_Color m_transparent_color;
00250 
00251   // This field is used for textures with type
00252   // bitmap_texture that reference bitmap files that do
00253   // not have an alpha channel and is used to set
00254   // runtime alpha values.  It needs to be parsed when the
00255   // texture is loaded and can be ignored at runtime.
00256   // 
00257   // If m_transparency_id is not nil, it is the id of another
00258   // texture in the ON_Material.m_textures[] array that has
00259   // type m_transparency_texture.  The runtime bitmap_texture's
00260   // alpha is set to (255-max(R,G,B)) (the "value" in the hue,
00261   // saturation,value sense) of the correspondeing 
00262   // transparency_texture pixel. 
00263   //
00264   // For example, if you had a bitmap texuture that was green 
00265   // with purple dots saved in a RGB .bmp file and you wanted
00266   // the purple dots to be semi-transparent, you could create
00267   // another bitmap that was black, where the original was green,
00268   // and gray, where the original was purple, have an 
00269   // transparency_texture reference the white/gray bitmap,
00270   // and have the bitmap_texture's m_transparency_id 
00271   // reference the transparency map.
00272   ON_UUID m_transparency_texture_id;
00273 
00274   // If the m_type is bump_texture, the height of the
00275   // bump is m_bump_scale.ParameterAt(value), where
00276   // value is in the HSV sense and normalized 
00277   // (black=0, white=1).  The interval can be 
00278   // decreasing.
00279   ON_Interval m_bump_scale;
00280 
00281   // If the m_mode is blend_texture, then m_blend_A[]
00282   // and m_blend_RGB[] determine the blending function.
00283   //  new alpha  = m_blend_constant_A 
00284   //             + m_blend_A[0]*(current alpha)
00285   //             + m_blend_A[1]*(texture alpha)
00286   //             + m_blend_A[2]*min(current alpha,texture alpha)
00287   //             + m_blend_A[3]*max(current alpha,texture alpha)
00288   //  new rgb    = m_blend_constant_RGB 
00289   //             + m_blend_RGB[0]*(current RGB)
00290   //             + m_blend_RGB[1]*(texture RGB)
00291   //             + m_blend_RGB[2]*min(current RGB,texture RGB)
00292   //             + m_blend_RGB[3]*max(current RGB,texture RGB)
00293   // Results are clamped to handle underflow or overflow.
00294   double m_blend_constant_A;
00295   double m_blend_A[4];
00296   ON_Color m_blend_constant_RGB;
00297   double m_blend_RGB[4];
00298 
00299   // If an ON_Material m_textures[] array has more than
00300   // one texture, the textures are blended, and the textures
00301   // have different m_blend_order values, the the texture 
00302   // with the smaller m_blend_order is first. 
00303   int m_blend_order;
00304 
00305   // Applications use the m_runtime_ptr_id and m_runtime_ptr fields
00306   // to cached runtime bitmaps. If either the id or the pointer
00307   // are non-zero, then you cannot use them.  If you hang something
00308   // on the pointer, then set the id to something unique to
00309   // prevent others from messing with it.
00310   ON_UUID m_runtime_ptr_id;
00311   const void* m_runtime_ptr;
00312 
00313   static TYPE   TypeFromInt( int i );
00314   static MODE   ModeFromInt( int i );
00315   static FILTER FilterFromInt( int i );
00316   static WRAP   WrapFromInt( int i );
00317 };
00318 
00319 #if defined(ON_DLL_TEMPLATE)
00320 // This stuff is here because of a limitation in the way Microsoft
00321 // handles templates and DLLs.  See Microsoft's knowledge base 
00322 // article ID Q168958 for details.
00323 #pragma warning( push )
00324 #pragma warning( disable : 4231 )
00325 ON_DLL_TEMPLATE template class ON_CLASS ON_ClassArray<ON_Texture>;
00326 ON_DLL_TEMPLATE template class ON_CLASS ON_ObjectArray<ON_Texture>;
00327 #pragma warning( pop )
00328 #endif
00329 
00330 #endif
00331 


pcl
Author(s): Open Perception
autogenerated on Wed Aug 26 2015 15:27:03