void ShadowVolumeGeometryGenerator::apply( Geode& geode ) { StateSet *ss = geode.getStateSet(); if(ss) setCurrentFacingAndOrdering(ss); if( geode.getStateSet() ) pushState( geode.getStateSet() ); for( unsigned int i=0; i<geode.getNumDrawables(); ++i ) { Drawable* drawable = geode.getDrawable( i ); if( drawable->getStateSet() ) pushState( drawable->getStateSet() ); apply( geode.getDrawable( i ) ); if( drawable->getStateSet() ) popState(drawable->getStateSet()); } if(ss) setCurrentFacingAndOrdering(ss); if( geode.getStateSet() ) popState(geode); }
void POVWriterNodeVisitor::apply( Geode& node ) { pushStateSet( node.getStateSet() ); // iterate through drawables for(unsigned int i=0; i<node.getNumDrawables(); ++i) { // get drawable const Drawable *d = node.getDrawable(i); if (!d) continue; // push state set const StateSet *ss = d->getStateSet(); if( ss ) pushStateSet( ss ); // transformation matrix Matrix m = _transformationStack.top(); // process lights processLights( _stateSetStack.top().get(), m ); // process geometry const Geometry *g = d->asGeometry(); if( g ) processGeometry( g, _stateSetStack.top().get(), m ); // pop state set if( ss ) popStateSet( ss ); } popStateSet( node.getStateSet() ); }
void BaseDotVisitor::apply(Geode& node) { int id; if ( getOrCreateId( &node, id ) ) { handle( node, id ); handleNodeAndTraverse( node, id ); unsigned int i; for ( i = 0; i < node.getNumDrawables(); i++ ) { osg::Drawable* drawable = node.getDrawable( i ); int id2; if ( getOrCreateId( drawable, id2 ) ) { handle( *drawable, id2 ); osg::StateSet* s = drawable->getStateSet(); if ( s ) { int id3; if ( getOrCreateId( s, id3 ) ) { handle( *s, id3 ); } handle( *drawable, *s, id2, id3 ); } } handle( node, *drawable, id, id2 ); } } }
void applyTextures(Group* root, vector<string>& fileVect, vector<Vec2Array*>& coordVect) { /*osg::Vec4Array* colors = new osg::Vec4Array; if (i == 29){ colors->push_back(osg::Vec4(1.0f, 1.0f, 1.0f, 1.0f)); } else{ colors->push_back(osg::Vec4(i/(float)numPlanes, i/(float)numPlanes, i/(float)numPlanes, 1.0f) ); } planeGeometry->setColorArray(colors); planeGeometry->setColorBinding(osg::Geometry::BIND_OVERALL);*/ for (int i = 0; i < fileVect.size(); i ++ ){ if (fileVect[i] == ""){ continue; } Geode* currGeode = (Geode*)root->getChild(i); Geometry* currGeometry = (Geometry*)currGeode->getDrawable(0); Vec2Array* currVectArray = coordVect[i]; osg::Vec2Array* texcoords = new osg::Vec2Array(currVectArray->size()); for (int j = 0; j < currVectArray->size(); j ++ ){ (*texcoords)[j].set(currVectArray->at(j)[0], currVectArray->at(j)[1]); } currGeometry->setTexCoordArray(0,texcoords); osg::Texture2D* currTexture = new osg::Texture2D; currTexture->setDataVariance(osg::Object::DYNAMIC); osg::Image* currFace = osgDB::readImageFile(fileVect[i]); currTexture->setImage(currFace); osg::StateSet* state = new osg::StateSet; state->setTextureAttributeAndModes(0, currTexture,osg::StateAttribute::ON); currGeode->setStateSet(state); } }
void TriStripVisitor::apply(Geode& geode) { for(unsigned int i = 0; i < geode.getNumDrawables(); ++i ) { osg::Geometry* geom = dynamic_cast<osg::Geometry*>(geode.getDrawable(i)); if (geom) _geometryList.insert(geom); } }
/** The 'apply' method for 'Geode' type instances * @param searchNode : Geode : node that is searched */ void lgNodeOverseer::apply(Geode &searchNode) { cout << spaces() << "Géode :"<< searchNode.getName() << ", " << searchNode.getNumDrawables() << " drawables" << endl; if(searchNode.getNumDrawables()>0 && showDrawable){ for (unsigned i=0;i<searchNode.getNumDrawables();i++) { _level++; cout << spaces() << "Drawable " << i << " : " << searchNode.getDrawable(i)->getName() << endl; ref_ptr<Geometry> myGeom = dynamic_cast<Geometry*>(searchNode.getDrawable(i)); if(myGeom) { ref_ptr<Vec3Array> arrayVertex = (Vec3Array*) myGeom->getVertexArray(); _level++; int size = arrayVertex->size(); cout << spaces() << "Il y a " << size << " sommets" << endl; for (int j=0; j<size;j++) { cout << spaces() << "Sommet " << j+1 << " : x=" << arrayVertex->at(j).x() << ", y=" << arrayVertex->at(j).y() << ", z=" << arrayVertex->at(j).z() << endl; } _level--; } else { cout << "Pas de géométrie" << endl; } _level--; } cout << spaces() << endl; } // If no node is found, return searchNode if (searchForName == "") { foundNodeList.push_back(&searchNode); } else { if (searchNode.getName() == searchForName) { foundNodeList.push_back(&searchNode); } _level++; traverse(searchNode); _level--; } }
void IntersectVisitor::apply(Geode& geode) { if (!enterNode(geode)) return; for(unsigned int i = 0; i < geode.getNumDrawables(); i++ ) { intersect(*geode.getDrawable(i)); } leaveNode(); }
void StateSetVisitor::apply( Geode& geode ) { StateSet *ss = geode.getStateSet(); if( ss ) apply( *ss ); for( unsigned int i=0; i<geode.getNumDrawables(); ++i ) apply( *geode.getDrawable( i ) ); traverse( geode ); }
void DisplayRequirementsVisitor::apply(Geode& geode) { osg::StateSet* geode_stateset = geode.getStateSet(); if (geode_stateset) applyStateSet(*geode_stateset); for(unsigned int i = 0; i < geode.getNumDrawables(); i++ ) { osg::StateSet* stateset = geode.getDrawable(i)->getStateSet(); if (stateset) applyStateSet(*stateset); } }
Drawable *Object3D::getDrawable(Node *node, unsigned int index) { GeodeFindVisitor visitor; node->accept(visitor); Geode *geode = visitor.getFirst(); if(geode) { Drawable *drawable = geode->getDrawable(index); return drawable; } return NULL; }
void Object3D::dirty() { GeodeFindVisitor visitor; _originalNode->accept(visitor); std::vector<Geode*> geodeList = visitor.getGeodeList(); std::vector<Geode*>::iterator it; for(it=geodeList.begin(); it!=geodeList.end(); ++it) { Geode *geode = *it; if(geode) { for(unsigned int i=0; i<geode->getNumDrawables(); i++) { Drawable *drawable = geode->getDrawable(i); drawable->dirtyBound(); Geometry* geom(drawable->asGeometry()); osgUtil::SmoothingVisitor sv; sv.smooth(*geom); geom->getNormalArray()->dirty(); } } } }
void ScreenMVCullVisitor::apply(Geode& node) { bool status = _cullingStatus; bool firstStatus = _firstCullStatus; if(isCulled(node)) { _firstCullStatus = firstStatus; _cullingStatus = status; return; } // push the node's state. StateSet* node_state = node.getStateSet(); if(node_state) pushStateSet(node_state); // traverse any call callbacks and traverse any children. handle_cull_callbacks_and_traverse(node); RefMatrix& matrix = *getModelViewMatrix(); for(unsigned int i = 0; i < node.getNumDrawables(); ++i) { Drawable* drawable = node.getDrawable(i); const BoundingBox &bb = drawable->getBound(); if(drawable->getCullCallback()) { if(drawable->getCullCallback()->cull(this,drawable,&_renderInfo) == true) continue; } //else { if(node.isCullingActive() && isCulled(bb)) continue; } if(_computeNearFar && bb.valid()) { if(!updateCalculatedNearFar(matrix,*drawable,false)) continue; } // need to track how push/pops there are, so we can unravel the stack correctly. unsigned int numPopStateSetRequired = 0; // push the geoset's state on the geostate stack. StateSet* stateset = drawable->getStateSet(); if(stateset) { ++numPopStateSetRequired; pushStateSet(stateset); } CullingSet& cs = getCurrentCullingSet(); if(!cs.getStateFrustumList().empty()) { osg::CullingSet::StateFrustumList& sfl = cs.getStateFrustumList(); for(osg::CullingSet::StateFrustumList::iterator itr = sfl.begin(); itr != sfl.end(); ++itr) { if(itr->second.contains(bb)) { ++numPopStateSetRequired; pushStateSet(itr->first.get()); } } } float depth = bb.valid() ? distance(bb.center(),matrix) : 0.0f; if(osg::isNaN(depth)) { /*OSG_NOTIFY(osg::NOTICE)<<"CullVisitor::apply(Geode&) detected NaN,"<<std::endl <<" depth="<<depth<<", center=("<<bb.center()<<"),"<<std::endl <<" matrix="<<matrix<<std::endl; OSG_NOTIFY(osg::DEBUG_INFO) << " NodePath:" << std::endl; for (NodePath::const_iterator i = getNodePath().begin(); i != getNodePath().end(); ++i) { OSG_NOTIFY(osg::DEBUG_INFO) << " \"" << (*i)->getName() << "\"" << std::endl; }*/ } else { addDrawableAndDepth(drawable,&matrix,depth); } for(unsigned int i = 0; i < numPopStateSetRequired; ++i) { popStateSet(); } } // pop the node's state off the geostate stack. if(node_state) popStateSet(); _firstCullStatus = firstStatus; _cullingStatus = status; }
void Normals::MakeNormalsVisitor::apply( Geode &geode ) { for( unsigned int i = 0; i < geode.getNumDrawables(); i++ ) { Geometry *geom = dynamic_cast<Geometry *>(geode.getDrawable(i)); if( geom ) { if (geom->containsDeprecatedData()) geom->fixDeprecatedData(); Vec3Array *coords = dynamic_cast<Vec3Array*>(geom->getVertexArray()); if( coords == 0L ) continue; Vec3Array *normals = dynamic_cast<Vec3Array*>(geom->getNormalArray()); if( normals == 0L ) continue; Geometry::AttributeBinding binding = geom->getNormalBinding(); if( binding == Geometry::BIND_OFF ) continue; if( binding == Geometry::BIND_OVERALL ) { Vec3 v(0,0,0); Vec3 n = normals->front(); Vec3Array::iterator coord_index = coords->begin(); while( coord_index != coords->end() ) v += *(coord_index++) * _mat; v /= (float)(coords->size()); n *= _normal_scale; _local_coords->push_back( v ); _local_coords->push_back( (v + n)); } else // BIND_PER_PRIMITIVE_SET, BIND_PER_VERTEX { Geometry::PrimitiveSetList& primitiveSets = geom->getPrimitiveSetList(); Geometry::PrimitiveSetList::iterator itr; Vec3Array::iterator coord_index = coords->begin(); Vec3Array::iterator normals_index = normals->begin(); for(itr=primitiveSets.begin(); itr!=primitiveSets.end(); ++itr) { #ifdef DEBUG _printPrimitiveType( (*itr).get() ); #endif if( binding == Geometry::BIND_PER_PRIMITIVE_SET ) { Vec3 v(0,0,0); Vec3 n = *(normals_index++); int ni = (*itr)->getNumIndices(); for( int i = 0; i < ni; i++ ) v += *(coord_index++) * _mat; v /= (float)(ni); n *= _normal_scale; _local_coords->push_back( v ); _local_coords->push_back( (v + n)); } else { switch((*itr)->getMode()) { case(PrimitiveSet::TRIANGLES): { for( unsigned int j = 0; j < (*itr)->getNumPrimitives(); j++ ) { _processPrimitive( 3, coord_index, normals_index, binding ); coord_index += 3; normals_index+=3; } break; } case(PrimitiveSet::TRIANGLE_STRIP): { for( unsigned int j = 0; j < (*itr)->getNumIndices()-2; j++ ) { _processPrimitive( 3, coord_index, normals_index, binding ); coord_index++; normals_index++; } coord_index += 2; if( binding == Geometry::BIND_PER_VERTEX ) normals_index += 2; break; } case(PrimitiveSet::TRIANGLE_FAN): break; case(PrimitiveSet::QUADS): { for( unsigned int j = 0; j < (*itr)->getNumPrimitives(); j++ ) { _processPrimitive( 4, coord_index, normals_index, binding ); coord_index += 4; normals_index +=4; } break; } case(PrimitiveSet::QUAD_STRIP): break; case(PrimitiveSet::POLYGON): { DrawArrayLengths* dal = dynamic_cast<DrawArrayLengths*>((*itr).get()); if (dal) { for (unsigned int j = 0; j < dal->size(); ++j) { unsigned int num_prim = (*dal)[j]; //OSG_WARN << "j=" << j << " num_prim=" << num_prim << std::endl; _processPrimitive(num_prim, coord_index, normals_index, binding); coord_index += num_prim; normals_index += num_prim; } } break; } default: break; } } } } } } traverse( geode ); }
void osgToy::Normals::MakeNormalsVisitor::apply( Geode &geode ) { for( unsigned int i = 0; i < geode.getNumDrawables(); i++ ) { osg::Geometry *geom = dynamic_cast<osg::Geometry *>(geode.getDrawable(i)); if( geom ) { osg::Vec3Array *coords = dynamic_cast<osg::Vec3Array*>(geom->getVertexArray()); if( coords == 0L ) continue; osg::Vec3Array *normals = dynamic_cast<osg::Vec3Array*>(geom->getNormalArray()); if( normals == 0L ) continue; osg::Geometry::AttributeBinding binding = geom->getNormalBinding(); if( binding == osg::Geometry::BIND_OFF ) continue; if( binding == osg::Geometry::BIND_OVERALL ) { osg::Vec3 v(0,0,0); osg::Vec3 n = normals->front(); osg::Vec3Array::iterator coord_index = coords->begin(); while( coord_index != coords->end() ) v += *(coord_index++); v /= (float)(coords->size()); n *= _normal_scale; _local_coords->push_back( v ); _local_coords->push_back( (v + n)); } else // BIND_PER_PRIMTIVE_SET, BIND_PER_PRIMTITIV, BIND_PER_VERTEX { osg::Geometry::PrimitiveSetList& primitiveSets = geom->getPrimitiveSetList(); osg::Geometry::PrimitiveSetList::iterator itr; osg::Vec3Array::iterator coord_index = coords->begin(); osg::Vec3Array::iterator normals_index = normals->begin(); for(itr=primitiveSets.begin(); itr!=primitiveSets.end(); ++itr) { if( binding == osg::Geometry::BIND_PER_PRIMITIVE_SET ) { osg::Vec3 v(0,0,0); osg::Vec3 n = *(normals_index++); int ni = (*itr)->getNumIndices(); for( int i = 0; i < ni; i++ ) v += *(coord_index++); v /= (float)(ni); n *= _normal_scale; _local_coords->push_back( v ); _local_coords->push_back( (v + n)); } else { switch((*itr)->getMode()) { case(osg::PrimitiveSet::TRIANGLES): for( unsigned int j = 0; j < (*itr)->getNumPrimitives(); j++ ) { _processPrimitive( 3, coord_index, normals_index, binding ); coord_index += 3; if( binding == osg::Geometry::BIND_PER_PRIMITIVE ) normals_index++; else normals_index+=3; } break; case(osg::PrimitiveSet::TRIANGLE_STRIP): for( unsigned int j = 0; j < (*itr)->getNumIndices()-2; j++ ) { _processPrimitive( 3, coord_index, normals_index, binding ); coord_index++; normals_index++; } coord_index += 2; if( binding == osg::Geometry::BIND_PER_VERTEX ) normals_index += 2; break; case(osg::PrimitiveSet::TRIANGLE_FAN): break; case(osg::PrimitiveSet::QUADS): for( unsigned int j = 0; j < (*itr)->getNumPrimitives(); j++ ) { _processPrimitive( 4, coord_index, normals_index, binding ); coord_index += 4; if( binding == osg::Geometry::BIND_PER_PRIMITIVE ) normals_index++; else normals_index+=4; } break; case(osg::PrimitiveSet::QUAD_STRIP): case(osg::PrimitiveSet::POLYGON): break; default: break; } } } } } } traverse( geode ); }