Ejemplo n.º 1
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;
}
Ejemplo n.º 2
0
void VRSceneLoader::optimizeGraph(VRObject* obj) { //TODO
    VRObject* p = obj->getParent();
    if (obj->getType() == "Geometry" && p->getType() == "Transform" && p->getChildrenCount() == 1) {
        obj->switchParent(p->getParent());
        obj->setName(p->getName());
        //obj->setMatrix(p->getMatrix()); //TODO: cast
        p->hide();
    }

    for (uint i=0;i<obj->getChildrenCount();i++)
        optimizeGraph(obj->getChild(i));
}