Exemplo n.º 1
0
void VRGeometry::loadContent(xmlpp::Element* e) {
    VRTransform::loadContent(e);

    source.type = toInt(e->get_attribute("sourcetype")->get_value().c_str());
    source.parameter = e->get_attribute("sourceparam")->get_value();

    string p1, p2;
    stringstream ss;
    VRGeometry* g;
    // get source info
    // construct data from that

    switch(source.type) {
        case CODE:
            return;
        case SCRIPT:
            break;
        case FILE:
            ss << source.parameter;
            ss >> p1; ss >> p2;
            g = VRImport::get()->loadGeometry(p1, p2);
            if (g) setMesh( g->getMesh(), source, true );
            else cout << "failed to load " << p2 << " from file " << p1 << endl;
            break;
        case PRIMITIVE:
            ss << source.parameter;
            ss >> p1; getline(ss, p2);
            setPrimitive(p1, p2);
            break;
    }
}
Exemplo n.º 2
0
bool CSGGeometry::disableEditMode() {
	if (children.size() != 2) { cout << "CSGGeometry: Warning: editMode disabled with less than 2 children. Doing nothing.\n"; return false; }

	vector<CGAL::Polyhedron*> polys(2,0); // We need two child geometries to work with

	for (int i=0; i<2; i++) { // Prepare the polyhedra
		VRObject *obj = children[i];
        obj->setVisible(false);

		if (obj->getType() == string("Geometry")) {
			VRGeometry *geo = dynamic_cast<VRGeometry*>(obj);
            cout << "child: " << geo->getName() << " toPolyhedron\n";
            bool success;
			try {
			    polys[i] = toPolyhedron( geo->getMesh(), geo->getWorldMatrix(), success );
			} catch (exception e) {
			    success = false;
			    cout << getName() << ": toPolyhedron exception: " << e.what() << endl;
			}

            if (!success) {
			    cout << getName() << ": toPolyhedron went totaly wrong :(\n";
                //setCSGGeometry(polys[i]);
                //obj->setVisible(true); // We stay in edit mode, so both children need to be visible
                return false;
            }
			continue;
		}

		if(obj->getType() == "CSGGeometry") {
			CSGGeometry *geo = dynamic_cast<CSGGeometry*>(obj);
			polys[i] = geo->getCSGGeometry(); // TODO: where does this come from?? keep the old!
			continue;
		}

		cout << "Warning! polyhedron " << i << " not acquired because ";
		cout << obj->getName() << " has wrong type " << obj->getType();
		cout << ", it should be 'Geometry' or 'CSGGeometry'!" << endl;
	}

	if (polys[0] == 0) cout << "Warning! first polyhedron is 0! " << children[0]->getName() << endl;
	if (polys[1] == 0) cout << "Warning! second polyhedron is 0! " << children[1]->getName() << endl;
	if (polys[0] == 0 || polys[1] == 0) return false;

    if (polyhedron) delete polyhedron;
    polyhedron = 0;
	if (operation == "unite") polyhedron = unite(polys[0], polys[1]);
	else if(operation == "subtract") polyhedron = subtract(polys[0], polys[1]);
	else if(operation == "intersect") polyhedron = intersect(polys[0], polys[1]);
	else cout << "CSGGeometry: Warning: unexpected CSG operation!\n";

	// Clean up
	for (auto p : polys) delete p;

	if (polyhedron == 0) return false;
    setCSGGeometry(polyhedron);
	return true;
}