geogram icon indicating copy to clipboard operation
geogram copied to clipboard

Using mesh_make_atlas

Open cdcseacave opened this issue 3 years ago • 2 comments
trafficstars

I'm trying to create the charts and parametrize them using mesh_make_atlas but all it does is to make one chart per triangle and parametrize that :) What am I doing wrong?

	GEO::Logger::initialize();
	GEO::FileSystem::initialize();
	GEO::CmdLine::initialize();
	GEO::CmdLine::import_arg_group("standard");
	GEO::CmdLine::import_arg_group("algo");
	GEO::mesh_io_initialize ();
	GEO::Mesh gmesh(3, false);
	gmesh.vertices.create_vertices(mesh.vertices.size());
	FOREACHIDX(Mesh::VIndex, i, mesh.vertices)
		Eigen::Map<Point3d>(gmesh.vertices.point_ptr(i)) = mesh.vertices[i].cast<double>();
	GEO::vector<GEO::index_t> triangles(mesh.faces.size() * 3);
	AC_ASSERT_EQ(sizeof(GEO::index_t), sizeof(Mesh::VIndex));
	FOREACHIDX(Mesh::FIndex, i, mesh.faces)
		memcpy(&triangles[i * 3], mesh.faces[i].data(), 3 * sizeof(GEO::index_t));
	gmesh.facets.assign_triangle_mesh(triangles, true);
	GEO::mesh_make_atlas(
		gmesh, 45.0 /* hard_angles_threshold */,
		GEO::ChartParameterizer::PARAM_ABF,
		GEO::ChartPacker::PACK_TETRIS
	);
	GEO::mesh_save(gmesh, "_mesh.obj");
	GEO::CmdLine::terminate();
	GEO::FileSystem::terminate();
	GEO::Logger::terminate();

image

cdcseacave avatar Nov 02 '22 09:11 cdcseacave

Maybe your vertices are duplicated , i.e., each vertex appears as many times as there are triangles it belongs to, each time with the same coordinates but different IDs.

devernay avatar Nov 02 '22 20:11 devernay

I finally found the issue, I have to manually call connect() after the mesh creation; that is fine, though what is not fine is that the code just runs normally without the face adjacency and does not complain in any way

now I have something working, but have no idea how to extract either the charts and how they are packed; ideally mesh_make_atlas should return what it computes, which is the charts and their packing instead of hiding them somewhere in the mesh (hopefully, still did not find them); we would love some comments or even better a full example in https://github.com/BrunoLevy/geogram/wiki/Texturing

as for the function it has no comments for the params, while in the example it has conflicting usage: by default the hard_angles_threshold angle seems to be in degrees, but in the example it is in radians 45.0 * M_PI / 180.0

just to be clear, this is an amazing library, powerful and fast, and I am thanking you for the effort of both writing it and making it public, it is just the features are somewhat non intuitive in accessing them and there is not help in form of comments or examples

cdcseacave avatar Nov 03 '22 05:11 cdcseacave

	GEO::Attribute<GEO::index_t> charts;
	charts.bind_if_is_defined(gmesh.facets.attributes(), "chart");

is failing, for some reason the attribute is deleted at the end of the function somehow; while there is a function to recompute them, it is not exposed

cdcseacave avatar Nov 03 '22 08:11 cdcseacave

the pack parameter might not be well used here:

	Packer packer;
	packer.pack_surface(mesh, false);
	if(pack == PACK_XATLAS) {
	    pack_atlas_using_xatlas(mesh);
	}

maybe should be:

	Packer packer;
	packer.pack_surface(mesh, pack == PACK_XATLAS);
	if(pack == PACK_XATLAS) {
	    pack_atlas_using_xatlas(mesh);
	}

cdcseacave avatar Nov 03 '22 08:11 cdcseacave

while the packing is needed, I can not find a way to recover it, so can you pls add a param to just skip the packing and I'll recompute it some other way?

cdcseacave avatar Nov 03 '22 08:11 cdcseacave

  • Yes, atlas_maker.h does not have doxygen comments ! (overlooked this one when I did a bit documentation pass last time), I'm adding the documentation shortly (+ double checking the degree/radiants incoherency you found, thanks for that !)
  • I'll also add an example of how to build a mesh here (including the need to call connect()
  • I'll double check the code for calling XATLAS, thank you for noticing
  • the "chart" attribute that is temporarily used (but not kept) by the packer stores in each facet an integer that indicates the chart this facet belongs to. Yes it would be possible to add a parameter to keep it, but no other user needed that, why do you need that ?
  • I do not understand what you mean by "keeping the packing"

BrunoLevy avatar Nov 03 '22 15:11 BrunoLevy

As far as I understand the chart is the list of face IDs contained in that chart. This is very useful for so many task, one of them for computing the texture for each one of them, packing them etc.

As for the charts packing we might speak about different things; in my mind packing the charts is finding their optimal position in a given texture image, or set of images if one is not enough. I do not see how to get any of that if that is computed in your packing. What packing means for geogram?

cdcseacave avatar Nov 03 '22 16:11 cdcseacave

Changed a couple of things:

  • replaced PACK_NA with PACK_NONE (to match other names in the library)
  • re-activated code to destroy the charts attribute (client code expects API functions to clean temporary attributes, and all the information is present in the texture coordinates)
  • added a function get_chart() to re-create it from the texture coordinates if needed

BrunoLevy avatar Nov 07 '22 14:11 BrunoLevy