Example #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);
	}
}
Example #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");
	}
}
Example #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);
		}
	}
}
DebugGeometryRenderer::DebugGeometryRenderer()
    : SingleNodeRenderer(RenderPhase::PreOverlay, "DebugGeometryRenderer")
{
    /**
     * Load programs
     */
    m_buildIns.shadedProgram = GetGlobal<DrawContext>()->createProgram(
        {deliberation::DeliberationDataPath(
             "Data/Shaders/DebugGeometryShaded.vert"),
         deliberation::DeliberationDataPath(
             "Data/Shaders/DebugGeometryShaded.frag")});

    m_buildIns.unicolorProgram = GetGlobal<DrawContext>()->createProgram(
        {deliberation::DeliberationDataPath(
             "Data/Shaders/DebugGeometryUnicolor.vert"),
         deliberation::DeliberationDataPath(
             "Data/Shaders/DebugGeometryUnicolor.frag")});

    m_buildIns.vertexColorProgram = GetGlobal<DrawContext>()->createProgram(
        {deliberation::DeliberationDataPath(
             "Data/Shaders/DebugGeometryVertexColor.vert"),
         deliberation::DeliberationDataPath(
             "Data/Shaders/DebugGeometryVertexColor.frag")});

    /**
     * Create Box meshes
     */
    auto mesh = CuboidMesh({2.0f, 2.0f, 2.0f}).generate();
    {
        auto compilation =
            MeshCompiler().compile(mesh, MeshCompilerPrimitive::Triangles);

        m_buildIns.boxTrianglesVertexBuffer =
            GetGlobal<DrawContext>()->createBuffer(compilation.vertices);
        m_buildIns.boxTrianglesIndexBuffer =
            GetGlobal<DrawContext>()->createBuffer(compilation.indices);
    }

    {
        auto compilation =
            MeshCompiler().compile(mesh, MeshCompilerPrimitive::Lines);

        m_buildIns.boxLinesVertexBuffer =
            GetGlobal<DrawContext>()->createBuffer(compilation.vertices);
        m_buildIns.boxLinesIndexBuffer =
            GetGlobal<DrawContext>()->createBuffer(compilation.indices);
    }

    /**
     * Create Cone mesh
     */
    {
        auto mesh = ConeMesh(0.1f, ARROW_CONE_HEIGHT).generate();
        auto compilation =
            MeshCompiler().compile(mesh, MeshCompilerPrimitive::Triangles);

        m_buildIns.coneVertexBuffer =
            GetGlobal<DrawContext>()->createBuffer(compilation.vertices);
        m_buildIns.coneIndexBuffer =
            GetGlobal<DrawContext>()->createBuffer(compilation.indices);
    }

    /**
     * Create Sphere Mesh
     */
    {
        auto sphereMesh = UVSphere(16, 16).generateMesh2();
        m_buildIns.sphereVertexBuffer =
            GetGlobal<DrawContext>()->createBuffer(sphereMesh.takeVertices());
        m_buildIns.sphereIndexBuffer =
            GetGlobal<DrawContext>()->createBuffer(sphereMesh.takeIndices());
    }

    /**
     * Create Point Mesh
     */
    {
        LayoutedBlob vertex(DataLayout("Position", Type_Vec3), 1);
        vertex.field<glm::vec3>("Position")[0] = glm::vec3(0.0f, 0.0f, 0.0f);
        m_buildIns.pointVertexBuffer = GetGlobal<DrawContext>()->createBuffer(vertex);
    }

    /**
     * Create Data Layouts
     */
    m_buildIns.unicolorDataLayout = DataLayout("Position", Type_Vec3);
    m_buildIns.vertexColorDataLayout =
        DataLayout({{"Position", Type_Vec3}, {"Color", Type_Vec3}});
    m_buildIns.shadedDataLayout =
        DataLayout({{"Position", Type_Vec3}, {"Normal", Type_Vec3}});
}
Example #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;
		}
	}
}