00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
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
00063 texture_major_axis = TEXTURE_AXIS_X;
00064 }
00065
00066
00067 void LWTexture::applyTexture(){
00068
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
00084
00085
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
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
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
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
00197
00198
00199
00200
00201
00202
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
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 };
00257 };
00258
00259
00260 #endif // TEDDY_INCLUDE_LW_SCENE