diff --git a/src/osgPlugins/lib3ds/ReaderWriter3DS.cpp b/src/osgPlugins/lib3ds/ReaderWriter3DS.cpp index 09bfed419..e9b8ced53 100644 --- a/src/osgPlugins/lib3ds/ReaderWriter3DS.cpp +++ b/src/osgPlugins/lib3ds/ReaderWriter3DS.cpp @@ -26,6 +26,7 @@ #include "matrix.h" #include "node.h" #include "quat.h" +#include "readwrite.h" #include #include @@ -126,6 +127,27 @@ osgDB::RegisterReaderWriterProxy g_readerWriter_3DS_Proxy; ReaderWriter3DS::ReaderWriter3DS() { + setByteOrder(); + +#if 0 + osg::notify(osg::NOTICE)<<"3DS reader sizes:"<name<name<nodes; node; node=node->next) { print(node,level+1); } - std::cout << "MESH TRAVERSAL of file "<name<name<meshes; mesh; mesh=mesh->next) { print(mesh,level+1); } - }*/ - + } // We can traverse by meshes (old method, broken for pivot points, but otherwise works), or by nodes (new method, not so well tested yet) // if your model is broken, especially wrt object positions try setting this flag. If that fixes it, @@ -481,11 +504,12 @@ osgDB::ReaderWriter::ReadResult ReaderWriter3DS::readNode(const std::string& fil } } - - /*cout << "Final OSG node structure looks like this:"<< endl; - PrintVisitor pv; - group->accept(pv);*/ - +; if (osg::getNotifyLevel()>=osg::INFO) + { + osg::notify(osg::NOTICE) << "Final OSG node structure looks like this:"<< endl; + PrintVisitor pv(osg::notify(osg::NOTICE)); + group->accept(pv); + } lib3ds_file_free(f); @@ -639,8 +663,10 @@ osg::Drawable* ReaderWriter3DS::ReaderObject::createDrawable(Lib3dsMesh *m,Fac geom->addPrimitiveSet(elements); +#if 0 osgUtil::TriStripVisitor tsv; tsv.stripify(*geom); +#endif return geom; } diff --git a/src/osgPlugins/lib3ds/chunk.cpp b/src/osgPlugins/lib3ds/chunk.cpp index bc0a12b4e..457eb4fc9 100644 --- a/src/osgPlugins/lib3ds/chunk.cpp +++ b/src/osgPlugins/lib3ds/chunk.cpp @@ -61,7 +61,7 @@ static void lib3ds_chunk_debug_dump(Lib3dsChunk *c) { if (enable_dump) { - printf("%s%s (0x%X) size=%lu\n", + printf("%s%s (0x%X) size=%u\n", lib3ds_chunk_level, lib3ds_chunk_name(c->chunk), c->chunk, diff --git a/src/osgPlugins/lib3ds/mesh.cpp b/src/osgPlugins/lib3ds/mesh.cpp index a27743828..cd13aed00 100644 --- a/src/osgPlugins/lib3ds/mesh.cpp +++ b/src/osgPlugins/lib3ds/mesh.cpp @@ -495,7 +495,7 @@ lib3ds_mesh_dump(Lib3dsMesh *mesh) Lib3dsVector p; ASSERT(mesh); - printf(" %s vertices=%ld faces=%ld\n", + printf(" %s vertices=%d faces=%d\n", mesh->name, mesh->points, mesh->faces diff --git a/src/osgPlugins/lib3ds/readwrite.cpp b/src/osgPlugins/lib3ds/readwrite.cpp index d555dd14d..cf03edbd5 100644 --- a/src/osgPlugins/lib3ds/readwrite.cpp +++ b/src/osgPlugins/lib3ds/readwrite.cpp @@ -21,7 +21,7 @@ */ #define LIB3DS_EXPORT #include "readwrite.h" - +#include /*! * \defgroup readwrite Portable Binary Input/Ouput @@ -30,6 +30,15 @@ */ +static bool s_requiresByteSwap = false; + +extern LIB3DSAPI void setByteOrder() +{ + s_requiresByteSwap = osg::getCpuByteOrder()==osg::BigEndian; +} + + + /*! * \ingroup readwrite * @@ -129,13 +138,16 @@ Lib3dsIntw lib3ds_intw_read(FILE *f) { Lib3dsByte b[2]; - Lib3dsWord w; ASSERT(f); fread(b,2,1,f); - w=((Lib3dsWord)b[1] << 8) | - ((Lib3dsWord)b[0]); - return((Lib3dsIntw)w); + + if (s_requiresByteSwap) + { + osg::swapBytes2((char*)b); + } + + return (*((Lib3dsIntw*)b)); } @@ -152,15 +164,16 @@ Lib3dsIntd lib3ds_intd_read(FILE *f) { Lib3dsByte b[4]; - Lib3dsDword d; ASSERT(f); fread(b,4,1,f); - d=((Lib3dsDword)b[3] << 24) | - ((Lib3dsDword)b[2] << 16) | - ((Lib3dsDword)b[1] << 8) | - ((Lib3dsDword)b[0]); - return((Lib3dsIntd)d); + + if (s_requiresByteSwap) + { + osg::swapBytes4((char*)b); + } + + return (*((Lib3dsIntd*)b)); } @@ -177,15 +190,16 @@ Lib3dsFloat lib3ds_float_read(FILE *f) { Lib3dsByte b[4]; - Lib3dsDword d; ASSERT(f); fread(b,4,1,f); - d=((Lib3dsDword)b[3] << 24) | - ((Lib3dsDword)b[2] << 16) | - ((Lib3dsDword)b[1] << 8) | - ((Lib3dsDword)b[0]); - return(*((Lib3dsFloat*)&d)); + + if (s_requiresByteSwap) + { + osg::swapBytes4((char*)b); + } + + return (*((Lib3dsFloat*)b)); } @@ -210,6 +224,9 @@ lib3ds_vector_read(Lib3dsVector v, FILE *f) if (ferror(f)) { return(LIB3DS_FALSE); } + + /*printf("lib3ds_vector_read %f %f %f\n",v[0],v[1],v[2]);*/ + return(LIB3DS_TRUE); } @@ -227,6 +244,8 @@ lib3ds_rgb_read(Lib3dsRgb rgb, FILE *f) if (ferror(f)) { return(LIB3DS_FALSE); } + /*printf("lib3ds_rgb_read %f %f %f\n",rgb[0],rgb[1],rgb[2]);*/ + return(LIB3DS_TRUE); } diff --git a/src/osgPlugins/lib3ds/readwrite.h b/src/osgPlugins/lib3ds/readwrite.h index 64b7bb7a7..94b275c43 100644 --- a/src/osgPlugins/lib3ds/readwrite.h +++ b/src/osgPlugins/lib3ds/readwrite.h @@ -31,6 +31,8 @@ extern "C" { #endif +extern LIB3DSAPI void setByteOrder(); + extern LIB3DSAPI Lib3dsByte lib3ds_byte_read(FILE *f); extern LIB3DSAPI Lib3dsWord lib3ds_word_read(FILE *f); extern LIB3DSAPI Lib3dsDword lib3ds_dword_read(FILE *f); diff --git a/src/osgPlugins/lib3ds/types.h b/src/osgPlugins/lib3ds/types.h index 2d1b46d2f..ca2695c4b 100644 --- a/src/osgPlugins/lib3ds/types.h +++ b/src/osgPlugins/lib3ds/types.h @@ -45,11 +45,11 @@ extern "C" { typedef int Lib3dsBool; typedef unsigned char Lib3dsByte; -typedef unsigned short int Lib3dsWord; -typedef unsigned long Lib3dsDword; +typedef unsigned short Lib3dsWord; +typedef unsigned int Lib3dsDword; typedef signed char Lib3dsIntb; -typedef signed short int Lib3dsIntw; -typedef signed long Lib3dsIntd; +typedef signed short Lib3dsIntw; +typedef signed int Lib3dsIntd; typedef float Lib3dsFloat; typedef double Lib3dsDouble;