diff --git a/tests/scene/test_occluder_instance_3d.h b/tests/scene/test_occluder_instance_3d.h new file mode 100644 index 000000000000..34c742ac45b0 --- /dev/null +++ b/tests/scene/test_occluder_instance_3d.h @@ -0,0 +1,91 @@ +/**************************************************************************/ +/* test_occluder_instance_3d.h */ +/**************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/**************************************************************************/ +/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ +/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/**************************************************************************/ + +#ifndef TEST_OCCLUDER_INSTANCE_3D_H +#define TEST_OCCLUDER_INSTANCE_3D_H + +#include "scene/3d/occluder_instance_3d.h" +#include "scene/3d/mesh_instance_3d.h" +#include "scene/resources/3d/primitive_meshes.h" +#include "core/io/file_access.h" +#include "scene/main/scene_tree.h" +#include "scene/main/window.h" + +#include "tests/test_macros.h" + +namespace TestOccluderInstance3D { + +TEST_CASE("[SceneTree][OccluderInstance3D] Test baking functionality") { + // We need to load an occluder path because when the light occluder generates + // it has to save to a file. + #ifdef WINDOWS_ENABLED + const String occluder_path = OS::get_singleton()->get_environment("TEMP").path_join("test_occluder.occ"); + #else + const String occluder_path = "/tmp/test_occluder.occ"; + #endif + + SceneTree *scene_tree = SceneTree::get_singleton(); + scene_tree->get_root()->set_use_occlusion_culling(true); + + OccluderInstance3D *occluder_instance = memnew(OccluderInstance3D); + Node *test_bake_scene = memnew(Node); + + scene_tree->get_root()->add_child(test_bake_scene); + scene_tree->get_root()->add_child(occluder_instance); + + // Instantiate some meshes to generate. There's a box and a cylinder here. + MeshInstance3D *box_mesh_instance = memnew(MeshInstance3D); + Ref box_mesh = Ref(); + box_mesh.instantiate(); + box_mesh_instance->set_mesh(box_mesh); + test_bake_scene->add_child(box_mesh_instance); + box_mesh_instance->set_owner(test_bake_scene); + + MeshInstance3D *cylinder_mesh_instance = memnew(MeshInstance3D); + Ref cylinder_mesh = Ref(); + cylinder_mesh.instantiate(); + cylinder_mesh_instance->set_mesh(cylinder_mesh); + test_bake_scene->add_child(cylinder_mesh_instance); + cylinder_mesh_instance->set_owner(test_bake_scene); + + OccluderInstance3D::BakeError error = occluder_instance->bake_scene(test_bake_scene, occluder_path); + + CHECK(error == OccluderInstance3D::BAKE_ERROR_OK); + + memdelete(box_mesh_instance); + memdelete(cylinder_mesh_instance); + memdelete(test_bake_scene); + memdelete(occluder_instance); + memdelete(scene_tree); +} + +} // namespace TestOccluderInstance3D + +#endif // TEST_OCCLUDER_INSTANCE_3D_H diff --git a/tests/test_main.cpp b/tests/test_main.cpp index 65d45ae92f9d..dcd268adf8ef 100644 --- a/tests/test_main.cpp +++ b/tests/test_main.cpp @@ -37,6 +37,7 @@ #include "editor/editor_settings.h" #endif // TOOLS_ENABLED +#include "tests/scene\test_occluder_instance_3d.h" #include "tests/core/config/test_project_settings.h" #include "tests/core/input/test_input_event.h" #include "tests/core/input/test_input_event_key.h"