mirror of
https://github.com/Relintai/voxelman.git
synced 2025-01-25 15:09:18 +01:00
Moved the position calculation from the world editor to a virtual method inside VoxelWorld.
This commit is contained in:
parent
c4eb758d20
commit
cf370025fc
@ -443,6 +443,26 @@ int VoxelWorld::_get_channel_index_info(const VoxelWorld::ChannelTypeInfo channe
|
||||
return -1;
|
||||
}
|
||||
|
||||
void VoxelWorld::_set_voxel_with_tool(const bool mode_add, const Vector3 hit_position, const Vector3 hit_normal, const int selected_voxel, const int isolevel) {
|
||||
Vector3 pos;
|
||||
|
||||
if (mode_add) {
|
||||
pos = (hit_position + (Vector3(0.1, 0.1, 0.1) * hit_normal * get_voxel_scale()));
|
||||
} else {
|
||||
pos = (hit_position + (Vector3(0.1, 0.1, 0.1) * -hit_normal * get_voxel_scale()));
|
||||
}
|
||||
|
||||
int channel_type = get_channel_index_info(VoxelWorld::CHANNEL_TYPE_INFO_TYPE);
|
||||
int channel_isolevel = get_channel_index_info(VoxelWorld::CHANNEL_TYPE_INFO_ISOLEVEL);
|
||||
|
||||
if (channel_isolevel == -1) {
|
||||
set_voxel_at_world_position(pos, selected_voxel, channel_type);
|
||||
} else {
|
||||
set_voxel_at_world_position(pos, selected_voxel, channel_type, false);
|
||||
set_voxel_at_world_position(pos, isolevel, channel_isolevel);
|
||||
}
|
||||
}
|
||||
|
||||
bool VoxelWorld::can_chunk_do_build_step() {
|
||||
if (_max_frame_chunk_build_steps == 0) {
|
||||
return true;
|
||||
@ -802,6 +822,10 @@ Ref<VoxelChunk> VoxelWorld::get_or_create_chunk_at_world_position(const Vector3
|
||||
return get_or_create_chunk(x, y, z);
|
||||
}
|
||||
|
||||
void VoxelWorld::set_voxel_with_tool(const bool mode_add, const Vector3 hit_position, const Vector3 hit_normal, const int selected_voxel, const int isolevel) {
|
||||
call("_set_voxel_with_tool", mode_add, hit_position, hit_normal, selected_voxel, isolevel);
|
||||
}
|
||||
|
||||
int VoxelWorld::get_channel_index_info(const VoxelWorld::ChannelTypeInfo channel_type) {
|
||||
return call("_get_channel_index_info", channel_type);
|
||||
}
|
||||
@ -1143,6 +1167,16 @@ void VoxelWorld::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_channel_index_info", "channel_type"), &VoxelWorld::get_channel_index_info);
|
||||
ClassDB::bind_method(D_METHOD("_get_channel_index_info", "channel_type"), &VoxelWorld::_get_channel_index_info);
|
||||
|
||||
BIND_VMETHOD(MethodInfo("_set_voxel_with_tool",
|
||||
PropertyInfo(Variant::BOOL, "mode_add"),
|
||||
PropertyInfo(Variant::VECTOR3, "hit_position"),
|
||||
PropertyInfo(Variant::VECTOR3, "hit_normal"),
|
||||
PropertyInfo(Variant::INT, "selected_voxel"),
|
||||
PropertyInfo(Variant::INT, "isolevel")));
|
||||
|
||||
ClassDB::bind_method(D_METHOD("set_voxel_with_tool", "mode_add", "hit_position", "hit_normal", "selected_voxel", "isolevel"), &VoxelWorld::set_voxel_with_tool);
|
||||
ClassDB::bind_method(D_METHOD("_set_voxel_with_tool", "mode_add", "hit_position", "hit_normal", "selected_voxel", "isolevel"), &VoxelWorld::_set_voxel_with_tool);
|
||||
|
||||
BIND_ENUM_CONSTANT(CHANNEL_TYPE_INFO_TYPE);
|
||||
BIND_ENUM_CONSTANT(CHANNEL_TYPE_INFO_ISOLEVEL);
|
||||
BIND_ENUM_CONSTANT(CHANNEL_TYPE_INFO_LIQUID_FLOW);
|
||||
|
@ -179,6 +179,7 @@ public:
|
||||
void set_voxel_at_world_position(const Vector3 &world_position, const uint8_t data, const int channel_index, const bool rebuild = true);
|
||||
Ref<VoxelChunk> get_chunk_at_world_position(const Vector3 &world_position);
|
||||
Ref<VoxelChunk> get_or_create_chunk_at_world_position(const Vector3 &world_position);
|
||||
void set_voxel_with_tool(const bool mode_add, const Vector3 hit_position, const Vector3 hit_normal, const int selected_voxel, const int isolevel);
|
||||
|
||||
int get_channel_index_info(const ChannelTypeInfo channel_type);
|
||||
|
||||
@ -189,6 +190,7 @@ protected:
|
||||
virtual void _generate_chunk(Ref<VoxelChunk> chunk);
|
||||
virtual Ref<VoxelChunk> _create_chunk(int x, int y, int z, Ref<VoxelChunk> p_chunk);
|
||||
virtual int _get_channel_index_info(const ChannelTypeInfo channel_type);
|
||||
virtual void _set_voxel_with_tool(const bool mode_add, const Vector3 hit_position, const Vector3 hit_normal, const int selected_voxel, const int isolevel);
|
||||
|
||||
virtual void _notification(int p_what);
|
||||
static void _bind_methods();
|
||||
|
@ -86,7 +86,6 @@ bool VoxelWorldEditor::do_input_action(Camera *p_camera, const Point2 &p_point,
|
||||
PhysicsDirectSpaceState::RayResult res;
|
||||
|
||||
if (ss->intersect_ray(from, to, res)) {
|
||||
Vector3 pos;
|
||||
int selected_voxel = 0;
|
||||
int channel = 0;
|
||||
|
||||
@ -96,22 +95,18 @@ bool VoxelWorldEditor::do_input_action(Camera *p_camera, const Point2 &p_point,
|
||||
return false;
|
||||
|
||||
int isolevel = _current_isolevel;
|
||||
bool mode_add = false;
|
||||
|
||||
if (_tool_mode == TOOL_MODE_ADD) {
|
||||
pos = (res.position + (Vector3(0.1, 0.1, 0.1) * res.normal));
|
||||
selected_voxel = _selected_type + 1;
|
||||
mode_add = true;
|
||||
} else if (_tool_mode == TOOL_MODE_REMOVE) {
|
||||
pos = (res.position + (Vector3(0.1, 0.1, 0.1) * -res.normal));
|
||||
selected_voxel = 0;
|
||||
isolevel = 0;
|
||||
mode_add = false;
|
||||
}
|
||||
|
||||
if (_channel_isolevel == -1) {
|
||||
_world->set_voxel_at_world_position(pos, selected_voxel, channel);
|
||||
} else {
|
||||
_world->set_voxel_at_world_position(pos, selected_voxel, channel, false);
|
||||
_world->set_voxel_at_world_position(pos, isolevel, _channel_isolevel);
|
||||
}
|
||||
_world->set_voxel_with_tool(mode_add, res.position, res.normal, selected_voxel, isolevel);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user