- Timestamp:
- 03/21/12 18:36:20 (15 months ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/src/osgPlugins/obj/OBJWriterNodeVisitor.h
r12292 r13041 9 9 * texture coord arrays, bug fixes, and support for texture mapping. 10 10 * 11 * Writing support added 2007 by Stephan Huber, http://digitalmind.de, 11 * Writing support added 2007 by Stephan Huber, http://digitalmind.de, 12 12 * some ideas taken from the dae-plugin 13 13 * 14 * The Open Scene Graph (OSG) is a cross platform C++/OpenGL library for 15 * real-time rendering of large 3D photo-realistic models. 14 * The Open Scene Graph (OSG) is a cross platform C++/OpenGL library for 15 * real-time rendering of large 3D photo-realistic models. 16 16 * The OSG homepage is http://www.openscenegraph.org/ 17 17 */ 18 18 19 19 #ifndef OBJ_WRITER_NODE_VISITOR_HEADER__ 20 20 #define OBJ_WRITER_NODE_VISITOR_HEADER__ … … 51 51 52 52 public: 53 OBJWriterNodeVisitor(std::ostream& fout, const std::string materialFileName = "") : 54 osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN), 55 _fout(fout), 53 OBJWriterNodeVisitor(std::ostream& fout, const std::string materialFileName = "") : 54 osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN), 55 _fout(fout), 56 56 _currentStateSet(new osg::StateSet()), 57 57 _lastVertexIndex(1), … … 60 60 { 61 61 _fout << "# file written by OpenSceneGraph" << std::endl << std::endl; 62 62 63 63 if (!materialFileName.empty()) { 64 64 _fout << "mtllib " << materialFileName << std::endl << std::endl; 65 65 } 66 66 } 67 67 68 68 virtual void apply(osg::Geode &node); 69 70 virtual void apply(osg::Group &node) 69 70 virtual void apply(osg::Group &node) 71 71 { 72 72 _nameStack.push_back( node.getName().empty() ? node.className() : node.getName() ); 73 73 _fout << std::endl; 74 74 _fout << "g " << getUniqueName() << std::endl; 75 75 76 76 osg::NodeVisitor::traverse( node ); 77 77 _nameStack.pop_back(); 78 78 } 79 79 80 80 void traverse (osg::Node &node) 81 81 { … … 92 92 // Save our current stateset 93 93 _stateSetStack.push(_currentStateSet.get()); 94 94 95 95 // merge with node stateset 96 96 _currentStateSet = static_cast<osg::StateSet*>(_currentStateSet->clone(osg::CopyOp::SHALLOW_COPY)); 97 _currentStateSet->merge(*ss); 97 _currentStateSet->merge(*ss); 98 98 } 99 99 } … … 108 108 } 109 109 } 110 111 110 111 112 112 void writeMaterials(std::ostream& fout); 113 114 115 113 114 115 116 116 class OBJMaterial { 117 117 public: 118 118 OBJMaterial() {} 119 119 OBJMaterial(osg::Material* mat, osg::Texture* tex); 120 120 121 121 osg::Vec4 diffuse, ambient, specular; 122 122 std::string image; 123 123 std::string name; 124 124 }; 125 125 126 126 protected: 127 127 struct CompareStateSet … … 134 134 }; 135 135 136 136 137 137 private: 138 138 139 139 OBJWriterNodeVisitor& operator = (const OBJWriterNodeVisitor&) { return *this; } 140 140 141 141 void processGeometry(osg::Geometry* geo, osg::Matrix& m); 142 142 void processArray(const std::string& key, osg::Array* array, const osg::Matrix& m = osg::Matrix::identity(), bool isNormal = false); 143 143 144 144 void processStateSet(osg::StateSet* stateset); 145 145 146 146 std::string getUniqueName(const std::string& defaultValue = ""); 147 147 148 148 typedef std::stack<osg::ref_ptr<osg::StateSet> > StateSetStack; 149 149 typedef std::map< osg::ref_ptr<osg::StateSet>, OBJMaterial, CompareStateSet> MaterialMap; … … 156 156 std::map<std::string, unsigned int> _nameMap; 157 157 unsigned int _lastVertexIndex, _lastNormalIndex, _lastTexIndex; 158 MaterialMap _materialMap; 158 MaterialMap _materialMap; 159 159 160 160 };
