mirror of
https://github.com/godotengine/godot.git
synced 2024-11-21 03:18:37 +08:00
d95bbb8922
Fixes the following GCC 5 warnings: ``` drivers/gles2/rasterizer_canvas_gles2.cpp:814:8: warning: variable 'rt_size' set but not used [-Wunused-but-set-variable] drivers/gles2/rasterizer_scene_gles2.cpp:2270:11: warning: variable 'vp_height' set but not used [-Wunused-but-set-variable] drivers/gles2/rasterizer_scene_gles2.cpp:2673:22: warning: variable 'e' set but not used [-Wunused-but-set-variable] drivers/gles2/rasterizer_scene_gles2.cpp:715:7: warning: variable 'no_cull' set but not used [-Wunused-but-set-variable] drivers/gles2/shader_gles2.cpp:693:14: warning: variable 'cc' set but not used [-Wunused-but-set-variable] drivers/gles3/rasterizer_canvas_gles3.cpp:1226:8: warning: variable 'rt_size' set but not used [-Wunused-but-set-variable] drivers/gles3/rasterizer_scene_gles3.cpp:3039:10: warning: variable 'contrib' set but not used [-Wunused-but-set-variable] drivers/gles3/rasterizer_scene_gles3.cpp:4504:32: warning: variable 'vp_height' set but not used [-Wunused-but-set-variable] editor/editor_inspector.cpp:272:9: warning: variable 'guide_color' set but not used [-Wunused-but-set-variable] editor/editor_themes.cpp:1067:14: warning: variable 'alpha3' set but not used [-Wunused-but-set-variable] editor/editor_themes.cpp:263:8: warning: variable 'script_bg_color' set but not used [-Wunused-but-set-variable] editor/plugins/collision_shape_2d_editor_plugin.cpp:326:11: warning: variable 'cpoint' set but not used [-Wunused-but-set-variable] editor/plugins/mesh_editor_plugin.cpp:72:9: warning: variable 'size' set but not used [-Wunused-but-set-variable] editor/plugins/shader_editor_plugin.cpp:471:12: warning: variable 'mpos' set but not used [-Wunused-but-set-variable] editor/plugins/shader_editor_plugin.cpp:89:8: warning: variable 'basetype_color' set but not used [-Wunused-but-set-variable] editor/plugins/shader_editor_plugin.cpp:90:8: warning: variable 'type_color' set but not used [-Wunused-but-set-variable] editor/plugins/shader_editor_plugin.cpp:92:8: warning: variable 'string_color' set but not used [-Wunused-but-set-variable] modules/visual_script/visual_script_editor.cpp:2521:7: warning: variable 'seq_connect' set but not used [-Wunused-but-set-variable] platform/android/export/export.cpp:580:12: warning: variable 'styles_count' set but not used [-Wunused-but-set-variable] platform/android/export/export.cpp:584:12: warning: variable 'styles_offset' set but not used [-Wunused-but-set-variable] platform/osx/export/export.cpp:464:9: warning: variable 'zerr' set but not used [-Wunused-but-set-variable] scene/2d/tile_map.cpp:260:10: warning: variable 'tcenter' set but not used [-Wunused-but-set-variable] scene/3d/light.cpp:166:7: warning: variable 'editor_ok' set but not used [-Wunused-but-set-variable] scene/3d/navigation.cpp:566:11: warning: variable 'closest_navmesh' set but not used [-Wunused-but-set-variable] scene/gui/rich_text_label.cpp:869:8: warning: variable 'size' set but not used [-Wunused-but-set-variable] scene/main/viewport.cpp:705:14: warning: variable 'xform' set but not used [-Wunused-but-set-variable] scene/main/viewport.cpp:706:8: warning: variable 'ss' set but not used [-Wunused-but-set-variable] scene/main/viewport.cpp:726:14: warning: variable 'xform' set but not used [-Wunused-but-set-variable] scene/main/viewport.cpp:727:8: warning: variable 'ss' set but not used [-Wunused-but-set-variable] scene/resources/material.cpp:430:7: warning: variable 'using_world' set but not used [-Wunused-but-set-variable] servers/visual/shader_language.cpp:2026:7: warning: variable 'all_const' set but not used [-Wunused-but-set-variable] servers/visual/visual_server_scene.cpp:1383:28: warning: variable 'z_max_cam' set but not used [-Wunused-but-set-variable] ``` Also fixes two [-Wunused-value] warnings: ``` scene/gui/text_edit.cpp:4405:20: warning: statement has no effect [-Wunused-value] servers/visual/visual_server_scene.cpp:905:48: warning: value computed is not used [-Wunused-value] ``` Some of those are bugs and need further work, they are identified with `// FIXME` comments.
215 lines
6.7 KiB
C++
215 lines
6.7 KiB
C++
/*************************************************************************/
|
|
/* mesh_editor_plugin.cpp */
|
|
/*************************************************************************/
|
|
/* This file is part of: */
|
|
/* GODOT ENGINE */
|
|
/* https://godotengine.org */
|
|
/*************************************************************************/
|
|
/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */
|
|
/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */
|
|
/* */
|
|
/* 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 "mesh_editor_plugin.h"
|
|
|
|
void MeshEditor::_gui_input(Ref<InputEvent> p_event) {
|
|
|
|
Ref<InputEventMouseMotion> mm = p_event;
|
|
if (mm.is_valid() && mm->get_button_mask() & BUTTON_MASK_LEFT) {
|
|
|
|
rot_x -= mm->get_relative().y * 0.01;
|
|
rot_y -= mm->get_relative().x * 0.01;
|
|
if (rot_x < -Math_PI / 2)
|
|
rot_x = -Math_PI / 2;
|
|
else if (rot_x > Math_PI / 2) {
|
|
rot_x = Math_PI / 2;
|
|
}
|
|
_update_rotation();
|
|
}
|
|
}
|
|
|
|
void MeshEditor::_notification(int p_what) {
|
|
|
|
if (p_what == NOTIFICATION_PHYSICS_PROCESS) {
|
|
}
|
|
|
|
if (p_what == NOTIFICATION_READY) {
|
|
|
|
//get_scene()->connect("node_removed",this,"_node_removed");
|
|
|
|
if (first_enter) {
|
|
//it's in propertyeditor so. could be moved around
|
|
|
|
light_1_switch->set_normal_texture(get_icon("MaterialPreviewLight1", "EditorIcons"));
|
|
light_1_switch->set_pressed_texture(get_icon("MaterialPreviewLight1Off", "EditorIcons"));
|
|
light_2_switch->set_normal_texture(get_icon("MaterialPreviewLight2", "EditorIcons"));
|
|
light_2_switch->set_pressed_texture(get_icon("MaterialPreviewLight2Off", "EditorIcons"));
|
|
first_enter = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
void MeshEditor::_update_rotation() {
|
|
|
|
Transform t;
|
|
t.basis.rotate(Vector3(0, 1, 0), -rot_y);
|
|
t.basis.rotate(Vector3(1, 0, 0), -rot_x);
|
|
rotation->set_transform(t);
|
|
}
|
|
|
|
void MeshEditor::edit(Ref<Mesh> p_mesh) {
|
|
|
|
mesh = p_mesh;
|
|
mesh_instance->set_mesh(mesh);
|
|
|
|
if (mesh.is_null()) {
|
|
|
|
hide();
|
|
} else {
|
|
rot_x = 0;
|
|
rot_y = 0;
|
|
_update_rotation();
|
|
|
|
AABB aabb = mesh->get_aabb();
|
|
Vector3 ofs = aabb.position + aabb.size * 0.5;
|
|
float m = aabb.get_longest_axis_size();
|
|
if (m != 0) {
|
|
m = 1.0 / m;
|
|
m *= 0.5;
|
|
Transform xform;
|
|
xform.basis.scale(Vector3(m, m, m));
|
|
xform.origin = -xform.basis.xform(ofs); //-ofs*m;
|
|
//xform.origin.z -= aabb.get_longest_axis_size() * 2;
|
|
mesh_instance->set_transform(xform);
|
|
}
|
|
}
|
|
}
|
|
|
|
void MeshEditor::_button_pressed(Node *p_button) {
|
|
|
|
if (p_button == light_1_switch) {
|
|
light1->set_visible(!light_1_switch->is_pressed());
|
|
}
|
|
|
|
if (p_button == light_2_switch) {
|
|
light2->set_visible(!light_2_switch->is_pressed());
|
|
}
|
|
}
|
|
|
|
void MeshEditor::_bind_methods() {
|
|
|
|
ClassDB::bind_method(D_METHOD("_gui_input"), &MeshEditor::_gui_input);
|
|
ClassDB::bind_method(D_METHOD("_button_pressed"), &MeshEditor::_button_pressed);
|
|
}
|
|
|
|
MeshEditor::MeshEditor() {
|
|
|
|
viewport = memnew(Viewport);
|
|
Ref<World> world;
|
|
world.instance();
|
|
viewport->set_world(world); //use own world
|
|
add_child(viewport);
|
|
viewport->set_disable_input(true);
|
|
set_stretch(true);
|
|
|
|
camera = memnew(Camera);
|
|
camera->set_transform(Transform(Basis(), Vector3(0, 0, 1.1)));
|
|
camera->set_perspective(45, 0.1, 10);
|
|
viewport->add_child(camera);
|
|
|
|
light1 = memnew(DirectionalLight);
|
|
light1->set_transform(Transform().looking_at(Vector3(-1, -1, -1), Vector3(0, 1, 0)));
|
|
viewport->add_child(light1);
|
|
|
|
light2 = memnew(DirectionalLight);
|
|
light2->set_transform(Transform().looking_at(Vector3(0, 1, 0), Vector3(0, 0, 1)));
|
|
light2->set_color(Color(0.7, 0.7, 0.7));
|
|
viewport->add_child(light2);
|
|
|
|
rotation = memnew(Spatial);
|
|
viewport->add_child(rotation);
|
|
mesh_instance = memnew(MeshInstance);
|
|
rotation->add_child(mesh_instance);
|
|
|
|
set_custom_minimum_size(Size2(1, 150) * EDSCALE);
|
|
|
|
HBoxContainer *hb = memnew(HBoxContainer);
|
|
add_child(hb);
|
|
hb->set_anchors_and_margins_preset(Control::PRESET_WIDE, Control::PRESET_MODE_MINSIZE, 2);
|
|
|
|
hb->add_spacer();
|
|
|
|
VBoxContainer *vb_light = memnew(VBoxContainer);
|
|
hb->add_child(vb_light);
|
|
|
|
light_1_switch = memnew(TextureButton);
|
|
light_1_switch->set_toggle_mode(true);
|
|
vb_light->add_child(light_1_switch);
|
|
light_1_switch->connect("pressed", this, "_button_pressed", varray(light_1_switch));
|
|
|
|
light_2_switch = memnew(TextureButton);
|
|
light_2_switch->set_toggle_mode(true);
|
|
vb_light->add_child(light_2_switch);
|
|
light_2_switch->connect("pressed", this, "_button_pressed", varray(light_2_switch));
|
|
|
|
first_enter = true;
|
|
|
|
rot_x = 0;
|
|
rot_y = 0;
|
|
}
|
|
|
|
void MeshEditorPlugin::edit(Object *p_object) {
|
|
|
|
Mesh *s = Object::cast_to<Mesh>(p_object);
|
|
if (!s)
|
|
return;
|
|
|
|
mesh_editor->edit(Ref<Mesh>(s));
|
|
}
|
|
|
|
bool MeshEditorPlugin::handles(Object *p_object) const {
|
|
|
|
return p_object->is_class("Mesh");
|
|
}
|
|
|
|
void MeshEditorPlugin::make_visible(bool p_visible) {
|
|
|
|
if (p_visible) {
|
|
mesh_editor->show();
|
|
//mesh_editor->set_process(true);
|
|
} else {
|
|
|
|
mesh_editor->hide();
|
|
//mesh_editor->set_process(false);
|
|
}
|
|
}
|
|
|
|
MeshEditorPlugin::MeshEditorPlugin(EditorNode *p_node) {
|
|
|
|
editor = p_node;
|
|
mesh_editor = memnew(MeshEditor);
|
|
add_control_to_container(CONTAINER_PROPERTY_EDITOR_BOTTOM, mesh_editor);
|
|
mesh_editor->hide();
|
|
}
|
|
|
|
MeshEditorPlugin::~MeshEditorPlugin() {
|
|
}
|