mirror of
https://github.com/Relintai/voxelman.git
synced 2025-02-20 17:04:23 +01:00
A bit more work on the world editor.
This commit is contained in:
parent
fd24639e26
commit
c752086bdd
@ -70,7 +70,7 @@ bool VoxelWorldEditor::forward_spatial_input_event(Camera *p_camera, const Ref<I
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (mb->get_button_index() == BUTTON_LEFT) {
|
if (mb->get_button_index() == BUTTON_LEFT) {
|
||||||
return do_input_action(p_camera, Point2(mb->get_position().x, mb->get_position().y), true, _seletced_type);
|
return do_input_action(p_camera, Point2(mb->get_position().x, mb->get_position().y), true);
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -82,7 +82,7 @@ bool VoxelWorldEditor::forward_spatial_input_event(Camera *p_camera, const Ref<I
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool VoxelWorldEditor::do_input_action(Camera *p_camera, const Point2 &p_point, bool p_click, int selected_voxel) {
|
bool VoxelWorldEditor::do_input_action(Camera *p_camera, const Point2 &p_point, bool p_click) {
|
||||||
|
|
||||||
if (!spatial_editor || !_world)
|
if (!spatial_editor || !_world)
|
||||||
return false;
|
return false;
|
||||||
@ -99,7 +99,16 @@ bool VoxelWorldEditor::do_input_action(Camera *p_camera, const Point2 &p_point,
|
|||||||
PhysicsDirectSpaceState::RayResult res;
|
PhysicsDirectSpaceState::RayResult res;
|
||||||
|
|
||||||
if (ss->intersect_ray(from, to, res)) {
|
if (ss->intersect_ray(from, to, res)) {
|
||||||
Vector3 pos = (res.position + (Vector3(0.1, 0.1, 0.1) * res.normal)) / _world->get_voxel_scale();
|
Vector3 pos;
|
||||||
|
int selected_voxel = 0;
|
||||||
|
|
||||||
|
if (_tool_mode == TOOL_MODE_ADD) {
|
||||||
|
pos = (res.position + (Vector3(0.1, 0.1, 0.1) * res.normal)) / _world->get_voxel_scale();
|
||||||
|
selected_voxel = _seletced_type;
|
||||||
|
} else if (_tool_mode == TOOL_MODE_REMOVE) {
|
||||||
|
pos = (res.position + (Vector3(0.1, 0.1, 0.1) * -res.normal)) / _world->get_voxel_scale();
|
||||||
|
selected_voxel = 0;
|
||||||
|
}
|
||||||
|
|
||||||
//todo add these?:
|
//todo add these?:
|
||||||
//_world->set_voxel(pos, data[]);
|
//_world->set_voxel(pos, data[]);
|
||||||
@ -186,11 +195,13 @@ VoxelWorldEditor::VoxelWorldEditor() {
|
|||||||
_world = NULL;
|
_world = NULL;
|
||||||
_seletced_type = 1;
|
_seletced_type = 1;
|
||||||
_editor = NULL;
|
_editor = NULL;
|
||||||
|
_tool_mode = TOOL_MODE_ADD;
|
||||||
}
|
}
|
||||||
VoxelWorldEditor::VoxelWorldEditor(EditorNode *p_editor) {
|
VoxelWorldEditor::VoxelWorldEditor(EditorNode *p_editor) {
|
||||||
_world = NULL;
|
_world = NULL;
|
||||||
_seletced_type = 1;
|
_seletced_type = 1;
|
||||||
_editor = p_editor;
|
_editor = p_editor;
|
||||||
|
_tool_mode = TOOL_MODE_ADD;
|
||||||
|
|
||||||
spatial_editor_hb = memnew(HBoxContainer);
|
spatial_editor_hb = memnew(HBoxContainer);
|
||||||
spatial_editor_hb->set_h_size_flags(SIZE_EXPAND_FILL);
|
spatial_editor_hb->set_h_size_flags(SIZE_EXPAND_FILL);
|
||||||
|
@ -41,11 +41,17 @@ class SpatialEditorPlugin;
|
|||||||
class VoxelWorldEditor : public VBoxContainer {
|
class VoxelWorldEditor : public VBoxContainer {
|
||||||
GDCLASS(VoxelWorldEditor, VBoxContainer);
|
GDCLASS(VoxelWorldEditor, VBoxContainer);
|
||||||
|
|
||||||
|
public:
|
||||||
|
enum VoxelWorldEditorToolMode {
|
||||||
|
TOOL_MODE_ADD = 0,
|
||||||
|
TOOL_MODE_REMOVE,
|
||||||
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
bool forward_spatial_input_event(Camera *p_camera, const Ref<InputEvent> &p_event);
|
bool forward_spatial_input_event(Camera *p_camera, const Ref<InputEvent> &p_event);
|
||||||
|
|
||||||
void edit(VoxelWorld *p_world);
|
void edit(VoxelWorld *p_world);
|
||||||
bool do_input_action(Camera *p_camera, const Point2 &p_point, bool p_click, int selected_voxel);
|
bool do_input_action(Camera *p_camera, const Point2 &p_point, bool p_click);
|
||||||
|
|
||||||
VoxelWorldEditor();
|
VoxelWorldEditor();
|
||||||
VoxelWorldEditor(EditorNode *p_editor);
|
VoxelWorldEditor(EditorNode *p_editor);
|
||||||
@ -58,6 +64,7 @@ protected:
|
|||||||
void _node_removed(Node *p_node);
|
void _node_removed(Node *p_node);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
VoxelWorldEditorToolMode _tool_mode;
|
||||||
VoxelWorld *_world;
|
VoxelWorld *_world;
|
||||||
int _seletced_type;
|
int _seletced_type;
|
||||||
SpatialEditorPlugin *spatial_editor;
|
SpatialEditorPlugin *spatial_editor;
|
||||||
|
Loading…
Reference in New Issue
Block a user