Esempio n. 1
0
void initFloor(void)
{
    OSG::GeometryUnrecPtr  floor  = OSG::makePlaneGeo(2000.f, 2000.f, 10, 10);
    OSG::NodeUnrecPtr      floorN = OSG::makeNodeFor(floor);
    OSG::TransformUnrecPtr xform  = OSG::Transform::create();
    OSG::NodeUnrecPtr      xformN = OSG::makeNodeFor(xform);

    OSG::ImageUnrecPtr           img = OSG::ImageFileHandler::the()->read("sand1Tile.png");
    OSG::TextureObjChunkUnrecPtr tex = OSG::TextureObjChunk::create();
    tex->setImage(img);

    OSG::ChunkMaterial *chunkMat = dynamic_cast<OSG::ChunkMaterial *>(floor->getMaterial());
    if(chunkMat != NULL)
    {
        chunkMat->addChunk(tex);
    }

    OSG::Quaternion quat;
    quat.setValueAsAxisDeg(OSG::Vec3f(1.f, 0.f, 0.f), -90.f);

    xform->editMatrix().setRotate(quat);

    xformN->addChild(floorN);
    g->rootN->addChild(xformN);
}
Esempio n. 2
0
void enableRenderMode(OSG::SkinnedGeometry::RenderModeE rm)
{
    if(g->renderMode == rm)
        return;

    if(g->renderMode == OSG::SkinnedGeometry::RMSkinnedGPU)
    {
        // remove shader chunk
        MaterialStore::iterator mIt  = g->materials.begin();
        MaterialStore::iterator mEnd = g->materials.end  ();

        for(; mIt != mEnd; ++mIt)
        {
            OSG::ChunkMaterial *chunkMat = dynamic_cast<OSG::ChunkMaterial *>((*mIt));

            if(chunkMat != NULL)
                chunkMat->subChunk(g->skinShader);
        }
    }

    if(rm == OSG::SkinnedGeometry::RMSkinnedGPU)
    {
        // add shader chunk
        MaterialStore::iterator mIt  = g->materials.begin();
        MaterialStore::iterator mEnd = g->materials.end  ();

        for(; mIt != mEnd; ++mIt)
        {
            OSG::ChunkMaterial *chunkMat = dynamic_cast<OSG::ChunkMaterial *>((*mIt));

            if(chunkMat != NULL)
                chunkMat->addChunk(g->skinShader);
        }
    }

    SkinnedGeoStore::iterator sIt  = g->skinGeos.begin();
    SkinnedGeoStore::iterator sEnd = g->skinGeos.end  ();

    for(; sIt != sEnd; ++sIt)
    {
        (*sIt)->setRenderMode(rm);
    }

    FLOG(("enable render mode %d\n", rm));

    g->renderMode = rm;
}
Esempio n. 3
0
void loadTextures(void)
{
    MaterialStore::iterator mIt  = g->materials.begin();
    MaterialStore::iterator mEnd = g->materials.end  ();

    for(; mIt != mEnd; ++mIt)
    {
        if(OSG::getName(*mIt) != NULL)
        {
            FLOG(("mat name '%s'\n", OSG::getName(*mIt)));

            std::string matName = OSG::getName(*mIt);
            TextureMap::iterator tIt = g->texMap.find(matName);

            if(tIt == g->texMap.end())
            {
                std::string::size_type pos     = matName.find("_");
                std::string            texName = matName.substr(0, pos) + "_diffuse.tga";

                OSG::ImageUnrecPtr           texImg = OSG::ImageFileHandler::the()->read(texName.c_str());
                OSG::TextureObjChunkUnrecPtr texObj = OSG::TextureObjChunk::create();

                texObj->setImage(texImg);

                g->texMap.insert(TextureMap::value_type(matName, texObj));

                tIt = g->texMap.find(matName);
            }

            OSG_ASSERT(tIt != g->texMap.end());

            OSG::ChunkMaterial *chunkMat = dynamic_cast<OSG::ChunkMaterial*>(*mIt);

            if(chunkMat != NULL)
            {
                FLOG(("adding texture chunk\n"));
                chunkMat->addChunk((*tIt).second);
            }
        }
    }
}
void prepareSceneGraph(OSG::Node * const node)
{
    if(!prepared)
    {
        polygonChunk = OSG::PolygonChunk::create();
        prepared = true;
    }

    OSG::NodeCore *core  =node->getCore();
    if(core != NULL)
    {
        OSG::Geometry *geo   = dynamic_cast<OSG::Geometry *>(core);
        if(geo != NULL)
        {
            OSG::Material *mat = geo->getMaterial();
            if(mat != NULL)
            {
                OSG::ChunkMaterial *cmat = 
                    dynamic_cast<OSG::ChunkMaterial *>(mat);
                if(cmat->find(OSG::PolygonChunk::getClassType()) == NULL)
                {
                    cmat->addChunk(polygonChunk);
                }
            }
            // get num positions
            OSG::GeoVectorProperty *positionsPtr=geo->getPositions();
            if(positionsPtr != NULL)
                sum_positions += positionsPtr->size32();
            // get num triangles
            OSG::UInt32 triangle=0;
            OSG::UInt32 line=0;
            OSG::UInt32 point=0;
            calcPrimitiveCount(geo,triangle,line,point);
            sum_triangles += triangle;
            // sum of geometry nodes
            ++sum_geometries;
        }
        else
        {
            OSG::MaterialGroup *matGrp = 
                dynamic_cast<OSG::MaterialGroup *>(core);
            if(matGrp != NULL)
            {
                OSG::Material *mat = matGrp->getMaterial();
                if(mat != NULL)
                {
                    OSG::ChunkMaterial *cmat = 
                        dynamic_cast<OSG::ChunkMaterial *>(mat);
                    if(cmat->find(OSG::PolygonChunk::getClassType()) == NULL)
                    {
                        cmat->addChunk(polygonChunk);
                    }
                }
            }
            else
            {
                OSG::ProxyGroup *proxy = dynamic_cast<OSG::ProxyGroup *>(core);
                if(proxy != NULL)
                {
                    sum_triangles += proxy->getTriangles();
                    sum_positions += proxy->getPositions();
                    sum_geometries += proxy->getGeometries();
                }
            }
        }
    }
    for(OSG::MFUnrecChildNodePtr::const_iterator nI=node->getMFChildren()->begin();
        nI != node->getMFChildren()->end();
        ++nI)
    {
        prepareSceneGraph(*nI);
    }
}