Commit 74b75b9e authored by Michal Petr's avatar Michal Petr
Browse files

feat: More convex hull meshes

parent 432a39a1
Loading
Loading
Loading
Loading
+111 −15
Original line number Diff line number Diff line
@@ -32,7 +32,7 @@ namespace static_collision {
		// ########################################
		static constexpr size_t BENCHMARK_OBJECTS[] = { 125, 250, 500, 1000, 2000, 4000 };
		static constexpr size_t BENCHMARK_ITERATIONS = 100;
		static constexpr bool ALLOWED_OBJECTS[] = { true, true, true, true, true, true };
		static constexpr bool ALLOWED_OBJECTS[] = { true, true, true, true, true, true, true, true, true };
		static constexpr float OBJECT_SPREAD = 20.0f;
		static constexpr bool SHOW_GFX = false;

@@ -69,7 +69,11 @@ namespace static_collision {
		com::Folder* m_gfx_instances_cylinder;
		com::Folder* m_gfx_instances_cone;
		com::Folder* m_gfx_instances_capsule;
		com::Folder* m_gfx_instances_convex;

		com::Folder* m_gfx_instances_convex_1;
		com::Folder* m_gfx_instances_convex_2;
		com::Folder* m_gfx_instances_convex_3;
		com::Folder* m_gfx_instances_convex_4;

		std::vector<std::pair<com::Frame*, com::Folder*>> m_frames;

@@ -105,6 +109,69 @@ namespace static_collision {
			5, 6, 7, 7, 6, 8, 8, 6, 9, 9, 6, 0, 2, 9, 0, 8, 9, 2, 2, 7, 8,
			2, 10, 7, 7, 10, 5, 5, 10, 3, 3, 10, 2
		};

		const std::vector<vec3> m_rand_mesh_vertices_1 = std::vector{
			vec3(0.44693, -0.0888302, 0.955979), vec3(-0.362056, -0.123182, 0.956446),
			vec3(-0.847383, -0.545322, 0.559838), vec3(-0.383974, 0.0769918, -0.472258),
			vec3(0.737603, 0.607478, -0.338322), vec3(0.900259, 0.702589, -0.539394),
			vec3(0.862412, -0.474832, -0.950202), vec3(-0.161256, -0.463122, -0.968179),
			vec3(0.0022409, -0.826513, -0.855898), vec3(0.348661, -0.423709, 0.344635),
			vec3(-0.238118, -0.214115, -0.868127)
		};

		const std::vector<uint32_t> m_rand_mesh_indices_1 = {
			0, 1, 2, 2, 1, 3, 1, 4, 3, 3, 4, 5, 5, 4, 0, 0, 4, 1, 0, 6, 5,
			5, 6, 7, 7, 6, 8, 8, 6, 9, 9, 6, 0, 2, 9, 0, 8, 9, 2, 2, 7, 8,
			2, 10, 7, 7, 10, 5, 5, 10, 3, 3, 10, 2
		};

		const std::vector<vec3> m_rand_mesh_vertices_2 = std::vector{
			vec3(0.746859, -0.977771, 0.937081), vec3(0.965741, 0.35304, -0.744289),
			vec3(-0.0357518, 0.947711, 0.749632), vec3(-0.0432164, 0.852877, 0.110713),
			vec3(-0.521121, 0.738389, -0.244966), vec3(0.0617114, 0.632923, -0.534543),
			vec3(0.636532, 0.239364, -0.957437), vec3(-0.332452, -0.892378, -0.562398),
			vec3(-0.465546, -0.868383, -0.415715), vec3(-0.706951, 0.0867721, 0.403056),
			vec3(-0.19615, 0.0453494, 0.744177), vec3(-0.155298, -0.977202, 0.224067),
		};

		const std::vector<uint32_t> m_rand_mesh_indices_2 = {
			0, 1, 2, 1, 3, 2, 2, 3, 4, 3, 5, 4, 4, 5, 6, 6, 5, 1, 1, 5, 3,
			1, 7, 6, 7, 4, 6, 8, 4, 7, 9, 4, 8, 2, 4, 9, 9, 10, 2, 2, 10,
			0, 0, 10, 9, 9, 11, 0, 0, 11, 7, 7, 11, 8, 8, 11, 9, 0, 7, 1
		};

		const std::vector<vec3> m_rand_mesh_vertices_3 = std::vector{
			vec3(-0.979252, -0.271078, 0.00374913), vec3(-0.973356, -0.562883, 0.754442),
			vec3(-0.727986, 0.333798, 0.901614), vec3(0.14552, -0.72915, 0.796014),
			vec3(-0.722773, -0.831881, -0.208228), vec3(-0.732341, -0.367551, -0.715778),
			vec3(-0.162984, -0.724946, -0.503798), vec3(0.886614, -0.227046, 0.259102),
			vec3(0.901928, 0.469316, -0.922503), vec3(-0.00173926, -0.00845343, -0.984914),
			vec3(-0.368582, 0.757118, -0.252098), vec3(0.935808, 0.398215, 0.403097),
			vec3(0.388877, 0.129739, 0.649741),
		};

		const std::vector<uint32_t> m_rand_mesh_indices_3 = {
			0, 1, 2, 2, 1, 3, 3, 1, 4, 4, 1, 0, 0, 5, 4, 5, 6, 4, 4, 6, 3,
			3, 6, 7, 7, 6, 8, 8, 6, 9, 9, 6, 5, 10, 9, 5, 8, 9, 10, 11, 8,
			10, 11, 7, 8, 3, 7, 11, 11, 12, 3, 3, 12, 2, 2, 12, 11, 11, 10,
			2, 10, 0, 2, 10, 5, 0
		};

		const std::vector<vec3> m_rand_mesh_vertices_4 = std::vector{
			vec3(0.542641, -0.402478, -0.958496), vec3(0.166644, -0.550407, -0.949657),
			vec3(0.781633, 0.625242, -0.603756), vec3(-0.71566, 0.557458, -0.253318),
			vec3(-0.468868, -0.661778, -0.472794), vec3(0.225052, -0.938767, 0.443511),
			vec3(-0.82332, -0.699244, 0.37072), vec3(-0.603874, 0.418416, 0.521061),
			vec3(0.367637, 0.906787, 0.633204), vec3(0.75523, -0.416248, 0.454871),
			vec3(0.835548, 0.0817618, 0.429152), vec3(-0.992103, -0.327857, 0.0243845),

		};

		const std::vector<uint32_t> m_rand_mesh_indices_4 = {
			0, 1, 2, 2, 1, 3, 3, 1, 4, 1, 5, 4, 4, 5, 6, 6, 5, 7, 7, 5, 8,
			8, 5, 9, 9, 5, 0, 0, 5, 1, 0, 2, 9, 2, 10, 9, 9, 10, 8, 8, 10,
			2, 8, 2, 3, 3, 7, 8, 3, 11, 7, 7, 11, 6, 6, 11, 4, 4, 11, 3
		};
	};

	// Helper function to create a directional light
@@ -192,21 +259,22 @@ namespace static_collision {
			0.5f, 1.0f, 10, "cone_mesh", {"tutorial"});
		auto capsule_mesh = gfx::buffer_generators()->insert_procedural_capsule_solid(
			0.5f, 0.5f, 10, "capsule_mesh", {"tutorial"});
		auto convex_mesh = gfx::buffer_generators()->insert_explicit(m_rand_mesh_vertices, m_rand_mesh_indices,
		                                                             "convex_mesh", {"tutorial"});

		auto convex_mesh_1 = gfx::buffer_generators()->insert_explicit(m_rand_mesh_vertices, m_rand_mesh_indices, "convex_mesh_1", {"tutorial"});
		auto convex_mesh_2 = gfx::buffer_generators()->insert_explicit(m_rand_mesh_vertices_2, m_rand_mesh_indices_2, "convex_mesh_2", {"tutorial"});
		auto convex_mesh_3 = gfx::buffer_generators()->insert_explicit(m_rand_mesh_vertices_3, m_rand_mesh_indices_3, "convex_mesh_3", {"tutorial"});
		auto convex_mesh_4 = gfx::buffer_generators()->insert_explicit(m_rand_mesh_vertices_4, m_rand_mesh_indices_4, "convex_mesh_4", {"tutorial"});

		// We'll create the instance folders for the shapes and insert the lights
		m_gfx_instances_box = gfx::object_system()->insert_object({"tutorial", "box"}, m_material_crate, box_mesh);
		gfx::object_system()->insert_light(m_gfx_instances_box, light_ambient());
		gfx::object_system()->insert_light(m_gfx_instances_box, light_directional());

		m_gfx_instances_sphere = gfx::object_system()->insert_object({"tutorial", "sphere"}, m_material_crate,
		                                                             sphere_mesh);
		m_gfx_instances_sphere = gfx::object_system()->insert_object({"tutorial", "sphere"}, m_material_crate, sphere_mesh);
		gfx::object_system()->insert_light(m_gfx_instances_sphere, light_ambient());
		gfx::object_system()->insert_light(m_gfx_instances_sphere, light_directional());

		m_gfx_instances_cylinder = gfx::object_system()->insert_object({"tutorial", "cylinder"}, m_material_crate,
		                                                               cylinder_mesh);
		m_gfx_instances_cylinder = gfx::object_system()->insert_object({"tutorial", "cylinder"}, m_material_crate, cylinder_mesh);
		gfx::object_system()->insert_light(m_gfx_instances_cylinder, light_ambient());
		gfx::object_system()->insert_light(m_gfx_instances_cylinder, light_directional());

@@ -214,15 +282,25 @@ namespace static_collision {
		gfx::object_system()->insert_light(m_gfx_instances_cone, light_ambient());
		gfx::object_system()->insert_light(m_gfx_instances_cone, light_directional());

		m_gfx_instances_capsule = gfx::object_system()->insert_object({"tutorial", "capsule"}, m_material_crate,
		                                                              capsule_mesh);
		m_gfx_instances_capsule = gfx::object_system()->insert_object({"tutorial", "capsule"}, m_material_crate, capsule_mesh);
		gfx::object_system()->insert_light(m_gfx_instances_capsule, light_ambient());
		gfx::object_system()->insert_light(m_gfx_instances_capsule, light_directional());

		m_gfx_instances_convex = gfx::object_system()->insert_object({"tutorial", "convex"}, m_material_crate,
		                                                             convex_mesh);
		gfx::object_system()->insert_light(m_gfx_instances_convex, light_ambient());
		gfx::object_system()->insert_light(m_gfx_instances_convex, light_directional());
		m_gfx_instances_convex_1 = gfx::object_system()->insert_object({"tutorial", "convex"}, m_material_crate, convex_mesh_1);
		gfx::object_system()->insert_light(m_gfx_instances_convex_1, light_ambient());
		gfx::object_system()->insert_light(m_gfx_instances_convex_1, light_directional());

		m_gfx_instances_convex_2 = gfx::object_system()->insert_object({"tutorial", "convex"}, m_material_crate, convex_mesh_2);
		gfx::object_system()->insert_light(m_gfx_instances_convex_2, light_ambient());
		gfx::object_system()->insert_light(m_gfx_instances_convex_2, light_directional());

		m_gfx_instances_convex_3 = gfx::object_system()->insert_object({"tutorial", "convex"}, m_material_crate, convex_mesh_3);
		gfx::object_system()->insert_light(m_gfx_instances_convex_3, light_ambient());
		gfx::object_system()->insert_light(m_gfx_instances_convex_3, light_directional());

		m_gfx_instances_convex_4 = gfx::object_system()->insert_object({"tutorial", "convex"}, m_material_crate, convex_mesh_4);
		gfx::object_system()->insert_light(m_gfx_instances_convex_4, light_ambient());
		gfx::object_system()->insert_light(m_gfx_instances_convex_4, light_directional());
	}

	inline void Presenter::initialize_bodies() {
@@ -259,7 +337,25 @@ namespace static_collision {
		if (ALLOWED_OBJECTS[5]) {
			auto body_convex = phx::body_system()->insert_body({"convex"});
			phx::body_system()->insert_convex_hull_collider(body_convex, m_rand_mesh_vertices, m_rand_mesh_indices);
			m_body_prefabs.emplace_back(body_convex, m_gfx_instances_convex);
			m_body_prefabs.emplace_back(body_convex, m_gfx_instances_convex_1);
		}

		if (ALLOWED_OBJECTS[6]) {
			auto body_convex = phx::body_system()->insert_body({"convex_2"});
			phx::body_system()->insert_convex_hull_collider(body_convex, m_rand_mesh_vertices_2, m_rand_mesh_indices_2);
			m_body_prefabs.emplace_back(body_convex, m_gfx_instances_convex_2);
		}

		if (ALLOWED_OBJECTS[7]) {
			auto body_convex = phx::body_system()->insert_body({"convex_3"});
			phx::body_system()->insert_convex_hull_collider(body_convex, m_rand_mesh_vertices_3, m_rand_mesh_indices_3);
			m_body_prefabs.emplace_back(body_convex, m_gfx_instances_convex_3);
		}

		if (ALLOWED_OBJECTS[8]) {
			auto body_convex = phx::body_system()->insert_body({"convex_4"});
			phx::body_system()->insert_convex_hull_collider(body_convex, m_rand_mesh_vertices_4, m_rand_mesh_indices_4);
			m_body_prefabs.emplace_back(body_convex, m_gfx_instances_convex_4);
		}
	}