| 1 | /**************************************************************************/ | 
|---|
| 2 | /*  camera_3d_editor_plugin.cpp                                           */ | 
|---|
| 3 | /**************************************************************************/ | 
|---|
| 4 | /*                         This file is part of:                          */ | 
|---|
| 5 | /*                             GODOT ENGINE                               */ | 
|---|
| 6 | /*                        https://godotengine.org                         */ | 
|---|
| 7 | /**************************************************************************/ | 
|---|
| 8 | /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ | 
|---|
| 9 | /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur.                  */ | 
|---|
| 10 | /*                                                                        */ | 
|---|
| 11 | /* Permission is hereby granted, free of charge, to any person obtaining  */ | 
|---|
| 12 | /* a copy of this software and associated documentation files (the        */ | 
|---|
| 13 | /* "Software"), to deal in the Software without restriction, including    */ | 
|---|
| 14 | /* without limitation the rights to use, copy, modify, merge, publish,    */ | 
|---|
| 15 | /* distribute, sublicense, and/or sell copies of the Software, and to     */ | 
|---|
| 16 | /* permit persons to whom the Software is furnished to do so, subject to  */ | 
|---|
| 17 | /* the following conditions:                                              */ | 
|---|
| 18 | /*                                                                        */ | 
|---|
| 19 | /* The above copyright notice and this permission notice shall be         */ | 
|---|
| 20 | /* included in all copies or substantial portions of the Software.        */ | 
|---|
| 21 | /*                                                                        */ | 
|---|
| 22 | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,        */ | 
|---|
| 23 | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF     */ | 
|---|
| 24 | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ | 
|---|
| 25 | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY   */ | 
|---|
| 26 | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,   */ | 
|---|
| 27 | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE      */ | 
|---|
| 28 | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                 */ | 
|---|
| 29 | /**************************************************************************/ | 
|---|
| 30 |  | 
|---|
| 31 | #include "camera_3d_editor_plugin.h" | 
|---|
| 32 |  | 
|---|
| 33 | #include "editor/editor_node.h" | 
|---|
| 34 | #include "node_3d_editor_plugin.h" | 
|---|
| 35 |  | 
|---|
| 36 | void Camera3DEditor::_node_removed(Node *p_node) { | 
|---|
| 37 | if (p_node == node) { | 
|---|
| 38 | node = nullptr; | 
|---|
| 39 | Node3DEditor::get_singleton()->set_custom_camera(nullptr); | 
|---|
| 40 | hide(); | 
|---|
| 41 | } | 
|---|
| 42 | } | 
|---|
| 43 |  | 
|---|
| 44 | void Camera3DEditor::_pressed() { | 
|---|
| 45 | Node *sn = (node && preview->is_pressed()) ? node : nullptr; | 
|---|
| 46 | Node3DEditor::get_singleton()->set_custom_camera(sn); | 
|---|
| 47 | } | 
|---|
| 48 |  | 
|---|
| 49 | void Camera3DEditor::_bind_methods() { | 
|---|
| 50 | } | 
|---|
| 51 |  | 
|---|
| 52 | void Camera3DEditor::edit(Node *p_camera) { | 
|---|
| 53 | node = p_camera; | 
|---|
| 54 |  | 
|---|
| 55 | if (!node) { | 
|---|
| 56 | preview->set_pressed(false); | 
|---|
| 57 | Node3DEditor::get_singleton()->set_custom_camera(nullptr); | 
|---|
| 58 | } else { | 
|---|
| 59 | if (preview->is_pressed()) { | 
|---|
| 60 | Node3DEditor::get_singleton()->set_custom_camera(p_camera); | 
|---|
| 61 | } else { | 
|---|
| 62 | Node3DEditor::get_singleton()->set_custom_camera(nullptr); | 
|---|
| 63 | } | 
|---|
| 64 | } | 
|---|
| 65 | } | 
|---|
| 66 |  | 
|---|
| 67 | Camera3DEditor::Camera3DEditor() { | 
|---|
| 68 | preview = memnew(Button); | 
|---|
| 69 | add_child(preview); | 
|---|
| 70 |  | 
|---|
| 71 | preview->set_text(TTR( "Preview")); | 
|---|
| 72 | preview->set_toggle_mode(true); | 
|---|
| 73 | preview->set_anchor(SIDE_LEFT, Control::ANCHOR_END); | 
|---|
| 74 | preview->set_anchor(SIDE_RIGHT, Control::ANCHOR_END); | 
|---|
| 75 | preview->set_offset(SIDE_LEFT, -60); | 
|---|
| 76 | preview->set_offset(SIDE_RIGHT, 0); | 
|---|
| 77 | preview->set_offset(SIDE_TOP, 0); | 
|---|
| 78 | preview->set_offset(SIDE_BOTTOM, 10); | 
|---|
| 79 | preview->connect( "pressed", callable_mp(this, &Camera3DEditor::_pressed)); | 
|---|
| 80 | } | 
|---|
| 81 |  | 
|---|
| 82 | void Camera3DEditorPlugin::edit(Object *p_object) { | 
|---|
| 83 | Node3DEditor::get_singleton()->set_can_preview(Object::cast_to<Camera3D>(p_object)); | 
|---|
| 84 | //camera_editor->edit(Object::cast_to<Node>(p_object)); | 
|---|
| 85 | } | 
|---|
| 86 |  | 
|---|
| 87 | bool Camera3DEditorPlugin::handles(Object *p_object) const { | 
|---|
| 88 | return p_object->is_class( "Camera3D"); | 
|---|
| 89 | } | 
|---|
| 90 |  | 
|---|
| 91 | void Camera3DEditorPlugin::make_visible(bool p_visible) { | 
|---|
| 92 | if (p_visible) { | 
|---|
| 93 | //Node3DEditor::get_singleton()->set_can_preview(Object::cast_to<Camera3D>(p_object)); | 
|---|
| 94 | } else { | 
|---|
| 95 | Node3DEditor::get_singleton()->set_can_preview(nullptr); | 
|---|
| 96 | } | 
|---|
| 97 | } | 
|---|
| 98 |  | 
|---|
| 99 | Camera3DEditorPlugin::Camera3DEditorPlugin() { | 
|---|
| 100 | /*	camera_editor = memnew( CameraEditor ); | 
|---|
| 101 | EditorNode::get_singleton()->get_main_screen_control()->add_child(camera_editor); | 
|---|
| 102 |  | 
|---|
| 103 | camera_editor->set_anchor(SIDE_LEFT,Control::ANCHOR_END); | 
|---|
| 104 | camera_editor->set_anchor(SIDE_RIGHT,Control::ANCHOR_END); | 
|---|
| 105 | camera_editor->set_offset(SIDE_LEFT,60); | 
|---|
| 106 | camera_editor->set_offset(SIDE_RIGHT,0); | 
|---|
| 107 | camera_editor->set_offset(SIDE_TOP,0); | 
|---|
| 108 | camera_editor->set_offset(SIDE_BOTTOM,10); | 
|---|
| 109 |  | 
|---|
| 110 |  | 
|---|
| 111 | camera_editor->hide(); | 
|---|
| 112 | */ | 
|---|
| 113 | } | 
|---|
| 114 |  | 
|---|
| 115 | Camera3DEditorPlugin::~Camera3DEditorPlugin() { | 
|---|
| 116 | } | 
|---|
| 117 |  | 
|---|