From 966c2c9fef44c8023060bb136151e2724fb6506d Mon Sep 17 00:00:00 2001 From: Marc Gilleron Date: Sat, 10 Jul 2021 20:27:55 +0100 Subject: [PATCH] Change default channel attribution when using `get_voxel_tool()` - It now depends first on the mesher - If no mesher is assigned, it depends on the generator - If no generator is assigned, it depends on the stream - If no stream is assigned, it defaults to 0 - If multiple channels are found, pick the first one instead of last - The reason is, some streams can support all channels so they dont represent well what the user intends to use. --- terrain/voxel_node.cpp | 13 ++++++++----- terrain/voxel_terrain.cpp | 1 + 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/terrain/voxel_node.cpp b/terrain/voxel_node.cpp index 92eb560a..c4857e7c 100644 --- a/terrain/voxel_node.cpp +++ b/terrain/voxel_node.cpp @@ -100,16 +100,19 @@ String VoxelNode::get_configuration_warning() const { } int VoxelNode::get_used_channels_mask() const { + Ref mesher = get_mesher(); + if (mesher.is_valid()) { + return mesher->get_used_channels_mask(); + } Ref generator = get_generator(); - Ref stream = get_stream(); - int used_channels_mask = 0; if (generator.is_valid()) { - used_channels_mask |= generator->get_used_channels_mask(); + return generator->get_used_channels_mask(); } + Ref stream = get_stream(); if (stream.is_valid()) { - used_channels_mask |= stream->get_used_channels_mask(); + return stream->get_used_channels_mask(); } - return used_channels_mask; + return 0; } void VoxelNode::_bind_methods() { diff --git a/terrain/voxel_terrain.cpp b/terrain/voxel_terrain.cpp index 0ebdf806..9a20027e 100644 --- a/terrain/voxel_terrain.cpp +++ b/terrain/voxel_terrain.cpp @@ -1248,6 +1248,7 @@ Ref VoxelTerrain::get_voxel_tool() { for (int channel = 0; channel < VoxelBuffer::MAX_CHANNELS; ++channel) { if ((used_channels_mask & (1 << channel)) != 0) { vt->set_channel(channel); + break; } } return vt;