void RemoveEmptyGroupsVisitor::apply( osg::Group& group ) { bool removed = true; while( removed ) { removed = false; for( unsigned i = 0; i < group.getNumChildren(); ++i ) { osg::Group* child = group.getChild(i)->asGroup(); if ( child ) { if (child->className() == std::string("Group") && child->getStateSet() == 0L && child->getCullCallback() == 0L && child->getUpdateCallback() == 0L && child->getUserData() == 0L && child->getName().empty() && child->getDescriptions().size() == 0 ) { for( unsigned j = 0; j < child->getNumChildren(); ++j ) { group.addChild( child->getChild( j ) ); } group.removeChild( i-- ); removed = true; } } } } traverse(group); }
/** Attacca al/ai nodi che corrispondono a nodeName */ void LoadThreadsHandler::AttachNodeToSceneByName::apply(osg::Group& grp) { if (grp.getName() == _nodeName) { if(!_attached || _multipleattach) { if(_ranged) { osg::ref_ptr<osg::LOD> newlod = new osg::LOD; newlod->setName("RangedLOD_" + _attachNode->getName()); newlod->addChild(_attachNode.get(), _min, _max); grp.addChild(newlod.get()); } else { grp.addChild(_attachNode.get()); } _attached = true; } } traverse(grp); }
void CVRCullVisitor::PreCullVisitor::apply(osg::Group& group) { bool setMask = false; for(int i = 0; i < group.getNumChildren(); i++) { _setMask = false; group.getChild(i)->accept(*this); if(_setMask) { setMask = true; } } if(group.getNodeMask() & FIRST_CULL_STATUS) { _setMask = true; } else if(setMask) { //std::cerr << "Pulling up node mask." << std::endl; _setMask = true; group.setNodeMask(group.getNodeMask() | FIRST_CULL_STATUS); } }
// apply method for groups void GeometryExtractorVisitor::apply( osg::Group& group ) { // call the appropriate apply method for all children if( group.getNumChildren() > 0 ) { for( unsigned int i = 0; i < group.getNumChildren(); i++) { osg::Node* node = group.getChild( i ); apply( *node ); } } }
static bool writeChildren( osgDB::OutputStream& os, const osg::Group& node ) { unsigned int size = node.getNumChildren(); os << size << osgDB::BEGIN_BRACKET << std::endl; for ( unsigned int i=0; i<size; ++i ) { os << node.getChild(i); } os << osgDB::END_BRACKET << std::endl; return true; }
void FltExportVisitor::apply( osg::Group& node ) { ScopedStatePushPop guard( this, node.getStateSet() ); if (_firstNode) { // On input, a FLT header creates a Group node. // On export, we always write a Header record, but then the first Node // we export is the Group that was created from the original input Header. // On successive roundtrips, this results in increased redundant top-level Group nodes/records. // Avoid this by NOT outputting anything for a top-level Group node. _firstNode = false; traverse( node ); return; } // A Group node could indicate one of many possible records. // Header record -- Don't need to support this here. We always output a header. // Group record -- HIGH // Child of an LOD node -- HIGH Currently write out a Group record regardless. // InstanceDefinition/InstanceReference -- MED -- multiparented Group is an instance // Extension record -- MED // Object record -- MED // LightPointSystem record (if psgSim::MultiSwitch) -- LOW osgSim::MultiSwitch* multiSwitch = dynamic_cast<osgSim::MultiSwitch*>( &node ); if (multiSwitch) { writeSwitch( multiSwitch ); } else { osgSim::ObjectRecordData* ord = dynamic_cast< osgSim::ObjectRecordData* >( node.getUserData() ); if (ord) { // This Group should write an Object Record. writeObject( node, ord ); } else { // Handle other cases here. // For now, just output a Group record. writeGroup( node ); } } writeMatrix( node.getUserData() ); writeComment( node ); writePushTraverseWritePop( node ); }
void SimpleDotVisitor::handle(osg::Group &node, int id) { std::stringstream label; label << "<top> " << node.className(); if (!node.getName().empty()) { label << "| " << node.getName(); } drawNode(id, "record", "solid", label.str(), "black", "white"); }
void StatsVisitor::apply(osg::Group& node) { if (node.getStateSet()) { apply(*node.getStateSet()); } ++_numInstancedGroup; _groupSet.insert(&node); traverse(node); }
virtual void apply(osg::Group &group ) { for (unsigned int i = 0; i<group.getNumChildren(); ) { if( dynamic_cast<osgAL::SoundRoot*>(group.getChild(i)) && _mode==SEARCH_AND_DESTROY ) { group.removeChild(i); } else { if (dynamic_cast<osgAL::SoundRoot*>(group.getChild(i)) && _mode==SEARCH) _found_count++; group.getChild(i)->accept(*this); i++; } } }
void WriterNodeVisitor::apply(osg::Group &node) { pushStateSet(node.getStateSet()); Lib3dsMeshInstanceNode * parent = _cur3dsNode; #if DISABLE_3DS_ANIMATION osg::Matrix mat( osg::computeLocalToWorld(getNodePath()) ); apply3DSMatrixNode(node, &mat, "grp"); #else apply3DSMatrixNode(node, NULL, "grp"); #endif if (succeeded()) traverse(node); _cur3dsNode = parent; popStateSet(node.getStateSet()); }
void FltExportVisitor::writeObject(const osg::Group &group, osgSim::ObjectRecordData *ord) { uint16 length(28); IdHelper id(*this, group.getName()); if (!ord) { std::string warning("fltexp: writeObject has invalid ObjectRecordData."); OSG_WARN << warning << std::endl; _fltOpt->getWriteResult().warn(warning); return; } _records->writeInt16((int16) OBJECT_OP); _records->writeInt16(length); _records->writeID(id); _records->writeInt32(ord->_flags); _records->writeInt16(ord->_relativePriority); _records->writeUInt16(ord->_transparency); _records->writeUInt16(ord->_effectID1); _records->writeUInt16(ord->_effectID2); _records->writeUInt16(ord->_significance); _records->writeUInt16(0); // reserved }
void FltExportVisitor::writeGroup(const osg::Group &group, int32 flags, int32 loopCount, float32 loopDuration, float32 lastFrameDuration) // <-- placeholder: ignored { int16 length(44); IdHelper id(*this, group.getName()); _records->writeInt16((int16) GROUP_OP); _records->writeInt16(length); _records->writeID(id); _records->writeInt16(0); // Relative priority _records->writeInt16(0); // Reserved _records->writeUInt32(flags); _records->writeInt16(0); // Special effect ID1 _records->writeInt16(0); // Special effect ID2 _records->writeInt16(0); // Significance _records->writeInt8(0); // Layer code _records->writeInt8(0); // Reserved _records->writeInt32(0); // Reserved _records->writeInt32(loopCount); _records->writeFloat32(loopDuration); _records->writeFloat32(lastFrameDuration); }
virtual void apply(osg::Group& group) { for (unsigned int i = 0; i < group.getNumChildren(); i++) { osg::Node* child = group.getChild(i); osg::Node* seam = seamReplacement(child); if (child != seam) { group.replaceChild(child,seam); } else { child->accept(*this); } } }
void CVRCullVisitor::apply(osg::Group& node) { bool status = _cullingStatus; bool firstStatus = _firstCullStatus; if(isCulled(node)) { _firstCullStatus = firstStatus; _cullingStatus = status; return; } // push the culling mode. pushCurrentMask(); // push the node's state. StateSet* node_state = node.getStateSet(); if(node_state) pushStateSet(node_state); handle_cull_callbacks_and_traverse(node); // pop the node's state off the render graph stack. if(node_state) popStateSet(); // pop the culling mode. popCurrentMask(); _firstCullStatus = firstStatus; _cullingStatus = status; }
void POVWriteNodeVisitor::apply(osg::Group& group) { _out << "/* A group starts... */\n\n"; // visiting children group.traverse(*this); _out << "/* A group ends... */\n\n"; }
void FindByNameVisitor::apply(osg::Group &group) { if (Misc::StringUtils::ciEqual(group.getName(), mNameToFind)) { mFoundNode = &group; return; } traverse(group); }
void CountsVisitor::apply(osg::Group& node) { pushStateSet(node.getStateSet()); _groups++; osg::ref_ptr<osg::Object> rp = (osg::Object*)&node; _uGroups.insert(rp); _totalChildren += node.getNumChildren(); apply(node.getStateSet()); if (++_depth > _maxDepth) _maxDepth = _depth; traverse((osg::Node&)node); _depth--; popStateSet(); }
void WriteNodeVisitor::apply(osg::Group& group) { _out << "<group>\n"; // visiting children group.traverse(*this); _out << "</group>\n"; }
void GeometryValidator::apply(osg::Group& group) { for(unsigned i=0; i<group.getNumChildren(); ++i) { osg::Geometry* geom = group.getChild(i)->asGeometry(); if ( geom ) { apply( *geom ); if ( geom->getVertexArray() == 0L ) { OE_NOTICE << "removing " << geom->getName() << " b/c of null vertex array\n"; group.removeChild(geom); --i; } } } }
void Actualizar(int x,int y,int tamaño) { boton=y; left=x; //top=(8*tamaño)+z; //right=(11*tamaño); int tamaño_cubo_grade=tamaño*5; nave* cubomio=new nave (x,y,0,tamaño_cubo_grade); int puntopunta=tamaño_cubo_grade; puntopunta=puntopunta/2; puntopunta=puntopunta-(tamaño/2); nave* cubomio2=new nave(x+puntopunta,y,tamaño_cubo_grade,tamaño); Torreta->replaceChild(Torreta->getChild(0),cubomio->getNave()); Torreta->replaceChild(Torreta->getChild(1),cubomio2->getNave()); top=tamaño_cubo_grade+tamaño+y; right=tamaño_cubo_grade+x; yDisparo=top; xDisparo=x+puntopunta; }
static bool readChildren( osgDB::InputStream& is, osg::Group& node ) { unsigned int size = 0; is >> size >> osgDB::BEGIN_BRACKET; for ( unsigned int i=0; i<size; ++i ) { osg::Node* child = dynamic_cast<osg::Node*>( is.readObject() ); if ( child ) node.addChild( child ); } is >> osgDB::END_BRACKET; return true; }
void ShaderGenerator::apply(osg::Group& group) { if ( !_active ) return; traverse(group); #if 0 std::set<VirtualProgram*> childVPs; unsigned childrenWithVP = 0; for(unsigned i=0; i<group.getNumChildren(); ++i) { osg::StateSet* stateset = group.getChild(i)->getStateSet(); if ( !stateset ) break; VirtualProgram* vp = dynamic_cast<VirtualProgram*>(stateset->getAttribute(VirtualProgram::SA_TYPE)); if ( vp ) { childVPs.insert( vp ); childrenWithVP++; } } if ( childrenWithVP == group.getNumChildren() && childVPs.size() == 1 ) { group.getOrCreateStateSet()->setAttributeAndModes( *childVPs.begin(), 1 ); for(unsigned i=0; i<group.getNumChildren(); ++i) { group.getChild(i)->getStateSet()->removeAttribute(VirtualProgram::SA_TYPE); } } #endif }
void TileMapper::apply(osg::Group& node) { if (node.getName()=="TileContent") { _containsGeode = true; return; } if (isCulled(node)) return; // push the culling mode. pushCurrentMask(); TileIdentifier* tid = dynamic_cast<TileIdentifier*>(node.getUserData()); if (tid) { _containsGeode = false; } traverse(node); if (tid) { if (_containsGeode) { insertTile(*tid); _containsGeode = false; } } // pop the culling mode. popCurrentMask(); }
torreta(int x, int y, int z,int tamaño) { Torreta = new osg::Group(); material = new osg::Material; stateset =new osg::StateSet; //Configurar_Material(); boton=y; left=x; //top=(8*tamaño)+z; //right=(11*tamaño); int tamaño_cubo_grade=tamaño*5; nave* cubomio=new nave (x,y,z,tamaño_cubo_grade); int puntopunta=tamaño_cubo_grade; puntopunta=puntopunta/2; puntopunta=puntopunta-(tamaño/2); nave* cubomio2=new nave(x+puntopunta,y,tamaño_cubo_grade+z,tamaño); Torreta->addChild(cubomio->getNave()); Torreta->addChild(cubomio2->getNave()); top=tamaño_cubo_grade+tamaño+y; right=tamaño_cubo_grade+x; yDisparo=top; xDisparo=x+puntopunta; stateset->setAttributeAndModes(material,osg::StateAttribute::OVERRIDE|osg::StateAttribute::OFF); };
void Configurar_Material() { // version which sets the color of the wireframe. material->setColorMode(osg::Material::OFF); // switch glColor usage off // turn all lighting off material->setShininess(osg::Material::FRONT_AND_BACK,10.0f); material->setAmbient(osg::Material::FRONT_AND_BACK, osg::Vec4(0.0,1.0f,0.0f,1.0f)); material->setDiffuse(osg::Material::FRONT_AND_BACK, osg::Vec4(0.0,1.0f,0.0f,1.0f)); material->setSpecular(osg::Material::FRONT_AND_BACK, osg::Vec4(0.0,1.0f,0.0f,1.0f)); // except emission... in which we set the color we desire material->setEmission(osg::Material::FRONT_AND_BACK, osg::Vec4(0.0,0.0f,0.0f,1.0f)); stateset->setAttributeAndModes(material,osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON); stateset->setMode(GL_LIGHTING,osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON); Torreta->setStateSet(stateset); }
void OcclusionQueryVisitor::apply( osg::Group& group ) { if (group.getNumParents() == 0) { // Can't add an OQN above a root node. traverse( group ); return; } int preTraverseOQNCount = getNameIdx(); traverse( group ); if (getNameIdx() > preTraverseOQNCount) // A least one OQN was added below the current node. // Don't add one here to avoid hierarchical nesting. return; // There are no OQNs below this group. If the vertex // count exceeds the threshold, add an OQN here. addOQN( group ); }
void TileMapper::apply(osg::Group& node) { if (node.getName()=="TileContent") { _containsGeode = true; return; } if (isCulled(node)) return; // push the culling mode. pushCurrentMask(); TileIdentifier* tid = dynamic_cast<TileIdentifier*>(node.getUserData()); if (tid) { _tileStack.push_back(TileStack::value_type(*tid,&node)); _containsGeode = false; } traverse(node); if (tid) { if (_containsGeode) { insertTile(*tid); _containsGeode = false; #if 0 std::cout<<"found Group="<<tid->lod <<" X="<<tid->x <<" Y="<<tid->y <<" ptr="<<&node<<std::endl; std::cout<<" inheritance list "<<_tileStack.size()<<std::endl; for(TileStack::iterator itr=_tileStack.begin(); itr!=_tileStack.end(); ++itr) { std::cout<<" LOD="<<itr->first.lod <<" X="<<itr->first.x <<" Y="<<itr->first.y <<" className="<<itr->second->className() <<" ptr="<<itr->second<<std::endl; } osg::StateSet* stateset = node.getOrCreateStateSet(); osg::Material* material = new osg::Material; material->setColorMode(osg::Material::OFF); stateset->setAttribute(material); switch(tid->lod) { case(0): material->setEmission(osg::Material::FRONT_AND_BACK,osg::Vec4(1.0f,1.0f,1.0f,1.0f)); break; case(1): material->setEmission(osg::Material::FRONT_AND_BACK,osg::Vec4(1.0f,0.0f,0.0f,1.0f)); break; case(2): material->setEmission(osg::Material::FRONT_AND_BACK,osg::Vec4(0.0f,1.0f,0.0f,1.0f)); break; case(3): material->setEmission(osg::Material::FRONT_AND_BACK,osg::Vec4(0.0f,0.0f,1.0f,1.0f)); break; case(4): material->setEmission(osg::Material::FRONT_AND_BACK,osg::Vec4(1.0f,0.0f,1.0f,1.0f)); break; } #endif } _tileStack.pop_back(); } // pop the culling mode. popCurrentMask(); }
void CVRCullVisitor::PostCullVisitor::apply(osg::Group& group) { group.setNodeMask(group.getNodeMask() & ~(FIRST_CULL_STATUS)); traverse(group); }
void apply( osg::Group& grp ) { grp.traverse( *this ); }
static bool checkChildren( const osg::Group& node ) { return node.getNumChildren()>0; }