Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

LWTexture.cpp

Go to the documentation of this file.
00001 
00002 /*
00003     TEDDY - General graphics application library
00004     Copyright (C) 1999-2002  Timo Suoranta
00005     tksuoran@cc.helsinki.fi
00006 
00007     This library is free software; you can redistribute it and/or
00008     modify it under the terms of the GNU Lesser General Public
00009     License as published by the Free Software Foundation; either
00010     version 2.1 of the License, or (at your option) any later version.
00011 
00012     This library is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015     Lesser General Public License for more details.
00016 
00017     You should have received a copy of the GNU Lesser General Public
00018     License along with this library; if not, write to the Free Software
00019     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020 
00021     $Id: LWTexture.cpp,v 1.6 2002/02/16 16:38:11 tksuoran Exp $
00022 */
00023 
00024 
00025 #include "Teddy/TeddyConfig.h"
00026 #if defined( TEDDY_INCLUDE_LW_SCENE )
00027 
00028 
00029 #if defined(_MSC_VER)
00030 #   pragma warning(disable:4786)
00031 #endif
00032 
00033 
00034 #include "Teddy/Imports/LWFile.h"
00035 #include "Teddy/Imports/LWLayer.h"
00036 #include "Teddy/Imports/LWSurface.h"
00037 #include "Teddy/Imports/LWModel.h"
00038 #include "Teddy/Imports/LWTexture.h"
00039 #include "Teddy/Models/Geometry.h"
00040 #include "Teddy/Graphics/PixFileTexture.h"
00041 #include "Teddy/SysSupport/FileScan.h"
00042 #include "Teddy/SysSupport/StdIO.h"
00043 using namespace Teddy::Materials;
00044 
00045 
00046 namespace Teddy   {
00047 namespace Imports {
00048 
00049 
00050 LWTexture::LWTexture( LWSurface *surface, int map_type ){
00051     this->f       = surface->getLayer()->getModel()->getFile();
00052     this->surface = surface;
00053     switch( map_type ){
00054     case LW_PLANAR_IMAGE_MAP     : texture_projection_mode = LW_PROJECTION_PLANAR     ; break;
00055     case LW_CYLINDRICAL_IMAGE_MAP: texture_projection_mode = LW_PROJECTION_CYLINDRICAL; break;
00056     case LW_SPHERICAL_IMAGE_MAP  : texture_projection_mode = LW_PROJECTION_SPHERICAL  ; break;
00057     case LW_CUBIC_IMAGE_MAP      : texture_projection_mode = LW_PROJECTION_CUBIC      ; break;
00058     default: emsg( M_LWO, "Unknown projection mode" ); break;
00059     }
00060     texture_center          = Vector(0,0,0);        
00061     texture_size            = Vector(1,1,1);        
00062 //  texture_projection_mode = LW_PLANAR_IMAGE_MAP;  //!<  CTEX
00063     texture_major_axis      = TEXTURE_AXIS_X;       
00064 }
00065 
00066 
00067 void LWTexture::applyTexture(){
00068     //  We need to get the texture name; only still images are supported
00069     LWLayer *layer = dynamic_cast<LWLayer*>( surface->getLayer() );
00070     if( layer == NULL ){
00071         emsg( M_LWO, "Layer not found" );
00072         return;
00073     }
00074 
00075     Model *model = surface->getModel();
00076     if( model == NULL ){
00077         emsg( M_LWO, "Model not found" );
00078     }
00079 
00080     std::string texture_file_name = texture_image_map;
00081     std::string final_file_name   = fix_file_name( "Data/textures/", texture_file_name.c_str() );
00082     int         final_length      = final_file_name.length();
00083 /*  final_file_name[ final_length-4 ] = 'p';
00084     final_file_name[ final_length-3 ] = 'i';
00085     final_file_name[ final_length-2 ] = 'x';*/
00086     dmsg( M_LWO, "Look for texture file '%s'", final_file_name.c_str() );
00087     Texture *t = new PixFileTexture( final_file_name );
00088     surface->setTexture( t, true );
00089 
00090     //  Choose projection mode
00091     switch( texture_projection_mode ){
00092     case LW_PROJECTION_PLANAR:
00093         model->getGeometry()->makePlanarTextureCoordinates(
00094             texture_center,
00095             texture_size,
00096             texture_major_axis
00097         );
00098         dmsg( M_TMAP, "Planar Image Map done" );
00099         break;
00100 
00101     case LW_PROJECTION_CYLINDRICAL:
00102         model->getGeometry()->makeCylindricalTextureCoordinates(
00103             texture_center,
00104             texture_size,
00105             texture_major_axis
00106         );
00107         dmsg( M_TMAP, "Cylindrical Image Map done" );
00108         break;
00109 
00110     case LW_PROJECTION_SPHERICAL:
00111         model->getGeometry()->makeSphericalTextureCoordinates(
00112             texture_center,
00113             texture_size,
00114             texture_major_axis
00115         );
00116         dmsg( M_TMAP, "Spherical Image Map done" );
00117         break;
00118 
00119     case LW_PROJECTION_CUBIC:
00120         model->getGeometry()->makeCubicTextureCoordinates(
00121             texture_center,
00122             texture_size
00123         );
00124         dmsg( M_TMAP, "Cubic Image Map done" );
00125         break;
00126 
00127     case LW_PROJECTION_FRONT:
00128         dmsg( M_TMAP, "Front projection not yet implemented" );
00129         break;
00130 
00131     case LW_PROJECTION_UV:
00132         dmsg( M_TMAP, "UV projection not yet implemented" );
00133         break;
00134 
00135     default:
00136         dmsg( M_TMAP, "Unknown projection mode" );
00137         break;
00138     }
00139 
00140 }
00141 
00142 
00143 /*
00144 void LWTexture::processTexture(){
00145     ID4 chunk_type   = f->read_ID4();
00146     U2  chunk_length = f->read_U2();
00147 
00148     f->pushDomain( chunk_length );
00149 
00150     switch( chunk_type ){
00151         case ID_TFLG: readTextureFlags_U2          (); break;
00152         case ID_TSIZ: readTextureSize_VEC12        (); break;
00153         case ID_TCTR: readTextureCenter_VEC12      (); break;
00154         case ID_TFAL: readTextureFallOff_VEC12     (); break;
00155         case ID_TVEL: readTextureVelocity_VEC12    (); break;
00156         case ID_TREF: readTextureReferenceObject_S0(); break;
00157         case ID_TCLR: readTextureColor_COL4        (); break;
00158         case ID_TVAL: readTextureValue_IP2         (); break;
00159         case ID_TAMP: readBumpTextureAmplitude_FP4 (); break;
00160         case ID_TFP : readTextureAlgorithm_F4      (); break;  // ns not yet handled
00161         case ID_TIP : readTextureAlgorithm_I2      (); break;
00162         case ID_TSP : readTextureAlgorithm_F4      (); break;  // obsolete
00163         case ID_TFRQ: readTextureAlgorithm_I2      (); break;  // obsolete
00164         case ID_TIMG: readImageMap_FNAM0           (); break;
00165         case ID_TALP: readImageAlpha_FNAM0         (); break;
00166         case ID_TWRP: readImageWarpOptions_U2_U2   (); break;
00167         case ID_TAAS: readAntialiasingStrength_FP4 (); break;
00168         case ID_TOPC: readTextureOpacity_FP4       (); break;
00169         default: break;
00170     }
00171 
00172     f->popDomain( true );
00173 
00174 } */
00175 
00176 void LWTexture::readTextureFlags_U2(){
00177     int count = 0;
00178     U2  flags = f->read_U2();   
00179 
00180     dmsg( M_TMAP, "TMap flags 0x%x", flags );
00181 
00182     if( (flags & LW_TF_AXIS_X) == LW_TF_AXIS_X ){
00183         texture_major_axis = TEXTURE_AXIS_X;
00184         dmsg( M_TMAP, "TMap axis x" );
00185     }
00186 
00187     if( (flags & LW_TF_AXIS_Y) == LW_TF_AXIS_Y ){
00188         texture_major_axis = TEXTURE_AXIS_Y;
00189         dmsg( M_TMAP, "TMap axis y" );
00190     }
00191     if( (flags & LW_TF_AXIS_Z) == LW_TF_AXIS_Z ){
00192         texture_major_axis = TEXTURE_AXIS_Z;
00193         dmsg( M_TMAP, "TMap axis z" );
00194     }
00195 
00196     /*if( flags & LW_TF_WORLD_COORDINATES ){
00197     }
00198     if( flags & LW_TF_NEGATIVE_IMAGE ){
00199     }
00200     if( flags & LW_TF_PIXEL_BLENDING ){
00201     }
00202     if( flags & LW_TF_ANTIALISING ){
00203     }*/
00204 }
00205 
00206 void LWTexture::readTextureSize_VEC12(){
00207     texture_size = f->read_VEC12();
00208 }
00209 
00210 void LWTexture::readTextureCenter_VEC12(){
00211     texture_center = f->read_VEC12();
00212 }
00213 
00214 void LWTexture::readTextureFallOff_VEC12(){
00215 }
00216 
00217 void LWTexture::readTextureVelocity_VEC12(){
00218 }
00219 
00220 void LWTexture::readTextureReferenceObject_S0(){
00221 }
00222 
00223 void LWTexture::readTextureColor_COL4(){
00224 }
00225 
00226 void LWTexture::readTextureValue_IP2(){
00227 }
00228 
00229 void LWTexture::readBumpTextureAmplitude_FP4(){
00230 }
00231 
00232 void LWTexture::readTextureAlgorithm_F4(){
00233 }
00234 
00235 void LWTexture::readTextureAlgorithm_I2(){
00236 }
00237 
00238 void LWTexture::readImageMap_FNAM0(){
00239     texture_image_map = f->read_FNAM0();
00240 }
00241 
00242 void LWTexture::readImageAlpha_FNAM0(){
00243     //char *image_alpha = f->read_FNAM0();
00244 }
00245 
00246 void LWTexture::readImageWarpOptions_U2_U2(){
00247 }
00248 
00249 void LWTexture::readAntialiasingStrength_FP4(){
00250 }
00251 
00252 void LWTexture::readTextureOpacity_FP4(){
00253 }
00254 
00255 
00256 };  //  namespace Imports
00257 };  //  namespace Teddy
00258 
00259 
00260 #endif  //  TEDDY_INCLUDE_LW_SCENE