Changeset 8624
- Timestamp:
- 07/17/08 15:51:14
- Files:
-
- OpenSceneGraph/trunk/include/osg/View (modified) (2 diffs)
- OpenSceneGraph/trunk/include/osgViewer/ViewerBase (modified) (1 diff)
- OpenSceneGraph/trunk/src/osg/View.cpp (modified) (1 diff)
- OpenSceneGraph/trunk/src/osgPlugins/normals/Normals.cpp (modified) (5 diffs)
- OpenSceneGraph/trunk/src/osgPlugins/normals/ReaderWriterNormals.cpp (modified) (3 diffs)
- OpenSceneGraph/trunk/src/osgPlugins/stl/ReaderWriterSTL.cpp (modified) (6 diffs)
- OpenSceneGraph/trunk/src/osgPlugins/x/ReaderWriterDirectX.cpp (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
OpenSceneGraph/trunk/include/osg/View
r7668 r8624 116 116 bool addSlave(osg::Camera* camera, bool useMastersSceneData=true) { return addSlave(camera, osg::Matrix::identity(), osg::Matrix::identity(), useMastersSceneData); } 117 117 118 bool addSlave(osg::Camera* camera, const osg::Matrix& projectionOffset, const osg::Matrix& viewOffse , bool useMastersSceneData=true);118 bool addSlave(osg::Camera* camera, const osg::Matrix& projectionOffset, const osg::Matrix& viewOffset, bool useMastersSceneData=true); 119 119 120 120 bool removeSlave(unsigned int pos); … … 125 125 const Slave& getSlave(unsigned int pos) const { return _slaves[pos]; } 126 126 127 unsigned int findSlaveIndexForCamera(osg::Camera* camera) ;127 unsigned int findSlaveIndexForCamera(osg::Camera* camera) const; 128 128 129 129 Slave * findSlaveForCamera(osg::Camera* camera); OpenSceneGraph/trunk/include/osgViewer/ViewerBase
r8406 r8624 99 99 100 100 /** Set the position of the end barrier. 101 * AfterSwapBuffers will may result is slightly higher framerates, bymay101 * AfterSwapBuffers may result in slightly higher framerates, but may 102 102 * lead to inconsistent swapping between different windows. 103 103 * BeforeSwapBuffers may lead to slightly lower framerate, but improve consistency in timing of swap buffers, OpenSceneGraph/trunk/src/osg/View.cpp
r8439 r8624 213 213 } 214 214 215 unsigned int View::findSlaveIndexForCamera(osg::Camera* camera) 215 unsigned int View::findSlaveIndexForCamera(osg::Camera* camera) const 216 216 { 217 217 if (_camera == camera) return _slaves.size(); OpenSceneGraph/trunk/src/osgPlugins/normals/Normals.cpp
r7648 r8624 5 5 Normals::Normals( Node *node, float scale, Mode mode ) 6 6 { 7 setName(mode == VertexNormals ? "VertexNormals" : "SurfaceNormals"); 8 7 9 MakeNormalsVisitor mnv(scale,mode); 8 10 node->accept( mnv ); … … 109 111 _local_coords->push_back( v ); 110 112 _local_coords->push_back( (v + n)); 111 112 113 } 113 114 else … … 125 126 else 126 127 normals_index+=3; 127 128 128 } 129 129 break; … … 159 159 } 160 160 case(PrimitiveSet::QUAD_STRIP): 161 break; 162 161 163 case(PrimitiveSet::POLYGON): 162 break; 164 { 165 DrawArrayLengths* dal = dynamic_cast<DrawArrayLengths*>((*itr).get()); 166 if (dal) { 167 for (unsigned int j = 0; j < dal->size(); ++j) { 168 unsigned int num_prim = (*dal)[j]; 169 //notify(WARN) << "j=" << j << " num_prim=" << num_prim << std::endl; 170 _processPrimitive(num_prim, coord_index, normals_index, binding); 171 coord_index += num_prim; 172 if (binding == Geometry::BIND_PER_PRIMITIVE) { 173 ++normals_index; 174 } else { 175 normals_index += num_prim; 176 } 177 } 178 } 179 break; 180 } 181 163 182 default: 164 183 break; … … 194 213 195 214 for( unsigned int i = 0; i < nv; i++ ) 196 v += *(coords++) * _mat;215 v += *(coords++) * _mat; 197 216 v /= (float)(nv); 198 217 OpenSceneGraph/trunk/src/osgPlugins/normals/ReaderWriterNormals.cpp
r8578 r8624 46 46 if( opt == "help" || opt == "HELP" ) 47 47 { 48 osg::notify( osg::INFO ) << 49 "Normals Plugin usage: <application> [-O options] <model.ext>.normals\n" 50 " options: \"scale=<scale>\" (default = 1.0)\n" 51 " \"mode=<VertexNormals|SurfaceNormals>\" (default = VertexNormals)" << std::endl; 52 48 usage(); 53 49 } 54 50 else 55 51 { 56 int index = opt.find( "=" ); 57 if( opt.substr( 0, index ) == "scale" || 58 opt.substr( 0, index ) == "SCALE" ) 59 { 60 scale = atof( opt.substr( index+1 ).c_str() ); 61 } 62 else if( opt.substr( 0, index ) == "mode" || opt.substr( 0, index ) == "MODE" ) 63 { 64 std::string modestr = opt.substr(index+1); 65 if( modestr == "VertexNormals" ) 66 mode = Normals::VertexNormals; 67 else if( modestr == "SurfaceNormals" ) 68 mode = Normals::SurfaceNormals; 69 else 70 mode = Normals::VertexNormals; 52 size_t index = opt.find( "=" ); 53 if (index == std::string::npos) { 54 usage(); 55 } else { 56 std::string key = opt.substr(0, index); 57 std::string value = opt.substr(index+1); 58 if( key == "scale" || key == "SCALE" ) 59 { 60 scale = atof( value.c_str() ); 61 } 62 else if( key == "mode" || key == "MODE" ) 63 { 64 if( value == "VertexNormals" ) 65 mode = Normals::VertexNormals; 66 else if( value == "SurfaceNormals" ) 67 mode = Normals::SurfaceNormals; 68 else 69 mode = Normals::VertexNormals; 70 } 71 71 } 72 72 } … … 82 82 osg::ref_ptr<osg::Group> group = new osg::Group; 83 83 group->addChild( node.get() ); 84 85 const osg::BoundingSphere& bsph = group->getBound(); 86 scale = bsph.radius() * 0.05f * scale; // default is 5% of bounding-sphere radius 87 84 88 if( mode == Normals::VertexNormals ) 85 89 group->addChild( new VertexNormals( node.get(), scale )); … … 92 96 return 0L; 93 97 } 98 99 private: 100 void usage() const { 101 osg::notify( osg::INFO ) << 102 "Normals Plugin usage: <application> [-O options] <model.ext>.normals\n" 103 " options: \"scale=<scale>\" (default = 1.0)\n" 104 " \"mode=<VertexNormals|SurfaceNormals>\" (default = VertexNormals)" << std::endl; 105 } 94 106 }; 95 107 OpenSceneGraph/trunk/src/osgPlugins/stl/ReaderWriterSTL.cpp
r8578 r8624 48 48 ReaderWriterSTL() 49 49 { 50 supportsExtension("stl","STL format"); 51 supportsExtension("sta","STL format"); 50 supportsExtension("stl","STL binary format"); 51 supportsExtension("sta","STL ASCII format"); 52 supportsOption("smooth", "run SmoothingVisitor"); 52 53 } 53 54 … … 120 121 // determine ASCII vs. binary mode 121 122 FILE* fp = fopen(fileName.c_str(), "rb"); 122 123 123 if (!fp) { 124 return ReadResult::FILE_NOT_ HANDLED;124 return ReadResult::FILE_NOT_FOUND; 125 125 } 126 126 … … 131 131 if (fread((void*) &header, sizeof(header), 1, fp) != 1) { 132 132 fclose(fp); 133 return ReadResult:: FILE_NOT_HANDLED;133 return ReadResult::ERROR_IN_READING_FILE; 134 134 } 135 135 bool isBinary = false; … … 147 147 osg::notify(osg::FATAL) << "ReaderWriterSTL::readNode: Unable to stat '" << fileName << "'" << std::endl; 148 148 fclose(fp); 149 return ReadResult:: FILE_NOT_HANDLED;149 return ReadResult::ERROR_IN_READING_FILE; 150 150 } 151 151 … … 164 164 osg::notify(osg::FATAL) << "ReaderWriterSTL::readNode(" << fileName.c_str() << ") unable to determine file format" << std::endl; 165 165 fclose(fp); 166 return ReadResult:: FILE_NOT_HANDLED;166 return ReadResult::ERROR_IN_READING_FILE; 167 167 } 168 168 … … 205 205 geode->addDrawable(geom); 206 206 207 bool doSmoothing = false; 208 209 if (options && (options->getOptionString() == "smooth")) 210 { 211 doSmoothing = true; 212 } 213 214 if (doSmoothing) 215 { 207 if (options && (options->getOptionString() == "smooth")) { 216 208 osgUtil::SmoothingVisitor smooter; 217 209 geode->accept(smooter); OpenSceneGraph/trunk/src/osgPlugins/x/ReaderWriterDirectX.cpp
r8578 r8624 52 52 { 53 53 supportsExtension("x","DirectX scene format"); 54 supportsOption("flipTexture", "flip texture upside-down"); 54 55 } 55 56 56 57 virtual const char* className() const { 57 return "DirectX Reader /Writer";58 return "DirectX Reader"; 58 59 } 59 60 … … 85 86 // Load DirectX mesh 86 87 DX::Object obj; 87 if (obj.load(fileName.c_str())) { 88 89 // code for setting up the database path so that internally referenced file are searched for on relative paths. 90 osg::ref_ptr<Options> local_opt = options ? static_cast<Options*>(options->clone(osg::CopyOp::SHALLOW_COPY)) : new Options; 91 local_opt->setDatabasePath(osgDB::getFilePath(fileName)); 92 93 // Options? 94 bool flipTexture = true; 95 float creaseAngle = 80.0f; 96 if (options) { 97 const std::string option = options->getOptionString(); 98 if (option.find("flipTexture") != std::string::npos) 99 flipTexture = false; 100 if (option.find("creaseAngle") != std::string::npos) { 101 // TODO 102 } 103 } 104 105 // Convert to osg::Group 106 osg::Group* group = convertFromDX(obj, flipTexture, creaseAngle, local_opt.get()); 107 if (!group) 108 return ReadResult::FILE_NOT_HANDLED; 109 110 return group; 111 } 112 113 return ReadResult::FILE_NOT_HANDLED; 88 if (obj.load(fileName.c_str()) == false) { 89 return ReadResult::ERROR_IN_READING_FILE; 90 } 91 92 // code for setting up the database path so that internally referenced file are searched for on relative paths. 93 osg::ref_ptr<Options> local_opt = options ? static_cast<Options*>(options->clone(osg::CopyOp::SHALLOW_COPY)) : new Options; 94 local_opt->setDatabasePath(osgDB::getFilePath(fileName)); 95 96 // Options? 97 bool flipTexture = true; 98 float creaseAngle = 80.0f; 99 if (options) { 100 const std::string option = options->getOptionString(); 101 if (option.find("flipTexture") != std::string::npos) { 102 flipTexture = false; 103 } 104 if (option.find("creaseAngle") != std::string::npos) { 105 // TODO 106 } 107 } 108 109 // Convert to osg::Group 110 osg::Group* group = convertFromDX(obj, flipTexture, creaseAngle, local_opt.get()); 111 if (!group) { 112 return ReadResult::ERROR_IN_READING_FILE; 113 } 114 115 return group; 114 116 } 115 117 … … 119 121 const osgDB::ReaderWriter::Options * options) const 120 122 { 121 osg:: Group *group = new osg::Group;123 osg::ref_ptr<osg::Group> group = new osg::Group; 122 124 123 125 for (unsigned int i = 0; i < obj.getNumMeshes(); ++i) { … … 125 127 DX::Mesh & mesh = *obj.getMesh(i); 126 128 osg::Geode * geode = convertFromDX(mesh, flipTexture, creaseAngle, options); 127 if (geode) 128 group->addChild(geode); 129 } 130 131 return group; 129 if (!geode) { 130 return 0; 131 } 132 group->addChild(geode); 133 } 134 135 return group.release(); 132 136 } 133 137
