- Timestamp:
- 03/21/12 18:36:20 (14 months ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/src/osgPlugins/lwo/ReaderWriterLWO.cpp
r11517 r13041 7 7 * Improved LWO2 reader is (C) 2003-2004 Marco Jez <marco.jez@poste.it> 8 8 * 9 * The Open Scene Graph (OSG) is a cross platform C++/OpenGL library for 10 * real-time rendering of large 3D photo-realistic models. 9 * The Open Scene Graph (OSG) is a cross platform C++/OpenGL library for 10 * real-time rendering of large 3D photo-realistic models. 11 11 * The OSG homepage is http://www.openscenegraph.org/ 12 12 */ … … 55 55 supportsExtension("geo","Lightwave geometry format"); 56 56 } 57 57 58 58 virtual const char* className() const { return "Lightwave Object Reader"; } 59 59 60 60 virtual ReadResult readNode(const std::string& file, const osgDB::ReaderWriter::Options* options) const 61 61 { 62 std::string ext = osgDB::getLowerCaseFileExtension(file); 62 std::string ext = osgDB::getLowerCaseFileExtension(file); 63 63 if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; 64 64 … … 66 66 if (fileName.empty()) return ReadResult::FILE_NOT_FOUND; 67 67 68 // code for setting up the database path so that internally referenced file are searched for on relative paths. 68 // code for setting up the database path so that internally referenced file are searched for on relative paths. 69 69 osg::ref_ptr<Options> local_opt = options ? static_cast<Options*>(options->clone(osg::CopyOp::SHALLOW_COPY)) : new Options; 70 70 local_opt->setDatabasePath(osgDB::getFilePath(fileName)); … … 72 72 ReadResult result = readNode_LWO1(fileName,local_opt.get()); 73 73 if (result.success()) return result; 74 74 75 75 if (!options || options->getOptionString() != "USE_OLD_READER") { 76 76 ReadResult result = readNode_LWO2(fileName, local_opt.get()); … … 89 89 protected: 90 90 91 91 92 92 93 93 }; … … 197 197 typedef std::map<int,GeometryCollection> MaterialToGeometryCollectionMap; 198 198 MaterialToGeometryCollectionMap mtgcm; 199 199 200 200 // bin the indices for each material into the mtis; 201 201 int i; … … 211 211 } 212 212 } 213 213 214 214 MaterialToGeometryCollectionMap::iterator itr; 215 215 for(itr=mtgcm.begin(); itr!=mtgcm.end(); ++itr) … … 222 222 223 223 gc._geom = new osg::Geometry; 224 224 225 225 osg::Vec3Array* vertArray = new osg::Vec3Array(gc._numPoints); 226 226 gc._vertices = vertArray->begin(); … … 233 233 lw_material.b, 234 234 1.0f); 235 235 236 236 gc._geom->setColorArray(colors); 237 237 gc._geom->setColorBinding(osg::Geometry::BIND_OVERALL); 238 238 239 239 // set up texture if needed. 240 240 if (gc._numPrimitivesWithTexCoords==gc._numPrimitives) … … 267 267 stateset->setTextureAttributeAndModes(0,texture,osg::StateAttribute::ON); 268 268 gc._texturesActive=true; 269 269 270 270 gc._geom->setStateSet(stateset); 271 271 … … 276 276 } 277 277 } 278 } 279 } 280 281 278 } 279 } 280 281 282 282 for (i = 0; i < lw->face_cnt; ++i) 283 283 { … … 286 286 { 287 287 GeometryCollection& gc = mtgcm[face.material]; 288 288 289 289 osg::PrimitiveSet::Mode mode; 290 290 switch(face.index_cnt) … … 309 309 break; 310 310 } 311 311 312 312 gc._geom->addPrimitiveSet(new osg::DrawArrays(mode,gc._coordCount,face.index_cnt)); 313 313 gc._coordCount += face.index_cnt; … … 326 326 (*gc._vertices++).set(lw->vertex[face.index[j]*3], lw->vertex[face.index[j]*3+2], lw->vertex[face.index[j]*3+1]); 327 327 } 328 328 329 329 if (gc._texturesActive && face.texcoord) 330 330 { … … 332 332 { 333 333 (*gc._texcoords++).set(face.texcoord[j*2],face.texcoord[j*2+1]); 334 } 335 } 334 } 335 } 336 336 } 337 337 } 338 338 339 339 osg::Geode* geode = new osg::Geode; 340 340 341 341 osgUtil::Tessellator tessellator; 342 343 // add everthing into the Geode. 342 343 // add everthing into the Geode. 344 344 osgUtil::SmoothingVisitor smoother; 345 345 for(itr=mtgcm.begin(); … … 350 350 if (gc._geom) 351 351 { 352 352 353 353 tessellator.retessellatePolygons(*gc._geom); 354 354 355 355 smoother.smooth(*gc._geom); 356 356 357 357 geode->addDrawable(gc._geom); 358 358 }
