Expose the new gizmo plugin system to scripting

This commit is contained in:
JFonS 2018-10-29 11:30:28 +01:00
parent 13582354fd
commit 6b15b4f904
11 changed files with 364 additions and 40 deletions

View File

@ -110,6 +110,14 @@
<description> <description>
</description> </description>
</method> </method>
<method name="add_spatial_gizmo_plugin">
<return type="void">
</return>
<argument index="0" name="plugin" type="EditorSpatialGizmoPlugin">
</argument>
<description>
</description>
</method>
<method name="add_tool_menu_item"> <method name="add_tool_menu_item">
<return type="void"> <return type="void">
</return> </return>
@ -394,6 +402,14 @@
<description> <description>
</description> </description>
</method> </method>
<method name="remove_spatial_gizmo_plugin">
<return type="void">
</return>
<argument index="0" name="plugin" type="EditorSpatialGizmoPlugin">
</argument>
<description>
</description>
</method>
<method name="remove_tool_menu_item"> <method name="remove_tool_menu_item">
<return type="void"> <return type="void">
</return> </return>

View File

@ -0,0 +1,175 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="EditorSpatialGizmoPlugin" inherits="Resource" category="Core" version="3.1">
<brief_description>
</brief_description>
<description>
</description>
<tutorials>
</tutorials>
<demos>
</demos>
<methods>
<method name="add_material">
<return type="void">
</return>
<argument index="0" name="name" type="String">
</argument>
<argument index="1" name="material" type="SpatialMaterial">
</argument>
<description>
</description>
</method>
<method name="can_be_hidden" qualifiers="virtual">
<return type="bool">
</return>
<description>
</description>
</method>
<method name="commit_handle" qualifiers="virtual">
<return type="void">
</return>
<argument index="0" name="gizmo" type="EditorSpatialGizmo">
</argument>
<argument index="1" name="index" type="int">
</argument>
<argument index="2" name="restore" type="Variant">
</argument>
<argument index="3" name="cancel" type="bool" default="false">
</argument>
<description>
</description>
</method>
<method name="create_gizmo" qualifiers="virtual">
<return type="EditorSpatialGizmo">
</return>
<argument index="0" name="spatial" type="Spatial">
</argument>
<description>
</description>
</method>
<method name="create_handle_material">
<return type="void">
</return>
<argument index="0" name="name" type="String">
</argument>
<argument index="1" name="billboard" type="bool" default="false">
</argument>
<description>
</description>
</method>
<method name="create_icon_material">
<return type="void">
</return>
<argument index="0" name="name" type="String">
</argument>
<argument index="1" name="texture" type="Texture">
</argument>
<argument index="2" name="on_top" type="bool" default="false">
</argument>
<argument index="3" name="color" type="Color" default="Color( 1, 1, 1, 1 )">
</argument>
<description>
</description>
</method>
<method name="create_material">
<return type="void">
</return>
<argument index="0" name="name" type="String">
</argument>
<argument index="1" name="color" type="Color">
</argument>
<argument index="2" name="billboard" type="bool" default="false">
</argument>
<argument index="3" name="on_top" type="bool" default="false">
</argument>
<argument index="4" name="use_vertex_color" type="bool" default="false">
</argument>
<description>
</description>
</method>
<method name="get_handle_name" qualifiers="virtual">
<return type="String">
</return>
<argument index="0" name="gizmo" type="EditorSpatialGizmo">
</argument>
<argument index="1" name="index" type="int">
</argument>
<description>
</description>
</method>
<method name="get_handle_value" qualifiers="virtual">
<return type="Variant">
</return>
<argument index="0" name="gizmo" type="EditorSpatialGizmo">
</argument>
<argument index="1" name="index" type="int">
</argument>
<description>
</description>
</method>
<method name="get_material">
<return type="SpatialMaterial">
</return>
<argument index="0" name="name" type="String">
</argument>
<argument index="1" name="gizmo" type="EditorSpatialGizmo">
</argument>
<description>
</description>
</method>
<method name="get_name" qualifiers="virtual">
<return type="String">
</return>
<description>
</description>
</method>
<method name="has_gizmo" qualifiers="virtual">
<return type="bool">
</return>
<argument index="0" name="spatial" type="Spatial">
</argument>
<description>
</description>
</method>
<method name="is_gizmo_handle_highlighted" qualifiers="virtual">
<return type="bool">
</return>
<argument index="0" name="gizmo" type="EditorSpatialGizmo">
</argument>
<argument index="1" name="index" type="int">
</argument>
<description>
</description>
</method>
<method name="is_selectable_when_hidden" qualifiers="virtual">
<return type="bool">
</return>
<description>
</description>
</method>
<method name="redraw" qualifiers="virtual">
<return type="void">
</return>
<argument index="0" name="gizmo" type="EditorSpatialGizmo">
</argument>
<description>
</description>
</method>
<method name="set_handle" qualifiers="virtual">
<return type="void">
</return>
<argument index="0" name="gizmo" type="EditorSpatialGizmo">
</argument>
<argument index="1" name="index" type="int">
</argument>
<argument index="2" name="camera" type="Camera">
</argument>
<argument index="3" name="point" type="Vector2">
</argument>
<description>
</description>
</method>
</methods>
<constants>
</constants>
</class>

View File

@ -3091,6 +3091,7 @@ void EditorNode::register_editor_types() {
ClassDB::register_class<EditorFileDialog>(); ClassDB::register_class<EditorFileDialog>();
ClassDB::register_virtual_class<EditorSettings>(); ClassDB::register_virtual_class<EditorSettings>();
ClassDB::register_class<EditorSpatialGizmo>(); ClassDB::register_class<EditorSpatialGizmo>();
ClassDB::register_class<EditorSpatialGizmoPlugin>();
ClassDB::register_virtual_class<EditorResourcePreview>(); ClassDB::register_virtual_class<EditorResourcePreview>();
ClassDB::register_class<EditorResourcePreviewGenerator>(); ClassDB::register_class<EditorResourcePreviewGenerator>();
ClassDB::register_virtual_class<EditorFileSystem>(); ClassDB::register_virtual_class<EditorFileSystem>();

View File

@ -683,6 +683,14 @@ void EditorPlugin::remove_export_plugin(const Ref<EditorExportPlugin> &p_exporte
EditorExport::get_singleton()->remove_export_plugin(p_exporter); EditorExport::get_singleton()->remove_export_plugin(p_exporter);
} }
void EditorPlugin::add_spatial_gizmo_plugin(const Ref<EditorSpatialGizmoPlugin> &p_gizmo_plugin) {
SpatialEditor::get_singleton()->add_gizmo_plugin(p_gizmo_plugin);
}
void EditorPlugin::remove_spatial_gizmo_plugin(const Ref<EditorSpatialGizmoPlugin> &p_gizmo_plugin) {
SpatialEditor::get_singleton()->remove_gizmo_plugin(p_gizmo_plugin);
}
void EditorPlugin::add_inspector_plugin(const Ref<EditorInspectorPlugin> &p_plugin) { void EditorPlugin::add_inspector_plugin(const Ref<EditorInspectorPlugin> &p_plugin) {
EditorInspector::add_inspector_plugin(p_plugin); EditorInspector::add_inspector_plugin(p_plugin);
} }
@ -775,6 +783,8 @@ void EditorPlugin::_bind_methods() {
ClassDB::bind_method(D_METHOD("remove_scene_import_plugin", "scene_importer"), &EditorPlugin::remove_scene_import_plugin); ClassDB::bind_method(D_METHOD("remove_scene_import_plugin", "scene_importer"), &EditorPlugin::remove_scene_import_plugin);
ClassDB::bind_method(D_METHOD("add_export_plugin", "plugin"), &EditorPlugin::add_export_plugin); ClassDB::bind_method(D_METHOD("add_export_plugin", "plugin"), &EditorPlugin::add_export_plugin);
ClassDB::bind_method(D_METHOD("remove_export_plugin", "plugin"), &EditorPlugin::remove_export_plugin); ClassDB::bind_method(D_METHOD("remove_export_plugin", "plugin"), &EditorPlugin::remove_export_plugin);
ClassDB::bind_method(D_METHOD("add_spatial_gizmo_plugin", "plugin"), &EditorPlugin::add_spatial_gizmo_plugin);
ClassDB::bind_method(D_METHOD("remove_spatial_gizmo_plugin", "plugin"), &EditorPlugin::remove_spatial_gizmo_plugin);
ClassDB::bind_method(D_METHOD("add_inspector_plugin", "plugin"), &EditorPlugin::add_inspector_plugin); ClassDB::bind_method(D_METHOD("add_inspector_plugin", "plugin"), &EditorPlugin::add_inspector_plugin);
ClassDB::bind_method(D_METHOD("remove_inspector_plugin", "plugin"), &EditorPlugin::remove_inspector_plugin); ClassDB::bind_method(D_METHOD("remove_inspector_plugin", "plugin"), &EditorPlugin::remove_inspector_plugin);
ClassDB::bind_method(D_METHOD("set_input_event_forwarding_always_enabled"), &EditorPlugin::set_input_event_forwarding_always_enabled); ClassDB::bind_method(D_METHOD("set_input_event_forwarding_always_enabled"), &EditorPlugin::set_input_event_forwarding_always_enabled);

View File

@ -53,6 +53,7 @@ class EditorExport;
class EditorSettings; class EditorSettings;
class EditorImportPlugin; class EditorImportPlugin;
class EditorExportPlugin; class EditorExportPlugin;
class EditorSpatialGizmoPlugin;
class EditorResourcePreview; class EditorResourcePreview;
class EditorFileSystem; class EditorFileSystem;
class EditorToolAddons; class EditorToolAddons;
@ -219,6 +220,9 @@ public:
void add_export_plugin(const Ref<EditorExportPlugin> &p_exporter); void add_export_plugin(const Ref<EditorExportPlugin> &p_exporter);
void remove_export_plugin(const Ref<EditorExportPlugin> &p_exporter); void remove_export_plugin(const Ref<EditorExportPlugin> &p_exporter);
void add_spatial_gizmo_plugin(const Ref<EditorSpatialGizmoPlugin> &p_gizmo_plugin);
void remove_spatial_gizmo_plugin(const Ref<EditorSpatialGizmoPlugin> &p_gizmo_plugin);
void add_inspector_plugin(const Ref<EditorInspectorPlugin> &p_plugin); void add_inspector_plugin(const Ref<EditorInspectorPlugin> &p_plugin);
void remove_inspector_plugin(const Ref<EditorInspectorPlugin> &p_plugin); void remove_inspector_plugin(const Ref<EditorInspectorPlugin> &p_plugin);

View File

@ -563,7 +563,7 @@ PathEditorPlugin::PathEditorPlugin(EditorNode *p_node) {
Ref<PathSpatialGizmoPlugin> gizmo_plugin; Ref<PathSpatialGizmoPlugin> gizmo_plugin;
gizmo_plugin.instance(); gizmo_plugin.instance();
SpatialEditor::get_singleton()->register_gizmo_plugin(gizmo_plugin); SpatialEditor::get_singleton()->add_gizmo_plugin(gizmo_plugin);
sep = memnew(VSeparator); sep = memnew(VSeparator);
sep->hide(); sep->hide();

View File

@ -4818,9 +4818,9 @@ struct _GizmoPluginComparator {
} }
}; };
void SpatialEditor::_init_gizmos_menu() { void SpatialEditor::_update_gizmos_menu() {
_register_all_gizmos();
gizmos_menu->clear();
gizmo_plugins.sort_custom<_GizmoPluginComparator>(); gizmo_plugins.sort_custom<_GizmoPluginComparator>();
for (int i = 0; i < gizmo_plugins.size(); ++i) { for (int i = 0; i < gizmo_plugins.size(); ++i) {
@ -5124,7 +5124,8 @@ void SpatialEditor::_notification(int p_what) {
if (p_what == NOTIFICATION_ENTER_TREE) { if (p_what == NOTIFICATION_ENTER_TREE) {
_init_gizmos_menu(); _register_all_gizmos();
_update_gizmos_menu();
_init_indicators(); _init_indicators();
} }
@ -5260,27 +5261,27 @@ void SpatialEditor::_node_removed(Node *p_node) {
} }
void SpatialEditor::_register_all_gizmos() { void SpatialEditor::_register_all_gizmos() {
register_gizmo_plugin(Ref<CameraSpatialGizmoPlugin>(memnew(CameraSpatialGizmoPlugin))); add_gizmo_plugin(Ref<CameraSpatialGizmoPlugin>(memnew(CameraSpatialGizmoPlugin)));
register_gizmo_plugin(Ref<LightSpatialGizmoPlugin>(memnew(LightSpatialGizmoPlugin))); add_gizmo_plugin(Ref<LightSpatialGizmoPlugin>(memnew(LightSpatialGizmoPlugin)));
register_gizmo_plugin(Ref<AudioStreamPlayer3DSpatialGizmoPlugin>(memnew(AudioStreamPlayer3DSpatialGizmoPlugin))); add_gizmo_plugin(Ref<AudioStreamPlayer3DSpatialGizmoPlugin>(memnew(AudioStreamPlayer3DSpatialGizmoPlugin)));
register_gizmo_plugin(Ref<MeshInstanceSpatialGizmoPlugin>(memnew(MeshInstanceSpatialGizmoPlugin))); add_gizmo_plugin(Ref<MeshInstanceSpatialGizmoPlugin>(memnew(MeshInstanceSpatialGizmoPlugin)));
register_gizmo_plugin(Ref<SoftBodySpatialGizmoPlugin>(memnew(SoftBodySpatialGizmoPlugin))); add_gizmo_plugin(Ref<SoftBodySpatialGizmoPlugin>(memnew(SoftBodySpatialGizmoPlugin)));
register_gizmo_plugin(Ref<Sprite3DSpatialGizmoPlugin>(memnew(Sprite3DSpatialGizmoPlugin))); add_gizmo_plugin(Ref<Sprite3DSpatialGizmoPlugin>(memnew(Sprite3DSpatialGizmoPlugin)));
register_gizmo_plugin(Ref<SkeletonSpatialGizmoPlugin>(memnew(SkeletonSpatialGizmoPlugin))); add_gizmo_plugin(Ref<SkeletonSpatialGizmoPlugin>(memnew(SkeletonSpatialGizmoPlugin)));
register_gizmo_plugin(Ref<Position3DSpatialGizmoPlugin>(memnew(Position3DSpatialGizmoPlugin))); add_gizmo_plugin(Ref<Position3DSpatialGizmoPlugin>(memnew(Position3DSpatialGizmoPlugin)));
register_gizmo_plugin(Ref<RayCastSpatialGizmoPlugin>(memnew(RayCastSpatialGizmoPlugin))); add_gizmo_plugin(Ref<RayCastSpatialGizmoPlugin>(memnew(RayCastSpatialGizmoPlugin)));
register_gizmo_plugin(Ref<SpringArmSpatialGizmoPlugin>(memnew(SpringArmSpatialGizmoPlugin))); add_gizmo_plugin(Ref<SpringArmSpatialGizmoPlugin>(memnew(SpringArmSpatialGizmoPlugin)));
register_gizmo_plugin(Ref<VehicleWheelSpatialGizmoPlugin>(memnew(VehicleWheelSpatialGizmoPlugin))); add_gizmo_plugin(Ref<VehicleWheelSpatialGizmoPlugin>(memnew(VehicleWheelSpatialGizmoPlugin)));
register_gizmo_plugin(Ref<VisibilityNotifierGizmoPlugin>(memnew(VisibilityNotifierGizmoPlugin))); add_gizmo_plugin(Ref<VisibilityNotifierGizmoPlugin>(memnew(VisibilityNotifierGizmoPlugin)));
register_gizmo_plugin(Ref<ParticlesGizmoPlugin>(memnew(ParticlesGizmoPlugin))); add_gizmo_plugin(Ref<ParticlesGizmoPlugin>(memnew(ParticlesGizmoPlugin)));
register_gizmo_plugin(Ref<ReflectionProbeGizmoPlugin>(memnew(ReflectionProbeGizmoPlugin))); add_gizmo_plugin(Ref<ReflectionProbeGizmoPlugin>(memnew(ReflectionProbeGizmoPlugin)));
register_gizmo_plugin(Ref<GIProbeGizmoPlugin>(memnew(GIProbeGizmoPlugin))); add_gizmo_plugin(Ref<GIProbeGizmoPlugin>(memnew(GIProbeGizmoPlugin)));
register_gizmo_plugin(Ref<BakedIndirectLightGizmoPlugin>(memnew(BakedIndirectLightGizmoPlugin))); add_gizmo_plugin(Ref<BakedIndirectLightGizmoPlugin>(memnew(BakedIndirectLightGizmoPlugin)));
register_gizmo_plugin(Ref<CollisionShapeSpatialGizmoPlugin>(memnew(CollisionShapeSpatialGizmoPlugin))); add_gizmo_plugin(Ref<CollisionShapeSpatialGizmoPlugin>(memnew(CollisionShapeSpatialGizmoPlugin)));
register_gizmo_plugin(Ref<CollisionPolygonSpatialGizmoPlugin>(memnew(CollisionPolygonSpatialGizmoPlugin))); add_gizmo_plugin(Ref<CollisionPolygonSpatialGizmoPlugin>(memnew(CollisionPolygonSpatialGizmoPlugin)));
register_gizmo_plugin(Ref<NavigationMeshSpatialGizmoPlugin>(memnew(NavigationMeshSpatialGizmoPlugin))); add_gizmo_plugin(Ref<NavigationMeshSpatialGizmoPlugin>(memnew(NavigationMeshSpatialGizmoPlugin)));
register_gizmo_plugin(Ref<JointSpatialGizmoPlugin>(memnew(JointSpatialGizmoPlugin))); add_gizmo_plugin(Ref<JointSpatialGizmoPlugin>(memnew(JointSpatialGizmoPlugin)));
register_gizmo_plugin(Ref<PhysicalBoneSpatialGizmoPlugin>(memnew(PhysicalBoneSpatialGizmoPlugin))); add_gizmo_plugin(Ref<PhysicalBoneSpatialGizmoPlugin>(memnew(PhysicalBoneSpatialGizmoPlugin)));
} }
void SpatialEditor::_bind_methods() { void SpatialEditor::_bind_methods() {
@ -5715,8 +5716,15 @@ void SpatialEditorPlugin::snap_cursor_to_plane(const Plane &p_plane) {
spatial_editor->snap_cursor_to_plane(p_plane); spatial_editor->snap_cursor_to_plane(p_plane);
} }
void SpatialEditor::register_gizmo_plugin(Ref<EditorSpatialGizmoPlugin> ref) { void SpatialEditor::add_gizmo_plugin(Ref<EditorSpatialGizmoPlugin> p_plugin) {
gizmo_plugins.push_back(ref); gizmo_plugins.push_back(p_plugin);
_update_gizmos_menu();
SpatialEditor::get_singleton()->update_all_gizmos();
}
void SpatialEditor::remove_gizmo_plugin(Ref<EditorSpatialGizmoPlugin> p_plugin) {
gizmo_plugins.erase(p_plugin);
_update_gizmos_menu();
} }
SpatialEditorPlugin::SpatialEditorPlugin(EditorNode *p_node) { SpatialEditorPlugin::SpatialEditorPlugin(EditorNode *p_node) {
@ -5842,11 +5850,11 @@ void EditorSpatialGizmoPlugin::add_material(const String &p_name, Ref<SpatialMat
materials[p_name].push_back(p_material); materials[p_name].push_back(p_material);
} }
Ref<SpatialMaterial> EditorSpatialGizmoPlugin::get_material(const String &p_name, EditorSpatialGizmo *p_gizmo) { Ref<SpatialMaterial> EditorSpatialGizmoPlugin::get_material(const String &p_name, const Ref<EditorSpatialGizmo> &p_gizmo) {
ERR_FAIL_COND_V(!materials.has(p_name), Ref<SpatialMaterial>()); ERR_FAIL_COND_V(!materials.has(p_name), Ref<SpatialMaterial>());
ERR_FAIL_COND_V(materials[p_name].size() == 0, Ref<SpatialMaterial>()); ERR_FAIL_COND_V(materials[p_name].size() == 0, Ref<SpatialMaterial>());
if (p_gizmo == NULL) return materials[p_name][0]; if (p_gizmo.is_null()) return materials[p_name][0];
int index = (p_gizmo->is_selected() ? 1 : 0) + (p_gizmo->is_editable() ? 2 : 0); int index = (p_gizmo->is_selected() ? 1 : 0) + (p_gizmo->is_editable() ? 2 : 0);
@ -5861,8 +5869,19 @@ Ref<SpatialMaterial> EditorSpatialGizmoPlugin::get_material(const String &p_name
return mat; return mat;
} }
String EditorSpatialGizmoPlugin::get_name() const {
if (get_script_instance() && get_script_instance()->has_method("get_name")) {
return get_script_instance()->call("get_name");
}
return TTR("Name-less gizmo");
}
Ref<EditorSpatialGizmo> EditorSpatialGizmoPlugin::get_gizmo(Spatial *p_spatial) { Ref<EditorSpatialGizmo> EditorSpatialGizmoPlugin::get_gizmo(Spatial *p_spatial) {
if (get_script_instance() && get_script_instance()->has_method("get_gizmo")) {
return get_script_instance()->call("get_gizmo", p_spatial);
}
Ref<EditorSpatialGizmo> ref = create_gizmo(p_spatial); Ref<EditorSpatialGizmo> ref = create_gizmo(p_spatial);
if (ref.is_null()) return ref; if (ref.is_null()) return ref;
@ -5875,22 +5894,109 @@ Ref<EditorSpatialGizmo> EditorSpatialGizmoPlugin::get_gizmo(Spatial *p_spatial)
return ref; return ref;
} }
void EditorSpatialGizmoPlugin::_bind_methods() {
#define GIZMO_REF PropertyInfo(Variant::OBJECT, "gizmo", PROPERTY_HINT_RESOURCE_TYPE, "EditorSpatialGizmo")
BIND_VMETHOD(MethodInfo(Variant::BOOL, "has_gizmo", PropertyInfo(Variant::OBJECT, "spatial", PROPERTY_HINT_RESOURCE_TYPE, "Spatial")));
BIND_VMETHOD(MethodInfo(GIZMO_REF, "create_gizmo", PropertyInfo(Variant::OBJECT, "spatial", PROPERTY_HINT_RESOURCE_TYPE, "Spatial")));
ClassDB::bind_method(D_METHOD("create_material", "name", "color", "billboard", "on_top", "use_vertex_color"), &EditorSpatialGizmoPlugin::create_material, DEFVAL(false), DEFVAL(false), DEFVAL(false));
ClassDB::bind_method(D_METHOD("create_icon_material", "name", "texture", "on_top", "color"), &EditorSpatialGizmoPlugin::create_icon_material, DEFVAL(false), DEFVAL(Color(1, 1, 1, 1)));
ClassDB::bind_method(D_METHOD("create_handle_material", "name", "billboard"), &EditorSpatialGizmoPlugin::create_handle_material, DEFVAL(false));
ClassDB::bind_method(D_METHOD("add_material", "name", "material"), &EditorSpatialGizmoPlugin::add_material);
ClassDB::bind_method(D_METHOD("get_material", "name", "gizmo"), &EditorSpatialGizmoPlugin::get_material); //, DEFVAL(Ref<EditorSpatialGizmo>()));
BIND_VMETHOD(MethodInfo(Variant::STRING, "get_name"));
BIND_VMETHOD(MethodInfo(Variant::BOOL, "can_be_hidden"));
BIND_VMETHOD(MethodInfo(Variant::BOOL, "is_selectable_when_hidden"));
BIND_VMETHOD(MethodInfo("redraw", GIZMO_REF));
BIND_VMETHOD(MethodInfo(Variant::STRING, "get_handle_name", GIZMO_REF, PropertyInfo(Variant::INT, "index")));
MethodInfo hvget(Variant::NIL, "get_handle_value", GIZMO_REF, PropertyInfo(Variant::INT, "index"));
hvget.return_val.usage |= PROPERTY_USAGE_NIL_IS_VARIANT;
BIND_VMETHOD(hvget);
BIND_VMETHOD(MethodInfo("set_handle", GIZMO_REF, PropertyInfo(Variant::INT, "index"), PropertyInfo(Variant::OBJECT, "camera", PROPERTY_HINT_RESOURCE_TYPE, "Camera"), PropertyInfo(Variant::VECTOR2, "point")));
MethodInfo cm = MethodInfo("commit_handle", GIZMO_REF, PropertyInfo(Variant::INT, "index"), PropertyInfo(Variant::NIL, "restore"), PropertyInfo(Variant::BOOL, "cancel"));
cm.default_arguments.push_back(false);
BIND_VMETHOD(cm);
BIND_VMETHOD(MethodInfo(Variant::BOOL, "is_gizmo_handle_highlighted", GIZMO_REF, PropertyInfo(Variant::INT, "index")));
#undef GIZMO_REF
}
bool EditorSpatialGizmoPlugin::has_gizmo(Spatial *p_spatial) { bool EditorSpatialGizmoPlugin::has_gizmo(Spatial *p_spatial) {
if (get_script_instance() && get_script_instance()->has_method("has_gizmo")) {
return get_script_instance()->call("has_gizmo", p_spatial);
}
return false; return false;
} }
Ref<EditorSpatialGizmo> EditorSpatialGizmoPlugin::create_gizmo(Spatial *p_spatial) { Ref<EditorSpatialGizmo> EditorSpatialGizmoPlugin::create_gizmo(Spatial *p_spatial) {
if (get_script_instance() && get_script_instance()->has_method("create_gizmo")) {
return get_script_instance()->call("create_gizmo", p_spatial);
}
Ref<EditorSpatialGizmo> ref; Ref<EditorSpatialGizmo> ref;
if (has_gizmo(p_spatial)) ref.instance(); if (has_gizmo(p_spatial)) ref.instance();
return ref; return ref;
} }
bool EditorSpatialGizmoPlugin::can_be_hidden() const { bool EditorSpatialGizmoPlugin::can_be_hidden() const {
if (get_script_instance() && get_script_instance()->has_method("can_be_hidden")) {
return get_script_instance()->call("can_be_hidden");
}
return true; return true;
} }
bool EditorSpatialGizmoPlugin::is_selectable_when_hidden() const { bool EditorSpatialGizmoPlugin::is_selectable_when_hidden() const {
if (get_script_instance() && get_script_instance()->has_method("is_selectable_when_hidden")) {
return get_script_instance()->call("is_selectable_when_hidden");
}
return false;
}
void EditorSpatialGizmoPlugin::redraw(EditorSpatialGizmo *p_gizmo) {
if (get_script_instance() && get_script_instance()->has_method("redraw")) {
Ref<EditorSpatialGizmo> ref(p_gizmo);
get_script_instance()->call("redraw", ref);
}
}
String EditorSpatialGizmoPlugin::get_handle_name(const EditorSpatialGizmo *p_gizmo, int p_idx) const {
if (get_script_instance() && get_script_instance()->has_method("get_handle_name")) {
return get_script_instance()->call("get_handle_name", p_gizmo, p_idx);
}
return "";
}
Variant EditorSpatialGizmoPlugin::get_handle_value(EditorSpatialGizmo *p_gizmo, int p_idx) const {
if (get_script_instance() && get_script_instance()->has_method("get_handle_value")) {
return get_script_instance()->call("get_handle_value", p_gizmo, p_idx);
}
return Variant();
}
void EditorSpatialGizmoPlugin::set_handle(EditorSpatialGizmo *p_gizmo, int p_idx, Camera *p_camera, const Point2 &p_point) {
if (get_script_instance() && get_script_instance()->has_method("set_handle")) {
get_script_instance()->call("set_handle", p_gizmo, p_idx, p_camera, p_point);
}
}
void EditorSpatialGizmoPlugin::commit_handle(EditorSpatialGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel) {
if (get_script_instance() && get_script_instance()->has_method("commit_handle")) {
get_script_instance()->call("commit_handle", p_gizmo, p_idx, p_restore, p_cancel);
}
}
bool EditorSpatialGizmoPlugin::is_gizmo_handle_highlighted(const EditorSpatialGizmo *p_gizmo, int p_idx) const {
if (get_script_instance() && get_script_instance()->has_method("is_gizmo_handle_highlighted")) {
return get_script_instance()->call("is_gizmo_handle_highlighted", p_gizmo, p_idx);
}
return false; return false;
} }
@ -5910,4 +6016,9 @@ EditorSpatialGizmoPlugin::EditorSpatialGizmoPlugin() {
} }
EditorSpatialGizmoPlugin::~EditorSpatialGizmoPlugin() { EditorSpatialGizmoPlugin::~EditorSpatialGizmoPlugin() {
for (int i = 0; i < current_gizmos.size(); ++i) {
current_gizmos[i]->set_plugin(NULL);
current_gizmos[i]->get_spatial_node()->set_gizmo(NULL);
}
SpatialEditor::get_singleton()->update_all_gizmos();
} }

View File

@ -615,7 +615,7 @@ private:
void _instance_scene(); void _instance_scene();
void _init_indicators(); void _init_indicators();
void _init_gizmos_menu(); void _update_gizmos_menu();
void _init_grid(); void _init_grid();
void _finish_indicators(); void _finish_indicators();
void _finish_grid(); void _finish_grid();
@ -710,7 +710,8 @@ public:
return viewports[p_idx]; return viewports[p_idx];
} }
void register_gizmo_plugin(Ref<EditorSpatialGizmoPlugin> ref); void add_gizmo_plugin(Ref<EditorSpatialGizmoPlugin> p_plugin);
void remove_gizmo_plugin(Ref<EditorSpatialGizmoPlugin> p_plugin);
void edit(Spatial *p_spatial); void edit(Spatial *p_spatial);
void clear(); void clear();
@ -764,6 +765,7 @@ private:
HashMap<String, Vector<Ref<SpatialMaterial> > > materials; HashMap<String, Vector<Ref<SpatialMaterial> > > materials;
protected: protected:
static void _bind_methods();
virtual bool has_gizmo(Spatial *p_spatial); virtual bool has_gizmo(Spatial *p_spatial);
virtual Ref<EditorSpatialGizmo> create_gizmo(Spatial *p_spatial); virtual Ref<EditorSpatialGizmo> create_gizmo(Spatial *p_spatial);
@ -773,18 +775,18 @@ public:
void create_handle_material(const String &p_name, bool p_billboard = false); void create_handle_material(const String &p_name, bool p_billboard = false);
void add_material(const String &p_name, Ref<SpatialMaterial> p_material); void add_material(const String &p_name, Ref<SpatialMaterial> p_material);
Ref<SpatialMaterial> get_material(const String &p_name, EditorSpatialGizmo *p_gizmo = NULL); Ref<SpatialMaterial> get_material(const String &p_name, const Ref<EditorSpatialGizmo> &p_gizmo = Ref<EditorSpatialGizmo>());
virtual String get_name() const = 0; virtual String get_name() const;
virtual bool can_be_hidden() const; virtual bool can_be_hidden() const;
virtual bool is_selectable_when_hidden() const; virtual bool is_selectable_when_hidden() const;
virtual void redraw(EditorSpatialGizmo *p_gizmo) {} virtual void redraw(EditorSpatialGizmo *p_gizmo);
virtual String get_handle_name(const EditorSpatialGizmo *p_gizmo, int p_idx) const { return ""; } virtual String get_handle_name(const EditorSpatialGizmo *p_gizmo, int p_idx) const;
virtual Variant get_handle_value(EditorSpatialGizmo *p_gizmo, int p_idx) const { return Variant(); } virtual Variant get_handle_value(EditorSpatialGizmo *p_gizmo, int p_idx) const;
virtual void set_handle(EditorSpatialGizmo *p_gizmo, int p_idx, Camera *p_camera, const Point2 &p_point) {} virtual void set_handle(EditorSpatialGizmo *p_gizmo, int p_idx, Camera *p_camera, const Point2 &p_point);
virtual void commit_handle(EditorSpatialGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel = false) {} virtual void commit_handle(EditorSpatialGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel = false);
virtual bool is_gizmo_handle_highlighted(const EditorSpatialGizmo *p_gizmo, int idx) const { return false; } virtual bool is_gizmo_handle_highlighted(const EditorSpatialGizmo *p_gizmo, int p_idx) const;
Ref<EditorSpatialGizmo> get_gizmo(Spatial *p_spatial); Ref<EditorSpatialGizmo> get_gizmo(Spatial *p_spatial);
void set_state(int p_state); void set_state(int p_state);

View File

@ -356,5 +356,5 @@ void CSGShapeSpatialGizmoPlugin::redraw(EditorSpatialGizmo *p_gizmo) {
EditorPluginCSG::EditorPluginCSG(EditorNode *p_editor) { EditorPluginCSG::EditorPluginCSG(EditorNode *p_editor) {
Ref<CSGShapeSpatialGizmoPlugin> gizmo_plugin = Ref<CSGShapeSpatialGizmoPlugin>(memnew(CSGShapeSpatialGizmoPlugin)); Ref<CSGShapeSpatialGizmoPlugin> gizmo_plugin = Ref<CSGShapeSpatialGizmoPlugin>(memnew(CSGShapeSpatialGizmoPlugin));
SpatialEditor::get_singleton()->register_gizmo_plugin(gizmo_plugin); SpatialEditor::get_singleton()->add_gizmo_plugin(gizmo_plugin);
} }

View File

@ -138,6 +138,8 @@ void MeshInstance::set_mesh(const Ref<Mesh> &p_mesh) {
set_base(RID()); set_base(RID());
} }
update_gizmo();
_change_notify(); _change_notify();
} }
Ref<Mesh> MeshInstance::get_mesh() const { Ref<Mesh> MeshInstance::get_mesh() const {

View File

@ -32,6 +32,7 @@
#include "core/engine.h" #include "core/engine.h"
#include "core/message_queue.h" #include "core/message_queue.h"
#include "scene/main/scene_tree.h"
#include "scene/main/viewport.h" #include "scene/main/viewport.h"
#include "scene/scene_string_names.h" #include "scene/scene_string_names.h"
@ -400,6 +401,8 @@ void Spatial::update_gizmo() {
#ifdef TOOLS_ENABLED #ifdef TOOLS_ENABLED
if (!is_inside_world()) if (!is_inside_world())
return; return;
if (!data.gizmo.is_valid())
get_tree()->call_group_flags(SceneTree::GROUP_CALL_REALTIME, SceneStringNames::get_singleton()->_spatial_editor_group, SceneStringNames::get_singleton()->_request_gizmo, this);
if (!data.gizmo.is_valid()) if (!data.gizmo.is_valid())
return; return;
if (data.gizmo_dirty) if (data.gizmo_dirty)