From 8993190ec757556de34851af2b8118bcfd8d19e0 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 7 Mar 2005 12:14:24 +0000 Subject: [PATCH] From Marco Jez, "Current version of the LWO plugin creates one Geode with a single Geometry for each Lighwave surface, in order to keep surface names (geometries can't have names). The attached fix adds a plugin option named "COMBINE_GEODES" that allows to place all geometries under a single Geode whenever possible, thus offering better chances of further optimization through osgUtil::Optimizer. The downside is that surface names are no longer stored in the scene graph when using this option." --- src/osgPlugins/lwo/Converter.cpp | 39 +++++++++++++++++++------- src/osgPlugins/lwo/Converter.h | 11 +++++++- src/osgPlugins/lwo/ReaderWriterLWO.cpp | 1 + 3 files changed, 40 insertions(+), 11 deletions(-) diff --git a/src/osgPlugins/lwo/Converter.cpp b/src/osgPlugins/lwo/Converter.cpp index 520fa9967..ab4024c7d 100644 --- a/src/osgPlugins/lwo/Converter.cpp +++ b/src/osgPlugins/lwo/Converter.cpp @@ -161,6 +161,9 @@ void Converter::build_scene_graph(Object &obj) // create normal array osg::ref_ptr normals = j->normals()->asVec3Array(j->points()->size()); + // create first geode + osg::ref_ptr geode = new osg::Geode; + for (GeometryBin_map::iterator i=bins.begin(); i!=bins.end(); ++i) { const Surface *surface = i->first; GeometryBin &bin = i->second; @@ -180,17 +183,18 @@ void Converter::build_scene_graph(Object &obj) osg::notify(osg::DEBUG_INFO) << "DEBUG INFO: lwosg::Converter: \tcreating geometry for surface '" << (surface ? surface->get_name() : std::string("anonymous")) << "'\n"; - osg::ref_ptr geode = new osg::Geode; - osg::ref_ptr geo = new osg::Geometry; - geode->addDrawable(geo.get()); - geo->setVertexArray(new_points.get()); geo->setNormalArray(new_normals.get()); geo->setNormalBinding(osg::Geometry::BIND_PER_VERTEX); + bool group_used = false; + if (surface) { - geode->setName(surface->get_name()); + if (!options_.combine_geodes) + { + geode->setName(surface->get_name()); + } // apply surface parameters and texture/color maps according to remapping map osg::ref_ptr rm_texture_maps = j->texture_maps()->remap(remapping); @@ -204,14 +208,29 @@ void Converter::build_scene_graph(Object &obj) options_.use_osgfx, options_.force_arb_compression, db_options_.get()); - if (sgrp) { - sgrp->addChild(geode.get()); + if (sgrp) + { + group_used = true; + osg::ref_ptr grp_geode = new osg::Geode; + grp_geode->setName(surface->get_name()); + grp_geode->addDrawable(geo.get()); + sgrp->addChild(grp_geode.get()); layer_group->addChild(sgrp); - } else { + } + } + + if (!group_used) + { + geode->addDrawable(geo.get()); + if (geode->getNumParents() == 0) + { layer_group->addChild(geode.get()); } - } else { - layer_group->addChild(geode.get()); + } + + if (!options_.combine_geodes) + { + geode = new osg::Geode; } // add primitive sets to geometry diff --git a/src/osgPlugins/lwo/Converter.h b/src/osgPlugins/lwo/Converter.h index 7bfe0ffc9..4e498ea26 100644 --- a/src/osgPlugins/lwo/Converter.h +++ b/src/osgPlugins/lwo/Converter.h @@ -30,8 +30,17 @@ namespace lwosg bool apply_light_model; bool use_osgfx; bool force_arb_compression; + bool combine_geodes; - Options(): csf(new LwoCoordFixer), max_tex_units(0), apply_light_model(true), use_osgfx(false), force_arb_compression(false) {} + Options() + : csf(new LwoCoordFixer), + max_tex_units(0), + apply_light_model(true), + use_osgfx(false), + force_arb_compression(false), + combine_geodes(false) + { + } }; Converter(); diff --git a/src/osgPlugins/lwo/ReaderWriterLWO.cpp b/src/osgPlugins/lwo/ReaderWriterLWO.cpp index 402f4fada..7bcb5aa32 100644 --- a/src/osgPlugins/lwo/ReaderWriterLWO.cpp +++ b/src/osgPlugins/lwo/ReaderWriterLWO.cpp @@ -94,6 +94,7 @@ lwosg::Converter::Options ReaderWriterLWO::parse_options(const Options *options) std::istringstream iss(options->getOptionString()); std::string opt; while (iss >> opt) { + if (opt == "COMBINE_GEODES") conv_options.combine_geodes = true; if (opt == "FORCE_ARB_COMPRESSION") conv_options.force_arb_compression = true; if (opt == "USE_OSGFX") conv_options.use_osgfx = true; if (opt == "NO_LIGHTMODEL_ATTRIBUTE") conv_options.apply_light_model = false;