Fast-Quadric-Mesh-Simplification icon indicating copy to clipboard operation
Fast-Quadric-Mesh-Simplification copied to clipboard

Mesh simplification gives invalid result

Open StudenteChamp2 opened this issue 1 year ago • 1 comments

Hello,

I am implementing mesh simplification in my renderer. I found your library pretty cool. Unfortunately I a get wrong results with my scenes. For example with a 20000 triangles model

No simplification:
OK

With simplification:
Issue

Source code:


void Decimate(const std::vector<Math::Vec3>& inVertices,
	const std::vector<nbUint32>& inIndices,
	std::vector<Math::Vec3>& outVertices,
	std::vector<nbUint32>& outIndices)
{
	// Free previous memory
	Simplify::vertices.clear();
	Simplify::triangles.clear();


	// Build vertices.
	Simplify::vertices.reserve(inVertices.size());
	{
		for (const Math::Vec3& vtx : inVertices)
		{
			Simplify::Vertex simplifyVtx;
			simplifyVtx.p.x = vtx.x;
			simplifyVtx.p.y = vtx.y;
			simplifyVtx.p.z = vtx.z;
			Simplify::vertices.push_back(simplifyVtx);
		}
	}

	// Build triangles.
	Simplify::triangles.reserve(inIndices.size() / 3);
	{
		for (unsigned int i = 0u; i < inIndices.size(); i += 3)
		{
			Simplify::Triangle simplifyTri;
			simplifyTri.v[0] = inIndices[i];
			simplifyTri.v[1] = inIndices[i + 1u];
			simplifyTri.v[2] = inIndices[i + 2u];
			Simplify::triangles.push_back(simplifyTri);
		}
	}

	// Perform decimation.
	{
		const int targetTriangleCount = (int)Simplify::triangles.size() >> 2;

		const int startSize = (int)Simplify::triangles.size();
		double agressiveness = 7.0;
		Simplify::simplify_mesh(targetTriangleCount, agressiveness, true);
	}

	// Convert results back.
	{
		// Vertices.
		outVertices.reserve(Simplify::vertices.size());
		for (const Simplify::Vertex& simplifyVtx : Simplify::vertices)
		{
			Math::Vec3 vtx;
			vtx.x = (float)simplifyVtx.p.x;
			vtx.y = (float)simplifyVtx.p.y;
			vtx.z = (float)simplifyVtx.p.z;

			outVertices.push_back(vtx);
		}

		// Indices
		outIndices.reserve(Simplify::triangles.size() * size_t(3));

		for (const Simplify::Triangle& simplifyTri : Simplify::triangles)
		{
			outIndices.push_back(simplifyTri.v[0]);
			outIndices.push_back(simplifyTri.v[1]);
			outIndices.push_back(simplifyTri.v[2]);
		}
	}
}


Am i doing something wrong? or its is a F.Q.M.S. issue?

StudenteChamp2 avatar Oct 11 '23 21:10 StudenteChamp2

If I use Surfice it reads the dragon.obj fine and the Advanced/SimplifyMesh works as expected. However, if I load the dragon.obj with the web version it reports unrecognized sequence exiting.

Curiously, if I open your Dragon.obj with Surfice and use Advanced/SaveMesh to save it (without decimation) as an obj format file, the web version processes it fine.

Viewing the file with a text browser shows some lines that are not correctly commented:

vt 0.1229 2.7132 0.2959
# 14064 texture coords

g Box01
f 1/1 2/2 3/3 4/4 

neurolabusc avatar Oct 16 '23 16:10 neurolabusc