Unigine::Mesh class is not saving/loading custom normals.


photo

Recommended Posts

Hi,

When loading my created mesh objects which I saved before there are no normals anymore in the mesh object.

Here is a reproducer:

{
		auto mesh = Unigine::Mesh::create();
		mesh->addSurface("0");
		mesh->addVertex(Unigine::Math::vec3(1.f, 1.f, 0.f), 0);
		mesh->addVertex(Unigine::Math::vec3(1.f, 0.f, 1.f), 0);
		mesh->addVertex(Unigine::Math::vec3(0.f, 1.f, 1.f), 0);

		mesh->addNormal(Unigine::Math::vec3(0.f, 0.f, 1.f), 0);
		mesh->addNormal(Unigine::Math::vec3(0.f, 0.f, 1.f), 0);
		mesh->addNormal(Unigine::Math::vec3(0.f, 0.f, 1.f), 0);

		mesh->addIndex(0, 0);
		mesh->addIndex(1, 0);
		mesh->addIndex(2, 0);

		auto numVertex = mesh->getNumVertex(0);
		auto numNormals=mesh->getNumNormals(0);
		std::cout << numVertex << numNormals << std::endl;

		mesh->save("hello.mesh");
	}
	{
		auto mesh = Unigine::Mesh::create("hello.mesh");
		auto numVertex = mesh->getNumVertex(0);
		auto numNormals = mesh->getNumNormals(0);
		std::cout << numVertex << numNormals << std::endl;
	}

It affects versions 2.7.2.1 to 2.8.0.1.

Thanks,

Sebastian

Link to post

Hello Sebastian,

Normals of mesh are not serializable. The whole tangent basis is serialized instead. Custom normals can be used to calculate it like this:

mesh->addNormal(Unigine::Math::vec3(0.f, 0.f, 1.f), 0);
mesh->addNormal(Unigine::Math::vec3(0.f, 0.f, 1.f), 0);
mesh->addNormal(Unigine::Math::vec3(0.f, 0.f, 1.f), 0);

mesh->addIndex(0, 0);
mesh->addIndex(1, 0);
mesh->addIndex(2, 0);

mesh->createTangents();

And after loading normals can be read back:

auto numTangents = mesh->getNumTangents(0);
auto normal = mesh->getTangent(0, 0).getNormal();

 

Link to post

Ok, can you please update your documentation for the save and load method to mark which properties are serialized and which not? ;)

Thanks

Edited by sebastian.vesenmayer
Link to post