From 70d78c0713fceafc8b701f3ef8fe13da6356a644 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 15 Apr 2010 18:40:40 +0000 Subject: [PATCH] From Colin McDonald, "The new 3ds plugin isn't working at all on big-endian machines, due to a byte order issue. The problem is that osg::SwapBytes code has been copied from the old plugin to the new one, but the latest lib3ds also incorporates code to handle byte ordering in read & writing. So the net result is that the swap is done twice. The solution is simply to remove the custom osg code, and use the stock lib3ds code. The attached files are against today's revision 11331. I've tested on Sparc & Intel. " --- src/osgPlugins/3ds/ReaderWriter3DS.cpp | 1 - src/osgPlugins/3ds/lib3ds/lib3ds.h | 2 - src/osgPlugins/3ds/lib3ds/lib3ds_io.c | 73 +------------------------- 3 files changed, 1 insertion(+), 75 deletions(-) diff --git a/src/osgPlugins/3ds/ReaderWriter3DS.cpp b/src/osgPlugins/3ds/ReaderWriter3DS.cpp index b721f1210..db754bdf3 100644 --- a/src/osgPlugins/3ds/ReaderWriter3DS.cpp +++ b/src/osgPlugins/3ds/ReaderWriter3DS.cpp @@ -225,7 +225,6 @@ ReaderWriter3DS::ReaderWriter3DS() supportsOption("noMatrixTransforms", "(Read option) Set the plugin to apply matrices into the mesh vertices (\"old behaviour\") instead of restoring them (\"new behaviour\"). You may use this option to avoid a few rounding errors."); supportsOption("checkForEspilonIdentityMatrices", "(Read option) If not set, then consider \"almost identity\" matrices to be identity ones (in case of rounding errors)."); supportsOption("restoreMatrixTransformsNoMeshes", "(Read option) Makes an exception to the behaviour when 'noMatrixTransforms' is not set for mesh instances. When a mesh instance has a transform on it, the reader creates a MatrixTransform above the Geode. If you don't want the hierarchy to be modified, then you can use this option to merge the transform into vertices."); - setByteOrder(); #if 0 OSG_NOTIFY(osg::NOTICE)<<"3DS reader sizes:"< - -static bool s_requiresByteSwap = false; -extern LIB3DSAPI void setByteOrder() -{ - s_requiresByteSwap = osg::getCpuByteOrder()==osg::BigEndian; -} -/* --- (end) Code for OpenSceneGraph --- */ typedef union { uint32_t dword_value; @@ -171,12 +161,6 @@ lib3ds_io_read_word(Lib3dsIo *io) { lib3ds_io_read(io, b, 2); w = ((uint16_t)b[1] << 8) | ((uint16_t)b[0]); - /* --- Code for OpenSceneGraph --- */ - if (s_requiresByteSwap) - { - osg::swapBytes2((char*)&w); - } - /* --- (end) Code for OpenSceneGraph --- */ return(w); } @@ -195,12 +179,6 @@ lib3ds_io_read_dword(Lib3dsIo *io) { ((uint32_t)b[2] << 16) | ((uint32_t)b[1] << 8) | ((uint32_t)b[0]); - /* --- Code for OpenSceneGraph --- */ - if (s_requiresByteSwap) - { - osg::swapBytes4((char*)&d); - } - /* --- (end) Code for OpenSceneGraph --- */ return(d); } @@ -230,12 +208,6 @@ lib3ds_io_read_intw(Lib3dsIo *io) { lib3ds_io_read(io, b, 2); w = ((uint16_t)b[1] << 8) | ((uint16_t)b[0]); - /* --- Code for OpenSceneGraph --- */ - if (s_requiresByteSwap) - { - osg::swapBytes2((char*)&w); - } - /* --- (end) Code for OpenSceneGraph --- */ return((int16_t)w); } @@ -254,12 +226,6 @@ lib3ds_io_read_intd(Lib3dsIo *io) { ((uint32_t)b[2] << 16) | ((uint32_t)b[1] << 8) | ((uint32_t)b[0]); - /* --- Code for OpenSceneGraph --- */ - if (s_requiresByteSwap) - { - osg::swapBytes4((char*)&d); - } - /* --- (end) Code for OpenSceneGraph --- */ return((int32_t)d); } @@ -278,12 +244,6 @@ lib3ds_io_read_float(Lib3dsIo *io) { ((uint32_t)b[2] << 16) | ((uint32_t)b[1] << 8) | ((uint32_t)b[0]); - /* --- Code for OpenSceneGraph --- */ - if (s_requiresByteSwap) - { - osg::swapBytes4((char*)&(d.dword_value)); - } - /* --- (end) Code for OpenSceneGraph --- */ return d.float_value; } @@ -360,13 +320,6 @@ lib3ds_io_write_byte(Lib3dsIo *io, uint8_t b) { */ void lib3ds_io_write_word(Lib3dsIo *io, uint16_t w) { - /* --- Code for OpenSceneGraph --- */ - if (s_requiresByteSwap) - { - osg::swapBytes2((char*)&w); - } - /* --- (end) Code for OpenSceneGraph --- */ - uint8_t b[2]; assert(io); @@ -383,12 +336,6 @@ lib3ds_io_write_word(Lib3dsIo *io, uint16_t w) { */ void lib3ds_io_write_dword(Lib3dsIo *io, uint32_t d) { - /* --- Code for OpenSceneGraph --- */ - if (s_requiresByteSwap) - { - osg::swapBytes4((char*)&d); - } - /* --- (end) Code for OpenSceneGraph --- */ uint8_t b[4]; assert(io); @@ -419,12 +366,6 @@ lib3ds_io_write_intb(Lib3dsIo *io, int8_t b) { */ void lib3ds_io_write_intw(Lib3dsIo *io, int16_t w) { - /* --- Code for OpenSceneGraph --- */ - if (s_requiresByteSwap) - { - osg::swapBytes2((char*)&w); - } - /* --- (end) Code for OpenSceneGraph --- */ uint8_t b[2]; assert(io); @@ -441,12 +382,6 @@ lib3ds_io_write_intw(Lib3dsIo *io, int16_t w) { */ void lib3ds_io_write_intd(Lib3dsIo *io, int32_t d) { - /* --- Code for OpenSceneGraph --- */ - if (s_requiresByteSwap) - { - osg::swapBytes4((char*)&d); - } - /* --- (end) Code for OpenSceneGraph --- */ uint8_t b[4]; assert(io); @@ -465,17 +400,11 @@ lib3ds_io_write_intd(Lib3dsIo *io, int32_t d) { */ void lib3ds_io_write_float(Lib3dsIo *io, float l) { - uint8_t b[4]; + uint8_t b[4]; Lib3dsDwordFloat d; assert(io); d.float_value = l; - /* --- Code for OpenSceneGraph --- */ - if (s_requiresByteSwap) - { - osg::swapBytes4((char*)&d.dword_value); - } - /* --- (end) Code for OpenSceneGraph --- */ b[3] = (uint8_t)(((uint32_t)d.dword_value & 0xFF000000) >> 24); b[2] = (uint8_t)(((uint32_t)d.dword_value & 0x00FF0000) >> 16); b[1] = (uint8_t)(((uint32_t)d.dword_value & 0x0000FF00) >> 8);