Hi Yu, Could it be that you haven't done anything to update the position of the viewer Camera to account or the scene that you've just updated? My guess is that it's simply that the viewer's Camera is still in it's default position looking at the center of the empty canvas node.
Robert. On 18 July 2014 17:33, Yu Zhang <[email protected]> wrote: > Hi experts, > > I have 2 piece of code, use tessellaor to extrude and hole generation. > Looks the setSceneData should call after hole tessellation operation, > otherwise the viewer will draw nothing. Could you please advice on how > to setSceneData the root nodes in the begin of application, and update > the tessellated geometries in the runtime? > > Code piece A runs fine.: > > _viewer.setSceneData( canvas ); //canvas is a osg::Group, root node > > osg::ref_ptr<osg::Vec3Array> vertices = new osg::Vec3Array; > vertices->push_back(osg::Vec3(1.0, 1.0, 0.0)); > vertices->push_back(osg::Vec3(-1.0, 1.0, 0.0)); > vertices->push_back(osg::Vec3(-1.0, -1.0, 0.0)); > vertices->push_back(osg::Vec3(1.0, -1.0, 0.0)); > > osg::ref_ptr<osg::Vec3Array> newVertices = new osg::Vec3Array; > newVertices->insert( newVertices->begin(), vertices->begin(), > vertices->end() ); > > unsigned int numVertices = vertices->size(); > osg::Vec3 offset = osg::Vec3(0.0, 0.0, 1.0) * 1.0; > for ( osg::Vec3Array::reverse_iterator ritr=vertices->rbegin(); > ritr!=vertices->rend(); ++ritr ) > { > newVertices->push_back( (*ritr) + offset ); > } > > osg::ref_ptr<osg::Geometry> extrusion = new osg::Geometry; > extrusion->setVertexArray( newVertices.get() ); > extrusion->addPrimitiveSet( new osg::DrawArrays(GL_POLYGON, 0, > numVertices) ); > extrusion->addPrimitiveSet( new osg::DrawArrays(GL_POLYGON, > numVertices, numVertices) ); > > osgUtil::Tessellator tessellator; > tessellator.setTessellationType( > osgUtil::Tessellator::TESS_TYPE_GEOMETRY ); > tessellator.setWindingType( osgUtil::Tessellator::TESS_WINDING_ODD ); > tessellator.retessellatePolygons( *extrusion ); > > osg::ref_ptr<osg::DrawElementsUInt> sideIndices = new > osg::DrawElementsUInt( GL_QUAD_STRIP ); > for ( unsigned int i=0; i<numVertices; ++i ) > { > sideIndices->push_back( i ); > sideIndices->push_back( (numVertices-1-i) + numVertices ); > } > sideIndices->push_back( 0 ); > sideIndices->push_back( numVertices*2 - 1 ); > extrusion->addPrimitiveSet( sideIndices.get() ); > > osg::Geode* geode = new osg::Geode; > geode->addDrawable(extrusion); > canvas->addChild(geode); > > Code piece B: runs without any geometry showed, if I put the first > setSceneData to the last line, it works. > > _viewer.setSceneData( canvas ); > > int nstart=0; // counts vertices used for the geometry primitives > > osg::ref_ptr<osg::Geometry> gtess= new osg::Geometry; > int i; > osg::ref_ptr<osg::Vec3Array> coords = new osg::Vec3Array; > double zpos = 0.0; > // front wall > static GLdouble wall[5][2] = > { { 2200.0, 1130.0 }, > { 2600.0, 1130.0 }, > { 2600.0, 1340.0 }, > { 2400.0, 1440.0 }, > { 2200.0, 1340.0 } }; > > static GLdouble windows[16][2] = > { { 2240.0, 1180.0 }, > { 2330.0, 1180.0 }, > { 2330.0, 1220.0 }, > { 2240.0, 1220.0 } }; > > gtess->setVertexArray(coords); > > // add one large pentagon -the wall > for (i = 0; i < 5; i++) { > coords->push_back(osg::Vec3(wall[i][0],zpos,wall[i][1])); > } > > osg::ref_ptr<osg::DrawArrays> contour1 = new > osg::DrawArrays(osg::PrimitiveSet::POLYGON,nstart,5); > gtess->addPrimitiveSet(contour1);nstart+=5; > > // and windows > for (i = 0; i < 4; i++) { > coords->push_back(osg::Vec3(windows[i][0],zpos,windows[i][1])); > } > > osg::ref_ptr<osg::DrawArrays> contour2 = new > osg::DrawArrays(osg::PrimitiveSet::QUADS,nstart,4); > gtess->addPrimitiveSet(contour2);nstart+=4; > > osgUtil::Tessellator tscx; // the v1.2 multi-contour Tessellator. > > tscx.setTessellationType(osgUtil::Tessellator::TESS_TYPE_GEOMETRY); > tscx.setBoundaryOnly(false); > tscx.setWindingType( osgUtil::Tessellator::TESS_WINDING_ODD); > > tscx.retessellatePolygons(*gtess); > > osg::Geode* geode = new osg::Geode; > geode->addDrawable(gtess); > canvas->addChild(geode); > > OSG 3.2.0 OS X 10.9.4, with Qt 4.8.6 with osgQt > > Thank you! > > Cheers, > Yu > > ------------------ > Read this topic online here: > http://forum.openscenegraph.org/viewtopic.php?p=60336#60336 > > > > > > _______________________________________________ > osg-users mailing list > [email protected] > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org >
_______________________________________________ osg-users mailing list [email protected] http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

