Example #1
0
 void runTest() {
   QList<string> attributes;
   attributes.push_back("color");
   attributes.push_back("normal");
   attributes.push_back("tangent");
   attributes.push_back("bitangent");
   attributes.push_back("uv");
   Config::Instance().load("config.xml");
   Mesh * sphere = Geometry::sphere(attributes, 11.0f, 100, 50);
   sphere->setDrawType(GL_PATCHES);
   Mesh * cube = Geometry::cube(attributes);
   cube->setDrawType(GL_PATCHES);
   Mesh * tetrahedron = Geometry::tetrahedron(attributes);
   tetrahedron->setDrawType(GL_PATCHES);
   Mesh * plane = Geometry::plane(attributes, QRectF(0,0,10,10));
   plane->setDrawType(GL_PATCHES);
   vector<float> resolution = { 10.0f, 10.0f, 10.0f };
   Mesh * stars = Geometry::stars(attributes, resolution, 1.0f, 1.0f, 1.0f);
   stars->setDrawType(GL_PATCHES);
   Mesh * spiral = Geometry::spiral(attributes, 30);
   spiral->setDrawType(GL_PATCHES);
   Mesh * icosahedron = Geometry::icosahedron(attributes);
   icosahedron->setDrawType(GL_PATCHES);
   Mesh * monkey = MeshLoader::load(attributes,"monkey.blend");
   monkey->setDrawType(GL_POINTS);
   MengerSponge * sponge = new MengerSponge(attributes, 3);
   Mesh * spongeMesh = sponge->getMesh();
   spongeMesh->setDrawType(GL_POINTS);
 }
	TestObject():sponge(false,2,false){
		mesh = new IndexedMesh();
		sponge.toMesh(mesh);
		std::cout << mesh->getFaces().size() << std::endl;
		mesh->removeDoubleTriangles(true);
		std::cout << mesh->getFaces().size() << std::endl;

		meshRender = new MeshRenderer();
		meshRender->buildFromMesh(mesh,false);
	}
Example #3
0
void SceneLoader::appendMesh(const QDomElement & meshNode) {
    string name = meshNode.attribute("name").toStdString();
    LogDebug << "Mesh name:" << name;
    Mesh *mesh = NULL;

    if (meshNode.tagName() == "File") {
        string meshUrl = meshNode.attribute("url").toStdString();
        QList<string> attributes;
        attributes.push_back("normal");
        attributes.push_back("tangent");
        attributes.push_back("bitangent");
        attributes.push_back("uv");
            mesh = MeshLoader::load(attributes, meshUrl);
    } else if (meshNode.tagName() == "Procedural") {
        if (meshNode.attribute("type") == "Sponge") {
          QList<string> attributes;
          attributes.push_back("normal");
          MengerSponge * sponge = new MengerSponge(attributes, meshNode.attribute(
                    "recursion").toUInt());
          mesh = sponge->getMesh();
        } else if (meshNode.attribute("type") == "Stars") {
          QList<string> attributes;
          attributes.push_back("color");
          float resolution = meshNode.attribute("resolution").toFloat();
          QVector3D resolutionVec =
                  QVector3D(resolution, resolution, resolution);
            mesh = Geometry::stars(
                attributes,
                    resolutionVec,
                    meshNode.attribute("density").toFloat(),
                    meshNode.attribute("randomness").toFloat(),
                    meshNode.attribute("colorIntensity").toFloat());
        } else if (meshNode.attribute("type") == "Tetrahedron") {
          QList<string> attributes;
          attributes.push_back("color");
            mesh = Geometry::tetrahedron(attributes);
        } else if (meshNode.attribute("type") == "Cube") {
          QList<string> attributes;
          attributes.push_back("color");
            mesh = Geometry::cube(attributes);
        } else if (meshNode.attribute("type") == "Plane") {
          QList<string> attributes;
          attributes.push_back("color");
            mesh = Geometry::plane(
                attributes,
                QRectF(
                    meshNode.attribute("left").toFloat(),
                    meshNode.attribute("top").toFloat(),
                    meshNode.attribute("width").toFloat(),
                    meshNode.attribute("height").toFloat()));
        } else if (meshNode.attribute("type") == "Sphere") {
          QList<string> attributes;
          attributes.push_back("color");
            mesh = Geometry::sphere(
                attributes,
                    meshNode.attribute("radius").toFloat(),
                    meshNode.attribute("slices").toInt(),
                    meshNode.attribute("stacks").toInt());
        } else if (meshNode.attribute("type") == "Icosahedron") {
          QList<string> attributes;
          attributes.push_back("color");
            mesh = Geometry::icosahedron(attributes);
        } else if (meshNode.attribute("type") == "Spiral") {
          QList<string> attributes;
          attributes.push_back("color");
            mesh = Geometry::spiral(
                attributes,
                    meshNode.attribute("resolution").toInt());
        } else {
          QList<string> attributes;
          attributes.push_back("color");
            mesh = Geometry::cube(attributes);
          LogError << "Unknown Mesh Type" << meshNode.attribute("type").toStdString();
        }

    }
    if (meshNode.hasAttribute("drawType")) {
      GLenum drawType = GL_TRIANGLES;
      string drawTypeString = meshNode.attribute("drawType").toStdString();

      if (drawTypeString == "PATCHES")
        drawType = GL_PATCHES;
      else if (drawTypeString == "POINTS")
        drawType = GL_POINTS;
      else if (drawTypeString == "TRIANGLE_STRIP")
        drawType = GL_TRIANGLE_STRIP;
      else if (drawTypeString == "TRIANGLES")
        drawType = GL_TRIANGLES;
      else if (drawTypeString == "LINES")
        drawType = GL_LINES;

      mesh->setDrawType(drawType);
    }

    Scene::Instance().meshes.insert(name, mesh);
}
Example #4
0
void SceneLoader::appendMesh(const QDomElement & meshNode) {
    string name = meshNode.attribute("name").toStdString();
    LogDebug << "Mesh name:" << name;
    Mesh *mesh = NULL;

    if (meshNode.tagName() == "File") {
        string meshUrl = meshNode.attribute("url").toStdString();
        QList<string> attributes;
        attributes.push_back("normal");
        attributes.push_back("tangent");
        attributes.push_back("bitangent");
        attributes.push_back("uv");

        if (meshNode.hasAttribute("drawType")) {
            GLint drawType = GL_TRIANGLES;
            string drawTypeString =
                    meshNode.attribute("drawType").toStdString();

            if (drawTypeString == "PATCHES")
                drawType = GL_PATCHES;
            else if (drawTypeString == "POINTS")
                drawType = GL_POINTS;
            else if (drawTypeString == "TRIANGLE_STRIP")
                drawType = GL_TRIANGLE_STRIP;
            else if (drawTypeString == "TRIANGLES")
                drawType = GL_TRIANGLES;
            else if (drawTypeString == "LINES")
                drawType = GL_LINES;

            mesh = MeshLoader::load(attributes, meshUrl);
            mesh->setDrawType(drawType);
        } else {
            mesh = MeshLoader::load(attributes, meshUrl);
        }
    } else if (meshNode.tagName() == "Procedural") {
        if (meshNode.attribute("type") == "Sponge") {
          QList<string> attributes;
          attributes.push_back("normal");
          MengerSponge * sponge = new MengerSponge(attributes, meshNode.attribute(
                    "recursion").toInt());
          mesh = sponge->getMesh();
        } else if (meshNode.attribute("type") == "Stars") {
          QList<string> attributes;
          attributes.push_back("color");
          float resolution = meshNode.attribute("resolution").toFloat();
          vector<float> resolutionvec = { resolution, resolution, resolution };
            mesh = Geometry::stars(
                attributes,
                    resolutionvec,
                    meshNode.attribute("density").toFloat(),
                    meshNode.attribute("randomness").toFloat(),
                    meshNode.attribute("colorIntensity").toFloat());
        } else if (meshNode.attribute("type") == "Spiral") {
          QList<string> attributes;
          attributes.push_back("color");
            mesh = Geometry::spiral(
                attributes,
                    meshNode.attribute("resolution").toFloat());
        }
    }

    SceneData::Instance().meshes.insert(name, mesh);
}