void GeometryValidator::apply(osg::Geode& geode) { for(unsigned i=0; i<geode.getNumDrawables(); ++i) { osg::Geometry* geom = geode.getDrawable(i)->asGeometry(); if ( geom ) apply( *geom ); } }
void apply(osg::Geode& geode) { apply(static_cast<osg::Node&>(geode)); for(unsigned int i=0;i<geode.getNumDrawables();++i) { osg::Drawable* drawable = geode.getDrawable(i); if (drawable->getStateSet()) process(drawable->getStateSet()); } }
virtual void apply(osg::Geode& geode) { apply(geode.getStateSet()); for(unsigned int i=0; i<geode.getNumDrawables(); ++i) { apply(geode.getDrawable(i)->getStateSet()); osg::Geometry* geometry = geode.getDrawable(i)->asGeometry(); if (geometry) apply(geometry); } }
unsigned int WriterNodeVisitor::calcVertices(osg::Geode & geo) { unsigned int numVertice = 0; for (unsigned int i = 0; i < geo.getNumDrawables(); ++i) { osg::Geometry *g = geo.getDrawable( i )->asGeometry(); if (g!=NULL && g->getVertexArray()) numVertice += g->getVertexArray()->getNumElements(); } return numVertice; }
static bool writeDrawables( osgDB::OutputStream& os, const osg::Geode& node ) { unsigned int size = node.getNumDrawables(); os << size << os.BEGIN_BRACKET << std::endl; for ( unsigned int i=0; i<size; ++i ) { os << node.getDrawable(i); } os << os.END_BRACKET << std::endl; return true; }
virtual void apply(osg::Geode& geode) { for(unsigned int i=0; i<geode.getNumDrawables(); ++i) { osg::Geometry* geometry = dynamic_cast<osg::Geometry*>(geode.getDrawable(i)); if (geometry) { geometry->setUseVertexBufferObjects(true); } } }
virtual void apply(osg::Geode& geode) { apply(geode.getStateSet()); for(unsigned int i=0;i<geode.getNumDrawables();++i) { apply(geode.getDrawable(i)->getStateSet()); } traverse(geode); }
void TexCoordVisitor::apply(osg::Geode& geode) { for(unsigned int i = 0; i < geode.getNumDrawables(); i++ ) { osg::Geometry* geom = dynamic_cast<osg::Geometry*>( geode.getDrawable(i) ); if ( geom ) { // To do } } }
void apply(osg::Geode& geode) { for(unsigned int i=0; i<geode.getNumDrawables();++i) { osg::Geometry* geom = geode.getDrawable(i)->asGeometry(); if (geom) { osg::notify(osg::NOTICE)<<"Enabling VBO"<<std::endl; geom->setUseVertexBufferObjects(true); } } }
virtual void apply(osg::Geode& node) { if (node.getStateSet()) isTransparent(*node.getStateSet()); for(unsigned int i=0;i<node.getNumDrawables();++i) { osg::Drawable* drawable = node.getDrawable(i); if (drawable && drawable->getStateSet()) isTransparent(*drawable->getStateSet()); } traverse(node); }
void ProtectTransparencyVisitor::apply( osg::Geode& geode ) { protectTransparent( geode.getStateSet() ); unsigned int idx; for( idx=0; idx<geode.getNumDrawables(); idx++ ) { protectTransparent( geode.getDrawable( idx )->getStateSet() ); } traverse( geode ); }
virtual void apply(osg::Geode& node) { int nDrawable = node.getNumDrawables(); for(int i=0;i<nDrawable;i++) { osg::ref_ptr<osg::Vec3Array> verts = dynamic_cast<osg::Vec3Array*>(node.getDrawable(i)->asGeometry()->getVertexArray()); osg::Vec3Array::iterator iter; for(iter = verts->begin();iter!=verts->end();iter++) iter->_v[2]=h; } }
void apply(osg::Geode& geode) { for(unsigned int i=0; i<geode.getNumDrawables(); ++i) { osg::Geometry* geom = geode.getDrawable(i)->asGeometry(); if (geom) { osg::Vec3Array* vertices = dynamic_cast<osg::Vec3Array*>(geom->getVertexArray()); if (vertices) updateBound(*vertices); } } }
void SetDataVarianceVisitor::apply(osg::Geode& geode) { for(unsigned i=0; i<geode.getNumDrawables(); ++i) { osg::Drawable* d = geode.getDrawable(i); if ( d ) d->setDataVariance( _value ); } traverse(geode); }
void DrawElementTypeSimplifierVisitor::apply(osg::Geode& node) { DrawElementTypeSimplifier dets; unsigned int numDrawables = node.getNumDrawables(); for (unsigned int i = 0; i != numDrawables; ++i) { osg::Geometry * geom = dynamic_cast<osg::Geometry*>(node.getDrawable(i)); if (geom) dets.simplify(*geom); } osg::NodeVisitor::apply((osg::Node&)node); }
void RestoreOpacityVisitor::apply( osg::Geode& geode ) { transparentDisable( &geode ); unsigned int idx; for( idx=0; idx<geode.getNumDrawables(); idx++ ) { transparentDisable( geode.getDrawable( idx ) ); } traverse( geode ); }
void InfoVisitor::apply(osg::Geode& geode) { std::cout << spaces() << geode.libraryName() << "::" << geode.className() << std::endl; ++_level; osg::Drawable* drawable = nullptr; for (size_t i = 0; i < geode.getNumDrawables(); ++i) { drawable = geode.getDrawable(i); std::cout << spaces() << drawable->libraryName() << "::" << drawable->className() << std::endl; } traverse(geode); --_level; }
void OBJWriterNodeVisitor::apply( osg::Geode &node ) { pushStateSet(node.getStateSet()); _nameStack.push_back(node.getName()); unsigned int count = node.getNumDrawables(); for ( unsigned int i = 0; i < count; i++ ) { node.getDrawable( i )->accept(*this); } popStateSet(node.getStateSet()); _nameStack.pop_back(); }
void WriteNodeVisitor::apply(osg::Geode& geode) { // iterating through list of drawables for(unsigned i = 0; i < geode.getNumDrawables(); i++) { const osg::Drawable *drawable = geode.getDrawable(i); // which kind of drawable is this if(const GridTerrain* grid_terrain = dynamic_cast<const GridTerrain*>(drawable)) { write(grid_terrain); } else if(0) { // TODO: add more type tests } } }
void apply(osg::Geode& geode) { for(unsigned int i=0; i<geode.getNumDrawables(); ++i) { osg::TriangleFunctor<CollectTriangles> triangleCollector; geode.getDrawable(i)->accept(triangleCollector); for (unsigned int j = 0; j < triangleCollector.verts->size(); j++) { osg::Matrix& matrix = _matrixStack.back(); _vertices->push_back((*triangleCollector.verts)[j] * matrix); } } }
virtual void apply( osg::Geode & geode ) { for( unsigned int ii = 0; ii < geode.getNumDrawables(); ++ii ) { osg::ref_ptr< osg::Geometry > geometry = dynamic_cast< osg::Geometry * >( geode.getDrawable( ii ) ); if( geometry.valid() ) { osg::ref_ptr< osg::Vec3Array > newnormals = new osg::Vec3Array; newnormals->push_back( osg::Z_AXIS ); geometry->setNormalArray( newnormals.get(), osg::Array::BIND_OVERALL ); } } }
void ShapesToGeometriesVisitor::apply( osg::Geode& geode ) { for(unsigned int i=0; i<geode.getNumDrawables(); ++i) { osg::ShapeDrawable* drawable = dynamic_cast<osg::ShapeDrawable*>( geode.getDrawable(i) ); if(drawable==NULL) continue; osg::Geometry* newGeom = convertShapeToGeometry(*(drawable->getShape()), _hints); newGeom->setStateSet( drawable->getStateSet() ); geode.setDrawable( i, newGeom ); } traverse(geode); }
virtual void apply(osg::Geode& geode) { osg::StateSet* stateset = geode.getStateSet(); if (stateset) applyStateSet(stateset); for (unsigned int i=0; i<geode.getNumDrawables(); ++i) { osg::Drawable* drw = geode.getDrawable(i); stateset = drw->getStateSet(); if (stateset) applyStateSet(stateset); } }
//--by SophiaSoo/CUHK: for two arms, NEW FUNCTION void HapticRenderPrepareVisitor::apply(osg::Geode& node) { //--by SophiaSoo/CUHK: for two arms hdMakeCurrentDevice(m_device->getHandle()); // iterate over all drawables. for (unsigned int i=0; i < node.getNumDrawables(); i++) { osg::Drawable *drawable = node.getDrawable(i); osg::StateSet *ss = drawable->getOrCreateStateSet(); // Check if there are already a shape attached to this drawable osg::StateAttribute *sa = ss->getAttribute(Shape::getSAType()); if (!sa) { // attach a shape Shape *shape = new Shape(m_device.get()); ss->setAttributeAndModes(shape, osg::StateAttribute::ON); if (!m_shape.valid()) { //--by SophiaSoo/CUHK: for two arms //m_shape = new ShapeComposite(m_device.get()); //--by SophiaSoo/CUHK: for two arms m_shape = new ShapeComposite(); } m_shape->addChild(shape); } else { //--by SophiaSoo/CUHK: for two arms, add child to shape osgHaptics::Shape *shape = static_cast<osgHaptics::Shape*> (sa); shape->addDevice(m_device.get()); if (!m_shape.valid()) m_shape = new ShapeComposite(); m_shape->addChild(shape); /*--by SophiaSoo/CUHK: for two arms osg::notify(osg::WARN) << std::endl << "Drawables are instanced, which means that problem will occur" << std::endl; osg::notify(osg::WARN) << "Each Drawable can have only one haptic Shape attached to it." << std::endl; osg::notify(osg::WARN) << "and we cant draw to the same haptic shape multiple times. This means that only " << std::endl; osg::notify(osg::WARN) << "the first occurence of the drawable will been drawn haptically. " << std::endl; osg::notify(osg::WARN) << "Consider regenerating the scene and remove instanced drawables making each one unique." << std::endl << std::endl; */ } // collect all the shapes into a ShapeComposite } }
void VertexCacheOptimizer::apply(osg::Geode& geode) { if (geode.getDataVariance() == osg::Object::DYNAMIC) return; for(unsigned i=0; i<geode.getNumDrawables(); ++i ) { osg::Geometry* geom = geode.getDrawable(i)->asGeometry(); if ( geom ) { if ( geom->getDataVariance() == osg::Object::DYNAMIC ) return; // vertex cache optimizations currently only support surface geometries. // all or nothing in the geode. osg::Geometry::PrimitiveSetList& psets = geom->getPrimitiveSetList(); for( osg::Geometry::PrimitiveSetList::iterator i = psets.begin(); i != psets.end(); ++i ) { switch( (*i)->getMode() ) { case GL_TRIANGLES: case GL_TRIANGLE_FAN: case GL_TRIANGLE_STRIP: case GL_QUADS: case GL_QUAD_STRIP: case GL_POLYGON: break; default: return; } } } } //OE_NOTICE << LC << "VC optimizing..." << std::endl; // passed the test; run the optimizer. osgUtil::VertexCacheVisitor vcv; geode.accept( vcv ); vcv.optimizeVertices(); osgUtil::VertexAccessOrderVisitor vaov; geode.accept( vaov ); vaov.optimizeOrder(); traverse( geode ); }
void Writer3DCNodeVisitor::apply( osg::Geode &node ) { osg::Matrix matrix = osg::computeLocalToWorld(getNodePath()); unsigned int count = node.getNumDrawables(); for ( unsigned int i = 0; i < count; i++ ) { osg::Geometry *geometry = node.getDrawable( i )->asGeometry(); if ( geometry ) { osg::Vec3Array* vertices = dynamic_cast<osg::Vec3Array*>(geometry->getVertexArray()); osg::Vec3Array* normals = dynamic_cast<osg::Vec3Array*>(geometry->getNormalArray()); osg::Vec3Array* colours = dynamic_cast<osg::Vec3Array*>(geometry->getColorArray()); if ( vertices ) { for (unsigned int ii=0;ii<vertices->size();ii++) { // update nodes with world coords osg::Vec3d v = vertices->at(ii) * matrix; _fout << v[0] << ' ' << v[1] << ' ' << v[2]; if ( colours ) { v=colours->at(ii); _fout << ' ' << (int)v[0]*255.0 << ' ' << (int)v[1]*255.0 << ' ' << (int)v[2]*255.0; } else { _fout << " 255 255 255"; } if ( normals ) { v = normals->at(ii); _fout << ' ' << v[0] << ' ' << v[1] << ' ' << v[2]; } else { _fout << " 0.0 0.0 1.0"; } _fout << std::endl; } } } } }
void IntersectionVisitor::apply(osg::Geode& geode) { // osg::notify(osg::NOTICE)<<"apply(Geode&)"<<std::endl; if (!enter(geode)) return; // osg::notify(osg::NOTICE)<<"inside apply(Geode&)"<<std::endl; for(unsigned int i=0; i<geode.getNumDrawables(); ++i) { intersect( geode.getDrawable(i) ); } leave(); }
void ComputeBoundingBoxVisitor::apply(osg::Geode &geode) { for(unsigned int i = 0; i < geode.getNumDrawables(); i++) { osg::BoundingBox bb = geode.getDrawable(i)->computeBound(); m_bb.expandBy(bb.corner(0) * m_curMatrix); m_bb.expandBy(bb.corner(1) * m_curMatrix); m_bb.expandBy(bb.corner(2) * m_curMatrix); m_bb.expandBy(bb.corner(3) * m_curMatrix); m_bb.expandBy(bb.corner(4) * m_curMatrix); m_bb.expandBy(bb.corner(5) * m_curMatrix); m_bb.expandBy(bb.corner(6) * m_curMatrix); m_bb.expandBy(bb.corner(7) * m_curMatrix); } }
void apply(osg::Geode& geode) { if (_visited.count(&geode)!=0) return; _visited.insert(&geode); if (geode.getStateSet()) apply(*(geode.getStateSet())); for(unsigned int i=0; i<geode.getNumDrawables(); ++i) { if (geode.getDrawable(i)->getStateSet()) apply(*(geode.getDrawable(i)->getStateSet())); osg::Geometry* geom = geode.getDrawable(i)->asGeometry(); if (geom) apply(*geom); } }
virtual void apply(osg::Geode& geode) { for(unsigned int i=0;i<geode.getNumDrawables();++i) { osg::Geometry* geometry = dynamic_cast<osg::Geometry*>(geode.getDrawable(i)); if (geometry) { if (geometry->getColorArray()==0 || geometry->getColorArray()->getNumElements()==0) { osg::Vec4Array* colours = new osg::Vec4Array(1); (*colours)[0].set(1.0f,1.0f,1.0f,1.0f); geometry->setColorArray(colours, osg::Array::BIND_OVERALL); } } } }