2020-12-18 22:58:41 +00:00
|
|
|
#include "voxel_node.h"
|
2021-01-17 17:18:05 +00:00
|
|
|
#include "../generators/voxel_generator.h"
|
2020-12-18 22:58:41 +00:00
|
|
|
#include "../meshers/voxel_mesher.h"
|
|
|
|
#include "../streams/voxel_stream.h"
|
|
|
|
|
2022-01-09 22:13:10 +00:00
|
|
|
namespace zylann::voxel {
|
|
|
|
|
2020-12-18 22:58:41 +00:00
|
|
|
void VoxelNode::set_mesher(Ref<VoxelMesher> mesher) {
|
2021-01-17 17:18:05 +00:00
|
|
|
// Implemented in subclasses
|
2020-12-18 22:58:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Ref<VoxelMesher> VoxelNode::get_mesher() const {
|
2021-01-17 17:18:05 +00:00
|
|
|
// Implemented in subclasses
|
2020-12-18 22:58:41 +00:00
|
|
|
return Ref<VoxelMesher>();
|
|
|
|
}
|
|
|
|
|
|
|
|
void VoxelNode::set_stream(Ref<VoxelStream> stream) {
|
2021-01-17 17:18:05 +00:00
|
|
|
// Implemented in subclasses
|
2020-12-18 22:58:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Ref<VoxelStream> VoxelNode::get_stream() const {
|
2021-01-17 17:18:05 +00:00
|
|
|
// Implemented in subclasses
|
2020-12-18 22:58:41 +00:00
|
|
|
return Ref<VoxelStream>();
|
|
|
|
}
|
|
|
|
|
2021-01-17 17:18:05 +00:00
|
|
|
void VoxelNode::set_generator(Ref<VoxelGenerator> generator) {
|
|
|
|
// Implemented in subclasses
|
|
|
|
}
|
|
|
|
|
|
|
|
Ref<VoxelGenerator> VoxelNode::get_generator() const {
|
|
|
|
// Implemented in subclasses
|
|
|
|
return Ref<VoxelGenerator>();
|
|
|
|
}
|
|
|
|
|
2020-12-18 22:58:41 +00:00
|
|
|
void VoxelNode::restart_stream() {
|
|
|
|
// Not implemented
|
|
|
|
}
|
|
|
|
|
|
|
|
void VoxelNode::remesh_all_blocks() {
|
|
|
|
// Not implemented
|
|
|
|
}
|
|
|
|
|
2021-12-13 21:38:10 +00:00
|
|
|
TypedArray<String> VoxelNode::get_configuration_warnings() const {
|
2020-12-18 22:58:41 +00:00
|
|
|
Ref<VoxelMesher> mesher = get_mesher();
|
|
|
|
Ref<VoxelStream> stream = get_stream();
|
2021-01-17 17:18:05 +00:00
|
|
|
Ref<VoxelGenerator> generator = get_generator();
|
2020-12-18 22:58:41 +00:00
|
|
|
|
2021-12-14 01:28:10 +00:00
|
|
|
TypedArray<String> warnings = Node3D::get_configuration_warnings();
|
2021-12-13 21:38:10 +00:00
|
|
|
|
2020-12-18 22:58:41 +00:00
|
|
|
if (mesher.is_null()) {
|
2021-12-13 21:38:10 +00:00
|
|
|
warnings.append(TTR("This node has no mesher assigned, it wont produce any mesh visuals. "
|
|
|
|
"You can assign one on the `mesher` property."));
|
2020-12-18 22:58:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (stream.is_valid()) {
|
|
|
|
Ref<Script> script = stream->get_script();
|
|
|
|
|
|
|
|
if (script.is_valid()) {
|
|
|
|
if (script->is_tool()) {
|
2021-12-13 21:38:10 +00:00
|
|
|
// TODO This is very annoying. Probably needs an issue or proposal in Godot so we can handle this
|
|
|
|
// properly?
|
|
|
|
warnings.append(TTR("Careful, don't edit your custom stream while it's running, "
|
|
|
|
"it can cause crashes. Turn off `run_stream_in_editor` before doing so."));
|
2020-12-18 22:58:41 +00:00
|
|
|
} else {
|
2021-12-13 21:38:10 +00:00
|
|
|
warnings.append(TTR("The custom stream is not tool, the editor won't be able to use it."));
|
2020-12-18 22:58:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-13 21:38:10 +00:00
|
|
|
if (mesher.is_valid()) {
|
|
|
|
const int stream_channels = stream->get_used_channels_mask();
|
|
|
|
const int mesher_channels = mesher->get_used_channels_mask();
|
2020-12-18 22:58:41 +00:00
|
|
|
|
2021-12-13 21:38:10 +00:00
|
|
|
if ((stream_channels & mesher_channels) == 0) {
|
|
|
|
warnings.append(TTR("The current stream is providing voxel data only on channels that are not used by "
|
|
|
|
"the current mesher. This will result in nothing being visible."));
|
|
|
|
}
|
2021-01-17 17:18:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (generator.is_valid()) {
|
|
|
|
Ref<Script> script = generator->get_script();
|
2021-06-14 19:06:30 +01:00
|
|
|
bool can_check_generator_channels = true;
|
2021-01-17 17:18:05 +00:00
|
|
|
|
|
|
|
if (script.is_valid()) {
|
|
|
|
if (script->is_tool()) {
|
2021-12-13 21:38:10 +00:00
|
|
|
// TODO This is very annoying. Probably needs an issue or proposal in Godot so we can handle this
|
|
|
|
// properly?
|
|
|
|
warnings.append(TTR("Careful, don't edit your custom generator while it's running, "
|
|
|
|
"it can cause crashes. Turn off `run_stream_in_editor` before doing so."));
|
2021-01-17 17:18:05 +00:00
|
|
|
} else {
|
2021-06-14 19:06:30 +01:00
|
|
|
can_check_generator_channels = false;
|
|
|
|
// return TTR("The custom generator is not tool, the editor won't be able to use it.");
|
2021-01-17 17:18:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-13 21:38:10 +00:00
|
|
|
if (can_check_generator_channels && mesher.is_valid()) {
|
2021-06-14 19:06:30 +01:00
|
|
|
const int generator_channels = generator->get_used_channels_mask();
|
|
|
|
const int mesher_channels = mesher->get_used_channels_mask();
|
2021-01-17 17:18:05 +00:00
|
|
|
|
2021-06-14 19:06:30 +01:00
|
|
|
if ((generator_channels & mesher_channels) == 0) {
|
2021-12-13 21:38:10 +00:00
|
|
|
warnings.append(
|
|
|
|
TTR("The current generator is providing voxel data only on channels that are not used by "
|
|
|
|
"the current mesher. This will result in nothing being visible."));
|
2021-06-14 19:06:30 +01:00
|
|
|
}
|
2020-12-18 22:58:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-13 21:38:10 +00:00
|
|
|
return warnings;
|
2020-12-18 22:58:41 +00:00
|
|
|
}
|
|
|
|
|
2021-01-17 17:18:05 +00:00
|
|
|
int VoxelNode::get_used_channels_mask() const {
|
2021-07-10 20:27:55 +01:00
|
|
|
Ref<VoxelMesher> mesher = get_mesher();
|
|
|
|
if (mesher.is_valid()) {
|
|
|
|
return mesher->get_used_channels_mask();
|
|
|
|
}
|
2021-01-17 17:18:05 +00:00
|
|
|
Ref<VoxelGenerator> generator = get_generator();
|
|
|
|
if (generator.is_valid()) {
|
2021-07-10 20:27:55 +01:00
|
|
|
return generator->get_used_channels_mask();
|
2021-01-17 17:18:05 +00:00
|
|
|
}
|
2021-07-10 20:27:55 +01:00
|
|
|
Ref<VoxelStream> stream = get_stream();
|
2021-01-17 17:18:05 +00:00
|
|
|
if (stream.is_valid()) {
|
2021-07-10 20:27:55 +01:00
|
|
|
return stream->get_used_channels_mask();
|
2021-01-17 17:18:05 +00:00
|
|
|
}
|
2021-07-10 20:27:55 +01:00
|
|
|
return 0;
|
2021-01-17 17:18:05 +00:00
|
|
|
}
|
|
|
|
|
2021-12-16 00:11:11 +00:00
|
|
|
void VoxelNode::set_gi_mode(VoxelNode::GIMode mode) {
|
|
|
|
ERR_FAIL_INDEX(mode, _GI_MODE_COUNT);
|
|
|
|
if (mode != _gi_mode) {
|
|
|
|
_gi_mode = mode;
|
|
|
|
_on_gi_mode_changed();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
VoxelNode::GIMode VoxelNode::get_gi_mode() const {
|
|
|
|
return _gi_mode;
|
|
|
|
}
|
|
|
|
|
2020-12-18 22:58:41 +00:00
|
|
|
void VoxelNode::_bind_methods() {
|
|
|
|
ClassDB::bind_method(D_METHOD("set_stream", "stream"), &VoxelNode::_b_set_stream);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_stream"), &VoxelNode::_b_get_stream);
|
|
|
|
|
2021-01-17 17:18:05 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_generator", "generator"), &VoxelNode::_b_set_generator);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_generator"), &VoxelNode::_b_get_generator);
|
|
|
|
|
2020-12-18 22:58:41 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_mesher", "mesher"), &VoxelNode::_b_set_mesher);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_mesher"), &VoxelNode::_b_get_mesher);
|
|
|
|
|
2021-12-16 00:11:11 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_gi_mode", "mode"), &VoxelNode::set_gi_mode);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_gi_mode"), &VoxelNode::get_gi_mode);
|
|
|
|
|
2021-12-13 21:38:10 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "stream", PROPERTY_HINT_RESOURCE_TYPE, "VoxelStream"), "set_stream",
|
|
|
|
"get_stream");
|
2021-01-17 17:18:05 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "generator", PROPERTY_HINT_RESOURCE_TYPE, "VoxelGenerator"),
|
|
|
|
"set_generator", "get_generator");
|
2021-12-13 21:38:10 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "mesher", PROPERTY_HINT_RESOURCE_TYPE, "VoxelMesher"), "set_mesher",
|
|
|
|
"get_mesher");
|
2021-12-16 00:11:11 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "gi_mode", PROPERTY_HINT_ENUM, "Disabled,Baked,Dynamic"), "set_gi_mode",
|
|
|
|
"get_gi_mode");
|
2020-12-18 22:58:41 +00:00
|
|
|
}
|
2022-01-09 22:13:10 +00:00
|
|
|
|
|
|
|
} // namespace zylann::voxel
|