From 6331a54a686d5bd2cfbe61c403c8744a87cd7be8 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 24 Jun 2013 11:39:26 +0000 Subject: [PATCH] From Luc Frauciel, "You'll find attached a modification of DXWriter to support Material color: If a material is present, the diffuse color is affected to current layer." --- src/osgPlugins/dxf/DXFWriterNodeVisitor.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/osgPlugins/dxf/DXFWriterNodeVisitor.cpp b/src/osgPlugins/dxf/DXFWriterNodeVisitor.cpp index 70a6d19e1..2f439c6f2 100644 --- a/src/osgPlugins/dxf/DXFWriterNodeVisitor.cpp +++ b/src/osgPlugins/dxf/DXFWriterNodeVisitor.cpp @@ -481,6 +481,12 @@ void DXFWriterNodeVisitor::processStateSet(osg::StateSet* ss) { if (pm->getMode(osg::PolygonMode::FRONT)==osg::PolygonMode::LINE) _writeTriangleAs3DFace = false; } + osg::Material * mat = dynamic_cast(ss->getAttribute(osg::StateAttribute::MATERIAL)); + if (mat) + { + const osg::Vec4& color = mat->getDiffuse(osg::Material::FRONT); + _layer._color = _acadColor.findColor(color.asABGR()>>8); + } } void DXFWriterNodeVisitor::processGeometry(osg::Geometry* geo, osg::Matrix& m) @@ -490,8 +496,6 @@ void DXFWriterNodeVisitor::processGeometry(osg::Geometry* geo, osg::Matrix& m) // We only want to create a new layer for geometry with something to draw if (geo->getVertexArray() && geo->getVertexArray()->getNumElements() ) { - processStateSet(_currentStateSet.get()); - if ( _firstPass ) { // Must have unique layer names _layer._name = getLayerName( geo->getName().empty() ? geo->getParent(0)->getName() : geo->getName() ); @@ -510,6 +514,9 @@ void DXFWriterNodeVisitor::processGeometry(osg::Geometry* geo, osg::Matrix& m) } else { _layer = _layers[_count++]; OSG_DEBUG << "writing Layer " << _layer._name << std::endl; + + processStateSet(_currentStateSet.get()); + if ( geo->getNumPrimitiveSets() ) { for(unsigned int i = 0; i < geo->getNumPrimitiveSets(); ++i) {