Exemplo n.º 1
0
void ExportErrorImages()
{
	const uint32_t w = 1024;
	const uint32_t h = 512;
	const double maxError = 0.02;
	const double pointCount = 1000000;
	{
		Mesh m0;
		UVSphere(22, 11, m0);
		exportSurfaceErrorImage(m0, pointCount, std::string("uvsphere_error.png"), w, h, maxError);
	}
	{
		Mesh m0;
		NormalizedCube(6, m0);
		exportSurfaceErrorImage(m0, pointCount, std::string("normalizedcube_error.png"), w, h, maxError);
	}
	{
		Mesh m0;
		SpherifiedCube(6, m0);
		exportSurfaceErrorImage(m0, pointCount, std::string("spherifiedcube_error.png"), w, h, maxError);
	}
	{
		Mesh m3;
		Mesh m4;
		Mesh m5;
		Icosahedron(m3);
		SubdivideMesh(m3, m4);
		SubdivideMesh(m4, m5);
		exportSurfaceErrorImage(m5, pointCount, std::string("icosahedron_subdiv2_error.png"), w, h, maxError);
	}
}
Exemplo n.º 2
0
void ExportMeshes()
{
	// Example on how to export it meshes in wavefront obj format
	Mesh m0;
	UVSphere(22, 11, m0);
	exportObj(m0, "uvsphere.obj");

	Mesh m1;
	NormalizedCube(6, m1);
	exportObj(m1, "ncube.obj");

	Mesh m2;
	SpherifiedCube(6, m2);
	exportObj(m2, "scube.obj");

	{
		Mesh m3;
		Mesh m4;
		Mesh m5;
		Icosahedron(m3);
		SubdivideMesh(m3, m4);
		SubdivideMesh(m4, m5);
		exportObj(m5, "icosahedron.obj");
	}
}
Exemplo n.º 3
0
void PrintStats()
{
	std::cout << "count, surface MSE, surface max. error, area per triangle MSE, area per triangle max. error" << std::endl;

	std::cout << "UVSphere" << std::endl;
	for (uint32_t i = 0; i < 22; ++i)
	{
		Mesh m;
		UVSphere(2 * (i + 2), i + 2, m);
		Error se = surfaceError(m, 10000);
		Error sae = surfaceAreaError(m);
		std::cout << m.triangleCount() << ", " << se.mse << ", " << se.max << ", " << sae.mse << ", " << sae.max << std::endl;
	}

	std::cout << "NormalizedCube" << std::endl;
	for (uint32_t i = 1; i < 14; ++i)
	{
		Mesh m;
		NormalizedCube(i, m);
		Error se = surfaceError(m, 10000);
		Error sae = surfaceAreaError(m);
		std::cout << m.triangleCount() << ", " << se.mse << ", " << se.max << ", " << sae.mse << ", " << sae.max << std::endl;
	}

	std::cout << "SpherifiedCube" << std::endl;
	for (uint32_t i = 1; i < 14; ++i)
	{
		Mesh m;
		SpherifiedCube(i, m);
		Error se = surfaceError(m, 10000);
		Error sae = surfaceAreaError(m);
		std::cout << m.triangleCount() << ", " << se.mse << ", " << se.max << ", " << sae.mse << ", " << sae.max << std::endl;
	}

	std::cout << "Icosahedron" << std::endl;
	{
		Mesh meshes[2];
		uint32_t idx = 0;
		Icosahedron(meshes[0]);
		for (uint32_t i = 0; i < 4; ++i)
		{
			Mesh &m = meshes[idx];

			Error se = surfaceError(m, 10000);
			Error sae = surfaceAreaError(m);

			std::cout << m.triangleCount() << ", " << se.mse << ", " << se.max << ", " << sae.mse << ", " << sae.max << std::endl;

			idx = (idx + 1) % 2;
			Mesh &mOut = meshes[idx];
			mOut.vertices.clear();
			mOut.triangles.clear();
			SubdivideMesh(m, mOut);
		}
	}
}
Exemplo n.º 4
0
Node* PlanetComponent::place(Vector3 pos, int colour_id, int polyhedron_id, int scale_)
{
    colour = colours[colour_id];
    scale = scale_;

    node = GetScene()->CreateChild("Planet");
    node->SetPosition(pos);
    node->SetRotation(Quaternion(Random(360.0f), Random(360.0f), Random(360.0f)));
    node->SetScale(scale);

    polyhedra_t polyhedron_type = static_cast<polyhedra_t>(polyhedron_id);
    switch(polyhedron_type)
    {

        case polyhedra_t::tetrahedron:
            polyhedron = Tetrahedron();
            break;

        case polyhedra_t::octahedron:
            polyhedron = Octahedron();
            break;

        case polyhedra_t::hexahedron:
            polyhedron = Hexahedron();
            break;

        case polyhedra_t::icosahedron:
            polyhedron = Icosahedron();
            break;

        case polyhedra_t::dodecahedron:
            polyhedron = Dodecahedron();
            break;

    }

    CustomGeo* cg = new CustomGeo(context_);

    for (unsigned i = 0; i < polyhedron.vertices.size(); i += 3)
    {
        cg->AddPoint(
            Vector3(
                polyhedron.vertices[i],
                polyhedron.vertices[i + 1],
                polyhedron.vertices[i + 2]
            )
        );
    }

    for (unsigned i = 0; i < polyhedron.triangles.size(); i += 3)
    {
        cg->AddTriangle(
            polyhedron.triangles[i],
            polyhedron.triangles[i + 1],
            polyhedron.triangles[i + 2],
            false
        );
    }

    cg->Build(node, false, false, 32, 63);


    Material* material = new Material(context_);
    material->SetShaderParameter("MatDiffColor", colour.ToVector4() / Vector4(255, 255, 255, 1));
    material->SetShaderParameter("MatSpecColor", colour.ToVector4() / Vector4(255, 255, 255, 1));
    node->GetComponent<StaticModel>()->SetMaterial(material);

    return node;
}
Exemplo n.º 5
0
void PrintCreationTimes()
{
	uint32_t count = 1000;

	std::cout << "UVSphere" << std::endl;
	for (uint32_t i = 0; i < 22; ++i)
	{
		Timer timer;
		timer.start();
		Mesh m;
		for (uint32_t j = 0; j < count; ++j)
		{
			m.clear();
			UVSphere(2 * (i + 2), i + 2, m);
		}
		timer.end();
		std::cout << m.triangleCount() << " (x" << count << "): " << timer.getMilliseconds() << "ms" << std::endl;
	}

	std::cout << "Normalized Cube" << std::endl;
	for (uint32_t i = 1; i < 14; ++i)
	{
		Timer timer;
		timer.start();
		Mesh m;
		for (uint32_t j = 0; j < count; ++j)
		{
			m.clear();
			NormalizedCube(i, m);
		}
		timer.end();
		std::cout << m.triangleCount() << " (x" << count << "): " << timer.getMilliseconds() << "ms" << std::endl;
	}

	std::cout << "Spherified Cube" << std::endl;
	for (uint32_t i = 1; i < 14; ++i)
	{
		Timer timer;
		timer.start();
		Mesh m;
		for (uint32_t j = 0; j < count; ++j)
		{
			m.clear();
			SpherifiedCube(i, m);
		}
		timer.end();
		std::cout << m.triangleCount() << " (x" << count << "): " << timer.getMilliseconds() << "ms" << std::endl;
	}

	std::cout << "Icosahedron" << std::endl;
	{
		Mesh meshes[5];
		for (uint32_t i = 0; i < 5; ++i)
		{
			Timer timer;
			timer.start();
			for (uint32_t j = 0; j < count; ++j)
			{
				for (auto &m : meshes) m.clear();
				Icosahedron(meshes[0]);
				for (uint32_t k = 0; k < i; ++k) SubdivideMesh(meshes[k], meshes[k+1]);
			}
			timer.end();
			std::cout << meshes[i].triangleCount() << " (x" << count << "): " << timer.getMilliseconds() << "ms" << std::endl;
		}
	}
}