2018-01-04 23:50:27 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* baked_lightmap.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/*************************************************************************/
|
2020-01-01 10:16:22 +00:00
|
|
|
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
|
2018-01-04 23:50:27 +00:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
|
|
|
|
2019-10-03 20:39:08 +00:00
|
|
|
#if 0
|
2017-12-14 11:59:46 +00:00
|
|
|
#include "baked_lightmap.h"
|
2018-10-05 02:00:02 +00:00
|
|
|
#include "core/io/config_file.h"
|
2018-09-11 16:13:45 +00:00
|
|
|
#include "core/io/resource_saver.h"
|
|
|
|
#include "core/os/dir_access.h"
|
|
|
|
#include "core/os/os.h"
|
2017-12-14 11:59:46 +00:00
|
|
|
#include "voxel_light_baker.h"
|
|
|
|
|
|
|
|
void BakedLightmapData::set_bounds(const AABB &p_bounds) {
|
|
|
|
|
|
|
|
bounds = p_bounds;
|
2020-03-27 18:21:27 +00:00
|
|
|
RS::get_singleton()->lightmap_capture_set_bounds(baked_light, p_bounds);
|
2017-12-14 11:59:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AABB BakedLightmapData::get_bounds() const {
|
|
|
|
|
|
|
|
return bounds;
|
|
|
|
}
|
|
|
|
|
2020-02-17 21:06:54 +00:00
|
|
|
void BakedLightmapData::set_octree(const Vector<uint8_t> &p_octree) {
|
2017-12-14 11:59:46 +00:00
|
|
|
|
2020-03-27 18:21:27 +00:00
|
|
|
RS::get_singleton()->lightmap_capture_set_octree(baked_light, p_octree);
|
2017-12-14 11:59:46 +00:00
|
|
|
}
|
|
|
|
|
2020-02-17 21:06:54 +00:00
|
|
|
Vector<uint8_t> BakedLightmapData::get_octree() const {
|
2017-12-14 11:59:46 +00:00
|
|
|
|
2020-03-27 18:21:27 +00:00
|
|
|
return RS::get_singleton()->lightmap_capture_get_octree(baked_light);
|
2017-12-14 11:59:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void BakedLightmapData::set_cell_space_transform(const Transform &p_xform) {
|
|
|
|
|
|
|
|
cell_space_xform = p_xform;
|
2020-03-27 18:21:27 +00:00
|
|
|
RS::get_singleton()->lightmap_capture_set_octree_cell_transform(baked_light, p_xform);
|
2017-12-14 11:59:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Transform BakedLightmapData::get_cell_space_transform() const {
|
|
|
|
return cell_space_xform;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BakedLightmapData::set_cell_subdiv(int p_cell_subdiv) {
|
|
|
|
cell_subdiv = p_cell_subdiv;
|
2020-03-27 18:21:27 +00:00
|
|
|
RS::get_singleton()->lightmap_capture_set_octree_cell_subdiv(baked_light, p_cell_subdiv);
|
2017-12-14 11:59:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int BakedLightmapData::get_cell_subdiv() const {
|
|
|
|
return cell_subdiv;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BakedLightmapData::set_energy(float p_energy) {
|
|
|
|
|
|
|
|
energy = p_energy;
|
2020-03-27 18:21:27 +00:00
|
|
|
RS::get_singleton()->lightmap_capture_set_energy(baked_light, energy);
|
2017-12-14 11:59:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
float BakedLightmapData::get_energy() const {
|
|
|
|
|
|
|
|
return energy;
|
|
|
|
}
|
|
|
|
|
2019-06-11 18:43:37 +00:00
|
|
|
void BakedLightmapData::add_user(const NodePath &p_path, const Ref<Texture2D> &p_lightmap, int p_instance) {
|
2017-12-14 11:59:46 +00:00
|
|
|
|
2019-09-25 08:28:50 +00:00
|
|
|
ERR_FAIL_COND_MSG(p_lightmap.is_null(), "It's not a reference to a valid Texture object.");
|
2017-12-14 11:59:46 +00:00
|
|
|
User user;
|
|
|
|
user.path = p_path;
|
|
|
|
user.lightmap = p_lightmap;
|
2017-12-18 03:34:48 +00:00
|
|
|
user.instance_index = p_instance;
|
2017-12-14 11:59:46 +00:00
|
|
|
users.push_back(user);
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2019-06-11 18:43:37 +00:00
|
|
|
Ref<Texture2D> BakedLightmapData::get_user_lightmap(int p_user) const {
|
2017-12-14 11:59:46 +00:00
|
|
|
|
2019-06-11 18:43:37 +00:00
|
|
|
ERR_FAIL_INDEX_V(p_user, users.size(), Ref<Texture2D>());
|
2017-12-14 11:59:46 +00:00
|
|
|
return users[p_user].lightmap;
|
|
|
|
}
|
|
|
|
|
2017-12-18 03:34:48 +00:00
|
|
|
int BakedLightmapData::get_user_instance(int p_user) const {
|
|
|
|
|
|
|
|
ERR_FAIL_INDEX_V(p_user, users.size(), -1);
|
|
|
|
return users[p_user].instance_index;
|
|
|
|
}
|
|
|
|
|
2017-12-14 11:59:46 +00:00
|
|
|
void BakedLightmapData::clear_users() {
|
|
|
|
users.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void BakedLightmapData::_set_user_data(const Array &p_data) {
|
|
|
|
|
2017-12-18 03:34:48 +00:00
|
|
|
ERR_FAIL_COND((p_data.size() % 3) != 0);
|
2017-12-14 11:59:46 +00:00
|
|
|
|
2017-12-18 03:34:48 +00:00
|
|
|
for (int i = 0; i < p_data.size(); i += 3) {
|
|
|
|
add_user(p_data[i], p_data[i + 1], p_data[i + 2]);
|
2017-12-14 11:59:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Array BakedLightmapData::_get_user_data() const {
|
|
|
|
|
|
|
|
Array ret;
|
|
|
|
for (int i = 0; i < users.size(); i++) {
|
|
|
|
ret.push_back(users[i].path);
|
|
|
|
ret.push_back(users[i].lightmap);
|
2017-12-18 03:34:48 +00:00
|
|
|
ret.push_back(users[i].instance_index);
|
2017-12-14 11:59:46 +00:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
RID BakedLightmapData::get_rid() const {
|
|
|
|
return baked_light;
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("set_bounds", "bounds"), &BakedLightmapData::set_bounds);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_bounds"), &BakedLightmapData::get_bounds);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("set_cell_space_transform", "xform"), &BakedLightmapData::set_cell_space_transform);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_cell_space_transform"), &BakedLightmapData::get_cell_space_transform);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("set_cell_subdiv", "cell_subdiv"), &BakedLightmapData::set_cell_subdiv);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_cell_subdiv"), &BakedLightmapData::get_cell_subdiv);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("set_octree", "octree"), &BakedLightmapData::set_octree);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_octree"), &BakedLightmapData::get_octree);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("set_energy", "energy"), &BakedLightmapData::set_energy);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_energy"), &BakedLightmapData::get_energy);
|
|
|
|
|
2017-12-18 07:13:58 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("add_user", "path", "lightmap", "instance"), &BakedLightmapData::add_user);
|
2017-12-14 11:59:46 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("get_user_count"), &BakedLightmapData::get_user_count);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_user_path", "user_idx"), &BakedLightmapData::get_user_path);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_user_lightmap", "user_idx"), &BakedLightmapData::get_user_lightmap);
|
|
|
|
ClassDB::bind_method(D_METHOD("clear_users"), &BakedLightmapData::clear_users);
|
|
|
|
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::AABB, "bounds", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_bounds", "get_bounds");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM, "cell_space_transform", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_cell_space_transform", "get_cell_space_transform");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "cell_subdiv", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_cell_subdiv", "get_cell_subdiv");
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "energy", PROPERTY_HINT_RANGE, "0,16,0.01,or_greater"), "set_energy", "get_energy");
|
2020-02-17 21:06:54 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::PACKED_BYTE_ARRAY, "octree", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_octree", "get_octree");
|
2018-01-11 22:35:12 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "user_data", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL), "_set_user_data", "_get_user_data");
|
2017-12-14 11:59:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BakedLightmapData::BakedLightmapData() {
|
|
|
|
|
2020-03-27 18:21:27 +00:00
|
|
|
baked_light = RS::get_singleton()->lightmap_capture_create();
|
2017-12-14 11:59:46 +00:00
|
|
|
energy = 1;
|
|
|
|
cell_subdiv = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
BakedLightmapData::~BakedLightmapData() {
|
|
|
|
|
2020-03-27 18:21:27 +00:00
|
|
|
RS::get_singleton()->free(baked_light);
|
2017-12-14 11:59:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////
|
|
|
|
|
2020-04-01 23:20:12 +00:00
|
|
|
BakedLightmap::BakeBeginFunc BakedLightmap::bake_begin_function = nullptr;
|
|
|
|
BakedLightmap::BakeStepFunc BakedLightmap::bake_step_function = nullptr;
|
|
|
|
BakedLightmap::BakeEndFunc BakedLightmap::bake_end_function = nullptr;
|
2017-12-14 11:59:46 +00:00
|
|
|
|
2017-12-21 14:03:17 +00:00
|
|
|
void BakedLightmap::set_bake_cell_size(float p_cell_size) {
|
|
|
|
bake_cell_size = p_cell_size;
|
2017-12-14 11:59:46 +00:00
|
|
|
}
|
|
|
|
|
2017-12-21 14:03:17 +00:00
|
|
|
float BakedLightmap::get_bake_cell_size() const {
|
|
|
|
return bake_cell_size;
|
2017-12-14 11:59:46 +00:00
|
|
|
}
|
|
|
|
|
2017-12-21 14:03:17 +00:00
|
|
|
void BakedLightmap::set_capture_cell_size(float p_cell_size) {
|
|
|
|
capture_cell_size = p_cell_size;
|
2017-12-14 11:59:46 +00:00
|
|
|
}
|
|
|
|
|
2017-12-21 14:03:17 +00:00
|
|
|
float BakedLightmap::get_capture_cell_size() const {
|
|
|
|
return capture_cell_size;
|
2017-12-14 11:59:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void BakedLightmap::set_extents(const Vector3 &p_extents) {
|
|
|
|
extents = p_extents;
|
2017-12-15 19:34:02 +00:00
|
|
|
update_gizmo();
|
2019-07-10 18:06:59 +00:00
|
|
|
_change_notify("bake_extents");
|
2017-12-14 11:59:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Vector3 BakedLightmap::get_extents() const {
|
|
|
|
return extents;
|
|
|
|
}
|
|
|
|
|
2019-06-22 15:27:09 +00:00
|
|
|
void BakedLightmap::set_bake_default_texels_per_unit(const float &p_bake_texels_per_unit) {
|
|
|
|
bake_default_texels_per_unit = p_bake_texels_per_unit;
|
|
|
|
update_gizmo();
|
|
|
|
}
|
|
|
|
|
|
|
|
float BakedLightmap::get_bake_default_texels_per_unit() const {
|
|
|
|
return bake_default_texels_per_unit;
|
|
|
|
}
|
|
|
|
|
2017-12-14 11:59:46 +00:00
|
|
|
void BakedLightmap::_find_meshes_and_lights(Node *p_at_node, List<PlotMesh> &plot_meshes, List<PlotLight> &plot_lights) {
|
|
|
|
|
|
|
|
MeshInstance *mi = Object::cast_to<MeshInstance>(p_at_node);
|
|
|
|
if (mi && mi->get_flag(GeometryInstance::FLAG_USE_BAKED_LIGHT) && mi->is_visible_in_tree()) {
|
|
|
|
Ref<Mesh> mesh = mi->get_mesh();
|
|
|
|
if (mesh.is_valid()) {
|
|
|
|
|
|
|
|
bool all_have_uv2 = true;
|
|
|
|
for (int i = 0; i < mesh->get_surface_count(); i++) {
|
|
|
|
if (!(mesh->surface_get_format(i) & Mesh::ARRAY_FORMAT_TEX_UV2)) {
|
|
|
|
all_have_uv2 = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-22 15:27:09 +00:00
|
|
|
if (all_have_uv2) {
|
2017-12-14 11:59:46 +00:00
|
|
|
//READY TO BAKE! size hint could be computed if not found, actually..
|
|
|
|
|
|
|
|
AABB aabb = mesh->get_aabb();
|
|
|
|
|
|
|
|
Transform xf = get_global_transform().affine_inverse() * mi->get_global_transform();
|
|
|
|
|
|
|
|
if (AABB(-extents, extents * 2).intersects(xf.xform(aabb))) {
|
|
|
|
PlotMesh pm;
|
|
|
|
pm.local_xform = xf;
|
|
|
|
pm.mesh = mesh;
|
|
|
|
pm.path = get_path_to(mi);
|
2017-12-18 03:34:48 +00:00
|
|
|
pm.instance_idx = -1;
|
2017-12-14 11:59:46 +00:00
|
|
|
for (int i = 0; i < mesh->get_surface_count(); i++) {
|
|
|
|
pm.instance_materials.push_back(mi->get_surface_material(i));
|
|
|
|
}
|
|
|
|
pm.override_material = mi->get_material_override();
|
|
|
|
plot_meshes.push_back(pm);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-18 03:34:48 +00:00
|
|
|
Spatial *s = Object::cast_to<Spatial>(p_at_node);
|
|
|
|
|
|
|
|
if (!mi && s) {
|
|
|
|
Array meshes = p_at_node->call("get_bake_meshes");
|
|
|
|
if (meshes.size() && (meshes.size() & 1) == 0) {
|
|
|
|
Transform xf = get_global_transform().affine_inverse() * s->get_global_transform();
|
|
|
|
for (int i = 0; i < meshes.size(); i += 2) {
|
|
|
|
PlotMesh pm;
|
|
|
|
Transform mesh_xf = meshes[i + 1];
|
|
|
|
pm.local_xform = xf * mesh_xf;
|
|
|
|
pm.mesh = meshes[i];
|
|
|
|
pm.instance_idx = i / 2;
|
|
|
|
if (!pm.mesh.is_valid())
|
|
|
|
continue;
|
|
|
|
pm.path = get_path_to(s);
|
|
|
|
plot_meshes.push_back(pm);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-14 11:59:46 +00:00
|
|
|
Light *light = Object::cast_to<Light>(p_at_node);
|
|
|
|
|
|
|
|
if (light && light->get_bake_mode() != Light::BAKE_DISABLED) {
|
|
|
|
PlotLight pl;
|
|
|
|
Transform xf = get_global_transform().affine_inverse() * light->get_global_transform();
|
|
|
|
|
|
|
|
pl.local_xform = xf;
|
|
|
|
pl.light = light;
|
|
|
|
plot_lights.push_back(pl);
|
|
|
|
}
|
|
|
|
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
|
|
|
|
|
|
|
|
_find_meshes_and_lights(child, plot_meshes, plot_lights);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BakedLightmap::set_hdr(bool p_enable) {
|
|
|
|
hdr = p_enable;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BakedLightmap::is_hdr() const {
|
|
|
|
return hdr;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BakedLightmap::_bake_time(void *ud, float p_secs, float p_progress) {
|
|
|
|
|
|
|
|
uint64_t time = OS::get_singleton()->get_ticks_usec();
|
|
|
|
BakeTimeData *btd = (BakeTimeData *)ud;
|
|
|
|
|
|
|
|
if (time - btd->last_step > 1000000) {
|
|
|
|
|
|
|
|
int mins_left = p_secs / 60;
|
2017-12-14 14:32:53 +00:00
|
|
|
int secs_left = Math::fmod(p_secs, 60.0f);
|
2017-12-14 11:59:46 +00:00
|
|
|
int percent = p_progress * 100;
|
2018-02-19 14:26:05 +00:00
|
|
|
bool abort = bake_step_function(btd->pass + percent, btd->text + " " + vformat(RTR("%d%%"), percent) + " " + vformat(RTR("(Time Left: %d:%02d s)"), mins_left, secs_left));
|
2017-12-14 11:59:46 +00:00
|
|
|
btd->last_step = time;
|
|
|
|
if (abort)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
BakedLightmap::BakeError BakedLightmap::bake(Node *p_from_node, bool p_create_visual_debug) {
|
|
|
|
|
|
|
|
String save_path;
|
|
|
|
|
|
|
|
if (image_path.begins_with("res://")) {
|
|
|
|
save_path = image_path;
|
|
|
|
} else {
|
|
|
|
if (get_filename() != "") {
|
|
|
|
save_path = get_filename().get_base_dir();
|
|
|
|
} else if (get_owner() && get_owner()->get_filename() != "") {
|
|
|
|
save_path = get_owner()->get_filename().get_base_dir();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (save_path == "") {
|
|
|
|
return BAKE_ERROR_NO_SAVE_PATH;
|
|
|
|
}
|
|
|
|
if (image_path != "") {
|
|
|
|
save_path.plus_file(image_path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
{
|
|
|
|
//check for valid save path
|
|
|
|
DirAccessRef d = DirAccess::open(save_path);
|
|
|
|
if (!d) {
|
2019-11-06 16:03:04 +00:00
|
|
|
ERR_PRINT("Invalid Save Path '" + save_path + "'.");
|
2017-12-14 11:59:46 +00:00
|
|
|
return BAKE_ERROR_NO_SAVE_PATH;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Ref<BakedLightmapData> new_light_data;
|
|
|
|
new_light_data.instance();
|
|
|
|
|
2019-10-03 20:39:08 +00:00
|
|
|
Voxelizer baker;
|
2017-12-14 11:59:46 +00:00
|
|
|
|
2017-12-21 14:03:17 +00:00
|
|
|
int bake_subdiv;
|
|
|
|
int capture_subdiv;
|
|
|
|
AABB bake_bounds;
|
|
|
|
{
|
|
|
|
bake_bounds = AABB(-extents, extents * 2.0);
|
|
|
|
int subdiv = nearest_power_of_2_templated(int(bake_bounds.get_longest_axis_size() / bake_cell_size));
|
2018-10-03 17:57:47 +00:00
|
|
|
bake_bounds.size[bake_bounds.get_longest_axis_index()] = subdiv * bake_cell_size;
|
2017-12-21 14:03:17 +00:00
|
|
|
bake_subdiv = nearest_shift(subdiv) + 1;
|
|
|
|
|
|
|
|
capture_subdiv = bake_subdiv;
|
|
|
|
float css = bake_cell_size;
|
|
|
|
while (css < capture_cell_size && capture_subdiv > 2) {
|
|
|
|
capture_subdiv--;
|
|
|
|
css *= 2.0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
baker.begin_bake(bake_subdiv, bake_bounds);
|
2017-12-14 11:59:46 +00:00
|
|
|
|
|
|
|
List<PlotMesh> mesh_list;
|
|
|
|
List<PlotLight> light_list;
|
|
|
|
|
|
|
|
_find_meshes_and_lights(p_from_node ? p_from_node : get_parent(), mesh_list, light_list);
|
|
|
|
|
|
|
|
if (bake_begin_function) {
|
|
|
|
bake_begin_function(mesh_list.size() + light_list.size() + 1 + mesh_list.size() * 100);
|
|
|
|
}
|
|
|
|
|
|
|
|
int step = 0;
|
|
|
|
|
|
|
|
int pmc = 0;
|
|
|
|
|
|
|
|
for (List<PlotMesh>::Element *E = mesh_list.front(); E; E = E->next()) {
|
|
|
|
|
|
|
|
if (bake_step_function) {
|
|
|
|
bake_step_function(step++, RTR("Plotting Meshes: ") + " (" + itos(pmc + 1) + "/" + itos(mesh_list.size()) + ")");
|
|
|
|
}
|
|
|
|
|
|
|
|
pmc++;
|
|
|
|
baker.plot_mesh(E->get().local_xform, E->get().mesh, E->get().instance_materials, E->get().override_material);
|
|
|
|
}
|
|
|
|
|
|
|
|
pmc = 0;
|
2019-10-03 20:39:08 +00:00
|
|
|
baker.begin_bake_light(Voxelizer::BakeQuality(bake_quality), Voxelizer::BakeMode(bake_mode), propagation, energy);
|
2017-12-14 11:59:46 +00:00
|
|
|
|
|
|
|
for (List<PlotLight>::Element *E = light_list.front(); E; E = E->next()) {
|
|
|
|
|
|
|
|
if (bake_step_function) {
|
|
|
|
bake_step_function(step++, RTR("Plotting Lights:") + " (" + itos(pmc + 1) + "/" + itos(light_list.size()) + ")");
|
|
|
|
}
|
|
|
|
|
|
|
|
pmc++;
|
|
|
|
PlotLight pl = E->get();
|
|
|
|
switch (pl.light->get_light_type()) {
|
2020-03-27 18:21:27 +00:00
|
|
|
case RS::LIGHT_DIRECTIONAL: {
|
2017-12-14 11:59:46 +00:00
|
|
|
baker.plot_light_directional(-pl.local_xform.basis.get_axis(2), pl.light->get_color(), pl.light->get_param(Light::PARAM_ENERGY), pl.light->get_param(Light::PARAM_INDIRECT_ENERGY), pl.light->get_bake_mode() == Light::BAKE_ALL);
|
|
|
|
} break;
|
2020-03-27 18:21:27 +00:00
|
|
|
case RS::LIGHT_OMNI: {
|
2017-12-14 11:59:46 +00:00
|
|
|
baker.plot_light_omni(pl.local_xform.origin, pl.light->get_color(), pl.light->get_param(Light::PARAM_ENERGY), pl.light->get_param(Light::PARAM_INDIRECT_ENERGY), pl.light->get_param(Light::PARAM_RANGE), pl.light->get_param(Light::PARAM_ATTENUATION), pl.light->get_bake_mode() == Light::BAKE_ALL);
|
|
|
|
} break;
|
2020-03-27 18:21:27 +00:00
|
|
|
case RS::LIGHT_SPOT: {
|
2017-12-14 11:59:46 +00:00
|
|
|
baker.plot_light_spot(pl.local_xform.origin, pl.local_xform.basis.get_axis(2), pl.light->get_color(), pl.light->get_param(Light::PARAM_ENERGY), pl.light->get_param(Light::PARAM_INDIRECT_ENERGY), pl.light->get_param(Light::PARAM_RANGE), pl.light->get_param(Light::PARAM_ATTENUATION), pl.light->get_param(Light::PARAM_SPOT_ANGLE), pl.light->get_param(Light::PARAM_SPOT_ATTENUATION), pl.light->get_bake_mode() == Light::BAKE_ALL);
|
|
|
|
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*if (bake_step_function) {
|
|
|
|
bake_step_function(pmc++, RTR("Finishing Plot"));
|
|
|
|
}*/
|
|
|
|
|
|
|
|
baker.end_bake();
|
|
|
|
|
|
|
|
Set<String> used_mesh_names;
|
|
|
|
|
|
|
|
pmc = 0;
|
|
|
|
for (List<PlotMesh>::Element *E = mesh_list.front(); E; E = E->next()) {
|
|
|
|
|
|
|
|
String mesh_name = E->get().mesh->get_name();
|
|
|
|
if (mesh_name == "" || mesh_name.find(":") != -1 || mesh_name.find("/") != -1) {
|
|
|
|
mesh_name = "LightMap";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (used_mesh_names.has(mesh_name)) {
|
|
|
|
int idx = 2;
|
|
|
|
String base = mesh_name;
|
|
|
|
while (true) {
|
|
|
|
mesh_name = base + itos(idx);
|
|
|
|
if (!used_mesh_names.has(mesh_name))
|
|
|
|
break;
|
|
|
|
idx++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
used_mesh_names.insert(mesh_name);
|
|
|
|
|
|
|
|
pmc++;
|
2019-10-03 20:39:08 +00:00
|
|
|
Voxelizer::LightMapData lm;
|
2017-12-14 11:59:46 +00:00
|
|
|
|
|
|
|
Error err;
|
|
|
|
if (bake_step_function) {
|
|
|
|
BakeTimeData btd;
|
|
|
|
btd.text = RTR("Lighting Meshes: ") + mesh_name + " (" + itos(pmc) + "/" + itos(mesh_list.size()) + ")";
|
|
|
|
btd.pass = step;
|
|
|
|
btd.last_step = 0;
|
2019-06-22 15:27:09 +00:00
|
|
|
err = baker.make_lightmap(E->get().local_xform, E->get().mesh, bake_default_texels_per_unit, lm, _bake_time, &btd);
|
2017-12-14 11:59:46 +00:00
|
|
|
if (err != OK) {
|
|
|
|
bake_end_function();
|
|
|
|
if (err == ERR_SKIP)
|
|
|
|
return BAKE_ERROR_USER_ABORTED;
|
|
|
|
return BAKE_ERROR_CANT_CREATE_IMAGE;
|
|
|
|
}
|
|
|
|
step += 100;
|
|
|
|
} else {
|
|
|
|
|
2019-06-22 15:27:09 +00:00
|
|
|
err = baker.make_lightmap(E->get().local_xform, E->get().mesh, bake_default_texels_per_unit, lm);
|
2017-12-14 11:59:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (err == OK) {
|
|
|
|
|
|
|
|
Ref<Image> image;
|
|
|
|
image.instance();
|
|
|
|
|
|
|
|
if (hdr) {
|
|
|
|
|
|
|
|
//just save a regular image
|
2020-02-17 21:06:54 +00:00
|
|
|
Vector<uint8_t> data;
|
2017-12-14 11:59:46 +00:00
|
|
|
int s = lm.light.size();
|
|
|
|
data.resize(lm.light.size() * 2);
|
|
|
|
{
|
|
|
|
|
2020-02-17 21:06:54 +00:00
|
|
|
uint8_t* w = data.ptrw();
|
|
|
|
const float* r = lm.light.ptr();
|
2017-12-14 11:59:46 +00:00
|
|
|
uint16_t *hfw = (uint16_t *)w.ptr();
|
|
|
|
for (int i = 0; i < s; i++) {
|
|
|
|
hfw[i] = Math::make_half_float(r[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
image->create(lm.width, lm.height, false, Image::FORMAT_RGBH, data);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
//just save a regular image
|
2020-02-17 21:06:54 +00:00
|
|
|
Vector<uint8_t> data;
|
2017-12-14 11:59:46 +00:00
|
|
|
int s = lm.light.size();
|
|
|
|
data.resize(lm.light.size());
|
|
|
|
{
|
|
|
|
|
2020-02-17 21:06:54 +00:00
|
|
|
uint8_t* w = data.ptrw();
|
|
|
|
const float* r = lm.light.ptr();
|
2017-12-14 11:59:46 +00:00
|
|
|
for (int i = 0; i < s; i += 3) {
|
|
|
|
Color c(r[i + 0], r[i + 1], r[i + 2]);
|
|
|
|
c = c.to_srgb();
|
|
|
|
w[i + 0] = CLAMP(c.r * 255, 0, 255);
|
|
|
|
w[i + 1] = CLAMP(c.g * 255, 0, 255);
|
|
|
|
w[i + 2] = CLAMP(c.b * 255, 0, 255);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
image->create(lm.width, lm.height, false, Image::FORMAT_RGB8, data);
|
|
|
|
|
|
|
|
//This texture is saved to SRGB for two reasons:
|
|
|
|
// 1) first is so it looks better when doing the LINEAR->SRGB conversion (more accurate)
|
|
|
|
// 2) So it can be used in the GLES2 backend, which does not support linkear workflow
|
|
|
|
}
|
|
|
|
|
2018-10-05 02:00:02 +00:00
|
|
|
String image_path = save_path.plus_file(mesh_name);
|
2019-06-11 18:43:37 +00:00
|
|
|
Ref<Texture2D> texture;
|
2017-12-14 11:59:46 +00:00
|
|
|
|
2018-10-05 02:00:02 +00:00
|
|
|
if (ResourceLoader::import) {
|
|
|
|
|
|
|
|
bool srgb = false;
|
|
|
|
if (false && hdr) {
|
|
|
|
//save hdr
|
|
|
|
} else {
|
|
|
|
image_path += ".png";
|
|
|
|
print_line("image path saving png: " + image_path);
|
|
|
|
image->save_png(image_path);
|
|
|
|
srgb = true;
|
|
|
|
}
|
2017-12-14 11:59:46 +00:00
|
|
|
|
2018-10-05 02:00:02 +00:00
|
|
|
if (!FileAccess::exists(image_path + ".import")) {
|
|
|
|
Ref<ConfigFile> config;
|
|
|
|
config.instance();
|
|
|
|
config->set_value("remap", "importer", "texture");
|
|
|
|
config->set_value("remap", "type", "StreamTexture");
|
|
|
|
config->set_value("params", "compress/mode", 2);
|
|
|
|
config->set_value("params", "detect_3d", false);
|
|
|
|
config->set_value("params", "flags/repeat", false);
|
|
|
|
config->set_value("params", "flags/filter", true);
|
|
|
|
config->set_value("params", "flags/mipmaps", false);
|
|
|
|
config->set_value("params", "flags/srgb", srgb);
|
|
|
|
|
|
|
|
config->save(image_path + ".import");
|
|
|
|
}
|
|
|
|
|
|
|
|
ResourceLoader::import(image_path);
|
|
|
|
texture = ResourceLoader::load(image_path); //if already loaded, it will be updated on refocus?
|
|
|
|
} else {
|
2017-12-14 11:59:46 +00:00
|
|
|
|
2018-10-05 02:00:02 +00:00
|
|
|
image_path += ".text";
|
|
|
|
Ref<ImageTexture> tex;
|
|
|
|
bool set_path = true;
|
|
|
|
if (ResourceCache::has(image_path)) {
|
|
|
|
tex = Ref<Resource>((Resource *)ResourceCache::get(image_path));
|
|
|
|
set_path = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!tex.is_valid()) {
|
|
|
|
tex.instance();
|
|
|
|
}
|
|
|
|
|
2019-06-11 18:43:37 +00:00
|
|
|
tex->create_from_image(image);
|
2018-10-05 02:00:02 +00:00
|
|
|
|
|
|
|
err = ResourceSaver::save(image_path, tex, ResourceSaver::FLAG_CHANGE_PATH);
|
|
|
|
if (set_path) {
|
|
|
|
tex->set_path(image_path);
|
|
|
|
}
|
|
|
|
texture = tex;
|
|
|
|
}
|
2017-12-14 11:59:46 +00:00
|
|
|
if (err != OK) {
|
|
|
|
if (bake_end_function) {
|
|
|
|
bake_end_function();
|
|
|
|
}
|
|
|
|
ERR_FAIL_COND_V(err != OK, BAKE_ERROR_CANT_CREATE_IMAGE);
|
|
|
|
}
|
|
|
|
|
2018-10-05 02:00:02 +00:00
|
|
|
new_light_data->add_user(E->get().path, texture, E->get().instance_idx);
|
2017-12-14 11:59:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AABB bounds = AABB(-extents, extents * 2);
|
2017-12-21 14:03:17 +00:00
|
|
|
new_light_data->set_cell_subdiv(capture_subdiv);
|
2017-12-14 11:59:46 +00:00
|
|
|
new_light_data->set_bounds(bounds);
|
2017-12-21 14:03:17 +00:00
|
|
|
new_light_data->set_octree(baker.create_capture_octree(capture_subdiv));
|
2017-12-14 11:59:46 +00:00
|
|
|
{
|
|
|
|
|
2017-12-21 14:03:17 +00:00
|
|
|
float bake_bound_size = bake_bounds.get_longest_axis_size();
|
2017-12-14 11:59:46 +00:00
|
|
|
Transform to_bounds;
|
2017-12-21 14:03:17 +00:00
|
|
|
to_bounds.basis.scale(Vector3(bake_bound_size, bake_bound_size, bake_bound_size));
|
2017-12-14 11:59:46 +00:00
|
|
|
to_bounds.origin = bounds.position;
|
|
|
|
|
|
|
|
Transform to_grid;
|
2017-12-21 14:03:17 +00:00
|
|
|
to_grid.basis.scale(Vector3(1 << (capture_subdiv - 1), 1 << (capture_subdiv - 1), 1 << (capture_subdiv - 1)));
|
2017-12-14 11:59:46 +00:00
|
|
|
|
|
|
|
Transform to_cell_space = to_grid * to_bounds.affine_inverse();
|
|
|
|
new_light_data->set_cell_space_transform(to_cell_space);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bake_end_function) {
|
|
|
|
bake_end_function();
|
|
|
|
}
|
|
|
|
|
|
|
|
//create the data for visual server
|
|
|
|
|
|
|
|
if (p_create_visual_debug) {
|
|
|
|
MultiMeshInstance *mmi = memnew(MultiMeshInstance);
|
2019-10-03 20:39:08 +00:00
|
|
|
mmi->set_multimesh(baker.create_debug_multimesh(Voxelizer::DEBUG_LIGHT));
|
2017-12-14 11:59:46 +00:00
|
|
|
add_child(mmi);
|
|
|
|
#ifdef TOOLS_ENABLED
|
|
|
|
if (get_tree()->get_edited_scene_root() == this) {
|
|
|
|
mmi->set_owner(this);
|
|
|
|
} else {
|
|
|
|
mmi->set_owner(get_owner());
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
mmi->set_owner(get_owner());
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
set_light_data(new_light_data);
|
|
|
|
|
|
|
|
return BAKE_ERROR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BakedLightmap::_notification(int p_what) {
|
|
|
|
if (p_what == NOTIFICATION_READY) {
|
|
|
|
|
|
|
|
if (light_data.is_valid()) {
|
|
|
|
_assign_lightmaps();
|
|
|
|
}
|
|
|
|
request_ready(); //will need ready again if re-enters tree
|
|
|
|
}
|
|
|
|
|
|
|
|
if (p_what == NOTIFICATION_EXIT_TREE) {
|
|
|
|
|
|
|
|
if (light_data.is_valid()) {
|
|
|
|
_clear_lightmaps();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BakedLightmap::_assign_lightmaps() {
|
|
|
|
|
|
|
|
ERR_FAIL_COND(!light_data.is_valid());
|
|
|
|
|
|
|
|
for (int i = 0; i < light_data->get_user_count(); i++) {
|
2019-06-11 18:43:37 +00:00
|
|
|
Ref<Texture2D> lightmap = light_data->get_user_lightmap(i);
|
2017-12-14 11:59:46 +00:00
|
|
|
ERR_CONTINUE(!lightmap.is_valid());
|
2017-12-18 03:34:48 +00:00
|
|
|
|
|
|
|
Node *node = get_node(light_data->get_user_path(i));
|
|
|
|
int instance_idx = light_data->get_user_instance(i);
|
|
|
|
if (instance_idx >= 0) {
|
|
|
|
RID instance = node->call("get_bake_mesh_instance", instance_idx);
|
|
|
|
if (instance.is_valid()) {
|
2020-03-27 18:21:27 +00:00
|
|
|
RS::get_singleton()->instance_set_use_lightmap(instance, get_instance(), lightmap->get_rid());
|
2017-12-18 03:34:48 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
VisualInstance *vi = Object::cast_to<VisualInstance>(node);
|
|
|
|
ERR_CONTINUE(!vi);
|
2020-03-27 18:21:27 +00:00
|
|
|
RS::get_singleton()->instance_set_use_lightmap(vi->get_instance(), get_instance(), lightmap->get_rid());
|
2017-12-18 03:34:48 +00:00
|
|
|
}
|
2017-12-14 11:59:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BakedLightmap::_clear_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));
|
2017-12-18 03:34:48 +00:00
|
|
|
int instance_idx = light_data->get_user_instance(i);
|
|
|
|
if (instance_idx >= 0) {
|
|
|
|
RID instance = node->call("get_bake_mesh_instance", instance_idx);
|
|
|
|
if (instance.is_valid()) {
|
2020-03-27 18:21:27 +00:00
|
|
|
RS::get_singleton()->instance_set_use_lightmap(instance, get_instance(), RID());
|
2017-12-18 03:34:48 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
VisualInstance *vi = Object::cast_to<VisualInstance>(node);
|
|
|
|
ERR_CONTINUE(!vi);
|
2020-03-27 18:21:27 +00:00
|
|
|
RS::get_singleton()->instance_set_use_lightmap(vi->get_instance(), get_instance(), RID());
|
2017-12-18 03:34:48 +00:00
|
|
|
}
|
2017-12-14 11:59:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BakedLightmap::set_light_data(const Ref<BakedLightmapData> &p_data) {
|
|
|
|
|
|
|
|
if (light_data.is_valid()) {
|
|
|
|
if (is_inside_tree()) {
|
|
|
|
_clear_lightmaps();
|
|
|
|
}
|
|
|
|
set_base(RID());
|
|
|
|
}
|
|
|
|
light_data = p_data;
|
|
|
|
|
|
|
|
if (light_data.is_valid()) {
|
|
|
|
set_base(light_data->get_rid());
|
|
|
|
if (is_inside_tree()) {
|
|
|
|
_assign_lightmaps();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Ref<BakedLightmapData> BakedLightmap::get_light_data() const {
|
|
|
|
|
|
|
|
return light_data;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BakedLightmap::_debug_bake() {
|
|
|
|
bake(get_parent(), true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BakedLightmap::set_propagation(float p_propagation) {
|
|
|
|
propagation = p_propagation;
|
|
|
|
}
|
|
|
|
|
|
|
|
float BakedLightmap::get_propagation() const {
|
|
|
|
|
|
|
|
return propagation;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BakedLightmap::set_energy(float p_energy) {
|
|
|
|
energy = p_energy;
|
|
|
|
}
|
|
|
|
|
|
|
|
float BakedLightmap::get_energy() const {
|
|
|
|
|
|
|
|
return energy;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BakedLightmap::set_bake_quality(BakeQuality p_quality) {
|
|
|
|
bake_quality = p_quality;
|
|
|
|
}
|
|
|
|
|
|
|
|
BakedLightmap::BakeQuality BakedLightmap::get_bake_quality() const {
|
|
|
|
return bake_quality;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BakedLightmap::set_bake_mode(BakeMode p_mode) {
|
|
|
|
bake_mode = p_mode;
|
|
|
|
}
|
|
|
|
|
|
|
|
BakedLightmap::BakeMode BakedLightmap::get_bake_mode() const {
|
|
|
|
return bake_mode;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BakedLightmap::set_image_path(const String &p_path) {
|
|
|
|
image_path = p_path;
|
|
|
|
}
|
|
|
|
|
|
|
|
String BakedLightmap::get_image_path() const {
|
|
|
|
return image_path;
|
|
|
|
}
|
|
|
|
|
|
|
|
AABB BakedLightmap::get_aabb() const {
|
|
|
|
return AABB(-extents, extents * 2);
|
|
|
|
}
|
2020-02-17 21:06:54 +00:00
|
|
|
Vector<Face3> BakedLightmap::get_faces(uint32_t p_usage_flags) const {
|
|
|
|
return Vector<Face3>();
|
2017-12-14 11:59:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2017-12-21 14:03:17 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_bake_cell_size", "bake_cell_size"), &BakedLightmap::set_bake_cell_size);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_bake_cell_size"), &BakedLightmap::get_bake_cell_size);
|
2017-12-14 11:59:46 +00:00
|
|
|
|
2017-12-21 14:03:17 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_capture_cell_size", "capture_cell_size"), &BakedLightmap::set_capture_cell_size);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_capture_cell_size"), &BakedLightmap::get_capture_cell_size);
|
2017-12-14 11:59:46 +00:00
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("set_bake_quality", "bake_quality"), &BakedLightmap::set_bake_quality);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_bake_quality"), &BakedLightmap::get_bake_quality);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("set_bake_mode", "bake_mode"), &BakedLightmap::set_bake_mode);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_bake_mode"), &BakedLightmap::get_bake_mode);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("set_extents", "extents"), &BakedLightmap::set_extents);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_extents"), &BakedLightmap::get_extents);
|
|
|
|
|
2019-06-22 15:27:09 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_bake_default_texels_per_unit", "texels"), &BakedLightmap::set_bake_default_texels_per_unit);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_bake_default_texels_per_unit"), &BakedLightmap::get_bake_default_texels_per_unit);
|
|
|
|
|
2017-12-14 11:59:46 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_propagation", "propagation"), &BakedLightmap::set_propagation);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_propagation"), &BakedLightmap::get_propagation);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("set_energy", "energy"), &BakedLightmap::set_energy);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_energy"), &BakedLightmap::get_energy);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("set_hdr", "hdr"), &BakedLightmap::set_hdr);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_hdr"), &BakedLightmap::is_hdr);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("set_image_path", "image_path"), &BakedLightmap::set_image_path);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_image_path"), &BakedLightmap::get_image_path);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("bake", "from_node", "create_visual_debug"), &BakedLightmap::bake, DEFVAL(Variant()), DEFVAL(false));
|
|
|
|
ClassDB::bind_method(D_METHOD("debug_bake"), &BakedLightmap::_debug_bake);
|
|
|
|
ClassDB::set_method_flags(get_class_static(), _scs_create("debug_bake"), METHOD_FLAGS_DEFAULT | METHOD_FLAG_EDITOR);
|
|
|
|
|
2017-12-21 14:03:17 +00:00
|
|
|
ADD_GROUP("Bake", "bake_");
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "bake_cell_size", PROPERTY_HINT_RANGE, "0.01,64,0.01"), "set_bake_cell_size", "get_bake_cell_size");
|
2017-12-14 11:59:46 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "bake_quality", PROPERTY_HINT_ENUM, "Low,Medium,High"), "set_bake_quality", "get_bake_quality");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "bake_mode", PROPERTY_HINT_ENUM, "ConeTrace,RayTrace"), "set_bake_mode", "get_bake_mode");
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "bake_propagation", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_propagation", "get_propagation");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "bake_energy", PROPERTY_HINT_RANGE, "0,32,0.01"), "set_energy", "get_energy");
|
2017-12-21 14:03:17 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "bake_hdr"), "set_hdr", "is_hdr");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "bake_extents"), "set_extents", "get_extents");
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "bake_default_texels_per_unit"), "set_bake_default_texels_per_unit", "get_bake_default_texels_per_unit");
|
2017-12-21 14:03:17 +00:00
|
|
|
ADD_GROUP("Capture", "capture_");
|
Variant: Added 64-bit packed arrays, renamed Variant::REAL to FLOAT.
- Renames PackedIntArray to PackedInt32Array.
- Renames PackedFloatArray to PackedFloat32Array.
- Adds PackedInt64Array and PackedFloat64Array.
- Renames Variant::REAL to Variant::FLOAT for consistency.
Packed arrays are for storing large amount of data and creating stuff like
meshes, buffers. textures, etc. Forcing them to be 64 is a huge waste of
memory. That said, many users requested the ability to have 64 bits packed
arrays for their games, so this is just an optional added type.
For Variant, the float datatype is always 64 bits, and exposed as `float`.
We still have `real_t` which is the datatype that can change from 32 to 64
bits depending on a compile flag (not entirely working right now, but that's
the idea). It affects math related datatypes and code only.
Neither Variant nor PackedArray make use of real_t, which is only intended
for math precision, so the term is removed from there to keep only float.
2020-02-24 18:20:53 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "capture_cell_size", PROPERTY_HINT_RANGE, "0.01,64,0.01"), "set_capture_cell_size", "get_capture_cell_size");
|
2017-12-21 14:03:17 +00:00
|
|
|
ADD_GROUP("Data", "");
|
2017-12-14 11:59:46 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::STRING, "image_path", PROPERTY_HINT_DIR), "set_image_path", "get_image_path");
|
2018-01-11 12:53:54 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "light_data", PROPERTY_HINT_RESOURCE_TYPE, "BakedLightmapData"), "set_light_data", "get_light_data");
|
2017-12-14 11:59:46 +00:00
|
|
|
|
|
|
|
BIND_ENUM_CONSTANT(BAKE_QUALITY_LOW);
|
|
|
|
BIND_ENUM_CONSTANT(BAKE_QUALITY_MEDIUM);
|
|
|
|
BIND_ENUM_CONSTANT(BAKE_QUALITY_HIGH);
|
|
|
|
BIND_ENUM_CONSTANT(BAKE_MODE_CONE_TRACE);
|
|
|
|
BIND_ENUM_CONSTANT(BAKE_MODE_RAY_TRACE);
|
2017-12-17 00:47:21 +00:00
|
|
|
|
|
|
|
BIND_ENUM_CONSTANT(BAKE_ERROR_OK);
|
|
|
|
BIND_ENUM_CONSTANT(BAKE_ERROR_NO_SAVE_PATH);
|
|
|
|
BIND_ENUM_CONSTANT(BAKE_ERROR_NO_MESHES);
|
|
|
|
BIND_ENUM_CONSTANT(BAKE_ERROR_CANT_CREATE_IMAGE);
|
|
|
|
BIND_ENUM_CONSTANT(BAKE_ERROR_USER_ABORTED);
|
2017-12-14 11:59:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BakedLightmap::BakedLightmap() {
|
|
|
|
|
|
|
|
extents = Vector3(10, 10, 10);
|
2019-06-22 15:27:09 +00:00
|
|
|
bake_default_texels_per_unit = 20;
|
2017-12-24 12:31:17 +00:00
|
|
|
bake_cell_size = 0.25;
|
|
|
|
capture_cell_size = 0.5;
|
2017-12-21 14:03:17 +00:00
|
|
|
|
2017-12-14 11:59:46 +00:00
|
|
|
bake_quality = BAKE_QUALITY_MEDIUM;
|
|
|
|
bake_mode = BAKE_MODE_CONE_TRACE;
|
|
|
|
energy = 1;
|
|
|
|
propagation = 1;
|
|
|
|
hdr = false;
|
|
|
|
image_path = ".";
|
2018-07-18 16:47:42 +00:00
|
|
|
set_disable_scale(true);
|
2017-12-14 11:59:46 +00:00
|
|
|
}
|
2019-10-03 20:39:08 +00:00
|
|
|
#endif
|