Exemplo n.º 1
0
void VRSceneLoader_saveObject(VRObject* p, xmlpp::Element* e) {
    if (e == 0) return;
    p->save(e);
    for (uint i=0; i<p->getChildrenCount(); i++) {
        VRObject* c = p->getChild(i);
        if (c->getPersistency() == 0) continue; // generated objects are not be saved
        if (c->hasAttachment("global")) continue; // global objects are not be saved
        //xmlpp::Element* ce = e->add_child(c->getName());
        xmlpp::Element* ce = e->add_child("Object");
        VRSceneLoader_saveObject(c, ce);
    }
}
Exemplo n.º 2
0
void VRSceneLoader_loadObject(VRScene* scene, VRObject* p, xmlpp::Element* e) {
    if (e == 0) return;
    xmlpp::Node::NodeList nl = e->get_children();
    xmlpp::Node::NodeList::iterator itr;
    for (itr = nl.begin(); itr != nl.end(); itr++) {
        xmlpp::Node* n = *itr;

        xmlpp::Element* el = dynamic_cast<xmlpp::Element*>(n);
        if (!el) continue;

        VRObject* c = VRSceneLoader_createFromElement(scene, el);

        p->addChild(c);
        c->load(el);
        VRSceneLoader_loadObject(scene, c, el);
    }
}
Exemplo n.º 3
0
bool VRTransform::checkWorldChange() {
    if (frame == 0) {
        frame = 1;
        return true;
    }

    if (hasGraphChanged()) return true;

    VRObject* obj = this;
    VRTransform* ent;
    while(obj) {
        if (obj->hasAttachment("transform")) {
            ent = (VRTransform*)obj;
            if (ent->change) return true;
        }
        obj = obj->getParent();
    }

    return false;
}
Exemplo n.º 4
0
/** Returns the world matrix **/
void VRTransform::getWorldMatrix(Matrix& _m, bool parentOnly) {
    //if (checkWorldChange()) {
    if (true) {
        vector<Matrix> tv;

        Matrix m;
        VRObject* obj = this;
        if (parentOnly and obj->getParent() != 0) obj = obj->getParent();

        VRTransform* tmp;
        while(true) {
            if (obj->hasAttachment("transform")) {
                tmp = (VRTransform*)obj;
                tmp->getMatrix(m);
                //cout << "\nPARENT: " << tmp->getName();
                //cout << "\n" << m;
                tv.push_back(m);
            }

            if (obj->getParent() == 0) break;
            else obj = obj->getParent();
        }

        WorldTransformation = computeMatrixVector(tv);
    }

    _m = WorldTransformation;
    //if (getName() == "Box") cout << WorldTransformation << endl;
    //cout << "\nGETWM: " << getName() << endl << _m << endl;
}
Exemplo n.º 5
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;
}
Exemplo n.º 6
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));
}