Path: blob/master/editor/scene/3d/gizmos/fog_volume_gizmo_plugin.cpp
9903 views
/**************************************************************************/1/* fog_volume_gizmo_plugin.cpp */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#include "fog_volume_gizmo_plugin.h"3132#include "editor/editor_node.h"33#include "editor/editor_string_names.h"34#include "editor/scene/3d/gizmos/gizmo_3d_helper.h"35#include "editor/settings/editor_settings.h"36#include "scene/3d/fog_volume.h"3738FogVolumeGizmoPlugin::FogVolumeGizmoPlugin() {39helper.instantiate();40Color gizmo_color = EDITOR_GET("editors/3d_gizmos/gizmo_colors/fog_volume");41create_material("shape_material", gizmo_color);42gizmo_color.a = 0.15;43create_material("shape_material_internal", gizmo_color);4445create_icon_material("fog_volume_icon", EditorNode::get_singleton()->get_editor_theme()->get_icon(SNAME("GizmoFogVolume"), EditorStringName(EditorIcons)));4647create_handle_material("handles");48}4950bool FogVolumeGizmoPlugin::has_gizmo(Node3D *p_spatial) {51return (Object::cast_to<FogVolume>(p_spatial) != nullptr);52}5354String FogVolumeGizmoPlugin::get_gizmo_name() const {55return "FogVolume";56}5758int FogVolumeGizmoPlugin::get_priority() const {59return -1;60}6162String FogVolumeGizmoPlugin::get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary) const {63return helper->box_get_handle_name(p_id);64}6566Variant FogVolumeGizmoPlugin::get_handle_value(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary) const {67return Vector3(p_gizmo->get_node_3d()->call("get_size"));68}6970void FogVolumeGizmoPlugin::begin_handle_action(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary) {71helper->initialize_handle_action(get_handle_value(p_gizmo, p_id, p_secondary), p_gizmo->get_node_3d()->get_global_transform());72}7374void FogVolumeGizmoPlugin::set_handle(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary, Camera3D *p_camera, const Point2 &p_point) {75FogVolume *fog_volume = Object::cast_to<FogVolume>(p_gizmo->get_node_3d());76Vector3 size = fog_volume->get_size();7778Vector3 sg[2];79helper->get_segment(p_camera, p_point, sg);8081Vector3 position;82helper->box_set_handle(sg, p_id, size, position);83fog_volume->set_size(size);84fog_volume->set_global_position(position);85}8687void FogVolumeGizmoPlugin::commit_handle(const EditorNode3DGizmo *p_gizmo, int p_id, bool p_secondary, const Variant &p_restore, bool p_cancel) {88helper->box_commit_handle(TTR("Change FogVolume Size"), p_cancel, p_gizmo->get_node_3d());89}9091void FogVolumeGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {92FogVolume *fog_volume = Object::cast_to<FogVolume>(p_gizmo->get_node_3d());9394p_gizmo->clear();9596if (fog_volume->get_shape() != RS::FOG_VOLUME_SHAPE_WORLD) {97const Ref<Material> material =98get_material("shape_material", p_gizmo);99const Ref<Material> material_internal =100get_material("shape_material_internal", p_gizmo);101102Ref<Material> handles_material = get_material("handles");103104Vector<Vector3> lines;105AABB aabb;106aabb.size = fog_volume->get_size();107aabb.position = aabb.size / -2;108109for (int i = 0; i < 12; i++) {110Vector3 a, b;111aabb.get_edge(i, a, b);112lines.push_back(a);113lines.push_back(b);114}115116Vector<Vector3> handles = helper->box_get_handles(fog_volume->get_size());117118p_gizmo->add_lines(lines, material);119p_gizmo->add_collision_segments(lines);120const Ref<Material> icon = get_material("fog_volume_icon", p_gizmo);121p_gizmo->add_unscaled_billboard(icon, 0.05);122p_gizmo->add_handles(handles, handles_material);123}124}125126127