| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#pragma once |
| 32 |
|
| 33 |
#include "../csg.h" |
| 34 |
#include "../csg_shape.h" |
| 35 |
|
| 36 |
#include "tests/test_macros.h" |
| 37 |
|
| 38 |
namespace TestCSG { |
| 39 |
|
| 40 |
TEST_CASE("[SceneTree][CSG] CSGPolygon3D") { |
| 41 |
SUBCASE("[SceneTree][CSG] CSGPolygon3D: using accurate path tangent for polygon rotation") { |
| 42 |
const float polygon_radius = 10.0f; |
| 43 |
|
| 44 |
const Vector3 expected_min_bounds = Vector3(-polygon_radius, -polygon_radius, 0); |
| 45 |
const Vector3 expected_max_bounds = Vector3(100 + polygon_radius, polygon_radius, 100); |
| 46 |
const AABB expected_aabb = AABB(expected_min_bounds, expected_max_bounds - expected_min_bounds); |
| 47 |
|
| 48 |
Ref<Curve3D> curve; |
| 49 |
curve.instantiate(); |
| 50 |
curve->add_point( |
| 51 |
|
| 52 |
Vector3(0, 0, 0), |
| 53 |
|
| 54 |
Vector3(), |
| 55 |
|
| 56 |
Vector3(0, 0, 60)); |
| 57 |
curve->add_point( |
| 58 |
|
| 59 |
Vector3(100, 0, 100), |
| 60 |
|
| 61 |
Vector3(0, 0, -60), |
| 62 |
|
| 63 |
Vector3()); |
| 64 |
|
| 65 |
Path3D *path = memnew(Path3D); |
| 66 |
path->set_curve(curve); |
| 67 |
|
| 68 |
CSGPolygon3D *csg_polygon_3d = memnew(CSGPolygon3D); |
| 69 |
SceneTree::get_singleton()->get_root()->add_child(csg_polygon_3d); |
| 70 |
|
| 71 |
csg_polygon_3d->add_child(path); |
| 72 |
csg_polygon_3d->set_path_node(csg_polygon_3d->get_path_to(path)); |
| 73 |
csg_polygon_3d->set_mode(CSGPolygon3D::Mode::MODE_PATH); |
| 74 |
|
| 75 |
PackedVector2Array polygon; |
| 76 |
polygon.append(Vector2(-polygon_radius, 0)); |
| 77 |
polygon.append(Vector2(0, polygon_radius)); |
| 78 |
polygon.append(Vector2(polygon_radius, 0)); |
| 79 |
polygon.append(Vector2(0, -polygon_radius)); |
| 80 |
csg_polygon_3d->set_polygon(polygon); |
| 81 |
|
| 82 |
csg_polygon_3d->set_path_rotation(CSGPolygon3D::PathRotation::PATH_ROTATION_PATH); |
| 83 |
csg_polygon_3d->set_path_rotation_accurate(true); |
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
csg_polygon_3d->set_path_interval_type(CSGPolygon3D::PathIntervalType::PATH_INTERVAL_DISTANCE); |
| 90 |
csg_polygon_3d->set_path_interval(1000.0f); |
| 91 |
|
| 92 |
|
| 93 |
csg_polygon_3d->get_brush_faces(); |
| 94 |
|
| 95 |
CHECK(csg_polygon_3d->get_aabb().is_equal_approx(expected_aabb)); |
| 96 |
|
| 97 |
|
| 98 |
csg_polygon_3d->set_path_interval(1.0f); |
| 99 |
csg_polygon_3d->get_brush_faces(); |
| 100 |
|
| 101 |
CHECK(csg_polygon_3d->get_aabb().is_equal_approx(expected_aabb)); |
| 102 |
|
| 103 |
csg_polygon_3d->remove_child(path); |
| 104 |
SceneTree::get_singleton()->get_root()->remove_child(csg_polygon_3d); |
| 105 |
|
| 106 |
memdelete(csg_polygon_3d); |
| 107 |
memdelete(path); |
| 108 |
} |
| 109 |
} |
| 110 |
|
| 111 |
} |