From 059a7c052df041d80751fcb84f22423379a005a7 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 14 Feb 2011 16:09:51 +0000 Subject: [PATCH] From Tim Moore, "This patch fixes some performance problems with the DXF loader. It removes some unnecessary copies of vertex coordinates (which were causing an exponential explosion). It also replaces BIND_PER_PRIMITIVE normals with BIND_PER_VERTEX so that the resulting geometry will be on the fast path." --- src/osgPlugins/dxf/scene.cpp | 5 +---- src/osgPlugins/dxf/scene.h | 16 ++++++++++------ 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/osgPlugins/dxf/scene.cpp b/src/osgPlugins/dxf/scene.cpp index 65303b3f9..ce6798830 100644 --- a/src/osgPlugins/dxf/scene.cpp +++ b/src/osgPlugins/dxf/scene.cpp @@ -165,14 +165,11 @@ void scene::addQuads(const std::string & l, unsigned short color, std::vector_quadnorms[cindex].push_back( n ); - MapVList mvl = ly->_quads; - VList vl = mvl[cindex]; + VList& vl = ly->_quads[cindex]; vl.push_back(addVertex(*a)); vl.push_back(addVertex(*b)); vl.push_back(addVertex(*c)); vl.push_back(addVertex(*d)); - mvl[cindex] = vl; - ly->_quads = mvl; } } } diff --git a/src/osgPlugins/dxf/scene.h b/src/osgPlugins/dxf/scene.h index 758654cac..ebb08a63c 100644 --- a/src/osgPlugins/dxf/scene.h +++ b/src/osgPlugins/dxf/scene.h @@ -102,7 +102,7 @@ osg::Geometry* createTriGeometry( osg::Vec3Array* vertices, osg::Vec3Array* norm geom->setColorArray(colors); geom->setColorBinding(osg::Geometry::BIND_OVERALL); geom->setNormalArray(normals); - geom->setNormalBinding(osg::Geometry::BIND_PER_PRIMITIVE); + geom->setNormalBinding(osg::Geometry::BIND_PER_VERTEX); return geom; } @@ -117,7 +117,7 @@ osg::Geometry* createQuadGeometry( osg::Vec3Array* vertices, osg::Vec3Array* nor geom->setColorArray(colors); geom->setColorBinding(osg::Geometry::BIND_OVERALL); geom->setNormalArray(normals); - geom->setNormalBinding(osg::Geometry::BIND_PER_PRIMITIVE); + geom->setNormalBinding(osg::Geometry::BIND_PER_VERTEX); return geom; } @@ -252,11 +252,13 @@ protected: coords->push_back(v); } osg::Vec3Array *norms = new osg::Vec3Array; - VList normlist = _trinorms[mitr->first]; + VList& normlist = _trinorms[mitr->first]; for (itr = normlist.begin(); itr != normlist.end(); ++itr) { - norms->push_back(osg::Vec3(itr->x(), itr->y(), itr->z())); + osg::Vec3 norm(itr->x(), itr->y(), itr->z()); + for (int i = 0; i < 3; ++i) + norms->push_back(norm); } root->addChild(createModel(_name, createTriGeometry(coords, norms, getColor(mitr->first)))); } @@ -275,10 +277,12 @@ protected: coords->push_back(v); } osg::Vec3Array *norms = new osg::Vec3Array; - VList normlist = _quadnorms[mitr->first]; + VList& normlist = _quadnorms[mitr->first]; for (itr = normlist.begin(); itr != normlist.end(); ++itr) { - norms->push_back(osg::Vec3(itr->x(), itr->y(), itr->z())); + osg::Vec3 norm(itr->x(), itr->y(), itr->z()); + for (int i = 0; i < 4; ++i) + norms->push_back(norm); } root->addChild(createModel(_name, createQuadGeometry(coords, norms, getColor(mitr->first)))); }