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.
"
This commit is contained in:
Robert Osfield
2010-04-15 18:40:40 +00:00
parent 51d377c9f6
commit 70d78c0713
3 changed files with 1 additions and 75 deletions

View File

@@ -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:"<<std::endl;

View File

@@ -788,8 +788,6 @@ extern LIB3DSAPI void lib3ds_matrix_rotate(float m[4][4], float angle, float ax,
extern LIB3DSAPI void lib3ds_matrix_camera(float m[4][4], float pos[3], float tgt[3], float roll);
/* --- Code for OpenSceneGraph --- */
extern LIB3DSAPI void setByteOrder();
/* Definitions for compatibility with previous lib3DS used: */
typedef float Lib3dsMatrix[4][4];
typedef float Lib3dsVector[3];

View File

@@ -17,16 +17,6 @@
*/
#include "lib3ds_impl.h"
/* --- Code for OpenSceneGraph --- */
#include "lib3ds.h" // For setByteOrder()
#include <osg/Endian>
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);