summaryrefslogtreecommitdiffstats
path: root/scene/3d/baked_lightmap.cpp
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2020-05-14 13:23:58 +0200
committerRémi Verschelde <rverschelde@gmail.com>2020-05-14 16:54:55 +0200
commit0be6d925dc3c6413bce7a3ccb49631b8e4a6e67a (patch)
treea27e497da7104dd0a64f98a04fa3067668735e91 /scene/3d/baked_lightmap.cpp
parent710b34b70227becdc652b4ae027fe0ac47409642 (diff)
downloadredot-engine-0be6d925dc3c6413bce7a3ccb49631b8e4a6e67a.tar.gz
Style: clang-format: Disable KeepEmptyLinesAtTheStartOfBlocks
Which means that reduz' beloved style which we all became used to will now be changed automatically to remove the first empty line. This makes us lean closer to 1TBS (the one true brace style) instead of hybridating it with some Allman-inspired spacing. There's still the case of braces around single-statement blocks that needs to be addressed (but clang-format can't help with that, but clang-tidy may if we agree about it). Part of #33027.
Diffstat (limited to 'scene/3d/baked_lightmap.cpp')
-rw-r--r--scene/3d/baked_lightmap.cpp49
1 files changed, 0 insertions, 49 deletions
diff --git a/scene/3d/baked_lightmap.cpp b/scene/3d/baked_lightmap.cpp
index 82a9a1e589..8838295e93 100644
--- a/scene/3d/baked_lightmap.cpp
+++ b/scene/3d/baked_lightmap.cpp
@@ -41,7 +41,6 @@
#include "lightmap_probe.h"
void BakedLightmapData::add_user(const NodePath &p_path, const Rect2 &p_uv_scale, int p_slice_index, int32_t p_sub_instance) {
-
User user;
user.path = p_path;
user.uv_scale = p_uv_scale;
@@ -51,29 +50,24 @@ void BakedLightmapData::add_user(const NodePath &p_path, const Rect2 &p_uv_scale
}
int BakedLightmapData::get_user_count() const {
-
return users.size();
}
NodePath BakedLightmapData::get_user_path(int p_user) const {
-
ERR_FAIL_INDEX_V(p_user, users.size(), NodePath());
return users[p_user].path;
}
int32_t BakedLightmapData::get_user_sub_instance(int p_user) const {
-
ERR_FAIL_INDEX_V(p_user, users.size(), -1);
return users[p_user].sub_instance;
}
Rect2 BakedLightmapData::get_user_lightmap_uv_scale(int p_user) const {
-
ERR_FAIL_INDEX_V(p_user, users.size(), Rect2());
return users[p_user].uv_scale;
}
int BakedLightmapData::get_user_lightmap_slice_index(int p_user) const {
-
ERR_FAIL_INDEX_V(p_user, users.size(), -1);
return users[p_user].slice_index;
}
@@ -83,7 +77,6 @@ void BakedLightmapData::clear_users() {
}
void BakedLightmapData::_set_user_data(const Array &p_data) {
-
ERR_FAIL_COND((p_data.size() % 4) != 0);
for (int i = 0; i < p_data.size(); i += 4) {
@@ -92,7 +85,6 @@ void BakedLightmapData::_set_user_data(const Array &p_data) {
}
Array BakedLightmapData::_get_user_data() const {
-
Array ret;
for (int i = 0; i < users.size(); i++) {
ret.push_back(users[i].path);
@@ -190,7 +182,6 @@ Dictionary BakedLightmapData::_get_probe_data() const {
return d;
}
void BakedLightmapData::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("_set_user_data", "data"), &BakedLightmapData::_set_user_data);
ClassDB::bind_method(D_METHOD("_get_user_data"), &BakedLightmapData::_get_user_data);
@@ -215,28 +206,23 @@ void BakedLightmapData::_bind_methods() {
}
BakedLightmapData::BakedLightmapData() {
-
lightmap = RS::get_singleton()->lightmap_create();
}
BakedLightmapData::~BakedLightmapData() {
-
RS::get_singleton()->free(lightmap);
}
///////////////////////////
void BakedLightmap::_find_meshes_and_lights(Node *p_at_node, Vector<MeshesFound> &meshes, Vector<LightsFound> &lights, Vector<Vector3> &probes) {
-
MeshInstance3D *mi = Object::cast_to<MeshInstance3D>(p_at_node);
if (mi && mi->get_gi_mode() == GeometryInstance3D::GI_MODE_BAKED && mi->is_visible_in_tree()) {
Ref<Mesh> mesh = mi->get_mesh();
if (mesh.is_valid()) {
-
bool all_have_uv2_and_normal = true;
bool surfaces_found = false;
for (int i = 0; i < mesh->get_surface_count(); i++) {
-
if (mesh->surface_get_primitive_type(i) != Mesh::PRIMITIVE_TRIANGLES) {
continue;
}
@@ -284,7 +270,6 @@ void BakedLightmap::_find_meshes_and_lights(Node *p_at_node, Vector<MeshesFound>
if (bmeshes.size() && (bmeshes.size() & 1) == 0) {
Transform xf = get_global_transform().affine_inverse() * s->get_global_transform();
for (int i = 0; i < bmeshes.size(); i += 2) {
-
Ref<Mesh> mesh = bmeshes[i];
if (!mesh.is_valid())
continue;
@@ -306,7 +291,6 @@ void BakedLightmap::_find_meshes_and_lights(Node *p_at_node, Vector<MeshesFound>
Light3D *light = Object::cast_to<Light3D>(p_at_node);
if (light && light->get_bake_mode() != Light3D::BAKE_DISABLED) {
-
LightsFound lf;
lf.xform = get_global_transform().affine_inverse() * light->get_global_transform();
lf.light = light;
@@ -321,7 +305,6 @@ void BakedLightmap::_find_meshes_and_lights(Node *p_at_node, Vector<MeshesFound>
}
for (int i = 0; i < p_at_node->get_child_count(); i++) {
-
Node *child = p_at_node->get_child(i);
if (!child->get_owner())
continue; //maybe a helper
@@ -331,7 +314,6 @@ void BakedLightmap::_find_meshes_and_lights(Node *p_at_node, Vector<MeshesFound>
}
int BakedLightmap::_bsp_get_simplex_side(const Vector<Vector3> &p_points, const LocalVector<BSPSimplex> &p_simplices, const Plane &p_plane, uint32_t p_simplex) const {
-
int over = 0;
int under = 0;
int coplanar = 0;
@@ -360,7 +342,6 @@ int BakedLightmap::_bsp_get_simplex_side(const Vector<Vector3> &p_points, const
//#define DEBUG_BSP
int32_t BakedLightmap::_compute_bsp_tree(const Vector<Vector3> &p_points, const LocalVector<Plane> &p_planes, LocalVector<int32_t> &planes_tested, const LocalVector<BSPSimplex> &p_simplices, const LocalVector<int32_t> &p_simplex_indices, LocalVector<BSPNode> &bsp_nodes) {
-
//if we reach here, it means there is more than one simplex
int32_t node_index = (int32_t)bsp_nodes.size();
bsp_nodes.push_back(BSPNode());
@@ -427,7 +408,6 @@ int32_t BakedLightmap::_compute_bsp_tree(const Vector<Vector3> &p_points, const
//score *= Math::sqrt(float(over_count + under_count) / p_simplex_indices.size()); //also multiply score
if (score > best_plane_score) {
-
best_plane = plane;
best_plane_score = score;
}
@@ -439,7 +419,6 @@ int32_t BakedLightmap::_compute_bsp_tree(const Vector<Vector3> &p_points, const
//split again, but add to list
for (uint32_t i = 0; i < p_simplex_indices.size(); i++) {
-
uint32_t index = p_simplex_indices[i];
int side = _bsp_get_simplex_side(p_points, p_simplices, best_plane, index);
@@ -478,7 +457,6 @@ int32_t BakedLightmap::_compute_bsp_tree(const Vector<Vector3> &p_points, const
for (uint32_t i = 0; i < p_simplex_indices.size(); i++) {
AABB bounds;
for (uint32_t j = 0; j < 4; j++) {
-
Vector3 p = p_points[p_simplices[p_simplex_indices[i]].vertices[j]];
if (j == 0) {
bounds.position = p;
@@ -549,7 +527,6 @@ int32_t BakedLightmap::_compute_bsp_tree(const Vector<Vector3> &p_points, const
}
bool BakedLightmap::_lightmap_bake_step_function(float p_completion, const String &p_text, void *ud, bool p_refresh) {
-
BakeStepUD *bsud = (BakeStepUD *)ud;
bool ret = false;
if (bsud->func) {
@@ -559,7 +536,6 @@ bool BakedLightmap::_lightmap_bake_step_function(float p_completion, const Strin
}
void BakedLightmap::_plot_triangle_into_octree(GenProbesOctree *p_cell, float p_cell_size, const Vector3 *p_triangle) {
-
for (int i = 0; i < 8; i++) {
Vector3i pos = p_cell->offset;
uint32_t half_size = p_cell->size / 2;
@@ -594,9 +570,7 @@ void BakedLightmap::_plot_triangle_into_octree(GenProbesOctree *p_cell, float p_
}
}
void BakedLightmap::_gen_new_positions_from_octree(const GenProbesOctree *p_cell, float p_cell_size, const Vector<Vector3> &probe_positions, LocalVector<Vector3> &new_probe_positions, HashMap<Vector3i, bool, Vector3iHash> &positions_used, const AABB &p_bounds) {
-
for (int i = 0; i < 8; i++) {
-
Vector3i pos = p_cell->offset;
if (i & 1) {
pos.x += p_cell->size;
@@ -616,7 +590,6 @@ void BakedLightmap::_gen_new_positions_from_octree(const GenProbesOctree *p_cell
const Vector3 *pp = probe_positions.ptr();
bool exists = false;
for (int j = 0; j < ppcount; j++) {
-
if (pp[j].distance_to(real_pos) < CMP_EPSILON) {
exists = true;
break;
@@ -636,13 +609,11 @@ void BakedLightmap::_gen_new_positions_from_octree(const GenProbesOctree *p_cell
}
}
BakedLightmap::BakeError BakedLightmap::bake(Node *p_from_node, String p_image_data_path, Lightmapper::BakeStepFunc p_bake_step, void *p_bake_userdata) {
-
if (p_image_data_path == "" && (get_light_data().is_null() || !get_light_data()->get_path().is_resource_file())) {
return BAKE_ERROR_NO_SAVE_PATH;
}
if (p_image_data_path == "") {
-
if (get_light_data().is_null()) {
return BAKE_ERROR_NO_SAVE_PATH;
}
@@ -681,7 +652,6 @@ BakedLightmap::BakeError BakedLightmap::bake(Node *p_from_node, String p_image_d
//get the base material textures, help compute altlas size and bounds
for (int m_i = 0; m_i < meshes_found.size(); m_i++) {
-
if (p_bake_step) {
float p = (float)(m_i) / meshes_found.size();
p_bake_step(p * 0.1, vformat(TTR("Preparing geometry %d/%d"), m_i, meshes_found.size()), p_bake_userdata, false);
@@ -718,7 +688,6 @@ BakedLightmap::BakeError BakedLightmap::bake(Node *p_from_node, String p_image_d
}
{
-
if (albedo->get_format() != Image::FORMAT_RGBA8) {
albedo->convert(Image::FORMAT_RGBA8);
}
@@ -779,7 +748,6 @@ BakedLightmap::BakeError BakedLightmap::bake(Node *p_from_node, String p_image_d
const int *ir = nullptr;
if (index.size()) {
-
facecount = index.size() / 3;
ir = index.ptr();
} else {
@@ -787,7 +755,6 @@ BakedLightmap::BakeError BakedLightmap::bake(Node *p_from_node, String p_image_d
}
for (int j = 0; j < facecount; j++) {
-
uint32_t vidx[3];
if (ir) {
@@ -893,7 +860,6 @@ BakedLightmap::BakeError BakedLightmap::bake(Node *p_from_node, String p_image_d
}
//skip first level, since probes are always added at bounds endpoints anyway (code above this)
for (int i = 0; i < 8; i++) {
-
if (octree.children[i]) {
_gen_new_positions_from_octree(octree.children[i], subdiv_cell_size, probes_found, new_probe_positions, positions_used, bounds);
}
@@ -910,7 +876,6 @@ BakedLightmap::BakeError BakedLightmap::bake(Node *p_from_node, String p_image_d
}
{
-
for (int i = 0; i < mesh_data.size(); i++) {
lightmapper->add_mesh(mesh_data[i]);
}
@@ -995,7 +960,6 @@ BakedLightmap::BakeError BakedLightmap::bake(Node *p_from_node, String p_image_d
Ref<TextureLayered> texture;
{
-
Vector<Ref<Image>> images;
for (int i = 0; i < lightmapper->get_bake_texture_count(); i++) {
images.push_back(lightmapper->get_bake_texture(i));
@@ -1016,7 +980,6 @@ BakedLightmap::BakeError BakedLightmap::bake(Node *p_from_node, String p_image_d
config.instance();
if (FileAccess::exists(base_path + ".import")) {
-
config->load(base_path + ".import");
}
@@ -1095,7 +1058,6 @@ BakedLightmap::BakeError BakedLightmap::bake(Node *p_from_node, String p_image_d
PackedInt32Array tetrahedrons;
for (int i = 0; i < solved_simplices.size(); i++) {
-
//Prepare a special representation of the simplex, which uses a BSP Tree
BSPSimplex bsp_simplex;
for (int j = 0; j < 4; j++) {
@@ -1117,7 +1079,6 @@ BakedLightmap::BakeError BakedLightmap::bake(Node *p_from_node, String p_image_d
Plane p(a, b, c);
int plane_index = -1;
for (uint32_t k = 0; k < bsp_planes.size(); k++) {
-
if (bsp_planes[k].is_equal_approx_any_side(p)) {
plane_index = k;
break;
@@ -1218,14 +1179,12 @@ BakedLightmap::BakeError BakedLightmap::bake(Node *p_from_node, String p_image_d
void BakedLightmap::_notification(int p_what) {
if (p_what == NOTIFICATION_POST_ENTER_TREE) {
-
if (light_data.is_valid()) {
_assign_lightmaps();
}
}
if (p_what == NOTIFICATION_EXIT_TREE) {
-
if (light_data.is_valid()) {
_clear_lightmaps();
}
@@ -1233,11 +1192,9 @@ void BakedLightmap::_notification(int p_what) {
}
void BakedLightmap::_assign_lightmaps() {
-
ERR_FAIL_COND(!light_data.is_valid());
for (int i = 0; i < light_data->get_user_count(); i++) {
-
Node *node = get_node(light_data->get_user_path(i));
int instance_idx = light_data->get_user_sub_instance(i);
if (instance_idx >= 0) {
@@ -1272,7 +1229,6 @@ void BakedLightmap::_clear_lightmaps() {
}
void BakedLightmap::set_light_data(const Ref<BakedLightmapData> &p_data) {
-
if (light_data.is_valid()) {
if (is_inside_tree()) {
_clear_lightmaps();
@@ -1292,7 +1248,6 @@ void BakedLightmap::set_light_data(const Ref<BakedLightmapData> &p_data) {
}
Ref<BakedLightmapData> BakedLightmap::get_light_data() const {
-
return light_data;
}
@@ -1312,12 +1267,10 @@ Vector<Face3> BakedLightmap::get_faces(uint32_t p_usage_flags) const {
}
void BakedLightmap::set_use_denoiser(bool p_enable) {
-
use_denoiser = p_enable;
}
bool BakedLightmap::is_using_denoiser() const {
-
return use_denoiser;
}
@@ -1415,7 +1368,6 @@ void BakedLightmap::_validate_property(PropertyInfo &property) const {
}
void BakedLightmap::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("set_light_data", "data"), &BakedLightmap::set_light_data);
ClassDB::bind_method(D_METHOD("get_light_data"), &BakedLightmap::get_light_data);
@@ -1501,7 +1453,6 @@ void BakedLightmap::_bind_methods() {
}
BakedLightmap::BakedLightmap() {
-
environment_mode = ENVIRONMENT_MODE_DISABLED;
environment_custom_color = Color(0.2, 0.7, 1.0);
environment_custom_energy = 1.0;