[657] | 1 | #include "lwo.h"
|
---|
| 2 | #include "lwReader.h"
|
---|
| 3 | #include "lwo2mesh.h"
|
---|
| 4 |
|
---|
| 5 | #include "Ogre.h"
|
---|
| 6 | #include "OgreMeshSerializer.h"
|
---|
| 7 | #include "OgreSkeletonSerializer.h"
|
---|
| 8 | #include "OgreDataChunk.h"
|
---|
| 9 | #include "OgreDefaultHardwareBufferManager.h"
|
---|
| 10 |
|
---|
| 11 | #if OGRE_PLATFORM == OGRE_PLATFORM_LINUX
|
---|
| 12 | #include "asm/io.h"
|
---|
| 13 | #else
|
---|
| 14 | #include "io.h"
|
---|
| 15 | #endif
|
---|
| 16 | #include "time.h"
|
---|
| 17 |
|
---|
| 18 | LogManager* logMgr;
|
---|
| 19 | Math* mth;
|
---|
| 20 | MaterialManager* matMgr;
|
---|
| 21 | SkeletonManager* skelMgr;
|
---|
| 22 | MeshManager* meshMgr;
|
---|
| 23 | MeshSerializer* meshSerializer;
|
---|
| 24 | MaterialSerializer* materialSerializer;
|
---|
| 25 | SkeletonSerializer* skeletonSerializer;
|
---|
| 26 | DefaultHardwareBufferManager *bufferManager;
|
---|
| 27 |
|
---|
| 28 | bool flags[NUMFLAGS] =
|
---|
| 29 | {
|
---|
| 30 | false, // lightwave info
|
---|
| 31 | false, // dump vmaps
|
---|
| 32 | true, // shared geometry
|
---|
| 33 | false, // layers
|
---|
| 34 | false, // generate LOD
|
---|
| 35 | true, // use fixed method
|
---|
| 36 | true, // materials
|
---|
| 37 | false, // RenameMaterials
|
---|
| 38 | false, // UseInteractiveMethod
|
---|
| 39 | true, // UseObjectMethod, default
|
---|
| 40 | false, // UsePrefixMethod
|
---|
| 41 | true, // skeleton
|
---|
| 42 | true, // has normals
|
---|
| 43 | true, // new submesh
|
---|
| 44 | true // linear copy
|
---|
| 45 | };
|
---|
| 46 |
|
---|
| 47 | Mesh::LodDistanceList distanceList;
|
---|
| 48 | Real reduction = 0.0f;
|
---|
| 49 | char *matPrefix = 0;
|
---|
| 50 |
|
---|
| 51 | ostream& nl(ostream& os)
|
---|
| 52 | {
|
---|
| 53 | return os << '\n';
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 | int nobjects = 0, nlayers = 0, nsurfs = 0, nenvs = 0, nclips = 0, npoints = 0, npolygons = 0;
|
---|
| 57 |
|
---|
| 58 | /*
|
---|
| 59 | ======================================================================
|
---|
| 60 | print_vmaps1()
|
---|
| 61 |
|
---|
| 62 | Print vmap values for a layer, looping through the vmaps.
|
---|
| 63 |
|
---|
| 64 | for each vmap
|
---|
| 65 | print vmap statistics
|
---|
| 66 | for each mapped point
|
---|
| 67 | print point index and position
|
---|
| 68 | if vmad, print polygon index and vertex number
|
---|
| 69 | print vmap values
|
---|
| 70 | ====================================================================== */
|
---|
| 71 |
|
---|
| 72 | static void print_vmaps1( FILE *fp, lwLayer *layer )
|
---|
| 73 | {
|
---|
| 74 | lwPoint *pt;
|
---|
| 75 | lwVMap *vmap;
|
---|
| 76 | char *tag;
|
---|
| 77 | unsigned int i, j, k, n;
|
---|
| 78 |
|
---|
| 79 | fprintf( fp, "\n\nVertex Maps (%d)\n\n", layer->vmaps.size() );
|
---|
| 80 |
|
---|
| 81 | for ( i = 0; i < layer->vmaps.size(); i++ )
|
---|
| 82 | {
|
---|
| 83 | vmap = layer->vmaps[i];
|
---|
| 84 |
|
---|
| 85 | tag = ( char * ) &vmap->type;
|
---|
| 86 |
|
---|
| 87 | fprintf( fp, "%c%c%c%c \"%s\" dim %d nverts %d vmad (%s)\n",
|
---|
| 88 | tag[ 3 ], tag[ 2 ], tag[ 1 ], tag[ 0 ],
|
---|
| 89 | vmap->name,
|
---|
| 90 | vmap->dim,
|
---|
| 91 | vmap->nverts,
|
---|
| 92 | vmap->perpoly ? "yes" : "no" );
|
---|
| 93 |
|
---|
| 94 | printf( "%c%c%c%c \"%s\" dim %d nverts %d vmad (%s)\n",
|
---|
| 95 | tag[ 3 ], tag[ 2 ], tag[ 1 ], tag[ 0 ],
|
---|
| 96 | vmap->name,
|
---|
| 97 | vmap->dim,
|
---|
| 98 | vmap->nverts,
|
---|
| 99 | vmap->perpoly ? "yes" : "no" );
|
---|
| 100 |
|
---|
| 101 | for ( j = 0; j < vmap->nverts; j++ ) {
|
---|
| 102 | /* point index */
|
---|
| 103 | fprintf( fp, " point %d ", vmap->vindex[ j ] );
|
---|
| 104 |
|
---|
| 105 | /* if vmad */
|
---|
| 106 | if ( vmap->perpoly ) {
|
---|
| 107 | lwPolygon *pol;
|
---|
| 108 |
|
---|
| 109 | /* polygon index */
|
---|
| 110 | k = vmap->pindex[ j ];
|
---|
| 111 | fprintf( fp, " poly %d ", k );
|
---|
| 112 |
|
---|
| 113 | /* vertex index */
|
---|
| 114 | pol = layer->polygons[ k ];
|
---|
| 115 | for ( n = 0; n < pol->vertices.size(); n++ )
|
---|
| 116 | if ( pol->vertices[ n ]->index == vmap->vindex[ j ] ) break;
|
---|
| 117 | fprintf( fp, " vert %d ", n );
|
---|
| 118 | }
|
---|
| 119 |
|
---|
| 120 | /* point coords */
|
---|
| 121 | pt = layer->points[ vmap->vindex[ j ]];
|
---|
| 122 | fprintf( fp, " (%g, %g, %g) ", pt->x, pt->y, pt->z );
|
---|
| 123 |
|
---|
| 124 | /* vmap values */
|
---|
| 125 | for ( k = 0; k < vmap->dim; k++ )
|
---|
| 126 | fprintf( fp, " %g", vmap->val[ j ][ k ] );
|
---|
| 127 |
|
---|
| 128 | /* done with this point */
|
---|
| 129 | fprintf( fp, "\n" );
|
---|
| 130 | }
|
---|
| 131 | /* done with this vmap */
|
---|
| 132 | fprintf( fp, "\n" );
|
---|
| 133 | }
|
---|
| 134 | /* done with this layer */
|
---|
| 135 | fprintf( fp, "\n\n" );
|
---|
| 136 | }
|
---|
| 137 |
|
---|
| 138 |
|
---|
| 139 | /*
|
---|
| 140 | ======================================================================
|
---|
| 141 | print_vmaps2()
|
---|
| 142 |
|
---|
| 143 | Print vmap values for a layer, looping through the points.
|
---|
| 144 |
|
---|
| 145 | for each point
|
---|
| 146 | print point index, position, number of vmaps, polygon indexes
|
---|
| 147 | for each vmap on the point
|
---|
| 148 | print vmap name, type and values
|
---|
| 149 | ====================================================================== */
|
---|
| 150 |
|
---|
| 151 | static void print_vmaps2( FILE *fp, lwLayer *layer )
|
---|
| 152 | {
|
---|
| 153 | lwPoint *pt;
|
---|
| 154 | lwVMap *vmap;
|
---|
| 155 | char *tag;
|
---|
| 156 | unsigned int i, j, k, n;
|
---|
| 157 |
|
---|
| 158 | fprintf( fp, "\n\nPoints (%d)\n\n", layer->points.size() );
|
---|
| 159 |
|
---|
| 160 | for ( i = 0; i < layer->points.size(); i++ ) {
|
---|
| 161 | pt = layer->points[ i ];
|
---|
| 162 |
|
---|
| 163 | /* point index and position */
|
---|
| 164 | fprintf( fp, "%d (%g, %g, %g)", i, pt->x, pt->y, pt->z );
|
---|
| 165 |
|
---|
| 166 | /* number of vmaps and polygons */
|
---|
| 167 | fprintf( fp, " nvmaps %d npolygons %d", pt->vmaps.size(), pt->polygons.size() );
|
---|
| 168 |
|
---|
| 169 | /* polygon indexes */
|
---|
| 170 | fprintf( fp, " [" );
|
---|
| 171 | for ( j = 0; j < pt->polygons.size(); j++ )
|
---|
| 172 | fprintf( fp, " %d", pt->polygons[ j ] );
|
---|
| 173 | fprintf( fp, "]\n" );
|
---|
| 174 |
|
---|
| 175 | /* vmaps for this point */
|
---|
| 176 | for ( j = 0; j < pt->vmaps.size(); j++ ) {
|
---|
| 177 | vmap = pt->vmaps[ j ].vmap;
|
---|
| 178 | n = pt->vmaps[ j ].index;
|
---|
| 179 |
|
---|
| 180 | tag = ( char * ) &vmap->type;
|
---|
| 181 |
|
---|
| 182 | fprintf( fp, " %c%c%c%c \"%s\" vmad (%s)",
|
---|
| 183 | tag[ 3 ], tag[ 2 ], tag[ 1 ], tag[ 0 ], vmap->name,
|
---|
| 184 | vmap->perpoly ? "yes" : "no" );
|
---|
| 185 |
|
---|
| 186 | /* vmap values */
|
---|
| 187 | for ( k = 0; k < vmap->dim; k++ )
|
---|
| 188 | fprintf( fp, " %g", vmap->val[ n ][ k ] );
|
---|
| 189 |
|
---|
| 190 | /* done with this vmap */
|
---|
| 191 | fprintf( fp, "\n" );
|
---|
| 192 | }
|
---|
| 193 | /* done with this point */
|
---|
| 194 | fprintf( fp, "\n" );
|
---|
| 195 | }
|
---|
| 196 | /* done with this layer */
|
---|
| 197 | fprintf( fp, "\n\n" );
|
---|
| 198 | }
|
---|
| 199 |
|
---|
| 200 |
|
---|
| 201 | /*
|
---|
| 202 | ======================================================================
|
---|
| 203 | print_vmaps3()
|
---|
| 204 |
|
---|
| 205 | Print vmap values for a layer, looping through the polygons.
|
---|
| 206 |
|
---|
| 207 | for each polygon
|
---|
| 208 | print polygon index, number of points
|
---|
| 209 | for each vertex
|
---|
| 210 | print point index, position, number of vmaps
|
---|
| 211 | for each vmap on the point
|
---|
| 212 | print vmap name, type and values
|
---|
| 213 | ====================================================================== */
|
---|
| 214 |
|
---|
| 215 | static void print_vmaps3( FILE *fp, lwLayer *layer )
|
---|
| 216 | {
|
---|
| 217 | lwPoint *pt;
|
---|
| 218 | lwPolygon *pol;
|
---|
| 219 | lwVMap *vmap;
|
---|
| 220 | char *tag;
|
---|
| 221 | unsigned int i, j, k, m, n;
|
---|
| 222 |
|
---|
| 223 | fprintf( fp, "\n\nPolygons (%d)\n\n", layer->polygons.size() );
|
---|
| 224 |
|
---|
| 225 | for ( i = 0; i < layer->polygons.size(); i++ ) {
|
---|
| 226 | pol = layer->polygons[ i ];
|
---|
| 227 |
|
---|
| 228 | /* polygon index, type, number of vertices */
|
---|
| 229 | tag = ( char * ) &pol->type;
|
---|
| 230 | fprintf( fp, "%d %c%c%c%c nverts %d\n", i,
|
---|
| 231 | tag[ 3 ], tag[ 2 ], tag[ 1 ], tag[ 0 ], pol->vertices.size() );
|
---|
| 232 |
|
---|
| 233 | for ( k = 0; k < pol->vertices.size(); k++ ) {
|
---|
| 234 | /* point index, position, number of vmads and vmaps */
|
---|
| 235 | n = pol->vertices[ k ]->index;
|
---|
| 236 | pt = layer->points[ n ];
|
---|
| 237 | fprintf( fp, "%d (%g, %g, %g) nvmads %d nvmaps %d\n", n,
|
---|
| 238 | pt->x, pt->y, pt->z,
|
---|
| 239 | pol->vertices[ k ]->vmaps.size(), pt->vmaps.size() - pol->vertices[ k ]->vmaps.size() );
|
---|
| 240 |
|
---|
| 241 | /* vmads for this vertex */
|
---|
| 242 | for ( j = 0; j < pol->vertices[ k ]->vmaps.size(); j++ ) {
|
---|
| 243 | vmap = pol->vertices[ k ]->vmaps[ j ].vmap;
|
---|
| 244 | n = pol->vertices[ k ]->vmaps[ j ].index;
|
---|
| 245 |
|
---|
| 246 | tag = ( char * ) &vmap->type;
|
---|
| 247 | fprintf( fp, " %c%c%c%c vmad \"%s\"",
|
---|
| 248 | tag[ 3 ], tag[ 2 ], tag[ 1 ], tag[ 0 ], vmap->name );
|
---|
| 249 |
|
---|
| 250 | /* vmap values */
|
---|
| 251 | for ( m = 0; m < vmap->dim; m++ )
|
---|
| 252 | fprintf( fp, " %g", vmap->val[ m ][ n ] );
|
---|
| 253 |
|
---|
| 254 | /* done with this vmad */
|
---|
| 255 | fprintf( fp, "\n" );
|
---|
| 256 | }
|
---|
| 257 |
|
---|
| 258 | /* vmaps for this vertex */
|
---|
| 259 | for ( j = 0; j < pt->vmaps.size(); j++ ) {
|
---|
| 260 | vmap = pt->vmaps[ j ].vmap;
|
---|
| 261 | if ( vmap->perpoly ) continue;
|
---|
| 262 | n = pt->vmaps[ j ].index;
|
---|
| 263 |
|
---|
| 264 | tag = ( char * ) &vmap->type;
|
---|
| 265 | fprintf( fp, " %c%c%c%c vmap \"%s\"",
|
---|
| 266 | tag[ 3 ], tag[ 2 ], tag[ 1 ], tag[ 0 ], vmap->name );
|
---|
| 267 |
|
---|
| 268 | /* vmap values */
|
---|
| 269 | for ( m = 0; m < vmap->dim; m++ )
|
---|
| 270 | fprintf( fp, " %g", vmap->val[ m ][ n ] );
|
---|
| 271 |
|
---|
| 272 | /* done with this vmap */
|
---|
| 273 | fprintf( fp, "\n" );
|
---|
| 274 | }
|
---|
| 275 |
|
---|
| 276 | /* done with this vertex */
|
---|
| 277 | if ( pt->vmaps.size() )
|
---|
| 278 | fprintf( fp, "\n" );
|
---|
| 279 | }
|
---|
| 280 | /* done with this polygon */
|
---|
| 281 | fprintf( fp, "\n" );
|
---|
| 282 | }
|
---|
| 283 | /* done with this layer */
|
---|
| 284 | fprintf( fp, "\n\n" );
|
---|
| 285 | }
|
---|
| 286 |
|
---|
| 287 |
|
---|
| 288 | /*
|
---|
| 289 | ======================================================================
|
---|
| 290 | print_vmaps()
|
---|
| 291 |
|
---|
| 292 | Print vmap values for a layer.
|
---|
| 293 |
|
---|
| 294 | Calls print_vmaps1(), print_vmaps2() and print_vmaps3().
|
---|
| 295 | ====================================================================== */
|
---|
| 296 |
|
---|
| 297 | void print_vmaps( lwObject *obj )
|
---|
| 298 | {
|
---|
| 299 | FILE *fp[ 3 ];
|
---|
| 300 | char buf[ 64 ];
|
---|
| 301 | lwLayer *layer;
|
---|
| 302 | unsigned int i, j;
|
---|
| 303 |
|
---|
| 304 | for ( i = 0; i < 3; i++ ) {
|
---|
| 305 | sprintf( buf, "vmapout%d.txt", i + 1 );
|
---|
| 306 | fp[ i ] = fopen( buf, "w" );
|
---|
| 307 | if ( !fp[ i ] ) {
|
---|
| 308 | for ( j = i - 1; j >= 0; j-- )
|
---|
| 309 | fclose( fp[ j ] );
|
---|
| 310 | return;
|
---|
| 311 | }
|
---|
| 312 | }
|
---|
| 313 |
|
---|
| 314 | for ( i = 0; i < obj->layers.size(); i++ )
|
---|
| 315 | {
|
---|
| 316 | layer = obj->layers[i];
|
---|
| 317 |
|
---|
| 318 | fprintf( fp[ 0 ], "------------------------\nLayer %d\n", i );
|
---|
| 319 | print_vmaps1( fp[ 0 ], layer );
|
---|
| 320 |
|
---|
| 321 | fprintf( fp[ 1 ], "------------------------\nLayer %d\n", i );
|
---|
| 322 | print_vmaps2( fp[ 1 ], layer );
|
---|
| 323 |
|
---|
| 324 | fprintf( fp[ 2 ], "------------------------\nLayer %d\n", i );
|
---|
| 325 | print_vmaps3( fp[ 2 ], layer );
|
---|
| 326 | }
|
---|
| 327 |
|
---|
| 328 | for ( i = 0; i < 3; i++ )
|
---|
| 329 | fclose( fp[ i ] );
|
---|
| 330 | }
|
---|
| 331 |
|
---|
| 332 | int make_filename( char *spec, char *name, char *fullname )
|
---|
| 333 | {
|
---|
| 334 | char
|
---|
| 335 | drive[ _MAX_DRIVE ],
|
---|
| 336 | dir[ _MAX_DIR ],
|
---|
| 337 | node[ _MAX_FNAME ],
|
---|
| 338 | ext[ _MAX_EXT ];
|
---|
| 339 |
|
---|
| 340 | _splitpath( spec, drive, dir, node, ext );
|
---|
| 341 | _makepath( fullname, drive, dir, name, NULL );
|
---|
| 342 | return 1;
|
---|
| 343 | }
|
---|
| 344 |
|
---|
| 345 | int make_destname( char *spec, char *name, char *fullname )
|
---|
| 346 | {
|
---|
| 347 | char
|
---|
| 348 | drive[ _MAX_DRIVE ],
|
---|
| 349 | dir[ _MAX_DIR ],
|
---|
| 350 | node[ _MAX_FNAME ],
|
---|
| 351 | ext[ _MAX_EXT ],
|
---|
| 352 | dnode[ _MAX_FNAME ];
|
---|
| 353 |
|
---|
| 354 | _splitpath( name, drive, dir, dnode, ext );
|
---|
| 355 | _splitpath( spec, drive, dir, node, ext );
|
---|
| 356 | _makepath( fullname, drive, dir, dnode, ".mesh" );
|
---|
| 357 | return 1;
|
---|
| 358 | }
|
---|
| 359 |
|
---|
| 360 | int make_filespec( char *spec, char *subdir, char *fullname )
|
---|
| 361 | {
|
---|
| 362 | char
|
---|
| 363 | name[ _MAX_FNAME ],
|
---|
| 364 | drive[ _MAX_DRIVE ],
|
---|
| 365 | dir[ _MAX_DIR ],
|
---|
| 366 | node[ _MAX_FNAME ],
|
---|
| 367 | ext[ _MAX_EXT ];
|
---|
| 368 |
|
---|
| 369 | _splitpath( spec, drive, dir, node, ext );
|
---|
| 370 | _makepath( name, drive, dir, subdir, NULL );
|
---|
| 371 | _makepath( fullname, NULL, name, node, ext );
|
---|
| 372 | return 1;
|
---|
| 373 | }
|
---|
| 374 |
|
---|
| 375 | void help( char *filename )
|
---|
| 376 | {
|
---|
| 377 | cout << "lwo2mesh v0.89a (2004.10.05) by Dennis Verbeek." << nl
|
---|
| 378 | << "Converts a Lightwave object to an Ogre mesh." << nl
|
---|
| 379 | << "Please send any feedback to: dennis.verbeek@chello.nl" << nl << nl
|
---|
| 380 | #if OGRE_PLATFORM == OGRE_PLATFORM_LINUX
|
---|
| 381 | << "Linux Port (2004.10.16) by Magnus Møller Petersen." << nl
|
---|
| 382 | << "Please send feedback concerning Linux to: magnus@moaner.dk" << nl << nl
|
---|
| 383 | #endif
|
---|
| 384 | << "Usage: " << filename << " [options] source [dest]" << nl
|
---|
| 385 | << "options:" << nl
|
---|
| 386 | << "-g do not use shared geometry" << nl
|
---|
| 387 | << "-d generate level of detail information" << nl
|
---|
| 388 | << " method (f)ixed or (p)roportional" << nl
|
---|
| 389 | << " reduction (fixed) or reductionfactor (proportional)" << nl
|
---|
| 390 | << " number of LOD levels" << nl
|
---|
| 391 | << " distances" << nl
|
---|
| 392 | << " example: -dp 0.5 4 1000.0 2000.0 4000.0 8000.0" << nl
|
---|
| 393 | << "-l save layers separately" << nl
|
---|
| 394 | << "-m do not export materials" << nl
|
---|
| 395 | << "-r rename materials" << nl
|
---|
| 396 | << " method (i)nteractive, (o)bjectname or (p)refix" << nl
|
---|
| 397 | << " example: -rp prefix_" << nl
|
---|
| 398 | << "-s do not export skeleton" << nl
|
---|
| 399 | << "-i info on .lwo only, no conversion to mesh" << nl
|
---|
| 400 | << " -v dump vertex maps" << endl;
|
---|
| 401 | exit(0);
|
---|
| 402 | }
|
---|
| 403 |
|
---|
| 404 | void info(lwObject *object, char *filename)
|
---|
| 405 | {
|
---|
| 406 | unsigned int points = 0;
|
---|
| 407 | unsigned int polygons = 0;
|
---|
| 408 |
|
---|
| 409 | nlayers += object->layers.size();
|
---|
| 410 | nsurfs += object->surfaces.size();
|
---|
| 411 | nclips += object->clips.size();
|
---|
| 412 | nenvs += object->envelopes.size();
|
---|
| 413 |
|
---|
| 414 | cout << "File: " << filename << nl
|
---|
| 415 | << setw(8) << object->layers.size() << " layers" << nl
|
---|
| 416 | << setw(8) << object->surfaces.size() << " surfaces" << nl
|
---|
| 417 | << setw(8) << object->clips.size() << " clips" << nl
|
---|
| 418 | << setw(8) << object->envelopes.size() << " envelopes" << endl;
|
---|
| 419 |
|
---|
| 420 | if (object->layers.size() > 1)
|
---|
| 421 | {
|
---|
| 422 | for( unsigned int i = 0; i < object->layers.size(); i++ )
|
---|
| 423 | {
|
---|
| 424 | points += object->layers[i]->points.size();
|
---|
| 425 | cout << setw(8) << object->layers[i]->points.size() << " points (layer " << i;
|
---|
| 426 |
|
---|
| 427 | if (object->layers[i]->name)
|
---|
| 428 | cout << ", " << object->layers[i]->name << ")" << endl;
|
---|
| 429 | else
|
---|
| 430 | cout << ")" << endl;
|
---|
| 431 |
|
---|
| 432 | polygons += object->layers[i]->polygons.size();
|
---|
| 433 | cout << setw(8) << object->layers[i]->polygons.size() << " polygons (layer " << i;
|
---|
| 434 |
|
---|
| 435 | if (object->layers[i]->name)
|
---|
| 436 | cout << ", " << object->layers[i]->name << ")" << endl;
|
---|
| 437 | else
|
---|
| 438 | cout << ")" << endl;
|
---|
| 439 | }
|
---|
| 440 | }
|
---|
| 441 | else
|
---|
| 442 | {
|
---|
| 443 | points += object->layers[0]->points.size();
|
---|
| 444 | polygons += object->layers[0]->polygons.size();
|
---|
| 445 | }
|
---|
| 446 |
|
---|
| 447 | cout << setw(8) << points << " points (total)" << nl
|
---|
| 448 | << setw(8) << polygons << " polygons (total)" << nl << endl;
|
---|
| 449 |
|
---|
| 450 | nobjects++;
|
---|
| 451 | npoints += points;
|
---|
| 452 | npolygons += polygons;
|
---|
| 453 |
|
---|
| 454 | if (flags[PrintVMaps])
|
---|
| 455 | print_vmaps( object );
|
---|
| 456 | }
|
---|
| 457 |
|
---|
| 458 | #if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
|
---|
| 459 | int readFiles( char *source, char *dest)
|
---|
| 460 | {
|
---|
| 461 | long h, err;
|
---|
| 462 | struct _finddata_t data;
|
---|
| 463 | char *filename, *prevname, *destname;
|
---|
| 464 | unsigned int failID;
|
---|
| 465 | int failpos;
|
---|
| 466 | lwReader reader;
|
---|
| 467 | Lwo2MeshWriter lwo2mesh;
|
---|
| 468 |
|
---|
| 469 | filename = (char *)malloc(3 * 512);
|
---|
| 470 | if ( !filename ) return 0;
|
---|
| 471 | prevname = filename + 512;
|
---|
| 472 | destname = filename + 1024;
|
---|
| 473 |
|
---|
| 474 | err = h = _findfirst( source, &data );
|
---|
| 475 | if ( err == -1 )
|
---|
| 476 | {
|
---|
| 477 | printf( "No files found: '%s'\n", source );
|
---|
| 478 | return 0;
|
---|
| 479 | }
|
---|
| 480 |
|
---|
| 481 | while ( err != -1 )
|
---|
| 482 | {
|
---|
| 483 | if (( data.attrib & _A_SUBDIR ) && data.name[ 0 ] != '.' )
|
---|
| 484 | {
|
---|
| 485 | make_filespec( source, data.name, filename );
|
---|
| 486 | readFiles( filename, dest );
|
---|
| 487 | }
|
---|
| 488 | if ( !( data.attrib & _A_SUBDIR ))
|
---|
| 489 | {
|
---|
| 490 | make_filename( source, data.name, filename );
|
---|
| 491 |
|
---|
| 492 | if ( !strcmp( filename, prevname )) break;
|
---|
| 493 | strcpy( prevname, filename );
|
---|
| 494 | failID = failpos = 0;
|
---|
| 495 |
|
---|
| 496 | lwObject *object = reader.readObjectFromFile( filename );
|
---|
| 497 | if ( object )
|
---|
| 498 | {
|
---|
| 499 | if (flags[InfoOnly])
|
---|
| 500 | info(object, filename);
|
---|
| 501 | else
|
---|
| 502 | {
|
---|
| 503 | make_destname( dest, data.name, destname );
|
---|
| 504 | lwo2mesh.writeLwo2Mesh(object, destname);
|
---|
| 505 | }
|
---|
| 506 | delete object;
|
---|
| 507 | }
|
---|
| 508 | }
|
---|
| 509 | err = _findnext( h, &data );
|
---|
| 510 | }
|
---|
| 511 |
|
---|
| 512 | _findclose( h );
|
---|
| 513 | free (filename);
|
---|
| 514 | return 1;
|
---|
| 515 | }
|
---|
| 516 | #elif OGRE_PLATFORM == OGRE_PLATFORM_LINUX
|
---|
| 517 | int readFiles( char *source, char *dest ) {
|
---|
| 518 | return 1;
|
---|
| 519 | }
|
---|
| 520 | #else
|
---|
| 521 | #define readFiles( a, b )
|
---|
| 522 | #endif
|
---|
| 523 |
|
---|
| 524 | int main( int argc, char *argv[] )
|
---|
| 525 | {
|
---|
| 526 | int i = 1;
|
---|
| 527 | unsigned int ndistances = 0;
|
---|
| 528 | Real distance = 0;
|
---|
| 529 | char *source = 0;
|
---|
| 530 | char *dest = 0;
|
---|
| 531 |
|
---|
| 532 | if ( argc < 2 ) help(argv[0]);
|
---|
| 533 |
|
---|
| 534 | while (i < argc)
|
---|
| 535 | {
|
---|
| 536 | if (argv[i][0] == '-' || argv[i][0] == '/')
|
---|
| 537 | {
|
---|
| 538 | switch (argv[i++][1])
|
---|
| 539 | {
|
---|
| 540 | case 'd':
|
---|
| 541 | case 'D':
|
---|
| 542 | i--;
|
---|
| 543 | flags[GenerateLOD] = true;
|
---|
| 544 | switch (argv[i++][2])
|
---|
| 545 | {
|
---|
| 546 | case 'f':
|
---|
| 547 | case 'F':
|
---|
| 548 | flags[UseFixedMethod] = true;
|
---|
| 549 | break;
|
---|
| 550 | case 'p':
|
---|
| 551 | case 'P':
|
---|
| 552 | flags[UseFixedMethod] = false;
|
---|
| 553 | break;
|
---|
| 554 | default:
|
---|
| 555 | help(argv[0]);
|
---|
| 556 | }
|
---|
| 557 | try
|
---|
| 558 | {
|
---|
| 559 | reduction = atof(argv[i++]);
|
---|
| 560 | ndistances = atoi(argv[i++]);
|
---|
| 561 | while (ndistances > 0)
|
---|
| 562 | {
|
---|
| 563 | if (i < argc && argv[i][0] != '-' && argv[i][0] != '/')
|
---|
| 564 | distanceList.push_back(atof(argv[i++]));
|
---|
| 565 | else
|
---|
| 566 | ndistances = 0;
|
---|
| 567 | ndistances--;
|
---|
| 568 | }
|
---|
| 569 | }
|
---|
| 570 | catch (Exception *e)
|
---|
| 571 | {
|
---|
| 572 | ndistances = 0;
|
---|
| 573 | distanceList.clear();
|
---|
| 574 | flags[GenerateLOD] = false;
|
---|
| 575 | }
|
---|
| 576 | break;
|
---|
| 577 | case 'g':
|
---|
| 578 | case 'G':
|
---|
| 579 | flags[UseSharedVertexData] = false;
|
---|
| 580 | break;
|
---|
| 581 | case 'i':
|
---|
| 582 | case 'I':
|
---|
| 583 | flags[InfoOnly] = true;
|
---|
| 584 | break;
|
---|
| 585 | case 'l':
|
---|
| 586 | case 'L':
|
---|
| 587 | flags[UseSeparateLayers] = true;
|
---|
| 588 | break;
|
---|
| 589 | case 'm':
|
---|
| 590 | case 'M':
|
---|
| 591 | flags[ExportMaterials] = false;
|
---|
| 592 | break;
|
---|
| 593 | case 'r':
|
---|
| 594 | case 'R':
|
---|
| 595 | flags[RenameMaterials] = true;
|
---|
| 596 | if (strlen(argv[i-1]) > 2) {
|
---|
| 597 | i--;
|
---|
| 598 | switch (argv[i++][2])
|
---|
| 599 | {
|
---|
| 600 | case 'i':
|
---|
| 601 | case 'I':
|
---|
| 602 | flags[UseInteractiveMethod] = true;
|
---|
| 603 | break;
|
---|
| 604 | case 'o':
|
---|
| 605 | case 'O':
|
---|
| 606 | flags[UseObjectMethod] = true; // default
|
---|
| 607 | break;
|
---|
| 608 | case 'p':
|
---|
| 609 | case 'P':
|
---|
| 610 | flags[UsePrefixMethod] = true;
|
---|
| 611 | if (argv[i][0] != '-' && argv[i][0] != '/')
|
---|
| 612 | matPrefix = argv[i++];
|
---|
| 613 | else
|
---|
| 614 | help(argv[0]);
|
---|
| 615 | break;
|
---|
| 616 | default:
|
---|
| 617 | help(argv[0]);
|
---|
| 618 | }
|
---|
| 619 | }
|
---|
| 620 | break;
|
---|
| 621 | case 's':
|
---|
| 622 | case 'S':
|
---|
| 623 | flags[ExportSkeleton] = false;
|
---|
| 624 | break;
|
---|
| 625 | case 'v':
|
---|
| 626 | case 'V':
|
---|
| 627 | flags[PrintVMaps] = true;
|
---|
| 628 | break;
|
---|
| 629 | default:
|
---|
| 630 | help(argv[0]);
|
---|
| 631 | }
|
---|
| 632 | }
|
---|
| 633 | else
|
---|
| 634 | {
|
---|
| 635 | if (!source) source = argv[i];
|
---|
| 636 | else
|
---|
| 637 | if (!dest) dest = argv[i];
|
---|
| 638 | i++;
|
---|
| 639 | }
|
---|
| 640 | }
|
---|
| 641 |
|
---|
| 642 | if ( !source ) help(argv[0]);
|
---|
| 643 |
|
---|
| 644 | if (!dest) dest = "\0";
|
---|
| 645 |
|
---|
| 646 | float t1, t2;
|
---|
| 647 |
|
---|
| 648 | t1 = ( float ) clock() / CLOCKS_PER_SEC;
|
---|
| 649 |
|
---|
| 650 | if (!flags[InfoOnly])
|
---|
| 651 | {
|
---|
| 652 | logMgr = new LogManager();
|
---|
| 653 | mth = new Math();
|
---|
| 654 | matMgr = new MaterialManager();
|
---|
| 655 | matMgr->initialise();
|
---|
| 656 | meshMgr = new MeshManager();
|
---|
| 657 | skelMgr = new SkeletonManager();
|
---|
| 658 | meshSerializer = new MeshSerializer();
|
---|
| 659 | materialSerializer = new MaterialSerializer();
|
---|
| 660 | skeletonSerializer = new SkeletonSerializer();
|
---|
| 661 | bufferManager = new DefaultHardwareBufferManager(); // needed because we don't have a rendersystem
|
---|
| 662 | }
|
---|
| 663 |
|
---|
| 664 | if ( strchr(source, '*') )
|
---|
| 665 | // On Linux this will only be called if you pass the source argument in
|
---|
| 666 | // quotation marks (e.g. as LightwaveConverter "abc..*" ). Otherwise the
|
---|
| 667 | // shell will expand the arguments. At least, this is how it works with
|
---|
| 668 | // bash.
|
---|
| 669 | readFiles( source, dest );
|
---|
| 670 | else
|
---|
| 671 | {
|
---|
| 672 | lwReader reader;
|
---|
| 673 | lwObject *object = reader.readObjectFromFile(source);
|
---|
| 674 | if ( object )
|
---|
| 675 | {
|
---|
| 676 | if (flags[InfoOnly])
|
---|
| 677 | info(object, source);
|
---|
| 678 | else
|
---|
| 679 | {
|
---|
| 680 | char *destname = (char *)malloc(512);
|
---|
| 681 | if ( !destname ) return 1;
|
---|
| 682 |
|
---|
| 683 | if (strlen(dest))
|
---|
| 684 | make_destname(dest, dest, destname);
|
---|
| 685 | else
|
---|
| 686 | make_destname(dest, source, destname);
|
---|
| 687 |
|
---|
| 688 | Lwo2MeshWriter lwo2mesh;
|
---|
| 689 | lwo2mesh.writeLwo2Mesh(object, destname);
|
---|
| 690 | free(destname);
|
---|
| 691 | }
|
---|
| 692 | delete object;
|
---|
| 693 | }
|
---|
| 694 | }
|
---|
| 695 |
|
---|
| 696 | t2 = ( float ) clock() / CLOCKS_PER_SEC - t1;
|
---|
| 697 |
|
---|
| 698 | if (flags[InfoOnly])
|
---|
| 699 | {
|
---|
| 700 | cout << "Total:" << nl
|
---|
| 701 | << setw(8) << nobjects << " objects" << nl
|
---|
| 702 | << setw(8) << nlayers << " layers" << nl
|
---|
| 703 | << setw(8) << nsurfs << " surfaces" << nl
|
---|
| 704 | << setw(8) << nclips << " clips" << nl
|
---|
| 705 | << setw(8) << nenvs << " envelopes" << nl
|
---|
| 706 | << setw(8) << npoints << " points" << nl
|
---|
| 707 | << setw(8) << npolygons << " polygons" << nl
|
---|
| 708 | << setw(8) << t2 << " seconds processing time." << endl;
|
---|
| 709 | }
|
---|
| 710 | else
|
---|
| 711 | {
|
---|
| 712 | delete bufferManager;
|
---|
| 713 | delete skeletonSerializer;
|
---|
| 714 | delete materialSerializer;
|
---|
| 715 | delete meshSerializer;
|
---|
| 716 | delete meshMgr;
|
---|
| 717 | delete skelMgr;
|
---|
| 718 | delete matMgr;
|
---|
| 719 | delete mth;
|
---|
| 720 | delete logMgr;
|
---|
| 721 | }
|
---|
| 722 |
|
---|
| 723 | return 0;
|
---|
| 724 |
|
---|
| 725 | }
|
---|