Browse Source

Add lod to collision

Panagiotis Christopoulos Charitos 6 years ago
parent
commit
74ad9da65b
3 changed files with 19 additions and 4 deletions
  1. 16 2
      src/anki/importer/GltfImporter.cpp
  2. 2 1
      src/anki/importer/GltfImporterMesh.cpp
  3. 1 1
      thirdparty

+ 16 - 2
src/anki/importer/GltfImporter.cpp

@@ -619,7 +619,15 @@ Error GltfImporter::visitNode(
 				{
 					StringAuto name(self.m_importer->m_alloc);
 					name.sprintf("%s_lod1", self.m_mesh->name);
-					err = self.m_importer->writeMesh(*self.m_mesh, name, 0.5f);
+					err = self.m_importer->writeMesh(*self.m_mesh, name, 0.66f);
+				}
+
+				// LOD 2
+				if(!err)
+				{
+					StringAuto name(self.m_importer->m_alloc);
+					name.sprintf("%s_lod2", self.m_mesh->name);
+					err = self.m_importer->writeMesh(*self.m_mesh, name, 0.33f);
 				}
 
 				if(!err)
@@ -750,6 +758,12 @@ Error GltfImporter::writeModel(const cgltf_mesh& mesh, CString skinName)
 		ANKI_CHECK(file.writeText("\t\t\t<mesh1>%s%s.ankimesh</mesh1>\n", m_rpath.cstr(), name.cstr()));
 	}
 
+	{
+		StringAuto name(m_alloc);
+		name.sprintf("%s_lod2", mesh.name);
+		ANKI_CHECK(file.writeText("\t\t\t<mesh2>%s%s.ankimesh</mesh2>\n", m_rpath.cstr(), name.cstr()));
+	}
+
 	auto mtlOverride = extras.find("material_override");
 	if(mtlOverride != extras.getEnd())
 	{
@@ -999,7 +1013,7 @@ Error GltfImporter::writeCollisionMesh(const cgltf_mesh& mesh)
 	ANKI_CHECK(file.writeText("%s\n", XML_HEADER));
 
 	ANKI_CHECK(file.writeText("<collisionShape>\n\t<type>staticMesh</type>\n\t<value>"
-							  "%s%s.ankimesh</value>\n</collisionShape>\n",
+							  "%s%s_lod2.ankimesh</value>\n</collisionShape>\n",
 		m_rpath.cstr(),
 		mesh.name));
 

+ 2 - 1
src/anki/importer/GltfImporterMesh.cpp

@@ -224,7 +224,7 @@ static void decimateSubmesh(F32 factor, SubMesh& submesh, GenericMemoryPoolAlloc
 	}
 
 	// Decimate
-	DynamicArrayAuto<U32> newIndices(alloc, targetIndexCount);
+	DynamicArrayAuto<U32> newIndices(alloc, submesh.m_indices.getSize());
 	newIndices.resize(meshopt_simplify(&newIndices[0],
 		&submesh.m_indices[0],
 		submesh.m_indices.getSize(),
@@ -521,6 +521,7 @@ Error GltfImporter::writeMesh(const cgltf_mesh& mesh, CString nameOverride, F32
 			optimizeSubmesh(submesh, m_alloc);
 		}
 
+		// Simplify
 		if(decimateFactor < 1.0f)
 		{
 			decimateSubmesh(decimateFactor, submesh, m_alloc);

+ 1 - 1
thirdparty

@@ -1 +1 @@
-Subproject commit d611a3d01106ede727b66447d5b6cf22e627f247
+Subproject commit 56f6b7aac7556f1268d99475d80024ed49bd5349