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.
This commit is contained in:
Marc Gilleron 2021-07-10 20:27:55 +01:00
parent 3ffd07af47
commit 966c2c9fef
2 changed files with 9 additions and 5 deletions

View File

@ -100,16 +100,19 @@ String VoxelNode::get_configuration_warning() const {
}
int VoxelNode::get_used_channels_mask() const {
Ref<VoxelMesher> mesher = get_mesher();
if (mesher.is_valid()) {
return mesher->get_used_channels_mask();
}
Ref<VoxelGenerator> generator = get_generator();
Ref<VoxelStream> 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<VoxelStream> 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() {

View File

@ -1248,6 +1248,7 @@ Ref<VoxelTool> 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;