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

@ -3,5 +3,26 @@ from misc.utility.scons_hints import *
Import("env")
env.add_source_files(env.scene_sources, "*.cpp")
env.add_source_files(env.scene_sources, "fog_material.cpp")
env.add_source_files(env.scene_sources, "importer_mesh.cpp")
env.add_source_files(env.scene_sources, "mesh_library.cpp")
env.add_source_files(env.scene_sources, "primitive_meshes.cpp")
env.add_source_files(env.scene_sources, "skin.cpp")
env.add_source_files(env.scene_sources, "sky_material.cpp")
env.add_source_files(env.scene_sources, "world_3d.cpp")
env.add_source_files(env.scene_sources, "skeleton/*.cpp")
if not env["disable_physics_3d"]:
env.add_source_files(env.scene_sources, "box_shape_3d.cpp")
env.add_source_files(env.scene_sources, "capsule_shape_3d.cpp")
env.add_source_files(env.scene_sources, "circle_shape_3d.cpp")
env.add_source_files(env.scene_sources, "concave_polygon_shape_3d.cpp")
env.add_source_files(env.scene_sources, "convex_polygon_shape_3d.cpp")
env.add_source_files(env.scene_sources, "cylinder_shape_3d.cpp")
env.add_source_files(env.scene_sources, "height_map_shape_3d.cpp")
env.add_source_files(env.scene_sources, "separation_ray_shape_3d.cpp")
env.add_source_files(env.scene_sources, "shape_3d.cpp")
env.add_source_files(env.scene_sources, "sphere_shape_3d.cpp")
env.add_source_files(env.scene_sources, "world_boundary_shape_3d.cpp")
if not env["disable_navigation_3d"]:
env.add_source_files(env.scene_sources, "navigation_mesh_source_geometry_data_3d.cpp")

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef BOX_SHAPE_3D_H
#define BOX_SHAPE_3D_H
#pragma once
#include "scene/resources/3d/shape_3d.h"
@ -56,5 +55,3 @@ public:
BoxShape3D();
};
#endif // BOX_SHAPE_3D_H

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef CAPSULE_SHAPE_3D_H
#define CAPSULE_SHAPE_3D_H
#pragma once
#include "scene/resources/3d/shape_3d.h"
@ -57,5 +56,3 @@ public:
CapsuleShape3D();
};
#endif // CAPSULE_SHAPE_3D_H

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef CONCAVE_POLYGON_SHAPE_3D_H
#define CONCAVE_POLYGON_SHAPE_3D_H
#pragma once
#include "scene/resources/3d/shape_3d.h"
@ -79,5 +78,3 @@ public:
ConcavePolygonShape3D();
};
#endif // CONCAVE_POLYGON_SHAPE_3D_H

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef CONVEX_POLYGON_SHAPE_3D_H
#define CONVEX_POLYGON_SHAPE_3D_H
#pragma once
#include "scene/resources/3d/shape_3d.h"
@ -54,5 +53,3 @@ public:
ConvexPolygonShape3D();
};
#endif // CONVEX_POLYGON_SHAPE_3D_H

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef CYLINDER_SHAPE_3D_H
#define CYLINDER_SHAPE_3D_H
#pragma once
#include "scene/resources/3d/shape_3d.h"
@ -56,5 +55,3 @@ public:
CylinderShape3D();
};
#endif // CYLINDER_SHAPE_3D_H

View file

@ -144,7 +144,7 @@ void FogMaterial::_update_shader() {
// Add a comment to describe the shader origin (useful when converting to ShaderMaterial).
RS::get_singleton()->shader_set_code(shader, R"(
// NOTE: Shader automatically converted from )" VERSION_NAME " " VERSION_FULL_CONFIG R"('s FogMaterial.
// NOTE: Shader automatically converted from )" GODOT_VERSION_NAME " " GODOT_VERSION_FULL_CONFIG R"('s FogMaterial.
shader_type fog;

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef FOG_MATERIAL_H
#define FOG_MATERIAL_H
#pragma once
#include "scene/resources/material.h"
@ -83,5 +82,3 @@ public:
FogMaterial();
virtual ~FogMaterial();
};
#endif // FOG_MATERIAL_H

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef HEIGHT_MAP_SHAPE_3D_H
#define HEIGHT_MAP_SHAPE_3D_H
#pragma once
#include "scene/resources/3d/shape_3d.h"
@ -68,5 +67,3 @@ public:
HeightMapShape3D();
};
#endif // HEIGHT_MAP_SHAPE_3D_H

View file

@ -31,19 +31,15 @@
#include "importer_mesh.h"
#include "core/io/marshalls.h"
#include "core/math/convex_hull.h"
#include "core/math/random_pcg.h"
#include "scene/resources/surface_tool.h"
#include <cstdint>
#ifndef PHYSICS_3D_DISABLED
#include "core/math/convex_hull.h"
#endif // PHYSICS_3D_DISABLED
String ImporterMesh::validate_blend_shape_name(const String &p_name) {
String name = p_name;
const char *characters = ":";
for (const char *p = characters; *p; p++) {
name = name.replace(String::chr(*p), "_");
}
return name;
return p_name.replace_char(':', '_');
}
void ImporterMesh::add_blend_shape(const String &p_name) {
@ -91,13 +87,11 @@ void ImporterMesh::add_surface(Mesh::PrimitiveType p_primitive, const Array &p_a
s.blend_shape_data.push_back(bs);
}
List<Variant> lods;
p_lods.get_key_list(&lods);
for (const Variant &E : lods) {
ERR_CONTINUE(!E.is_num());
for (const KeyValue<Variant, Variant> &kv : p_lods) {
ERR_CONTINUE(!kv.key.is_num());
Surface::LOD lod;
lod.distance = E;
lod.indices = p_lods[E];
lod.distance = kv.key;
lod.indices = kv.value;
ERR_CONTINUE(lod.indices.is_empty());
s.lods.push_back(lod);
}
@ -787,6 +781,7 @@ Vector<Face3> ImporterMesh::get_faces() const {
return faces;
}
#ifndef PHYSICS_3D_DISABLED
Vector<Ref<Shape3D>> ImporterMesh::convex_decompose(const Ref<MeshConvexDecompositionSettings> &p_settings) const {
ERR_FAIL_NULL_V(Mesh::convex_decomposition_function, Vector<Ref<Shape3D>>());
@ -874,7 +869,7 @@ Ref<ConvexPolygonShape3D> ImporterMesh::create_convex_shape(bool p_clean, bool p
Ref<ConcavePolygonShape3D> ImporterMesh::create_trimesh_shape() const {
Vector<Face3> faces = get_faces();
if (faces.size() == 0) {
if (faces.is_empty()) {
return Ref<ConcavePolygonShape3D>();
}
@ -892,10 +887,11 @@ Ref<ConcavePolygonShape3D> ImporterMesh::create_trimesh_shape() const {
shape->set_faces(face_points);
return shape;
}
#endif // PHYSICS_3D_DISABLED
Ref<NavigationMesh> ImporterMesh::create_navigation_mesh() {
Vector<Face3> faces = get_faces();
if (faces.size() == 0) {
if (faces.is_empty()) {
return Ref<NavigationMesh>();
}

View file

@ -28,16 +28,16 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef IMPORTER_MESH_H
#define IMPORTER_MESH_H
#pragma once
#include "core/io/resource.h"
#include "scene/resources/3d/concave_polygon_shape_3d.h"
#include "scene/resources/3d/convex_polygon_shape_3d.h"
#include "scene/resources/mesh.h"
#include "scene/resources/navigation_mesh.h"
#include <cstdint>
#ifndef PHYSICS_3D_DISABLED
#include "scene/resources/3d/concave_polygon_shape_3d.h"
#include "scene/resources/3d/convex_polygon_shape_3d.h"
#endif // PHYSICS_3D_DISABLED
// The following classes are used by importers instead of ArrayMesh and MeshInstance3D
// so the data is not registered (hence, quality loss), importing happens faster and
@ -120,9 +120,11 @@ public:
Ref<ImporterMesh> get_shadow_mesh() const;
Vector<Face3> get_faces() const;
#ifndef PHYSICS_3D_DISABLED
Vector<Ref<Shape3D>> convex_decompose(const Ref<MeshConvexDecompositionSettings> &p_settings) const;
Ref<ConvexPolygonShape3D> create_convex_shape(bool p_clean = true, bool p_simplify = false) const;
Ref<ConcavePolygonShape3D> create_trimesh_shape() const;
#endif // PHYSICS_3D_DISABLED
Ref<NavigationMesh> create_navigation_mesh();
Error lightmap_unwrap_cached(const Transform3D &p_base_transform, float p_texel_size, const Vector<uint8_t> &p_src_cache, Vector<uint8_t> &r_dst_cache);
@ -133,5 +135,3 @@ public:
Ref<ArrayMesh> get_mesh(const Ref<ArrayMesh> &p_base = Ref<ArrayMesh>());
void clear();
};
#endif // IMPORTER_MESH_H

View file

@ -30,7 +30,9 @@
#include "mesh_library.h"
#ifndef PHYSICS_3D_DISABLED
#include "box_shape_3d.h"
#endif // PHYSICS_3D_DISABLED
bool MeshLibrary::_set(const StringName &p_name, const Variant &p_value) {
String prop_name = p_name;
@ -65,6 +67,7 @@ bool MeshLibrary::_set(const StringName &p_name, const Variant &p_value) {
set_item_mesh_cast_shadow(idx, RS::ShadowCastingSetting::SHADOW_CASTING_SETTING_ON);
} break;
}
#ifndef PHYSICS_3D_DISABLED
} else if (what == "shape") {
Vector<ShapeData> shapes;
ShapeData sd;
@ -73,6 +76,7 @@ bool MeshLibrary::_set(const StringName &p_name, const Variant &p_value) {
set_item_shapes(idx, shapes);
} else if (what == "shapes") {
_set_item_shapes(idx, p_value);
#endif // PHYSICS_3D_DISABLED
} else if (what == "preview") {
set_item_preview(idx, p_value);
} else if (what == "navigation_mesh") {
@ -111,8 +115,10 @@ bool MeshLibrary::_get(const StringName &p_name, Variant &r_ret) const {
r_ret = get_item_mesh_transform(idx);
} else if (what == "mesh_cast_shadow") {
r_ret = (int)get_item_mesh_cast_shadow(idx);
#ifndef PHYSICS_3D_DISABLED
} else if (what == "shapes") {
r_ret = _get_item_shapes(idx);
#endif // PHYSICS_3D_DISABLED
} else if (what == "navigation_mesh") {
r_ret = get_item_navigation_mesh(idx);
} else if (what == "navigation_mesh_transform") {
@ -181,12 +187,14 @@ void MeshLibrary::set_item_mesh_cast_shadow(int p_item, RS::ShadowCastingSetting
emit_changed();
}
#ifndef PHYSICS_3D_DISABLED
void MeshLibrary::set_item_shapes(int p_item, const Vector<ShapeData> &p_shapes) {
ERR_FAIL_COND_MSG(!item_map.has(p_item), "Requested for nonexistent MeshLibrary item '" + itos(p_item) + "'.");
item_map[p_item].shapes = p_shapes;
emit_changed();
notify_property_list_changed();
}
#endif // PHYSICS_3D_DISABLED
void MeshLibrary::set_item_navigation_mesh(int p_item, const Ref<NavigationMesh> &p_navigation_mesh) {
ERR_FAIL_COND_MSG(!item_map.has(p_item), "Requested for nonexistent MeshLibrary item '" + itos(p_item) + "'.");
@ -232,10 +240,12 @@ RS::ShadowCastingSetting MeshLibrary::get_item_mesh_cast_shadow(int p_item) cons
return item_map[p_item].mesh_cast_shadow;
}
#ifndef PHYSICS_3D_DISABLED
Vector<MeshLibrary::ShapeData> MeshLibrary::get_item_shapes(int p_item) const {
ERR_FAIL_COND_V_MSG(!item_map.has(p_item), Vector<ShapeData>(), "Requested for nonexistent MeshLibrary item '" + itos(p_item) + "'.");
return item_map[p_item].shapes;
}
#endif // PHYSICS_3D_DISABLED
Ref<NavigationMesh> MeshLibrary::get_item_navigation_mesh(int p_item) const {
ERR_FAIL_COND_V_MSG(!item_map.has(p_item), Ref<NavigationMesh>(), "Requested for nonexistent MeshLibrary item '" + itos(p_item) + "'.");
@ -302,6 +312,7 @@ int MeshLibrary::get_last_unused_item_id() const {
}
}
#ifndef PHYSICS_3D_DISABLED
void MeshLibrary::_set_item_shapes(int p_item, const Array &p_shapes) {
Array arr_shapes = p_shapes;
int size = p_shapes.size();
@ -351,6 +362,7 @@ Array MeshLibrary::_get_item_shapes(int p_item) const {
return ret;
}
#endif // PHYSICS_3D_DISABLED
void MeshLibrary::reset_state() {
clear();
@ -364,7 +376,9 @@ void MeshLibrary::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_item_navigation_mesh", "id", "navigation_mesh"), &MeshLibrary::set_item_navigation_mesh);
ClassDB::bind_method(D_METHOD("set_item_navigation_mesh_transform", "id", "navigation_mesh"), &MeshLibrary::set_item_navigation_mesh_transform);
ClassDB::bind_method(D_METHOD("set_item_navigation_layers", "id", "navigation_layers"), &MeshLibrary::set_item_navigation_layers);
#ifndef PHYSICS_3D_DISABLED
ClassDB::bind_method(D_METHOD("set_item_shapes", "id", "shapes"), &MeshLibrary::_set_item_shapes);
#endif // PHYSICS_3D_DISABLED
ClassDB::bind_method(D_METHOD("set_item_preview", "id", "texture"), &MeshLibrary::set_item_preview);
ClassDB::bind_method(D_METHOD("get_item_name", "id"), &MeshLibrary::get_item_name);
ClassDB::bind_method(D_METHOD("get_item_mesh", "id"), &MeshLibrary::get_item_mesh);
@ -373,7 +387,9 @@ void MeshLibrary::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_item_navigation_mesh", "id"), &MeshLibrary::get_item_navigation_mesh);
ClassDB::bind_method(D_METHOD("get_item_navigation_mesh_transform", "id"), &MeshLibrary::get_item_navigation_mesh_transform);
ClassDB::bind_method(D_METHOD("get_item_navigation_layers", "id"), &MeshLibrary::get_item_navigation_layers);
#ifndef PHYSICS_3D_DISABLED
ClassDB::bind_method(D_METHOD("get_item_shapes", "id"), &MeshLibrary::_get_item_shapes);
#endif // PHYSICS_3D_DISABLED
ClassDB::bind_method(D_METHOD("get_item_preview", "id"), &MeshLibrary::get_item_preview);
ClassDB::bind_method(D_METHOD("remove_item", "id"), &MeshLibrary::remove_item);
ClassDB::bind_method(D_METHOD("find_item_by_name", "name"), &MeshLibrary::find_item_by_name);

View file

@ -28,31 +28,37 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef MESH_LIBRARY_H
#define MESH_LIBRARY_H
#pragma once
#include "core/io/resource.h"
#include "core/templates/rb_map.h"
#include "scene/resources/mesh.h"
#include "scene/resources/navigation_mesh.h"
#include "servers/rendering_server.h"
#ifndef PHYSICS_3D_DISABLED
#include "shape_3d.h"
#endif // PHYSICS_3D_DISABLED
class MeshLibrary : public Resource {
GDCLASS(MeshLibrary, Resource);
RES_BASE_EXTENSION("meshlib");
public:
#ifndef PHYSICS_3D_DISABLED
struct ShapeData {
Ref<Shape3D> shape;
Transform3D local_transform;
};
#endif // PHYSICS_3D_DISABLED
struct Item {
String name;
Ref<Mesh> mesh;
Transform3D mesh_transform;
RS::ShadowCastingSetting mesh_cast_shadow = RS::ShadowCastingSetting::SHADOW_CASTING_SETTING_ON;
#ifndef PHYSICS_3D_DISABLED
Vector<ShapeData> shapes;
#endif // PHYSICS_3D_DISABLED
Ref<Texture2D> preview;
Ref<NavigationMesh> navigation_mesh;
Transform3D navigation_mesh_transform;
@ -61,8 +67,10 @@ public:
RBMap<int, Item> item_map;
#ifndef PHYSICS_3D_DISABLED
void _set_item_shapes(int p_item, const Array &p_shapes);
Array _get_item_shapes(int p_item) const;
#endif // PHYSICS_3D_DISABLED
protected:
bool _set(const StringName &p_name, const Variant &p_value);
@ -81,7 +89,9 @@ public:
void set_item_navigation_mesh(int p_item, const Ref<NavigationMesh> &p_navigation_mesh);
void set_item_navigation_mesh_transform(int p_item, const Transform3D &p_transform);
void set_item_navigation_layers(int p_item, uint32_t p_navigation_layers);
#ifndef PHYSICS_3D_DISABLED
void set_item_shapes(int p_item, const Vector<ShapeData> &p_shapes);
#endif // PHYSICS_3D_DISABLED
void set_item_preview(int p_item, const Ref<Texture2D> &p_preview);
String get_item_name(int p_item) const;
Ref<Mesh> get_item_mesh(int p_item) const;
@ -90,7 +100,9 @@ public:
Ref<NavigationMesh> get_item_navigation_mesh(int p_item) const;
Transform3D get_item_navigation_mesh_transform(int p_item) const;
uint32_t get_item_navigation_layers(int p_item) const;
#ifndef PHYSICS_3D_DISABLED
Vector<ShapeData> get_item_shapes(int p_item) const;
#endif // PHYSICS_3D_DISABLED
Ref<Texture2D> get_item_preview(int p_item) const;
void remove_item(int p_item);
@ -106,5 +118,3 @@ public:
MeshLibrary();
~MeshLibrary();
};
#endif // MESH_LIBRARY_H

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef NAVIGATION_MESH_SOURCE_GEOMETRY_DATA_3D_H
#define NAVIGATION_MESH_SOURCE_GEOMETRY_DATA_3D_H
#pragma once
#include "core/os/rw_lock.h"
#include "scene/resources/mesh.h"
@ -109,5 +108,3 @@ public:
NavigationMeshSourceGeometryData3D() {}
~NavigationMeshSourceGeometryData3D() { clear(); }
};
#endif // NAVIGATION_MESH_SOURCE_GEOMETRY_DATA_3D_H

View file

@ -103,7 +103,7 @@ void PrimitiveMesh::_update() const {
Vector<Vector2> uv = arr[RS::ARRAY_TEX_UV];
Vector<Vector2> uv2 = arr[RS::ARRAY_TEX_UV2];
if (uv.size() > 0 && uv2.size() == 0) {
if (uv.size() > 0 && uv2.is_empty()) {
Vector2 uv2_scale = get_uv2_scale();
uv2.resize(uv.size());
@ -389,7 +389,7 @@ void CapsuleMesh::_update_lightmap_size() {
Size2i _lightmap_size_hint;
float padding = get_uv2_padding();
float radial_length = radius * Math_PI * 0.5; // circumference of 90 degree bend
float radial_length = radius * Math::PI * 0.5; // circumference of 90 degree bend
float vertical_length = radial_length * 2 + (height - 2.0 * radius); // total vertical length
_lightmap_size_hint.x = MAX(1.0, 4.0 * radial_length / texel_size) + padding;
@ -413,9 +413,9 @@ void CapsuleMesh::create_mesh_array(Array &p_arr, const float radius, const floa
float twothirds = 2.0 / 3.0;
// Only used if we calculate UV2
float radial_width = 2.0 * radius * Math_PI;
float radial_width = 2.0 * radius * Math::PI;
float radial_h = radial_width / (radial_width + p_uv2_padding);
float radial_length = radius * Math_PI * 0.5; // circumference of 90 degree bend
float radial_length = radius * Math::PI * 0.5; // circumference of 90 degree bend
float vertical_length = radial_length * 2 + (height - 2.0 * radius) + p_uv2_padding; // total vertical length
float radial_v = radial_length / vertical_length; // v size of top and bottom section
float height_v = (height - 2.0 * radius) / vertical_length; // v size of height section
@ -447,8 +447,8 @@ void CapsuleMesh::create_mesh_array(Array &p_arr, const float radius, const floa
w = 1.0;
y = 0.0;
} else {
w = Math::sin(0.5 * Math_PI * v);
y = Math::cos(0.5 * Math_PI * v);
w = Math::sin(0.5 * Math::PI * v);
y = Math::cos(0.5 * Math::PI * v);
}
for (i = 0; i <= radial_segments; i++) {
@ -459,8 +459,8 @@ void CapsuleMesh::create_mesh_array(Array &p_arr, const float radius, const floa
x = 0.0;
z = 1.0;
} else {
x = -Math::sin(u * Math_TAU);
z = Math::cos(u * Math_TAU);
x = -Math::sin(u * Math::TAU);
z = Math::cos(u * Math::TAU);
}
Vector3 p = Vector3(x * w, y, -z * w);
@ -506,8 +506,8 @@ void CapsuleMesh::create_mesh_array(Array &p_arr, const float radius, const floa
x = 0.0;
z = 1.0;
} else {
x = -Math::sin(u * Math_TAU);
z = Math::cos(u * Math_TAU);
x = -Math::sin(u * Math::TAU);
z = Math::cos(u * Math::TAU);
}
Vector3 p = Vector3(x * radius, y, -z * radius);
@ -546,8 +546,8 @@ void CapsuleMesh::create_mesh_array(Array &p_arr, const float radius, const floa
w = 0.0;
y = -1.0;
} else {
w = Math::cos(0.5 * Math_PI * v);
y = -Math::sin(0.5 * Math_PI * v);
w = Math::cos(0.5 * Math::PI * v);
y = -Math::sin(0.5 * Math::PI * v);
}
for (i = 0; i <= radial_segments; i++) {
@ -558,8 +558,8 @@ void CapsuleMesh::create_mesh_array(Array &p_arr, const float radius, const floa
x = 0.0;
z = 1.0;
} else {
x = -Math::sin(u * Math_TAU);
z = Math::cos(u * Math_TAU);
x = -Math::sin(u * Math::TAU);
z = Math::cos(u * Math::TAU);
}
Vector3 p = Vector3(x * w, y, -z * w);
@ -1028,8 +1028,8 @@ void CylinderMesh::_update_lightmap_size() {
Size2i _lightmap_size_hint;
float padding = get_uv2_padding();
float top_circumference = top_radius * Math_PI * 2.0;
float bottom_circumference = bottom_radius * Math_PI * 2.0;
float top_circumference = top_radius * Math::PI * 2.0;
float bottom_circumference = bottom_radius * Math::PI * 2.0;
float _width = MAX(top_circumference, bottom_circumference) / texel_size + padding;
_width = MAX(_width, (((top_radius + bottom_radius) / texel_size) + padding) * 2.0); // this is extremely unlikely to be larger, will only happen if padding is larger then our diameter.
@ -1055,8 +1055,8 @@ void CylinderMesh::create_mesh_array(Array &p_arr, float top_radius, float botto
float x, y, z, u, v, radius, radius_h;
// Only used if we calculate UV2
float top_circumference = top_radius * Math_PI * 2.0;
float bottom_circumference = bottom_radius * Math_PI * 2.0;
float top_circumference = top_radius * Math::PI * 2.0;
float bottom_circumference = bottom_radius * Math::PI * 2.0;
float vertical_length = height + MAX(2.0 * top_radius, 2.0 * bottom_radius) + (2.0 * p_uv2_padding);
float height_v = height / vertical_length;
float padding_v = p_uv2_padding / vertical_length;
@ -1102,8 +1102,8 @@ void CylinderMesh::create_mesh_array(Array &p_arr, float top_radius, float botto
x = 0.0;
z = 1.0;
} else {
x = Math::sin(u * Math_TAU);
z = Math::cos(u * Math_TAU);
x = Math::sin(u * Math::TAU);
z = Math::cos(u * Math::TAU);
}
Vector3 p = Vector3(x * radius, y, z * radius);
@ -1159,8 +1159,8 @@ void CylinderMesh::create_mesh_array(Array &p_arr, float top_radius, float botto
x = 0.0;
z = 1.0;
} else {
x = Math::sin(r * Math_TAU);
z = Math::cos(r * Math_TAU);
x = Math::sin(r * Math::TAU);
z = Math::cos(r * Math::TAU);
}
u = ((x + 1.0) * 0.25);
@ -1206,8 +1206,8 @@ void CylinderMesh::create_mesh_array(Array &p_arr, float top_radius, float botto
x = 0.0;
z = 1.0;
} else {
x = Math::sin(r * Math_TAU);
z = Math::cos(r * Math_TAU);
x = Math::sin(r * Math::TAU);
z = Math::cos(r * Math::TAU);
}
u = 0.5 + ((x + 1.0) * 0.25);
@ -1921,9 +1921,9 @@ void SphereMesh::_update_lightmap_size() {
Size2i _lightmap_size_hint;
float padding = get_uv2_padding();
float _width = radius * Math_TAU;
float _width = radius * Math::TAU;
_lightmap_size_hint.x = MAX(1.0, (_width / texel_size) + padding);
float _height = (is_hemisphere ? 1.0 : 0.5) * height * Math_PI; // note, with hemisphere height is our radius, while with a full sphere it is the diameter..
float _height = (is_hemisphere ? 1.0 : 0.5) * height * Math::PI; // note, with hemisphere height is our radius, while with a full sphere it is the diameter..
_lightmap_size_hint.y = MAX(1.0, (_height / texel_size) + padding);
set_lightmap_size_hint(_lightmap_size_hint);
@ -1944,11 +1944,11 @@ void SphereMesh::create_mesh_array(Array &p_arr, float radius, float height, int
float scale = height / radius * (is_hemisphere ? 1.0 : 0.5);
// Only used if we calculate UV2
float circumference = radius * Math_TAU;
float circumference = radius * Math::TAU;
float horizontal_length = circumference + p_uv2_padding;
float center_h = 0.5 * circumference / horizontal_length;
float height_v = scale * Math_PI / ((scale * Math_PI) + p_uv2_padding / radius);
float height_v = scale * Math::PI / ((scale * Math::PI) + p_uv2_padding / radius);
// set our bounding box
@ -1977,8 +1977,8 @@ void SphereMesh::create_mesh_array(Array &p_arr, float radius, float height, int
w = 0.0;
y = -1.0;
} else {
w = Math::sin(Math_PI * v);
y = Math::cos(Math_PI * v);
w = Math::sin(Math::PI * v);
y = Math::cos(Math::PI * v);
}
for (i = 0; i <= radial_segments; i++) {
@ -1989,8 +1989,8 @@ void SphereMesh::create_mesh_array(Array &p_arr, float radius, float height, int
x = 0.0;
z = 1.0;
} else {
x = Math::sin(u * Math_TAU);
z = Math::cos(u * Math_TAU);
x = Math::sin(u * Math::TAU);
z = Math::cos(u * Math::TAU);
}
if (is_hemisphere && y < 0.0) {
@ -2141,9 +2141,9 @@ void TorusMesh::_update_lightmap_size() {
float radius = (max_radius - min_radius) * 0.5;
float _width = max_radius * Math_TAU;
float _width = max_radius * Math::TAU;
_lightmap_size_hint.x = MAX(1.0, (_width / texel_size) + padding);
float _height = radius * Math_TAU;
float _height = radius * Math::TAU;
_lightmap_size_hint.y = MAX(1.0, (_height / texel_size) + padding);
set_lightmap_size_hint(_lightmap_size_hint);
@ -2181,23 +2181,23 @@ void TorusMesh::_create_mesh_array(Array &p_arr) const {
bool _add_uv2 = get_add_uv2();
float _uv2_padding = get_uv2_padding() * texel_size;
float horizontal_total = max_radius * Math_TAU + _uv2_padding;
float max_h = max_radius * Math_TAU / horizontal_total;
float delta_h = (max_radius - min_radius) * Math_TAU / horizontal_total;
float horizontal_total = max_radius * Math::TAU + _uv2_padding;
float max_h = max_radius * Math::TAU / horizontal_total;
float delta_h = (max_radius - min_radius) * Math::TAU / horizontal_total;
float height_v = radius * Math_TAU / (radius * Math_TAU + _uv2_padding);
float height_v = radius * Math::TAU / (radius * Math::TAU + _uv2_padding);
for (int i = 0; i <= rings; i++) {
int prevrow = (i - 1) * (ring_segments + 1);
int thisrow = i * (ring_segments + 1);
float inci = float(i) / rings;
float angi = inci * Math_TAU;
float angi = inci * Math::TAU;
Vector2 normali = (i == rings) ? Vector2(0.0, -1.0) : Vector2(-Math::sin(angi), -Math::cos(angi));
for (int j = 0; j <= ring_segments; j++) {
float incj = float(j) / ring_segments;
float angj = incj * Math_TAU;
float angj = incj * Math::TAU;
Vector2 normalj = (j == ring_segments) ? Vector2(-1.0, 0.0) : Vector2(-Math::cos(angj), Math::sin(angj));
Vector2 normalk = normalj * radius + Vector2(min_radius + radius, 0);
@ -2486,8 +2486,8 @@ void TubeTrailMesh::_create_mesh_array(Array &p_arr) const {
float x = 0.0;
float z = 1.0;
if (i < radial_steps) {
x = Math::sin(u * Math_TAU);
z = Math::cos(u * Math_TAU);
x = Math::sin(u * Math::TAU);
z = Math::cos(u * Math::TAU);
}
Vector3 p = Vector3(x * r, y, z * r);
@ -2559,8 +2559,8 @@ void TubeTrailMesh::_create_mesh_array(Array &p_arr) const {
float x = 0.0;
float z = 1.0;
if (i < radial_steps) {
x = Math::sin(r * Math_TAU);
z = Math::cos(r * Math_TAU);
x = Math::sin(r * Math::TAU);
z = Math::cos(r * Math::TAU);
}
float u = ((x + 1.0) * 0.25);
@ -2628,8 +2628,8 @@ void TubeTrailMesh::_create_mesh_array(Array &p_arr) const {
float x = 0.0;
float z = 1.0;
if (i < radial_steps) {
x = Math::sin(r * Math_TAU);
z = Math::cos(r * Math_TAU);
x = Math::sin(r * Math::TAU);
z = Math::cos(r * Math::TAU);
}
float u = 0.5 + ((x + 1.0) * 0.25);
@ -2972,7 +2972,7 @@ void TextMesh::_generate_glyph_mesh_data(const GlyphMeshKey &p_key, const Glyph
PackedInt32Array contours = d["contours"];
bool orientation = d["orientation"];
if (points.size() < 3 || contours.size() < 1) {
if (points.size() < 3 || contours.is_empty()) {
return; // No full contours, only glyph control points (or nothing), ignore.
}
@ -3105,14 +3105,13 @@ void TextMesh::_generate_glyph_mesh_data(const GlyphMeshKey &p_key, const Glyph
ERR_FAIL_MSG("Convex decomposing failed. Make sure the font doesn't contain self-intersecting lines, as these are not supported in TextMesh.");
}
List<TPPLPoly> out_tris;
for (List<TPPLPoly>::Element *I = out_poly.front(); I; I = I->next()) {
if (tpart.Triangulate_OPT(&(I->get()), &out_tris) == 0) {
for (TPPLPoly &tp : out_poly) {
if (tpart.Triangulate_OPT(&tp, &out_tris) == 0) {
ERR_FAIL_MSG("Triangulation failed. Make sure the font doesn't contain self-intersecting lines, as these are not supported in TextMesh.");
}
}
for (List<TPPLPoly>::Element *I = out_tris.front(); I; I = I->next()) {
TPPLPoly &tp = I->get();
for (const TPPLPoly &tp : out_tris) {
ERR_FAIL_COND(tp.GetNumPoints() != 3); // Triangles only.
for (int i = 0; i < 3; i++) {
@ -3249,8 +3248,8 @@ void TextMesh::_create_mesh_array(Array &p_arr) const {
Vector<Vector2> uvs;
Vector<int32_t> indices;
Vector2 min_p = Vector2(INFINITY, INFINITY);
Vector2 max_p = Vector2(-INFINITY, -INFINITY);
Vector2 min_p = Vector2(Math::INF, Math::INF);
Vector2 max_p = Vector2(-Math::INF, -Math::INF);
int32_t p_size = 0;
int32_t i_size = 0;

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef PRIMITIVE_MESHES_H
#define PRIMITIVE_MESHES_H
#pragma once
#include "scene/resources/font.h"
#include "scene/resources/mesh.h"
@ -582,8 +581,8 @@ private:
Vector<Vector2> triangles;
Vector<Vector<ContourPoint>> contours;
Vector<ContourInfo> contours_info;
Vector2 min_p = Vector2(INFINITY, INFINITY);
Vector2 max_p = Vector2(-INFINITY, -INFINITY);
Vector2 min_p = Vector2(Math::INF, Math::INF);
Vector2 max_p = Vector2(-Math::INF, -Math::INF);
};
mutable HashMap<GlyphMeshKey, GlyphMeshData, GlyphMeshKeyHasher> cache;
@ -691,5 +690,3 @@ public:
};
VARIANT_ENUM_CAST(RibbonTrailMesh::Shape)
#endif // PRIMITIVE_MESHES_H

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef SEPARATION_RAY_SHAPE_3D_H
#define SEPARATION_RAY_SHAPE_3D_H
#pragma once
#include "scene/resources/3d/shape_3d.h"
@ -57,5 +56,3 @@ public:
SeparationRayShape3D();
};
#endif // SEPARATION_RAY_SHAPE_3D_H

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef SHAPE_3D_H
#define SHAPE_3D_H
#pragma once
#include "core/io/resource.h"
@ -94,5 +93,3 @@ public:
Shape3D();
~Shape3D();
};
#endif // SHAPE_3D_H

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef SKIN_H
#define SKIN_H
#pragma once
#include "core/io/resource.h"
@ -85,5 +84,3 @@ public:
Skin();
};
#endif // SKIN_H

View file

@ -276,7 +276,7 @@ void ProceduralSkyMaterial::_update_shader() {
// Add a comment to describe the shader origin (useful when converting to ShaderMaterial).
RS::get_singleton()->shader_set_code(shader_cache[i], vformat(R"(
// NOTE: Shader automatically converted from )" VERSION_NAME " " VERSION_FULL_CONFIG R"('s ProceduralSkyMaterial.
// NOTE: Shader automatically converted from )" GODOT_VERSION_NAME " " GODOT_VERSION_FULL_CONFIG R"('s ProceduralSkyMaterial.
shader_type sky;
%s
@ -470,7 +470,7 @@ void PanoramaSkyMaterial::_update_shader() {
// Add a comment to describe the shader origin (useful when converting to ShaderMaterial).
RS::get_singleton()->shader_set_code(shader_cache[i], vformat(R"(
// NOTE: Shader automatically converted from )" VERSION_NAME " " VERSION_FULL_CONFIG R"('s PanoramaSkyMaterial.
// NOTE: Shader automatically converted from )" GODOT_VERSION_NAME " " GODOT_VERSION_FULL_CONFIG R"('s PanoramaSkyMaterial.
shader_type sky;
@ -698,7 +698,7 @@ void PhysicalSkyMaterial::_update_shader() {
// Add a comment to describe the shader origin (useful when converting to ShaderMaterial).
RS::get_singleton()->shader_set_code(shader_cache[i], vformat(R"(
// NOTE: Shader automatically converted from )" VERSION_NAME " " VERSION_FULL_CONFIG R"('s PhysicalSkyMaterial.
// NOTE: Shader automatically converted from )" GODOT_VERSION_NAME " " GODOT_VERSION_FULL_CONFIG R"('s PhysicalSkyMaterial.
shader_type sky;
%s

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef SKY_MATERIAL_H
#define SKY_MATERIAL_H
#pragma once
#include "core/templates/rid.h"
#include "scene/resources/material.h"
@ -231,5 +230,3 @@ public:
PhysicalSkyMaterial();
~PhysicalSkyMaterial();
};
#endif // SKY_MATERIAL_H

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef SPHERE_SHAPE_3D_H
#define SPHERE_SHAPE_3D_H
#pragma once
#include "scene/resources/3d/shape_3d.h"
@ -54,5 +53,3 @@ public:
SphereShape3D();
};
#endif // SPHERE_SHAPE_3D_H

View file

@ -45,6 +45,7 @@ void World3D::_remove_camera(Camera3D *p_camera) {
}
RID World3D::get_space() const {
#ifndef PHYSICS_3D_DISABLED
if (space.is_null()) {
space = PhysicsServer3D::get_singleton()->space_create();
PhysicsServer3D::get_singleton()->space_set_active(space, true);
@ -53,6 +54,7 @@ RID World3D::get_space() const {
PhysicsServer3D::get_singleton()->area_set_param(space, PhysicsServer3D::AREA_PARAM_LINEAR_DAMP, GLOBAL_GET("physics/3d/default_linear_damp"));
PhysicsServer3D::get_singleton()->area_set_param(space, PhysicsServer3D::AREA_PARAM_ANGULAR_DAMP, GLOBAL_GET("physics/3d/default_angular_damp"));
}
#endif // PHYSICS_3D_DISABLED
return space;
}
@ -139,9 +141,11 @@ Ref<Compositor> World3D::get_compositor() const {
return compositor;
}
#ifndef PHYSICS_3D_DISABLED
PhysicsDirectSpaceState3D *World3D::get_direct_space_state() {
return PhysicsServer3D::get_singleton()->space_get_direct_state(get_space());
}
#endif // PHYSICS_3D_DISABLED
void World3D::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_space"), &World3D::get_space);
@ -153,14 +157,18 @@ void World3D::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_fallback_environment"), &World3D::get_fallback_environment);
ClassDB::bind_method(D_METHOD("set_camera_attributes", "attributes"), &World3D::set_camera_attributes);
ClassDB::bind_method(D_METHOD("get_camera_attributes"), &World3D::get_camera_attributes);
#ifndef PHYSICS_3D_DISABLED
ClassDB::bind_method(D_METHOD("get_direct_space_state"), &World3D::get_direct_space_state);
#endif // PHYSICS_3D_DISABLED
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "environment", PROPERTY_HINT_RESOURCE_TYPE, "Environment"), "set_environment", "get_environment");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "fallback_environment", PROPERTY_HINT_RESOURCE_TYPE, "Environment"), "set_fallback_environment", "get_fallback_environment");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "camera_attributes", PROPERTY_HINT_RESOURCE_TYPE, "CameraAttributesPractical,CameraAttributesPhysical"), "set_camera_attributes", "get_camera_attributes");
ADD_PROPERTY(PropertyInfo(Variant::RID, "space", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "", "get_space");
ADD_PROPERTY(PropertyInfo(Variant::RID, "navigation_map", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "", "get_navigation_map");
ADD_PROPERTY(PropertyInfo(Variant::RID, "scenario", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "", "get_scenario");
#ifndef PHYSICS_3D_DISABLED
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "direct_space_state", PROPERTY_HINT_RESOURCE_TYPE, "PhysicsDirectSpaceState3D", PROPERTY_USAGE_NONE), "", "get_direct_space_state");
#endif // PHYSICS_3D_DISABLED
}
World3D::World3D() {
@ -169,13 +177,17 @@ World3D::World3D() {
World3D::~World3D() {
ERR_FAIL_NULL(RenderingServer::get_singleton());
#ifndef PHYSICS_3D_DISABLED
ERR_FAIL_NULL(PhysicsServer3D::get_singleton());
#endif // PHYSICS_3D_DISABLED
ERR_FAIL_NULL(NavigationServer3D::get_singleton());
RenderingServer::get_singleton()->free(scenario);
#ifndef PHYSICS_3D_DISABLED
if (space.is_valid()) {
PhysicsServer3D::get_singleton()->free(space);
}
#endif // PHYSICS_3D_DISABLED
if (navigation_map.is_valid()) {
NavigationServer3D::get_singleton()->free(navigation_map);
}

View file

@ -28,14 +28,14 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef WORLD_3D_H
#define WORLD_3D_H
#pragma once
#include "core/io/resource.h"
#include "scene/resources/compositor.h"
#include "scene/resources/environment.h"
#ifndef PHYSICS_3D_DISABLED
#include "servers/physics_server_3d.h"
#include "servers/rendering_server.h"
#endif // PHYSICS_3D_DISABLED
class CameraAttributes;
class Camera3D;
@ -84,10 +84,10 @@ public:
_FORCE_INLINE_ const HashSet<Camera3D *> &get_cameras() const { return cameras; }
#ifndef PHYSICS_3D_DISABLED
PhysicsDirectSpaceState3D *get_direct_space_state();
#endif // PHYSICS_3D_DISABLED
World3D();
~World3D();
};
#endif // WORLD_3D_H

View file

@ -28,8 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef WORLD_BOUNDARY_SHAPE_3D_H
#define WORLD_BOUNDARY_SHAPE_3D_H
#pragma once
#include "scene/resources/3d/shape_3d.h"
@ -56,5 +55,3 @@ public:
WorldBoundaryShape3D();
};
#endif // WORLD_BOUNDARY_SHAPE_3D_H