示例#1
2
OSG::NodeTransitPtr createLabeledTorus(OSG::Vec3f trans, int idx)
{
    OSG::NodeTransitPtr  node  = OSG::Node::create();
    OSG::TransformRefPtr xform = OSG::Transform::create();
    OSG::Matrix          mat;

    // --- setup transform ------------------
    mat.setIdentity();
    mat.setTranslate(trans);
    xform->setMatrix(mat);
    node->setCore(xform);


    // --- setup label ----------------------
    OSG::NodeRefPtr  labelNode = OSG::Node::create();
    OSG::LabelRefPtr label     = 
        (idx) ? createTextLabel(idx) : createIconLabel();

    updateLabelParams(label, idx);
    labelNode->setCore(label);

    // --- add torus ------------------------
    labelNode->addChild(OSG::makeTorus(.5, 2, 16, 16));

    node->addChild(labelNode);
    return node;
}
示例#2
0
OSG::NodeTransitPtr createLabeledScene(void)
{
    OSG::NodeTransitPtr scene = OSG::Node::create();
    scene->setCore(OSG::Group::create());

#if 0
    scene->addChild(createLabeledTorus(OSG::Vec3f( 1, 3, 0), 0));
    scene->addChild(createLabeledTorus(OSG::Vec3f( 2, 3, 0), 0));
    scene->addChild(createLabeledTorus(OSG::Vec3f( 4, 3, 0), 0));
#endif
    scene->addChild(createLabeledTorus(OSG::Vec3f( 3, 3, 0), 0));
    scene->addChild(createLabeledTorus(OSG::Vec3f( 3,-3, 0), 1));
    scene->addChild(createLabeledTorus(OSG::Vec3f(-3, 3, 0), 2));
    scene->addChild(createLabeledTorus(OSG::Vec3f(-3,-3, 0), 3));

    return scene;
}
示例#3
0
OSG::NodeTransitPtr createScene(void)
{
    // create the scene:
    OSG::TransformTransitPtr xform = OSG::Transform::create();

    OSG::Matrix mat;
    mat.setTranslate(OSG::Vec3f(2,0,0));
    xform->setMatrix(mat);

    OSG::NodeTransitPtr scene = OSG::Node::create();
    scene->addChild(createLabeledScene());
    scene->setCore(xform);

    OSG::commitChanges();

    return scene;
}
OSG::NodeTransitPtr setupAnim(void)
{
    OSG::NodeTransitPtr returnValue = OSG::Node::create();

    returnValue->setCore(OSG::Group::create());

    static const OSG::Real32 aOffsets[6][3] = 
    {
        { -5.5,  0.0,  0.0 },
        {  5.5,  0.0,  0.0 },
        {  0.0, -5.5,  0.0 },
        {  0.0,  5.5,  0.0 },
        {  0.0,  0.0, -5.5 },
        {  0.0,  0.0,  5.5 }
    };

    static const OSG::Real32 aDiffuse[6][3] =
    {
        { 1.f, 0.f, 0.f },
        { 0.f, 1.f, 0.f },
        { 0.f, 0.f, 1.f },
        { 1.f, 1.f, 0.f },
        { 1.f, 0.f, 1.f },
        { 0.f, 1.f, 1.f }
    };

    for(OSG::UInt32 i = 0; i < 6; ++i)
    {
        OSG::NodeUnrecPtr pTN                = OSG::Node::create();
        
        pAnimTrs[i] = OSG::ComponentTransform::create();
        
        OSG::GeometryUnrecPtr pGeo     = OSG::makeBoxGeo(1.f, 1.f, 1.f, 
                                                         2,   2,   2);
        OSG::NodeUnrecPtr     pGeoNode = OSG::Node::create();
        
        pGeoNode->setCore(pGeo);

        OSG::SimpleMaterialUnrecPtr pMat = OSG::SimpleMaterial::create();
        
        pMat->setDiffuse(OSG::Color3f(aDiffuse[i][0],
                                      aDiffuse[i][1],
                                      aDiffuse[i][2]));
        pMat->setAmbient(OSG::Color3f(aDiffuse[i][0],
                                      aDiffuse[i][1],
                                      aDiffuse[i][2]));

        pGeo->setMaterial(pMat);

        pAnimTrs[i]->editTranslation().setValues(aOffsets[i][0],
                                                 aOffsets[i][1],
                                                 aOffsets[i][2]);
        
        pTN->setCore (pAnimTrs[i]);
        pTN->addChild(pGeoNode   );
        
        returnValue->addChild(pTN);
    }


    return returnValue;
}
OSG::NodeTransitPtr makeScene( void )
{
    setupDefaultMaterial();

    // Let's create two untrimmed surfaces that lie beside each other.
    // Even if the tessellation error is set to be the same for
    // both surfaces, due to numerical instabilities and sampling errors
    // small one pixel gaps will appear. By reducing the error you can
    // make most gaps disappear, but there will be still some left, even
    // if you reduce the error to be extremely small -- and as a sideeffect
    // the tessellation time plus the triangle count will explode.
    // You can try this by supplying the '-nofb' switch and
    // reducing the error by the 'g' key during rendering.
    // Of course if you set different tessellation errors (generally the
    // case when using view-dependent LOD algorithms) the gaps
    // will be a lot more visible. Try the '-nofb' and '-de' switches, and
    // play around with different errors using the 'f' and 'g'
    // keys for the first surface, and the 'h' and 'j' keys for the
    // second surface.
    //
    // Note that this is not a very good example for the Fat Borders as
    // the surfaces are untrimmed, and they are also very nice numerically
    // (real world models are usually much worse) and a basic uniform
    // tessellation would probably get rid of the gaps (which are not very
    // visible in the first place due to the nice properties of these
    // surfaces). Note also that if you set too high errors or
    // radically different errors, the spike-through artifacts of the
    // Fat Borders will appear.
    // We will hopefully come up with a better example later. :-)

    OSG::NodeTransitPtr root  = OSG::Node::create();
    OSG::NodeRefPtr     surf1 = OSG::Node::create();
    OSG::NodeRefPtr     surf2 = OSG::Node::create();

    root->setCore( OSG::Group::create() );
    root->addChild( surf1 );
    root->addChild( surf2 );

    OSG::SurfaceRefPtr          surface1 = OSG::Surface         ::create();
    OSG::GeoPnt3fPropertyRefPtr cps1     = OSG::GeoPnt3fProperty::create();

    cps1->clear();
    cps1->push_back( OSG::Pnt3f(  1, -1,  0 ));
    cps1->push_back( OSG::Pnt3f(  1,  0,  0 ));
    cps1->push_back( OSG::Pnt3f(  1,  0,  1 ));
    cps1->push_back( OSG::Pnt3f(  1,  1,  1 ));

    cps1->push_back( OSG::Pnt3f(  0, -1,  0 ));
    cps1->push_back( OSG::Pnt3f(  0,  0,  0 ));
    cps1->push_back( OSG::Pnt3f(  0,  0,  1 ));
    cps1->push_back( OSG::Pnt3f(  0,  1,  1 ));

    cps1->push_back( OSG::Pnt3f(  0, -1,  1 ));
    cps1->push_back( OSG::Pnt3f(  0,  0,  1 ));
    cps1->push_back( OSG::Pnt3f(  0,  0,  0 ));
    cps1->push_back( OSG::Pnt3f(  0,  1,  0 ));

    cps1->push_back( OSG::Pnt3f( -1, -1,  1 ));
    cps1->push_back( OSG::Pnt3f( -1,  0,  1 ));
    cps1->push_back( OSG::Pnt3f( -1,  0,  0 ));
    cps1->push_back( OSG::Pnt3f( -1,  1,  0 ));

    OSG::SurfaceRefPtr          surface2 = OSG::Surface         ::create();
    OSG::GeoPnt3fPropertyRefPtr cps2     = OSG::GeoPnt3fProperty::create();

    cps2->clear();
    cps2->push_back( OSG::Pnt3f(  5, -2,  2 ));
    cps2->push_back( OSG::Pnt3f(  4, -1,  2 ));
    cps2->push_back( OSG::Pnt3f(  3,  0,  0 ));
    cps2->push_back( OSG::Pnt3f(  5,  1,  0 ));

    cps2->push_back( OSG::Pnt3f(  2, -1,  1 ));
    cps2->push_back( OSG::Pnt3f(  2,  0,  1 ));
    cps2->push_back( OSG::Pnt3f(  2,  0,  0 ));
    cps2->push_back( OSG::Pnt3f(  2,  1,  0 ));

    cps2->push_back( OSG::Pnt3f(  2, -1,  0 ));
    cps2->push_back( OSG::Pnt3f(  2,  0,  0 ));
    cps2->push_back( OSG::Pnt3f(  2,  0,  1 ));
    cps2->push_back( OSG::Pnt3f(  2,  1,  1 ));

    cps2->push_back( OSG::Pnt3f(  1, -1,  0 ));
    cps2->push_back( OSG::Pnt3f(  1,  0,  0 ));
    cps2->push_back( OSG::Pnt3f(  1,  0,  1 ));
    cps2->push_back( OSG::Pnt3f(  1,  1,  1 ));

    std::vector<OSG::Real64> knots1;
    std::vector<OSG::Pnt2f > points;
    knots1.clear();
    knots1.push_back(0);
    knots1.push_back(0);
    knots1.push_back(1);
    knots1.push_back(1);

    // first, let's clear the trimming
    surface1->removeCurves();

    // add simple outer trimming around the domain
    points.clear();
    points.push_back( OSG::Pnt2f(0,0) );
    points.push_back( OSG::Pnt2f(1,0) );
    surface1->addCurve( 1, knots1, points, true );
    points.clear();
    points.push_back( OSG::Pnt2f(1,0) );
    points.push_back( OSG::Pnt2f(1,1) );
    surface1->addCurve( 1, knots1, points, false );
    points.clear();
    points.push_back( OSG::Pnt2f(1,1) );
    points.push_back( OSG::Pnt2f(0,1) );
    surface1->addCurve( 1, knots1, points, false );
    points.clear();
    points.push_back( OSG::Pnt2f(0,1) );
    points.push_back( OSG::Pnt2f(0,0) );
    surface1->addCurve( 1, knots1, points, false );

    // set up dimensions and knot vectors:
    surface1->setDimU( 3 );
    surface1->setDimV( 3 );
    surface1->editMFKnotsU()->clear();
    surface1->editMFKnotsU()->push_back( 0 );
    surface1->editMFKnotsU()->push_back( 0 );
    surface1->editMFKnotsU()->push_back( 0 );
    surface1->editMFKnotsU()->push_back( 0 );
    surface1->editMFKnotsU()->push_back( 1 );
    surface1->editMFKnotsU()->push_back( 1 );
    surface1->editMFKnotsU()->push_back( 1 );
    surface1->editMFKnotsU()->push_back( 1 );
    surface1->editMFKnotsV()->clear();
    surface1->editMFKnotsV()->push_back( 0 );
    surface1->editMFKnotsV()->push_back( 0 );
    surface1->editMFKnotsV()->push_back( 0 );
    surface1->editMFKnotsV()->push_back( 0 );
    surface1->editMFKnotsV()->push_back( 1 );
    surface1->editMFKnotsV()->push_back( 1 );
    surface1->editMFKnotsV()->push_back( 1 );
    surface1->editMFKnotsV()->push_back( 1 );

    // set control points
    surface1->setControlPoints( cps1 );

    // set error
    surface1->setError( g_error1 );

    // and finally set the material
    surface1->setMaterial( gpcl_defaultmat );

    // first, let's clear the trimming
    surface2->removeCurves();
    // add simple outer trimming around the domain
    points.clear();
    points.push_back( OSG::Pnt2f(1,0) );
    points.push_back( OSG::Pnt2f(2,0) );
    surface2->addCurve( 1, knots1, points, true );
    points.clear();
    points.push_back( OSG::Pnt2f(2,0) );
    points.push_back( OSG::Pnt2f(2,1) );
    surface2->addCurve( 1, knots1, points, false );
    points.clear();
    points.push_back( OSG::Pnt2f(2,1) );
    points.push_back( OSG::Pnt2f(1,1) );
    surface2->addCurve( 1, knots1, points, false );
    points.clear();
    points.push_back( OSG::Pnt2f(1,1) );
    points.push_back( OSG::Pnt2f(1,0) );
    surface2->addCurve( 1, knots1, points, false );

    // set up dimensions and knot vectors:
    surface2->setDimU( 3 );
    surface2->setDimV( 3 );
    surface2->editMFKnotsU()->clear();
    surface2->editMFKnotsU()->push_back( 1 );
    surface2->editMFKnotsU()->push_back( 1 );
    surface2->editMFKnotsU()->push_back( 1 );
    surface2->editMFKnotsU()->push_back( 1 );
    surface2->editMFKnotsU()->push_back( 2 );
    surface2->editMFKnotsU()->push_back( 2 );
    surface2->editMFKnotsU()->push_back( 2 );
    surface2->editMFKnotsU()->push_back( 2 );
    surface2->editMFKnotsV()->clear();
    surface2->editMFKnotsV()->push_back( 0 );
    surface2->editMFKnotsV()->push_back( 0 );
    surface2->editMFKnotsV()->push_back( 0 );
    surface2->editMFKnotsV()->push_back( 0 );
    surface2->editMFKnotsV()->push_back( 1 );
    surface2->editMFKnotsV()->push_back( 1 );
    surface2->editMFKnotsV()->push_back( 1 );
    surface2->editMFKnotsV()->push_back( 1 );

    // set control points
    surface2->setControlPoints( cps2 );

    // set error
    surface2->setError( g_error2 );

    // and finally set the material
    surface2->setMaterial( gpcl_defaultmat );

    surf1->setCore( surface1 );
    surf2->setCore( surface2 );

    gpcl_surface1 = surface1;
    gpcl_surface2 = surface2;

    return root;
}