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 #include "Teddy/Imports/LWFile.h"
00030 #include "Teddy/Imports/LWModel.h"
00031 #include "Teddy/Imports/LWLayer.h"
00032 #include "Teddy/Materials/Material.h"
00033 #include "Teddy/Models/Model.h"
00034 #include "Teddy/Models/Face.h"
00035 #include "Teddy/Models/Vertex.h"
00036 #include "Teddy/SysSupport/Exception.h"
00037 #include "Teddy/SysSupport/FileScan.h"
00038 #include "Teddy/SysSupport/Messages.h"
00039 #include "Teddy/SysSupport/StdMaths.h"
00040 #include "Teddy/SysSupport/StdIO.h"
00041 #ifndef SWIG
00042 #include <algorithm>
00043 using namespace std;
00044 #endif
00045 using namespace Teddy::Materials;
00046 using namespace Teddy::SysSupport;
00047
00048
00049
00050 #define USE_LIGHTWAVE_SCALE 1
00051 #define SCALE 1
00052
00053
00054 namespace Teddy {
00055 namespace Imports {
00056
00057
00059 LWModel::LWModel( const std::string &name ):Model(name){
00060 dmsg( M_LWO, "LWModel constructor" );
00061 }
00062
00063
00065 LWModel::LWModel( const std::string &fname, Uint32 options )
00066 :
00067 Model(fix_file_name("Data/lwo/",fname.c_str() ))
00068 {
00069 f = NULL;
00070 num_tags = 0;
00071 setMaterial( &Material::BLACK );
00072
00073 std::string final_file_name = fix_file_name( "Data/lwo/", fname.c_str() );
00074 FILE *f_test = fopen( final_file_name.c_str(), "r" );
00075 if( f_test == NULL ){
00076 emsg( M_LWO, "Could not open file %s", final_file_name.c_str() );
00077 return;
00078 }else{
00079 fclose( f_test );
00080 }
00081
00082 try{
00083 f = new LWFile( final_file_name, options );
00084
00085 f->pushDomain( 8 );
00086 ID4 form = f->read_ID4();
00087 f->setLen ( f->read_U4 () );
00088 f->pushDomain( f->getLen () );
00089 f->setType ( f->read_ID4() );
00090
00091 dmsg( M_LWO,
00092 "%s lwo file %s length %lu ",
00093 did( f->getType() ),
00094 final_file_name.c_str(),
00095 f->getLen()
00096 );
00097
00098 LWLayer *new_layer = new LWLayer( this, fname, 0, Vector(0,0,0), -1 );
00099 layers.insert( std::make_pair(0,new_layer) );
00100 add( new_layer );
00101 new_layer->processLayer();
00102
00103
00104
00105
00106
00107 }catch( ... ){
00108 dmsg( M_LWO, "Exception" );
00109 }
00110
00111 if( f != NULL ){
00112 f->close();
00113 }
00114
00115 setupClipRadius();
00116 }
00117
00118
00120 LWModel::~LWModel(){
00121
00122 }
00123
00124
00125
00126 LWFile *LWModel::getFile() const {
00127 return f;
00128 }
00129
00130 LWLayer *LWModel::getLayer( int layer_number ){
00131 U4_to_LWLayer::iterator l_it = layers.find( layer_number );
00132 LWLayer *layer = NULL;
00133
00134 if( l_it != layers.end() ){
00135 layer = (*l_it).second;
00136 if( layer == NULL ){
00137 emsg( M_LWO, "Layer found as NULL" );
00138 }
00139 }else{
00140 emsg( M_LWO, "Layer not found" );
00141 }
00142 return layer;
00143 }
00144
00145
00159 void LWModel::layer_U2_U2_S0(){
00160 U2 layer_number = f->read_U2();
00161 U2 layer_flags = f->read_U2();
00162 std::string layer_name = f->read_S0();
00163
00164 dmsg( M_LWO, "LAYER %s number %u", layer_name.c_str(), layer_number );
00165
00166 LWLayer *new_layer = new LWLayer(
00167 this,
00168 layer_name,
00169 layer_flags,
00170 Vector(0,0,0),
00171 -1
00172 );
00173 layers.insert( make_pair(layer_number,new_layer) );
00174 add( new_layer );
00175 f->popDomain( true );
00176 new_layer->processLayer();
00177 float lr = new_layer->getClipRadius();
00178 if( lr > getClipRadius() ){
00179 setClipRadius( lr );
00180 }
00181 }
00182
00183
00198 void LWModel::layer_U2_U2_VEC12_S0_U2(){
00199 U2 layer_number = f->read_U2();
00200 U2 layer_flags = f->read_U2();
00201 Vector layer_pivot = f->read_VEC12();
00202 std::string layer_name = f->read_S0();
00203 U2 layer_parent = 1;
00204
00205 if( f->domainLeft() >= 2 ){
00206 int lp = f->read_I2();
00207 if( lp>1 ){
00208 layer_parent = lp;
00209 }
00210 }
00211
00212 dmsg( M_LWO, "LAYER %s number %u parent %u",
00213 layer_name.c_str(),
00214 layer_number,
00215 layer_parent
00216 );
00217
00218 LWLayer *new_layer = new LWLayer( this, layer_name, layer_flags, layer_pivot, layer_parent );
00219 layers.insert( std::make_pair(layer_number,new_layer) );
00220 add( new_layer );
00221
00222 f->popDomain( true );
00223
00224 new_layer->processLayer();
00225 float lr = new_layer->getClipRadius();
00226 if( lr > this->getClipRadius() ){
00227 this->setClipRadius( lr );
00228 }
00229 }
00230
00231
00241 void LWModel::tags_d(){
00242 while( f->domainLeft() > 0 ){
00243 std::string tag = f->read_S0();
00244 tags.insert( std::make_pair(num_tags,tag) );
00245 num_tags++;
00246 }
00247 dmsg( M_LWO, "Tags found: %lu", num_tags );
00248 }
00249
00250
00251 std::string LWModel::getTag( VX tag_index ){
00252 U4_to_string::iterator t_it = tags.find( tag_index );
00253 std::string tag_value;
00254
00255 if( t_it != tags.end() ){
00256 tag_value = (*t_it).second;
00257 }else{
00258 emsg( M_LWO, "Tag not found" );
00259 }
00260
00261 return tag_value;
00262 }
00263
00264
00265 };
00266 };
00267
00268
00269 #endif // TEDDY_INCLUDE_LW_SCENE
00270