mirror of
https://github.com/Relintai/pandemonium_engine.git
synced 2025-04-19 01:43:12 +02:00
Added a Spatial Gizmo plugin for ESSEntityWorldSpawner3D.
This commit is contained in:
parent
26c53fd16d
commit
b792287b6e
@ -31,6 +31,12 @@
|
||||
|
||||
#include "ess_editor_plugin.h"
|
||||
|
||||
#include "editor/editor_settings.h"
|
||||
|
||||
#include "../world_spawners/ess_entity_world_spawner_3d.h"
|
||||
|
||||
#include "scene/resources/mesh/mesh.h"
|
||||
|
||||
void ESSEditorPlugin::fix_ids(Variant param) {
|
||||
}
|
||||
|
||||
@ -38,11 +44,98 @@ ESSEditorPlugin::ESSEditorPlugin(EditorNode *p_node) {
|
||||
editor = p_node;
|
||||
|
||||
//editor->add_tool_menu_item("ESS: make ids unique", this, "fix_ids");
|
||||
|
||||
gizmo_plugin.instance();
|
||||
add_spatial_gizmo_plugin(gizmo_plugin);
|
||||
}
|
||||
|
||||
ESSEditorPlugin::~ESSEditorPlugin() {
|
||||
}
|
||||
|
||||
void ESSEditorPlugin::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("fix_ids"), &ESSEditorPlugin::fix_ids);
|
||||
//ClassDB::bind_method(D_METHOD("fix_ids"), &ESSEditorPlugin::fix_ids);
|
||||
}
|
||||
|
||||
////////
|
||||
|
||||
WorldSpawner3DSpatialGizmoPlugin::WorldSpawner3DSpatialGizmoPlugin() {
|
||||
const Color gizmo_color = EDITOR_DEF("editors/props/gizmo_colors/outline", Color(0.5, 0.5, 1));
|
||||
|
||||
create_material("outline_material", gizmo_color);
|
||||
}
|
||||
|
||||
bool WorldSpawner3DSpatialGizmoPlugin::has_gizmo(Spatial *p_spatial) {
|
||||
return Object::cast_to<ESSEntityWorldSpawner3D>(p_spatial) != NULL;
|
||||
}
|
||||
|
||||
String WorldSpawner3DSpatialGizmoPlugin::get_gizmo_name() const {
|
||||
return "ESSEntityWorldSpawner3D";
|
||||
}
|
||||
|
||||
int WorldSpawner3DSpatialGizmoPlugin::get_priority() const {
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool WorldSpawner3DSpatialGizmoPlugin::can_be_hidden() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
void WorldSpawner3DSpatialGizmoPlugin::redraw(EditorSpatialGizmo *p_gizmo) {
|
||||
//ESSEntityWorldSpawner3D *ws = Object::cast_to<ESSEntityWorldSpawner3D>(p_gizmo->get_spatial_node());
|
||||
|
||||
p_gizmo->clear();
|
||||
|
||||
AABB aabb;
|
||||
aabb.size = Vector3(1, 2, 1);
|
||||
aabb.position = Vector3(-0.5, 0, -0.5);
|
||||
|
||||
Ref<ArrayMesh> cm;
|
||||
cm.instance();
|
||||
|
||||
//cm->set_size(aabb.size);
|
||||
|
||||
Array mesh_arr;
|
||||
mesh_arr.resize(Mesh::ARRAY_MAX);
|
||||
|
||||
// set our bounding box
|
||||
PoolVector<Vector3> points;
|
||||
|
||||
points.push_back(aabb.position);
|
||||
points.push_back(aabb.position + Vector3(aabb.size.x, 0, 0));
|
||||
points.push_back(aabb.position + Vector3(aabb.size.x, 0, 0));
|
||||
points.push_back(aabb.position + Vector3(aabb.size.x, 0, aabb.size.z));
|
||||
points.push_back(aabb.position);
|
||||
points.push_back(aabb.position + Vector3(0, 0, aabb.size.z));
|
||||
points.push_back(aabb.position + Vector3(0, 0, aabb.size.z));
|
||||
points.push_back(aabb.position + Vector3(aabb.size.x, 0, aabb.size.z));
|
||||
points.push_back(aabb.position);
|
||||
points.push_back(aabb.position + Vector3(0, aabb.size.y, 0));
|
||||
points.push_back(aabb.position + Vector3(aabb.size.x, 0, 0));
|
||||
points.push_back(aabb.position + Vector3(aabb.size.x, aabb.size.y, 0));
|
||||
points.push_back(aabb.position + Vector3(0, 0, aabb.size.z));
|
||||
points.push_back(aabb.position + Vector3(0, aabb.size.y, aabb.size.z));
|
||||
points.push_back(aabb.position + Vector3(aabb.size.x, 0, aabb.size.z));
|
||||
points.push_back(aabb.position + aabb.size);
|
||||
points.push_back(aabb.position + Vector3(0, aabb.size.y, 0));
|
||||
points.push_back(aabb.position + Vector3(aabb.size.x, aabb.size.y, 0));
|
||||
points.push_back(aabb.position + Vector3(0, aabb.size.y, 0));
|
||||
points.push_back(aabb.position + Vector3(0, aabb.size.y, aabb.size.z));
|
||||
points.push_back(aabb.position + Vector3(0, aabb.size.y, aabb.size.z));
|
||||
points.push_back(aabb.position + aabb.size);
|
||||
points.push_back(aabb.position + Vector3(aabb.size.x, aabb.size.y, 0));
|
||||
points.push_back(aabb.position + aabb.size);
|
||||
|
||||
mesh_arr[RS::ARRAY_VERTEX] = points;
|
||||
|
||||
cm->add_surface_from_arrays(Mesh::PRIMITIVE_LINES, mesh_arr);
|
||||
|
||||
Ref<TriangleMesh> tm = cm->generate_triangle_mesh_from_aabb();
|
||||
|
||||
if (tm.is_valid()) {
|
||||
p_gizmo->add_collision_triangles(tm);
|
||||
}
|
||||
|
||||
const Ref<Material> material = get_material("outline_material");
|
||||
|
||||
p_gizmo->add_mesh(cm, material);
|
||||
}
|
||||
|
@ -35,12 +35,12 @@
|
||||
#include "editor/editor_node.h"
|
||||
#include "editor/editor_plugin.h"
|
||||
|
||||
#include "editor/spatial_editor_gizmos.h"
|
||||
|
||||
class WorldSpawner3DSpatialGizmoPlugin;
|
||||
|
||||
class ESSEditorPlugin : public EditorPlugin {
|
||||
GDCLASS(ESSEditorPlugin, EditorPlugin);
|
||||
EditorNode *editor;
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
virtual String get_name() const { return "ESSEditorPlugin"; }
|
||||
@ -52,6 +52,26 @@ public:
|
||||
|
||||
ESSEditorPlugin(EditorNode *p_node);
|
||||
~ESSEditorPlugin();
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
EditorNode *editor;
|
||||
|
||||
Ref<WorldSpawner3DSpatialGizmoPlugin> gizmo_plugin;
|
||||
};
|
||||
|
||||
class WorldSpawner3DSpatialGizmoPlugin : public EditorSpatialGizmoPlugin {
|
||||
GDCLASS(WorldSpawner3DSpatialGizmoPlugin, EditorSpatialGizmoPlugin);
|
||||
|
||||
public:
|
||||
bool has_gizmo(Spatial *p_spatial);
|
||||
String get_gizmo_name() const;
|
||||
int get_priority() const;
|
||||
bool can_be_hidden() const;
|
||||
void redraw(EditorSpatialGizmo *p_gizmo);
|
||||
|
||||
WorldSpawner3DSpatialGizmoPlugin();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user