Ejemplo n.º 1
0
ProxyGroupPtr createPart(int i, partStats &stats)
{
    CreateGeoRec r;

    SLOG << "Assembling geometry for part " << i + 1 << " of "
         << nparts << endLog;

    split->feedResults(i, &r, &CreateGeoRec::pnt, &CreateGeoRec::tri);

    SLOG << "Got " << r.getNVert() << " verts, " 
                   << r.getNTris() << " tris, creating object..." << endLog;

    partStats s(r.getNVert(), r.getNTris());
    stats += s;

    char name[filebasename.size() + 20];
    sprintf(name, "%s_%04d.%s", filebasename.c_str(), i, outformat.c_str());

    NodePtr node = r.createScene();

    SLOG << "Running graph ops..." << endLog;
    opseq.run(node);

    SLOG << "Writing..." << endLog;
    SceneFileHandler::the().write(node, name);

    // Wrap it in a ProxyGroup and keep it

    ProxyGroupPtr proxy = ProxyGroup::create();

    beginEditCP(proxy);
    proxy->setVolume(node->getVolume(true));
    proxy->setUrl(name);
    proxy->setIndices(r.getNTris() * 3);
    proxy->setTriangles(r.getNTris());
    proxy->setPositions(r.getNVert());
    proxy->setGeometries(1);
    proxy->setConcurrentLoad(concurrent);
    endEditCP(proxy);

    subRefCP(node);
    
    return proxy;
}  
Ejemplo n.º 2
0
// Initialize GLUT & OpenSG and set up the scene
int main(int argc, char **argv)
{
    if(argc != 2)
    {
        std::cout << "Usage: 04Xml2Osb.exe [Filename]" << std::endl;
        return -1;
    }

    Path FilePath(argv[1]);
    if(!boost::filesystem::exists(FilePath))
    {
        std::cout << "No file by name: "<< FilePath.string() << " exists." << std::endl;
        return -1;
    }

    // OSG init
    osgInit(argc,argv);
    
    NodePtr TheScene(NullFC);

    //Load the Scene
	FCFileType::FCPtrStore NewContainers;
	NewContainers = FCFileHandler::the()->read(FilePath);

    FCFileType::FCPtrStore::iterator Itor;
    for(Itor = NewContainers.begin() ; Itor != NewContainers.end() ; ++Itor)
    {

        if( (*Itor)->getType() == Node::getClassType() &&
            Node::Ptr::dcast(*Itor)->getParent() == NullFC)
        {
            TheScene =  Node::Ptr::dcast(*Itor);
        }
    }

    //Check if the scene was loaded
    if(TheScene == NullFC)
    {
        std::cout << "Failed to load a scene from: "<< FilePath.string() << "." << std::endl;
        return -1;
    }

    //Run Graph optimizations
    GraphOpSeq *graphop = new GraphOpSeq;
    graphop->addGraphOp(new VerifyGeoGraphOp);
    graphop->addGraphOp(new StripeGraphOp);
    //graphop->addGraphOp(new MaterialMergeGraphOp);
    //graphop->addGraphOp(new SharePtrGraphOp);

    if(graphop != NULL)
    {
        graphop->run(TheScene);
    }



    //Export the Scene to an osb file

    std::string ExportFileName(FilePath.string().substr(0,FilePath.string().size()-3) + "osb");
    
    SceneFileHandler::the().write(TheScene, ExportFileName.c_str());
    
	// OSG exit
    osgExit();

    return 0;
}