void loadGeom( const char *filename, osg::NodePtr *node ) { // load file osg::NodePtr filescene = osg::SceneFileHandler::the().read( filename ); if ( filescene == osg::NullFC ) { fprintf(stderr, "\nCouldn't open file %s\n", filename ); exit(-1); } // create new geometry osg::NodePtr nod = osg::Node::create(); col::mergeGeom( filescene, &nod ); // scale geom nod->updateVolume(); //tanglei comment this, act as kcbp_cgal_cuda Pnt3f low, high; nod->getVolume().getBounds( low, high ); Pnt3f c = col::lincomb( 0.5, low, 0.5, high ); Pnt3f d = col::lincomb( 0.5, high, -0.5, low ); // d=0.5*(high-low), is actually a vector float s = col_max3( d[0], d[1], d[2] ); osg::MFPnt3f *points = col::getPoints( nod ); beginEditCP( nod ); for ( unsigned int i = 0; i < points->size(); i ++ ) for ( unsigned int j = 0; j < 3; j ++ ) (*points)[i][j] = ((*points)[i][j] - c[j]) / s; endEditCP( nod ); nod->updateVolume(); *node = nod; }
void addWithHull( osg::NodePtr testObj ) { testGeom = osg::GeometryPtr::dcast( testObj->getCore() ); testHull = testGeom; testHullObj = testHull.getGeomNode(); testHull.print(); // set material osg::SimpleMaterialPtr mat = osg::SimpleMaterial::create(); mat->setDiffuse( osg::Color3f( 1.0,0.7,1.0 ) ); mat->setAmbient( osg::Color3f( 0.2,0.2,0.2 ) ); mat->setSpecular( osg::Color3f( 1,1,1 ) ); mat->setShininess( 20 ); testGeom->setMaterial( mat ); osg::GeometryPtr::dcast(testHullObj->getCore())->setMaterial( mat ); // add to scene graph beginEditCP(root); root->addChild( testObj ); root->addChild( testHullObj ); endEditCP(root); }
int main( int argc, char *argv[] ) { // parse command line options parsecommandline( argc, argv ); // OSG init osg::osgLog().setLogLevel(osg::LOG_WARNING); osg::osgInit(argc, argv); // disable display lists osg::FieldContainerPtr pProto= osg::Geometry::getClassType().getPrototype(); osg::GeometryPtr pGeoProto = osg::GeometryPtr::dcast(pProto); if ( pGeoProto != osg::NullFC ) pGeoProto->setDlistCache(false); // create the graph osg::NodePtr node; // root root = osg::Node::create(); beginEditCP(root); root->setCore( osg::Group::create() ); // beacon for camera and light osg::NodePtr beacon; beacon = osg::Node::create(); beginEditCP(beacon); beacon->setCore( osg::Group::create() ); endEditCP(beacon); // light light_node = osg::Node::create(); osg::DirectionalLightPtr light = osg::DirectionalLight::create(); beginEditCP( light_node ); light_node->setCore( light ); endEditCP( light_node ); root->addChild( light_node ); beginEditCP(light); light->setAmbient( .3, .3, .3, 1 ); light->setDiffuse( 1, 1, 1, 1 ); light->setDirection(0,0,1); light->setBeacon( beacon ); endEditCP(light); // transformation, parent of beacon node = osg::Node::create(); cam_trans = osg::Transform::create(); beginEditCP(node); node->setCore( cam_trans ); node->addChild( beacon ); endEditCP(node); root->addChild( node ); // finish scene graph endEditCP(root); // Camera osg::PerspectiveCameraPtr cam = osg::PerspectiveCamera::create(); cam->setBeacon( beacon ); cam->setFov( 50 ); cam->setNear( 0.1 ); cam->setFar( 10000 ); // Background osg::SolidBackgroundPtr background = osg::SolidBackground::create(); // Viewport osg::ViewportPtr vp = osg::Viewport::create(); vp->setCamera( cam ); vp->setBackground( background ); vp->setRoot( root ); vp->setSize( 0,0, 1,1 ); if ( with_window ) { // GLUT init glutInitWindowSize( 400, 400 ); // before glutInit so user can glutInitWindowPosition( 100, 100 ); // override with comannd line args glutInit(&argc, argv); glutInitDisplayMode( GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE); int winid = glutCreateWindow("Polygon Intersection Check Test"); glutKeyboardFunc(key); glutVisibilityFunc(vis); glutReshapeFunc(reshape); glutDisplayFunc(display); glutMouseFunc(mouse); glutMotionFunc(motion); glutIdleFunc(display); glEnable( GL_DEPTH_TEST ); glEnable( GL_LIGHTING ); glEnable( GL_LIGHT0 ); // Window osg::GLUTWindowPtr gwin; GLint glvp[4]; glGetIntegerv( GL_VIEWPORT, glvp ); gwin = osg::GLUTWindow::create(); gwin->setId(winid); gwin->setSize( glvp[2], glvp[3] ); win = gwin; win->addPort( vp ); // Action render_action = osg::DrawAction::create(); // trackball Vec3f min(-1,-1,-1), max(1,1,1); // root->updateVolume(); // const osg::BoxVolume &vol = dynamic_cast<const osg::BoxVolume &>(root->getVolume()); // // in the long term, the abstract volume will be able to provide min/max // vol.getBounds( min, max ); trackball.setMode( osg::Trackball::OSGObject ); float d = max[2] + (max[2]-min[2])*1.5; trackball.setStartPosition( 0, 0, d, true ); trackball.setSum( true ); trackball.setTranslationMode( osg::Trackball::OSGFree ); // run... glutMainLoop(); } else { // run in batch mode int phase = 0; do testcase( &phase ); while ( phase > 0 ); } return 0; }
void testcase( int *phase ) { static testObj poly1( 3 ); // triangle static testObj poly2( 3 ); // triangle static testObj poly3( 4 ); // quadrangle static testObj poly4( -4 ); // quadstrip osg::MFPnt3f& p1 = * poly1.p; osg::MFPnt3f& p2 = * poly2.p; osg::MFPnt3f& p3 = * poly3.p; osg::MFPnt3f& p4 = * poly4.p; int result_wanted; bool result; static int n_rand_trian = 0; // We do a default selection for every test frame. Only for the cases // where poly3 and/or poly4 is used, a special selection is necessary! poly1.setActive( light_node, false ); poly2.setActive( light_node, false ); poly3.setActive( light_node, false ); poly4.setActive( light_node, false ); static testObjP obj1 = &poly1; testObjP obj2 = &poly2; printf("phase %d\n", *phase ); switch ( *phase ) { // selection and deselection of nodes is necessary b/c of the // possibility to jump into each phase by pressing keys 0..9 case 0: // 2 triangles touching in one vertex beginEditCP(poly1.pnts); p1[0][0] = 0; p1[0][1] = 0; p1[0][2] = 0; p1[1][0] = 1; p1[1][1] = 0; p1[1][2] = 0; p1[2][0] = 0; p1[2][1] = 1; p1[2][2] = 0; endEditCP(poly1.pnts); beginEditCP(poly2.pnts); p2[0][0] = 0; p2[0][1] = 0; p2[0][2] = 0; p2[1][0] = -1; p2[1][1] = 0; p2[1][2] = 0; p2[2][0] = 0; p2[2][1] = -1; p2[2][2] = 0; endEditCP(poly2.pnts); result_wanted = 1; (*phase) ++ ; break; case 1: // 2 triangles touching edge on vertex beginEditCP(poly1.pnts); p1[0][0] = 0; p1[0][1] = 0; p1[0][2] = 0; p1[1][0] = 1; p1[1][1] = 0; p1[1][2] = 0; p1[2][0] = 0; p1[2][1] = 1; p1[2][2] = 0; endEditCP(poly1.pnts); beginEditCP(poly2.pnts); p2[0][0] = -1.0; p2[0][1] = 1.0; p2[0][2] = 0; p2[1][0] = -1.0; p2[1][1] = -1.0; p2[1][2] = 0; p2[2][0] = 1.0; p2[2][1] = -1.0; p2[2][2] = 0; endEditCP(poly2.pnts); (*phase) ++ ; result_wanted = 1; break; case 2: // 2 parallel triangles not quite touching beginEditCP(poly1.pnts); p1[0][0] = 0; p1[0][1] = 0.0; p1[0][2] = 0.0; p1[1][0] = 1; p1[1][1] = 0.1; p1[1][2] = 0.2; p1[2][0] = 0; p1[2][1] = 1.0; p1[2][2] = 0.3; endEditCP(poly1.pnts); beginEditCP(poly2.pnts); for ( int i = 0; i < 3; i ++ ) { p2[i][0] = p1[i][0]; p2[i][1] = p1[i][1]; p2[i][2] = p1[i][2] + 1E-4; } endEditCP(poly2.pnts); (*phase) ++ ; result_wanted = 0; break; case 3: // 2 triangles touching plane on vertex beginEditCP(poly1.pnts); p1[0][0] = 0; p1[0][1] = 0; p1[0][2] = 0; p1[1][0] = 1; p1[1][1] = 0; p1[1][2] = 0; p1[2][0] = 0; p1[2][1] = 1; p1[2][2] = 0; endEditCP(poly1.pnts); beginEditCP(poly2.pnts); p2[0][0] = -1; p2[0][1] = 1; p2[0][2] = 1; p2[1][0] = 0; p2[1][1] = 0; p2[1][2] = -1; p2[2][0] = 1; p2[2][1] = -1; p2[2][2] = 1; endEditCP(poly2.pnts); (*phase) ++ ; result_wanted = 1; break; case 4: // 2 triangles touching plane on edge beginEditCP(poly1.pnts); p1[0][0] = 0; p1[0][1] = 0; p1[0][2] = 0; p1[1][0] = 1; p1[1][1] = 0; p1[1][2] = 0; p1[2][0] = 0; p1[2][1] = 1; p1[2][2] = 0; endEditCP(poly1.pnts); beginEditCP(poly2.pnts); p2[0][0] = 0; p2[0][1] = 0; p2[0][2] = 2; p2[1][0] = 0; p2[1][1] = -1; p2[1][2] = -1; p2[2][0] = 0; p2[2][1] = 2; p2[2][2] = -1; endEditCP(poly2.pnts); (*phase) ++ ; result_wanted = 1; break; case 5: // triangle and quadrangle touching beginEditCP(poly1.pnts); p1[0][0] = 0; p1[0][1] = 0; p1[0][2] = 0; p1[1][0] = 1; p1[1][1] = 0; p1[1][2] = 0; p1[2][0] = 0; p1[2][1] = 1; p1[2][2] = 0; endEditCP(poly1.pnts); obj2 = &poly3; beginEditCP(poly3.pnts); p3[0][0] = 0; p3[0][1] = 1; p3[0][2] = 1; p3[1][0] = 0; p3[1][1] = 1; p3[1][2] = -1; p3[2][0] = 0; p3[2][1] = -1; p3[2][2] = -1; p3[3][0] = 0; p3[3][1] = -1; p3[3][2] = 1; endEditCP(poly3.pnts); obj2 = &poly3; // select poly3 !!! (*phase) ++ ; result_wanted = 1; break; case 6: // triangle and quadstrip touching beginEditCP(poly1.pnts); p1[0][0] = 0; p1[0][1] = 0; p1[0][2] = 0; p1[1][0] = 1; p1[1][1] = 0; p1[1][2] = 0; p1[2][0] = 0; p1[2][1] = 1; p1[2][2] = 0; endEditCP(poly1.pnts); beginEditCP(poly4.pnts); p4[0][0] = 0; p4[0][1] = 1; p4[0][2] = 1; p4[1][0] = 0; p4[1][1] = 1; p4[1][2] = -1; p4[2][0] = 0; p4[2][1] = -1; p4[2][2] = 1; p4[3][0] = 0; p4[3][1] = -1; p4[3][2] = -1; endEditCP(poly4.pnts); obj2 = &poly4; // select poly4 !!! (*phase) ++ ; result_wanted = 1; break; case 7 : //poly3.setActive( light_node, false );//de-select poly3 beginEditCP(poly1.pnts); p1[0][0] = -0.176454; p1[0][1] = 0.071328; p1[0][2] = 0.213297; p1[1][0] = -0.163126; p1[2][1] = 0.060675; p1[1][2] = 0.197186; p1[2][0] = -0.201797; p1[1][1] = 0.071328; p1[2][2] = 0.189499; endEditCP(poly1.pnts); beginEditCP(poly2.pnts); p2[0][0] = -0.202112; p2[0][1] = 0.080522; p2[0][2] = 0.183896; p2[1][0] = -0.178983; p2[1][1] = 0.083684; p2[1][2] = 0.212995; p2[2][0] = -0.165755; p2[2][1] = 0.072958; p2[2][2] = 0.191836; endEditCP(poly2.pnts); (*phase) ++ ; result_wanted = 0; break; case 8: beginEditCP(poly1.pnts); p1[0][0] = -0.163126; p1[0][1] = 0.060675; p1[0][2] = 0.197186; p1[1][0] = -0.186555; p1[1][1] = 0.060675; p1[1][2] = 0.175186; p1[2][0] = -0.201797; p1[2][1] = 0.071328; p1[2][2] = 0.189499; endEditCP(poly1.pnts); beginEditCP(poly2.pnts); p2[0][0] = -0.202112; p2[0][1] = 0.080522; p2[0][2] = 0.183896; p2[1][0] = -0.178983; p2[1][1] = 0.083684; p2[1][2] = 0.212995; p2[2][0] = -0.165755; p2[2][1] = 0.072958; p2[2][2] = 0.191836; endEditCP(poly2.pnts); (*phase) ++ ; result_wanted = 0; break; case 9: beginEditCP(poly1.pnts); p1[0][0] = -0.176454; p1[0][1] = 0.071328; p1[0][2] = 0.213297; p1[1][0] = -0.201797; p1[1][1] = 0.071328; p1[1][2] = 0.189499; p1[2][0] = -0.218691; p1[2][1] = 0.075000; p1[2][2] = 0.205365; endEditCP(poly1.pnts); beginEditCP(poly2.pnts); p2[0][0] = -0.202112; p2[0][1] = 0.080522; p2[0][2] = 0.183896; p2[1][0] = -0.178983; p2[1][1] = 0.083684; p2[1][2] = 0.212995; p2[2][0] = -0.165755; p2[2][1] = 0.072958; p2[2][2] = 0.191836; endEditCP(poly2.pnts); (*phase) ++ ; result_wanted = 0; break; case 10: beginEditCP(poly1.pnts); p1[0][0] = -0.018837; p1[0][1] = 0.075000; p1[0][2] = 0.299408; p1[1][0] = -0.056214; p1[1][1] = 0.075000; p1[1][2] = 0.294687; p1[2][0] = -0.060557; p1[2][1] = 0.071328; p1[2][2] = 0.317451; endEditCP(poly1.pnts); p2[0][0] = -0.049907; p2[0][1] = 0.086203; p2[0][2] = 0.296841; p2[1][0] = -0.057335; p2[1][1] = 0.080902; p2[1][2] = 0.326649; p2[2][0] = -0.043106; p2[2][1] = 0.084220; p2[2][2] = 0.338304; endEditCP(poly2.pnts); (*phase) ++ ; result_wanted = 0; break; case 11: // 2 out of 1000 random triangles beginEditCP(poly1.pnts); for ( unsigned int i = 0; i < 3; i ++ ) for ( unsigned int j = 0; j < 3; j ++ ) p1[i][j] = col::pseudo_randomf(); // should produce the same sequence every time endEditCP(poly1.pnts); beginEditCP(poly2.pnts); for ( unsigned int i = 0; i < 3; i ++ ) for ( unsigned int j = 0; j < 3; j ++ ) p2[i][j] = col::pseudo_randomf(); endEditCP(poly2.pnts); n_rand_trian ++ ; if ( n_rand_trian >= Num_rand_triangles ) { n_rand_trian = 0; // else repeat this phase (*phase) ++ ; } result_wanted = -1; // = don't know break; default: // last phase has been reached, signal to caller *phase = 0; } // activate selected objects for rendering (don't do this before the switch // statement - there are cases, where obj1 or obj2 is changed!) obj1->setActive( light_node, true ); obj2->setActive( light_node, true ); try { // check intersection of the 2 triangles result = col::intersectPolygons( &((*obj1->p)[0]), obj1->_nPnts, &((*obj2->p)[0]), obj2->_nPnts ); } catch ( col::XCollision /*&x*/ ) { fputs("intersect: exception XCollision!\n", stderr ); } if ( *phase > 0 ) // skip default: case { if ( result_wanted == -1 ) { printf("Polygons %s\n", result ? "intersect" : "don't intersect" ); } else { printf("Polygons %s %s\n", result ? "intersect" : "don't intersect", ( result != result_wanted ) ? "ERROR!" : " -> OK" ); } } }
testObj::testObj( int nPnts ) : _nPnts(nPnts), _isActive(false) { node = osg::Node::create(); osg::GeometryPtr geom = osg::Geometry::create(); pnts = osg::GeoPositions3f::create(); osg::GeoIndicesUI32Ptr index = osg::GeoIndicesUI32::create(); osg::GeoPLengthsUI32Ptr lengths = osg::GeoPLengthsUI32::create(); osg::GeoPTypesUI8Ptr type = osg::GeoPTypesUI8::create(); // special for quadstrips: if ( nPnts == -4 ) nPnts = 4; // CAUTION: don't use _nPnts for the next initialization steps!!! // node beginEditCP( node ); node->setCore( geom ); endEditCP( node ); // geometry p = pnts->getFieldPtr(); geom->setPositions( pnts ); beginEditCP( pnts ); for ( int i = 0; i < nPnts; i ++ ) pnts->addValue( Pnt3f( -1, -1, -1) ); endEditCP( pnts ); // indexes geom->setIndices( index ); beginEditCP( index ); for ( int i = 0; i < nPnts; i ++ ) index->addValue( i ); endEditCP( index ); // lengths geom->setLengths( lengths ); beginEditCP( lengths ); lengths->addValue( nPnts ); endEditCP( lengths ); // set material osg::SimpleMaterialPtr mat = osg::SimpleMaterial::create(); mat->setDiffuse( osg::Color3f( 1,.7,1 ) ); mat->setAmbient( osg::Color3f( 0.2,0.2,0.2 ) ); mat->setSpecular( osg::Color3f( 0.5,0.5,0.5 ) ); mat->setShininess( 20 ); mat->setEmission ( osg::Color3f( col::pseudo_randomf(), 0, 0 ) ); (geom)->setMaterial( mat ); // types geom->setTypes( type ); beginEditCP( type ); if ( _nPnts == -4 ) type->addValue( GL_QUAD_STRIP ); else type->addValue( GL_POLYGON ); endEditCP( type ); }
int main( int argc, char *argv[] ) { // OSG init osg::osgLog().setLogLevel(osg::LOG_WARNING); osg::osgInit(argc, argv); // parse command line options parsecommandline( argc, argv ); // disable display lists osg::FieldContainerPtr pProto= osg::Geometry::getClassType().getPrototype(); osg::GeometryPtr pGeoProto = osg::GeometryPtr::dcast(pProto); if ( pGeoProto != osg::NullFC ) pGeoProto->setDlistCache(false); // create the graph osg::NodePtr node; // root root = osg::Node::create(); beginEditCP(root); root->setCore( osg::Group::create() ); // beacon for camera and light osg::NodePtr beacon; beacon = osg::Node::create(); beginEditCP(beacon); beacon->setCore( osg::Group::create() ); endEditCP(beacon); // light light_node = osg::Node::create(); osg::DirectionalLightPtr light = osg::DirectionalLight::create(); beginEditCP( light_node ); light_node->setCore( light ); root->addChild( light_node ); beginEditCP(light); light->setAmbient( .3, .3, .3, 1 ); light->setDiffuse( 1, 1, 1, 1 ); light->setDirection(0,0,1); light->setBeacon( beacon ); endEditCP(light); // transformation, parent of beacon node = osg::Node::create(); cam_trans = osg::Transform::create(); beginEditCP(node); node->setCore( cam_trans ); node->addChild( beacon ); endEditCP(node); root->addChild( node ); // Camera osg::PerspectiveCameraPtr cam = osg::PerspectiveCamera::create(); cam->setBeacon( beacon ); cam->setFov( 50 ); cam->setNear( 0.1 ); cam->setFar( 10000 ); // Background osg::SolidBackgroundPtr background = osg::SolidBackground::create(); if ( White_background ) { beginEditCP( background ); background->setColor(osg::Color3f(1,1,1)); endEditCP( background ); } // Viewport osg::ViewportPtr vp = osg::Viewport::create(); vp->setCamera( cam ); vp->setBackground( background ); vp->setRoot( root ); vp->setSize( 0,0, 1,1 ); if ( With_window ) { // GLUT init glutInitWindowSize( 400, 400 ); // before glutInit so user can glutInitWindowPosition( 100, 100 ); // override with comannd line args glutInit(&argc, argv); glutInitDisplayMode( GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE); int winid = glutCreateWindow("Collision Benchmark"); glutKeyboardFunc(key); glutVisibilityFunc(vis); glutReshapeFunc(reshape); glutDisplayFunc(display); glutMouseFunc(mouse); glutMotionFunc(motion); glutIdleFunc(display); glEnable( GL_DEPTH_TEST ); glEnable( GL_LIGHTING ); glEnable( GL_LIGHT0 ); glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 1); // Window osg::GLUTWindowPtr gwin; GLint glvp[4]; glGetIntegerv( GL_VIEWPORT, glvp ); gwin = osg::GLUTWindow::create(); gwin->setId(winid); gwin->setSize( glvp[2], glvp[3] ); win = gwin; win->addPort( vp ); // Action render_action = osg::DrawAction::create(); // trackball Vec3f min(-2.5,-2.5,-2.5), max(2.5,2.5,2.5); trackball.setMode( osg::Trackball::OSGObject ); float d = max[2] + (max[2]-min[2]); trackball.setStartPosition( 0, 0, d, true ); trackball.setSum( true ); trackball.setTranslationMode( osg::Trackball::OSGFree ); } // create moving objects if ( geom_type != OBJ_FILE ) createGeom( geom_type, Complexity, &fixed_node, &fixed_geom ); // else: has been loaded from file light_node->addChild( fixed_node ); if ( geom_type != OBJ_FILE ) createGeom( geom_type, Complexity, &moving_node, &moving_geom ); //#define DOPTREE_NUM_ORI 16 double pi = 3.141592653589793f; vector<Vec3f> translates; vector<Vec3f> rotation_xyzs; vector<float> rotates; //string config(""); if(configFile.length() == 0) { printf("config file is null, use -r configFileName\n"); return 0; } ifstream fin(configFile.data()); string line; int i = 0; int angle; float x,y,z; while(std::getline(fin, line)) { stringstream ss; ss << line; if(i & 0x1) // tranls { ss >> x >> y >> z; translates.push_back(Vec3f(x,y,z)); }else //angle rot {
void createGeom( GeometryTypeE type, unsigned int complexity, osg::NodePtr *node, osg::GeometryPtr *geom ) { char name[1000]; static unsigned int ngeom = 0; static float red = 1.0, green = 0.2, blue = 1.0; switch ( type ) { case OBJ_PLANES: { *node = osg::makePlane( 1, 1, complexity, complexity ); // move one point, so that convex hull can be computed osg::MFPnt3f *points = col::getPoints( *node ); beginEditCP( *node ); (*points)[0][2] += 3; (*points)[points->size()-1][2] -= 3; endEditCP( *node ); sprintf( name, "pl_%u_%u", complexity, ngeom ); break; } case OBJ_SPHERES: complexity = static_cast<unsigned int>( logf( complexity*complexity ) / 1.7 ); *node = osg::makeSphere( complexity, 0.5 ); sprintf( name, "sh_%u_%u", complexity, ngeom ); break; case OBJ_TORUS: *node = osg::makeTorus( 0.35, 0.5, complexity+1, complexity+1 ); sprintf( name, "to_%u_%u", complexity, ngeom ); break; default: fputs("createGeom: BUG: type is out of range!\n",stderr); exit(-1); } ngeom ++ ; if ( *node == osg::NullFC ) { fprintf(stderr,"interactive: createGeom failed!\n"); exit(-1); // makes no sense to continue } *geom = col::getGeom( *node ); // set material osg::SimpleMaterialPtr mat = osg::SimpleMaterial::create(); mat->setDiffuse( osg::Color3f( red, green, blue ) ); mat->setAmbient( osg::Color3f( 0.5,0.5,0.5 ) ); mat->setSpecular( osg::Color3f( 0.5,0.5,0.5 ) ); mat->setShininess( 20 ); // change color for next createGeom call (doesn't work too often) red -= 0.2; green += 0.2; blue -= 0.2; (*geom)->setMaterial( mat ); // set name osg::NamePtr name_attachm = osg::Name::create(); name_attachm->getFieldPtr()->getValue().assign( name ); (*node)->addAttachment( name_attachm ); }