Exemplo n.º 1
0
VRObject* VRGeometry::copy(vector<VRObject*> children) {
    VRGeometry* geo = new VRGeometry(getBaseName());
    geo->setMesh(mesh);
    geo->setMaterial(mat);
    geo->source = source;
    geo->setVisible(isVisible());
    geo->setPickable(isPickable());
    geo->setMatrix(getMatrix());
    return geo;
}
Exemplo n.º 2
0
void VRStroke::strokeProfile(vector<Vec3f> profile, bool closed, bool lit) {
    mode = 0;
    this->profile = profile;
    this->closed = closed;
    this->lit = lit;

    GeoUInt8PropertyRecPtr      Type = GeoUInt8Property::create();
    GeoUInt32PropertyRefPtr     Length = GeoUInt32Property::create();
    GeoPnt3fPropertyRecPtr      Pos = GeoPnt3fProperty::create();
    GeoVec3fPropertyRefPtr      Norms = GeoVec3fProperty::create();
    GeoVec3fPropertyRefPtr      Colors = GeoVec3fProperty::create();
    GeoUInt32PropertyRefPtr     Indices = GeoUInt32Property::create();

    Vec3f z = Vec3f(0,0,1);
    if (profile.size() == 1) Type->addValue(GL_LINES);
    else Type->addValue(GL_QUADS);

    clearChildren();
    for (uint i=0; i<paths.size(); i++) {
        vector<Vec3f> pnts = paths[i]->get();
        vector<Vec3f> norms = paths[i]->getNormals();
        vector<Vec3f> cols = paths[i]->getColors();

        Vec3f _p;
        for (uint j=0; j<pnts.size(); j++) {
            Vec3f p = pnts[j];
            Vec3f n = norms[j];
            Vec3f c = cols[j];

            //float ca = n.dot(z);
            Matrix m;
            //MatrixLookAt(m, Vec3f(0,0,0), n, z.cross(n));
            MatrixLookAt(m, Vec3f(0,0,0), n, Vec3f(0,1,0));

            // add new profile points and normals
            for (uint k=0; k<profile.size(); k++) {
                Vec3f tmp = profile[k];
                m.mult(tmp, tmp);

                Pos->addValue(p+tmp);
                tmp.normalize();
                Norms->addValue(tmp);
                Colors->addValue(c);
            }

            if (j==0 and profile.size() > 1) continue;

            // add line
            if (profile.size() == 1) {
                int N = Pos->size();
                Indices->addValue(N-2);
                Indices->addValue(N-1);
            } else {
                // add quad
                for (uint k=0; k<profile.size()-1; k++) {
                    int N1 = Pos->size() - 2*profile.size() + k;
                    int N2 = Pos->size() -   profile.size() + k;
                    Indices->addValue(N1);
                    Indices->addValue(N2);
                    Indices->addValue(N2+1);
                    Indices->addValue(N1+1);

                    //cout << "\nN1N2 " << N1 << " " << N2 << " " << N2+1 << " " << N1+1 << flush;
                }

                if (closed) {
                    int N0 = Pos->size() - 2*profile.size();
                    int N1 = Pos->size() - profile.size() - 1;
                    int N2 = Pos->size() - 1;
                    Indices->addValue(N1);
                    Indices->addValue(N2);
                    Indices->addValue(N1+1);
                    Indices->addValue(N0);

                    //cout << "\nN1N2 " << N1 << " " << N2 << " " << N1+1 << " " << N0 << flush;
                }
            }
        }
    }

    Length->addValue(Indices->size());


    SimpleMaterialRecPtr Mat = SimpleMaterial::create();
    GeometryRecPtr g = Geometry::create();
    g->setTypes(Type);
    g->setLengths(Length);
    g->setPositions(Pos);

    g->setNormals(Norms);
    g->setColors(Colors);
    g->setIndices(Indices);

    g->setMaterial(Mat);
    Mat->setLit(lit);

    VRGeometry* geo = new VRGeometry("stroke");
    geo->setMesh(g);
    addChild(geo);
}