void
OgreMeshReader::constructMaterial(SubMeshInfo &smInfo)
{
    OSG_OGRE_LOG(("OgreMeshReader::constructMaterial\n"));

    MaterialMap::const_iterator  mmIt = _matMap.find(smInfo.matName);
    Material                    *mat  = NULL;

    if(mmIt != _matMap.end())
    {
        mat = (*mmIt).second;
    }
    else
    {
        SimpleMaterialUnrecPtr newMat = SimpleMaterial::create();
        newMat->setDiffuse  (Color3f(1.0f, 1.0f, 1.0f));
        newMat->setAmbient  (Color3f(0.1f, 0.1f, 0.1f));
        newMat->setSpecular (Color3f(0.3f, 0.3f, 0.3f));
        newMat->setShininess(20.f);

        setName(newMat, smInfo.matName);

        _matMap.insert(MaterialMap::value_type(smInfo.matName, newMat));

        mat = newMat;
    }

    smInfo.mesh->setMaterial(mat);
}
// Initialize GLUT & OpenSG and set up the scene
int main(int argc, char **argv)
{
    // OSG init
    osgInit(argc,argv);

    {
        // Set up Window
        WindowEventProducerRecPtr TutorialWindow = createNativeWindow();

        //Initialize Window
        TutorialWindow->initWindow();

        SimpleSceneManager sceneManager;
        TutorialWindow->setDisplayCallback(boost::bind(display, &sceneManager));
        TutorialWindow->setReshapeCallback(boost::bind(reshape, _1, &sceneManager));

        // Tell the Manager what to manage
        sceneManager.setWindow(TutorialWindow);

        //Attach to events
        TutorialWindow->connectMousePressed(boost::bind(mousePressed, _1, &sceneManager));
        TutorialWindow->connectMouseReleased(boost::bind(mouseReleased, _1, &sceneManager));
        TutorialWindow->connectMouseDragged(boost::bind(mouseDragged, _1, &sceneManager));
        TutorialWindow->connectMouseWheelMoved(boost::bind(mouseWheelMoved, _1, &sceneManager));

        //Torus Material
        SimpleMaterialUnrecPtr TheTorusMaterial = SimpleMaterial::create();
        TheTorusMaterial->setAmbient(Color3f(0.3,0.3,0.3));
        TheTorusMaterial->setDiffuse(Color3f(0.7,0.7,0.7));
        TheTorusMaterial->setSpecular(Color3f(1.0,1.0,1.0));
        TheTorusMaterial->setShininess(20.0);

        //Torus Geometry
        GeometryUnrecPtr TorusGeometry = makeTorusGeo(.5, 2, 32, 32);
        TorusGeometry->setMaterial(TheTorusMaterial);

        NodeUnrecPtr TorusGeometryNode = Node::create();
        TorusGeometryNode->setCore(TorusGeometry);

        //Make Torus Node
        NodeUnrecPtr TorusNode = Node::create();
        TransformUnrecPtr TorusNodeTrans = Transform::create();
        setName(TorusNodeTrans, std::string("TorusNodeTransformationCore"));

        TorusNode->setCore(TorusNodeTrans);
        TorusNode->addChild(TorusGeometryNode);

        //Make Main Scene Node
        NodeUnrecPtr scene = Node::create();
        ComponentTransformUnrecPtr Trans = ComponentTransform::create();
        setName(Trans, std::string("MainTransformationCore"));
        scene->setCore(Trans);

        // add the torus as a child
        scene->addChild(TorusNode);

        AnimationGroupUnrecPtr TheAnimation = setupAnimation(TheTorusMaterial, TorusNodeTrans);
        TutorialWindow->connectKeyPressed(boost::bind(keyPressed, _1,
                                                      TheAnimation.get(),
                                                      TutorialWindow.get()));
        TheAnimation->attachUpdateProducer(TutorialWindow);
        TheAnimation->start();

        // tell the manager what to manage
        sceneManager.setRoot  (scene);

        //Create the Documentation
        SimpleScreenDoc TheSimpleScreenDoc(&sceneManager, TutorialWindow);

        // show the whole scene
        sceneManager.showAll();


        Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f);
        Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5);
        TutorialWindow->openWindow(WinPos,
                                   WinSize,
                                   "07AnimationGroup");

        //Enter main Loop
        TutorialWindow->mainLoop();
    }

    osgExit();

    return 0;
}
Esempio n. 3
0
NodeTransitPtr RAWSceneFileType::read(      std::istream &is, 
                                      const Char8        *,
                                            Resolver        ) const
{
    NodeTransitPtr              root;
    GeometryUnrecPtr            geo;
    GeoPnt3fPropertyUnrecPtr    points;
    GeoVec3fPropertyUnrecPtr    normals;
    GeoIntegralPropertyUnrecPtr index;
    GeoIntegralPropertyUnrecPtr lens;
    GeoIntegralPropertyUnrecPtr type;

    Vec3f vec[3];

    UInt32 i = 0, n, triCount = 0;

    Real32 x,y,z;

    if(is)
    {
        root = Node    ::create();
        geo  = Geometry::create();

        root->setCore( geo );

        points = GeoPnt3fProperty::create();

        geo->setPositions(points);

        normals = GeoVec3fProperty::create();

        geo->setNormals(normals);

        triCount = i = 0;


        while(1) 
        {
            is >> x >> y >> z;

            if(is.eof())
            {
                break;
            }
            else 
            {
                points->editFieldPtr()->push_back(Pnt3f(x, y, z));

                vec[i].setValues(x,y,z);

				std::cerr << x << " " << y << " " << z << std::endl;

                if(i == 2) 
                {
                    vec[0] -= vec[1];
                    vec[1] -= vec[2];
                    vec[0].crossThis(vec[1]);
                    vec[0].normalize();

                    normals->editFieldPtr()->push_back(vec[0]);
                    normals->editFieldPtr()->push_back(vec[0]);
                    normals->editFieldPtr()->push_back(vec[0]);

                    i = 0;
                    triCount++;
                }
                else
                {
                    i++;
                }
            }
        }

        if(triCount != 0)
        {
            index = GeoUInt32Property::create();

            geo->setIndex(index, Geometry::PositionsIndex);
            geo->setIndex(index, Geometry::NormalsIndex  );

            n = triCount * 3;

            for(i = 0; i < n; i++)
                index->push_back(i);



            lens = GeoUInt32Property::create();

            geo->setLengths(lens);

            lens->push_back(n);

            type = GeoUInt8Property::create();

            geo->setTypes(type);

            type->push_back(GL_TRIANGLES);
        }

        SimpleMaterialUnrecPtr mat = SimpleMaterial::create();

        mat->setDiffuse  (Color3f(  .8f,  .8f,  .8f));
        mat->setSpecular (Color3f( 1.f,  1.f,  1.f ));
        mat->setShininess(20.f                      );

        geo->setMaterial(mat);
    }

    if(triCount)
    {
        SNOTICE << triCount << " triangle read " << std::endl;
    }

    commitChanges();

    return root;
}