void OptTexture::apply(osg::Geode& geode) { // if(geode.getStateSet()) // { // apply(geode.getStateSet()); // } unsigned int cnt = geode.getNumDrawables(); for(unsigned int i = 0; i < cnt; i++) { //20130915 MYF模型深度测试不正确 osg::StateSet *stateset = geode.getDrawable(i)->getOrCreateStateSet(); stateset->setMode(GL_BLEND,osg::StateAttribute::ON); //取消深度测试 stateset->setMode( GL_DEPTH_TEST, osg::StateAttribute::ON ); // stateset->setMode( GL_LIGHTING, osg::StateAttribute::OFF | osg::StateAttribute::PROTECTED ); //stateset->setRenderBinDetails(0, "RenderBin"); //设置渲染优先级------级别理论上来讲 比你背景的node靠后就行,没设置过的是-1. geode.getDrawable(i)->setStateSet(stateset); //geode.getDrawable(i)->getStateSet()->setRenderBinMode(osg::StateSet::RenderBinMode::INHERIT_RENDERBIN_DETAILS); // apply(geode.getDrawable(i)->getStateSet()); } traverse(geode); }
void GeometryDataCollector::apply( osg::Geode& node ) { //osg::Matrix matrix = osg::computeLocalToWorld( node.getParentalNodePaths()[0] ); osg::Matrix matrix; if ( matrixStack.size()>0 ) matrix = matrixStack.back(); for ( unsigned int i=0; i<node.getNumDrawables(); ++i ) { osg::Geometry* geom = node.getDrawable(i)->asGeometry(); if ( geom ) { osg::Vec3Array* va = dynamic_cast<osg::Vec3Array*>( geom->getVertexArray() ); numTotalVertices += (va ? va->size() : 0); osg::TriangleFunctor<CollectFaceOperator> functor; functor.collector = this; functor.matrix = matrix; geom->accept( functor ); } else { osg::TriangleFunctor<CollectFaceOperator> functor; functor.collector = this; functor.matrix = matrix; node.getDrawable(i)->accept( functor ); } } traverse( node ); }
void ProjectVisitor::apply(osg::Geode& node) { if (_clearEveryDrawable) _projector.clear(); std::vector<osg::Drawable*> toremove; std::vector<osg::ref_ptr<osg::Geometry> > toadd; for (int i = 0; i < node.getNumDrawables(); i++) { osg::Timer_t t0 = osg::Timer::instance()->tick(); node.getDrawable(i)->accept(_projector); double duration = osg::Timer::instance()->delta_s(t0, osg::Timer::instance()->tick()); if (_projector.hasGeometry()) { toremove.push_back(node.getDrawable(i)); std::stringstream ss; ss << "projected_" << _index << ".osg"; osg::notify(osg::INFO) << "duration " << duration << " " << ss.str() << std::endl; if (_writeResultOnDisk) _projector.write(ss.str()); if (!_mergeGeometry) { osg::ref_ptr<osg::Geometry> result = _projector._result.get(); result->setUserData(node.getDrawable(i)->getUserData()); toadd.push_back(result); _projector.clear(); } } _index++; _cummulatedTime += duration; } if (_mergeGeometry) { if (_projector.hasGeometry()) { toadd.push_back(_projector._result.get()); } } for (int i = 0; i < toremove.size(); i++) // remove only where success to project data node.removeDrawable(toremove[i]); for (int i = 0; i < toadd.size(); i++) {// remove only where success to project data node.addDrawable(toadd[i]); } if (_projectToXYZ) { osg::ref_ptr<LatLongHeight2xyz> visitor = new LatLongHeight2xyz(); node.accept(*visitor); } // smooth after project if (_smooth) { osgUtil::SmoothingVisitor smooth; for (int i = 0; i < toadd.size(); i++) {// remove only where success to project data smooth.smooth(*toadd[i]); } } }
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); } }
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); } }
void ShaderGenerator::apply( osg::Geode& geode ) { osg::ref_ptr<osg::StateSet> ss = geode.getStateSet(); if ( ss.valid() ) { _state->pushStateSet( ss.get() ); osg::ref_ptr<osg::StateSet> replacement; if ( processGeometry(ss.get(), replacement) ) { _state->popStateSet(); geode.setStateSet( replacement.get() ); _state->pushStateSet( replacement.get() ); } } for( unsigned d = 0; d < geode.getNumDrawables(); ++d ) { apply( geode.getDrawable(d) ); } if ( ss.valid() ) { _state->popStateSet(); } }
void LODVisitor::apply( osg::Geode& node ) { unsigned int numDrawables = node.getNumDrawables(); for ( unsigned int cnt = 0; cnt < numDrawables; ++cnt ) { osg::Drawable* p_drawable = node.getDrawable( cnt ); osg::Geometry* p_geom = p_drawable->asGeometry(); // evaluate the geom and generate an appropriate collision geometry if ( p_geom ) { p_drawable->setUseDisplayList( false ); p_drawable->setSupportsDisplayList( false ); osg::ref_ptr< GLODMesh > p_lodmesh = new GLODMesh( p_geom ); p_lodmesh->createObject( *( _p_lodSettings.get() ) ); // the actual lod mesh object is stored in geometry object, the following update and draw callbacks hold references to it p_geom->setUserData( p_lodmesh.get() ); LODDrawCallback* p_cbdraw = new LODDrawCallback( p_lodmesh.get() ); p_geom->setDrawCallback( p_cbdraw ); //! TODO get the adaptation period from lod settings! LODUpdateCallback* p_cbupdate = new LODUpdateCallback( p_lodmesh.get(), 1.0 ); p_geom->setUpdateCallback( p_cbupdate ); } } }
virtual void apply(osg::Geode &n) { unsigned int nDraws = n.getNumDrawables(); for (unsigned int idraw = 0 ; idraw < nDraws; ++idraw) { osg::Geometry *geom = n.getDrawable( idraw )->asGeometry(); osg::Vec3Array *v = static_cast<osg::Vec3Array*>(geom->getVertexArray()); osg::Vec4Array *vc = static_cast<osg::Vec4Array*>(geom->getColorArray()); osg::Vec3Array *vn = static_cast<osg::Vec3Array*>(geom->getNormalArray()); osg::Vec2Array *vt = static_cast<osg::Vec2Array*>(geom->getTexCoordArray(0)); if (geom) { unsigned int nPrims = geom->getNumPrimitiveSets(); for (unsigned int iprim = 0; iprim < nPrims; ++iprim) { osg::PrimitiveSet *p = geom->getPrimitiveSet(iprim); for (GLsizei i = 0; i < p->getNumIndices(); ++i) { _s.vertexPositions.col(_idx) = toE(v->at(p->index(i))); if (_opts & ConvertVertexColors) _s.vertexColors.col(_idx) = toE(vc->at(p->index(i))); if (_opts & ConvertVertexNormals) _s.vertexNormals.col(_idx) = toE(vn->at(p->index(i))).normalized(); if (_opts & ConvertVertexUVs) { _s.vertexUVs.col(_idx) = toE(vt->at(p->index(i))); } ++_idx; } } } } traverse(n); }
virtual void apply(osg::Geode& node) { for (int i=0;i<_indent;++i) { std::cout<<" "; } std::cout<<"["<<_indent+1<<"]"<<node.libraryName() <<"::"<<node.className()<<std::endl; for (unsigned int n=0;n<node.getNumDrawables();++n) { osg::Drawable *drawable=node.getDrawable(n); if(!drawable)continue; for (int i=0;i<_indent;++i) { for (int i=0;i<_indent;++i) { std::cout<<" "; } std::cout<<drawable->libraryName()<<"::" <<drawable->className()<<std::endl; } _indent++; traverse(node); _indent--; } }
void WriterNodeVisitor::apply( osg::Geode &node ) { pushStateSet(node.getStateSet()); //_nameStack.push_back(node.getName()); unsigned int count = node.getNumDrawables(); ListTriangle listTriangles; bool texcoords = false; for ( unsigned int i = 0; i < count; i++ ) { osg::Geometry *g = node.getDrawable( i )->asGeometry(); if ( g != NULL ) { pushStateSet(g->getStateSet()); createListTriangle(g, listTriangles, texcoords, i); // May set _succeded to false popStateSet(g->getStateSet()); if (!succeeded()) break; } } if (succeeded() && count > 0) { #if DISABLE_3DS_ANIMATION osg::Matrix mat( osg::computeLocalToWorld(getNodePath()) ); buildFaces(node, mat, listTriangles, texcoords); // May set _succeded to false #else buildFaces(node, osg::Matrix(), listTriangles, texcoords); // May set _succeded to false #endif } popStateSet(node.getStateSet()); //_nameStack.pop_back(); if (succeeded()) traverse(node); }
void ConvertToDrawInstanced::apply( osg::Geode& geode ) { for( unsigned d=0; d<geode.getNumDrawables(); ++d ) { osg::Geometry* geom = geode.getDrawable(d)->asGeometry(); if ( geom ) { if ( _optimize ) { // activate VBOs geom->setUseDisplayList( false ); geom->setUseVertexBufferObjects( true ); } geom->setInitialBound(_bbox); // convert to use DrawInstanced for( unsigned p=0; p<geom->getNumPrimitiveSets(); ++p ) { osg::PrimitiveSet* ps = geom->getPrimitiveSet(p); ps->setNumInstances( _numInstances ); _primitiveSets.push_back( ps ); } #ifdef USE_INSTANCE_LODS geom->setDrawCallback( new LODCallback() ); #endif } } traverse(geode); }
void apply( osg::Geode& geode ) { for( unsigned d=0; d<geode.getNumDrawables(); ++d ) { osg::Geometry* geom = geode.getDrawable(d)->asGeometry(); if ( geom ) { if ( _optimize ) { // activate VBOs geom->setUseDisplayList( false ); geom->setUseVertexBufferObjects( true ); } //geom->setComputeBoundingBoxCallback( new StaticBoundingBox(_bb)); //geom->setComputeBoundingBoxCallback(NULL); geom->setInitialBound(_bb); //geom->dirtyBound(); // convert to use DrawInstanced for( unsigned p=0; p<geom->getNumPrimitiveSets(); ++p ) { osg::PrimitiveSet* ps = geom->getPrimitiveSet(p); ps->setNumInstances( _numInstances ); _primitiveSets.push_back( ps ); } _geometries.push_back(geom); } } traverse(geode); }
virtual void apply(osg::Geode& geode) { for (unsigned i=0; i<geode.getNumDrawables(); ++i) { osg::Geometry *geo = dynamic_cast<osg::Geometry *>(geode.getDrawable(i)); if (!geo) continue; osg::StateSet *stateset = geo->getStateSet(); if (!stateset) continue; osg::StateAttribute *state = stateset->getAttribute(osg::StateAttribute::MATERIAL); if (!state) continue; osg::Material *mat = dynamic_cast<osg::Material *>(state); if (!mat) continue; const osg::Vec4 v4 = mat->getDiffuse(FAB); if (v4.r() == 1.0f && v4.g() == 0.0f && v4.b() == 1.0f) { //VTLOG("oldmat rc %d, ", mat->referenceCount()); osg::Material *newmat = (osg::Material *)mat->clone(osg::CopyOp::DEEP_COPY_ALL); newmat->setDiffuse(FAB, osg::Vec4(c.r*2/3,c.g*2/3,c.b*2/3,1)); newmat->setAmbient(FAB, osg::Vec4(c.r*1/3,c.g*1/3,c.b*1/3,1)); //VTLOG("newmat rc %d\n", newmat->referenceCount()); stateset->setAttribute(newmat); //VTLOG(" -> %d %d\n", mat->referenceCount(), newmat->referenceCount()); } } osg::NodeVisitor::apply(geode); }
void ComputeCylinderVisitor::apply( osg::Geode & geode ) { for( unsigned int i = 0; i < geode.getNumDrawables(); ++i ) { applyDrawable( geode.getDrawable( i ) ); } }
void ConvertToDrawInstanced::apply( osg::Geode& geode ) { for( unsigned d=0; d<geode.getNumDrawables(); ++d ) { osg::Geometry* geom = geode.getDrawable(d)->asGeometry(); if ( geom ) { if ( _optimize ) { //osgUtil::IndexMeshVisitor imv; //imv.makeMesh( *geom ); // activate VBOs geom->setUseDisplayList( false ); geom->setUseVertexBufferObjects( true ); } geom->setComputeBoundingBoxCallback( _staticBBoxCallback.get() ); geom->dirtyBound(); // convert to use DrawInstanced for( unsigned p=0; p<geom->getNumPrimitiveSets(); ++p ) { geom->getPrimitiveSet(p)->setNumInstances( _numInstances ); } } } traverse(geode); }
void GeometryModifier::apply( osg::Geode& geode ) { // merge drawables if possible for best results if (getDrawableMerge()) { osgUtil::Optimizer::MergeGeometryVisitor mgv; mgv.setTargetMaximumNumberOfVertices(1000000); mgv.mergeGeode(geode); } for(unsigned int i=0;i<geode.getNumDrawables();++i) { _drawableCount++; osg::ref_ptr< osg::Geometry > geometry = geode.getDrawable(i)->asGeometry(); if( geometry.valid() ) { _geometryCount++; if( geometry->containsSharedArrays() ) osg::notify( osg::DEBUG_INFO ) << "Warning! Geometry contains shared arrays" << std::endl; // Get statistics before incStatistics( geometry.get(), _preVertices, _preIndices, _preTriangles ); osg::ref_ptr< osg::Geometry > newGeom = (*_geomOp)( *geometry ); geode.replaceDrawable( geometry.get(), newGeom.get() ); // Get statistics after incStatistics( newGeom.get(), _postVertices, _postIndices, _postTriangles ); } } }
void ShaderGenerator::apply( osg::Geode& geode ) { if ( !_active ) return; osg::ref_ptr<osg::StateSet> ss = geode.getStateSet(); if ( ss.valid() ) { _state->pushStateSet( ss.get() ); osg::ref_ptr<osg::StateSet> replacement; if ( processGeometry(ss.get(), replacement) ) { _state->popStateSet(); // optimize state set sharing if ( _stateSetCache.valid() ) _stateSetCache->share(replacement, replacement); geode.setStateSet( replacement.get() ); _state->pushStateSet( replacement.get() ); } } for( unsigned d = 0; d < geode.getNumDrawables(); ++d ) { apply( geode.getDrawable(d) ); } if ( ss.valid() ) { _state->popStateSet(); } }
void CURRENT_CLASS::apply(osg::Geode &geode) { // Contained drawables will only be individually considered if we are // allowed to continue traversing. if(shouldContinueTraversal(geode)) { osg::Drawable *drawable; double zNear, zFar; // Handle each drawable in this geode for(unsigned int i = 0; i < geode.getNumDrawables(); ++i) { drawable = geode.getDrawable(i); const osg::BoundingBox &bb = drawable->getBound(); if(bb.valid()) { bool containsTest = _localFrusta.back().contains(bb); // Make sure drawable will be visible in the scene if(!containsTest) continue; // Compute near/far distances for current drawable zNear = distanceDA(bb.corner(_bbCorners.back().first), _viewMatrices.back()); zFar = distanceDA(bb.corner(_bbCorners.back().second), _viewMatrices.back()); if(zNear > zFar) std::swap(zNear,zFar); pushDistancePair(zNear,zFar); } } } }
void ModelVisitor::apply(osg::Geode& geode) { for(unsigned int i = 0; i < geode.getNumDrawables(); i++ ) { if ( _task==BUILD_BSP ) { Model* model = dynamic_cast<Model*>( geode.getDrawable(i) ); if ( model ) buildBSP( *model ); } else if ( _task==BUILD_MESH ) { PolyMesh* mesh = dynamic_cast<PolyMesh*>( geode.getDrawable(i) ); if ( mesh ) buildMesh( *mesh ); } } }
virtual void apply(osg::Geode& geode) { geode.setUpdateCallback(new UpdateCallback()); //note, it makes no sense to attach a cull callback to the node //at there are no nodes to traverse below the geode, only //drawables, and as such the Cull node callbacks is ignored. //If you wish to control the culling of drawables //then use a drawable cullback... for(unsigned int i=0;i<geode.getNumDrawables();++i) { geode.getDrawable(i)->setUpdateCallback(new DrawableUpdateCallback()); geode.getDrawable(i)->setCullCallback(new DrawableCullCallback()); geode.getDrawable(i)->setDrawCallback(new DrawableDrawCallback()); } }
void osgToy::FacetingVisitor::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) facet(*geom); } }
void PhysicsVisitor::apply( osg::Geode& node ) { // retrieve the node mask which is used for physics material and later for other properies // only the first byte is relevant for pyhsics material description _attribute = node.getNodeMask() & 0xFF; // this means no need for building static collision geom // this is not the same as MAT_NOCOL, as MAT_NOCOL collisions are detected if ( _attribute == Physics::NO_BUILD ) return; // get the accumulated world matrix for this node osg::Matrixf mat = computeLocalToWorld( getNodePath() ); unsigned int numDrawables = node.getNumDrawables(); for ( unsigned int cnt = 0; cnt < numDrawables; ++cnt ) { osg::Drawable* p_drawable = node.getDrawable( cnt ); osg::Geometry* p_geom = p_drawable->asGeometry(); // evaluate the geom and generate an appropriate collision geometry if ( p_geom ) { osg::Array* p_verts = p_geom->getVertexArray(); osg::IndexArray* p_indices = p_geom->getVertexIndices(); unsigned int numPrims = p_geom->getNumPrimitiveSets(); { for ( unsigned int primcnt = 0; primcnt < numPrims; ++primcnt ) { osg::PrimitiveSet* p_set = p_geom->getPrimitiveSet( primcnt ); switch( p_set->getMode() ) { case osg::PrimitiveSet::POINTS: case osg::PrimitiveSet::LINES: case osg::PrimitiveSet::LINE_STRIP: case osg::PrimitiveSet::LINE_LOOP: return; case osg::PrimitiveSet::TRIANGLES: buildTrianlges( p_set, p_verts, mat, p_indices ); break; case osg::PrimitiveSet::TRIANGLE_STRIP: buildTrianlgeStrip( p_set, p_verts, mat, p_indices ); break; case osg::PrimitiveSet::TRIANGLE_FAN: case osg::PrimitiveSet::QUADS: case osg::PrimitiveSet::QUAD_STRIP: case osg::PrimitiveSet::POLYGON: default: log_error << "Physics Serializer: unsupported primitive set for physics geometry! currently only TRIANGLES and TRIANGLE_STRIP types are supported." << std::endl; } } } } } }
virtual void apply( osg::Geode& geode ) { for( unsigned int i=0; i<geode.getNumDrawables(); i++ ) { osg::StateSet* ss = geode.getDrawable( i )->getStateSet(); if ( ss ) rewrite( ss ); osg::NodeVisitor::apply( geode ); } }
void apply(osg::Geode& node) { apply((osg::Node&)node); for(unsigned int i=0;i<node.getNumDrawables();++i) { osg::Drawable* drawable = node.getDrawable(i); if (drawable->getStateSet()) process(drawable->getStateSet()); } }
void DisableFreezeOnCullVisitor::apply(osg::Geode &geode) { for (unsigned int i=0; i<geode.getNumDrawables(); ++i) { osg::Drawable* drw = geode.getDrawable(i); if (osgParticle::ParticleSystem* partsys = dynamic_cast<osgParticle::ParticleSystem*>(drw)) partsys->setFreezeOnCull(false); } }
virtual void apply(osg::Geode& geode) { replaceTexure(geode.getStateSet()); for (unsigned int i = 0; i < geode.getNumDrawables(); ++i) { replaceTexure(geode.getDrawable(i)->getStateSet()); } traverse(geode); }
virtual void apply(osg::Geode& geode) { if (geode.getName().compare(0,9,"tessellate")==0) { for(unsigned int i=0;i<geode.getNumDrawables();++i) { osg::Geometry* geom = dynamic_cast<osg::Geometry*>(geode.getDrawable(i)); if (geom) { osg::ref_ptr<osgUtil::Tessellator> tscx=new osgUtil::Tessellator(); if (tscx.valid()) { tscx->setTessellationType(osgUtil::Tessellator::TESS_TYPE_GEOMETRY); if (geode.getName()== "tessellate") { // add a Tessellator so that this geom is retessellated when N is pressed tscx->setBoundaryOnly(true); tscx->setWindingType( osgUtil::Tessellator::TESS_WINDING_ABS_GEQ_TWO); // so that first change in wind type makes the commonest tessellation - ODD. geom->setUserData(tscx.get()); } else if (geode.getName()== "tessellate odd") { // OR you can just apply the Tessellator once only, using these different types tscx->setWindingType( osgUtil::Tessellator::TESS_WINDING_ODD); // commonest tessellation - ODD. tscx->retessellatePolygons(*geom); } else if (geode.getName()== "tessellate odd bound") { tscx->setBoundaryOnly(true); tscx->setWindingType( osgUtil::Tessellator::TESS_WINDING_ODD); // tessellation - ODD, only show boundary. tscx->retessellatePolygons(*geom); } else if (geode.getName()== "tessellate positive") { tscx->setWindingType( osgUtil::Tessellator::TESS_WINDING_POSITIVE); // tessellation - pos. tscx->retessellatePolygons(*geom); } else if (geode.getName()== "tessellate positive bound") { tscx->setBoundaryOnly(true); tscx->setWindingType( osgUtil::Tessellator::TESS_WINDING_POSITIVE); tscx->retessellatePolygons(*geom); } else if (geode.getName()== "tessellate negative") { tscx->setWindingType( osgUtil::Tessellator::TESS_WINDING_NEGATIVE); tscx->retessellatePolygons(*geom); } else if (geode.getName()== "tessellate negative bound") { tscx->setBoundaryOnly(true); tscx->setWindingType( osgUtil::Tessellator::TESS_WINDING_NEGATIVE); tscx->retessellatePolygons(*geom); } else if (geode.getName()== "tessellate nonzero") { tscx->setWindingType( osgUtil::Tessellator::TESS_WINDING_NONZERO); tscx->retessellatePolygons(*geom); } else if (geode.getName()== "tessellate nonzero bound") { tscx->setBoundaryOnly(true); tscx->setWindingType( osgUtil::Tessellator::TESS_WINDING_NONZERO); tscx->retessellatePolygons(*geom); } else if (geode.getName()== "tessellate geq2") { tscx->setWindingType( osgUtil::Tessellator::TESS_WINDING_ABS_GEQ_TWO); tscx->retessellatePolygons(*geom); } else if (geode.getName()== "tessellate geq2 bound") { tscx->setBoundaryOnly(true); tscx->setWindingType( osgUtil::Tessellator::TESS_WINDING_ABS_GEQ_TWO); tscx->retessellatePolygons(*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()); } }
void LinkVisitor::apply(osg::Geode& node) { for (unsigned int i = 0; i < node.getNumDrawables(); i++) { osg::Drawable* drawable = node.getDrawable(i); if (drawable && drawable->getStateSet()) handle_stateset(drawable->getStateSet()); } apply(static_cast<osg::Node&>(node)); }
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 ); } }