feat: modules moved and engine moved to submodule

This commit is contained in:
Jan van der Weide 2025-04-12 18:40:44 +02:00
parent dfb5e645cd
commit c33d2130cc
5136 changed files with 225275 additions and 64485 deletions

View file

@ -36,10 +36,13 @@
#include "core/math/geometry_2d.h"
#include "scene/resources/3d/navigation_mesh_source_geometry_data_3d.h"
#include "scene/resources/navigation_mesh.h"
#ifndef NAVIGATION_3D_DISABLED
#include "servers/navigation_server_3d.h"
#endif // NAVIGATION_3D_DISABLED
#include <manifold/manifold.h>
#ifndef NAVIGATION_3D_DISABLED
Callable CSGShape3D::_navmesh_source_geometry_parsing_callback;
RID CSGShape3D::_navmesh_source_geometry_parser;
@ -60,9 +63,13 @@ void CSGShape3D::navmesh_parse_source_geometry(const Ref<NavigationMesh> &p_navi
}
NavigationMesh::ParsedGeometryType parsed_geometry_type = p_navigation_mesh->get_parsed_geometry_type();
uint32_t parsed_collision_mask = p_navigation_mesh->get_collision_mask();
if (parsed_geometry_type == NavigationMesh::PARSED_GEOMETRY_MESH_INSTANCES || (parsed_geometry_type == NavigationMesh::PARSED_GEOMETRY_STATIC_COLLIDERS && csgshape3d->is_using_collision() && (csgshape3d->get_collision_layer() & parsed_collision_mask)) || parsed_geometry_type == NavigationMesh::PARSED_GEOMETRY_BOTH) {
#ifndef PHYSICS_3D_DISABLED
bool nav_collision = (parsed_geometry_type == NavigationMesh::PARSED_GEOMETRY_STATIC_COLLIDERS && csgshape3d->is_using_collision() && (csgshape3d->get_collision_layer() & p_navigation_mesh->get_collision_mask()));
#else
bool nav_collision = false;
#endif // PHYSICS_3D_DISABLED
if (parsed_geometry_type == NavigationMesh::PARSED_GEOMETRY_MESH_INSTANCES || nav_collision || parsed_geometry_type == NavigationMesh::PARSED_GEOMETRY_BOTH) {
Array meshes = csgshape3d->get_meshes();
if (!meshes.is_empty()) {
Ref<Mesh> mesh = meshes[1];
@ -72,7 +79,9 @@ void CSGShape3D::navmesh_parse_source_geometry(const Ref<NavigationMesh> &p_navi
}
}
}
#endif // NAVIGATION_3D_DISABLED
#ifndef PHYSICS_3D_DISABLED
void CSGShape3D::set_use_collision(bool p_enable) {
if (use_collision == p_enable) {
return;
@ -186,6 +195,7 @@ void CSGShape3D::set_collision_priority(real_t p_priority) {
real_t CSGShape3D::get_collision_priority() const {
return collision_priority;
}
#endif // PHYSICS_3D_DISABLED
bool CSGShape3D::is_root_shape() const {
return !parent_shape;
@ -207,15 +217,20 @@ float CSGShape3D::get_snap() const {
#endif // DISABLE_DEPRECATED
void CSGShape3D::_make_dirty(bool p_parent_removing) {
#ifndef PHYSICS_3D_DISABLED
if ((p_parent_removing || is_root_shape()) && !dirty) {
callable_mp(this, &CSGShape3D::_update_shape).call_deferred(); // Must be deferred; otherwise, is_root_shape() will use the previous parent.
callable_mp(this, &CSGShape3D::update_shape).call_deferred(); // Must be deferred; otherwise, is_root_shape() will use the previous parent.
}
#endif // PHYSICS_3D_DISABLED
if (!is_root_shape()) {
parent_shape->_make_dirty();
} else if (!dirty) {
callable_mp(this, &CSGShape3D::_update_shape).call_deferred();
}
#ifndef PHYSICS_3D_DISABLED
else if (!dirty) {
callable_mp(this, &CSGShape3D::update_shape).call_deferred();
}
#endif // PHYSICS_3D_DISABLED
dirty = true;
}
@ -550,7 +565,7 @@ void CSGShape3D::mikktSetTSpaceDefault(const SMikkTSpaceContext *pContext, const
surface.tansw[i++] = d < 0 ? -1 : 1;
}
void CSGShape3D::_update_shape() {
void CSGShape3D::update_shape() {
if (!is_root_shape()) {
return;
}
@ -711,9 +726,20 @@ void CSGShape3D::_update_shape() {
set_base(root_mesh->get_rid());
#ifndef PHYSICS_3D_DISABLED
_update_collision_faces();
#endif // PHYSICS_3D_DISABLED
}
Ref<ArrayMesh> CSGShape3D::bake_static_mesh() {
Ref<ArrayMesh> baked_mesh;
if (is_root_shape() && root_mesh.is_valid()) {
baked_mesh = root_mesh;
}
return baked_mesh;
}
#ifndef PHYSICS_3D_DISABLED
Vector<Vector3> CSGShape3D::_get_brush_collision_faces() {
Vector<Vector3> collision_faces;
CSGBrush *n = _get_brush();
@ -746,14 +772,6 @@ void CSGShape3D::_update_collision_faces() {
}
}
Ref<ArrayMesh> CSGShape3D::bake_static_mesh() {
Ref<ArrayMesh> baked_mesh;
if (is_root_shape() && root_mesh.is_valid()) {
baked_mesh = root_mesh;
}
return baked_mesh;
}
Ref<ConcavePolygonShape3D> CSGShape3D::bake_collision_shape() {
Ref<ConcavePolygonShape3D> baked_collision_shape;
if (is_root_shape() && root_collision_shape.is_valid()) {
@ -800,6 +818,7 @@ void CSGShape3D::_on_transform_changed() {
RS::get_singleton()->instance_set_transform(root_collision_debug_instance, debug_shape_old_transform);
}
}
#endif // PHYSICS_3D_DISABLED
AABB CSGShape3D::get_aabb() const {
return node_aabb;
@ -872,6 +891,7 @@ void CSGShape3D::_notification(int p_what) {
}
} break;
#ifndef PHYSICS_3D_DISABLED
case NOTIFICATION_ENTER_TREE: {
if (use_collision && is_root_shape()) {
root_collision_shape.instantiate();
@ -904,6 +924,7 @@ void CSGShape3D::_notification(int p_what) {
}
_on_transform_changed();
} break;
#endif // PHYSICS_3D_DISABLED
}
}
@ -969,17 +990,18 @@ Ref<TriangleMesh> CSGShape3D::generate_triangle_mesh() const {
}
void CSGShape3D::_bind_methods() {
ClassDB::bind_method(D_METHOD("_update_shape"), &CSGShape3D::_update_shape);
ClassDB::bind_method(D_METHOD("is_root_shape"), &CSGShape3D::is_root_shape);
ClassDB::bind_method(D_METHOD("set_operation", "operation"), &CSGShape3D::set_operation);
ClassDB::bind_method(D_METHOD("get_operation"), &CSGShape3D::get_operation);
#ifndef DISABLE_DEPRECATED
ClassDB::bind_method(D_METHOD("_update_shape"), &CSGShape3D::update_shape);
ClassDB::bind_method(D_METHOD("set_snap", "snap"), &CSGShape3D::set_snap);
ClassDB::bind_method(D_METHOD("get_snap"), &CSGShape3D::get_snap);
#endif // DISABLE_DEPRECATED
#ifndef PHYSICS_3D_DISABLED
ClassDB::bind_method(D_METHOD("set_use_collision", "operation"), &CSGShape3D::set_use_collision);
ClassDB::bind_method(D_METHOD("is_using_collision"), &CSGShape3D::is_using_collision);
@ -1000,13 +1022,15 @@ void CSGShape3D::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_collision_priority", "priority"), &CSGShape3D::set_collision_priority);
ClassDB::bind_method(D_METHOD("get_collision_priority"), &CSGShape3D::get_collision_priority);
ClassDB::bind_method(D_METHOD("bake_collision_shape"), &CSGShape3D::bake_collision_shape);
#endif // PHYSICS_3D_DISABLED
ClassDB::bind_method(D_METHOD("set_calculate_tangents", "enabled"), &CSGShape3D::set_calculate_tangents);
ClassDB::bind_method(D_METHOD("is_calculating_tangents"), &CSGShape3D::is_calculating_tangents);
ClassDB::bind_method(D_METHOD("get_meshes"), &CSGShape3D::get_meshes);
ClassDB::bind_method(D_METHOD("bake_static_mesh"), &CSGShape3D::bake_static_mesh);
ClassDB::bind_method(D_METHOD("bake_collision_shape"), &CSGShape3D::bake_collision_shape);
ADD_PROPERTY(PropertyInfo(Variant::INT, "operation", PROPERTY_HINT_ENUM, "Union,Intersection,Subtraction"), "set_operation", "get_operation");
#ifndef DISABLE_DEPRECATED
@ -1014,11 +1038,13 @@ void CSGShape3D::_bind_methods() {
#endif // DISABLE_DEPRECATED
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "calculate_tangents"), "set_calculate_tangents", "is_calculating_tangents");
#ifndef PHYSICS_3D_DISABLED
ADD_GROUP("Collision", "collision_");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "use_collision"), "set_use_collision", "is_using_collision");
ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_layer", PROPERTY_HINT_LAYERS_3D_PHYSICS), "set_collision_layer", "get_collision_layer");
ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_mask", PROPERTY_HINT_LAYERS_3D_PHYSICS), "set_collision_mask", "get_collision_mask");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "collision_priority"), "set_collision_priority", "get_collision_priority");
#endif // PHYSICS_3D_DISABLED
BIND_ENUM_CONSTANT(OPERATION_UNION);
BIND_ENUM_CONSTANT(OPERATION_INTERSECTION);
@ -1109,13 +1135,13 @@ CSGBrush *CSGMesh3D::_build_brush() {
Array arrays = mesh->surface_get_arrays(i);
if (arrays.size() == 0) {
if (arrays.is_empty()) {
_make_dirty();
ERR_FAIL_COND_V(arrays.is_empty(), memnew(CSGBrush));
}
Vector<Vector3> avertices = arrays[Mesh::ARRAY_VERTEX];
if (avertices.size() == 0) {
if (avertices.is_empty()) {
continue;
}
@ -1231,7 +1257,7 @@ CSGBrush *CSGMesh3D::_build_brush() {
}
}
if (vertices.size() == 0) {
if (vertices.is_empty()) {
return memnew(CSGBrush);
}
@ -1322,14 +1348,14 @@ CSGBrush *CSGSphere3D::_build_brush() {
// We want to follow an order that's convenient for UVs.
// For latitude step we start at the top and move down like in an image.
const double latitude_step = -Math_PI / rings;
const double longitude_step = Math_TAU / radial_segments;
const double latitude_step = -Math::PI / rings;
const double longitude_step = Math::TAU / radial_segments;
int face = 0;
for (int i = 0; i < rings; i++) {
double cos0 = 0;
double sin0 = 1;
if (i > 0) {
double latitude0 = latitude_step * i + Math_TAU / 4;
double latitude0 = latitude_step * i + Math::TAU / 4;
cos0 = Math::cos(latitude0);
sin0 = Math::sin(latitude0);
}
@ -1338,7 +1364,7 @@ CSGBrush *CSGSphere3D::_build_brush() {
double cos1 = 0;
double sin1 = -1;
if (i < rings - 1) {
double latitude1 = latitude_step * (i + 1) + Math_TAU / 4;
double latitude1 = latitude_step * (i + 1) + Math::TAU / 4;
cos1 = Math::cos(latitude1);
sin1 = Math::sin(latitude1);
}
@ -1701,8 +1727,8 @@ CSGBrush *CSGCylinder3D::_build_brush() {
inc_n = 0;
}
float ang = inc * Math_TAU;
float ang_n = inc_n * Math_TAU;
float ang = inc * Math::TAU;
float ang_n = inc_n * Math::TAU;
Vector3 face_base(Math::cos(ang), 0, Math::sin(ang));
Vector3 face_base_n(Math::cos(ang_n), 0, Math::sin(ang_n));
@ -1944,8 +1970,8 @@ CSGBrush *CSGTorus3D::_build_brush() {
inci_n = 0;
}
float angi = inci * Math_TAU;
float angi_n = inci_n * Math_TAU;
float angi = inci * Math::TAU;
float angi_n = inci_n * Math::TAU;
Vector3 normali = Vector3(Math::cos(angi), 0, Math::sin(angi));
Vector3 normali_n = Vector3(Math::cos(angi_n), 0, Math::sin(angi_n));
@ -1957,8 +1983,8 @@ CSGBrush *CSGTorus3D::_build_brush() {
incj_n = 0;
}
float angj = incj * Math_TAU;
float angj_n = incj_n * Math_TAU;
float angj = incj * Math::TAU;
float angj_n = incj_n * Math::TAU;
Vector2 normalj = Vector2(Math::cos(angj), Math::sin(angj)) * radius + Vector2(min_radius + radius, 0);
Vector2 normalj_n = Vector2(Math::cos(angj_n), Math::sin(angj_n)) * radius + Vector2(min_radius + radius, 0);