From f9ee0fe44a9636921a51dcb59671fce16601cd2a Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 2 Jan 2002 11:03:26 +0000 Subject: [PATCH] A small bug fix to the matrix dump function (it was primtiing out 5 columns instead of four). Added support for multiplying mesh geometry by the matrix attached to the Lib3dsMesh structure, however this produces disjointed models so have to the default mode to bypass this multiplication code. Will need to revisit this in the future. --- src/osgPlugins/lib3ds/ReaderWriter3DS.cpp | 33 ++++++++++++++++++++--- src/osgPlugins/lib3ds/matrix.cpp | 2 +- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/osgPlugins/lib3ds/ReaderWriter3DS.cpp b/src/osgPlugins/lib3ds/ReaderWriter3DS.cpp index ce5ce97fc..ca15f0536 100644 --- a/src/osgPlugins/lib3ds/ReaderWriter3DS.cpp +++ b/src/osgPlugins/lib3ds/ReaderWriter3DS.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include #include @@ -284,14 +285,14 @@ osg::StateSet* ReaderWriter3DS::createStateSet(Lib3dsMaterial *mat) return stateset; } - osg::GeoSet* ReaderWriter3DS::createGeoSet(Lib3dsMesh *m,FaceList& faceList) { osg::GeoSet* geoset = new osg::GeoSet; unsigned int i; - + + std::vector orig2NewMapping; for(i=0;ipoints;++i) orig2NewMapping.push_back(-1); @@ -316,10 +317,36 @@ osg::GeoSet* ReaderWriter3DS::createGeoSet(Lib3dsMesh *m,FaceList& faceList) } osg::Vec3* osg_coords = new osg::Vec3[noVertex]; + Lib3dsVector c; + + // Note for Ben, 1st Jan 2002 from Robert. + // added code to use the matrix attached with each lib3dsMesh to + // multiply each coord on the mesh before passing to the OSG. + // however, this caused plenty of problems as applying the matrices + // moved the objects away from the original positions. + + bool useMatrix = false; + + if (useMatrix) + { + lib3ds_matrix_dump(m->matrix); + } + for (i=0; ipoints; ++i) { // lib3ds_vector_transform(pos, m->matrix, m->pointL[i].pos); - if (orig2NewMapping[i]>=0) osg_coords[orig2NewMapping[i]].set(m->pointL[i].pos[0],m->pointL[i].pos[1],m->pointL[i].pos[2]); + if (orig2NewMapping[i]>=0) { + if (useMatrix) + { + lib3ds_vector_transform(c,m->matrix, m->pointL[i].pos); + osg_coords[orig2NewMapping[i]].set(c[0],c[1],c[2]); + } + else + { + // original no transform code. + osg_coords[orig2NewMapping[i]].set(m->pointL[i].pos[0],m->pointL[i].pos[1],m->pointL[i].pos[2]); + } + } } osg::Vec2* osg_tcoords = NULL; diff --git a/src/osgPlugins/lib3ds/matrix.cpp b/src/osgPlugins/lib3ds/matrix.cpp index ba9a40ca3..294a87862 100644 --- a/src/osgPlugins/lib3ds/matrix.cpp +++ b/src/osgPlugins/lib3ds/matrix.cpp @@ -630,7 +630,7 @@ lib3ds_matrix_dump(Lib3dsMatrix matrix) int i,j; for (i=0; i<4; ++i) { - for (j=0; j<4; ++j) { + for (j=0; j<3; ++j) { printf("%f ", matrix[j][i]); } printf("%f\n", matrix[j][i]);