Skip to content

Commit

Permalink
Small fixes and renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitriySalnikov committed Jul 26, 2024
1 parent a18034c commit 0cc3998
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 130 deletions.
14 changes: 7 additions & 7 deletions src/3d/config_scope_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,21 +70,21 @@ real_t DebugDraw3DScopeConfig::get_plane_size() const {
}

Ref<DebugDraw3DScopeConfig> DebugDraw3DScopeConfig::set_viewport(Viewport *_value) const {
data->dgcd.viewport = _value;
data->dcd.viewport = _value;
return Ref<DebugDraw3DScopeConfig>(this);
}

Viewport *DebugDraw3DScopeConfig::get_viewport() const {
return data->dgcd.viewport;
return data->dcd.viewport;
}

Ref<DebugDraw3DScopeConfig> DebugDraw3DScopeConfig::set_no_depth_test(bool _value) const {
data->dgcd.no_depth_test = _value;
data->dcd.no_depth_test = _value;
return Ref<DebugDraw3DScopeConfig>(this);
}

bool DebugDraw3DScopeConfig::is_no_depth_test() const {
return data->dgcd.no_depth_test;
return data->dcd.no_depth_test;
}

DebugDraw3DScopeConfig::DebugDraw3DScopeConfig() {
Expand Down Expand Up @@ -113,7 +113,7 @@ DebugDraw3DScopeConfig::Data::Data() {
center_brightness = 0;
hd_sphere = false;
plane_size = INFINITY;
dgcd = {};
dcd = {};
}

DebugDraw3DScopeConfig::Data::Data(const std::shared_ptr<Data> &p_parent) {
Expand All @@ -122,6 +122,6 @@ DebugDraw3DScopeConfig::Data::Data(const std::shared_ptr<Data> &p_parent) {
hd_sphere = p_parent->hd_sphere;
plane_size = p_parent->plane_size;

dgcd.viewport = p_parent->dgcd.viewport;
dgcd.no_depth_test = p_parent->dgcd.no_depth_test;
dcd.viewport = p_parent->dcd.viewport;
dcd.no_depth_test = p_parent->dcd.no_depth_test;
}
2 changes: 1 addition & 1 deletion src/3d/config_scope_3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class DebugDraw3DScopeConfig : public RefCounted {
real_t center_brightness;
bool hd_sphere;
real_t plane_size;
DebugContainerDependent dgcd;
DebugContainerDependent dcd;

Data();
Data(const std::shared_ptr<Data> &parent);
Expand Down
23 changes: 8 additions & 15 deletions src/3d/debug_draw_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -685,28 +685,21 @@ void DebugDraw3D::clear_all() {
if (NEED_LEAVE || config->is_freeze_3d_render()) return;
#endif

#define GET_SCOPED_CFG_AND_DGC() \
auto scfg = scoped_config_for_current_thread(); \
auto dgc = get_debug_container(scfg->dgcd, true); \
#define GET_SCOPED_CFG_AND_DGC() \
auto scfg = scoped_config_for_current_thread(); \
auto dgc = get_debug_container(scfg->dcd, true); \
if (!dgc) return

#ifndef DISABLE_DEBUG_RENDERING

Vector3 DebugDraw3D::get_up_vector(const Vector3 &p_dir) {
bool ex = Math::is_equal_approx(p_dir.x, 0);
bool ey = Math::is_equal_approx(p_dir.y, 0);
bool ez = Math::is_equal_approx(p_dir.z, 0);

if (ex) {
if (ey) {
return Vector3_UP;
} else if (ez) {
if (Math::is_equal_approx(p_dir.x, 0)) {
if (Math::is_equal_approx(p_dir.z, 0))
return Vector3_FORWARD;
}
return Vector3_UP;
} else if (ey) {
} else if (Math::is_equal_approx(p_dir.y, 0)) {
return p_dir.normalized().cross(Vector3_UP);
} else if (ez) {
} else if (Math::is_equal_approx(p_dir.z, 0)) {
return Vector3_UP;
}

Expand Down Expand Up @@ -1138,7 +1131,7 @@ void DebugDraw3D::draw_plane(const Plane &plane, const Color &color, const Vecto
LOCK_GUARD(datalock);
GET_SCOPED_CFG_AND_DGC();

Camera3D *cam = scfg->dgcd.viewport ? scfg->dgcd.viewport->get_camera_3d() : nullptr;
Camera3D *cam = scfg->dcd.viewport ? scfg->dcd.viewport->get_camera_3d() : nullptr;

Vector3 center_pos = plane.project(anchor_point == Vector3_INF ? (cam ? cam->get_global_position() : Vector3()) : anchor_point);
real_t plane_size = scfg->plane_size != INFINITY ? scfg->plane_size : (cam ? (real_t)cam->get_far() : 1000);
Expand Down
44 changes: 22 additions & 22 deletions src/3d/debug_geometry_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,31 +48,31 @@ DebugGeometryContainer::DebugGeometryContainer(class DebugDraw3D *p_root, bool p
auto *meshes = owner->get_shared_meshes();
int mat_variant = !!no_depth_test;

CreateMMI(InstanceType::CUBE, NAMEOF(mmi_cubes), meshes[(int)InstanceType::CUBE][mat_variant]);
CreateMMI(InstanceType::CUBE_CENTERED, NAMEOF(mmi_cubes_centered), meshes[(int)InstanceType::CUBE_CENTERED][mat_variant]);
CreateMMI(InstanceType::ARROWHEAD, NAMEOF(mmi_arrowheads), meshes[(int)InstanceType::ARROWHEAD][mat_variant]);
CreateMMI(InstanceType::POSITION, NAMEOF(mmi_positions), meshes[(int)InstanceType::POSITION][mat_variant]);
CreateMMI(InstanceType::SPHERE, NAMEOF(mmi_spheres), meshes[(int)InstanceType::SPHERE][mat_variant]);
CreateMMI(InstanceType::SPHERE_HD, NAMEOF(mmi_spheres_hd), meshes[(int)InstanceType::SPHERE_HD][mat_variant]);
CreateMMI(InstanceType::CYLINDER, NAMEOF(mmi_cylinders), meshes[(int)InstanceType::CYLINDER][mat_variant]);
CreateMMI(InstanceType::CYLINDER_AB, NAMEOF(mmi_cylinders), meshes[(int)InstanceType::CYLINDER_AB][mat_variant]);
CreateMMI(InstanceType::CUBE, meshes[(int)InstanceType::CUBE][mat_variant]);
CreateMMI(InstanceType::CUBE_CENTERED, meshes[(int)InstanceType::CUBE_CENTERED][mat_variant]);
CreateMMI(InstanceType::ARROWHEAD, meshes[(int)InstanceType::ARROWHEAD][mat_variant]);
CreateMMI(InstanceType::POSITION, meshes[(int)InstanceType::POSITION][mat_variant]);
CreateMMI(InstanceType::SPHERE, meshes[(int)InstanceType::SPHERE][mat_variant]);
CreateMMI(InstanceType::SPHERE_HD, meshes[(int)InstanceType::SPHERE_HD][mat_variant]);
CreateMMI(InstanceType::CYLINDER, meshes[(int)InstanceType::CYLINDER][mat_variant]);
CreateMMI(InstanceType::CYLINDER_AB, meshes[(int)InstanceType::CYLINDER_AB][mat_variant]);

// VOLUMETRIC

CreateMMI(InstanceType::LINE_VOLUMETRIC, NAMEOF(mmi_cubes_volumetric), meshes[(int)InstanceType::LINE_VOLUMETRIC][mat_variant]);
CreateMMI(InstanceType::CUBE_VOLUMETRIC, NAMEOF(mmi_cubes_volumetric), meshes[(int)InstanceType::CUBE_VOLUMETRIC][mat_variant]);
CreateMMI(InstanceType::CUBE_CENTERED_VOLUMETRIC, NAMEOF(mmi_cubes_centered_volumetric), meshes[(int)InstanceType::CUBE_CENTERED_VOLUMETRIC][mat_variant]);
CreateMMI(InstanceType::ARROWHEAD_VOLUMETRIC, NAMEOF(mmi_arrowheads_volumetric), meshes[(int)InstanceType::ARROWHEAD_VOLUMETRIC][mat_variant]);
CreateMMI(InstanceType::POSITION_VOLUMETRIC, NAMEOF(mmi_positions_volumetric), meshes[(int)InstanceType::POSITION_VOLUMETRIC][mat_variant]);
CreateMMI(InstanceType::SPHERE_VOLUMETRIC, NAMEOF(mmi_spheres_volumetric), meshes[(int)InstanceType::SPHERE_VOLUMETRIC][mat_variant]);
CreateMMI(InstanceType::SPHERE_HD_VOLUMETRIC, NAMEOF(mmi_spheres_hd_volumetric), meshes[(int)InstanceType::SPHERE_HD_VOLUMETRIC][mat_variant]);
CreateMMI(InstanceType::CYLINDER_VOLUMETRIC, NAMEOF(mmi_cylinders_volumetric), meshes[(int)InstanceType::CYLINDER_VOLUMETRIC][mat_variant]);
CreateMMI(InstanceType::CYLINDER_AB_VOLUMETRIC, NAMEOF(mmi_cylinders_volumetric), meshes[(int)InstanceType::CYLINDER_AB_VOLUMETRIC][mat_variant]);
CreateMMI(InstanceType::LINE_VOLUMETRIC, meshes[(int)InstanceType::LINE_VOLUMETRIC][mat_variant]);
CreateMMI(InstanceType::CUBE_VOLUMETRIC, meshes[(int)InstanceType::CUBE_VOLUMETRIC][mat_variant]);
CreateMMI(InstanceType::CUBE_CENTERED_VOLUMETRIC, meshes[(int)InstanceType::CUBE_CENTERED_VOLUMETRIC][mat_variant]);
CreateMMI(InstanceType::ARROWHEAD_VOLUMETRIC, meshes[(int)InstanceType::ARROWHEAD_VOLUMETRIC][mat_variant]);
CreateMMI(InstanceType::POSITION_VOLUMETRIC, meshes[(int)InstanceType::POSITION_VOLUMETRIC][mat_variant]);
CreateMMI(InstanceType::SPHERE_VOLUMETRIC, meshes[(int)InstanceType::SPHERE_VOLUMETRIC][mat_variant]);
CreateMMI(InstanceType::SPHERE_HD_VOLUMETRIC, meshes[(int)InstanceType::SPHERE_HD_VOLUMETRIC][mat_variant]);
CreateMMI(InstanceType::CYLINDER_VOLUMETRIC, meshes[(int)InstanceType::CYLINDER_VOLUMETRIC][mat_variant]);
CreateMMI(InstanceType::CYLINDER_AB_VOLUMETRIC, meshes[(int)InstanceType::CYLINDER_AB_VOLUMETRIC][mat_variant]);

// SOLID

CreateMMI(InstanceType::BILLBOARD_SQUARE, NAMEOF(mmi_billboard_squares), meshes[(int)InstanceType::BILLBOARD_SQUARE][mat_variant]);
CreateMMI(InstanceType::PLANE, NAMEOF(mmi_planes), meshes[(int)InstanceType::PLANE][mat_variant]);
CreateMMI(InstanceType::BILLBOARD_SQUARE, meshes[(int)InstanceType::BILLBOARD_SQUARE][mat_variant]);
CreateMMI(InstanceType::PLANE, meshes[(int)InstanceType::PLANE][mat_variant]);

set_render_layer_mask(1);
}
Expand All @@ -90,7 +90,7 @@ bool DebugGeometryContainer::is_no_depth_test() const {
return no_depth_test;
}

void DebugGeometryContainer::CreateMMI(InstanceType p_type, const String &p_name, Ref<ArrayMesh> p_mesh) {
void DebugGeometryContainer::CreateMMI(InstanceType p_type, Ref<ArrayMesh> p_mesh) {
ZoneScoped;
RenderingServer *rs = RenderingServer::get_singleton();

Expand Down Expand Up @@ -277,7 +277,7 @@ void DebugGeometryContainer::update_geometry(double p_delta) {

// Draw custom sphere for 1 frame
for (auto &i : new_instances) {
cfg->dgcd.viewport = vp;
cfg->dcd.viewport = vp;
Vector3 diag = i.max - i.min;
Vector3 center = i.center;
real_t radius = i.radius;
Expand Down Expand Up @@ -309,7 +309,7 @@ void DebugGeometryContainer::update_geometry(double p_delta) {
Vector3 center = o->bounds.center;
real_t radius = o->bounds.radius;

cfg->dgcd.viewport = vp;
cfg->dcd.viewport = vp;
geometry_pool.add_or_update_instance(
cfg,
InstanceType::CUBE_CENTERED,
Expand Down
2 changes: 1 addition & 1 deletion src/3d/debug_geometry_container.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class DebugGeometryContainer {
bool is_frame_rendered = false;
bool no_depth_test = false;

void CreateMMI(InstanceType p_type, const String &p_name, Ref<ArrayMesh> p_mesh);
void CreateMMI(InstanceType p_type, Ref<ArrayMesh> p_mesh);

public:
DebugGeometryContainer(class DebugDraw3D *p_root, bool p_no_depth_test);
Expand Down
124 changes: 45 additions & 79 deletions src/3d/geometry_generators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,43 +20,31 @@ const std::array<Vector3, 8> GeometryGenerator::CenteredCubeVertexes{
};

const std::array<Vector3, 8> GeometryGenerator::CubeVertexes{
Vector3(0, 0, 0),
Vector3(1, 0, 0),
Vector3(1, 0, 1),
Vector3(0, 0, 1),
Vector3(0, 1, 0),
Vector3(1, 1, 0),
Vector3(1, 1, 1),
Vector3(0, 1, 1)
Vector3(0, 0, 0), // 0
Vector3(1, 0, 0), // 1
Vector3(1, 0, 1), // 2
Vector3(0, 0, 1), // 3
Vector3(0, 1, 0), // 4
Vector3(1, 1, 0), // 5
Vector3(1, 1, 1), // 6
Vector3(0, 1, 1) // 7
};

const std::array<int, 24> GeometryGenerator::CubeIndexes{
0,
1,
1,
2,
2,
3,
3,
0,

4,
5,
5,
6,
6,
7,
7,
4,

0,
4,
1,
5,
2,
6,
3,
7,
0, 1,
1, 2,
2, 3,
3, 0,

4, 5,
5, 6,
6, 7,
7, 4,

0, 4,
1, 5,
2, 6,
3, 7
};

const std::array<int, 36> GeometryGenerator::CubeWithDiagonalsIndexes{
Expand Down Expand Up @@ -112,40 +100,27 @@ const std::array<Vector3, 6> GeometryGenerator::ArrowheadVertexes{
};

const std::array<int, 18> GeometryGenerator::ArrowheadIndexes{
0,
1,
0,
2,
0,
3,
0,
4,
0, 1,
0, 2,
0, 3,
0, 4,
// Center line
5,
0,
5, 0,
// Cross
// 1, 2,
// 3, 4,
// Or Cross to center
5,
1,
5,
2,
5,
3,
5,
4,
5, 1,
5, 2,
5, 3,
5, 4
};

const std::array<int, 18> GeometryGenerator::ArrowheadIndexesSimplified{
0,
1,
0,
2,
0,
3,
0,
4,
const std::array<int, 8> GeometryGenerator::ArrowheadIndexesSimplified{
0, 1,
0, 2,
0, 3,
0, 4
};

const std::array<Vector3, 4> GeometryGenerator::CenteredSquareVertexes{
Expand All @@ -156,21 +131,15 @@ const std::array<Vector3, 4> GeometryGenerator::CenteredSquareVertexes{
};

const std::array<int, 6> GeometryGenerator::SquareBackwardsIndexes{
0,
1,
2,
2,
3,
0,
0, 1,
2, 2,
3, 0
};

const std::array<int, 6> GeometryGenerator::SquareIndexes{
0,
2,
1,
2,
0,
3,
0, 2,
1, 2,
0, 3
};

const std::array<Vector3, 6> GeometryGenerator::PositionVertexes{
Expand All @@ -183,12 +152,9 @@ const std::array<Vector3, 6> GeometryGenerator::PositionVertexes{
};

const std::array<int, 6> GeometryGenerator::PositionIndexes{
0,
1,
2,
3,
4,
5,
0, 1,
2, 3,
4, 5
};

#pragma endregion
Expand Down
2 changes: 1 addition & 1 deletion src/3d/geometry_generators.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class GeometryGenerator {

const static std::array<Vector3, 6> ArrowheadVertexes;
const static std::array<int, 18> ArrowheadIndexes;
const static std::array<int, 18> ArrowheadIndexesSimplified;
const static std::array<int, 8> ArrowheadIndexesSimplified;

const static std::array<Vector3, 4> CenteredSquareVertexes;
const static std::array<int, 6> SquareBackwardsIndexes;
Expand Down
8 changes: 4 additions & 4 deletions src/3d/render_instances.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -469,9 +469,9 @@ void GeometryPool::add_or_update_instance(const std::shared_ptr<DebugDraw3DScope

void GeometryPool::add_or_update_instance(const std::shared_ptr<DebugDraw3DScopeConfig::Data> &p_cfg, InstanceType p_type, const real_t &p_exp_time, const ProcessType &p_proc, const Transform3D &p_transform, const Color &p_col, const SphereBounds &p_bounds, const Color *p_custom_col) {
ZoneScoped;
auto &proc = pools[p_cfg->dgcd.viewport][(int)p_proc];
auto &proc = pools[p_cfg->dcd.viewport][(int)p_proc];
DelayedRendererInstance *inst = proc.instances[(int)p_type].get(p_exp_time > 0);
viewport_ids[p_cfg->dgcd.viewport] = p_cfg->dgcd.viewport->get_instance_id();
viewport_ids[p_cfg->dcd.viewport] = p_cfg->dcd.viewport->get_instance_id();

SphereBounds thick_sphere = p_bounds;
thick_sphere.radius += p_cfg->thickness * 0.5f;
Expand All @@ -485,9 +485,9 @@ void GeometryPool::add_or_update_instance(const std::shared_ptr<DebugDraw3DScope

void GeometryPool::add_or_update_line(const std::shared_ptr<DebugDraw3DScopeConfig::Data> &p_cfg, const real_t &p_exp_time, const ProcessType &p_proc, std::unique_ptr<Vector3[]> p_lines, const size_t p_line_count, const Color &p_col) {
ZoneScoped;
auto &proc = pools[p_cfg->dgcd.viewport][(int)p_proc];
auto &proc = pools[p_cfg->dcd.viewport][(int)p_proc];
DelayedRendererLine *inst = proc.lines.get(p_exp_time > 0);
viewport_ids[p_cfg->dgcd.viewport] = p_cfg->dgcd.viewport->get_instance_id();
viewport_ids[p_cfg->dcd.viewport] = p_cfg->dcd.viewport->get_instance_id();

inst->lines = std::move(p_lines);
inst->lines_count = p_line_count;
Expand Down

0 comments on commit 0cc3998

Please sign in to comment.