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 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() ); }
Geode* createTextureQuad(Texture2D *texture) { Vec3Array *vertices = new Vec3Array; vertices->push_back(Vec3(-1.0, -1.0, 0.0)); vertices->push_back(Vec3(1.0, -1.0, 0.0)); vertices->push_back(Vec3(1.0, 1.0, 0.0)); vertices->push_back(Vec3(-1.0, 1.0, 0.0)); Vec2Array *texcoord = new Vec2Array; texcoord->push_back(Vec2(0.0, 0.0)); texcoord->push_back(Vec2(1.0, 0.0)); texcoord->push_back(Vec2(1.0, 1.0)); texcoord->push_back(Vec2(0.0, 1.0)); Geometry *geom = new Geometry; geom->setVertexArray(vertices); geom->setTexCoordArray(0, texcoord); geom->addPrimitiveSet(new DrawArrays(GL_QUADS, 0, 4)); Geode *geode = new Geode; geode->addDrawable(geom); geode->getOrCreateStateSet()->setTextureAttributeAndModes(0, texture, StateAttribute::ON); return geode; }
/*************************************************************** * Function: createText() ***************************************************************/ Geode *CAVEGroupReferenceAxis::createText3D(osgText::Text3D **text) { Geode *textGeode = new Geode; *text = new osgText::Text3D; textGeode->addDrawable(*text); (*text)->setFont(CAVEGeode::getDataDir() + "Fonts/TN.ttf"); (*text)->setCharacterSize(gCharSize, 0.7); (*text)->setCharacterDepth(gCharDepth); (*text)->setPosition(Vec3(0, 0, 0)); (*text)->setAlignment(osgText::Text3D::CENTER_BOTTOM); (*text)->setDrawMode(osgText::Text3D::TEXT); (*text)->setAxisAlignment(osgText::Text3D::XZ_PLANE); (*text)->setRenderMode(osgText::Text3D::PER_GLYPH); (*text)->setText(""); Material *material = new Material; material->setDiffuse(Material::FRONT_AND_BACK, Vec4(0, 1, 0, 1)); material->setAmbient(Material::FRONT_AND_BACK, Vec4(0, 1, 0, 1)); material->setAlpha(Material::FRONT_AND_BACK, 1.0f); StateSet *stateset = textGeode->getOrCreateStateSet(); stateset->setAttributeAndModes(material, StateAttribute::OVERRIDE | StateAttribute::ON); stateset->setMode(GL_BLEND, StateAttribute::OVERRIDE | StateAttribute::ON ); stateset->setRenderingHint(StateSet::TRANSPARENT_BIN); return textGeode; }
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 Marker::init(GeometryType gt, Interaction *interaction, float size, Vec4 &color) { Geode *geode; _gt = gt; if (_gt == CONE) geode = createCone(color); else if (_gt == BOX) geode = createBox(color); else geode = createSphere(color); setSize(size); setColor(color); // Make sure lighting is correct when marker is scaled: StateSet *stateSet = geode->getOrCreateStateSet(); stateSet->setMode(GL_RESCALE_NORMAL, StateAttribute::ON); //stateSet->setMode(GL_LIGHTING, osg::StateAttribute::OFF); // Philip added this else the color is not visible in opencover _interaction = interaction; _node->addChild(geode); if (_interaction) _interaction->addListener(this, this); _interactionA = new vrui::coTrackerButtonInteraction(vrui::coInteraction::ButtonA, "MarkerMove", vrui::coInteraction::Medium); _interactionB = NULL; assert(_interactionA); }
void _dwobj::buildDrawable(Group *grp, const osgDB::ReaderWriter::Options *options) { // current DWobject complete; make a drawable, and add it to a osg::Group if (nfaces>0) { if (themat->isType(dwmaterial::PointLight) || themat->isType(dwmaterial::SpotLight)) { Vec4 pos; pos.set(0.0f,0.0f,0.0f,0.0f); for (int i=0; i<nverts; i++) { pos[0]+=verts[i].x(); pos[1]+=verts[i].y(); pos[2]+=verts[i].z(); } pos/=nverts; pos[3]=1.0f; LightSource *ls=themat->makeLight(pos); grp->addChild(ls); } else { Geode *geode = new Geode; int nfnvf=0; // number of vertices for faces plus holes int i; // a general counter for (i=0; i<nfaces; i++) { // for each face faces[i].setnorm(verts); // set its normal and any hole normals nfnvf+=faces[i].getallverts(); // get total vertices in object, defines dimensions of NEW arrays } GLUtesselator* ts=gluNewTess(); gluTessCallback(ts, GLU_TESS_BEGIN, (GLU_TESS_CALLBACK) myFaceBegin); gluTessCallback(ts, GLU_TESS_VERTEX, (GLU_TESS_CALLBACK) myVertex); gluTessCallback(ts, GLU_TESS_END, (GLU_TESS_CALLBACK) myFaceEnd); gluTessCallback(ts, GLU_TESS_ERROR, (GLU_TESS_CALLBACK) error); gluTessCallback(ts, GLU_TESS_COMBINE_DATA, (GLU_TESS_CALLBACK) combineCallback); // for (int nvf=0; nvf<6; nvf++) { // for each length of face // for Geometry we dont need to collect prim types individually // prd.setmode(nvf , nfnvf); // filter out only this type of tessellated face prd=new prims; prd->settmat(tmat.get()); osg::Geometry *gset = new osg::Geometry; prd->setGeometry(gset); StateSet *dstate=themat->make(options); gset->setStateSet( dstate ); grp->addChild( geode ); // add to the world outside geode->addDrawable(gset); // each face adds a primitive to the geometry, after it is tessellated for (i=0; i<nfaces; i++) { // for each face, collect up prd->tessellate(faces[i],verts, themat, ts, this); } for (i=0; i<nopens; i++) { // for each hole, join up front & back with Quads if (fc1 && fc2) { faces[fc1[i]].link(openings[i*2], &faces[fc2[i]],openings[i*2+1],verts, themat); } } // for each opening prd->buildGeometry(); gluDeleteTess(ts); delete prd; } } // nfaces>0 verts.clear(); }
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); } }
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 IntersectVisitor::apply(Geode& geode) { if (!enterNode(geode)) return; for(unsigned int i = 0; i < geode.getNumDrawables(); i++ ) { intersect(*geode.getDrawable(i)); } leaveNode(); }
unsigned int Object3D::getNumDrawables() const { GeodeFindVisitor visitor; _originalNode->accept(visitor); Geode *geode = visitor.getFirst(); if(geode) { return geode->getNumDrawables(); } return 0; }
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; }
Geode* ChessUtils::createRectangleWithTexture(Vec3 centerPosition, Image* image, int width, int height, Vec4 color) { int halfWidth = width / 2; int halfHeight = height / 2; Vec3Array* vertices = new Vec3Array(); vertices->push_back(Vec3(centerPosition.x() - halfWidth, centerPosition.y() - halfHeight, centerPosition.z())); vertices->push_back(Vec3(centerPosition.x() + halfWidth, centerPosition.y() - halfHeight, centerPosition.z())); vertices->push_back(Vec3(centerPosition.x() + halfWidth, centerPosition.y() + halfHeight, centerPosition.z())); vertices->push_back(Vec3(centerPosition.x() - halfWidth, centerPosition.y() + halfHeight, centerPosition.z())); Vec3Array* normals = new Vec3Array(); normals->push_back(Vec3(0.0f, 0.0f, 1.0f)); Vec2Array* texcoords = new Vec2Array(); texcoords->push_back(Vec2(0.0f, 0.0f)); texcoords->push_back(Vec2(1.0f, 0.0f)); texcoords->push_back(Vec2(1.0f, 1.0f)); texcoords->push_back(Vec2(0.0f, 1.0f)); Vec4Array* colors = new Vec4Array(); colors->push_back(color); Geometry* quad = new Geometry(); quad->setVertexArray(vertices); quad->setNormalArray(normals); quad->setNormalBinding(osg::Geometry::BIND_OVERALL); quad->setColorArray(colors); quad->setColorBinding(osg::Geometry::BIND_OVERALL); quad->setTexCoordArray(0, texcoords); quad->addPrimitiveSet(new osg::DrawArrays(GL_QUADS, 0, 4)); Texture2D* texture = new Texture2D(); if (image != NULL) { texture->setImage(image); } Geode* geode = new Geode(); geode->addDrawable(quad); osg::BlendFunc* blendFunc = new osg::BlendFunc(); blendFunc->setFunction(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); osg::TexEnv* blendTexEnv = new osg::TexEnv(); blendTexEnv->setMode(osg::TexEnv::BLEND); osg::StateSet* geodeStateset = geode->getOrCreateStateSet(); geodeStateset->setAttributeAndModes(blendFunc); geodeStateset->setTextureAttribute(0, blendTexEnv); geodeStateset->setTextureAttributeAndModes(0, texture); geodeStateset->setRenderingHint(osg::StateSet::TRANSPARENT_BIN); return geode; }
AppState::AppState(osgViewer::Viewer* viewer_) : displayScene(true), invertRange(true), currentConfig(0), viewer(viewer_), zNear(0.03125) { sw = new Switch; string fontName("fonts/arial.ttf"); // Text description of current config configText = new osgText::Text; configText->setDataVariance(Object::DYNAMIC); configText->setFont(fontName); configText->setPosition(Vec3(50.0f, 50.0f, 0.0f)); configText->setColor(Vec4(1.0, 1.0, 1.0, 1.0)); Geode* textGeode = new Geode; textGeode->addDrawable(configText.get()); // Text for the near plane distance zNearText = new osgText::Text; zNearText->setDataVariance(Object::DYNAMIC); zNearText->setFont(fontName); zNearText->setPosition(Vec3(1230.0f, 50.0f, 0.0f)); zNearText->setColor(Vec4(1.0, 1.0, 1.0, 1.0)); zNearText->setAlignment(osgText::Text::RIGHT_BASE_LINE); textGeode->addDrawable(zNearText.get()); // Projection that lets the text be placed in pixels. textProjection = new Projection; textProjection->setMatrix(Matrix::ortho2D(0,1280,0,1024)); textProjection->addChild(textGeode); // "texture not available" text displayed when the user trys to // display the depth texture while multisampling. osgText::Text* noCanDo = new osgText::Text; noCanDo->setFont(fontName); noCanDo->setPosition(Vec3(512.0f, 384.0f, 0.0f)); noCanDo->setColor(Vec4(1.0, 0.0, 0.0, 1.0)); noCanDo->setText("not available"); textNotAvailable = new Geode; textNotAvailable->addDrawable(noCanDo); textProjection->addChild(textNotAvailable.get()); // Is the depth test inverted? osgText::Text* inverted = new osgText::Text; inverted->setFont(fontName); inverted->setPosition(Vec3(512.0f, 50.0f, 0.0f)); inverted->setColor(Vec4(1.0, 1.0, 1.0, 1.0)); inverted->setText("inverted depth test"); textInverted = new Geode; textInverted->addDrawable(inverted); textInverted->setNodeMask(~0u); textProjection->addChild(textInverted.get()); textProjection->getOrCreateStateSet()->setRenderBinDetails(11, "RenderBin"); }
Geode *Marker::createBox(Vec4 &color) { Geode *geode = new Geode(); TessellationHints *hints = new TessellationHints(); hints->setDetailRatio(0.3f); Vec3 boxCenter(0.0f, 0.0f, 0.0f); _boxShape = new Box(boxCenter, 1.0f); _shapeDrawable = new ShapeDrawable(_boxShape); _shapeDrawable->setTessellationHints(hints); _shapeDrawable->setColor(color); geode->addDrawable(_shapeDrawable); _shapeDrawable->setUseDisplayList(false); // allow changes to color and shape return geode; }
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); }
OpenRAVE::GraphHandlePtr OSGViewer::plot3(const float* ppoints, int numPoints, int stride, float pointsize, const float* colors, int drawstyle, bool bhasalpha) { osg::Geometry* geom = new osg::Geometry; int floats_per_pt = stride / sizeof(float); Vec3Array* osgPts = new Vec3Array; osgPts->reserve(numPoints); for (int i=0; i < numPoints; ++i) { const float* p = ppoints + i*floats_per_pt; if (isfinite(p[0])) osgPts->push_back(osg::Vec3(p[0], p[1], p[2])); } osg::StateSet* ss = geom->getOrCreateStateSet(); osg::Point *point = new osg::Point(); point->setSize(pointsize); ss->setAttribute(point); ss->setMode(GL_LIGHTING, osg::StateAttribute::OFF); osg::BlendFunc* blendFunc = new osg::BlendFunc; blendFunc->setFunction(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); ss->setAttributeAndModes(blendFunc); ss->setMode(GL_BLEND, osg::StateAttribute::ON); geom->setVertexArray(osgPts); geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::POINTS,0,osgPts->size())); // // if (colors != NULL) { // Vec4Array* osgCols = new Vec4Array; // for (int i=0; i < numPoints; ++i) { // float* p = colors + i; // osgCols->push_back(osg::Vec4(p[0], p[1], p[2],1)); // } // geom->setColorArray(osgCols); // geom->setColorBinding(osg::Geometry::BIND_PER_VERTEX); // } Geode* geode = new osg::Geode(); geode->addDrawable(geom); return GraphHandlePtr(new OsgGraphHandle(geode, m_root.get())); }
void World::addDrawable(Drawable::Drawable *drawable, Transform *transform, std::string name) { // adding all to top-level group for now Geode *geo = new Geode; geo->addDrawable(drawable); if(transform) { transform->addChild(geo); _root->addChild(transform); } else { _root->addChild(geo); } if(!name.empty()) { _names[name] = drawable; } //notifyViews(); }
Geode *Marker::createSphere(Vec4 &color) { Geode *geode = new Geode(); // setDetailRatio is a factor to multiply the default values for // numSegments (40) and numRows (10). // They won't go below the minimum values of MIN_NUM_SEGMENTS = 5, MIN_NUM_ROWS = 3 TessellationHints *hints = new TessellationHints(); hints->setDetailRatio(0.3f); Vec3 sphereCenter(0.0f, 0.0f, 0.0f); _sphereShape = new Sphere(sphereCenter, 1.0f); _shapeDrawable = new ShapeDrawable(_sphereShape); _shapeDrawable->setTessellationHints(hints); _shapeDrawable->setColor(color); geode->addDrawable(_shapeDrawable); _shapeDrawable->setUseDisplayList(false); // allow changes to color and shape return geode; }
Geode *Marker::createCone(Vec4 &color) { Geode *geode = new Geode(); // setDetailRatio is a factor to multiply the default values for // numSegments (40) and numRows (10). // They won't go below the minimum values of MIN_NUM_SEGMENTS = 5, MIN_NUM_ROWS = 3 TessellationHints *hints = new TessellationHints(); hints->setDetailRatio(0.3f); // Create cone geometry: _coneShape = new Cone(Vec3(0, 0, 0), 0.1f, 0.5f); // center, radius, height _shapeDrawable = new ShapeDrawable(_coneShape); _shapeDrawable->setTessellationHints(hints); _shapeDrawable->setColor(color); _shapeDrawable->setUseDisplayList(false); // allow changes to color and shape geode->addDrawable(_shapeDrawable); return geode; }
Group* CreateBomb() { MatrixTransform *matrix_trans = new MatrixTransform(); Matrix *matrix = new Matrix(); Geode *node = new Geode(); float radius = 10; //创建精细度对象,精细度越高,细分就越多 osg::TessellationHints* hints = new osg::TessellationHints; //设置精细度为0.5f hints->setDetailRatio(0.5f); //添加一个球体,第一个参数是预定义几何体对象,第二个是精细度,默认为0 node->addDrawable(new osg::ShapeDrawable(new osg::Sphere(osg::Vec3(0, 100, 300), radius),hints)); matrix_trans->addChild(node); matrix_trans->setUpdateCallback(new BombCallback(Vec3(0,100,300))); //matrix_trans->setDataVariance(osg::Object::DYNAMIC); return matrix_trans; }
PositionAttitudeTransform *VideoGeode::createVideoSphere(float size, bool texRepeat) { Geode *sphere = new Geode(); sphere->addDrawable(new ShapeDrawable(new Sphere(Vec3(0, 0, 4), size))); // assign the material to the sphere StateSet *sphereStateSet = sphere->getOrCreateStateSet(); sphereStateSet->ref(); sphereStateSet->setAttribute(_material); try { sphereStateSet->setTextureAttributeAndModes(0, createVideoTexture(texRepeat), StateAttribute::ON); } catch (char *e) { throw e; } PositionAttitudeTransform *sphereTransform = new PositionAttitudeTransform(); sphereTransform->addChild(sphere); return sphereTransform; }
/*************************************************************** * Function: switchFloorplan() ***************************************************************/ void VirtualScenicHandler::switchFloorplan(const int &idx, const VisibilityOption &option) { if (idx >= mFloorplanSwitch->getNumChildren()) { return; } if (option == INVISIBLE) { if (mFloorplanIdx >= 0) { mFloorplanSwitch->setSingleChildOn(mFloorplanIdx); } else { mFloorplanSwitch->setAllChildrenOff(); } } else { Geode *floorplanGeode = dynamic_cast <Geode*> (mFloorplanSwitch->getChild(idx)); StateSet *stateset = floorplanGeode->getOrCreateStateSet(); Material *material = dynamic_cast<Material*> (stateset->getAttribute(StateAttribute::MATERIAL)); if (!material) { material = new Material; } if (option == TRANSPARENT) { material->setAlpha(Material::FRONT_AND_BACK, 0.5f); } else if (option == SOLID) { material->setAlpha(Material::FRONT_AND_BACK, 1.0f); mFloorplanIdx = idx; } mFloorplanSwitch->setSingleChildOn(idx); } }
TFColorWidget::TFColorWidget(Interaction *interaction, Measure *b, int size) : Widget() , Events() { _interaction = interaction; Geode *geode = new Geode(); _geom = new Geometry(); _geom->setUseDisplayList(false); _vertices = new Vec3Array(); _vertices->push_back(Vec3(0, 0, 0)); _vertices->push_back(Vec3(0, 0, .2)); _vector = (*_vertices)[1] - (*_vertices)[0]; _vector.normalize(); _geom->setVertexArray(_vertices); DrawElementsUInt *line = new DrawElementsUInt(osg::PrimitiveSet::LINES, 0); line->push_back(0); line->push_back(1); _geom->addPrimitiveSet(line); _colors = new Vec4Array(1); (*_colors)[0].set(0.0, 0.0, 0.0, 1.0); _geom->setColorArray(_colors); _geom->setColorBinding(osg::Geometry::BIND_OVERALL); geode->addDrawable(_geom); _node->addChild(geode); LineWidth *width = new LineWidth(); width->setWidth(size); StateSet *state = _geom->getOrCreateStateSet(); state->setAttribute(width, osg::StateAttribute::ON); state->setMode(GL_LIGHTING, StateAttribute::OFF); _interaction->addListener(this, this); }
OpenRAVE::GraphHandlePtr OSGViewer::drawlinelist(const float *ppoints, int numPoints, int stride, float fwidth, const RaveVectorf &color) { osg::Geometry* geom = new osg::Geometry; int floats_per_pt = stride / sizeof(float); Vec3Array* osgPts = new Vec3Array; osgPts->reserve(numPoints); for (int i=0; i < numPoints; ++i) { const float* p = ppoints + i*floats_per_pt; if (isfinite(p[0])) osgPts->push_back(osg::Vec3(p[0], p[1], p[2])); } osg::StateSet* ss = geom->getOrCreateStateSet(); osg::LineWidth *lw= new osg::LineWidth; lw->setWidth(fwidth); ss->setAttribute(lw); ss->setMode(GL_LIGHTING, osg::StateAttribute::OFF); osg::BlendFunc* blendFunc = new osg::BlendFunc; blendFunc->setFunction(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); ss->setAttributeAndModes(blendFunc); ss->setMode(GL_BLEND, osg::StateAttribute::ON); osg::Vec4Array* osgColor = new osg::Vec4Array(); osgColor->push_back( osg::Vec4( color[0], color[1], color[2], color[3] ) ); geom->setColorArray(osgColor); geom->setColorBinding(osg::Geometry::BIND_OVERALL); geom->setVertexArray(osgPts); geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINES,0,osgPts->size())); Geode* geode = new osg::Geode(); geode->addDrawable(geom); return GraphHandlePtr(new OsgGraphHandle(geode, m_root.get())); }
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(); } } } }
/** 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 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; }
PositionAttitudeTransform *VideoGeode::createVideoPlane(float sizeX, float sizeY, bool texRepeat) { // vertex array Vec3Array *vertexArray = new Vec3Array(); sizeX /= 2.0; sizeY /= 2.0; vertexArray->push_back(Vec3(-sizeX, 0, -sizeY)); vertexArray->push_back(Vec3(sizeX, 0, -sizeY)); vertexArray->push_back(Vec3(sizeX, 0, sizeY)); vertexArray->push_back(Vec3(-sizeX, 0, sizeY)); /*vertexArray->push_back(Vec3(-sizeX, -sizeY, 0)); vertexArray->push_back(Vec3(sizeX, -sizeY, 0)); vertexArray->push_back(Vec3(sizeX, sizeY, 0)); vertexArray->push_back(Vec3(-sizeX, sizeY, 0));*/ // face array DrawElementsUInt *faceArray = new DrawElementsUInt(PrimitiveSet::TRIANGLES, 0); faceArray->push_back(0); // face 1 faceArray->push_back(1); faceArray->push_back(2); faceArray->push_back(2); // face 2 faceArray->push_back(3); faceArray->push_back(0); // normal array Vec3Array *normalArray = new Vec3Array(); normalArray->push_back(Vec3(0, 0, 1)); // normal index TemplateIndexArray<unsigned int, Array::UIntArrayType, 24, 4> *normalIndexArray; normalIndexArray = new TemplateIndexArray<unsigned int, Array::UIntArrayType, 24, 4>(); normalIndexArray->push_back(0); normalIndexArray->push_back(0); normalIndexArray->push_back(0); normalIndexArray->push_back(0); // texture coordinates Vec2Array *texCoords = new Vec2Array(); texCoords->push_back(Vec2(0.0f, 0.0f)); texCoords->push_back(Vec2(1.0f, 0.0f)); texCoords->push_back(Vec2(1.0f, 1.0f)); texCoords->push_back(Vec2(0.0f, 1.0f)); Geometry *geometry = new Geometry(); geometry->setVertexArray(vertexArray); geometry->setNormalArray(normalArray); geometry->setNormalIndices(normalIndexArray); geometry->setNormalBinding(Geometry::BIND_PER_VERTEX); geometry->setTexCoordArray(0, texCoords); geometry->addPrimitiveSet(faceArray); Geode *plane = new Geode(); plane->addDrawable(geometry); // assign the material to the sphere StateSet *planeStateSet = plane->getOrCreateStateSet(); planeStateSet->ref(); planeStateSet->setAttribute(_material); try { planeStateSet->setTextureAttributeAndModes(0, createVideoTexture(texRepeat), StateAttribute::ON); } catch (char *e) { throw e; } PositionAttitudeTransform *planeTransform = new PositionAttitudeTransform(); planeTransform->addChild(plane); return planeTransform; }