Initial gizmo setup for Terraman.

This commit is contained in:
Relintai 2025-02-05 11:05:42 +01:00
parent 3610209f54
commit 91f6141b5c
7 changed files with 320 additions and 1 deletions

View File

@ -49,6 +49,8 @@ sources = [
if env["tools"]:
sources.append("editor/terrain_world_editor.cpp")
sources.append("editor/terraman_gizmo.cpp")
sources.append("editor/terraman_gizmo_plugin.cpp")
if env["module_texture_packer_enabled"]:
sources.append("library/terrain_library_merger.cpp")

View File

@ -38,10 +38,12 @@
#include "editor/editor_scale.h"
#include "editor/editor_settings.h"
#include "modules/terraman/editor/terraman_gizmo_plugin.h"
#include "../world/terrain_world.h"
#include "scene/gui/box_container.h"
#include "scene/gui/flow_container.h"
#include "scene/main/control.h"
#include "../world/terrain_world.h"
#include "core/os/keyboard.h"
@ -981,6 +983,11 @@ void TerrainWorldEditorPlugin::make_visible(bool p_visible) {
TerrainWorldEditorPlugin::TerrainWorldEditorPlugin(EditorNode *p_node) {
editor = p_node;
gizmo_plugin.instance();
gizmo_plugin->plugin = this;
add_spatial_gizmo_plugin(gizmo_plugin);
EDITOR_DEF("editors/terrain/editor_side", 1);
EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::INT, "editors/terrain/editor_side", PROPERTY_HINT_ENUM, "Left,Right"));

View File

@ -43,6 +43,7 @@ class HSlider;
class BoxContainer;
class HFlowContainer;
class SpinBox;
class TerramanGizmoPlugin;
class TerrainWorldEditor : public PanelContainer {
GDCLASS(TerrainWorldEditor, PanelContainer);
@ -182,6 +183,7 @@ class TerrainWorldEditorPlugin : public EditorPlugin {
TerrainWorldEditor *terrain_world_editor;
EditorNode *editor;
Ref<TerramanGizmoPlugin> gizmo_plugin;
protected:
void _notification(int p_what);

View File

@ -0,0 +1,101 @@
/*************************************************************************/
/* terraman_gizmo.cpp */
/*************************************************************************/
/* This file is part of: */
/* PANDEMONIUM ENGINE */
/* https://github.com/Relintai/pandemonium_engine */
/*************************************************************************/
/* Copyright (c) 2022-present Péter Magyar. */
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "terraman_gizmo.h"
#include "editor/editor_node.h"
#include "editor/editor_settings.h"
#include "scene/3d/camera.h"
void TerramanGizmo::set_visible(const bool visible) {
_visible = visible;
redraw();
}
void TerramanGizmo::set_editor_plugin(EditorPlugin *editor_plugin) {
_editor_plugin = editor_plugin;
_undo_redo = EditorNode::get_undo_redo();
}
void TerramanGizmo::set_handle(int index, bool secondary, Camera *camera, const Point2 &point) {
}
void TerramanGizmo::redraw() {
clear();
if (!_visible) {
return;
}
if (!get_plugin().is_valid()) {
return;
}
/*
Ref<SpatialMaterial> handles_material = get_plugin()->get_material("handles", Ref<EditorSpatialGizmo>(this));
Ref<SpatialMaterial> material = get_plugin()->get_material("main", Ref<EditorSpatialGizmo>(this));
Ref<SpatialMaterial> seam_material = get_plugin()->get_material("seam", Ref<EditorSpatialGizmo>(this));
_mesh_outline_generator->setup(_mdr);
if (selection_mode == SELECTION_MODE_EDGE) {
_mesh_outline_generator->generate_mark_edges(visual_indicator_outline, visual_indicator_handle);
} else if (selection_mode == SELECTION_MODE_FACE) {
_mesh_outline_generator->generate_mark_faces(visual_indicator_outline, visual_indicator_handle);
} else {
_mesh_outline_generator->generate(visual_indicator_outline, visual_indicator_handle);
}
if (visual_indicator_outline || visual_indicator_handle) {
add_lines(_mesh_outline_generator->lines, material, false);
}
if (visual_indicator_seam) {
add_lines(_mesh_outline_generator->seam_lines, seam_material, false);
}
*/
}
void TerramanGizmo::apply() {
}
TerramanGizmo::TerramanGizmo() {
_editor_plugin = nullptr;
_undo_redo = nullptr;
_visible = false;
}
TerramanGizmo::~TerramanGizmo() {
}
void TerramanGizmo::_bind_methods() {
}

View File

@ -0,0 +1,73 @@
#ifndef TERRAMAN_GIZMO_H
#define TERRAMAN_GIZMO_H
/*************************************************************************/
/* terraman_gizmo.h */
/*************************************************************************/
/* This file is part of: */
/* PANDEMONIUM ENGINE */
/* https://github.com/Relintai/pandemonium_engine */
/*************************************************************************/
/* Copyright (c) 2022-present Péter Magyar. */
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "editor/spatial_editor_gizmos.h"
#include "core/variant/variant.h"
class Camera;
class MeshDataResource;
class MDREDMeshOutline;
class InputEvent;
class EditorPlugin;
class UndoRedo;
class TerramanGizmo : public EditorSpatialGizmo {
GDCLASS(TerramanGizmo, EditorSpatialGizmo);
public:
void set_visible(const bool visible);
void set_editor_plugin(EditorPlugin *editor_plugin);
void set_handle(int index, bool secondary, Camera *camera, const Point2 &point);
void redraw();
void apply();
TerramanGizmo();
~TerramanGizmo();
PoolVector3Array _vertices;
PoolIntArray _indices;
EditorPlugin *_editor_plugin;
UndoRedo *_undo_redo;
bool _visible;
protected:
static void _bind_methods();
};
#endif

View File

@ -0,0 +1,76 @@
/*************************************************************************/
/* terrmana_gizmo_plugin.cpp */
/*************************************************************************/
/* This file is part of: */
/* PANDEMONIUM ENGINE */
/* https://github.com/Relintai/pandemonium_engine */
/*************************************************************************/
/* Copyright (c) 2022-present Péter Magyar. */
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "terraman_gizmo_plugin.h"
#include "../world/terrain_world.h"
#include "terrain_world_editor.h"
#include "terraman_gizmo.h"
String TerramanGizmoPlugin::get_gizmo_name() const {
return "TerramanGizmo";
}
int TerramanGizmoPlugin::get_priority() const {
return 100;
}
bool TerramanGizmoPlugin::is_handle_highlighted(const EditorSpatialGizmo *p_gizmo, int p_idx, bool p_secondary) const {
return EditorSpatialGizmoPlugin::is_handle_highlighted(p_gizmo, p_idx, p_secondary);
}
Ref<EditorSpatialGizmo> TerramanGizmoPlugin::create_gizmo(Spatial *p_spatial) {
TerrainWorld *world = Object::cast_to<TerrainWorld>(p_spatial);
if (world) {
Ref<TerramanGizmo> gizmo;
gizmo.instance();
gizmo->set_editor_plugin(plugin);
gizmo->set_spatial_node(p_spatial);
return gizmo;
} else {
return Ref<EditorSpatialGizmo>();
}
}
TerramanGizmoPlugin::TerramanGizmoPlugin() {
plugin = nullptr;
create_material("main", Color(0.7, 0.7, 0.7));
create_material("seam", Color(1, 0, 0), false, true);
create_handle_material("handles");
}
TerramanGizmoPlugin::~TerramanGizmoPlugin() {
}
void TerramanGizmoPlugin::_bind_methods() {
}

View File

@ -0,0 +1,58 @@
#ifndef TERRAMAN_GIZMO_PLUGIN_H
#define TERRAMAN_GIZMO_PLUGIN_H
/*************************************************************************/
/* terraman_gizmo_plugin.h */
/*************************************************************************/
/* This file is part of: */
/* PANDEMONIUM ENGINE */
/* https://github.com/Relintai/pandemonium_engine */
/*************************************************************************/
/* Copyright (c) 2022-present Péter Magyar. */
/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "editor/spatial_editor_gizmos.h"
class TerrainWorldEditorPlugin;
class TerramanGizmoPlugin : public EditorSpatialGizmoPlugin {
GDCLASS(TerramanGizmoPlugin, EditorSpatialGizmoPlugin);
public:
void _init();
String get_gizmo_name() const;
int get_priority() const;
bool is_handle_highlighted(const EditorSpatialGizmo *p_gizmo, int p_idx, bool p_secondary) const;
TerramanGizmoPlugin();
~TerramanGizmoPlugin();
TerrainWorldEditorPlugin *plugin;
protected:
Ref<EditorSpatialGizmo> create_gizmo(Spatial *p_spatial);
static void _bind_methods();
};
#endif