/**************************************************************************/1/* test_csg.h */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#pragma once3132#include "../csg.h"33#include "../csg_shape.h"3435#include "tests/test_macros.h"3637namespace TestCSG {3839TEST_CASE("[SceneTree][CSG] CSGPolygon3D") {40SUBCASE("[SceneTree][CSG] CSGPolygon3D: using accurate path tangent for polygon rotation") {41const float polygon_radius = 10.0f;4243const Vector3 expected_min_bounds = Vector3(-polygon_radius, -polygon_radius, 0);44const Vector3 expected_max_bounds = Vector3(100 + polygon_radius, polygon_radius, 100);45const AABB expected_aabb = AABB(expected_min_bounds, expected_max_bounds - expected_min_bounds);4647Ref<Curve3D> curve;48curve.instantiate();49curve->add_point(50// p_position51Vector3(0, 0, 0),52// p_in53Vector3(),54// p_out55Vector3(0, 0, 60));56curve->add_point(57// p_position58Vector3(100, 0, 100),59// p_in60Vector3(0, 0, -60),61// p_out62Vector3());6364Path3D *path = memnew(Path3D);65path->set_curve(curve);6667CSGPolygon3D *csg_polygon_3d = memnew(CSGPolygon3D);68SceneTree::get_singleton()->get_root()->add_child(csg_polygon_3d);6970csg_polygon_3d->add_child(path);71csg_polygon_3d->set_path_node(csg_polygon_3d->get_path_to(path));72csg_polygon_3d->set_mode(CSGPolygon3D::Mode::MODE_PATH);7374PackedVector2Array polygon;75polygon.append(Vector2(-polygon_radius, 0));76polygon.append(Vector2(0, polygon_radius));77polygon.append(Vector2(polygon_radius, 0));78polygon.append(Vector2(0, -polygon_radius));79csg_polygon_3d->set_polygon(polygon);8081csg_polygon_3d->set_path_rotation(CSGPolygon3D::PathRotation::PATH_ROTATION_PATH);82csg_polygon_3d->set_path_rotation_accurate(true);8384// Minimize the number of extrusions.85// This decreases the number of samples taken from the curve.86// Having fewer samples increases the inaccuracy of the line between samples as an approximation of the tangent of the curve.87// With correct polygon orientation, the bounding box for the given curve should be independent of the number of extrusions.88csg_polygon_3d->set_path_interval_type(CSGPolygon3D::PathIntervalType::PATH_INTERVAL_DISTANCE);89csg_polygon_3d->set_path_interval(1000.0f);9091// Call get_brush_faces to force the bounding box to update.92csg_polygon_3d->get_brush_faces();9394CHECK(csg_polygon_3d->get_aabb().is_equal_approx(expected_aabb));9596// Perform the bounding box check again with a greater number of extrusions.97csg_polygon_3d->set_path_interval(1.0f);98csg_polygon_3d->get_brush_faces();99100CHECK(csg_polygon_3d->get_aabb().is_equal_approx(expected_aabb));101102csg_polygon_3d->remove_child(path);103SceneTree::get_singleton()->get_root()->remove_child(csg_polygon_3d);104105memdelete(csg_polygon_3d);106memdelete(path);107}108}109110} // namespace TestCSG111112113