Exemplo n.º 1
0
void FLogistics::fillContainer(shared_ptr<FContainer> c, int N, VRTransformPtr t) {
    for (int i=0; i<N; i++) {
        auto p = addProduct();
        t = static_pointer_cast<VRTransform>(t->duplicate(true));
        t->setVisible(true);
        t->setPersistency(0);
        p->setTransformation(t);
        c->add( p );
    }
}
Exemplo n.º 2
0
shared_ptr<FContainer> FLogistics::addContainer(VRTransformPtr t) {
    if (t == 0) return 0;
    auto c = shared_ptr<FContainer>(new FContainer());
    t = static_pointer_cast<VRTransform>(t->duplicate(true));
    t->setVisible(true);
    t->setPersistency(0);
    c->setTransformation(t);
    objects[c->getID()] = c;
    return c;
}
Exemplo n.º 3
0
void VRNature::computeLODs3(map<OctreeNode*, VRLodLeafPtr>& leafs) {
    // construct master material
    auto mosaic1 = VRTextureMosaic::create();
    auto mosaic2 = VRTextureMosaic::create();

    int j = 0;
    int k = 0;
    int H = 0;

    auto prepSprites = [&]( map<string, VRTreePtr>& templates ) {
        for (auto tree : templates) {
            if (!tree.second) continue;

            int Hmax = 1;
            auto sides = tree.second->getLodMaterials();
            for (auto side : sides) Hmax = max(Hmax, side->getTexture(0)->getSize()[1]);

            for (int i=0; i<sides.size(); i++) {
                mosaic1->add( sides[i]->getTexture(0), Vec2i(512*i,H), Vec2i(i,j) );
                mosaic2->add( sides[i]->getTexture(1), Vec2i(512*i,H), Vec2i(i,j) );
                //sides[i]->getTexture(0)->write("test_"+toString(i)+".png");
            }

            H += Hmax;
            j++;
        }
    };

    auto updateUVs = [&]( map<string, VRTreePtr>& templates ) {
        for (auto tree : templates) {
            VRGeometryPtr tlod = dynamic_pointer_cast<VRGeometry>( tree.second->getLOD(0) );
            VRGeoData data(tlod);

            int N = 3;
            for (int i=0; i<N; i++) { // update UV coordinates
                Vec2i ID = Vec2i(i,k);
                float i1 = i*1.0/N;
                float i2 = (i+1)*1.0/N;
                float j1 = mosaic1->getChunkPosition(ID)[1]/float(H);
                float j2 = j1+mosaic1->getChunkSize(ID)[1]/float(H);
                data.setTexCoord(4*i  , Vec2d(i2,j1));
                data.setTexCoord(4*i+1, Vec2d(i1,j1));
                data.setTexCoord(4*i+2, Vec2d(i1,j2));
                data.setTexCoord(4*i+3, Vec2d(i2,j2));
            }
            k++;
        }
    };

    prepSprites(treeTemplates);
    prepSprites(bushTemplates);
    updateUVs(treeTemplates);
    updateUVs(bushTemplates);
    mosaic1->write("test.png");

    auto m = VRMaterial::create("natureMosaic");
    m->setVertexShader(VRTree::treeSprLODvp, "treeSprLODvp");
    m->setFragmentShader(VRTree::treeSprLODdfp, "treeSprLODdfp", true);
    m->setShaderParameter("tex0", 0);
    m->setShaderParameter("tex1", 1);
    m->setTexture(mosaic1, false, 0);
    m->setTexture(mosaic2, false, 1);
    trees->setMaterial(m);
    VRGeoData treesData(trees);

    cout << "treeRefs: " << treeRefs.size() << endl;
    for (auto tree : treeRefs) {
        auto tRef = tree.second;
        VRTree* t = tree.first;
        if (!tRef || !t) continue;
        Vec3d offset = t->getWorldPosition();
        VRTransformPtr tlod = tRef->getLOD(0);
        VRGeometryPtr l = dynamic_pointer_cast<VRGeometry>( tlod->duplicate() );
        VRGeoData other(l);
        treesData.append(other, getMatrixTo(t->ptr()) );
    }

    treesData.apply(trees);
}
Exemplo n.º 4
0
void VRNature::computeLODs2(map<OctreeNode*, VRLodLeafPtr>& leafs) {

    // get all trees and grass patches for each leaf layer
    map<VRLodLeaf*, vector<VRTree*> > trees;
    map<VRLodLeaf*, vector<VRGrassPatch*> > grass;
    for (auto l : leafs) {
        auto& leaf = l.second;
        int lvl = leaf->getLevel();
        if (lvl == 0) continue;

        vector<void*> data = leaf->getOLeaf()->getAllData();
        for (auto v : data) {
            if (((VRObject*)v)->hasTag("tree")) trees[leaf.get()].push_back((VRTree*)v);
            if (((VRObject*)v)->hasTag("grass")) grass[leaf.get()].push_back((VRGrassPatch*)v);
        }
    }

    // create layer node geometries
    for (auto l : leafs) {
        auto& leaf = l.second;
        leaf->reset();
        int lvl = leaf->getLevel();
        if (lvl == 0) continue;
        bool doTrees = (trees.count(leaf.get()) >= 0);
        bool doGrass = (grass.count(leaf.get()) >= 0);

        Boundingbox bb;
        if (doTrees) for (auto t : trees[leaf.get()]) bb.update( t->getWorldPosition() );
        //if (doGrass) for (auto g : grass[leaf.get()]) bb.update( g->getWorldPosition() );
        Vec3d pos = bb.center();

        VRGeoData geo;
        VRMaterialPtr m;

        if (doTrees) for (auto t : trees[leaf.get()]) {
            if (treeRefs.count(t) == 0) continue;
            auto tRef = treeRefs[t];
            if (!tRef || !t) continue;
            Vec3d offset = t->getWorldPosition() - pos;
            VRTransformPtr tlod = tRef->getLOD(0);
            /*tRef->appendLOD(geo, lvl, offset);
            m = tlod->getMaterial();*/
            VRTransformPtr l = dynamic_pointer_cast<VRTransform>( tlod->duplicate() );
            leaf->add( l, 1 );
            l->setWorldPosition(t->getWorldPosition());
        }

        /*if (doGrass) for (auto g : grass[leaf.get()]) {
            if (grassPatchRefs.count(g) == 0) continue;
            auto gRef = grassPatchRefs[g];
            if (!gRef || !g) continue;
            Vec3d offset = g->getWorldPosition() - pos;
            gRef->createLod(geoGrass, lvl, offset, g->getID());
        }*/

        /*VRGeometryPtr woods;
        if (geo.size() > 0) {
            woods = geo.asGeometry("woods");
            if (m) woods->setMaterial(m);
            //cout << "YAY: lod data: " << geo.size() << " " << woods << endl;

            leaf->set( woods, 1 );
            woods->setWorldPosition(pos);
            woods->setDir(Vec3d(0,0,-1));
            woods->setUp(Vec3d(0,1,0));
        }*/
    }
}