2015-10-08 20:00:40 +02:00
|
|
|
/*************************************************************************/
|
2020-03-27 08:44:44 +01:00
|
|
|
/* node_3d_editor_gizmos.cpp */
|
2015-10-08 20:00:40 +02:00
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 14:16:55 +02:00
|
|
|
/* https://godotengine.org */
|
2015-10-08 20:00:40 +02:00
|
|
|
/*************************************************************************/
|
2020-01-01 11:16:22 +01:00
|
|
|
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
|
2015-10-08 20:00:40 +02:00
|
|
|
/* */
|
|
|
|
/* 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. */
|
|
|
|
/*************************************************************************/
|
2018-01-05 00:50:27 +01:00
|
|
|
|
2020-03-27 08:44:44 +01:00
|
|
|
#include "node_3d_editor_gizmos.h"
|
2017-01-16 08:04:19 +01:00
|
|
|
|
2020-05-25 19:20:45 +02:00
|
|
|
#include "core/math/geometry_2d.h"
|
|
|
|
#include "core/math/geometry_3d.h"
|
2018-09-11 18:13:45 +02:00
|
|
|
#include "core/math/quick_hull.h"
|
2018-09-04 11:30:04 +02:00
|
|
|
#include "scene/3d/audio_stream_player_3d.h"
|
|
|
|
#include "scene/3d/baked_lightmap.h"
|
2020-03-26 22:49:16 +01:00
|
|
|
#include "scene/3d/collision_polygon_3d.h"
|
|
|
|
#include "scene/3d/collision_shape_3d.h"
|
|
|
|
#include "scene/3d/cpu_particles_3d.h"
|
2020-04-14 05:05:21 +02:00
|
|
|
#include "scene/3d/decal.h"
|
2018-09-04 11:30:04 +02:00
|
|
|
#include "scene/3d/gi_probe.h"
|
2020-03-26 22:49:16 +01:00
|
|
|
#include "scene/3d/gpu_particles_3d.h"
|
2020-10-08 02:29:49 +02:00
|
|
|
#include "scene/3d/gpu_particles_collision_3d.h"
|
2020-03-26 22:49:16 +01:00
|
|
|
#include "scene/3d/light_3d.h"
|
2020-05-01 14:34:23 +02:00
|
|
|
#include "scene/3d/lightmap_probe.h"
|
2020-03-26 22:49:16 +01:00
|
|
|
#include "scene/3d/listener_3d.h"
|
|
|
|
#include "scene/3d/mesh_instance_3d.h"
|
|
|
|
#include "scene/3d/navigation_region_3d.h"
|
|
|
|
#include "scene/3d/physics_joint_3d.h"
|
2018-09-04 11:30:04 +02:00
|
|
|
#include "scene/3d/position_3d.h"
|
2020-03-26 22:49:16 +01:00
|
|
|
#include "scene/3d/ray_cast_3d.h"
|
2018-09-04 11:30:04 +02:00
|
|
|
#include "scene/3d/reflection_probe.h"
|
2020-03-26 22:49:16 +01:00
|
|
|
#include "scene/3d/soft_body_3d.h"
|
|
|
|
#include "scene/3d/spring_arm_3d.h"
|
2018-09-04 11:30:04 +02:00
|
|
|
#include "scene/3d/sprite_3d.h"
|
2020-03-27 08:44:44 +01:00
|
|
|
#include "scene/3d/vehicle_body_3d.h"
|
2020-03-26 22:49:16 +01:00
|
|
|
#include "scene/3d/visibility_notifier_3d.h"
|
|
|
|
#include "scene/resources/box_shape_3d.h"
|
|
|
|
#include "scene/resources/capsule_shape_3d.h"
|
|
|
|
#include "scene/resources/concave_polygon_shape_3d.h"
|
|
|
|
#include "scene/resources/convex_polygon_shape_3d.h"
|
|
|
|
#include "scene/resources/cylinder_shape_3d.h"
|
2020-03-27 08:44:44 +01:00
|
|
|
#include "scene/resources/height_map_shape_3d.h"
|
2017-08-28 08:21:54 +02:00
|
|
|
#include "scene/resources/primitive_meshes.h"
|
2020-03-27 08:44:44 +01:00
|
|
|
#include "scene/resources/ray_shape_3d.h"
|
2020-03-26 22:49:16 +01:00
|
|
|
#include "scene/resources/sphere_shape_3d.h"
|
2017-03-05 16:44:50 +01:00
|
|
|
#include "scene/resources/surface_tool.h"
|
2020-03-26 22:49:16 +01:00
|
|
|
#include "scene/resources/world_margin_shape_3d.h"
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
#define HANDLE_HALF_SIZE 9.5
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
bool EditorNode3DGizmo::is_editable() const {
|
2017-08-26 05:40:45 +02:00
|
|
|
ERR_FAIL_COND_V(!spatial_node, false);
|
|
|
|
Node *edited_root = spatial_node->get_tree()->get_edited_scene_root();
|
2020-05-14 16:41:43 +02:00
|
|
|
if (spatial_node == edited_root) {
|
2017-08-26 05:40:45 +02:00
|
|
|
return true;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
|
|
|
if (spatial_node->get_owner() == edited_root) {
|
2017-08-26 05:40:45 +02:00
|
|
|
return true;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2017-08-26 05:40:45 +02:00
|
|
|
|
2020-05-14 16:41:43 +02:00
|
|
|
if (edited_root->is_editable_instance(spatial_node->get_owner())) {
|
2017-08-26 05:40:45 +02:00
|
|
|
return true;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2017-08-26 05:40:45 +02:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
void EditorNode3DGizmo::clear() {
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < instances.size(); i++) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (instances[i].instance.is_valid()) {
|
2020-03-27 19:21:27 +01:00
|
|
|
RS::get_singleton()->free(instances[i].instance);
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
billboard_handle = false;
|
2015-10-08 20:00:40 +02:00
|
|
|
collision_segments.clear();
|
2017-03-05 16:44:50 +01:00
|
|
|
collision_mesh = Ref<TriangleMesh>();
|
2015-10-08 20:00:40 +02:00
|
|
|
instances.clear();
|
|
|
|
handles.clear();
|
|
|
|
secondary_handles.clear();
|
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
void EditorNode3DGizmo::redraw() {
|
2019-01-25 12:57:32 +01:00
|
|
|
if (get_script_instance() && get_script_instance()->has_method("redraw")) {
|
|
|
|
get_script_instance()->call("redraw");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
ERR_FAIL_COND(!gizmo_plugin);
|
|
|
|
gizmo_plugin->redraw(this);
|
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
String EditorNode3DGizmo::get_handle_name(int p_idx) const {
|
2019-01-25 12:57:32 +01:00
|
|
|
if (get_script_instance() && get_script_instance()->has_method("get_handle_name")) {
|
|
|
|
return get_script_instance()->call("get_handle_name", p_idx);
|
|
|
|
}
|
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
ERR_FAIL_COND_V(!gizmo_plugin, "");
|
|
|
|
return gizmo_plugin->get_handle_name(this, p_idx);
|
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
bool EditorNode3DGizmo::is_handle_highlighted(int p_idx) const {
|
2019-01-25 12:57:32 +01:00
|
|
|
if (get_script_instance() && get_script_instance()->has_method("is_handle_highlighted")) {
|
|
|
|
return get_script_instance()->call("is_handle_highlighted", p_idx);
|
|
|
|
}
|
|
|
|
|
|
|
|
ERR_FAIL_COND_V(!gizmo_plugin, false);
|
|
|
|
return gizmo_plugin->is_handle_highlighted(this, p_idx);
|
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
Variant EditorNode3DGizmo::get_handle_value(int p_idx) {
|
2019-01-25 12:57:32 +01:00
|
|
|
if (get_script_instance() && get_script_instance()->has_method("get_handle_value")) {
|
|
|
|
return get_script_instance()->call("get_handle_value", p_idx);
|
|
|
|
}
|
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
ERR_FAIL_COND_V(!gizmo_plugin, Variant());
|
|
|
|
return gizmo_plugin->get_handle_value(this, p_idx);
|
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
void EditorNode3DGizmo::set_handle(int p_idx, Camera3D *p_camera, const Point2 &p_point) {
|
2019-01-25 12:57:32 +01:00
|
|
|
if (get_script_instance() && get_script_instance()->has_method("set_handle")) {
|
|
|
|
get_script_instance()->call("set_handle", p_idx, p_camera, p_point);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
ERR_FAIL_COND(!gizmo_plugin);
|
2019-07-01 12:59:42 +02:00
|
|
|
gizmo_plugin->set_handle(this, p_idx, p_camera, p_point);
|
2018-07-25 00:08:49 +02:00
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
void EditorNode3DGizmo::commit_handle(int p_idx, const Variant &p_restore, bool p_cancel) {
|
2019-01-25 12:57:32 +01:00
|
|
|
if (get_script_instance() && get_script_instance()->has_method("commit_handle")) {
|
|
|
|
get_script_instance()->call("commit_handle", p_idx, p_restore, p_cancel);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
ERR_FAIL_COND(!gizmo_plugin);
|
2019-07-01 12:59:42 +02:00
|
|
|
gizmo_plugin->commit_handle(this, p_idx, p_restore, p_cancel);
|
2018-07-25 00:08:49 +02:00
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
void EditorNode3DGizmo::set_spatial_node(Node3D *p_node) {
|
2018-07-25 00:08:49 +02:00
|
|
|
ERR_FAIL_NULL(p_node);
|
|
|
|
spatial_node = p_node;
|
2016-02-28 03:10:44 +01:00
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
void EditorNode3DGizmo::Instance::create_instance(Node3D *p_base, bool p_hidden) {
|
2020-04-18 11:00:51 +02:00
|
|
|
instance = RS::get_singleton()->instance_create2(mesh->get_rid(), p_base->get_world_3d()->get_scenario());
|
2020-03-27 19:21:27 +01:00
|
|
|
RS::get_singleton()->instance_attach_object_instance_id(instance, p_base->get_instance_id());
|
2019-09-25 21:44:44 +02:00
|
|
|
if (skin_reference.is_valid()) {
|
2020-03-27 19:21:27 +01:00
|
|
|
RS::get_singleton()->instance_attach_skeleton(instance, skin_reference->get_skeleton());
|
2019-09-25 21:44:44 +02:00
|
|
|
}
|
2020-05-14 16:41:43 +02:00
|
|
|
if (extra_margin) {
|
2020-03-27 19:21:27 +01:00
|
|
|
RS::get_singleton()->instance_set_extra_visibility_margin(instance, 1);
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2020-03-27 19:21:27 +01:00
|
|
|
RS::get_singleton()->instance_geometry_set_cast_shadows_setting(instance, RS::SHADOW_CASTING_SETTING_OFF);
|
2020-03-26 22:49:16 +01:00
|
|
|
int layer = p_hidden ? 0 : 1 << Node3DEditorViewport::GIZMO_EDIT_LAYER;
|
2020-03-27 19:21:27 +01:00
|
|
|
RS::get_singleton()->instance_set_layer_mask(instance, layer); //gizmos are 26
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
void EditorNode3DGizmo::add_mesh(const Ref<ArrayMesh> &p_mesh, bool p_billboard, const Ref<SkinReference> &p_skin_reference, const Ref<Material> &p_material) {
|
2015-10-08 20:00:40 +02:00
|
|
|
ERR_FAIL_COND(!spatial_node);
|
|
|
|
Instance ins;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ins.billboard = p_billboard;
|
|
|
|
ins.mesh = p_mesh;
|
2019-09-19 00:46:32 +02:00
|
|
|
ins.skin_reference = p_skin_reference;
|
2019-02-24 00:20:54 +01:00
|
|
|
ins.material = p_material;
|
2015-10-08 20:00:40 +02:00
|
|
|
if (valid) {
|
2018-07-25 00:08:49 +02:00
|
|
|
ins.create_instance(spatial_node, hidden);
|
2020-03-27 19:21:27 +01:00
|
|
|
RS::get_singleton()->instance_set_transform(ins.instance, spatial_node->get_global_transform());
|
2019-02-24 00:20:54 +01:00
|
|
|
if (ins.material.is_valid()) {
|
2020-03-27 19:21:27 +01:00
|
|
|
RS::get_singleton()->instance_geometry_set_material_override(ins.instance, p_material->get_rid());
|
2019-02-24 00:20:54 +01:00
|
|
|
}
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
instances.push_back(ins);
|
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
void EditorNode3DGizmo::add_lines(const Vector<Vector3> &p_lines, const Ref<Material> &p_material, bool p_billboard, const Color &p_modulate) {
|
2019-12-05 19:27:57 +01:00
|
|
|
if (p_lines.empty()) {
|
|
|
|
return;
|
|
|
|
}
|
2015-10-08 20:00:40 +02:00
|
|
|
|
|
|
|
ERR_FAIL_COND(!spatial_node);
|
|
|
|
Instance ins;
|
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
Ref<ArrayMesh> mesh = memnew(ArrayMesh);
|
2015-10-08 20:00:40 +02:00
|
|
|
Array a;
|
|
|
|
a.resize(Mesh::ARRAY_MAX);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
a[Mesh::ARRAY_VERTEX] = p_lines;
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2020-02-17 22:06:54 +01:00
|
|
|
Vector<Color> color;
|
2015-10-08 20:00:40 +02:00
|
|
|
color.resize(p_lines.size());
|
|
|
|
{
|
2020-02-17 22:06:54 +01:00
|
|
|
Color *w = color.ptrw();
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < p_lines.size(); i++) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (is_selected()) {
|
2020-01-01 00:52:20 +01:00
|
|
|
w[i] = Color(1, 1, 1, 0.8) * p_modulate;
|
2020-05-14 16:41:43 +02:00
|
|
|
} else {
|
2020-01-01 00:52:20 +01:00
|
|
|
w[i] = Color(1, 1, 1, 0.2) * p_modulate;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
a[Mesh::ARRAY_COLOR] = color;
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
mesh->add_surface_from_arrays(Mesh::PRIMITIVE_LINES, a);
|
|
|
|
mesh->surface_set_material(0, p_material);
|
2015-10-08 20:00:40 +02:00
|
|
|
|
|
|
|
if (p_billboard) {
|
2017-03-05 16:44:50 +01:00
|
|
|
float md = 0;
|
|
|
|
for (int i = 0; i < p_lines.size(); i++) {
|
|
|
|
md = MAX(0, p_lines[i].length());
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
if (md) {
|
2017-11-17 03:09:00 +01:00
|
|
|
mesh->set_custom_aabb(AABB(Vector3(-md, -md, -md), Vector3(md, md, md) * 2.0));
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ins.billboard = p_billboard;
|
|
|
|
ins.mesh = mesh;
|
2015-10-08 20:00:40 +02:00
|
|
|
if (valid) {
|
2018-07-25 00:08:49 +02:00
|
|
|
ins.create_instance(spatial_node, hidden);
|
2020-03-27 19:21:27 +01:00
|
|
|
RS::get_singleton()->instance_set_transform(ins.instance, spatial_node->get_global_transform());
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
instances.push_back(ins);
|
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
void EditorNode3DGizmo::add_unscaled_billboard(const Ref<Material> &p_material, float p_scale, const Color &p_modulate) {
|
2015-10-08 20:00:40 +02:00
|
|
|
ERR_FAIL_COND(!spatial_node);
|
|
|
|
Instance ins;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Vector<Vector3> vs;
|
|
|
|
Vector<Vector2> uv;
|
2020-01-01 00:52:20 +01:00
|
|
|
Vector<Color> colors;
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
vs.push_back(Vector3(-p_scale, p_scale, 0));
|
|
|
|
vs.push_back(Vector3(p_scale, p_scale, 0));
|
|
|
|
vs.push_back(Vector3(p_scale, -p_scale, 0));
|
|
|
|
vs.push_back(Vector3(-p_scale, -p_scale, 0));
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
uv.push_back(Vector2(0, 0));
|
2017-08-28 04:50:46 +02:00
|
|
|
uv.push_back(Vector2(1, 0));
|
2017-03-05 16:44:50 +01:00
|
|
|
uv.push_back(Vector2(1, 1));
|
2017-08-28 04:50:46 +02:00
|
|
|
uv.push_back(Vector2(0, 1));
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2020-01-01 00:52:20 +01:00
|
|
|
colors.push_back(p_modulate);
|
|
|
|
colors.push_back(p_modulate);
|
|
|
|
colors.push_back(p_modulate);
|
|
|
|
colors.push_back(p_modulate);
|
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
Ref<ArrayMesh> mesh = memnew(ArrayMesh);
|
2015-10-08 20:00:40 +02:00
|
|
|
Array a;
|
|
|
|
a.resize(Mesh::ARRAY_MAX);
|
2017-03-05 16:44:50 +01:00
|
|
|
a[Mesh::ARRAY_VERTEX] = vs;
|
|
|
|
a[Mesh::ARRAY_TEX_UV] = uv;
|
2019-06-16 04:45:24 +02:00
|
|
|
Vector<int> indices;
|
|
|
|
indices.push_back(0);
|
|
|
|
indices.push_back(1);
|
|
|
|
indices.push_back(2);
|
|
|
|
indices.push_back(0);
|
|
|
|
indices.push_back(2);
|
|
|
|
indices.push_back(3);
|
|
|
|
a[Mesh::ARRAY_INDEX] = indices;
|
2020-01-01 00:52:20 +01:00
|
|
|
a[Mesh::ARRAY_COLOR] = colors;
|
2019-06-16 04:45:24 +02:00
|
|
|
mesh->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, a);
|
2017-03-05 16:44:50 +01:00
|
|
|
mesh->surface_set_material(0, p_material);
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2019-06-26 15:08:25 +02:00
|
|
|
float md = 0;
|
|
|
|
for (int i = 0; i < vs.size(); i++) {
|
|
|
|
md = MAX(0, vs[i].length());
|
|
|
|
}
|
|
|
|
if (md) {
|
|
|
|
mesh->set_custom_aabb(AABB(Vector3(-md, -md, -md), Vector3(md, md, md) * 2.0));
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
|
2018-05-06 20:49:22 +02:00
|
|
|
selectable_icon_size = p_scale;
|
2018-06-27 16:59:45 +02:00
|
|
|
mesh->set_custom_aabb(AABB(Vector3(-selectable_icon_size, -selectable_icon_size, -selectable_icon_size) * 100.0f, Vector3(selectable_icon_size, selectable_icon_size, selectable_icon_size) * 200.0f));
|
2018-05-06 20:49:22 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ins.mesh = mesh;
|
|
|
|
ins.unscaled = true;
|
|
|
|
ins.billboard = true;
|
2015-10-08 20:00:40 +02:00
|
|
|
if (valid) {
|
2018-07-25 00:08:49 +02:00
|
|
|
ins.create_instance(spatial_node, hidden);
|
2020-03-27 19:21:27 +01:00
|
|
|
RS::get_singleton()->instance_set_transform(ins.instance, spatial_node->get_global_transform());
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
|
2018-06-27 16:59:45 +02:00
|
|
|
selectable_icon_size = p_scale;
|
2018-05-06 20:49:22 +02:00
|
|
|
|
2015-10-08 20:00:40 +02:00
|
|
|
instances.push_back(ins);
|
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
void EditorNode3DGizmo::add_collision_triangles(const Ref<TriangleMesh> &p_tmesh) {
|
2017-03-05 16:44:50 +01:00
|
|
|
collision_mesh = p_tmesh;
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
void EditorNode3DGizmo::add_collision_segments(const Vector<Vector3> &p_lines) {
|
2017-03-05 16:44:50 +01:00
|
|
|
int from = collision_segments.size();
|
|
|
|
collision_segments.resize(from + p_lines.size());
|
|
|
|
for (int i = 0; i < p_lines.size(); i++) {
|
2018-07-25 03:11:03 +02:00
|
|
|
collision_segments.write[from + i] = p_lines[i];
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
void EditorNode3DGizmo::add_handles(const Vector<Vector3> &p_handles, const Ref<Material> &p_material, bool p_billboard, bool p_secondary) {
|
2017-03-05 16:44:50 +01:00
|
|
|
billboard_handle = p_billboard;
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!is_selected() || !is_editable()) {
|
2015-10-08 20:00:40 +02:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2015-10-08 20:00:40 +02:00
|
|
|
|
|
|
|
ERR_FAIL_COND(!spatial_node);
|
|
|
|
|
|
|
|
Instance ins;
|
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
Ref<ArrayMesh> mesh = memnew(ArrayMesh);
|
2015-10-08 20:00:40 +02:00
|
|
|
|
|
|
|
Array a;
|
2020-03-27 19:21:27 +01:00
|
|
|
a.resize(RS::ARRAY_MAX);
|
|
|
|
a[RS::ARRAY_VERTEX] = p_handles;
|
2020-02-17 22:06:54 +01:00
|
|
|
Vector<Color> colors;
|
2015-10-08 20:00:40 +02:00
|
|
|
{
|
|
|
|
colors.resize(p_handles.size());
|
2020-02-17 22:06:54 +01:00
|
|
|
Color *w = colors.ptrw();
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < p_handles.size(); i++) {
|
|
|
|
Color col(1, 1, 1, 1);
|
2020-05-14 16:41:43 +02:00
|
|
|
if (is_handle_highlighted(i)) {
|
2017-11-21 01:36:32 +01:00
|
|
|
col = Color(0, 0, 1, 0.9);
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2017-11-21 01:36:32 +01:00
|
|
|
|
2020-05-14 16:41:43 +02:00
|
|
|
if (Node3DEditor::get_singleton()->get_over_gizmo_handle() != i) {
|
2017-11-21 01:36:32 +01:00
|
|
|
col.a = 0.8;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2017-11-21 01:36:32 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
w[i] = col;
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
}
|
2020-03-27 19:21:27 +01:00
|
|
|
a[RS::ARRAY_COLOR] = colors;
|
2017-03-05 16:44:50 +01:00
|
|
|
mesh->add_surface_from_arrays(Mesh::PRIMITIVE_POINTS, a);
|
2018-07-25 00:08:49 +02:00
|
|
|
mesh->surface_set_material(0, p_material);
|
2015-10-08 20:00:40 +02:00
|
|
|
|
|
|
|
if (p_billboard) {
|
2017-03-05 16:44:50 +01:00
|
|
|
float md = 0;
|
|
|
|
for (int i = 0; i < p_handles.size(); i++) {
|
|
|
|
md = MAX(0, p_handles[i].length());
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
if (md) {
|
2017-11-17 03:09:00 +01:00
|
|
|
mesh->set_custom_aabb(AABB(Vector3(-md, -md, -md), Vector3(md, md, md) * 2.0));
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ins.mesh = mesh;
|
|
|
|
ins.billboard = p_billboard;
|
|
|
|
ins.extra_margin = true;
|
2015-10-08 20:00:40 +02:00
|
|
|
if (valid) {
|
2018-07-25 00:08:49 +02:00
|
|
|
ins.create_instance(spatial_node, hidden);
|
2020-03-27 19:21:27 +01:00
|
|
|
RS::get_singleton()->instance_set_transform(ins.instance, spatial_node->get_global_transform());
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
instances.push_back(ins);
|
|
|
|
if (!p_secondary) {
|
2017-03-05 16:44:50 +01:00
|
|
|
int chs = handles.size();
|
|
|
|
handles.resize(chs + p_handles.size());
|
|
|
|
for (int i = 0; i < p_handles.size(); i++) {
|
2018-07-25 03:11:03 +02:00
|
|
|
handles.write[i + chs] = p_handles[i];
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
} else {
|
2017-03-05 16:44:50 +01:00
|
|
|
int chs = secondary_handles.size();
|
|
|
|
secondary_handles.resize(chs + p_handles.size());
|
|
|
|
for (int i = 0; i < p_handles.size(); i++) {
|
2018-07-25 03:11:03 +02:00
|
|
|
secondary_handles.write[i + chs] = p_handles[i];
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
void EditorNode3DGizmo::add_solid_box(Ref<Material> &p_material, Vector3 p_size, Vector3 p_position) {
|
2017-08-30 00:50:45 +02:00
|
|
|
ERR_FAIL_COND(!spatial_node);
|
|
|
|
|
2020-12-04 16:39:45 +01:00
|
|
|
BoxMesh box_mesh;
|
|
|
|
box_mesh.set_size(p_size);
|
2018-02-03 18:17:57 +01:00
|
|
|
|
2020-12-04 16:39:45 +01:00
|
|
|
Array arrays = box_mesh.surface_get_arrays(0);
|
2020-03-27 19:21:27 +01:00
|
|
|
PackedVector3Array vertex = arrays[RS::ARRAY_VERTEX];
|
2020-02-17 22:06:54 +01:00
|
|
|
Vector3 *w = vertex.ptrw();
|
2018-02-03 18:17:57 +01:00
|
|
|
|
|
|
|
for (int i = 0; i < vertex.size(); ++i) {
|
|
|
|
w[i] += p_position;
|
|
|
|
}
|
|
|
|
|
2020-03-27 19:21:27 +01:00
|
|
|
arrays[RS::ARRAY_VERTEX] = vertex;
|
2018-02-03 18:17:57 +01:00
|
|
|
|
2017-08-28 08:21:54 +02:00
|
|
|
Ref<ArrayMesh> m = memnew(ArrayMesh);
|
2020-12-04 16:39:45 +01:00
|
|
|
m->add_surface_from_arrays(box_mesh.surface_get_primitive_type(0), arrays);
|
2017-08-28 08:21:54 +02:00
|
|
|
m->surface_set_material(0, p_material);
|
|
|
|
add_mesh(m);
|
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
bool EditorNode3DGizmo::intersect_frustum(const Camera3D *p_camera, const Vector<Plane> &p_frustum) {
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!spatial_node, false);
|
|
|
|
ERR_FAIL_COND_V(!valid, false);
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2020-05-14 16:41:43 +02:00
|
|
|
if (hidden && !gizmo_plugin->is_selectable_when_hidden()) {
|
2020-05-10 12:56:01 +02:00
|
|
|
return false;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2018-07-25 00:08:49 +02:00
|
|
|
|
2018-05-06 20:49:22 +02:00
|
|
|
if (selectable_icon_size > 0.0f) {
|
|
|
|
Vector3 origin = spatial_node->get_global_transform().get_origin();
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
const Plane *p = p_frustum.ptr();
|
|
|
|
int fc = p_frustum.size();
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2018-05-06 20:49:22 +02:00
|
|
|
bool any_out = false;
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2018-05-06 20:49:22 +02:00
|
|
|
for (int j = 0; j < fc; j++) {
|
|
|
|
if (p[j].is_point_over(origin)) {
|
|
|
|
any_out = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-26 15:08:25 +02:00
|
|
|
return !any_out;
|
2018-05-06 20:49:22 +02:00
|
|
|
}
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2018-05-06 20:49:22 +02:00
|
|
|
if (collision_segments.size()) {
|
|
|
|
const Plane *p = p_frustum.ptr();
|
|
|
|
int fc = p_frustum.size();
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2018-05-06 20:49:22 +02:00
|
|
|
int vc = collision_segments.size();
|
|
|
|
const Vector3 *vptr = collision_segments.ptr();
|
|
|
|
Transform t = spatial_node->get_global_transform();
|
|
|
|
|
|
|
|
bool any_out = false;
|
|
|
|
for (int j = 0; j < fc; j++) {
|
|
|
|
for (int i = 0; i < vc; i++) {
|
|
|
|
Vector3 v = t.xform(vptr[i]);
|
|
|
|
if (p[j].is_point_over(v)) {
|
2017-03-05 16:44:50 +01:00
|
|
|
any_out = true;
|
2015-10-08 20:00:40 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2020-05-14 16:41:43 +02:00
|
|
|
if (any_out) {
|
2020-05-10 12:56:01 +02:00
|
|
|
break;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!any_out) {
|
2020-05-10 12:56:01 +02:00
|
|
|
return true;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
|
2018-05-06 20:49:22 +02:00
|
|
|
if (collision_mesh.is_valid()) {
|
2017-09-12 15:06:13 +02:00
|
|
|
Transform t = spatial_node->get_global_transform();
|
|
|
|
|
2018-05-06 20:49:22 +02:00
|
|
|
Vector3 mesh_scale = t.get_basis().get_scale();
|
|
|
|
t.orthonormalize();
|
2017-09-12 15:06:13 +02:00
|
|
|
|
2018-05-06 20:49:22 +02:00
|
|
|
Transform it = t.affine_inverse();
|
2017-09-12 15:06:13 +02:00
|
|
|
|
2018-05-06 20:49:22 +02:00
|
|
|
Vector<Plane> transformed_frustum;
|
2017-09-12 15:06:13 +02:00
|
|
|
|
2020-04-29 02:14:06 +02:00
|
|
|
for (int i = 0; i < p_frustum.size(); i++) {
|
2018-05-06 20:49:22 +02:00
|
|
|
transformed_frustum.push_back(it.xform(p_frustum[i]));
|
2017-09-12 15:06:13 +02:00
|
|
|
}
|
|
|
|
|
2020-05-25 19:20:45 +02:00
|
|
|
Vector<Vector3> convex_points = Geometry3D::compute_convex_mesh_points(p_frustum.ptr(), p_frustum.size());
|
2020-04-29 02:14:06 +02:00
|
|
|
if (collision_mesh->inside_convex_shape(transformed_frustum.ptr(), transformed_frustum.size(), convex_points.ptr(), convex_points.size(), mesh_scale)) {
|
2017-09-12 15:06:13 +02:00
|
|
|
return true;
|
2018-05-06 20:49:22 +02:00
|
|
|
}
|
2017-09-12 15:06:13 +02:00
|
|
|
}
|
|
|
|
|
2015-10-08 20:00:40 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
bool EditorNode3DGizmo::intersect_ray(Camera3D *p_camera, const Point2 &p_point, Vector3 &r_pos, Vector3 &r_normal, int *r_gizmo_handle, bool p_sec_first) {
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!spatial_node, false);
|
|
|
|
ERR_FAIL_COND_V(!valid, false);
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2020-05-14 16:41:43 +02:00
|
|
|
if (hidden && !gizmo_plugin->is_selectable_when_hidden()) {
|
2020-05-10 12:56:01 +02:00
|
|
|
return false;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2018-07-25 00:08:49 +02:00
|
|
|
|
|
|
|
if (r_gizmo_handle && !hidden) {
|
2015-10-08 20:00:40 +02:00
|
|
|
Transform t = spatial_node->get_global_transform();
|
|
|
|
if (billboard_handle) {
|
2017-04-07 04:36:37 +02:00
|
|
|
t.set_look_at(t.origin, t.origin - p_camera->get_transform().basis.get_axis(2), p_camera->get_transform().basis.get_axis(1));
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
float min_d = 1e20;
|
|
|
|
int idx = -1;
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < secondary_handles.size(); i++) {
|
2015-10-08 20:00:40 +02:00
|
|
|
Vector3 hpos = t.xform(secondary_handles[i]);
|
|
|
|
Vector2 p = p_camera->unproject_position(hpos);
|
2018-07-25 00:08:49 +02:00
|
|
|
|
|
|
|
if (p.distance_to(p_point) < HANDLE_HALF_SIZE) {
|
2015-10-08 20:00:40 +02:00
|
|
|
real_t dp = p_camera->get_transform().origin.distance_to(hpos);
|
2017-03-05 16:44:50 +01:00
|
|
|
if (dp < min_d) {
|
|
|
|
r_pos = t.xform(hpos);
|
|
|
|
r_normal = p_camera->get_transform().basis.get_axis(2);
|
|
|
|
min_d = dp;
|
|
|
|
idx = i + handles.size();
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (p_sec_first && idx != -1) {
|
|
|
|
*r_gizmo_handle = idx;
|
2015-10-08 20:00:40 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
min_d = 1e20;
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < handles.size(); i++) {
|
2015-10-08 20:00:40 +02:00
|
|
|
Vector3 hpos = t.xform(handles[i]);
|
|
|
|
Vector2 p = p_camera->unproject_position(hpos);
|
2018-07-25 00:08:49 +02:00
|
|
|
|
|
|
|
if (p.distance_to(p_point) < HANDLE_HALF_SIZE) {
|
2015-10-08 20:00:40 +02:00
|
|
|
real_t dp = p_camera->get_transform().origin.distance_to(hpos);
|
2017-03-05 16:44:50 +01:00
|
|
|
if (dp < min_d) {
|
|
|
|
r_pos = t.xform(hpos);
|
|
|
|
r_normal = p_camera->get_transform().basis.get_axis(2);
|
|
|
|
min_d = dp;
|
|
|
|
idx = i;
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (idx >= 0) {
|
|
|
|
*r_gizmo_handle = idx;
|
2015-10-08 20:00:40 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-06 20:49:22 +02:00
|
|
|
if (selectable_icon_size > 0.0f) {
|
|
|
|
Transform t = spatial_node->get_global_transform();
|
2019-01-25 00:52:28 +01:00
|
|
|
Vector3 camera_position = p_camera->get_camera_transform().origin;
|
|
|
|
if (camera_position.distance_squared_to(t.origin) > 0.01) {
|
|
|
|
t.set_look_at(t.origin, camera_position, Vector3(0, 1, 0));
|
|
|
|
}
|
2018-05-06 20:49:22 +02:00
|
|
|
|
|
|
|
float scale = t.origin.distance_to(p_camera->get_camera_transform().origin);
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
if (p_camera->get_projection() == Camera3D::PROJECTION_ORTHOGONAL) {
|
2018-06-27 16:59:45 +02:00
|
|
|
float aspect = p_camera->get_viewport()->get_visible_rect().size.aspect();
|
|
|
|
float size = p_camera->get_size();
|
|
|
|
scale = size / aspect;
|
2018-05-06 20:49:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Point2 center = p_camera->unproject_position(t.origin);
|
|
|
|
|
2019-01-25 00:52:28 +01:00
|
|
|
Transform orig_camera_transform = p_camera->get_camera_transform();
|
2018-05-06 20:49:22 +02:00
|
|
|
|
2019-05-07 17:36:35 +02:00
|
|
|
if (orig_camera_transform.origin.distance_squared_to(t.origin) > 0.01 &&
|
|
|
|
ABS(orig_camera_transform.basis.get_axis(Vector3::AXIS_Z).dot(Vector3(0, 1, 0))) < 0.99) {
|
2019-01-25 00:52:28 +01:00
|
|
|
p_camera->look_at(t.origin, Vector3(0, 1, 0));
|
|
|
|
}
|
2019-05-07 17:36:35 +02:00
|
|
|
|
2018-05-06 20:49:22 +02:00
|
|
|
Vector3 c0 = t.xform(Vector3(selectable_icon_size, selectable_icon_size, 0) * scale);
|
|
|
|
Vector3 c1 = t.xform(Vector3(-selectable_icon_size, -selectable_icon_size, 0) * scale);
|
|
|
|
|
|
|
|
Point2 p0 = p_camera->unproject_position(c0);
|
|
|
|
Point2 p1 = p_camera->unproject_position(c1);
|
|
|
|
|
2019-01-25 00:52:28 +01:00
|
|
|
p_camera->set_global_transform(orig_camera_transform);
|
2018-05-06 20:49:22 +02:00
|
|
|
|
2019-05-07 17:36:35 +02:00
|
|
|
Rect2 rect(p0, (p1 - p0).abs());
|
2018-05-06 20:49:22 +02:00
|
|
|
|
|
|
|
rect.set_position(center - rect.get_size() / 2.0);
|
|
|
|
|
|
|
|
if (rect.has_point(p_point)) {
|
2018-08-11 23:07:00 +02:00
|
|
|
r_pos = t.origin;
|
|
|
|
r_normal = -p_camera->project_ray_normal(p_point);
|
2018-05-06 20:49:22 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-10-08 20:00:40 +02:00
|
|
|
if (collision_segments.size()) {
|
2017-03-05 16:44:50 +01:00
|
|
|
Plane camp(p_camera->get_transform().origin, (-p_camera->get_transform().basis.get_axis(2)).normalized());
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
int vc = collision_segments.size();
|
|
|
|
const Vector3 *vptr = collision_segments.ptr();
|
2015-10-08 20:00:40 +02:00
|
|
|
Transform t = spatial_node->get_global_transform();
|
|
|
|
if (billboard_handle) {
|
2017-04-07 04:36:37 +02:00
|
|
|
t.set_look_at(t.origin, t.origin - p_camera->get_transform().basis.get_axis(2), p_camera->get_transform().basis.get_axis(1));
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Vector3 cp;
|
2017-03-05 16:44:50 +01:00
|
|
|
float cpd = 1e20;
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < vc / 2; i++) {
|
|
|
|
Vector3 a = t.xform(vptr[i * 2 + 0]);
|
|
|
|
Vector3 b = t.xform(vptr[i * 2 + 1]);
|
2015-10-08 20:00:40 +02:00
|
|
|
Vector2 s[2];
|
|
|
|
s[0] = p_camera->unproject_position(a);
|
|
|
|
s[1] = p_camera->unproject_position(b);
|
|
|
|
|
2020-05-25 19:20:45 +02:00
|
|
|
Vector2 p = Geometry2D::get_closest_point_to_segment(p_point, s);
|
2015-10-08 20:00:40 +02:00
|
|
|
|
|
|
|
float pd = p.distance_to(p_point);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (pd < cpd) {
|
2015-10-08 20:00:40 +02:00
|
|
|
float d = s[0].distance_to(s[1]);
|
|
|
|
Vector3 tcp;
|
2017-03-05 16:44:50 +01:00
|
|
|
if (d > 0) {
|
|
|
|
float d2 = s[0].distance_to(p) / d;
|
|
|
|
tcp = a + (b - a) * d2;
|
2015-10-08 20:00:40 +02:00
|
|
|
|
|
|
|
} else {
|
2017-03-05 16:44:50 +01:00
|
|
|
tcp = a;
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
|
2020-05-14 16:41:43 +02:00
|
|
|
if (camp.distance_to(tcp) < p_camera->get_znear()) {
|
2015-10-08 20:00:40 +02:00
|
|
|
continue;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
cp = tcp;
|
|
|
|
cpd = pd;
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (cpd < 8) {
|
|
|
|
r_pos = cp;
|
|
|
|
r_normal = -p_camera->project_ray_normal(p_point);
|
2015-10-08 20:00:40 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (collision_mesh.is_valid()) {
|
|
|
|
Transform gt = spatial_node->get_global_transform();
|
|
|
|
|
|
|
|
if (billboard_handle) {
|
2017-04-07 04:36:37 +02:00
|
|
|
gt.set_look_at(gt.origin, gt.origin - p_camera->get_transform().basis.get_axis(2), p_camera->get_transform().basis.get_axis(1));
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Transform ai = gt.affine_inverse();
|
2015-10-08 20:00:40 +02:00
|
|
|
Vector3 ray_from = ai.xform(p_camera->project_ray_origin(p_point));
|
2017-03-05 16:44:50 +01:00
|
|
|
Vector3 ray_dir = ai.basis.xform(p_camera->project_ray_normal(p_point)).normalized();
|
|
|
|
Vector3 rpos, rnorm;
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (collision_mesh->intersect_ray(ray_from, ray_dir, rpos, rnorm)) {
|
|
|
|
r_pos = gt.xform(rpos);
|
|
|
|
r_normal = gt.basis.xform(rnorm).normalized();
|
2015-10-08 20:00:40 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
void EditorNode3DGizmo::create() {
|
2015-10-08 20:00:40 +02:00
|
|
|
ERR_FAIL_COND(!spatial_node);
|
|
|
|
ERR_FAIL_COND(valid);
|
2017-03-05 16:44:50 +01:00
|
|
|
valid = true;
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < instances.size(); i++) {
|
2018-07-25 00:08:49 +02:00
|
|
|
instances.write[i].create_instance(spatial_node, hidden);
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
transform();
|
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
void EditorNode3DGizmo::transform() {
|
2015-10-08 20:00:40 +02:00
|
|
|
ERR_FAIL_COND(!spatial_node);
|
|
|
|
ERR_FAIL_COND(!valid);
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < instances.size(); i++) {
|
2020-03-27 19:21:27 +01:00
|
|
|
RS::get_singleton()->instance_set_transform(instances[i].instance, spatial_node->get_global_transform());
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
void EditorNode3DGizmo::free() {
|
2015-10-08 20:00:40 +02:00
|
|
|
ERR_FAIL_COND(!spatial_node);
|
|
|
|
ERR_FAIL_COND(!valid);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < instances.size(); i++) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (instances[i].instance.is_valid()) {
|
2020-03-27 19:21:27 +01:00
|
|
|
RS::get_singleton()->free(instances[i].instance);
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2018-07-25 03:11:03 +02:00
|
|
|
instances.write[i].instance = RID();
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
clear();
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
valid = false;
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
void EditorNode3DGizmo::set_hidden(bool p_hidden) {
|
2018-07-25 00:08:49 +02:00
|
|
|
hidden = p_hidden;
|
2020-03-26 22:49:16 +01:00
|
|
|
int layer = hidden ? 0 : 1 << Node3DEditorViewport::GIZMO_EDIT_LAYER;
|
2018-07-25 00:08:49 +02:00
|
|
|
for (int i = 0; i < instances.size(); ++i) {
|
2020-03-27 19:21:27 +01:00
|
|
|
RS::get_singleton()->instance_set_layer_mask(instances[i].instance, layer);
|
2017-08-26 05:40:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
void EditorNode3DGizmo::set_plugin(EditorNode3DGizmoPlugin *p_plugin) {
|
2018-07-25 00:08:49 +02:00
|
|
|
gizmo_plugin = p_plugin;
|
2017-08-26 05:40:45 +02:00
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
void EditorNode3DGizmo::_bind_methods() {
|
|
|
|
ClassDB::bind_method(D_METHOD("add_lines", "lines", "material", "billboard", "modulate"), &EditorNode3DGizmo::add_lines, DEFVAL(false), DEFVAL(Color(1, 1, 1)));
|
|
|
|
ClassDB::bind_method(D_METHOD("add_mesh", "mesh", "billboard", "skeleton", "material"), &EditorNode3DGizmo::add_mesh, DEFVAL(false), DEFVAL(Ref<SkinReference>()), DEFVAL(Variant()));
|
|
|
|
ClassDB::bind_method(D_METHOD("add_collision_segments", "segments"), &EditorNode3DGizmo::add_collision_segments);
|
|
|
|
ClassDB::bind_method(D_METHOD("add_collision_triangles", "triangles"), &EditorNode3DGizmo::add_collision_triangles);
|
|
|
|
ClassDB::bind_method(D_METHOD("add_unscaled_billboard", "material", "default_scale", "modulate"), &EditorNode3DGizmo::add_unscaled_billboard, DEFVAL(1), DEFVAL(Color(1, 1, 1)));
|
|
|
|
ClassDB::bind_method(D_METHOD("add_handles", "handles", "material", "billboard", "secondary"), &EditorNode3DGizmo::add_handles, DEFVAL(false), DEFVAL(false));
|
|
|
|
ClassDB::bind_method(D_METHOD("set_spatial_node", "node"), &EditorNode3DGizmo::_set_spatial_node);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_spatial_node"), &EditorNode3DGizmo::get_spatial_node);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_plugin"), &EditorNode3DGizmo::get_plugin);
|
|
|
|
ClassDB::bind_method(D_METHOD("clear"), &EditorNode3DGizmo::clear);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_hidden", "hidden"), &EditorNode3DGizmo::set_hidden);
|
2017-03-05 16:44:50 +01:00
|
|
|
|
|
|
|
BIND_VMETHOD(MethodInfo("redraw"));
|
|
|
|
BIND_VMETHOD(MethodInfo(Variant::STRING, "get_handle_name", PropertyInfo(Variant::INT, "index")));
|
2019-01-25 12:57:32 +01:00
|
|
|
BIND_VMETHOD(MethodInfo(Variant::BOOL, "is_handle_highlighted", PropertyInfo(Variant::INT, "index")));
|
2017-08-29 07:15:46 +02:00
|
|
|
|
|
|
|
MethodInfo hvget(Variant::NIL, "get_handle_value", PropertyInfo(Variant::INT, "index"));
|
|
|
|
hvget.return_val.usage |= PROPERTY_USAGE_NIL_IS_VARIANT;
|
|
|
|
BIND_VMETHOD(hvget);
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
BIND_VMETHOD(MethodInfo("set_handle", PropertyInfo(Variant::INT, "index"), PropertyInfo(Variant::OBJECT, "camera", PROPERTY_HINT_RESOURCE_TYPE, "Camera3D"), PropertyInfo(Variant::VECTOR2, "point")));
|
2017-08-29 07:15:46 +02:00
|
|
|
MethodInfo cm = MethodInfo("commit_handle", PropertyInfo(Variant::INT, "index"), PropertyInfo(Variant::NIL, "restore"), PropertyInfo(Variant::BOOL, "cancel"));
|
2016-02-28 03:10:44 +01:00
|
|
|
cm.default_arguments.push_back(false);
|
2017-03-05 16:44:50 +01:00
|
|
|
BIND_VMETHOD(cm);
|
2016-02-28 03:10:44 +01:00
|
|
|
}
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
EditorNode3DGizmo::EditorNode3DGizmo() {
|
2017-03-05 16:44:50 +01:00
|
|
|
valid = false;
|
|
|
|
billboard_handle = false;
|
2018-07-25 00:08:49 +02:00
|
|
|
hidden = false;
|
2020-04-02 01:20:12 +02:00
|
|
|
base = nullptr;
|
2018-07-25 00:08:49 +02:00
|
|
|
selected = false;
|
|
|
|
instanced = false;
|
2020-04-02 01:20:12 +02:00
|
|
|
spatial_node = nullptr;
|
|
|
|
gizmo_plugin = nullptr;
|
2018-09-26 11:22:59 +02:00
|
|
|
selectable_icon_size = -1.0f;
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
EditorNode3DGizmo::~EditorNode3DGizmo() {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (gizmo_plugin != nullptr) {
|
2020-05-10 12:56:01 +02:00
|
|
|
gizmo_plugin->unregister_gizmo(this);
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2015-10-08 20:00:40 +02:00
|
|
|
clear();
|
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
Vector3 EditorNode3DGizmo::get_handle_pos(int p_idx) const {
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_INDEX_V(p_idx, handles.size(), Vector3());
|
2015-10-08 20:00:40 +02:00
|
|
|
|
|
|
|
return handles[p_idx];
|
|
|
|
}
|
|
|
|
|
|
|
|
//// light gizmo
|
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
Light3DGizmoPlugin::Light3DGizmoPlugin() {
|
2020-01-01 00:52:20 +01:00
|
|
|
// Enable vertex colors for the materials below as the gizmo color depends on the light color.
|
|
|
|
create_material("lines_primary", Color(1, 1, 1), false, false, true);
|
|
|
|
create_material("lines_secondary", Color(1, 1, 1, 0.35), false, false, true);
|
|
|
|
create_material("lines_billboard", Color(1, 1, 1), true, false, true);
|
2018-07-25 00:08:49 +02:00
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
create_icon_material("light_directional_icon", Node3DEditor::get_singleton()->get_theme_icon("GizmoDirectionalLight", "EditorIcons"));
|
|
|
|
create_icon_material("light_omni_icon", Node3DEditor::get_singleton()->get_theme_icon("GizmoLight", "EditorIcons"));
|
|
|
|
create_icon_material("light_spot_icon", Node3DEditor::get_singleton()->get_theme_icon("GizmoSpotLight", "EditorIcons"));
|
2018-07-25 00:08:49 +02:00
|
|
|
|
|
|
|
create_handle_material("handles");
|
|
|
|
create_handle_material("handles_billboard", true);
|
|
|
|
}
|
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
bool Light3DGizmoPlugin::has_gizmo(Node3D *p_spatial) {
|
2020-04-02 01:20:12 +02:00
|
|
|
return Object::cast_to<Light3D>(p_spatial) != nullptr;
|
2018-07-25 00:08:49 +02:00
|
|
|
}
|
|
|
|
|
2020-07-23 00:39:21 +02:00
|
|
|
String Light3DGizmoPlugin::get_gizmo_name() const {
|
2020-04-06 12:40:52 +02:00
|
|
|
return "Light3D";
|
2018-07-25 00:08:49 +02:00
|
|
|
}
|
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
int Light3DGizmoPlugin::get_priority() const {
|
2019-03-12 00:30:50 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
String Light3DGizmoPlugin::get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_idx) const {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (p_idx == 0) {
|
2016-05-21 01:18:35 +02:00
|
|
|
return "Radius";
|
2020-05-14 16:41:43 +02:00
|
|
|
} else {
|
2016-05-21 01:18:35 +02:00
|
|
|
return "Aperture";
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
Variant Light3DGizmoPlugin::get_handle_value(EditorNode3DGizmo *p_gizmo, int p_idx) const {
|
2020-03-26 22:49:16 +01:00
|
|
|
Light3D *light = Object::cast_to<Light3D>(p_gizmo->get_spatial_node());
|
2020-05-14 16:41:43 +02:00
|
|
|
if (p_idx == 0) {
|
2020-03-26 22:49:16 +01:00
|
|
|
return light->get_param(Light3D::PARAM_RANGE);
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
|
|
|
if (p_idx == 1) {
|
2020-03-26 22:49:16 +01:00
|
|
|
return light->get_param(Light3D::PARAM_SPOT_ANGLE);
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2015-10-08 20:00:40 +02:00
|
|
|
|
|
|
|
return Variant();
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
static float _find_closest_angle_to_half_pi_arc(const Vector3 &p_from, const Vector3 &p_to, float p_arc_radius, const Transform &p_arc_xform) {
|
2015-10-08 20:00:40 +02:00
|
|
|
//bleh, discrete is simpler
|
2017-03-05 16:44:50 +01:00
|
|
|
static const int arc_test_points = 64;
|
2015-10-08 20:00:40 +02:00
|
|
|
float min_d = 1e20;
|
|
|
|
Vector3 min_p;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < arc_test_points; i++) {
|
|
|
|
float a = i * Math_PI * 0.5 / arc_test_points;
|
|
|
|
float an = (i + 1) * Math_PI * 0.5 / arc_test_points;
|
|
|
|
Vector3 p = Vector3(Math::cos(a), 0, -Math::sin(a)) * p_arc_radius;
|
|
|
|
Vector3 n = Vector3(Math::cos(an), 0, -Math::sin(an)) * p_arc_radius;
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Vector3 ra, rb;
|
2020-05-25 19:20:45 +02:00
|
|
|
Geometry3D::get_closest_points_between_segments(p, n, p_from, p_to, ra, rb);
|
2015-10-08 20:00:40 +02:00
|
|
|
|
|
|
|
float d = ra.distance_to(rb);
|
2017-03-05 16:44:50 +01:00
|
|
|
if (d < min_d) {
|
|
|
|
min_d = d;
|
|
|
|
min_p = ra;
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//min_p = p_arc_xform.affine_inverse().xform(min_p);
|
2017-10-02 05:59:39 +02:00
|
|
|
float a = (Math_PI * 0.5) - Vector2(min_p.x, -min_p.z).angle();
|
2017-03-05 16:44:50 +01:00
|
|
|
return a * 180.0 / Math_PI;
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
void Light3DGizmoPlugin::set_handle(EditorNode3DGizmo *p_gizmo, int p_idx, Camera3D *p_camera, const Point2 &p_point) {
|
2020-03-26 22:49:16 +01:00
|
|
|
Light3D *light = Object::cast_to<Light3D>(p_gizmo->get_spatial_node());
|
2015-10-08 20:00:40 +02:00
|
|
|
Transform gt = light->get_global_transform();
|
|
|
|
Transform gi = gt.affine_inverse();
|
|
|
|
|
|
|
|
Vector3 ray_from = p_camera->project_ray_origin(p_point);
|
|
|
|
Vector3 ray_dir = p_camera->project_ray_normal(p_point);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Vector3 s[2] = { gi.xform(ray_from), gi.xform(ray_from + ray_dir * 4096) };
|
|
|
|
if (p_idx == 0) {
|
2020-03-26 22:49:16 +01:00
|
|
|
if (Object::cast_to<SpotLight3D>(light)) {
|
2017-03-05 16:44:50 +01:00
|
|
|
Vector3 ra, rb;
|
2020-05-25 19:20:45 +02:00
|
|
|
Geometry3D::get_closest_points_between_segments(Vector3(), Vector3(0, 0, -4096), s[0], s[1], ra, rb);
|
2015-10-08 20:00:40 +02:00
|
|
|
|
|
|
|
float d = -ra.z;
|
2020-03-26 22:49:16 +01:00
|
|
|
if (Node3DEditor::get_singleton()->is_snap_enabled()) {
|
|
|
|
d = Math::stepify(d, Node3DEditor::get_singleton()->get_translate_snap());
|
2019-07-03 12:11:12 +02:00
|
|
|
}
|
|
|
|
|
2020-05-14 16:41:43 +02:00
|
|
|
if (d <= 0) { // Equal is here for negative zero.
|
2017-03-05 16:44:50 +01:00
|
|
|
d = 0;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
light->set_param(Light3D::PARAM_RANGE, d);
|
|
|
|
} else if (Object::cast_to<OmniLight3D>(light)) {
|
2017-03-05 16:44:50 +01:00
|
|
|
Plane cp = Plane(gt.origin, p_camera->get_transform().basis.get_axis(2));
|
2015-10-08 20:00:40 +02:00
|
|
|
|
|
|
|
Vector3 inters;
|
2017-03-05 16:44:50 +01:00
|
|
|
if (cp.intersects_ray(ray_from, ray_dir, &inters)) {
|
2015-10-08 20:00:40 +02:00
|
|
|
float r = inters.distance_to(gt.origin);
|
2020-03-26 22:49:16 +01:00
|
|
|
if (Node3DEditor::get_singleton()->is_snap_enabled()) {
|
|
|
|
r = Math::stepify(r, Node3DEditor::get_singleton()->get_translate_snap());
|
2019-07-03 12:11:12 +02:00
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
light->set_param(Light3D::PARAM_RANGE, r);
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
} else if (p_idx == 1) {
|
2020-03-26 22:49:16 +01:00
|
|
|
float a = _find_closest_angle_to_half_pi_arc(s[0], s[1], light->get_param(Light3D::PARAM_RANGE), gt);
|
|
|
|
light->set_param(Light3D::PARAM_SPOT_ANGLE, CLAMP(a, 0.01, 89.99));
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
void Light3DGizmoPlugin::commit_handle(EditorNode3DGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel) {
|
2020-03-26 22:49:16 +01:00
|
|
|
Light3D *light = Object::cast_to<Light3D>(p_gizmo->get_spatial_node());
|
2015-10-08 20:00:40 +02:00
|
|
|
if (p_cancel) {
|
2020-03-26 22:49:16 +01:00
|
|
|
light->set_param(p_idx == 0 ? Light3D::PARAM_RANGE : Light3D::PARAM_SPOT_ANGLE, p_restore);
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
} else if (p_idx == 0) {
|
2020-03-26 22:49:16 +01:00
|
|
|
UndoRedo *ur = Node3DEditor::get_singleton()->get_undo_redo();
|
2016-05-04 03:25:37 +02:00
|
|
|
ur->create_action(TTR("Change Light Radius"));
|
2020-03-26 22:49:16 +01:00
|
|
|
ur->add_do_method(light, "set_param", Light3D::PARAM_RANGE, light->get_param(Light3D::PARAM_RANGE));
|
|
|
|
ur->add_undo_method(light, "set_param", Light3D::PARAM_RANGE, p_restore);
|
2015-10-08 20:00:40 +02:00
|
|
|
ur->commit_action();
|
2017-03-05 16:44:50 +01:00
|
|
|
} else if (p_idx == 1) {
|
2020-03-26 22:49:16 +01:00
|
|
|
UndoRedo *ur = Node3DEditor::get_singleton()->get_undo_redo();
|
2016-05-04 03:25:37 +02:00
|
|
|
ur->create_action(TTR("Change Light Radius"));
|
2020-03-26 22:49:16 +01:00
|
|
|
ur->add_do_method(light, "set_param", Light3D::PARAM_SPOT_ANGLE, light->get_param(Light3D::PARAM_SPOT_ANGLE));
|
|
|
|
ur->add_undo_method(light, "set_param", Light3D::PARAM_SPOT_ANGLE, p_restore);
|
2015-10-08 20:00:40 +02:00
|
|
|
ur->commit_action();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
void Light3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
|
2020-03-26 22:49:16 +01:00
|
|
|
Light3D *light = Object::cast_to<Light3D>(p_gizmo->get_spatial_node());
|
2018-07-25 00:08:49 +02:00
|
|
|
|
2020-01-01 00:52:20 +01:00
|
|
|
Color color = light->get_color();
|
|
|
|
// Make the gizmo color as bright as possible for better visibility
|
|
|
|
color.set_hsv(color.get_h(), color.get_s(), 1);
|
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
p_gizmo->clear();
|
2017-08-26 05:40:45 +02:00
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
if (Object::cast_to<DirectionalLight3D>(light)) {
|
2019-09-16 23:07:24 +02:00
|
|
|
Ref<Material> material = get_material("lines_primary", p_gizmo);
|
2018-07-25 00:08:49 +02:00
|
|
|
Ref<Material> icon = get_material("light_directional_icon", p_gizmo);
|
2017-08-26 05:40:45 +02:00
|
|
|
|
2017-08-28 20:32:28 +02:00
|
|
|
const int arrow_points = 7;
|
|
|
|
const float arrow_length = 1.5;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Vector3 arrow[arrow_points] = {
|
2017-08-28 20:32:28 +02:00
|
|
|
Vector3(0, 0, -1),
|
|
|
|
Vector3(0, 0.8, 0),
|
|
|
|
Vector3(0, 0.3, 0),
|
|
|
|
Vector3(0, 0.3, arrow_length),
|
|
|
|
Vector3(0, -0.3, arrow_length),
|
|
|
|
Vector3(0, -0.3, 0),
|
|
|
|
Vector3(0, -0.8, 0)
|
2015-10-08 20:00:40 +02:00
|
|
|
};
|
|
|
|
|
2017-08-28 20:32:28 +02:00
|
|
|
int arrow_sides = 2;
|
2015-10-08 20:00:40 +02:00
|
|
|
|
|
|
|
Vector<Vector3> lines;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < arrow_sides; i++) {
|
2017-08-28 20:32:28 +02:00
|
|
|
for (int j = 0; j < arrow_points; j++) {
|
|
|
|
Basis ma(Vector3(0, 0, 1), Math_PI * i / arrow_sides);
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2017-08-28 20:32:28 +02:00
|
|
|
Vector3 v1 = arrow[j] - Vector3(0, 0, arrow_length);
|
|
|
|
Vector3 v2 = arrow[(j + 1) % arrow_points] - Vector3(0, 0, arrow_length);
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2017-08-28 20:32:28 +02:00
|
|
|
lines.push_back(ma.xform(v1));
|
|
|
|
lines.push_back(ma.xform(v2));
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-01 00:52:20 +01:00
|
|
|
p_gizmo->add_lines(lines, material, false, color);
|
|
|
|
p_gizmo->add_unscaled_billboard(icon, 0.05, color);
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
if (Object::cast_to<OmniLight3D>(light)) {
|
2019-09-16 23:07:24 +02:00
|
|
|
// Use both a billboard circle and 3 non-billboard circles for a better sphere-like representation
|
|
|
|
const Ref<Material> lines_material = get_material("lines_secondary", p_gizmo);
|
|
|
|
const Ref<Material> lines_billboard_material = get_material("lines_billboard", p_gizmo);
|
|
|
|
const Ref<Material> icon = get_material("light_omni_icon", p_gizmo);
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
OmniLight3D *on = Object::cast_to<OmniLight3D>(light);
|
|
|
|
const float r = on->get_param(Light3D::PARAM_RANGE);
|
2015-10-08 20:00:40 +02:00
|
|
|
Vector<Vector3> points;
|
2019-09-16 23:07:24 +02:00
|
|
|
Vector<Vector3> points_billboard;
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2019-09-16 23:07:24 +02:00
|
|
|
for (int i = 0; i < 120; i++) {
|
|
|
|
// Create a circle
|
|
|
|
const float ra = Math::deg2rad((float)(i * 3));
|
|
|
|
const float rb = Math::deg2rad((float)((i + 1) * 3));
|
|
|
|
const Point2 a = Vector2(Math::sin(ra), Math::cos(ra)) * r;
|
|
|
|
const Point2 b = Vector2(Math::sin(rb), Math::cos(rb)) * r;
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2019-09-16 23:07:24 +02:00
|
|
|
// Draw axis-aligned circles
|
|
|
|
points.push_back(Vector3(a.x, 0, a.y));
|
|
|
|
points.push_back(Vector3(b.x, 0, b.y));
|
|
|
|
points.push_back(Vector3(0, a.x, a.y));
|
|
|
|
points.push_back(Vector3(0, b.x, b.y));
|
2017-03-05 16:44:50 +01:00
|
|
|
points.push_back(Vector3(a.x, a.y, 0));
|
|
|
|
points.push_back(Vector3(b.x, b.y, 0));
|
2019-09-16 23:07:24 +02:00
|
|
|
|
|
|
|
// Draw a billboarded circle
|
|
|
|
points_billboard.push_back(Vector3(a.x, a.y, 0));
|
|
|
|
points_billboard.push_back(Vector3(b.x, b.y, 0));
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
|
2020-01-01 00:52:20 +01:00
|
|
|
p_gizmo->add_lines(points, lines_material, true, color);
|
|
|
|
p_gizmo->add_lines(points_billboard, lines_billboard_material, true, color);
|
|
|
|
p_gizmo->add_unscaled_billboard(icon, 0.05, color);
|
2015-10-08 20:00:40 +02:00
|
|
|
|
|
|
|
Vector<Vector3> handles;
|
2017-03-05 16:44:50 +01:00
|
|
|
handles.push_back(Vector3(r, 0, 0));
|
2018-07-25 00:08:49 +02:00
|
|
|
p_gizmo->add_handles(handles, get_material("handles_billboard"), true);
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
if (Object::cast_to<SpotLight3D>(light)) {
|
2019-09-16 23:07:24 +02:00
|
|
|
const Ref<Material> material_primary = get_material("lines_primary", p_gizmo);
|
|
|
|
const Ref<Material> material_secondary = get_material("lines_secondary", p_gizmo);
|
|
|
|
const Ref<Material> icon = get_material("light_spot_icon", p_gizmo);
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2019-09-16 23:07:24 +02:00
|
|
|
Vector<Vector3> points_primary;
|
|
|
|
Vector<Vector3> points_secondary;
|
2020-03-26 22:49:16 +01:00
|
|
|
SpotLight3D *sl = Object::cast_to<SpotLight3D>(light);
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
float r = sl->get_param(Light3D::PARAM_RANGE);
|
|
|
|
float w = r * Math::sin(Math::deg2rad(sl->get_param(Light3D::PARAM_SPOT_ANGLE)));
|
|
|
|
float d = r * Math::cos(Math::deg2rad(sl->get_param(Light3D::PARAM_SPOT_ANGLE)));
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2019-09-16 23:07:24 +02:00
|
|
|
for (int i = 0; i < 120; i++) {
|
|
|
|
// Draw a circle
|
|
|
|
const float ra = Math::deg2rad((float)(i * 3));
|
|
|
|
const float rb = Math::deg2rad((float)((i + 1) * 3));
|
|
|
|
const Point2 a = Vector2(Math::sin(ra), Math::cos(ra)) * w;
|
|
|
|
const Point2 b = Vector2(Math::sin(rb), Math::cos(rb)) * w;
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2019-09-16 23:07:24 +02:00
|
|
|
points_primary.push_back(Vector3(a.x, a.y, -d));
|
|
|
|
points_primary.push_back(Vector3(b.x, b.y, -d));
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2019-09-16 23:07:24 +02:00
|
|
|
if (i % 15 == 0) {
|
|
|
|
// Draw 8 lines from the cone origin to the sides of the circle
|
|
|
|
points_secondary.push_back(Vector3(a.x, a.y, -d));
|
|
|
|
points_secondary.push_back(Vector3());
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-16 23:07:24 +02:00
|
|
|
points_primary.push_back(Vector3(0, 0, -r));
|
|
|
|
points_primary.push_back(Vector3());
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2020-01-01 00:52:20 +01:00
|
|
|
p_gizmo->add_lines(points_primary, material_primary, false, color);
|
|
|
|
p_gizmo->add_lines(points_secondary, material_secondary, false, color);
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2019-09-16 23:07:24 +02:00
|
|
|
const float ra = 16 * Math_PI * 2.0 / 64.0;
|
|
|
|
const Point2 a = Vector2(Math::sin(ra), Math::cos(ra)) * w;
|
2018-09-09 19:39:34 +02:00
|
|
|
|
2015-10-08 20:00:40 +02:00
|
|
|
Vector<Vector3> handles;
|
2017-03-05 16:44:50 +01:00
|
|
|
handles.push_back(Vector3(0, 0, -r));
|
2018-09-09 19:39:34 +02:00
|
|
|
handles.push_back(Vector3(a.x, a.y, -d));
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
p_gizmo->add_handles(handles, get_material("handles"));
|
2020-01-01 00:52:20 +01:00
|
|
|
p_gizmo->add_unscaled_billboard(icon, 0.05, color);
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
//////
|
|
|
|
|
|
|
|
//// player gizmo
|
2020-04-06 12:40:52 +02:00
|
|
|
AudioStreamPlayer3DGizmoPlugin::AudioStreamPlayer3DGizmoPlugin() {
|
2018-07-25 00:08:49 +02:00
|
|
|
Color gizmo_color = EDITOR_DEF("editors/3d_gizmos/gizmo_colors/stream_player_3d", Color(0.4, 0.8, 1));
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
create_icon_material("stream_player_3d_icon", Node3DEditor::get_singleton()->get_theme_icon("Gizmo3DSamplePlayer", "EditorIcons"));
|
2019-09-24 22:39:54 +02:00
|
|
|
create_material("stream_player_3d_material_primary", gizmo_color);
|
|
|
|
create_material("stream_player_3d_material_secondary", gizmo_color * Color(1, 1, 1, 0.35));
|
2018-07-25 00:08:49 +02:00
|
|
|
create_handle_material("handles");
|
2016-03-20 03:10:04 +01:00
|
|
|
}
|
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
bool AudioStreamPlayer3DGizmoPlugin::has_gizmo(Node3D *p_spatial) {
|
2020-04-02 01:20:12 +02:00
|
|
|
return Object::cast_to<AudioStreamPlayer3D>(p_spatial) != nullptr;
|
2018-07-25 00:08:49 +02:00
|
|
|
}
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2020-07-23 00:39:21 +02:00
|
|
|
String AudioStreamPlayer3DGizmoPlugin::get_gizmo_name() const {
|
2018-07-25 00:08:49 +02:00
|
|
|
return "AudioStreamPlayer3D";
|
|
|
|
}
|
2017-07-15 06:23:10 +02:00
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
int AudioStreamPlayer3DGizmoPlugin::get_priority() const {
|
2019-03-12 00:30:50 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
String AudioStreamPlayer3DGizmoPlugin::get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_idx) const {
|
2017-07-15 06:23:10 +02:00
|
|
|
return "Emission Radius";
|
|
|
|
}
|
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
Variant AudioStreamPlayer3DGizmoPlugin::get_handle_value(EditorNode3DGizmo *p_gizmo, int p_idx) const {
|
2018-07-25 00:08:49 +02:00
|
|
|
AudioStreamPlayer3D *player = Object::cast_to<AudioStreamPlayer3D>(p_gizmo->get_spatial_node());
|
2017-07-15 06:23:10 +02:00
|
|
|
return player->get_emission_angle();
|
|
|
|
}
|
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
void AudioStreamPlayer3DGizmoPlugin::set_handle(EditorNode3DGizmo *p_gizmo, int p_idx, Camera3D *p_camera, const Point2 &p_point) {
|
2018-07-25 00:08:49 +02:00
|
|
|
AudioStreamPlayer3D *player = Object::cast_to<AudioStreamPlayer3D>(p_gizmo->get_spatial_node());
|
2017-07-15 06:23:10 +02:00
|
|
|
|
|
|
|
Transform gt = player->get_global_transform();
|
|
|
|
Transform gi = gt.affine_inverse();
|
|
|
|
|
|
|
|
Vector3 ray_from = p_camera->project_ray_origin(p_point);
|
|
|
|
Vector3 ray_dir = p_camera->project_ray_normal(p_point);
|
|
|
|
Vector3 ray_to = ray_from + ray_dir * 4096;
|
|
|
|
|
|
|
|
ray_from = gi.xform(ray_from);
|
|
|
|
ray_to = gi.xform(ray_to);
|
|
|
|
|
|
|
|
float closest_dist = 1e20;
|
|
|
|
float closest_angle = 1e20;
|
|
|
|
|
|
|
|
for (int i = 0; i < 180; i++) {
|
|
|
|
float a = i * Math_PI / 180.0;
|
|
|
|
float an = (i + 1) * Math_PI / 180.0;
|
|
|
|
|
|
|
|
Vector3 from(Math::sin(a), 0, -Math::cos(a));
|
|
|
|
Vector3 to(Math::sin(an), 0, -Math::cos(an));
|
|
|
|
|
|
|
|
Vector3 r1, r2;
|
2020-05-25 19:20:45 +02:00
|
|
|
Geometry3D::get_closest_points_between_segments(from, to, ray_from, ray_to, r1, r2);
|
2017-07-15 06:23:10 +02:00
|
|
|
float d = r1.distance_to(r2);
|
|
|
|
if (d < closest_dist) {
|
|
|
|
closest_dist = d;
|
|
|
|
closest_angle = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (closest_angle < 91) {
|
|
|
|
player->set_emission_angle(closest_angle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
void AudioStreamPlayer3DGizmoPlugin::commit_handle(EditorNode3DGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel) {
|
2018-07-25 00:08:49 +02:00
|
|
|
AudioStreamPlayer3D *player = Object::cast_to<AudioStreamPlayer3D>(p_gizmo->get_spatial_node());
|
2017-07-15 06:23:10 +02:00
|
|
|
|
|
|
|
if (p_cancel) {
|
|
|
|
player->set_emission_angle(p_restore);
|
|
|
|
|
|
|
|
} else {
|
2020-03-26 22:49:16 +01:00
|
|
|
UndoRedo *ur = Node3DEditor::get_singleton()->get_undo_redo();
|
2017-07-15 06:23:10 +02:00
|
|
|
ur->create_action(TTR("Change AudioStreamPlayer3D Emission Angle"));
|
|
|
|
ur->add_do_method(player, "set_emission_angle", player->get_emission_angle());
|
|
|
|
ur->add_undo_method(player, "set_emission_angle", p_restore);
|
|
|
|
ur->commit_action();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
void AudioStreamPlayer3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
|
2019-09-24 22:39:54 +02:00
|
|
|
const AudioStreamPlayer3D *player = Object::cast_to<AudioStreamPlayer3D>(p_gizmo->get_spatial_node());
|
2018-07-25 00:08:49 +02:00
|
|
|
|
|
|
|
p_gizmo->clear();
|
2017-07-15 06:23:10 +02:00
|
|
|
|
2019-09-24 22:39:54 +02:00
|
|
|
const Ref<Material> icon = get_material("stream_player_3d_icon", p_gizmo);
|
2017-08-26 05:40:45 +02:00
|
|
|
|
2017-07-15 06:23:10 +02:00
|
|
|
if (player->is_emission_angle_enabled()) {
|
2019-09-24 22:39:54 +02:00
|
|
|
const float pc = player->get_emission_angle();
|
|
|
|
const float ofs = -Math::cos(Math::deg2rad(pc));
|
|
|
|
const float radius = Math::sin(Math::deg2rad(pc));
|
2017-07-15 06:23:10 +02:00
|
|
|
|
2019-09-24 22:39:54 +02:00
|
|
|
Vector<Vector3> points_primary;
|
|
|
|
points_primary.resize(200);
|
2017-07-15 06:23:10 +02:00
|
|
|
|
|
|
|
for (int i = 0; i < 100; i++) {
|
2019-09-24 22:39:54 +02:00
|
|
|
const float a = i * 2.0 * Math_PI / 100.0;
|
|
|
|
const float an = (i + 1) * 2.0 * Math_PI / 100.0;
|
2017-07-15 06:23:10 +02:00
|
|
|
|
2019-09-24 22:39:54 +02:00
|
|
|
const Vector3 from(Math::sin(a) * radius, Math::cos(a) * radius, ofs);
|
|
|
|
const Vector3 to(Math::sin(an) * radius, Math::cos(an) * radius, ofs);
|
2017-07-15 06:23:10 +02:00
|
|
|
|
2019-09-24 22:39:54 +02:00
|
|
|
points_primary.write[i * 2 + 0] = from;
|
|
|
|
points_primary.write[i * 2 + 1] = to;
|
2017-07-15 06:23:10 +02:00
|
|
|
}
|
|
|
|
|
2019-09-24 22:39:54 +02:00
|
|
|
const Ref<Material> material_primary = get_material("stream_player_3d_material_primary", p_gizmo);
|
|
|
|
p_gizmo->add_lines(points_primary, material_primary);
|
2017-07-15 06:23:10 +02:00
|
|
|
|
2019-09-24 22:39:54 +02:00
|
|
|
Vector<Vector3> points_secondary;
|
|
|
|
points_secondary.resize(16);
|
2017-07-15 06:23:10 +02:00
|
|
|
|
2019-09-24 22:39:54 +02:00
|
|
|
for (int i = 0; i < 8; i++) {
|
|
|
|
const float a = i * 2.0 * Math_PI / 8.0;
|
|
|
|
const Vector3 from(Math::sin(a) * radius, Math::cos(a) * radius, ofs);
|
|
|
|
|
|
|
|
points_secondary.write[i * 2 + 0] = from;
|
|
|
|
points_secondary.write[i * 2 + 1] = Vector3();
|
2017-07-15 06:23:10 +02:00
|
|
|
}
|
|
|
|
|
2019-09-24 22:39:54 +02:00
|
|
|
const Ref<Material> material_secondary = get_material("stream_player_3d_material_secondary", p_gizmo);
|
|
|
|
p_gizmo->add_lines(points_secondary, material_secondary);
|
2017-07-15 06:23:10 +02:00
|
|
|
|
|
|
|
Vector<Vector3> handles;
|
2019-09-24 22:39:54 +02:00
|
|
|
const float ha = Math::deg2rad(player->get_emission_angle());
|
2017-07-15 06:23:10 +02:00
|
|
|
handles.push_back(Vector3(Math::sin(ha), 0, -Math::cos(ha)));
|
2018-07-25 00:08:49 +02:00
|
|
|
p_gizmo->add_handles(handles, get_material("handles"));
|
2017-07-15 06:23:10 +02:00
|
|
|
}
|
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
p_gizmo->add_unscaled_billboard(icon, 0.05);
|
|
|
|
}
|
|
|
|
|
|
|
|
//////
|
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
Camera3DGizmoPlugin::Camera3DGizmoPlugin() {
|
2018-07-25 00:08:49 +02:00
|
|
|
Color gizmo_color = EDITOR_DEF("editors/3d_gizmos/gizmo_colors/camera", Color(0.8, 0.4, 0.8));
|
|
|
|
|
|
|
|
create_material("camera_material", gizmo_color);
|
|
|
|
create_handle_material("handles");
|
2017-07-15 06:23:10 +02:00
|
|
|
}
|
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
bool Camera3DGizmoPlugin::has_gizmo(Node3D *p_spatial) {
|
2020-04-02 01:20:12 +02:00
|
|
|
return Object::cast_to<Camera3D>(p_spatial) != nullptr;
|
2018-07-25 00:08:49 +02:00
|
|
|
}
|
2017-07-15 06:23:10 +02:00
|
|
|
|
2020-07-23 00:39:21 +02:00
|
|
|
String Camera3DGizmoPlugin::get_gizmo_name() const {
|
2020-03-26 22:49:16 +01:00
|
|
|
return "Camera3D";
|
2017-07-15 06:23:10 +02:00
|
|
|
}
|
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
int Camera3DGizmoPlugin::get_priority() const {
|
2019-03-12 00:30:50 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
String Camera3DGizmoPlugin::get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_idx) const {
|
2020-03-26 22:49:16 +01:00
|
|
|
Camera3D *camera = Object::cast_to<Camera3D>(p_gizmo->get_spatial_node());
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
if (camera->get_projection() == Camera3D::PROJECTION_PERSPECTIVE) {
|
2016-05-21 01:18:35 +02:00
|
|
|
return "FOV";
|
2015-10-08 20:00:40 +02:00
|
|
|
} else {
|
2016-05-21 01:18:35 +02:00
|
|
|
return "Size";
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
}
|
2018-07-25 00:08:49 +02:00
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
Variant Camera3DGizmoPlugin::get_handle_value(EditorNode3DGizmo *p_gizmo, int p_idx) const {
|
2020-03-26 22:49:16 +01:00
|
|
|
Camera3D *camera = Object::cast_to<Camera3D>(p_gizmo->get_spatial_node());
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
if (camera->get_projection() == Camera3D::PROJECTION_PERSPECTIVE) {
|
2015-10-08 20:00:40 +02:00
|
|
|
return camera->get_fov();
|
|
|
|
} else {
|
|
|
|
return camera->get_size();
|
|
|
|
}
|
|
|
|
}
|
2018-07-25 00:08:49 +02:00
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
void Camera3DGizmoPlugin::set_handle(EditorNode3DGizmo *p_gizmo, int p_idx, Camera3D *p_camera, const Point2 &p_point) {
|
2020-03-26 22:49:16 +01:00
|
|
|
Camera3D *camera = Object::cast_to<Camera3D>(p_gizmo->get_spatial_node());
|
2015-10-08 20:00:40 +02:00
|
|
|
|
|
|
|
Transform gt = camera->get_global_transform();
|
|
|
|
Transform gi = gt.affine_inverse();
|
|
|
|
|
|
|
|
Vector3 ray_from = p_camera->project_ray_origin(p_point);
|
|
|
|
Vector3 ray_dir = p_camera->project_ray_normal(p_point);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Vector3 s[2] = { gi.xform(ray_from), gi.xform(ray_from + ray_dir * 4096) };
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
if (camera->get_projection() == Camera3D::PROJECTION_PERSPECTIVE) {
|
2019-02-12 21:10:08 +01:00
|
|
|
Transform gt2 = camera->get_global_transform();
|
|
|
|
float a = _find_closest_angle_to_half_pi_arc(s[0], s[1], 1.0, gt2);
|
2019-12-29 04:36:57 +01:00
|
|
|
camera->set("fov", CLAMP(a * 2.0, 1, 179));
|
2015-10-08 20:00:40 +02:00
|
|
|
} else {
|
2017-03-05 16:44:50 +01:00
|
|
|
Vector3 ra, rb;
|
2020-05-25 19:20:45 +02:00
|
|
|
Geometry3D::get_closest_points_between_segments(Vector3(0, 0, -1), Vector3(4096, 0, -1), s[0], s[1], ra, rb);
|
2015-10-08 20:00:40 +02:00
|
|
|
float d = ra.x * 2.0;
|
2020-03-26 22:49:16 +01:00
|
|
|
if (Node3DEditor::get_singleton()->is_snap_enabled()) {
|
|
|
|
d = Math::stepify(d, Node3DEditor::get_singleton()->get_translate_snap());
|
2019-07-03 12:11:12 +02:00
|
|
|
}
|
|
|
|
|
2019-12-29 04:36:57 +01:00
|
|
|
d = CLAMP(d, 0.1, 16384);
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
camera->set("size", d);
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
}
|
2018-07-25 00:08:49 +02:00
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
void Camera3DGizmoPlugin::commit_handle(EditorNode3DGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel) {
|
2020-03-26 22:49:16 +01:00
|
|
|
Camera3D *camera = Object::cast_to<Camera3D>(p_gizmo->get_spatial_node());
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
if (camera->get_projection() == Camera3D::PROJECTION_PERSPECTIVE) {
|
2015-10-08 20:00:40 +02:00
|
|
|
if (p_cancel) {
|
2017-03-05 16:44:50 +01:00
|
|
|
camera->set("fov", p_restore);
|
2015-10-08 20:00:40 +02:00
|
|
|
} else {
|
2020-03-26 22:49:16 +01:00
|
|
|
UndoRedo *ur = Node3DEditor::get_singleton()->get_undo_redo();
|
2016-05-04 03:25:37 +02:00
|
|
|
ur->create_action(TTR("Change Camera FOV"));
|
2017-03-05 16:44:50 +01:00
|
|
|
ur->add_do_property(camera, "fov", camera->get_fov());
|
|
|
|
ur->add_undo_property(camera, "fov", p_restore);
|
2015-10-08 20:00:40 +02:00
|
|
|
ur->commit_action();
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
if (p_cancel) {
|
2017-03-05 16:44:50 +01:00
|
|
|
camera->set("size", p_restore);
|
2015-10-08 20:00:40 +02:00
|
|
|
} else {
|
2020-03-26 22:49:16 +01:00
|
|
|
UndoRedo *ur = Node3DEditor::get_singleton()->get_undo_redo();
|
2016-05-04 03:25:37 +02:00
|
|
|
ur->create_action(TTR("Change Camera Size"));
|
2017-03-05 16:44:50 +01:00
|
|
|
ur->add_do_property(camera, "size", camera->get_size());
|
|
|
|
ur->add_undo_property(camera, "size", p_restore);
|
2015-10-08 20:00:40 +02:00
|
|
|
ur->commit_action();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
void Camera3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
|
2020-03-26 22:49:16 +01:00
|
|
|
Camera3D *camera = Object::cast_to<Camera3D>(p_gizmo->get_spatial_node());
|
2018-07-25 00:08:49 +02:00
|
|
|
|
|
|
|
p_gizmo->clear();
|
2015-10-08 20:00:40 +02:00
|
|
|
|
|
|
|
Vector<Vector3> lines;
|
|
|
|
Vector<Vector3> handles;
|
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
Ref<Material> material = get_material("camera_material", p_gizmo);
|
2017-08-26 05:40:45 +02:00
|
|
|
|
2019-02-19 17:17:02 +01:00
|
|
|
#define ADD_TRIANGLE(m_a, m_b, m_c) \
|
|
|
|
{ \
|
|
|
|
lines.push_back(m_a); \
|
|
|
|
lines.push_back(m_b); \
|
|
|
|
lines.push_back(m_b); \
|
|
|
|
lines.push_back(m_c); \
|
|
|
|
lines.push_back(m_c); \
|
|
|
|
lines.push_back(m_a); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define ADD_QUAD(m_a, m_b, m_c, m_d) \
|
|
|
|
{ \
|
|
|
|
lines.push_back(m_a); \
|
|
|
|
lines.push_back(m_b); \
|
|
|
|
lines.push_back(m_b); \
|
|
|
|
lines.push_back(m_c); \
|
|
|
|
lines.push_back(m_c); \
|
|
|
|
lines.push_back(m_d); \
|
|
|
|
lines.push_back(m_d); \
|
|
|
|
lines.push_back(m_a); \
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
switch (camera->get_projection()) {
|
2020-03-26 22:49:16 +01:00
|
|
|
case Camera3D::PROJECTION_PERSPECTIVE: {
|
2018-02-04 23:28:04 +01:00
|
|
|
// The real FOV is halved for accurate representation
|
|
|
|
float fov = camera->get_fov() / 2.0;
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Vector3 side = Vector3(Math::sin(Math::deg2rad(fov)), 0, -Math::cos(Math::deg2rad(fov)));
|
|
|
|
Vector3 nside = side;
|
|
|
|
nside.x = -nside.x;
|
|
|
|
Vector3 up = Vector3(0, side.x, 0);
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ADD_TRIANGLE(Vector3(), side + up, side - up);
|
|
|
|
ADD_TRIANGLE(Vector3(), nside + up, nside - up);
|
|
|
|
ADD_TRIANGLE(Vector3(), side + up, nside + up);
|
|
|
|
ADD_TRIANGLE(Vector3(), side - up, nside - up);
|
2015-10-08 20:00:40 +02:00
|
|
|
|
|
|
|
handles.push_back(side);
|
2017-03-05 16:44:50 +01:00
|
|
|
side.x *= 0.25;
|
|
|
|
nside.x *= 0.25;
|
|
|
|
Vector3 tup(0, up.y * 3 / 2, side.z);
|
|
|
|
ADD_TRIANGLE(tup, side + up, nside + up);
|
2015-10-08 20:00:40 +02:00
|
|
|
|
|
|
|
} break;
|
2020-03-26 22:49:16 +01:00
|
|
|
case Camera3D::PROJECTION_ORTHOGONAL: {
|
2015-10-08 20:00:40 +02:00
|
|
|
float size = camera->get_size();
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
float hsize = size * 0.5;
|
|
|
|
Vector3 right(hsize, 0, 0);
|
|
|
|
Vector3 up(0, hsize, 0);
|
|
|
|
Vector3 back(0, 0, -1.0);
|
|
|
|
Vector3 front(0, 0, 0);
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ADD_QUAD(-up - right, -up + right, up + right, up - right);
|
|
|
|
ADD_QUAD(-up - right + back, -up + right + back, up + right + back, up - right + back);
|
|
|
|
ADD_QUAD(up + right, up + right + back, up - right + back, up - right);
|
|
|
|
ADD_QUAD(-up + right, -up + right + back, -up - right + back, -up - right);
|
2019-02-19 17:17:02 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
handles.push_back(right + back);
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
right.x *= 0.25;
|
|
|
|
Vector3 tup(0, up.y * 3 / 2, back.z);
|
|
|
|
ADD_TRIANGLE(tup, right + up + back, -right + up + back);
|
2015-10-08 20:00:40 +02:00
|
|
|
|
|
|
|
} break;
|
2020-03-26 22:49:16 +01:00
|
|
|
case Camera3D::PROJECTION_FRUSTUM: {
|
2019-02-19 17:17:02 +01:00
|
|
|
float hsize = camera->get_size() / 2.0;
|
|
|
|
|
|
|
|
Vector3 side = Vector3(hsize, 0, -camera->get_znear()).normalized();
|
|
|
|
Vector3 nside = side;
|
|
|
|
nside.x = -nside.x;
|
|
|
|
Vector3 up = Vector3(0, side.x, 0);
|
|
|
|
Vector3 offset = Vector3(camera->get_frustum_offset().x, camera->get_frustum_offset().y, 0.0);
|
|
|
|
|
|
|
|
ADD_TRIANGLE(Vector3(), side + up + offset, side - up + offset);
|
|
|
|
ADD_TRIANGLE(Vector3(), nside + up + offset, nside - up + offset);
|
|
|
|
ADD_TRIANGLE(Vector3(), side + up + offset, nside + up + offset);
|
|
|
|
ADD_TRIANGLE(Vector3(), side - up + offset, nside - up + offset);
|
|
|
|
|
|
|
|
side.x *= 0.25;
|
|
|
|
nside.x *= 0.25;
|
|
|
|
Vector3 tup(0, up.y * 3 / 2, side.z);
|
|
|
|
ADD_TRIANGLE(tup + offset, side + up + offset, nside + up + offset);
|
|
|
|
}
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
|
2019-02-19 17:17:02 +01:00
|
|
|
#undef ADD_TRIANGLE
|
|
|
|
#undef ADD_QUAD
|
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
p_gizmo->add_lines(lines, material);
|
|
|
|
p_gizmo->add_handles(handles, get_material("handles"));
|
2018-08-21 16:48:17 +02:00
|
|
|
|
2020-03-27 08:44:44 +01:00
|
|
|
ClippedCamera3D *clipcam = Object::cast_to<ClippedCamera3D>(camera);
|
2018-08-21 16:48:17 +02:00
|
|
|
if (clipcam) {
|
2020-03-26 22:49:16 +01:00
|
|
|
Node3D *parent = Object::cast_to<Node3D>(camera->get_parent());
|
2018-08-21 16:48:17 +02:00
|
|
|
if (!parent) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Vector3 cam_normal = -camera->get_global_transform().basis.get_axis(Vector3::AXIS_Z).normalized();
|
|
|
|
Vector3 cam_x = camera->get_global_transform().basis.get_axis(Vector3::AXIS_X).normalized();
|
|
|
|
Vector3 cam_y = camera->get_global_transform().basis.get_axis(Vector3::AXIS_Y).normalized();
|
|
|
|
Vector3 cam_pos = camera->get_global_transform().origin;
|
|
|
|
Vector3 parent_pos = parent->get_global_transform().origin;
|
|
|
|
|
|
|
|
Plane parent_plane(parent_pos, cam_normal);
|
|
|
|
Vector3 ray_from = parent_plane.project(cam_pos);
|
|
|
|
|
|
|
|
lines.clear();
|
|
|
|
lines.push_back(ray_from + cam_x * 0.5 + cam_y * 0.5);
|
|
|
|
lines.push_back(ray_from + cam_x * 0.5 + cam_y * -0.5);
|
|
|
|
|
|
|
|
lines.push_back(ray_from + cam_x * 0.5 + cam_y * -0.5);
|
|
|
|
lines.push_back(ray_from + cam_x * -0.5 + cam_y * -0.5);
|
|
|
|
|
|
|
|
lines.push_back(ray_from + cam_x * -0.5 + cam_y * -0.5);
|
|
|
|
lines.push_back(ray_from + cam_x * -0.5 + cam_y * 0.5);
|
|
|
|
|
|
|
|
lines.push_back(ray_from + cam_x * -0.5 + cam_y * 0.5);
|
|
|
|
lines.push_back(ray_from + cam_x * 0.5 + cam_y * 0.5);
|
|
|
|
|
|
|
|
if (parent_plane.distance_to(cam_pos) < 0) {
|
|
|
|
lines.push_back(ray_from);
|
|
|
|
lines.push_back(cam_pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
Transform local = camera->get_global_transform().affine_inverse();
|
|
|
|
for (int i = 0; i < lines.size(); i++) {
|
|
|
|
lines.write[i] = local.xform(lines[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
p_gizmo->add_lines(lines, material);
|
|
|
|
}
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
//////
|
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
MeshInstance3DGizmoPlugin::MeshInstance3DGizmoPlugin() {
|
2018-07-25 00:08:49 +02:00
|
|
|
}
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
bool MeshInstance3DGizmoPlugin::has_gizmo(Node3D *p_spatial) {
|
2020-04-02 01:20:12 +02:00
|
|
|
return Object::cast_to<MeshInstance3D>(p_spatial) != nullptr && Object::cast_to<SoftBody3D>(p_spatial) == nullptr;
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
|
2020-07-23 00:39:21 +02:00
|
|
|
String MeshInstance3DGizmoPlugin::get_gizmo_name() const {
|
2020-03-26 22:49:16 +01:00
|
|
|
return "MeshInstance3D";
|
2018-07-25 00:08:49 +02:00
|
|
|
}
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
int MeshInstance3DGizmoPlugin::get_priority() const {
|
2019-03-12 00:30:50 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
bool MeshInstance3DGizmoPlugin::can_be_hidden() const {
|
2018-07-25 00:08:49 +02:00
|
|
|
return false;
|
2017-08-26 05:40:45 +02:00
|
|
|
}
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
void MeshInstance3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
|
2020-03-26 22:49:16 +01:00
|
|
|
MeshInstance3D *mesh = Object::cast_to<MeshInstance3D>(p_gizmo->get_spatial_node());
|
2018-07-25 00:08:49 +02:00
|
|
|
|
|
|
|
p_gizmo->clear();
|
2018-05-06 20:49:22 +02:00
|
|
|
|
2017-08-19 00:25:18 +02:00
|
|
|
Ref<Mesh> m = mesh->get_mesh();
|
2018-07-25 00:08:49 +02:00
|
|
|
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!m.is_valid()) {
|
2015-10-08 20:00:40 +02:00
|
|
|
return; //none
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2015-10-08 20:00:40 +02:00
|
|
|
|
|
|
|
Ref<TriangleMesh> tm = m->generate_triangle_mesh();
|
2017-09-12 15:06:13 +02:00
|
|
|
if (tm.is_valid()) {
|
2018-07-25 00:08:49 +02:00
|
|
|
p_gizmo->add_collision_triangles(tm);
|
2017-09-12 15:06:13 +02:00
|
|
|
}
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
/////
|
2020-04-06 12:40:52 +02:00
|
|
|
Sprite3DGizmoPlugin::Sprite3DGizmoPlugin() {
|
2018-07-25 00:08:49 +02:00
|
|
|
}
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
bool Sprite3DGizmoPlugin::has_gizmo(Node3D *p_spatial) {
|
2020-04-02 01:20:12 +02:00
|
|
|
return Object::cast_to<Sprite3D>(p_spatial) != nullptr;
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
|
2020-07-23 00:39:21 +02:00
|
|
|
String Sprite3DGizmoPlugin::get_gizmo_name() const {
|
2018-07-25 00:08:49 +02:00
|
|
|
return "Sprite3D";
|
|
|
|
}
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
int Sprite3DGizmoPlugin::get_priority() const {
|
2019-03-12 00:30:50 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
bool Sprite3DGizmoPlugin::can_be_hidden() const {
|
2018-07-25 00:08:49 +02:00
|
|
|
return false;
|
2018-05-06 20:49:22 +02:00
|
|
|
}
|
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
void Sprite3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
|
2018-07-25 00:08:49 +02:00
|
|
|
Sprite3D *sprite = Object::cast_to<Sprite3D>(p_gizmo->get_spatial_node());
|
|
|
|
|
|
|
|
p_gizmo->clear();
|
2018-05-06 20:49:22 +02:00
|
|
|
|
|
|
|
Ref<TriangleMesh> tm = sprite->generate_triangle_mesh();
|
|
|
|
if (tm.is_valid()) {
|
2018-07-25 00:08:49 +02:00
|
|
|
p_gizmo->add_collision_triangles(tm);
|
2018-05-06 20:49:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
///
|
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
Position3DGizmoPlugin::Position3DGizmoPlugin() {
|
2018-07-25 00:08:49 +02:00
|
|
|
pos3d_mesh = Ref<ArrayMesh>(memnew(ArrayMesh));
|
|
|
|
cursor_points = Vector<Vector3>();
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2020-02-17 22:06:54 +01:00
|
|
|
Vector<Color> cursor_colors;
|
2015-10-08 20:00:40 +02:00
|
|
|
float cs = 0.25;
|
2017-03-05 16:44:50 +01:00
|
|
|
cursor_points.push_back(Vector3(+cs, 0, 0));
|
|
|
|
cursor_points.push_back(Vector3(-cs, 0, 0));
|
|
|
|
cursor_points.push_back(Vector3(0, +cs, 0));
|
|
|
|
cursor_points.push_back(Vector3(0, -cs, 0));
|
|
|
|
cursor_points.push_back(Vector3(0, 0, +cs));
|
|
|
|
cursor_points.push_back(Vector3(0, 0, -cs));
|
2020-03-12 13:37:40 +01:00
|
|
|
cursor_colors.push_back(EditorNode::get_singleton()->get_gui_base()->get_theme_color("axis_x_color", "Editor"));
|
|
|
|
cursor_colors.push_back(EditorNode::get_singleton()->get_gui_base()->get_theme_color("axis_x_color", "Editor"));
|
|
|
|
cursor_colors.push_back(EditorNode::get_singleton()->get_gui_base()->get_theme_color("axis_y_color", "Editor"));
|
|
|
|
cursor_colors.push_back(EditorNode::get_singleton()->get_gui_base()->get_theme_color("axis_y_color", "Editor"));
|
|
|
|
cursor_colors.push_back(EditorNode::get_singleton()->get_gui_base()->get_theme_color("axis_z_color", "Editor"));
|
|
|
|
cursor_colors.push_back(EditorNode::get_singleton()->get_gui_base()->get_theme_color("axis_z_color", "Editor"));
|
2018-07-25 00:08:49 +02:00
|
|
|
|
2019-09-15 06:01:52 +02:00
|
|
|
Ref<StandardMaterial3D> mat = memnew(StandardMaterial3D);
|
|
|
|
mat->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
|
|
|
|
mat->set_flag(StandardMaterial3D::FLAG_ALBEDO_FROM_VERTEX_COLOR, true);
|
|
|
|
mat->set_flag(StandardMaterial3D::FLAG_SRGB_VERTEX_COLOR, true);
|
|
|
|
mat->set_transparency(StandardMaterial3D::TRANSPARENCY_ALPHA);
|
2019-07-12 15:12:48 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
Array d;
|
2020-03-27 19:21:27 +01:00
|
|
|
d.resize(RS::ARRAY_MAX);
|
2018-07-25 00:08:49 +02:00
|
|
|
d[Mesh::ARRAY_VERTEX] = cursor_points;
|
|
|
|
d[Mesh::ARRAY_COLOR] = cursor_colors;
|
|
|
|
pos3d_mesh->add_surface_from_arrays(Mesh::PRIMITIVE_LINES, d);
|
|
|
|
pos3d_mesh->surface_set_material(0, mat);
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
bool Position3DGizmoPlugin::has_gizmo(Node3D *p_spatial) {
|
2020-04-02 01:20:12 +02:00
|
|
|
return Object::cast_to<Position3D>(p_spatial) != nullptr;
|
2018-07-25 00:08:49 +02:00
|
|
|
}
|
|
|
|
|
2020-07-23 00:39:21 +02:00
|
|
|
String Position3DGizmoPlugin::get_gizmo_name() const {
|
2018-07-25 00:08:49 +02:00
|
|
|
return "Position3D";
|
|
|
|
}
|
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
int Position3DGizmoPlugin::get_priority() const {
|
2019-03-12 00:30:50 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
void Position3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
|
2018-07-25 00:08:49 +02:00
|
|
|
p_gizmo->clear();
|
|
|
|
p_gizmo->add_mesh(pos3d_mesh);
|
|
|
|
p_gizmo->add_collision_segments(cursor_points);
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/////
|
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
Skeleton3DGizmoPlugin::Skeleton3DGizmoPlugin() {
|
2018-07-25 00:08:49 +02:00
|
|
|
Color gizmo_color = EDITOR_DEF("editors/3d_gizmos/gizmo_colors/skeleton", Color(1, 0.8, 0.4));
|
|
|
|
create_material("skeleton_material", gizmo_color);
|
|
|
|
}
|
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
bool Skeleton3DGizmoPlugin::has_gizmo(Node3D *p_spatial) {
|
2020-04-02 01:20:12 +02:00
|
|
|
return Object::cast_to<Skeleton3D>(p_spatial) != nullptr;
|
2018-07-25 00:08:49 +02:00
|
|
|
}
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2020-07-23 00:39:21 +02:00
|
|
|
String Skeleton3DGizmoPlugin::get_gizmo_name() const {
|
2020-03-26 22:49:16 +01:00
|
|
|
return "Skeleton3D";
|
2018-07-25 00:08:49 +02:00
|
|
|
}
|
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
int Skeleton3DGizmoPlugin::get_priority() const {
|
2019-03-12 00:30:50 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
void Skeleton3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
|
2020-03-26 22:49:16 +01:00
|
|
|
Skeleton3D *skel = Object::cast_to<Skeleton3D>(p_gizmo->get_spatial_node());
|
2018-07-25 00:08:49 +02:00
|
|
|
|
|
|
|
p_gizmo->clear();
|
|
|
|
|
|
|
|
Ref<Material> material = get_material("skeleton_material", p_gizmo);
|
2017-08-26 05:40:45 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Ref<SurfaceTool> surface_tool(memnew(SurfaceTool));
|
2015-10-08 20:00:40 +02:00
|
|
|
|
|
|
|
surface_tool->begin(Mesh::PRIMITIVE_LINES);
|
2017-08-26 05:40:45 +02:00
|
|
|
surface_tool->set_material(material);
|
2015-10-08 20:00:40 +02:00
|
|
|
Vector<Transform> grests;
|
|
|
|
grests.resize(skel->get_bone_count());
|
|
|
|
|
|
|
|
Vector<int> bones;
|
|
|
|
Vector<float> weights;
|
|
|
|
bones.resize(4);
|
|
|
|
weights.resize(4);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < 4; i++) {
|
2018-07-25 03:11:03 +02:00
|
|
|
bones.write[i] = 0;
|
|
|
|
weights.write[i] = 0;
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
|
2018-07-25 03:11:03 +02:00
|
|
|
weights.write[0] = 1;
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2017-11-17 03:09:00 +01:00
|
|
|
AABB aabb;
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Color bonecolor = Color(1.0, 0.4, 0.4, 0.3);
|
|
|
|
Color rootcolor = Color(0.4, 1.0, 0.4, 0.1);
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2018-08-07 03:35:09 +02:00
|
|
|
for (int i_bone = 0; i_bone < skel->get_bone_count(); i_bone++) {
|
|
|
|
int i = skel->get_process_order(i_bone);
|
2015-10-08 20:00:40 +02:00
|
|
|
|
|
|
|
int parent = skel->get_bone_parent(i);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (parent >= 0) {
|
2018-07-25 03:11:03 +02:00
|
|
|
grests.write[i] = grests[parent] * skel->get_bone_rest(i);
|
2015-10-08 20:00:40 +02:00
|
|
|
|
|
|
|
Vector3 v0 = grests[parent].origin;
|
|
|
|
Vector3 v1 = grests[i].origin;
|
2017-03-05 16:44:50 +01:00
|
|
|
Vector3 d = (v1 - v0).normalized();
|
2015-10-08 20:00:40 +02:00
|
|
|
float dist = v0.distance_to(v1);
|
|
|
|
|
|
|
|
//find closest axis
|
2017-03-05 16:44:50 +01:00
|
|
|
int closest = -1;
|
2015-10-08 20:00:40 +02:00
|
|
|
float closest_d = 0.0;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int j = 0; j < 3; j++) {
|
2015-10-08 20:00:40 +02:00
|
|
|
float dp = Math::abs(grests[parent].basis[j].normalized().dot(d));
|
2020-05-14 16:41:43 +02:00
|
|
|
if (j == 0 || dp > closest_d) {
|
2017-03-05 16:44:50 +01:00
|
|
|
closest = j;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//find closest other
|
|
|
|
Vector3 first;
|
|
|
|
Vector3 points[4];
|
2017-03-05 16:44:50 +01:00
|
|
|
int pointidx = 0;
|
|
|
|
for (int j = 0; j < 3; j++) {
|
2018-07-25 03:11:03 +02:00
|
|
|
bones.write[0] = parent;
|
2020-12-02 02:40:47 +01:00
|
|
|
surface_tool->set_bones(bones);
|
|
|
|
surface_tool->set_weights(weights);
|
|
|
|
surface_tool->set_color(rootcolor);
|
2017-03-05 16:44:50 +01:00
|
|
|
surface_tool->add_vertex(v0 - grests[parent].basis[j].normalized() * dist * 0.05);
|
2020-12-02 02:40:47 +01:00
|
|
|
surface_tool->set_bones(bones);
|
|
|
|
surface_tool->set_weights(weights);
|
|
|
|
surface_tool->set_color(rootcolor);
|
2017-03-05 16:44:50 +01:00
|
|
|
surface_tool->add_vertex(v0 + grests[parent].basis[j].normalized() * dist * 0.05);
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2020-05-14 16:41:43 +02:00
|
|
|
if (j == closest) {
|
2015-10-08 20:00:40 +02:00
|
|
|
continue;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2015-10-08 20:00:40 +02:00
|
|
|
|
|
|
|
Vector3 axis;
|
2017-03-05 16:44:50 +01:00
|
|
|
if (first == Vector3()) {
|
2015-10-08 20:00:40 +02:00
|
|
|
axis = d.cross(d.cross(grests[parent].basis[j])).normalized();
|
2017-03-05 16:44:50 +01:00
|
|
|
first = axis;
|
2015-10-08 20:00:40 +02:00
|
|
|
} else {
|
|
|
|
axis = d.cross(first).normalized();
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int k = 0; k < 2; k++) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (k == 1) {
|
2017-03-05 16:44:50 +01:00
|
|
|
axis = -axis;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
Vector3 point = v0 + d * dist * 0.2;
|
|
|
|
point += axis * dist * 0.1;
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2018-07-25 03:11:03 +02:00
|
|
|
bones.write[0] = parent;
|
2020-12-02 02:40:47 +01:00
|
|
|
surface_tool->set_bones(bones);
|
|
|
|
surface_tool->set_weights(weights);
|
|
|
|
surface_tool->set_color(bonecolor);
|
2015-10-08 20:00:40 +02:00
|
|
|
surface_tool->add_vertex(v0);
|
2020-12-02 02:40:47 +01:00
|
|
|
surface_tool->set_bones(bones);
|
|
|
|
surface_tool->set_weights(weights);
|
|
|
|
surface_tool->set_color(bonecolor);
|
2015-10-08 20:00:40 +02:00
|
|
|
surface_tool->add_vertex(point);
|
|
|
|
|
2018-07-25 03:11:03 +02:00
|
|
|
bones.write[0] = parent;
|
2020-12-02 02:40:47 +01:00
|
|
|
surface_tool->set_bones(bones);
|
|
|
|
surface_tool->set_weights(weights);
|
|
|
|
surface_tool->set_color(bonecolor);
|
2015-10-08 20:00:40 +02:00
|
|
|
surface_tool->add_vertex(point);
|
2018-07-25 03:11:03 +02:00
|
|
|
bones.write[0] = i;
|
2020-12-02 02:40:47 +01:00
|
|
|
surface_tool->set_bones(bones);
|
|
|
|
surface_tool->set_weights(weights);
|
|
|
|
surface_tool->set_color(bonecolor);
|
2015-10-08 20:00:40 +02:00
|
|
|
surface_tool->add_vertex(v1);
|
2017-03-05 16:44:50 +01:00
|
|
|
points[pointidx++] = point;
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
SWAP(points[1], points[2]);
|
|
|
|
for (int j = 0; j < 4; j++) {
|
2018-07-25 03:11:03 +02:00
|
|
|
bones.write[0] = parent;
|
2020-12-02 02:40:47 +01:00
|
|
|
surface_tool->set_bones(bones);
|
|
|
|
surface_tool->set_weights(weights);
|
|
|
|
surface_tool->set_color(bonecolor);
|
2015-10-08 20:00:40 +02:00
|
|
|
surface_tool->add_vertex(points[j]);
|
2020-12-02 02:40:47 +01:00
|
|
|
surface_tool->set_bones(bones);
|
|
|
|
surface_tool->set_weights(weights);
|
|
|
|
surface_tool->set_color(bonecolor);
|
2017-03-05 16:44:50 +01:00
|
|
|
surface_tool->add_vertex(points[(j + 1) % 4]);
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
/*
|
2015-10-08 20:00:40 +02:00
|
|
|
bones[0]=parent;
|
|
|
|
surface_tool->add_bones(bones);
|
|
|
|
surface_tool->add_weights(weights);
|
|
|
|
surface_tool->add_color(Color(0.4,1,0.4,0.4));
|
|
|
|
surface_tool->add_vertex(v0);
|
|
|
|
bones[0]=i;
|
|
|
|
surface_tool->add_bones(bones);
|
|
|
|
surface_tool->add_weights(weights);
|
|
|
|
surface_tool->add_color(Color(0.4,1,0.4,0.4));
|
|
|
|
surface_tool->add_vertex(v1);
|
|
|
|
*/
|
|
|
|
} else {
|
2018-07-25 03:11:03 +02:00
|
|
|
grests.write[i] = skel->get_bone_rest(i);
|
|
|
|
bones.write[0] = i;
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
/*
|
2015-10-08 20:00:40 +02:00
|
|
|
Transform t = grests[i];
|
|
|
|
t.orthonormalize();
|
|
|
|
|
|
|
|
for (int i=0;i<6;i++) {
|
|
|
|
|
|
|
|
|
|
|
|
Vector3 face_points[4];
|
|
|
|
|
|
|
|
for (int j=0;j<4;j++) {
|
|
|
|
float v[3];
|
|
|
|
v[0]=1.0;
|
|
|
|
v[1]=1-2*((j>>1)&1);
|
|
|
|
v[2]=v[1]*(1-2*(j&1));
|
|
|
|
|
|
|
|
for (int k=0;k<3;k++) {
|
|
|
|
if (i<3)
|
|
|
|
face_points[j][(i+k)%3]=v[k]*(i>=3?-1:1);
|
|
|
|
else
|
|
|
|
face_points[3-j][(i+k)%3]=v[k]*(i>=3?-1:1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for(int j=0;j<4;j++) {
|
|
|
|
surface_tool->add_bones(bones);
|
|
|
|
surface_tool->add_weights(weights);
|
|
|
|
surface_tool->add_color(Color(1.0,0.4,0.4,0.4));
|
|
|
|
surface_tool->add_vertex(t.xform(face_points[j]*0.04));
|
|
|
|
surface_tool->add_bones(bones);
|
|
|
|
surface_tool->add_weights(weights);
|
|
|
|
surface_tool->add_color(Color(1.0,0.4,0.4,0.4));
|
|
|
|
surface_tool->add_vertex(t.xform(face_points[(j+1)%4]*0.04));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
2017-06-07 23:18:55 +02:00
|
|
|
Ref<ArrayMesh> m = surface_tool->commit();
|
2019-09-19 00:46:32 +02:00
|
|
|
p_gizmo->add_mesh(m, false, skel->register_skin(Ref<Skin>()));
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
////
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
PhysicalBone3DGizmoPlugin::PhysicalBone3DGizmoPlugin() {
|
2018-07-25 00:08:49 +02:00
|
|
|
create_material("joint_material", EDITOR_DEF("editors/3d_gizmos/gizmo_colors/joint", Color(0.5, 0.8, 1)));
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
2017-12-17 15:29:39 +01:00
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
bool PhysicalBone3DGizmoPlugin::has_gizmo(Node3D *p_spatial) {
|
2020-04-02 01:20:12 +02:00
|
|
|
return Object::cast_to<PhysicalBone3D>(p_spatial) != nullptr;
|
2017-10-03 18:49:32 +02:00
|
|
|
}
|
|
|
|
|
2020-07-23 00:39:21 +02:00
|
|
|
String PhysicalBone3DGizmoPlugin::get_gizmo_name() const {
|
2020-04-06 12:40:52 +02:00
|
|
|
return "PhysicalBone3D";
|
2018-07-25 00:08:49 +02:00
|
|
|
}
|
2017-10-03 18:49:32 +02:00
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
int PhysicalBone3DGizmoPlugin::get_priority() const {
|
2019-03-12 00:30:50 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
void PhysicalBone3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
|
2018-07-25 00:08:49 +02:00
|
|
|
p_gizmo->clear();
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
PhysicalBone3D *physical_bone = Object::cast_to<PhysicalBone3D>(p_gizmo->get_spatial_node());
|
2017-10-03 18:49:32 +02:00
|
|
|
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!physical_bone) {
|
2017-10-03 18:49:32 +02:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2017-10-03 18:49:32 +02:00
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
Skeleton3D *sk(physical_bone->find_skeleton_parent());
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!sk) {
|
2018-08-26 11:55:58 +02:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2018-08-26 11:55:58 +02:00
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
PhysicalBone3D *pb(sk->get_physical_bone(physical_bone->get_bone_id()));
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!pb) {
|
2018-08-26 11:55:58 +02:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2018-08-26 11:55:58 +02:00
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
PhysicalBone3D *pbp(sk->get_physical_bone_parent(physical_bone->get_bone_id()));
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!pbp) {
|
2018-08-26 11:55:58 +02:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2017-10-03 18:49:32 +02:00
|
|
|
|
|
|
|
Vector<Vector3> points;
|
|
|
|
|
|
|
|
switch (physical_bone->get_joint_type()) {
|
2020-03-26 22:49:16 +01:00
|
|
|
case PhysicalBone3D::JOINT_TYPE_PIN: {
|
2020-04-06 12:40:52 +02:00
|
|
|
Joint3DGizmoPlugin::CreatePinJointGizmo(physical_bone->get_joint_offset(), points);
|
2017-10-03 18:49:32 +02:00
|
|
|
} break;
|
2020-03-26 22:49:16 +01:00
|
|
|
case PhysicalBone3D::JOINT_TYPE_CONE: {
|
|
|
|
const PhysicalBone3D::ConeJointData *cjd(static_cast<const PhysicalBone3D::ConeJointData *>(physical_bone->get_joint_data()));
|
2020-04-06 12:40:52 +02:00
|
|
|
Joint3DGizmoPlugin::CreateConeTwistJointGizmo(
|
2017-10-03 18:49:32 +02:00
|
|
|
physical_bone->get_joint_offset(),
|
|
|
|
physical_bone->get_global_transform() * physical_bone->get_joint_offset(),
|
2019-06-20 16:59:48 +02:00
|
|
|
pb->get_global_transform(),
|
|
|
|
pbp->get_global_transform(),
|
2017-10-03 18:49:32 +02:00
|
|
|
cjd->swing_span,
|
|
|
|
cjd->twist_span,
|
2019-06-20 16:59:48 +02:00
|
|
|
&points,
|
|
|
|
&points);
|
2017-10-03 18:49:32 +02:00
|
|
|
} break;
|
2020-03-26 22:49:16 +01:00
|
|
|
case PhysicalBone3D::JOINT_TYPE_HINGE: {
|
|
|
|
const PhysicalBone3D::HingeJointData *hjd(static_cast<const PhysicalBone3D::HingeJointData *>(physical_bone->get_joint_data()));
|
2020-04-06 12:40:52 +02:00
|
|
|
Joint3DGizmoPlugin::CreateHingeJointGizmo(
|
2017-10-03 18:49:32 +02:00
|
|
|
physical_bone->get_joint_offset(),
|
|
|
|
physical_bone->get_global_transform() * physical_bone->get_joint_offset(),
|
2019-06-20 16:59:48 +02:00
|
|
|
pb->get_global_transform(),
|
|
|
|
pbp->get_global_transform(),
|
2017-10-03 18:49:32 +02:00
|
|
|
hjd->angular_limit_lower,
|
|
|
|
hjd->angular_limit_upper,
|
|
|
|
hjd->angular_limit_enabled,
|
|
|
|
points,
|
2019-06-20 16:59:48 +02:00
|
|
|
&points,
|
|
|
|
&points);
|
2017-10-03 18:49:32 +02:00
|
|
|
} break;
|
2020-03-26 22:49:16 +01:00
|
|
|
case PhysicalBone3D::JOINT_TYPE_SLIDER: {
|
|
|
|
const PhysicalBone3D::SliderJointData *sjd(static_cast<const PhysicalBone3D::SliderJointData *>(physical_bone->get_joint_data()));
|
2020-04-06 12:40:52 +02:00
|
|
|
Joint3DGizmoPlugin::CreateSliderJointGizmo(
|
2017-10-03 18:49:32 +02:00
|
|
|
physical_bone->get_joint_offset(),
|
|
|
|
physical_bone->get_global_transform() * physical_bone->get_joint_offset(),
|
2019-06-20 16:59:48 +02:00
|
|
|
pb->get_global_transform(),
|
|
|
|
pbp->get_global_transform(),
|
2017-10-03 18:49:32 +02:00
|
|
|
sjd->angular_limit_lower,
|
|
|
|
sjd->angular_limit_upper,
|
|
|
|
sjd->linear_limit_lower,
|
|
|
|
sjd->linear_limit_upper,
|
|
|
|
points,
|
2019-06-20 16:59:48 +02:00
|
|
|
&points,
|
|
|
|
&points);
|
2017-10-03 18:49:32 +02:00
|
|
|
} break;
|
2020-03-26 22:49:16 +01:00
|
|
|
case PhysicalBone3D::JOINT_TYPE_6DOF: {
|
|
|
|
const PhysicalBone3D::SixDOFJointData *sdofjd(static_cast<const PhysicalBone3D::SixDOFJointData *>(physical_bone->get_joint_data()));
|
2020-04-06 12:40:52 +02:00
|
|
|
Joint3DGizmoPlugin::CreateGeneric6DOFJointGizmo(
|
2017-10-03 18:49:32 +02:00
|
|
|
physical_bone->get_joint_offset(),
|
|
|
|
|
|
|
|
physical_bone->get_global_transform() * physical_bone->get_joint_offset(),
|
2019-06-20 16:59:48 +02:00
|
|
|
pb->get_global_transform(),
|
|
|
|
pbp->get_global_transform(),
|
2017-10-03 18:49:32 +02:00
|
|
|
|
|
|
|
sdofjd->axis_data[0].angular_limit_lower,
|
|
|
|
sdofjd->axis_data[0].angular_limit_upper,
|
|
|
|
sdofjd->axis_data[0].linear_limit_lower,
|
|
|
|
sdofjd->axis_data[0].linear_limit_upper,
|
|
|
|
sdofjd->axis_data[0].angular_limit_enabled,
|
|
|
|
sdofjd->axis_data[0].linear_limit_enabled,
|
|
|
|
|
|
|
|
sdofjd->axis_data[1].angular_limit_lower,
|
|
|
|
sdofjd->axis_data[1].angular_limit_upper,
|
|
|
|
sdofjd->axis_data[1].linear_limit_lower,
|
|
|
|
sdofjd->axis_data[1].linear_limit_upper,
|
|
|
|
sdofjd->axis_data[1].angular_limit_enabled,
|
|
|
|
sdofjd->axis_data[1].linear_limit_enabled,
|
|
|
|
|
|
|
|
sdofjd->axis_data[2].angular_limit_lower,
|
|
|
|
sdofjd->axis_data[2].angular_limit_upper,
|
|
|
|
sdofjd->axis_data[2].linear_limit_lower,
|
|
|
|
sdofjd->axis_data[2].linear_limit_upper,
|
|
|
|
sdofjd->axis_data[2].angular_limit_enabled,
|
|
|
|
sdofjd->axis_data[2].linear_limit_enabled,
|
|
|
|
|
|
|
|
points,
|
2019-06-20 16:59:48 +02:00
|
|
|
&points,
|
|
|
|
&points);
|
2017-10-03 18:49:32 +02:00
|
|
|
} break;
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
Ref<Material> material = get_material("joint_material", p_gizmo);
|
2017-10-03 18:49:32 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
p_gizmo->add_collision_segments(points);
|
|
|
|
p_gizmo->add_lines(points, material);
|
2017-10-03 18:49:32 +02:00
|
|
|
}
|
|
|
|
|
2015-10-08 20:00:40 +02:00
|
|
|
/////
|
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
RayCast3DGizmoPlugin::RayCast3DGizmoPlugin() {
|
2019-08-21 15:27:02 +02:00
|
|
|
const Color gizmo_color = EDITOR_DEF("editors/3d_gizmos/gizmo_colors/shape", Color(0.5, 0.7, 1));
|
2018-07-25 00:08:49 +02:00
|
|
|
create_material("shape_material", gizmo_color);
|
2019-08-21 15:27:02 +02:00
|
|
|
const float gizmo_value = gizmo_color.get_v();
|
|
|
|
const Color gizmo_color_disabled = Color(gizmo_value, gizmo_value, gizmo_value, 0.65);
|
|
|
|
create_material("shape_material_disabled", gizmo_color_disabled);
|
2018-07-25 00:08:49 +02:00
|
|
|
}
|
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
bool RayCast3DGizmoPlugin::has_gizmo(Node3D *p_spatial) {
|
2020-04-02 01:20:12 +02:00
|
|
|
return Object::cast_to<RayCast3D>(p_spatial) != nullptr;
|
2018-07-25 00:08:49 +02:00
|
|
|
}
|
|
|
|
|
2020-07-23 00:39:21 +02:00
|
|
|
String RayCast3DGizmoPlugin::get_gizmo_name() const {
|
2020-03-30 18:22:57 +02:00
|
|
|
return "RayCast3D";
|
2018-07-25 00:08:49 +02:00
|
|
|
}
|
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
int RayCast3DGizmoPlugin::get_priority() const {
|
2019-03-12 00:30:50 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
void RayCast3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
|
2020-03-26 22:49:16 +01:00
|
|
|
RayCast3D *raycast = Object::cast_to<RayCast3D>(p_gizmo->get_spatial_node());
|
2018-07-25 00:08:49 +02:00
|
|
|
|
|
|
|
p_gizmo->clear();
|
2015-10-08 20:00:40 +02:00
|
|
|
|
|
|
|
Vector<Vector3> lines;
|
|
|
|
|
|
|
|
lines.push_back(Vector3());
|
2020-09-10 19:06:21 +02:00
|
|
|
lines.push_back(raycast->get_target_position());
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2019-09-15 06:01:52 +02:00
|
|
|
const Ref<StandardMaterial3D> material =
|
2019-08-21 15:27:02 +02:00
|
|
|
get_material(raycast->is_enabled() ? "shape_material" : "shape_material_disabled", p_gizmo);
|
2017-08-26 05:40:45 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
p_gizmo->add_lines(lines, material);
|
|
|
|
p_gizmo->add_collision_segments(lines);
|
|
|
|
}
|
|
|
|
|
|
|
|
/////
|
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
void SpringArm3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
|
2020-03-26 22:49:16 +01:00
|
|
|
SpringArm3D *spring_arm = Object::cast_to<SpringArm3D>(p_gizmo->get_spatial_node());
|
2018-05-13 21:27:56 +02:00
|
|
|
|
|
|
|
p_gizmo->clear();
|
|
|
|
|
|
|
|
Vector<Vector3> lines;
|
|
|
|
|
|
|
|
lines.push_back(Vector3());
|
|
|
|
lines.push_back(Vector3(0, 0, 1.0) * spring_arm->get_length());
|
|
|
|
|
2019-09-15 06:01:52 +02:00
|
|
|
Ref<StandardMaterial3D> material = get_material("shape_material", p_gizmo);
|
2018-05-13 21:27:56 +02:00
|
|
|
|
|
|
|
p_gizmo->add_lines(lines, material);
|
|
|
|
p_gizmo->add_collision_segments(lines);
|
|
|
|
}
|
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
SpringArm3DGizmoPlugin::SpringArm3DGizmoPlugin() {
|
2018-05-13 21:27:56 +02:00
|
|
|
Color gizmo_color = EDITOR_DEF("editors/3d_gizmos/gizmo_colors/shape", Color(0.5, 0.7, 1));
|
|
|
|
create_material("shape_material", gizmo_color);
|
|
|
|
}
|
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
bool SpringArm3DGizmoPlugin::has_gizmo(Node3D *p_spatial) {
|
2020-04-02 01:20:12 +02:00
|
|
|
return Object::cast_to<SpringArm3D>(p_spatial) != nullptr;
|
2018-05-13 21:27:56 +02:00
|
|
|
}
|
|
|
|
|
2020-07-23 00:39:21 +02:00
|
|
|
String SpringArm3DGizmoPlugin::get_gizmo_name() const {
|
2020-03-30 18:22:57 +02:00
|
|
|
return "SpringArm3D";
|
2018-05-13 21:27:56 +02:00
|
|
|
}
|
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
int SpringArm3DGizmoPlugin::get_priority() const {
|
2019-03-12 00:30:50 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2018-05-13 21:27:56 +02:00
|
|
|
/////
|
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
VehicleWheel3DGizmoPlugin::VehicleWheel3DGizmoPlugin() {
|
2018-07-25 00:08:49 +02:00
|
|
|
Color gizmo_color = EDITOR_DEF("editors/3d_gizmos/gizmo_colors/shape", Color(0.5, 0.7, 1));
|
|
|
|
create_material("shape_material", gizmo_color);
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
bool VehicleWheel3DGizmoPlugin::has_gizmo(Node3D *p_spatial) {
|
2020-04-02 01:20:12 +02:00
|
|
|
return Object::cast_to<VehicleWheel3D>(p_spatial) != nullptr;
|
2018-07-25 00:08:49 +02:00
|
|
|
}
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2020-07-23 00:39:21 +02:00
|
|
|
String VehicleWheel3DGizmoPlugin::get_gizmo_name() const {
|
2020-03-30 18:22:57 +02:00
|
|
|
return "VehicleWheel3D";
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
int VehicleWheel3DGizmoPlugin::get_priority() const {
|
2019-03-12 00:30:50 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
void VehicleWheel3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
|
2020-03-27 08:44:44 +01:00
|
|
|
VehicleWheel3D *car_wheel = Object::cast_to<VehicleWheel3D>(p_gizmo->get_spatial_node());
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
p_gizmo->clear();
|
2015-10-08 20:00:40 +02:00
|
|
|
|
|
|
|
Vector<Vector3> points;
|
|
|
|
|
|
|
|
float r = car_wheel->get_radius();
|
2017-03-05 16:44:50 +01:00
|
|
|
const int skip = 10;
|
|
|
|
for (int i = 0; i <= 360; i += skip) {
|
|
|
|
float ra = Math::deg2rad((float)i);
|
|
|
|
float rb = Math::deg2rad((float)i + skip);
|
|
|
|
Point2 a = Vector2(Math::sin(ra), Math::cos(ra)) * r;
|
|
|
|
Point2 b = Vector2(Math::sin(rb), Math::cos(rb)) * r;
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
points.push_back(Vector3(0, a.x, a.y));
|
|
|
|
points.push_back(Vector3(0, b.x, b.y));
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
const int springsec = 4;
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int j = 0; j < springsec; j++) {
|
|
|
|
float t = car_wheel->get_suspension_rest_length() * 5;
|
|
|
|
points.push_back(Vector3(a.x, i / 360.0 * t / springsec + j * (t / springsec), a.y) * 0.2);
|
|
|
|
points.push_back(Vector3(b.x, (i + skip) / 360.0 * t / springsec + j * (t / springsec), b.y) * 0.2);
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//travel
|
2017-03-05 16:44:50 +01:00
|
|
|
points.push_back(Vector3(0, 0, 0));
|
|
|
|
points.push_back(Vector3(0, car_wheel->get_suspension_rest_length(), 0));
|
2015-10-08 20:00:40 +02:00
|
|
|
|
|
|
|
//axis
|
2017-03-05 16:44:50 +01:00
|
|
|
points.push_back(Vector3(r * 0.2, car_wheel->get_suspension_rest_length(), 0));
|
|
|
|
points.push_back(Vector3(-r * 0.2, car_wheel->get_suspension_rest_length(), 0));
|
2015-10-08 20:00:40 +02:00
|
|
|
//axis
|
2017-03-05 16:44:50 +01:00
|
|
|
points.push_back(Vector3(r * 0.2, 0, 0));
|
|
|
|
points.push_back(Vector3(-r * 0.2, 0, 0));
|
2015-10-08 20:00:40 +02:00
|
|
|
|
|
|
|
//forward line
|
2017-03-05 16:44:50 +01:00
|
|
|
points.push_back(Vector3(0, -r, 0));
|
|
|
|
points.push_back(Vector3(0, -r, r * 2));
|
|
|
|
points.push_back(Vector3(0, -r, r * 2));
|
|
|
|
points.push_back(Vector3(r * 2 * 0.2, -r, r * 2 * 0.8));
|
|
|
|
points.push_back(Vector3(0, -r, r * 2));
|
|
|
|
points.push_back(Vector3(-r * 2 * 0.2, -r, r * 2 * 0.8));
|
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
Ref<Material> material = get_material("shape_material", p_gizmo);
|
2017-08-26 05:40:45 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
p_gizmo->add_lines(points, material);
|
|
|
|
p_gizmo->add_collision_segments(points);
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
///////////
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
SoftBody3DGizmoPlugin::SoftBody3DGizmoPlugin() {
|
2018-07-25 00:08:49 +02:00
|
|
|
Color gizmo_color = EDITOR_DEF("editors/3d_gizmos/gizmo_colors/shape", Color(0.5, 0.7, 1));
|
|
|
|
create_material("shape_material", gizmo_color);
|
|
|
|
create_handle_material("handles");
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
bool SoftBody3DGizmoPlugin::has_gizmo(Node3D *p_spatial) {
|
2020-04-02 01:20:12 +02:00
|
|
|
return Object::cast_to<SoftBody3D>(p_spatial) != nullptr;
|
2018-07-25 00:08:49 +02:00
|
|
|
}
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2020-07-23 00:39:21 +02:00
|
|
|
String SoftBody3DGizmoPlugin::get_gizmo_name() const {
|
2020-03-30 18:22:57 +02:00
|
|
|
return "SoftBody3D";
|
2018-07-25 00:08:49 +02:00
|
|
|
}
|
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
int SoftBody3DGizmoPlugin::get_priority() const {
|
2019-03-12 00:30:50 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
bool SoftBody3DGizmoPlugin::is_selectable_when_hidden() const {
|
2018-07-25 00:08:49 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
void SoftBody3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
|
2020-03-26 22:49:16 +01:00
|
|
|
SoftBody3D *soft_body = Object::cast_to<SoftBody3D>(p_gizmo->get_spatial_node());
|
2018-07-25 00:08:49 +02:00
|
|
|
|
|
|
|
p_gizmo->clear();
|
2017-11-21 01:36:32 +01:00
|
|
|
|
|
|
|
if (!soft_body || soft_body->get_mesh().is_null()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// find mesh
|
|
|
|
|
|
|
|
Vector<Vector3> lines;
|
|
|
|
|
|
|
|
soft_body->get_mesh()->generate_debug_mesh_lines(lines);
|
|
|
|
|
|
|
|
if (!lines.size()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
Ref<TriangleMesh> tm = soft_body->get_mesh()->generate_triangle_mesh();
|
|
|
|
|
2017-11-21 01:36:32 +01:00
|
|
|
Vector<Vector3> points;
|
|
|
|
soft_body->get_mesh()->generate_debug_mesh_indices(points);
|
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
Ref<Material> material = get_material("shape_material", p_gizmo);
|
2017-11-21 01:36:32 +01:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
p_gizmo->add_lines(lines, material);
|
|
|
|
p_gizmo->add_handles(points, get_material("handles"));
|
|
|
|
p_gizmo->add_collision_triangles(tm);
|
2017-11-21 01:36:32 +01:00
|
|
|
}
|
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
String SoftBody3DGizmoPlugin::get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_idx) const {
|
2020-03-30 18:22:57 +02:00
|
|
|
return "SoftBody3D pin point";
|
2017-11-21 01:36:32 +01:00
|
|
|
}
|
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
Variant SoftBody3DGizmoPlugin::get_handle_value(EditorNode3DGizmo *p_gizmo, int p_idx) const {
|
2020-03-26 22:49:16 +01:00
|
|
|
SoftBody3D *soft_body = Object::cast_to<SoftBody3D>(p_gizmo->get_spatial_node());
|
2018-07-25 00:08:49 +02:00
|
|
|
return Variant(soft_body->is_point_pinned(p_idx));
|
2017-11-21 01:36:32 +01:00
|
|
|
}
|
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
void SoftBody3DGizmoPlugin::commit_handle(EditorNode3DGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel) {
|
2020-03-26 22:49:16 +01:00
|
|
|
SoftBody3D *soft_body = Object::cast_to<SoftBody3D>(p_gizmo->get_spatial_node());
|
2018-07-25 00:08:49 +02:00
|
|
|
soft_body->pin_point_toggle(p_idx);
|
2017-11-21 01:36:32 +01:00
|
|
|
}
|
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
bool SoftBody3DGizmoPlugin::is_handle_highlighted(const EditorNode3DGizmo *p_gizmo, int idx) const {
|
2020-03-26 22:49:16 +01:00
|
|
|
SoftBody3D *soft_body = Object::cast_to<SoftBody3D>(p_gizmo->get_spatial_node());
|
2018-07-25 00:08:49 +02:00
|
|
|
return soft_body->is_point_pinned(idx);
|
2017-11-21 01:36:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
///////////
|
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
VisibilityNotifier3DGizmoPlugin::VisibilityNotifier3DGizmoPlugin() {
|
2018-07-25 00:08:49 +02:00
|
|
|
Color gizmo_color = EDITOR_DEF("editors/3d_gizmos/gizmo_colors/visibility_notifier", Color(0.8, 0.5, 0.7));
|
|
|
|
create_material("visibility_notifier_material", gizmo_color);
|
|
|
|
gizmo_color.a = 0.1;
|
|
|
|
create_material("visibility_notifier_solid_material", gizmo_color);
|
|
|
|
create_handle_material("handles");
|
|
|
|
}
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
bool VisibilityNotifier3DGizmoPlugin::has_gizmo(Node3D *p_spatial) {
|
2020-04-02 01:20:12 +02:00
|
|
|
return Object::cast_to<VisibilityNotifier3D>(p_spatial) != nullptr;
|
2018-07-25 00:08:49 +02:00
|
|
|
}
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2020-07-23 00:39:21 +02:00
|
|
|
String VisibilityNotifier3DGizmoPlugin::get_gizmo_name() const {
|
2020-03-30 18:22:57 +02:00
|
|
|
return "VisibilityNotifier3D";
|
2018-07-25 00:08:49 +02:00
|
|
|
}
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
int VisibilityNotifier3DGizmoPlugin::get_priority() const {
|
2019-03-12 00:30:50 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
String VisibilityNotifier3DGizmoPlugin::get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_idx) const {
|
2018-07-25 00:08:49 +02:00
|
|
|
switch (p_idx) {
|
2020-05-10 13:00:47 +02:00
|
|
|
case 0:
|
|
|
|
return "Size X";
|
|
|
|
case 1:
|
|
|
|
return "Size Y";
|
|
|
|
case 2:
|
|
|
|
return "Size Z";
|
|
|
|
case 3:
|
|
|
|
return "Pos X";
|
|
|
|
case 4:
|
|
|
|
return "Pos Y";
|
|
|
|
case 5:
|
|
|
|
return "Pos Z";
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
return "";
|
|
|
|
}
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
Variant VisibilityNotifier3DGizmoPlugin::get_handle_value(EditorNode3DGizmo *p_gizmo, int p_idx) const {
|
2020-03-26 22:49:16 +01:00
|
|
|
VisibilityNotifier3D *notifier = Object::cast_to<VisibilityNotifier3D>(p_gizmo->get_spatial_node());
|
2018-07-25 00:08:49 +02:00
|
|
|
return notifier->get_aabb();
|
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
void VisibilityNotifier3DGizmoPlugin::set_handle(EditorNode3DGizmo *p_gizmo, int p_idx, Camera3D *p_camera, const Point2 &p_point) {
|
2020-03-26 22:49:16 +01:00
|
|
|
VisibilityNotifier3D *notifier = Object::cast_to<VisibilityNotifier3D>(p_gizmo->get_spatial_node());
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
Transform gt = notifier->get_global_transform();
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
Transform gi = gt.affine_inverse();
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
bool move = p_idx >= 3;
|
|
|
|
p_idx = p_idx % 3;
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
AABB aabb = notifier->get_aabb();
|
|
|
|
Vector3 ray_from = p_camera->project_ray_origin(p_point);
|
|
|
|
Vector3 ray_dir = p_camera->project_ray_normal(p_point);
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
Vector3 sg[2] = { gi.xform(ray_from), gi.xform(ray_from + ray_dir * 4096) };
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
Vector3 ofs = aabb.position + aabb.size * 0.5;
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
Vector3 axis;
|
|
|
|
axis[p_idx] = 1.0;
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
if (move) {
|
|
|
|
Vector3 ra, rb;
|
2020-05-25 19:20:45 +02:00
|
|
|
Geometry3D::get_closest_points_between_segments(ofs - axis * 4096, ofs + axis * 4096, sg[0], sg[1], ra, rb);
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
float d = ra[p_idx];
|
2020-03-26 22:49:16 +01:00
|
|
|
if (Node3DEditor::get_singleton()->is_snap_enabled()) {
|
|
|
|
d = Math::stepify(d, Node3DEditor::get_singleton()->get_translate_snap());
|
2019-07-03 12:11:12 +02:00
|
|
|
}
|
2018-06-13 00:53:28 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
aabb.position[p_idx] = d - 1.0 - aabb.size[p_idx] * 0.5;
|
|
|
|
notifier->set_aabb(aabb);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
Vector3 ra, rb;
|
2020-05-25 19:20:45 +02:00
|
|
|
Geometry3D::get_closest_points_between_segments(ofs, ofs + axis * 4096, sg[0], sg[1], ra, rb);
|
2018-07-25 00:08:49 +02:00
|
|
|
|
|
|
|
float d = ra[p_idx] - ofs[p_idx];
|
2020-03-26 22:49:16 +01:00
|
|
|
if (Node3DEditor::get_singleton()->is_snap_enabled()) {
|
|
|
|
d = Math::stepify(d, Node3DEditor::get_singleton()->get_translate_snap());
|
2019-07-03 12:11:12 +02:00
|
|
|
}
|
|
|
|
|
2020-05-14 16:41:43 +02:00
|
|
|
if (d < 0.001) {
|
2018-07-25 00:08:49 +02:00
|
|
|
d = 0.001;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2018-07-25 00:08:49 +02:00
|
|
|
//resize
|
|
|
|
aabb.position[p_idx] = (aabb.position[p_idx] + aabb.size[p_idx] * 0.5) - d;
|
|
|
|
aabb.size[p_idx] = d * 2;
|
|
|
|
notifier->set_aabb(aabb);
|
2018-06-13 00:53:28 +02:00
|
|
|
}
|
2018-07-25 00:08:49 +02:00
|
|
|
}
|
2018-06-13 00:53:28 +02:00
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
void VisibilityNotifier3DGizmoPlugin::commit_handle(EditorNode3DGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel) {
|
2020-03-26 22:49:16 +01:00
|
|
|
VisibilityNotifier3D *notifier = Object::cast_to<VisibilityNotifier3D>(p_gizmo->get_spatial_node());
|
2018-07-25 00:08:49 +02:00
|
|
|
|
|
|
|
if (p_cancel) {
|
|
|
|
notifier->set_aabb(p_restore);
|
|
|
|
return;
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
UndoRedo *ur = Node3DEditor::get_singleton()->get_undo_redo();
|
2018-07-25 00:08:49 +02:00
|
|
|
ur->create_action(TTR("Change Notifier AABB"));
|
|
|
|
ur->add_do_method(notifier, "set_aabb", notifier->get_aabb());
|
|
|
|
ur->add_undo_method(notifier, "set_aabb", p_restore);
|
|
|
|
ur->commit_action();
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
void VisibilityNotifier3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
|
2020-03-26 22:49:16 +01:00
|
|
|
VisibilityNotifier3D *notifier = Object::cast_to<VisibilityNotifier3D>(p_gizmo->get_spatial_node());
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
p_gizmo->clear();
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
Vector<Vector3> lines;
|
|
|
|
AABB aabb = notifier->get_aabb();
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
for (int i = 0; i < 12; i++) {
|
|
|
|
Vector3 a, b;
|
|
|
|
aabb.get_edge(i, a, b);
|
|
|
|
lines.push_back(a);
|
|
|
|
lines.push_back(b);
|
|
|
|
}
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
Vector<Vector3> handles;
|
|
|
|
|
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
Vector3 ax;
|
|
|
|
ax[i] = aabb.position[i] + aabb.size[i];
|
|
|
|
ax[(i + 1) % 3] = aabb.position[(i + 1) % 3] + aabb.size[(i + 1) % 3] * 0.5;
|
|
|
|
ax[(i + 2) % 3] = aabb.position[(i + 2) % 3] + aabb.size[(i + 2) % 3] * 0.5;
|
|
|
|
handles.push_back(ax);
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
Vector3 center = aabb.position + aabb.size * 0.5;
|
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
Vector3 ax;
|
|
|
|
ax[i] = 1.0;
|
|
|
|
handles.push_back(center + ax);
|
|
|
|
lines.push_back(center);
|
|
|
|
lines.push_back(center + ax);
|
|
|
|
}
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
Ref<Material> material = get_material("visibility_notifier_material", p_gizmo);
|
|
|
|
|
|
|
|
p_gizmo->add_lines(lines, material);
|
|
|
|
p_gizmo->add_collision_segments(lines);
|
|
|
|
|
|
|
|
if (p_gizmo->is_selected()) {
|
|
|
|
Ref<Material> solid_material = get_material("visibility_notifier_solid_material", p_gizmo);
|
|
|
|
p_gizmo->add_solid_box(solid_material, aabb.get_size(), aabb.get_position() + aabb.get_size() / 2.0);
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
p_gizmo->add_handles(handles, get_material("handles"));
|
|
|
|
}
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
////
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2020-03-30 18:22:57 +02:00
|
|
|
CPUParticles3DGizmoPlugin::CPUParticles3DGizmoPlugin() {
|
|
|
|
create_icon_material("particles_icon", Node3DEditor::get_singleton()->get_theme_icon("GizmoCPUParticles3D", "EditorIcons"));
|
2019-08-08 08:18:09 +02:00
|
|
|
}
|
|
|
|
|
2020-03-30 18:22:57 +02:00
|
|
|
bool CPUParticles3DGizmoPlugin::has_gizmo(Node3D *p_spatial) {
|
2020-04-02 01:20:12 +02:00
|
|
|
return Object::cast_to<CPUParticles3D>(p_spatial) != nullptr;
|
2019-08-08 08:18:09 +02:00
|
|
|
}
|
|
|
|
|
2020-07-23 00:39:21 +02:00
|
|
|
String CPUParticles3DGizmoPlugin::get_gizmo_name() const {
|
2020-03-30 18:22:57 +02:00
|
|
|
return "CPUParticles3D";
|
2019-08-08 08:18:09 +02:00
|
|
|
}
|
|
|
|
|
2020-03-30 18:22:57 +02:00
|
|
|
int CPUParticles3DGizmoPlugin::get_priority() const {
|
2019-08-08 08:18:09 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2020-03-30 18:22:57 +02:00
|
|
|
bool CPUParticles3DGizmoPlugin::is_selectable_when_hidden() const {
|
2019-08-08 08:18:09 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-03-30 18:22:57 +02:00
|
|
|
void CPUParticles3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
|
2019-08-08 08:18:09 +02:00
|
|
|
Ref<Material> icon = get_material("particles_icon", p_gizmo);
|
|
|
|
p_gizmo->add_unscaled_billboard(icon, 0.05);
|
|
|
|
}
|
|
|
|
|
|
|
|
////
|
|
|
|
|
2020-03-30 18:22:57 +02:00
|
|
|
GPUParticles3DGizmoPlugin::GPUParticles3DGizmoPlugin() {
|
2018-07-25 00:08:49 +02:00
|
|
|
Color gizmo_color = EDITOR_DEF("editors/3d_gizmos/gizmo_colors/particles", Color(0.8, 0.7, 0.4));
|
|
|
|
create_material("particles_material", gizmo_color);
|
|
|
|
gizmo_color.a = 0.1;
|
|
|
|
create_material("particles_solid_material", gizmo_color);
|
2020-03-30 18:22:57 +02:00
|
|
|
create_icon_material("particles_icon", Node3DEditor::get_singleton()->get_theme_icon("GizmoGPUParticles3D", "EditorIcons"));
|
2018-07-25 00:08:49 +02:00
|
|
|
create_handle_material("handles");
|
|
|
|
}
|
|
|
|
|
2020-03-30 18:22:57 +02:00
|
|
|
bool GPUParticles3DGizmoPlugin::has_gizmo(Node3D *p_spatial) {
|
2020-04-02 01:20:12 +02:00
|
|
|
return Object::cast_to<GPUParticles3D>(p_spatial) != nullptr;
|
2018-07-25 00:08:49 +02:00
|
|
|
}
|
|
|
|
|
2020-07-23 00:39:21 +02:00
|
|
|
String GPUParticles3DGizmoPlugin::get_gizmo_name() const {
|
2020-03-30 18:22:57 +02:00
|
|
|
return "GPUParticles3D";
|
2018-07-25 00:08:49 +02:00
|
|
|
}
|
|
|
|
|
2020-03-30 18:22:57 +02:00
|
|
|
int GPUParticles3DGizmoPlugin::get_priority() const {
|
2019-03-12 00:30:50 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2020-03-30 18:22:57 +02:00
|
|
|
bool GPUParticles3DGizmoPlugin::is_selectable_when_hidden() const {
|
2018-07-25 00:08:49 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-03-30 18:22:57 +02:00
|
|
|
String GPUParticles3DGizmoPlugin::get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_idx) const {
|
2018-07-25 00:08:49 +02:00
|
|
|
switch (p_idx) {
|
2020-05-10 13:00:47 +02:00
|
|
|
case 0:
|
|
|
|
return "Size X";
|
|
|
|
case 1:
|
|
|
|
return "Size Y";
|
|
|
|
case 2:
|
|
|
|
return "Size Z";
|
|
|
|
case 3:
|
|
|
|
return "Pos X";
|
|
|
|
case 4:
|
|
|
|
return "Pos Y";
|
|
|
|
case 5:
|
|
|
|
return "Pos Z";
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
return "";
|
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2020-03-30 18:22:57 +02:00
|
|
|
Variant GPUParticles3DGizmoPlugin::get_handle_value(EditorNode3DGizmo *p_gizmo, int p_idx) const {
|
2020-03-26 22:49:16 +01:00
|
|
|
GPUParticles3D *particles = Object::cast_to<GPUParticles3D>(p_gizmo->get_spatial_node());
|
2018-07-25 00:08:49 +02:00
|
|
|
return particles->get_visibility_aabb();
|
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2020-03-30 18:22:57 +02:00
|
|
|
void GPUParticles3DGizmoPlugin::set_handle(EditorNode3DGizmo *p_gizmo, int p_idx, Camera3D *p_camera, const Point2 &p_point) {
|
2020-03-26 22:49:16 +01:00
|
|
|
GPUParticles3D *particles = Object::cast_to<GPUParticles3D>(p_gizmo->get_spatial_node());
|
2018-07-25 00:08:49 +02:00
|
|
|
|
|
|
|
Transform gt = particles->get_global_transform();
|
|
|
|
Transform gi = gt.affine_inverse();
|
|
|
|
|
|
|
|
bool move = p_idx >= 3;
|
|
|
|
p_idx = p_idx % 3;
|
|
|
|
|
|
|
|
AABB aabb = particles->get_visibility_aabb();
|
|
|
|
Vector3 ray_from = p_camera->project_ray_origin(p_point);
|
|
|
|
Vector3 ray_dir = p_camera->project_ray_normal(p_point);
|
|
|
|
|
|
|
|
Vector3 sg[2] = { gi.xform(ray_from), gi.xform(ray_from + ray_dir * 4096) };
|
|
|
|
|
|
|
|
Vector3 ofs = aabb.position + aabb.size * 0.5;
|
|
|
|
|
|
|
|
Vector3 axis;
|
|
|
|
axis[p_idx] = 1.0;
|
|
|
|
|
|
|
|
if (move) {
|
2017-03-05 16:44:50 +01:00
|
|
|
Vector3 ra, rb;
|
2020-05-25 19:20:45 +02:00
|
|
|
Geometry3D::get_closest_points_between_segments(ofs - axis * 4096, ofs + axis * 4096, sg[0], sg[1], ra, rb);
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
float d = ra[p_idx];
|
2020-03-26 22:49:16 +01:00
|
|
|
if (Node3DEditor::get_singleton()->is_snap_enabled()) {
|
|
|
|
d = Math::stepify(d, Node3DEditor::get_singleton()->get_translate_snap());
|
2019-07-03 12:11:12 +02:00
|
|
|
}
|
2018-06-13 00:53:28 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
aabb.position[p_idx] = d - 1.0 - aabb.size[p_idx] * 0.5;
|
|
|
|
particles->set_visibility_aabb(aabb);
|
2018-06-13 00:53:28 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
} else {
|
2018-06-13 00:53:28 +02:00
|
|
|
Vector3 ra, rb;
|
2020-05-25 19:20:45 +02:00
|
|
|
Geometry3D::get_closest_points_between_segments(ofs, ofs + axis * 4096, sg[0], sg[1], ra, rb);
|
2018-06-13 00:53:28 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
float d = ra[p_idx] - ofs[p_idx];
|
2020-03-26 22:49:16 +01:00
|
|
|
if (Node3DEditor::get_singleton()->is_snap_enabled()) {
|
|
|
|
d = Math::stepify(d, Node3DEditor::get_singleton()->get_translate_snap());
|
2019-07-03 12:11:12 +02:00
|
|
|
}
|
|
|
|
|
2020-05-14 16:41:43 +02:00
|
|
|
if (d < 0.001) {
|
2018-06-13 00:53:28 +02:00
|
|
|
d = 0.001;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2018-07-25 00:08:49 +02:00
|
|
|
//resize
|
|
|
|
aabb.position[p_idx] = (aabb.position[p_idx] + aabb.size[p_idx] * 0.5) - d;
|
|
|
|
aabb.size[p_idx] = d * 2;
|
|
|
|
particles->set_visibility_aabb(aabb);
|
2018-06-13 00:53:28 +02:00
|
|
|
}
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
2018-07-25 00:08:49 +02:00
|
|
|
|
2020-03-30 18:22:57 +02:00
|
|
|
void GPUParticles3DGizmoPlugin::commit_handle(EditorNode3DGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel) {
|
2020-03-26 22:49:16 +01:00
|
|
|
GPUParticles3D *particles = Object::cast_to<GPUParticles3D>(p_gizmo->get_spatial_node());
|
2018-07-25 00:08:49 +02:00
|
|
|
|
|
|
|
if (p_cancel) {
|
|
|
|
particles->set_visibility_aabb(p_restore);
|
2015-10-08 20:00:40 +02:00
|
|
|
return;
|
2018-07-25 00:08:49 +02:00
|
|
|
}
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
UndoRedo *ur = Node3DEditor::get_singleton()->get_undo_redo();
|
2018-07-25 00:08:49 +02:00
|
|
|
ur->create_action(TTR("Change Particles AABB"));
|
2019-02-08 12:26:52 +01:00
|
|
|
ur->add_do_method(particles, "set_visibility_aabb", particles->get_visibility_aabb());
|
|
|
|
ur->add_undo_method(particles, "set_visibility_aabb", p_restore);
|
2018-07-25 00:08:49 +02:00
|
|
|
ur->commit_action();
|
|
|
|
}
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2020-03-30 18:22:57 +02:00
|
|
|
void GPUParticles3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
|
2020-03-26 22:49:16 +01:00
|
|
|
GPUParticles3D *particles = Object::cast_to<GPUParticles3D>(p_gizmo->get_spatial_node());
|
2018-07-25 00:08:49 +02:00
|
|
|
|
|
|
|
p_gizmo->clear();
|
|
|
|
|
|
|
|
Vector<Vector3> lines;
|
|
|
|
AABB aabb = particles->get_visibility_aabb();
|
|
|
|
|
|
|
|
for (int i = 0; i < 12; i++) {
|
|
|
|
Vector3 a, b;
|
|
|
|
aabb.get_edge(i, a, b);
|
|
|
|
lines.push_back(a);
|
|
|
|
lines.push_back(b);
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
Vector<Vector3> handles;
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
Vector3 ax;
|
|
|
|
ax[i] = aabb.position[i] + aabb.size[i];
|
|
|
|
ax[(i + 1) % 3] = aabb.position[(i + 1) % 3] + aabb.size[(i + 1) % 3] * 0.5;
|
|
|
|
ax[(i + 2) % 3] = aabb.position[(i + 2) % 3] + aabb.size[(i + 2) % 3] * 0.5;
|
|
|
|
handles.push_back(ax);
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
Vector3 center = aabb.position + aabb.size * 0.5;
|
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
Vector3 ax;
|
|
|
|
ax[i] = 1.0;
|
|
|
|
handles.push_back(center + ax);
|
|
|
|
lines.push_back(center);
|
|
|
|
lines.push_back(center + ax);
|
|
|
|
}
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
Ref<Material> material = get_material("particles_material", p_gizmo);
|
|
|
|
Ref<Material> icon = get_material("particles_icon", p_gizmo);
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
p_gizmo->add_lines(lines, material);
|
|
|
|
|
|
|
|
if (p_gizmo->is_selected()) {
|
|
|
|
Ref<Material> solid_material = get_material("particles_solid_material", p_gizmo);
|
|
|
|
p_gizmo->add_solid_box(solid_material, aabb.get_size(), aabb.get_position() + aabb.get_size() / 2.0);
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
p_gizmo->add_handles(handles, get_material("handles"));
|
|
|
|
p_gizmo->add_unscaled_billboard(icon, 0.05);
|
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
////
|
2018-06-13 00:53:28 +02:00
|
|
|
|
2020-10-08 02:29:49 +02:00
|
|
|
////
|
|
|
|
|
|
|
|
GPUParticlesCollision3DGizmoPlugin::GPUParticlesCollision3DGizmoPlugin() {
|
|
|
|
Color gizmo_color = EDITOR_DEF("editors/3d_gizmos/gizmo_colors/particle_collision", Color(0.5, 0.7, 1));
|
|
|
|
create_material("shape_material", gizmo_color);
|
|
|
|
gizmo_color.a = 0.15;
|
|
|
|
create_material("shape_material_internal", gizmo_color);
|
|
|
|
|
|
|
|
create_handle_material("handles");
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GPUParticlesCollision3DGizmoPlugin::has_gizmo(Node3D *p_spatial) {
|
|
|
|
return (Object::cast_to<GPUParticlesCollision3D>(p_spatial) != nullptr) || (Object::cast_to<GPUParticlesAttractor3D>(p_spatial) != nullptr);
|
|
|
|
}
|
|
|
|
|
2020-07-23 00:39:21 +02:00
|
|
|
String GPUParticlesCollision3DGizmoPlugin::get_gizmo_name() const {
|
2020-10-08 02:29:49 +02:00
|
|
|
return "GPUParticlesCollision3D";
|
|
|
|
}
|
|
|
|
|
|
|
|
int GPUParticlesCollision3DGizmoPlugin::get_priority() const {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
String GPUParticlesCollision3DGizmoPlugin::get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_idx) const {
|
|
|
|
const Node3D *cs = p_gizmo->get_spatial_node();
|
|
|
|
|
|
|
|
if (Object::cast_to<GPUParticlesCollisionSphere>(cs) || Object::cast_to<GPUParticlesAttractorSphere>(cs)) {
|
|
|
|
return "Radius";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Object::cast_to<GPUParticlesCollisionBox>(cs) || Object::cast_to<GPUParticlesAttractorBox>(cs) || Object::cast_to<GPUParticlesAttractorVectorField>(cs) || Object::cast_to<GPUParticlesCollisionSDF>(cs) || Object::cast_to<GPUParticlesCollisionHeightField>(cs)) {
|
|
|
|
return "Extents";
|
|
|
|
}
|
|
|
|
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
Variant GPUParticlesCollision3DGizmoPlugin::get_handle_value(EditorNode3DGizmo *p_gizmo, int p_idx) const {
|
|
|
|
const Node3D *cs = p_gizmo->get_spatial_node();
|
|
|
|
|
|
|
|
if (Object::cast_to<GPUParticlesCollisionSphere>(cs) || Object::cast_to<GPUParticlesAttractorSphere>(cs)) {
|
|
|
|
return p_gizmo->get_spatial_node()->call("get_radius");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Object::cast_to<GPUParticlesCollisionBox>(cs) || Object::cast_to<GPUParticlesAttractorBox>(cs) || Object::cast_to<GPUParticlesAttractorVectorField>(cs) || Object::cast_to<GPUParticlesCollisionSDF>(cs) || Object::cast_to<GPUParticlesCollisionHeightField>(cs)) {
|
|
|
|
return Vector3(p_gizmo->get_spatial_node()->call("get_extents"));
|
|
|
|
}
|
|
|
|
|
|
|
|
return Variant();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GPUParticlesCollision3DGizmoPlugin::set_handle(EditorNode3DGizmo *p_gizmo, int p_idx, Camera3D *p_camera, const Point2 &p_point) {
|
|
|
|
Node3D *sn = p_gizmo->get_spatial_node();
|
|
|
|
|
|
|
|
Transform gt = sn->get_global_transform();
|
|
|
|
Transform gi = gt.affine_inverse();
|
|
|
|
|
|
|
|
Vector3 ray_from = p_camera->project_ray_origin(p_point);
|
|
|
|
Vector3 ray_dir = p_camera->project_ray_normal(p_point);
|
|
|
|
|
|
|
|
Vector3 sg[2] = { gi.xform(ray_from), gi.xform(ray_from + ray_dir * 4096) };
|
|
|
|
|
|
|
|
if (Object::cast_to<GPUParticlesCollisionSphere>(sn) || Object::cast_to<GPUParticlesAttractorSphere>(sn)) {
|
|
|
|
Vector3 ra, rb;
|
|
|
|
Geometry3D::get_closest_points_between_segments(Vector3(), Vector3(4096, 0, 0), sg[0], sg[1], ra, rb);
|
|
|
|
float d = ra.x;
|
|
|
|
if (Node3DEditor::get_singleton()->is_snap_enabled()) {
|
|
|
|
d = Math::stepify(d, Node3DEditor::get_singleton()->get_translate_snap());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (d < 0.001) {
|
|
|
|
d = 0.001;
|
|
|
|
}
|
|
|
|
|
|
|
|
sn->call("set_radius", d);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Object::cast_to<GPUParticlesCollisionBox>(sn) || Object::cast_to<GPUParticlesAttractorBox>(sn) || Object::cast_to<GPUParticlesAttractorVectorField>(sn) || Object::cast_to<GPUParticlesCollisionSDF>(sn) || Object::cast_to<GPUParticlesCollisionHeightField>(sn)) {
|
|
|
|
Vector3 axis;
|
|
|
|
axis[p_idx] = 1.0;
|
|
|
|
Vector3 ra, rb;
|
|
|
|
Geometry3D::get_closest_points_between_segments(Vector3(), axis * 4096, sg[0], sg[1], ra, rb);
|
|
|
|
float d = ra[p_idx];
|
|
|
|
if (Node3DEditor::get_singleton()->is_snap_enabled()) {
|
|
|
|
d = Math::stepify(d, Node3DEditor::get_singleton()->get_translate_snap());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (d < 0.001) {
|
|
|
|
d = 0.001;
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector3 he = sn->call("get_extents");
|
|
|
|
he[p_idx] = d;
|
|
|
|
sn->call("set_extents", he);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GPUParticlesCollision3DGizmoPlugin::commit_handle(EditorNode3DGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel) {
|
|
|
|
Node3D *sn = p_gizmo->get_spatial_node();
|
|
|
|
|
|
|
|
if (Object::cast_to<GPUParticlesCollisionSphere>(sn) || Object::cast_to<GPUParticlesAttractorSphere>(sn)) {
|
|
|
|
if (p_cancel) {
|
|
|
|
sn->call("set_radius", p_restore);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
UndoRedo *ur = Node3DEditor::get_singleton()->get_undo_redo();
|
|
|
|
ur->create_action(TTR("Change Radius"));
|
|
|
|
ur->add_do_method(sn, "set_radius", sn->call("get_radius"));
|
|
|
|
ur->add_undo_method(sn, "set_radius", p_restore);
|
|
|
|
ur->commit_action();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Object::cast_to<GPUParticlesCollisionBox>(sn) || Object::cast_to<GPUParticlesAttractorBox>(sn) || Object::cast_to<GPUParticlesAttractorVectorField>(sn) || Object::cast_to<GPUParticlesCollisionSDF>(sn) || Object::cast_to<GPUParticlesCollisionHeightField>(sn)) {
|
|
|
|
if (p_cancel) {
|
|
|
|
sn->call("set_extents", p_restore);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
UndoRedo *ur = Node3DEditor::get_singleton()->get_undo_redo();
|
|
|
|
ur->create_action(TTR("Change Box Shape Extents"));
|
|
|
|
ur->add_do_method(sn, "set_extents", sn->call("get_extents"));
|
|
|
|
ur->add_undo_method(sn, "set_extents", p_restore);
|
|
|
|
ur->commit_action();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GPUParticlesCollision3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
|
|
|
|
Node3D *cs = p_gizmo->get_spatial_node();
|
|
|
|
|
|
|
|
print_line("redraw request " + itos(cs != nullptr));
|
|
|
|
p_gizmo->clear();
|
|
|
|
|
|
|
|
const Ref<Material> material =
|
|
|
|
get_material("shape_material", p_gizmo);
|
|
|
|
const Ref<Material> material_internal =
|
|
|
|
get_material("shape_material_internal", p_gizmo);
|
|
|
|
|
|
|
|
Ref<Material> handles_material = get_material("handles");
|
|
|
|
|
|
|
|
if (Object::cast_to<GPUParticlesCollisionSphere>(cs) || Object::cast_to<GPUParticlesAttractorSphere>(cs)) {
|
|
|
|
float r = cs->call("get_radius");
|
|
|
|
|
|
|
|
Vector<Vector3> points;
|
|
|
|
|
|
|
|
for (int i = 0; i <= 360; i++) {
|
|
|
|
float ra = Math::deg2rad((float)i);
|
|
|
|
float rb = Math::deg2rad((float)i + 1);
|
|
|
|
Point2 a = Vector2(Math::sin(ra), Math::cos(ra)) * r;
|
|
|
|
Point2 b = Vector2(Math::sin(rb), Math::cos(rb)) * r;
|
|
|
|
|
|
|
|
points.push_back(Vector3(a.x, 0, a.y));
|
|
|
|
points.push_back(Vector3(b.x, 0, b.y));
|
|
|
|
points.push_back(Vector3(0, a.x, a.y));
|
|
|
|
points.push_back(Vector3(0, b.x, b.y));
|
|
|
|
points.push_back(Vector3(a.x, a.y, 0));
|
|
|
|
points.push_back(Vector3(b.x, b.y, 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector<Vector3> collision_segments;
|
|
|
|
|
|
|
|
for (int i = 0; i < 64; i++) {
|
|
|
|
float ra = i * Math_PI * 2.0 / 64.0;
|
|
|
|
float rb = (i + 1) * Math_PI * 2.0 / 64.0;
|
|
|
|
Point2 a = Vector2(Math::sin(ra), Math::cos(ra)) * r;
|
|
|
|
Point2 b = Vector2(Math::sin(rb), Math::cos(rb)) * r;
|
|
|
|
|
|
|
|
collision_segments.push_back(Vector3(a.x, 0, a.y));
|
|
|
|
collision_segments.push_back(Vector3(b.x, 0, b.y));
|
|
|
|
collision_segments.push_back(Vector3(0, a.x, a.y));
|
|
|
|
collision_segments.push_back(Vector3(0, b.x, b.y));
|
|
|
|
collision_segments.push_back(Vector3(a.x, a.y, 0));
|
|
|
|
collision_segments.push_back(Vector3(b.x, b.y, 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
p_gizmo->add_lines(points, material);
|
|
|
|
p_gizmo->add_collision_segments(collision_segments);
|
|
|
|
Vector<Vector3> handles;
|
|
|
|
handles.push_back(Vector3(r, 0, 0));
|
|
|
|
p_gizmo->add_handles(handles, handles_material);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Object::cast_to<GPUParticlesCollisionBox>(cs) || Object::cast_to<GPUParticlesAttractorBox>(cs) || Object::cast_to<GPUParticlesAttractorVectorField>(cs) || Object::cast_to<GPUParticlesCollisionSDF>(cs) || Object::cast_to<GPUParticlesCollisionHeightField>(cs)) {
|
|
|
|
Vector<Vector3> lines;
|
|
|
|
AABB aabb;
|
|
|
|
aabb.position = -cs->call("get_extents").operator Vector3();
|
|
|
|
aabb.size = aabb.position * -2;
|
|
|
|
|
|
|
|
for (int i = 0; i < 12; i++) {
|
|
|
|
Vector3 a, b;
|
|
|
|
aabb.get_edge(i, a, b);
|
|
|
|
lines.push_back(a);
|
|
|
|
lines.push_back(b);
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector<Vector3> handles;
|
|
|
|
|
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
Vector3 ax;
|
|
|
|
ax[i] = cs->call("get_extents").operator Vector3()[i];
|
|
|
|
handles.push_back(ax);
|
|
|
|
}
|
|
|
|
|
|
|
|
p_gizmo->add_lines(lines, material);
|
|
|
|
p_gizmo->add_collision_segments(lines);
|
|
|
|
p_gizmo->add_handles(handles, handles_material);
|
|
|
|
|
|
|
|
GPUParticlesCollisionSDF *col_sdf = Object::cast_to<GPUParticlesCollisionSDF>(cs);
|
|
|
|
if (col_sdf) {
|
|
|
|
static const int subdivs[GPUParticlesCollisionSDF::RESOLUTION_MAX] = { 16, 32, 64, 128, 256, 512 };
|
|
|
|
int subdiv = subdivs[col_sdf->get_resolution()];
|
|
|
|
float cell_size = aabb.get_longest_axis_size() / subdiv;
|
|
|
|
|
|
|
|
lines.clear();
|
|
|
|
|
|
|
|
for (int i = 1; i < subdiv; i++) {
|
|
|
|
for (int j = 0; j < 3; j++) {
|
|
|
|
if (cell_size * i > aabb.size[j]) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector2 dir;
|
|
|
|
dir[j] = 1.0;
|
|
|
|
Vector2 ta, tb;
|
|
|
|
int j_n1 = (j + 1) % 3;
|
|
|
|
int j_n2 = (j + 2) % 3;
|
|
|
|
ta[j_n1] = 1.0;
|
|
|
|
tb[j_n2] = 1.0;
|
|
|
|
|
|
|
|
for (int k = 0; k < 4; k++) {
|
|
|
|
Vector3 from = aabb.position, to = aabb.position;
|
|
|
|
from[j] += cell_size * i;
|
|
|
|
to[j] += cell_size * i;
|
|
|
|
|
|
|
|
if (k & 1) {
|
|
|
|
to[j_n1] += aabb.size[j_n1];
|
|
|
|
} else {
|
|
|
|
to[j_n2] += aabb.size[j_n2];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (k & 2) {
|
|
|
|
from[j_n1] += aabb.size[j_n1];
|
|
|
|
from[j_n2] += aabb.size[j_n2];
|
|
|
|
}
|
|
|
|
|
|
|
|
lines.push_back(from);
|
|
|
|
lines.push_back(to);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
p_gizmo->add_lines(lines, material_internal);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/////
|
|
|
|
|
|
|
|
////
|
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
ReflectionProbeGizmoPlugin::ReflectionProbeGizmoPlugin() {
|
|
|
|
Color gizmo_color = EDITOR_DEF("editors/3d_gizmos/gizmo_colors/reflection_probe", Color(0.6, 1, 0.5));
|
2018-06-13 00:53:28 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
create_material("reflection_probe_material", gizmo_color);
|
2018-06-13 00:53:28 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
gizmo_color.a = 0.5;
|
|
|
|
create_material("reflection_internal_material", gizmo_color);
|
2018-06-13 00:53:28 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
gizmo_color.a = 0.1;
|
|
|
|
create_material("reflection_probe_solid_material", gizmo_color);
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
create_icon_material("reflection_probe_icon", Node3DEditor::get_singleton()->get_theme_icon("GizmoReflectionProbe", "EditorIcons"));
|
2018-07-25 00:08:49 +02:00
|
|
|
create_handle_material("handles");
|
|
|
|
}
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
bool ReflectionProbeGizmoPlugin::has_gizmo(Node3D *p_spatial) {
|
2020-04-02 01:20:12 +02:00
|
|
|
return Object::cast_to<ReflectionProbe>(p_spatial) != nullptr;
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
|
2020-07-23 00:39:21 +02:00
|
|
|
String ReflectionProbeGizmoPlugin::get_gizmo_name() const {
|
2018-07-25 00:08:49 +02:00
|
|
|
return "ReflectionProbe";
|
|
|
|
}
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2019-03-12 00:30:50 +01:00
|
|
|
int ReflectionProbeGizmoPlugin::get_priority() const {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
String ReflectionProbeGizmoPlugin::get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_idx) const {
|
2018-07-25 00:08:49 +02:00
|
|
|
switch (p_idx) {
|
2020-05-10 13:00:47 +02:00
|
|
|
case 0:
|
|
|
|
return "Extents X";
|
|
|
|
case 1:
|
|
|
|
return "Extents Y";
|
|
|
|
case 2:
|
|
|
|
return "Extents Z";
|
|
|
|
case 3:
|
|
|
|
return "Origin X";
|
|
|
|
case 4:
|
|
|
|
return "Origin Y";
|
|
|
|
case 5:
|
|
|
|
return "Origin Z";
|
2018-07-25 00:08:49 +02:00
|
|
|
}
|
2017-08-26 05:40:45 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
return "";
|
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
Variant ReflectionProbeGizmoPlugin::get_handle_value(EditorNode3DGizmo *p_gizmo, int p_idx) const {
|
2018-07-25 00:08:49 +02:00
|
|
|
ReflectionProbe *probe = Object::cast_to<ReflectionProbe>(p_gizmo->get_spatial_node());
|
|
|
|
return AABB(probe->get_extents(), probe->get_origin_offset());
|
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
void ReflectionProbeGizmoPlugin::set_handle(EditorNode3DGizmo *p_gizmo, int p_idx, Camera3D *p_camera, const Point2 &p_point) {
|
2018-07-25 00:08:49 +02:00
|
|
|
ReflectionProbe *probe = Object::cast_to<ReflectionProbe>(p_gizmo->get_spatial_node());
|
|
|
|
Transform gt = probe->get_global_transform();
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
Transform gi = gt.affine_inverse();
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
if (p_idx < 3) {
|
|
|
|
Vector3 extents = probe->get_extents();
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
Vector3 ray_from = p_camera->project_ray_origin(p_point);
|
|
|
|
Vector3 ray_dir = p_camera->project_ray_normal(p_point);
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
Vector3 sg[2] = { gi.xform(ray_from), gi.xform(ray_from + ray_dir * 16384) };
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
Vector3 axis;
|
|
|
|
axis[p_idx] = 1.0;
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
Vector3 ra, rb;
|
2020-05-25 19:20:45 +02:00
|
|
|
Geometry3D::get_closest_points_between_segments(Vector3(), axis * 16384, sg[0], sg[1], ra, rb);
|
2018-07-25 00:08:49 +02:00
|
|
|
float d = ra[p_idx];
|
2020-03-26 22:49:16 +01:00
|
|
|
if (Node3DEditor::get_singleton()->is_snap_enabled()) {
|
|
|
|
d = Math::stepify(d, Node3DEditor::get_singleton()->get_translate_snap());
|
2019-07-03 12:11:12 +02:00
|
|
|
}
|
|
|
|
|
2020-05-14 16:41:43 +02:00
|
|
|
if (d < 0.001) {
|
2018-07-25 00:08:49 +02:00
|
|
|
d = 0.001;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
extents[p_idx] = d;
|
|
|
|
probe->set_extents(extents);
|
|
|
|
} else {
|
|
|
|
p_idx -= 3;
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
Vector3 origin = probe->get_origin_offset();
|
|
|
|
origin[p_idx] = 0;
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
Vector3 ray_from = p_camera->project_ray_origin(p_point);
|
|
|
|
Vector3 ray_dir = p_camera->project_ray_normal(p_point);
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
Vector3 sg[2] = { gi.xform(ray_from), gi.xform(ray_from + ray_dir * 16384) };
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
Vector3 axis;
|
|
|
|
axis[p_idx] = 1.0;
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
Vector3 ra, rb;
|
2020-05-25 19:20:45 +02:00
|
|
|
Geometry3D::get_closest_points_between_segments(origin - axis * 16384, origin + axis * 16384, sg[0], sg[1], ra, rb);
|
2019-07-03 12:11:12 +02:00
|
|
|
// Adjust the actual position to account for the gizmo handle position
|
|
|
|
float d = ra[p_idx] + 0.25;
|
2020-03-26 22:49:16 +01:00
|
|
|
if (Node3DEditor::get_singleton()->is_snap_enabled()) {
|
|
|
|
d = Math::stepify(d, Node3DEditor::get_singleton()->get_translate_snap());
|
2019-07-03 12:11:12 +02:00
|
|
|
}
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
origin[p_idx] = d;
|
|
|
|
probe->set_origin_offset(origin);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
void ReflectionProbeGizmoPlugin::commit_handle(EditorNode3DGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel) {
|
2018-07-25 00:08:49 +02:00
|
|
|
ReflectionProbe *probe = Object::cast_to<ReflectionProbe>(p_gizmo->get_spatial_node());
|
|
|
|
|
|
|
|
AABB restore = p_restore;
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
if (p_cancel) {
|
|
|
|
probe->set_extents(restore.position);
|
|
|
|
probe->set_origin_offset(restore.size);
|
|
|
|
return;
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
UndoRedo *ur = Node3DEditor::get_singleton()->get_undo_redo();
|
2018-07-25 00:08:49 +02:00
|
|
|
ur->create_action(TTR("Change Probe Extents"));
|
|
|
|
ur->add_do_method(probe, "set_extents", probe->get_extents());
|
|
|
|
ur->add_do_method(probe, "set_origin_offset", probe->get_origin_offset());
|
|
|
|
ur->add_undo_method(probe, "set_extents", restore.position);
|
|
|
|
ur->add_undo_method(probe, "set_origin_offset", restore.size);
|
|
|
|
ur->commit_action();
|
|
|
|
}
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
void ReflectionProbeGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
|
2018-07-25 00:08:49 +02:00
|
|
|
ReflectionProbe *probe = Object::cast_to<ReflectionProbe>(p_gizmo->get_spatial_node());
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
p_gizmo->clear();
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
Vector<Vector3> lines;
|
|
|
|
Vector<Vector3> internal_lines;
|
|
|
|
Vector3 extents = probe->get_extents();
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
AABB aabb;
|
|
|
|
aabb.position = -extents;
|
|
|
|
aabb.size = extents * 2;
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
for (int i = 0; i < 12; i++) {
|
|
|
|
Vector3 a, b;
|
|
|
|
aabb.get_edge(i, a, b);
|
|
|
|
lines.push_back(a);
|
|
|
|
lines.push_back(b);
|
|
|
|
}
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
for (int i = 0; i < 8; i++) {
|
|
|
|
Vector3 ep = aabb.get_endpoint(i);
|
|
|
|
internal_lines.push_back(probe->get_origin_offset());
|
|
|
|
internal_lines.push_back(ep);
|
|
|
|
}
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
Vector<Vector3> handles;
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
Vector3 ax;
|
|
|
|
ax[i] = aabb.position[i] + aabb.size[i];
|
|
|
|
handles.push_back(ax);
|
|
|
|
}
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
Vector3 orig_handle = probe->get_origin_offset();
|
|
|
|
orig_handle[i] -= 0.25;
|
|
|
|
lines.push_back(orig_handle);
|
|
|
|
handles.push_back(orig_handle);
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
orig_handle[i] += 0.5;
|
|
|
|
lines.push_back(orig_handle);
|
|
|
|
}
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
Ref<Material> material = get_material("reflection_probe_material", p_gizmo);
|
|
|
|
Ref<Material> material_internal = get_material("reflection_internal_material", p_gizmo);
|
|
|
|
Ref<Material> icon = get_material("reflection_probe_icon", p_gizmo);
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
p_gizmo->add_lines(lines, material);
|
|
|
|
p_gizmo->add_lines(internal_lines, material_internal);
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
if (p_gizmo->is_selected()) {
|
|
|
|
Ref<Material> solid_material = get_material("reflection_probe_solid_material", p_gizmo);
|
|
|
|
p_gizmo->add_solid_box(solid_material, probe->get_extents() * 2.0);
|
|
|
|
}
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
p_gizmo->add_unscaled_billboard(icon, 0.05);
|
|
|
|
p_gizmo->add_handles(handles, get_material("handles"));
|
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2020-04-14 05:05:21 +02:00
|
|
|
///////////////////////////////
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2020-04-14 05:05:21 +02:00
|
|
|
////
|
|
|
|
|
|
|
|
DecalGizmoPlugin::DecalGizmoPlugin() {
|
|
|
|
Color gizmo_color = EDITOR_DEF("editors/3d_gizmos/gizmo_colors/decal", Color(0.6, 0.5, 1.0));
|
|
|
|
|
|
|
|
create_material("decal_material", gizmo_color);
|
|
|
|
|
|
|
|
create_handle_material("handles");
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DecalGizmoPlugin::has_gizmo(Node3D *p_spatial) {
|
|
|
|
return Object::cast_to<Decal>(p_spatial) != nullptr;
|
|
|
|
}
|
|
|
|
|
2020-07-23 00:39:21 +02:00
|
|
|
String DecalGizmoPlugin::get_gizmo_name() const {
|
2020-04-14 05:05:21 +02:00
|
|
|
return "Decal";
|
|
|
|
}
|
|
|
|
|
|
|
|
int DecalGizmoPlugin::get_priority() const {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
String DecalGizmoPlugin::get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_idx) const {
|
|
|
|
switch (p_idx) {
|
2020-05-10 13:00:47 +02:00
|
|
|
case 0:
|
|
|
|
return "Extents X";
|
|
|
|
case 1:
|
|
|
|
return "Extents Y";
|
|
|
|
case 2:
|
|
|
|
return "Extents Z";
|
2020-04-14 05:05:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return "";
|
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2020-04-14 05:05:21 +02:00
|
|
|
Variant DecalGizmoPlugin::get_handle_value(EditorNode3DGizmo *p_gizmo, int p_idx) const {
|
|
|
|
Decal *decal = Object::cast_to<Decal>(p_gizmo->get_spatial_node());
|
|
|
|
return decal->get_extents();
|
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2020-04-14 05:05:21 +02:00
|
|
|
void DecalGizmoPlugin::set_handle(EditorNode3DGizmo *p_gizmo, int p_idx, Camera3D *p_camera, const Point2 &p_point) {
|
|
|
|
Decal *decal = Object::cast_to<Decal>(p_gizmo->get_spatial_node());
|
|
|
|
Transform gt = decal->get_global_transform();
|
|
|
|
|
|
|
|
Transform gi = gt.affine_inverse();
|
|
|
|
|
|
|
|
Vector3 extents = decal->get_extents();
|
|
|
|
|
|
|
|
Vector3 ray_from = p_camera->project_ray_origin(p_point);
|
|
|
|
Vector3 ray_dir = p_camera->project_ray_normal(p_point);
|
|
|
|
|
|
|
|
Vector3 sg[2] = { gi.xform(ray_from), gi.xform(ray_from + ray_dir * 16384) };
|
|
|
|
|
|
|
|
Vector3 axis;
|
|
|
|
axis[p_idx] = 1.0;
|
|
|
|
|
|
|
|
Vector3 ra, rb;
|
2020-05-25 19:20:45 +02:00
|
|
|
Geometry3D::get_closest_points_between_segments(Vector3(), axis * 16384, sg[0], sg[1], ra, rb);
|
2020-04-14 05:05:21 +02:00
|
|
|
float d = ra[p_idx];
|
|
|
|
if (Node3DEditor::get_singleton()->is_snap_enabled()) {
|
|
|
|
d = Math::stepify(d, Node3DEditor::get_singleton()->get_translate_snap());
|
|
|
|
}
|
|
|
|
|
2020-05-14 16:41:43 +02:00
|
|
|
if (d < 0.001) {
|
2020-04-14 05:05:21 +02:00
|
|
|
d = 0.001;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2020-04-14 05:05:21 +02:00
|
|
|
|
|
|
|
extents[p_idx] = d;
|
|
|
|
decal->set_extents(extents);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DecalGizmoPlugin::commit_handle(EditorNode3DGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel) {
|
|
|
|
Decal *decal = Object::cast_to<Decal>(p_gizmo->get_spatial_node());
|
|
|
|
|
|
|
|
Vector3 restore = p_restore;
|
|
|
|
|
|
|
|
if (p_cancel) {
|
|
|
|
decal->set_extents(restore);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
UndoRedo *ur = Node3DEditor::get_singleton()->get_undo_redo();
|
|
|
|
ur->create_action(TTR("Change Decal Extents"));
|
|
|
|
ur->add_do_method(decal, "set_extents", decal->get_extents());
|
|
|
|
ur->add_undo_method(decal, "set_extents", restore);
|
|
|
|
ur->commit_action();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DecalGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
|
|
|
|
Decal *decal = Object::cast_to<Decal>(p_gizmo->get_spatial_node());
|
|
|
|
|
|
|
|
p_gizmo->clear();
|
|
|
|
|
|
|
|
Vector<Vector3> lines;
|
|
|
|
Vector3 extents = decal->get_extents();
|
|
|
|
|
|
|
|
AABB aabb;
|
|
|
|
aabb.position = -extents;
|
|
|
|
aabb.size = extents * 2;
|
|
|
|
|
|
|
|
for (int i = 0; i < 12; i++) {
|
|
|
|
Vector3 a, b;
|
|
|
|
aabb.get_edge(i, a, b);
|
|
|
|
if (a.y == b.y) {
|
|
|
|
lines.push_back(a);
|
|
|
|
lines.push_back(b);
|
|
|
|
} else {
|
2020-03-16 10:07:33 +01:00
|
|
|
Vector3 ah = a.lerp(b, 0.2);
|
2020-04-14 05:05:21 +02:00
|
|
|
lines.push_back(a);
|
|
|
|
lines.push_back(ah);
|
2020-03-16 10:07:33 +01:00
|
|
|
Vector3 bh = b.lerp(a, 0.2);
|
2020-04-14 05:05:21 +02:00
|
|
|
lines.push_back(b);
|
|
|
|
lines.push_back(bh);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
lines.push_back(Vector3(0, extents.y, 0));
|
|
|
|
lines.push_back(Vector3(0, extents.y * 1.2, 0));
|
|
|
|
|
|
|
|
Vector<Vector3> handles;
|
|
|
|
|
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
Vector3 ax;
|
|
|
|
ax[i] = aabb.position[i] + aabb.size[i];
|
|
|
|
handles.push_back(ax);
|
|
|
|
}
|
|
|
|
|
|
|
|
Ref<Material> material = get_material("decal_material", p_gizmo);
|
|
|
|
|
|
|
|
p_gizmo->add_lines(lines, material);
|
|
|
|
|
|
|
|
p_gizmo->add_handles(handles, get_material("handles"));
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////
|
2018-07-25 00:08:49 +02:00
|
|
|
GIProbeGizmoPlugin::GIProbeGizmoPlugin() {
|
|
|
|
Color gizmo_color = EDITOR_DEF("editors/3d_gizmos/gizmo_colors/gi_probe", Color(0.5, 1, 0.6));
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
create_material("gi_probe_material", gizmo_color);
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2020-03-02 23:00:53 +01:00
|
|
|
// This gizmo draws a lot of lines. Use a low opacity to make it not too intrusive.
|
|
|
|
gizmo_color.a = 0.1;
|
2018-07-25 00:08:49 +02:00
|
|
|
create_material("gi_probe_internal_material", gizmo_color);
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2020-03-02 23:00:53 +01:00
|
|
|
gizmo_color.a = 0.05;
|
2018-07-25 00:08:49 +02:00
|
|
|
create_material("gi_probe_solid_material", gizmo_color);
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
create_icon_material("gi_probe_icon", Node3DEditor::get_singleton()->get_theme_icon("GizmoGIProbe", "EditorIcons"));
|
2018-07-25 00:08:49 +02:00
|
|
|
create_handle_material("handles");
|
|
|
|
}
|
2018-06-13 00:53:28 +02:00
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
bool GIProbeGizmoPlugin::has_gizmo(Node3D *p_spatial) {
|
2020-04-02 01:20:12 +02:00
|
|
|
return Object::cast_to<GIProbe>(p_spatial) != nullptr;
|
2018-07-25 00:08:49 +02:00
|
|
|
}
|
2018-06-13 00:53:28 +02:00
|
|
|
|
2020-07-23 00:39:21 +02:00
|
|
|
String GIProbeGizmoPlugin::get_gizmo_name() const {
|
2018-07-25 00:08:49 +02:00
|
|
|
return "GIProbe";
|
|
|
|
}
|
2018-06-13 00:53:28 +02:00
|
|
|
|
2019-03-12 00:30:50 +01:00
|
|
|
int GIProbeGizmoPlugin::get_priority() const {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
String GIProbeGizmoPlugin::get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_idx) const {
|
2018-07-25 00:08:49 +02:00
|
|
|
switch (p_idx) {
|
2020-05-10 13:00:47 +02:00
|
|
|
case 0:
|
|
|
|
return "Extents X";
|
|
|
|
case 1:
|
|
|
|
return "Extents Y";
|
|
|
|
case 2:
|
|
|
|
return "Extents Z";
|
2018-07-25 00:08:49 +02:00
|
|
|
}
|
2018-06-13 00:53:28 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
return "";
|
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
Variant GIProbeGizmoPlugin::get_handle_value(EditorNode3DGizmo *p_gizmo, int p_idx) const {
|
2018-07-25 00:08:49 +02:00
|
|
|
GIProbe *probe = Object::cast_to<GIProbe>(p_gizmo->get_spatial_node());
|
|
|
|
return probe->get_extents();
|
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
void GIProbeGizmoPlugin::set_handle(EditorNode3DGizmo *p_gizmo, int p_idx, Camera3D *p_camera, const Point2 &p_point) {
|
2018-07-25 00:08:49 +02:00
|
|
|
GIProbe *probe = Object::cast_to<GIProbe>(p_gizmo->get_spatial_node());
|
2018-06-13 00:53:28 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
Transform gt = probe->get_global_transform();
|
|
|
|
Transform gi = gt.affine_inverse();
|
2018-06-13 00:53:28 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
Vector3 extents = probe->get_extents();
|
2018-06-13 00:53:28 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
Vector3 ray_from = p_camera->project_ray_origin(p_point);
|
|
|
|
Vector3 ray_dir = p_camera->project_ray_normal(p_point);
|
2018-06-13 00:53:28 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
Vector3 sg[2] = { gi.xform(ray_from), gi.xform(ray_from + ray_dir * 16384) };
|
2018-06-13 00:53:28 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
Vector3 axis;
|
|
|
|
axis[p_idx] = 1.0;
|
2018-06-13 00:53:28 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
Vector3 ra, rb;
|
2020-05-25 19:20:45 +02:00
|
|
|
Geometry3D::get_closest_points_between_segments(Vector3(), axis * 16384, sg[0], sg[1], ra, rb);
|
2018-07-25 00:08:49 +02:00
|
|
|
float d = ra[p_idx];
|
2020-03-26 22:49:16 +01:00
|
|
|
if (Node3DEditor::get_singleton()->is_snap_enabled()) {
|
|
|
|
d = Math::stepify(d, Node3DEditor::get_singleton()->get_translate_snap());
|
2019-07-03 12:11:12 +02:00
|
|
|
}
|
|
|
|
|
2020-05-14 16:41:43 +02:00
|
|
|
if (d < 0.001) {
|
2018-07-25 00:08:49 +02:00
|
|
|
d = 0.001;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2018-06-13 00:53:28 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
extents[p_idx] = d;
|
|
|
|
probe->set_extents(extents);
|
|
|
|
}
|
2018-06-13 00:53:28 +02:00
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
void GIProbeGizmoPlugin::commit_handle(EditorNode3DGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel) {
|
2018-07-25 00:08:49 +02:00
|
|
|
GIProbe *probe = Object::cast_to<GIProbe>(p_gizmo->get_spatial_node());
|
2018-06-13 00:53:28 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
Vector3 restore = p_restore;
|
2018-06-13 00:53:28 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
if (p_cancel) {
|
|
|
|
probe->set_extents(restore);
|
|
|
|
return;
|
2018-06-13 00:53:28 +02:00
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
UndoRedo *ur = Node3DEditor::get_singleton()->get_undo_redo();
|
2018-07-25 00:08:49 +02:00
|
|
|
ur->create_action(TTR("Change Probe Extents"));
|
|
|
|
ur->add_do_method(probe, "set_extents", probe->get_extents());
|
|
|
|
ur->add_undo_method(probe, "set_extents", restore);
|
|
|
|
ur->commit_action();
|
|
|
|
}
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
void GIProbeGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
|
2018-07-25 00:08:49 +02:00
|
|
|
GIProbe *probe = Object::cast_to<GIProbe>(p_gizmo->get_spatial_node());
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
Ref<Material> material = get_material("gi_probe_material", p_gizmo);
|
|
|
|
Ref<Material> icon = get_material("gi_probe_icon", p_gizmo);
|
|
|
|
Ref<Material> material_internal = get_material("gi_probe_internal_material", p_gizmo);
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
p_gizmo->clear();
|
|
|
|
|
|
|
|
Vector<Vector3> lines;
|
|
|
|
Vector3 extents = probe->get_extents();
|
|
|
|
|
|
|
|
static const int subdivs[GIProbe::SUBDIV_MAX] = { 64, 128, 256, 512 };
|
|
|
|
|
|
|
|
AABB aabb = AABB(-extents, extents * 2);
|
|
|
|
int subdiv = subdivs[probe->get_subdiv()];
|
|
|
|
float cell_size = aabb.get_longest_axis_size() / subdiv;
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
for (int i = 0; i < 12; i++) {
|
|
|
|
Vector3 a, b;
|
|
|
|
aabb.get_edge(i, a, b);
|
|
|
|
lines.push_back(a);
|
|
|
|
lines.push_back(b);
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
p_gizmo->add_lines(lines, material);
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
lines.clear();
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
for (int i = 1; i < subdiv; i++) {
|
|
|
|
for (int j = 0; j < 3; j++) {
|
|
|
|
if (cell_size * i > aabb.size[j]) {
|
|
|
|
continue;
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
Vector2 dir;
|
|
|
|
dir[j] = 1.0;
|
|
|
|
Vector2 ta, tb;
|
|
|
|
int j_n1 = (j + 1) % 3;
|
|
|
|
int j_n2 = (j + 2) % 3;
|
|
|
|
ta[j_n1] = 1.0;
|
|
|
|
tb[j_n2] = 1.0;
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
for (int k = 0; k < 4; k++) {
|
|
|
|
Vector3 from = aabb.position, to = aabb.position;
|
|
|
|
from[j] += cell_size * i;
|
|
|
|
to[j] += cell_size * i;
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
if (k & 1) {
|
|
|
|
to[j_n1] += aabb.size[j_n1];
|
|
|
|
} else {
|
|
|
|
to[j_n2] += aabb.size[j_n2];
|
|
|
|
}
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
if (k & 2) {
|
|
|
|
from[j_n1] += aabb.size[j_n1];
|
|
|
|
from[j_n2] += aabb.size[j_n2];
|
|
|
|
}
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
lines.push_back(from);
|
|
|
|
lines.push_back(to);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
p_gizmo->add_lines(lines, material_internal);
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
Vector<Vector3> handles;
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
Vector3 ax;
|
|
|
|
ax[i] = aabb.position[i] + aabb.size[i];
|
|
|
|
handles.push_back(ax);
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
if (p_gizmo->is_selected()) {
|
|
|
|
Ref<Material> solid_material = get_material("gi_probe_solid_material", p_gizmo);
|
|
|
|
p_gizmo->add_solid_box(solid_material, aabb.get_size());
|
|
|
|
}
|
2017-08-26 05:40:45 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
p_gizmo->add_unscaled_billboard(icon, 0.05);
|
|
|
|
p_gizmo->add_handles(handles, get_material("handles"));
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
////
|
|
|
|
|
2020-05-01 14:34:23 +02:00
|
|
|
BakedLightmapGizmoPlugin::BakedLightmapGizmoPlugin() {
|
|
|
|
Color gizmo_color = EDITOR_DEF("editors/3d_gizmos/gizmo_colors/lightmap_lines", Color(0.5, 0.6, 1));
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
gizmo_color.a = 0.1;
|
2020-05-01 14:34:23 +02:00
|
|
|
create_material("lightmap_lines", gizmo_color);
|
2018-07-25 00:08:49 +02:00
|
|
|
|
2020-05-01 14:34:23 +02:00
|
|
|
Ref<StandardMaterial3D> mat = memnew(StandardMaterial3D);
|
|
|
|
mat->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);
|
|
|
|
mat->set_cull_mode(StandardMaterial3D::CULL_DISABLED);
|
|
|
|
mat->set_flag(StandardMaterial3D::FLAG_ALBEDO_FROM_VERTEX_COLOR, true);
|
|
|
|
mat->set_flag(StandardMaterial3D::FLAG_SRGB_VERTEX_COLOR, false);
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2020-05-01 14:34:23 +02:00
|
|
|
add_material("lightmap_probe_material", mat);
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2020-05-01 14:34:23 +02:00
|
|
|
create_icon_material("baked_indirect_light_icon", Node3DEditor::get_singleton()->get_theme_icon("GizmoBakedLightmap", "EditorIcons"));
|
|
|
|
}
|
|
|
|
|
|
|
|
String BakedLightmapGizmoPlugin::get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_idx) const {
|
2015-10-08 20:00:40 +02:00
|
|
|
return "";
|
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2020-05-01 14:34:23 +02:00
|
|
|
Variant BakedLightmapGizmoPlugin::get_handle_value(EditorNode3DGizmo *p_gizmo, int p_idx) const {
|
|
|
|
return Variant();
|
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2020-05-01 14:34:23 +02:00
|
|
|
void BakedLightmapGizmoPlugin::set_handle(EditorNode3DGizmo *p_gizmo, int p_idx, Camera3D *p_camera, const Point2 &p_point) {
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
|
2020-05-01 14:34:23 +02:00
|
|
|
void BakedLightmapGizmoPlugin::commit_handle(EditorNode3DGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel) {
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BakedLightmapGizmoPlugin::has_gizmo(Node3D *p_spatial) {
|
|
|
|
return Object::cast_to<BakedLightmap>(p_spatial) != nullptr;
|
|
|
|
}
|
|
|
|
|
2020-07-23 00:39:21 +02:00
|
|
|
String BakedLightmapGizmoPlugin::get_gizmo_name() const {
|
2020-05-01 14:34:23 +02:00
|
|
|
return "BakedLightmap";
|
|
|
|
}
|
|
|
|
|
|
|
|
int BakedLightmapGizmoPlugin::get_priority() const {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BakedLightmapGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
|
|
|
|
Ref<Material> icon = get_material("baked_indirect_light_icon", p_gizmo);
|
2018-07-25 00:08:49 +02:00
|
|
|
BakedLightmap *baker = Object::cast_to<BakedLightmap>(p_gizmo->get_spatial_node());
|
2020-05-01 14:34:23 +02:00
|
|
|
Ref<BakedLightmapData> data = baker->get_light_data();
|
2018-07-25 00:08:49 +02:00
|
|
|
|
2020-05-01 14:34:23 +02:00
|
|
|
p_gizmo->add_unscaled_billboard(icon, 0.05);
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2020-05-01 14:34:23 +02:00
|
|
|
if (data.is_null()) {
|
|
|
|
return;
|
|
|
|
}
|
2018-07-25 00:08:49 +02:00
|
|
|
|
2020-05-01 14:34:23 +02:00
|
|
|
Ref<Material> material_lines = get_material("lightmap_lines", p_gizmo);
|
|
|
|
Ref<Material> material_probes = get_material("lightmap_probe_material", p_gizmo);
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2020-05-01 14:34:23 +02:00
|
|
|
p_gizmo->clear();
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2020-05-01 14:34:23 +02:00
|
|
|
Vector<Vector3> lines;
|
|
|
|
Set<Vector2i> lines_found;
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2020-05-01 14:34:23 +02:00
|
|
|
Vector<Vector3> points = data->get_capture_points();
|
|
|
|
if (points.size() == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Vector<Color> sh = data->get_capture_sh();
|
|
|
|
if (sh.size() != points.size() * 9) {
|
|
|
|
return;
|
2019-07-03 12:11:12 +02:00
|
|
|
}
|
|
|
|
|
2020-05-01 14:34:23 +02:00
|
|
|
Vector<int> tetrahedrons = data->get_capture_tetrahedra();
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2020-05-01 14:34:23 +02:00
|
|
|
for (int i = 0; i < tetrahedrons.size(); i += 4) {
|
|
|
|
for (int j = 0; j < 4; j++) {
|
|
|
|
for (int k = j + 1; k < 4; k++) {
|
|
|
|
Vector2i pair;
|
|
|
|
pair.x = tetrahedrons[i + j];
|
|
|
|
pair.y = tetrahedrons[i + k];
|
2018-07-25 00:08:49 +02:00
|
|
|
|
2020-05-01 14:34:23 +02:00
|
|
|
if (pair.y < pair.x) {
|
|
|
|
SWAP(pair.x, pair.y);
|
|
|
|
}
|
|
|
|
if (lines_found.has(pair)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
lines_found.insert(pair);
|
|
|
|
lines.push_back(points[pair.x]);
|
|
|
|
lines.push_back(points[pair.y]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2020-05-01 14:34:23 +02:00
|
|
|
p_gizmo->add_lines(lines, material_lines);
|
|
|
|
|
|
|
|
int stack_count = 8;
|
|
|
|
int sector_count = 16;
|
|
|
|
|
|
|
|
float sector_step = 2 * Math_PI / sector_count;
|
|
|
|
float stack_step = Math_PI / stack_count;
|
|
|
|
|
|
|
|
Vector<Vector3> vertices;
|
|
|
|
Vector<Color> colors;
|
|
|
|
Vector<int> indices;
|
|
|
|
float radius = 0.3;
|
|
|
|
|
|
|
|
for (int p = 0; p < points.size(); p++) {
|
|
|
|
int vertex_base = vertices.size();
|
|
|
|
Vector3 sh_col[9];
|
|
|
|
for (int i = 0; i < 9; i++) {
|
|
|
|
sh_col[i].x = sh[p * 9 + i].r;
|
|
|
|
sh_col[i].y = sh[p * 9 + i].g;
|
|
|
|
sh_col[i].z = sh[p * 9 + i].b;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i <= stack_count; ++i) {
|
|
|
|
float stack_angle = Math_PI / 2 - i * stack_step; // starting from pi/2 to -pi/2
|
|
|
|
float xy = radius * Math::cos(stack_angle); // r * cos(u)
|
|
|
|
float z = radius * Math::sin(stack_angle); // r * sin(u)
|
|
|
|
|
|
|
|
// add (sector_count+1) vertices per stack
|
|
|
|
// the first and last vertices have same position and normal, but different tex coords
|
|
|
|
for (int j = 0; j <= sector_count; ++j) {
|
|
|
|
float sector_angle = j * sector_step; // starting from 0 to 2pi
|
|
|
|
|
|
|
|
// vertex position (x, y, z)
|
|
|
|
float x = xy * Math::cos(sector_angle); // r * cos(u) * cos(v)
|
|
|
|
float y = xy * Math::sin(sector_angle); // r * cos(u) * sin(v)
|
|
|
|
|
|
|
|
Vector3 n = Vector3(x, z, y);
|
|
|
|
vertices.push_back(points[p] + n);
|
|
|
|
n.normalize();
|
|
|
|
|
|
|
|
const float c1 = 0.429043;
|
|
|
|
const float c2 = 0.511664;
|
|
|
|
const float c3 = 0.743125;
|
|
|
|
const float c4 = 0.886227;
|
|
|
|
const float c5 = 0.247708;
|
|
|
|
Vector3 light = (c1 * sh_col[8] * (n.x * n.x - n.y * n.y) +
|
|
|
|
c3 * sh_col[6] * n.z * n.z +
|
|
|
|
c4 * sh_col[0] -
|
|
|
|
c5 * sh_col[6] +
|
|
|
|
2.0 * c1 * sh_col[4] * n.x * n.y +
|
|
|
|
2.0 * c1 * sh_col[7] * n.x * n.z +
|
|
|
|
2.0 * c1 * sh_col[5] * n.y * n.z +
|
|
|
|
2.0 * c2 * sh_col[3] * n.x +
|
|
|
|
2.0 * c2 * sh_col[1] * n.y +
|
|
|
|
2.0 * c2 * sh_col[2] * n.z);
|
|
|
|
|
|
|
|
colors.push_back(Color(light.x, light.y, light.z, 1));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < stack_count; ++i) {
|
|
|
|
int k1 = i * (sector_count + 1); // beginning of current stack
|
|
|
|
int k2 = k1 + sector_count + 1; // beginning of next stack
|
|
|
|
|
|
|
|
for (int j = 0; j < sector_count; ++j, ++k1, ++k2) {
|
|
|
|
// 2 triangles per sector excluding first and last stacks
|
|
|
|
// k1 => k2 => k1+1
|
|
|
|
if (i != 0) {
|
|
|
|
indices.push_back(vertex_base + k1);
|
|
|
|
indices.push_back(vertex_base + k2);
|
|
|
|
indices.push_back(vertex_base + k1 + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// k1+1 => k2 => k2+1
|
|
|
|
if (i != (stack_count - 1)) {
|
|
|
|
indices.push_back(vertex_base + k1 + 1);
|
|
|
|
indices.push_back(vertex_base + k2);
|
|
|
|
indices.push_back(vertex_base + k2 + 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
|
2020-05-01 14:34:23 +02:00
|
|
|
Array array;
|
|
|
|
array.resize(RS::ARRAY_MAX);
|
|
|
|
array[RS::ARRAY_VERTEX] = vertices;
|
|
|
|
array[RS::ARRAY_INDEX] = indices;
|
|
|
|
array[RS::ARRAY_COLOR] = colors;
|
|
|
|
|
|
|
|
Ref<ArrayMesh> mesh;
|
|
|
|
mesh.instance();
|
|
|
|
mesh->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, array, Array(), Dictionary(), 0); //no compression
|
|
|
|
mesh->surface_set_material(0, material_probes);
|
|
|
|
|
|
|
|
p_gizmo->add_mesh(mesh);
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2020-05-01 14:34:23 +02:00
|
|
|
/////////
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2020-05-01 14:34:23 +02:00
|
|
|
LightmapProbeGizmoPlugin::LightmapProbeGizmoPlugin() {
|
|
|
|
Color gizmo_color = EDITOR_DEF("editors/3d_gizmos/gizmo_colors/lightprobe_lines", Color(0.5, 0.6, 1));
|
|
|
|
|
|
|
|
gizmo_color.a = 0.3;
|
|
|
|
create_material("lightprobe_lines", gizmo_color);
|
2018-07-25 00:08:49 +02:00
|
|
|
}
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2020-05-01 14:34:23 +02:00
|
|
|
String LightmapProbeGizmoPlugin::get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_idx) const {
|
|
|
|
return "";
|
2018-07-25 00:08:49 +02:00
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2020-05-01 14:34:23 +02:00
|
|
|
Variant LightmapProbeGizmoPlugin::get_handle_value(EditorNode3DGizmo *p_gizmo, int p_idx) const {
|
|
|
|
return Variant();
|
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2020-05-01 14:34:23 +02:00
|
|
|
void LightmapProbeGizmoPlugin::set_handle(EditorNode3DGizmo *p_gizmo, int p_idx, Camera3D *p_camera, const Point2 &p_point) {
|
2019-03-12 00:30:50 +01:00
|
|
|
}
|
|
|
|
|
2020-05-01 14:34:23 +02:00
|
|
|
void LightmapProbeGizmoPlugin::commit_handle(EditorNode3DGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel) {
|
|
|
|
}
|
2018-07-25 00:08:49 +02:00
|
|
|
|
2020-05-01 14:34:23 +02:00
|
|
|
bool LightmapProbeGizmoPlugin::has_gizmo(Node3D *p_spatial) {
|
|
|
|
return Object::cast_to<LightmapProbe>(p_spatial) != nullptr;
|
|
|
|
}
|
2018-07-25 00:08:49 +02:00
|
|
|
|
2020-07-23 00:39:21 +02:00
|
|
|
String LightmapProbeGizmoPlugin::get_gizmo_name() const {
|
2020-05-01 14:34:23 +02:00
|
|
|
return "LightmapProbe";
|
|
|
|
}
|
|
|
|
|
|
|
|
int LightmapProbeGizmoPlugin::get_priority() const {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void LightmapProbeGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
|
|
|
|
Ref<Material> material_lines = get_material("lightprobe_lines", p_gizmo);
|
2018-07-25 00:08:49 +02:00
|
|
|
|
|
|
|
p_gizmo->clear();
|
2015-10-08 20:00:40 +02:00
|
|
|
|
|
|
|
Vector<Vector3> lines;
|
2018-07-25 00:08:49 +02:00
|
|
|
|
2020-05-01 14:34:23 +02:00
|
|
|
int stack_count = 8;
|
|
|
|
int sector_count = 16;
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2020-05-01 14:34:23 +02:00
|
|
|
float sector_step = 2 * Math_PI / sector_count;
|
|
|
|
float stack_step = Math_PI / stack_count;
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2020-05-01 14:34:23 +02:00
|
|
|
Vector<Vector3> vertices;
|
|
|
|
float radius = 0.2;
|
2018-07-25 00:08:49 +02:00
|
|
|
|
2020-05-01 14:34:23 +02:00
|
|
|
for (int i = 0; i <= stack_count; ++i) {
|
|
|
|
float stack_angle = Math_PI / 2 - i * stack_step; // starting from pi/2 to -pi/2
|
|
|
|
float xy = radius * Math::cos(stack_angle); // r * cos(u)
|
|
|
|
float z = radius * Math::sin(stack_angle); // r * sin(u)
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2020-05-01 14:34:23 +02:00
|
|
|
// add (sector_count+1) vertices per stack
|
|
|
|
// the first and last vertices have same position and normal, but different tex coords
|
|
|
|
for (int j = 0; j <= sector_count; ++j) {
|
|
|
|
float sector_angle = j * sector_step; // starting from 0 to 2pi
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2020-05-01 14:34:23 +02:00
|
|
|
// vertex position (x, y, z)
|
|
|
|
float x = xy * Math::cos(sector_angle); // r * cos(u) * cos(v)
|
|
|
|
float y = xy * Math::sin(sector_angle); // r * cos(u) * sin(v)
|
|
|
|
|
|
|
|
Vector3 n = Vector3(x, z, y);
|
|
|
|
vertices.push_back(n);
|
|
|
|
}
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
|
2020-05-01 14:34:23 +02:00
|
|
|
for (int i = 0; i < stack_count; ++i) {
|
|
|
|
int k1 = i * (sector_count + 1); // beginning of current stack
|
|
|
|
int k2 = k1 + sector_count + 1; // beginning of next stack
|
|
|
|
|
|
|
|
for (int j = 0; j < sector_count; ++j, ++k1, ++k2) {
|
|
|
|
// 2 triangles per sector excluding first and last stacks
|
|
|
|
// k1 => k2 => k1+1
|
|
|
|
if (i != 0) {
|
|
|
|
lines.push_back(vertices[k1]);
|
|
|
|
lines.push_back(vertices[k2]);
|
|
|
|
lines.push_back(vertices[k1]);
|
|
|
|
lines.push_back(vertices[k1 + 1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i != (stack_count - 1)) {
|
|
|
|
lines.push_back(vertices[k1 + 1]);
|
|
|
|
lines.push_back(vertices[k2]);
|
|
|
|
lines.push_back(vertices[k2]);
|
|
|
|
lines.push_back(vertices[k2 + 1]);
|
|
|
|
}
|
|
|
|
}
|
2018-07-25 00:08:49 +02:00
|
|
|
}
|
|
|
|
|
2020-05-01 14:34:23 +02:00
|
|
|
p_gizmo->add_lines(lines, material_lines);
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
////
|
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
CollisionShape3DGizmoPlugin::CollisionShape3DGizmoPlugin() {
|
2019-08-21 15:27:02 +02:00
|
|
|
const Color gizmo_color = EDITOR_DEF("editors/3d_gizmos/gizmo_colors/shape", Color(0.5, 0.7, 1));
|
2018-07-25 00:08:49 +02:00
|
|
|
create_material("shape_material", gizmo_color);
|
2019-08-21 15:27:02 +02:00
|
|
|
const float gizmo_value = gizmo_color.get_v();
|
|
|
|
const Color gizmo_color_disabled = Color(gizmo_value, gizmo_value, gizmo_value, 0.65);
|
|
|
|
create_material("shape_material_disabled", gizmo_color_disabled);
|
2018-07-25 00:08:49 +02:00
|
|
|
create_handle_material("handles");
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
bool CollisionShape3DGizmoPlugin::has_gizmo(Node3D *p_spatial) {
|
2020-04-02 01:20:12 +02:00
|
|
|
return Object::cast_to<CollisionShape3D>(p_spatial) != nullptr;
|
2018-07-25 00:08:49 +02:00
|
|
|
}
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2020-07-23 00:39:21 +02:00
|
|
|
String CollisionShape3DGizmoPlugin::get_gizmo_name() const {
|
2020-03-26 22:49:16 +01:00
|
|
|
return "CollisionShape3D";
|
2018-07-25 00:08:49 +02:00
|
|
|
}
|
2016-11-19 17:23:37 +01:00
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
int CollisionShape3DGizmoPlugin::get_priority() const {
|
2019-03-12 00:30:50 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
String CollisionShape3DGizmoPlugin::get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_idx) const {
|
2020-03-26 22:49:16 +01:00
|
|
|
const CollisionShape3D *cs = Object::cast_to<CollisionShape3D>(p_gizmo->get_spatial_node());
|
2018-07-25 00:08:49 +02:00
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
Ref<Shape3D> s = cs->get_shape();
|
2020-05-14 16:41:43 +02:00
|
|
|
if (s.is_null()) {
|
2018-07-25 00:08:49 +02:00
|
|
|
return "";
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2018-07-25 00:08:49 +02:00
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
if (Object::cast_to<SphereShape3D>(*s)) {
|
2018-07-25 00:08:49 +02:00
|
|
|
return "Radius";
|
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
if (Object::cast_to<BoxShape3D>(*s)) {
|
2018-07-25 00:08:49 +02:00
|
|
|
return "Extents";
|
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
if (Object::cast_to<CapsuleShape3D>(*s)) {
|
2018-07-25 00:08:49 +02:00
|
|
|
return p_idx == 0 ? "Radius" : "Height";
|
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
if (Object::cast_to<CylinderShape3D>(*s)) {
|
2018-07-25 00:08:49 +02:00
|
|
|
return p_idx == 0 ? "Radius" : "Height";
|
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
if (Object::cast_to<RayShape3D>(*s)) {
|
2018-07-25 00:08:49 +02:00
|
|
|
return "Length";
|
2017-04-09 03:38:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
Variant CollisionShape3DGizmoPlugin::get_handle_value(EditorNode3DGizmo *p_gizmo, int p_idx) const {
|
2020-03-26 22:49:16 +01:00
|
|
|
CollisionShape3D *cs = Object::cast_to<CollisionShape3D>(p_gizmo->get_spatial_node());
|
2017-04-09 03:38:11 +02:00
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
Ref<Shape3D> s = cs->get_shape();
|
2020-05-14 16:41:43 +02:00
|
|
|
if (s.is_null()) {
|
2018-07-25 00:08:49 +02:00
|
|
|
return Variant();
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2017-04-09 03:38:11 +02:00
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
if (Object::cast_to<SphereShape3D>(*s)) {
|
|
|
|
Ref<SphereShape3D> ss = s;
|
2018-07-25 00:08:49 +02:00
|
|
|
return ss->get_radius();
|
|
|
|
}
|
2017-04-09 03:38:11 +02:00
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
if (Object::cast_to<BoxShape3D>(*s)) {
|
|
|
|
Ref<BoxShape3D> bs = s;
|
2018-07-25 00:08:49 +02:00
|
|
|
return bs->get_extents();
|
|
|
|
}
|
2017-04-09 03:38:11 +02:00
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
if (Object::cast_to<CapsuleShape3D>(*s)) {
|
|
|
|
Ref<CapsuleShape3D> cs2 = s;
|
2019-02-12 21:10:08 +01:00
|
|
|
return p_idx == 0 ? cs2->get_radius() : cs2->get_height();
|
2018-07-25 00:08:49 +02:00
|
|
|
}
|
2017-04-09 03:38:11 +02:00
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
if (Object::cast_to<CylinderShape3D>(*s)) {
|
|
|
|
Ref<CylinderShape3D> cs2 = s;
|
2019-02-12 21:10:08 +01:00
|
|
|
return p_idx == 0 ? cs2->get_radius() : cs2->get_height();
|
2018-07-25 00:08:49 +02:00
|
|
|
}
|
2017-04-09 03:38:11 +02:00
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
if (Object::cast_to<RayShape3D>(*s)) {
|
|
|
|
Ref<RayShape3D> cs2 = s;
|
2019-02-12 21:10:08 +01:00
|
|
|
return cs2->get_length();
|
2017-04-09 03:38:11 +02:00
|
|
|
}
|
2018-07-25 00:08:49 +02:00
|
|
|
|
|
|
|
return Variant();
|
2017-04-09 03:38:11 +02:00
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
void CollisionShape3DGizmoPlugin::set_handle(EditorNode3DGizmo *p_gizmo, int p_idx, Camera3D *p_camera, const Point2 &p_point) {
|
2020-03-26 22:49:16 +01:00
|
|
|
CollisionShape3D *cs = Object::cast_to<CollisionShape3D>(p_gizmo->get_spatial_node());
|
2017-04-09 03:38:11 +02:00
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
Ref<Shape3D> s = cs->get_shape();
|
2020-05-14 16:41:43 +02:00
|
|
|
if (s.is_null()) {
|
2017-04-09 03:38:11 +02:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2017-04-09 03:38:11 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
Transform gt = cs->get_global_transform();
|
|
|
|
Transform gi = gt.affine_inverse();
|
2017-04-09 03:38:11 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
Vector3 ray_from = p_camera->project_ray_origin(p_point);
|
|
|
|
Vector3 ray_dir = p_camera->project_ray_normal(p_point);
|
2017-04-09 03:38:11 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
Vector3 sg[2] = { gi.xform(ray_from), gi.xform(ray_from + ray_dir * 4096) };
|
2017-04-09 03:38:11 +02:00
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
if (Object::cast_to<SphereShape3D>(*s)) {
|
|
|
|
Ref<SphereShape3D> ss = s;
|
2018-07-25 00:08:49 +02:00
|
|
|
Vector3 ra, rb;
|
2020-05-25 19:20:45 +02:00
|
|
|
Geometry3D::get_closest_points_between_segments(Vector3(), Vector3(4096, 0, 0), sg[0], sg[1], ra, rb);
|
2018-07-25 00:08:49 +02:00
|
|
|
float d = ra.x;
|
2020-03-26 22:49:16 +01:00
|
|
|
if (Node3DEditor::get_singleton()->is_snap_enabled()) {
|
|
|
|
d = Math::stepify(d, Node3DEditor::get_singleton()->get_translate_snap());
|
2019-07-03 12:11:12 +02:00
|
|
|
}
|
|
|
|
|
2020-05-14 16:41:43 +02:00
|
|
|
if (d < 0.001) {
|
2018-07-25 00:08:49 +02:00
|
|
|
d = 0.001;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2018-07-25 00:08:49 +02:00
|
|
|
|
|
|
|
ss->set_radius(d);
|
2017-04-09 03:38:11 +02:00
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
if (Object::cast_to<RayShape3D>(*s)) {
|
|
|
|
Ref<RayShape3D> rs = s;
|
2018-07-25 00:08:49 +02:00
|
|
|
Vector3 ra, rb;
|
2020-05-25 19:20:45 +02:00
|
|
|
Geometry3D::get_closest_points_between_segments(Vector3(), Vector3(0, 0, 4096), sg[0], sg[1], ra, rb);
|
2018-07-25 00:08:49 +02:00
|
|
|
float d = ra.z;
|
2020-03-26 22:49:16 +01:00
|
|
|
if (Node3DEditor::get_singleton()->is_snap_enabled()) {
|
|
|
|
d = Math::stepify(d, Node3DEditor::get_singleton()->get_translate_snap());
|
2019-07-03 12:11:12 +02:00
|
|
|
}
|
|
|
|
|
2020-05-14 16:41:43 +02:00
|
|
|
if (d < 0.001) {
|
2018-07-25 00:08:49 +02:00
|
|
|
d = 0.001;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2017-04-09 03:38:11 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
rs->set_length(d);
|
2017-04-09 03:38:11 +02:00
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
if (Object::cast_to<BoxShape3D>(*s)) {
|
2018-07-25 00:08:49 +02:00
|
|
|
Vector3 axis;
|
|
|
|
axis[p_idx] = 1.0;
|
2020-03-26 22:49:16 +01:00
|
|
|
Ref<BoxShape3D> bs = s;
|
2018-07-25 00:08:49 +02:00
|
|
|
Vector3 ra, rb;
|
2020-05-25 19:20:45 +02:00
|
|
|
Geometry3D::get_closest_points_between_segments(Vector3(), axis * 4096, sg[0], sg[1], ra, rb);
|
2018-07-25 00:08:49 +02:00
|
|
|
float d = ra[p_idx];
|
2020-03-26 22:49:16 +01:00
|
|
|
if (Node3DEditor::get_singleton()->is_snap_enabled()) {
|
|
|
|
d = Math::stepify(d, Node3DEditor::get_singleton()->get_translate_snap());
|
2019-07-03 12:11:12 +02:00
|
|
|
}
|
|
|
|
|
2020-05-14 16:41:43 +02:00
|
|
|
if (d < 0.001) {
|
2018-07-25 00:08:49 +02:00
|
|
|
d = 0.001;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2018-07-25 00:08:49 +02:00
|
|
|
|
|
|
|
Vector3 he = bs->get_extents();
|
|
|
|
he[p_idx] = d;
|
|
|
|
bs->set_extents(he);
|
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
if (Object::cast_to<CapsuleShape3D>(*s)) {
|
2018-07-25 00:08:49 +02:00
|
|
|
Vector3 axis;
|
|
|
|
axis[p_idx == 0 ? 0 : 2] = 1.0;
|
2020-03-26 22:49:16 +01:00
|
|
|
Ref<CapsuleShape3D> cs2 = s;
|
2018-07-25 00:08:49 +02:00
|
|
|
Vector3 ra, rb;
|
2020-05-25 19:20:45 +02:00
|
|
|
Geometry3D::get_closest_points_between_segments(Vector3(), axis * 4096, sg[0], sg[1], ra, rb);
|
2018-07-25 00:08:49 +02:00
|
|
|
float d = axis.dot(ra);
|
2020-05-14 16:41:43 +02:00
|
|
|
if (p_idx == 1) {
|
2019-02-12 21:10:08 +01:00
|
|
|
d -= cs2->get_radius();
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2019-07-03 12:11:12 +02:00
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
if (Node3DEditor::get_singleton()->is_snap_enabled()) {
|
|
|
|
d = Math::stepify(d, Node3DEditor::get_singleton()->get_translate_snap());
|
2019-07-03 12:11:12 +02:00
|
|
|
}
|
|
|
|
|
2020-05-14 16:41:43 +02:00
|
|
|
if (d < 0.001) {
|
2018-07-25 00:08:49 +02:00
|
|
|
d = 0.001;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2018-07-25 00:08:49 +02:00
|
|
|
|
2020-05-14 16:41:43 +02:00
|
|
|
if (p_idx == 0) {
|
2019-02-12 21:10:08 +01:00
|
|
|
cs2->set_radius(d);
|
2020-05-14 16:41:43 +02:00
|
|
|
} else if (p_idx == 1) {
|
2019-02-12 21:10:08 +01:00
|
|
|
cs2->set_height(d * 2.0);
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2017-04-09 03:38:11 +02:00
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
if (Object::cast_to<CylinderShape3D>(*s)) {
|
2018-07-25 00:08:49 +02:00
|
|
|
Vector3 axis;
|
|
|
|
axis[p_idx == 0 ? 0 : 1] = 1.0;
|
2020-03-26 22:49:16 +01:00
|
|
|
Ref<CylinderShape3D> cs2 = s;
|
2018-07-25 00:08:49 +02:00
|
|
|
Vector3 ra, rb;
|
2020-05-25 19:20:45 +02:00
|
|
|
Geometry3D::get_closest_points_between_segments(Vector3(), axis * 4096, sg[0], sg[1], ra, rb);
|
2018-07-25 00:08:49 +02:00
|
|
|
float d = axis.dot(ra);
|
2020-03-26 22:49:16 +01:00
|
|
|
if (Node3DEditor::get_singleton()->is_snap_enabled()) {
|
|
|
|
d = Math::stepify(d, Node3DEditor::get_singleton()->get_translate_snap());
|
2019-07-03 12:11:12 +02:00
|
|
|
}
|
2017-08-28 08:21:54 +02:00
|
|
|
|
2020-05-14 16:41:43 +02:00
|
|
|
if (d < 0.001) {
|
2018-07-25 00:08:49 +02:00
|
|
|
d = 0.001;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2017-08-28 08:21:54 +02:00
|
|
|
|
2020-05-14 16:41:43 +02:00
|
|
|
if (p_idx == 0) {
|
2019-02-12 21:10:08 +01:00
|
|
|
cs2->set_radius(d);
|
2020-05-14 16:41:43 +02:00
|
|
|
} else if (p_idx == 1) {
|
2019-02-12 21:10:08 +01:00
|
|
|
cs2->set_height(d * 2.0);
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2017-08-28 08:21:54 +02:00
|
|
|
}
|
2017-04-09 03:38:11 +02:00
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
void CollisionShape3DGizmoPlugin::commit_handle(EditorNode3DGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel) {
|
2020-03-26 22:49:16 +01:00
|
|
|
CollisionShape3D *cs = Object::cast_to<CollisionShape3D>(p_gizmo->get_spatial_node());
|
2017-04-09 03:38:11 +02:00
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
Ref<Shape3D> s = cs->get_shape();
|
2020-05-14 16:41:43 +02:00
|
|
|
if (s.is_null()) {
|
2018-07-25 00:08:49 +02:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2017-04-09 03:38:11 +02:00
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
if (Object::cast_to<SphereShape3D>(*s)) {
|
|
|
|
Ref<SphereShape3D> ss = s;
|
2018-07-25 00:08:49 +02:00
|
|
|
if (p_cancel) {
|
|
|
|
ss->set_radius(p_restore);
|
|
|
|
return;
|
|
|
|
}
|
2016-11-19 17:23:37 +01:00
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
UndoRedo *ur = Node3DEditor::get_singleton()->get_undo_redo();
|
2018-07-25 00:08:49 +02:00
|
|
|
ur->create_action(TTR("Change Sphere Shape Radius"));
|
|
|
|
ur->add_do_method(ss.ptr(), "set_radius", ss->get_radius());
|
|
|
|
ur->add_undo_method(ss.ptr(), "set_radius", p_restore);
|
|
|
|
ur->commit_action();
|
2016-11-19 17:23:37 +01:00
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
if (Object::cast_to<BoxShape3D>(*s)) {
|
|
|
|
Ref<BoxShape3D> ss = s;
|
2018-07-25 00:08:49 +02:00
|
|
|
if (p_cancel) {
|
|
|
|
ss->set_extents(p_restore);
|
|
|
|
return;
|
|
|
|
}
|
2016-11-19 17:23:37 +01:00
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
UndoRedo *ur = Node3DEditor::get_singleton()->get_undo_redo();
|
2018-07-25 00:08:49 +02:00
|
|
|
ur->create_action(TTR("Change Box Shape Extents"));
|
|
|
|
ur->add_do_method(ss.ptr(), "set_extents", ss->get_extents());
|
|
|
|
ur->add_undo_method(ss.ptr(), "set_extents", p_restore);
|
|
|
|
ur->commit_action();
|
|
|
|
}
|
2016-11-19 17:23:37 +01:00
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
if (Object::cast_to<CapsuleShape3D>(*s)) {
|
|
|
|
Ref<CapsuleShape3D> ss = s;
|
2018-07-25 00:08:49 +02:00
|
|
|
if (p_cancel) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (p_idx == 0) {
|
2018-07-25 00:08:49 +02:00
|
|
|
ss->set_radius(p_restore);
|
2020-05-14 16:41:43 +02:00
|
|
|
} else {
|
2018-07-25 00:08:49 +02:00
|
|
|
ss->set_height(p_restore);
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2018-07-25 00:08:49 +02:00
|
|
|
return;
|
|
|
|
}
|
2016-11-19 17:23:37 +01:00
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
UndoRedo *ur = Node3DEditor::get_singleton()->get_undo_redo();
|
2018-07-25 00:08:49 +02:00
|
|
|
if (p_idx == 0) {
|
|
|
|
ur->create_action(TTR("Change Capsule Shape Radius"));
|
|
|
|
ur->add_do_method(ss.ptr(), "set_radius", ss->get_radius());
|
|
|
|
ur->add_undo_method(ss.ptr(), "set_radius", p_restore);
|
|
|
|
} else {
|
|
|
|
ur->create_action(TTR("Change Capsule Shape Height"));
|
|
|
|
ur->add_do_method(ss.ptr(), "set_height", ss->get_height());
|
|
|
|
ur->add_undo_method(ss.ptr(), "set_height", p_restore);
|
|
|
|
}
|
2016-11-19 17:23:37 +01:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
ur->commit_action();
|
|
|
|
}
|
2016-11-19 17:23:37 +01:00
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
if (Object::cast_to<CylinderShape3D>(*s)) {
|
|
|
|
Ref<CylinderShape3D> ss = s;
|
2018-07-25 00:08:49 +02:00
|
|
|
if (p_cancel) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (p_idx == 0) {
|
2018-07-25 00:08:49 +02:00
|
|
|
ss->set_radius(p_restore);
|
2020-05-14 16:41:43 +02:00
|
|
|
} else {
|
2018-07-25 00:08:49 +02:00
|
|
|
ss->set_height(p_restore);
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2018-07-25 00:08:49 +02:00
|
|
|
return;
|
|
|
|
}
|
2016-11-19 17:23:37 +01:00
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
UndoRedo *ur = Node3DEditor::get_singleton()->get_undo_redo();
|
2018-07-25 00:08:49 +02:00
|
|
|
if (p_idx == 0) {
|
|
|
|
ur->create_action(TTR("Change Cylinder Shape Radius"));
|
|
|
|
ur->add_do_method(ss.ptr(), "set_radius", ss->get_radius());
|
|
|
|
ur->add_undo_method(ss.ptr(), "set_radius", p_restore);
|
|
|
|
} else {
|
|
|
|
ur->create_action(
|
|
|
|
///
|
2016-11-19 17:23:37 +01:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
////////
|
|
|
|
TTR("Change Cylinder Shape Height"));
|
|
|
|
ur->add_do_method(ss.ptr(), "set_height", ss->get_height());
|
|
|
|
ur->add_undo_method(ss.ptr(), "set_height", p_restore);
|
|
|
|
}
|
2016-11-19 17:23:37 +01:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
ur->commit_action();
|
|
|
|
}
|
2016-11-19 17:23:37 +01:00
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
if (Object::cast_to<RayShape3D>(*s)) {
|
|
|
|
Ref<RayShape3D> ss = s;
|
2018-07-25 00:08:49 +02:00
|
|
|
if (p_cancel) {
|
|
|
|
ss->set_length(p_restore);
|
|
|
|
return;
|
|
|
|
}
|
2016-11-19 17:23:37 +01:00
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
UndoRedo *ur = Node3DEditor::get_singleton()->get_undo_redo();
|
2018-07-25 00:08:49 +02:00
|
|
|
ur->create_action(TTR("Change Ray Shape Length"));
|
|
|
|
ur->add_do_method(ss.ptr(), "set_length", ss->get_length());
|
|
|
|
ur->add_undo_method(ss.ptr(), "set_length", p_restore);
|
|
|
|
ur->commit_action();
|
2016-11-19 17:23:37 +01:00
|
|
|
}
|
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
void CollisionShape3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
|
2020-03-26 22:49:16 +01:00
|
|
|
CollisionShape3D *cs = Object::cast_to<CollisionShape3D>(p_gizmo->get_spatial_node());
|
2016-11-19 17:23:37 +01:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
p_gizmo->clear();
|
2016-11-19 17:23:37 +01:00
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
Ref<Shape3D> s = cs->get_shape();
|
2020-05-14 16:41:43 +02:00
|
|
|
if (s.is_null()) {
|
2016-11-19 17:23:37 +01:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2016-11-19 17:23:37 +01:00
|
|
|
|
2019-08-21 15:27:02 +02:00
|
|
|
const Ref<Material> material =
|
|
|
|
get_material(!cs->is_disabled() ? "shape_material" : "shape_material_disabled", p_gizmo);
|
2018-07-25 00:08:49 +02:00
|
|
|
Ref<Material> handles_material = get_material("handles");
|
2016-11-19 17:23:37 +01:00
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
if (Object::cast_to<SphereShape3D>(*s)) {
|
|
|
|
Ref<SphereShape3D> sp = s;
|
2018-07-25 00:08:49 +02:00
|
|
|
float r = sp->get_radius();
|
2016-11-19 17:23:37 +01:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
Vector<Vector3> points;
|
2016-11-19 17:23:37 +01:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
for (int i = 0; i <= 360; i++) {
|
|
|
|
float ra = Math::deg2rad((float)i);
|
|
|
|
float rb = Math::deg2rad((float)i + 1);
|
|
|
|
Point2 a = Vector2(Math::sin(ra), Math::cos(ra)) * r;
|
|
|
|
Point2 b = Vector2(Math::sin(rb), Math::cos(rb)) * r;
|
2016-11-19 17:23:37 +01:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
points.push_back(Vector3(a.x, 0, a.y));
|
|
|
|
points.push_back(Vector3(b.x, 0, b.y));
|
|
|
|
points.push_back(Vector3(0, a.x, a.y));
|
|
|
|
points.push_back(Vector3(0, b.x, b.y));
|
|
|
|
points.push_back(Vector3(a.x, a.y, 0));
|
|
|
|
points.push_back(Vector3(b.x, b.y, 0));
|
|
|
|
}
|
2016-11-19 17:23:37 +01:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
Vector<Vector3> collision_segments;
|
2016-11-19 17:23:37 +01:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
for (int i = 0; i < 64; i++) {
|
|
|
|
float ra = i * Math_PI * 2.0 / 64.0;
|
|
|
|
float rb = (i + 1) * Math_PI * 2.0 / 64.0;
|
|
|
|
Point2 a = Vector2(Math::sin(ra), Math::cos(ra)) * r;
|
|
|
|
Point2 b = Vector2(Math::sin(rb), Math::cos(rb)) * r;
|
2016-11-19 17:23:37 +01:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
collision_segments.push_back(Vector3(a.x, 0, a.y));
|
|
|
|
collision_segments.push_back(Vector3(b.x, 0, b.y));
|
|
|
|
collision_segments.push_back(Vector3(0, a.x, a.y));
|
|
|
|
collision_segments.push_back(Vector3(0, b.x, b.y));
|
|
|
|
collision_segments.push_back(Vector3(a.x, a.y, 0));
|
|
|
|
collision_segments.push_back(Vector3(b.x, b.y, 0));
|
|
|
|
}
|
2016-11-19 17:23:37 +01:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
p_gizmo->add_lines(points, material);
|
|
|
|
p_gizmo->add_collision_segments(collision_segments);
|
|
|
|
Vector<Vector3> handles;
|
|
|
|
handles.push_back(Vector3(r, 0, 0));
|
|
|
|
p_gizmo->add_handles(handles, handles_material);
|
2016-11-19 17:23:37 +01:00
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
if (Object::cast_to<BoxShape3D>(*s)) {
|
|
|
|
Ref<BoxShape3D> bs = s;
|
2018-07-25 00:08:49 +02:00
|
|
|
Vector<Vector3> lines;
|
|
|
|
AABB aabb;
|
|
|
|
aabb.position = -bs->get_extents();
|
|
|
|
aabb.size = aabb.position * -2;
|
2016-11-19 17:23:37 +01:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
for (int i = 0; i < 12; i++) {
|
|
|
|
Vector3 a, b;
|
|
|
|
aabb.get_edge(i, a, b);
|
|
|
|
lines.push_back(a);
|
|
|
|
lines.push_back(b);
|
|
|
|
}
|
2016-11-19 17:23:37 +01:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
Vector<Vector3> handles;
|
2016-11-19 17:23:37 +01:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
Vector3 ax;
|
|
|
|
ax[i] = bs->get_extents()[i];
|
|
|
|
handles.push_back(ax);
|
|
|
|
}
|
2016-12-20 04:21:07 +01:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
p_gizmo->add_lines(lines, material);
|
|
|
|
p_gizmo->add_collision_segments(lines);
|
|
|
|
p_gizmo->add_handles(handles, handles_material);
|
2016-12-20 04:21:07 +01:00
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
if (Object::cast_to<CapsuleShape3D>(*s)) {
|
|
|
|
Ref<CapsuleShape3D> cs2 = s;
|
2019-02-12 21:10:08 +01:00
|
|
|
float radius = cs2->get_radius();
|
|
|
|
float height = cs2->get_height();
|
2016-12-20 04:21:07 +01:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
Vector<Vector3> points;
|
2016-12-20 04:21:07 +01:00
|
|
|
|
2020-02-23 19:41:31 +01:00
|
|
|
Vector3 d(0, height * 0.5, 0);
|
2018-07-25 00:08:49 +02:00
|
|
|
for (int i = 0; i < 360; i++) {
|
|
|
|
float ra = Math::deg2rad((float)i);
|
|
|
|
float rb = Math::deg2rad((float)i + 1);
|
|
|
|
Point2 a = Vector2(Math::sin(ra), Math::cos(ra)) * radius;
|
|
|
|
Point2 b = Vector2(Math::sin(rb), Math::cos(rb)) * radius;
|
2016-12-20 04:21:07 +01:00
|
|
|
|
2020-02-23 19:41:31 +01:00
|
|
|
points.push_back(Vector3(a.x, 0, a.y) + d);
|
|
|
|
points.push_back(Vector3(b.x, 0, b.y) + d);
|
2016-12-20 04:21:07 +01:00
|
|
|
|
2020-02-23 19:41:31 +01:00
|
|
|
points.push_back(Vector3(a.x, 0, a.y) - d);
|
|
|
|
points.push_back(Vector3(b.x, 0, b.y) - d);
|
2016-12-20 04:21:07 +01:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
if (i % 90 == 0) {
|
2020-02-23 19:41:31 +01:00
|
|
|
points.push_back(Vector3(a.x, 0, a.y) + d);
|
|
|
|
points.push_back(Vector3(a.x, 0, a.y) - d);
|
2018-07-25 00:08:49 +02:00
|
|
|
}
|
2016-12-20 04:21:07 +01:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
Vector3 dud = i < 180 ? d : -d;
|
2016-12-20 04:21:07 +01:00
|
|
|
|
2020-02-23 19:41:31 +01:00
|
|
|
points.push_back(Vector3(0, a.x, a.y) + dud);
|
|
|
|
points.push_back(Vector3(0, b.x, b.y) + dud);
|
|
|
|
points.push_back(Vector3(a.y, a.x, 0) + dud);
|
|
|
|
points.push_back(Vector3(b.y, b.x, 0) + dud);
|
2018-07-25 00:08:49 +02:00
|
|
|
}
|
2016-12-20 04:21:07 +01:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
p_gizmo->add_lines(points, material);
|
2016-12-20 04:21:07 +01:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
Vector<Vector3> collision_segments;
|
2016-12-20 04:21:07 +01:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
for (int i = 0; i < 64; i++) {
|
|
|
|
float ra = i * Math_PI * 2.0 / 64.0;
|
|
|
|
float rb = (i + 1) * Math_PI * 2.0 / 64.0;
|
|
|
|
Point2 a = Vector2(Math::sin(ra), Math::cos(ra)) * radius;
|
|
|
|
Point2 b = Vector2(Math::sin(rb), Math::cos(rb)) * radius;
|
2017-08-26 05:40:45 +02:00
|
|
|
|
2020-02-23 19:41:31 +01:00
|
|
|
collision_segments.push_back(Vector3(a.x, 0, a.y) + d);
|
|
|
|
collision_segments.push_back(Vector3(b.x, 0, b.y) + d);
|
2016-12-20 04:21:07 +01:00
|
|
|
|
2020-02-23 19:41:31 +01:00
|
|
|
collision_segments.push_back(Vector3(a.x, 0, a.y) - d);
|
|
|
|
collision_segments.push_back(Vector3(b.x, 0, b.y) - d);
|
2016-12-20 04:21:07 +01:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
if (i % 16 == 0) {
|
2020-02-23 19:41:31 +01:00
|
|
|
collision_segments.push_back(Vector3(a.x, 0, a.y) + d);
|
|
|
|
collision_segments.push_back(Vector3(a.x, 0, a.y) - d);
|
2018-07-25 00:08:49 +02:00
|
|
|
}
|
2016-12-20 04:21:07 +01:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
Vector3 dud = i < 32 ? d : -d;
|
2016-12-20 04:21:07 +01:00
|
|
|
|
2020-02-23 19:41:31 +01:00
|
|
|
collision_segments.push_back(Vector3(0, a.x, a.y) + dud);
|
|
|
|
collision_segments.push_back(Vector3(0, b.x, b.y) + dud);
|
|
|
|
collision_segments.push_back(Vector3(a.y, a.x, 0) + dud);
|
|
|
|
collision_segments.push_back(Vector3(b.y, b.x, 0) + dud);
|
2018-07-25 00:08:49 +02:00
|
|
|
}
|
2016-12-20 04:21:07 +01:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
p_gizmo->add_collision_segments(collision_segments);
|
2016-12-20 04:21:07 +01:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
Vector<Vector3> handles;
|
2019-02-12 21:10:08 +01:00
|
|
|
handles.push_back(Vector3(cs2->get_radius(), 0, 0));
|
2020-02-23 19:41:31 +01:00
|
|
|
handles.push_back(Vector3(0, cs2->get_height() * 0.5 + cs2->get_radius(), 0));
|
2018-07-25 00:08:49 +02:00
|
|
|
p_gizmo->add_handles(handles, handles_material);
|
|
|
|
}
|
2016-12-20 04:21:07 +01:00
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
if (Object::cast_to<CylinderShape3D>(*s)) {
|
|
|
|
Ref<CylinderShape3D> cs2 = s;
|
2019-02-12 21:10:08 +01:00
|
|
|
float radius = cs2->get_radius();
|
|
|
|
float height = cs2->get_height();
|
2016-12-20 04:21:07 +01:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
Vector<Vector3> points;
|
2016-12-20 04:21:07 +01:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
Vector3 d(0, height * 0.5, 0);
|
|
|
|
for (int i = 0; i < 360; i++) {
|
|
|
|
float ra = Math::deg2rad((float)i);
|
|
|
|
float rb = Math::deg2rad((float)i + 1);
|
|
|
|
Point2 a = Vector2(Math::sin(ra), Math::cos(ra)) * radius;
|
|
|
|
Point2 b = Vector2(Math::sin(rb), Math::cos(rb)) * radius;
|
2016-12-20 04:21:07 +01:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
points.push_back(Vector3(a.x, 0, a.y) + d);
|
|
|
|
points.push_back(Vector3(b.x, 0, b.y) + d);
|
2016-12-20 04:21:07 +01:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
points.push_back(Vector3(a.x, 0, a.y) - d);
|
|
|
|
points.push_back(Vector3(b.x, 0, b.y) - d);
|
2016-12-20 04:21:07 +01:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
if (i % 90 == 0) {
|
|
|
|
points.push_back(Vector3(a.x, 0, a.y) + d);
|
|
|
|
points.push_back(Vector3(a.x, 0, a.y) - d);
|
2016-12-20 04:21:07 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
p_gizmo->add_lines(points, material);
|
2016-12-20 04:21:07 +01:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
Vector<Vector3> collision_segments;
|
2016-12-20 04:21:07 +01:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
for (int i = 0; i < 64; i++) {
|
|
|
|
float ra = i * Math_PI * 2.0 / 64.0;
|
|
|
|
float rb = (i + 1) * Math_PI * 2.0 / 64.0;
|
|
|
|
Point2 a = Vector2(Math::sin(ra), Math::cos(ra)) * radius;
|
|
|
|
Point2 b = Vector2(Math::sin(rb), Math::cos(rb)) * radius;
|
2016-12-20 04:21:07 +01:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
collision_segments.push_back(Vector3(a.x, 0, a.y) + d);
|
|
|
|
collision_segments.push_back(Vector3(b.x, 0, b.y) + d);
|
2017-08-28 08:21:54 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
collision_segments.push_back(Vector3(a.x, 0, a.y) - d);
|
|
|
|
collision_segments.push_back(Vector3(b.x, 0, b.y) - d);
|
2017-08-28 08:21:54 +02:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
if (i % 16 == 0) {
|
|
|
|
collision_segments.push_back(Vector3(a.x, 0, a.y) + d);
|
|
|
|
collision_segments.push_back(Vector3(a.x, 0, a.y) - d);
|
|
|
|
}
|
|
|
|
}
|
2016-12-20 04:21:07 +01:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
p_gizmo->add_collision_segments(collision_segments);
|
2017-12-14 12:59:46 +01:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
Vector<Vector3> handles;
|
2019-02-12 21:10:08 +01:00
|
|
|
handles.push_back(Vector3(cs2->get_radius(), 0, 0));
|
|
|
|
handles.push_back(Vector3(0, cs2->get_height() * 0.5, 0));
|
2018-07-25 00:08:49 +02:00
|
|
|
p_gizmo->add_handles(handles, handles_material);
|
|
|
|
}
|
2017-12-14 12:59:46 +01:00
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
if (Object::cast_to<WorldMarginShape3D>(*s)) {
|
|
|
|
Ref<WorldMarginShape3D> ps = s;
|
2018-07-25 00:08:49 +02:00
|
|
|
Plane p = ps->get_plane();
|
|
|
|
Vector<Vector3> points;
|
2017-12-14 12:59:46 +01:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
Vector3 n1 = p.get_any_perpendicular_normal();
|
|
|
|
Vector3 n2 = p.normal.cross(n1).normalized();
|
2017-12-14 12:59:46 +01:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
Vector3 pface[4] = {
|
2020-05-10 16:47:11 +02:00
|
|
|
p.normal * p.d + n1 * 10.0 + n2 * 10.0,
|
|
|
|
p.normal * p.d + n1 * 10.0 + n2 * -10.0,
|
|
|
|
p.normal * p.d + n1 * -10.0 + n2 * -10.0,
|
|
|
|
p.normal * p.d + n1 * -10.0 + n2 * 10.0,
|
2018-07-25 00:08:49 +02:00
|
|
|
};
|
2017-12-14 12:59:46 +01:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
points.push_back(pface[0]);
|
|
|
|
points.push_back(pface[1]);
|
|
|
|
points.push_back(pface[1]);
|
|
|
|
points.push_back(pface[2]);
|
|
|
|
points.push_back(pface[2]);
|
|
|
|
points.push_back(pface[3]);
|
|
|
|
points.push_back(pface[3]);
|
|
|
|
points.push_back(pface[0]);
|
2020-05-10 16:47:11 +02:00
|
|
|
points.push_back(p.normal * p.d);
|
|
|
|
points.push_back(p.normal * p.d + p.normal * 3);
|
2017-12-14 12:59:46 +01:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
p_gizmo->add_lines(points, material);
|
|
|
|
p_gizmo->add_collision_segments(points);
|
|
|
|
}
|
2017-12-14 12:59:46 +01:00
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
if (Object::cast_to<ConvexPolygonShape3D>(*s)) {
|
|
|
|
Vector<Vector3> points = Object::cast_to<ConvexPolygonShape3D>(*s)->get_points();
|
2017-12-14 12:59:46 +01:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
if (points.size() > 3) {
|
|
|
|
Vector<Vector3> varr = Variant(points);
|
2020-05-25 19:20:45 +02:00
|
|
|
Geometry3D::MeshData md;
|
2018-10-04 15:38:52 +02:00
|
|
|
Error err = QuickHull::build(varr, md);
|
2018-07-25 00:08:49 +02:00
|
|
|
if (err == OK) {
|
2019-02-12 21:10:08 +01:00
|
|
|
Vector<Vector3> points2;
|
|
|
|
points2.resize(md.edges.size() * 2);
|
2018-07-25 00:08:49 +02:00
|
|
|
for (int i = 0; i < md.edges.size(); i++) {
|
2019-02-12 21:10:08 +01:00
|
|
|
points2.write[i * 2 + 0] = md.vertices[md.edges[i].a];
|
|
|
|
points2.write[i * 2 + 1] = md.vertices[md.edges[i].b];
|
2018-07-25 00:08:49 +02:00
|
|
|
}
|
2017-12-14 12:59:46 +01:00
|
|
|
|
2019-02-12 21:10:08 +01:00
|
|
|
p_gizmo->add_lines(points2, material);
|
|
|
|
p_gizmo->add_collision_segments(points2);
|
2018-07-25 00:08:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-12-14 12:59:46 +01:00
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
if (Object::cast_to<ConcavePolygonShape3D>(*s)) {
|
|
|
|
Ref<ConcavePolygonShape3D> cs2 = s;
|
2019-02-24 00:20:54 +01:00
|
|
|
Ref<ArrayMesh> mesh = cs2->get_debug_mesh();
|
2019-09-19 00:46:32 +02:00
|
|
|
p_gizmo->add_mesh(mesh, false, Ref<SkinReference>(), material);
|
2019-10-10 22:35:00 +02:00
|
|
|
p_gizmo->add_collision_segments(cs2->get_debug_mesh_lines());
|
2018-09-09 19:39:34 +02:00
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
if (Object::cast_to<RayShape3D>(*s)) {
|
|
|
|
Ref<RayShape3D> rs = s;
|
2017-12-14 12:59:46 +01:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
Vector<Vector3> points;
|
|
|
|
points.push_back(Vector3());
|
|
|
|
points.push_back(Vector3(0, 0, rs->get_length()));
|
|
|
|
p_gizmo->add_lines(points, material);
|
|
|
|
p_gizmo->add_collision_segments(points);
|
|
|
|
Vector<Vector3> handles;
|
|
|
|
handles.push_back(Vector3(0, 0, rs->get_length()));
|
|
|
|
p_gizmo->add_handles(handles, handles_material);
|
2017-12-14 12:59:46 +01:00
|
|
|
}
|
2019-06-03 11:59:55 +02:00
|
|
|
|
2020-03-27 08:44:44 +01:00
|
|
|
if (Object::cast_to<HeightMapShape3D>(*s)) {
|
|
|
|
Ref<HeightMapShape3D> hms = s;
|
2019-06-03 11:59:55 +02:00
|
|
|
|
|
|
|
Ref<ArrayMesh> mesh = hms->get_debug_mesh();
|
2019-09-19 00:46:32 +02:00
|
|
|
p_gizmo->add_mesh(mesh, false, Ref<SkinReference>(), material);
|
2019-06-03 11:59:55 +02:00
|
|
|
}
|
2017-12-14 12:59:46 +01:00
|
|
|
}
|
2016-12-20 04:21:07 +01:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
/////
|
2017-12-14 12:59:46 +01:00
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
CollisionPolygon3DGizmoPlugin::CollisionPolygon3DGizmoPlugin() {
|
2019-08-21 15:27:02 +02:00
|
|
|
const Color gizmo_color = EDITOR_DEF("editors/3d_gizmos/gizmo_colors/shape", Color(0.5, 0.7, 1));
|
2018-07-25 00:08:49 +02:00
|
|
|
create_material("shape_material", gizmo_color);
|
2019-08-21 15:27:02 +02:00
|
|
|
const float gizmo_value = gizmo_color.get_v();
|
|
|
|
const Color gizmo_color_disabled = Color(gizmo_value, gizmo_value, gizmo_value, 0.65);
|
|
|
|
create_material("shape_material_disabled", gizmo_color_disabled);
|
2018-07-25 00:08:49 +02:00
|
|
|
}
|
2017-12-14 12:59:46 +01:00
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
bool CollisionPolygon3DGizmoPlugin::has_gizmo(Node3D *p_spatial) {
|
2020-04-02 01:20:12 +02:00
|
|
|
return Object::cast_to<CollisionPolygon3D>(p_spatial) != nullptr;
|
2018-07-25 00:08:49 +02:00
|
|
|
}
|
2017-12-14 12:59:46 +01:00
|
|
|
|
2020-07-23 00:39:21 +02:00
|
|
|
String CollisionPolygon3DGizmoPlugin::get_gizmo_name() const {
|
2020-03-26 22:49:16 +01:00
|
|
|
return "CollisionPolygon3D";
|
2018-07-25 00:08:49 +02:00
|
|
|
}
|
2017-12-14 12:59:46 +01:00
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
int CollisionPolygon3DGizmoPlugin::get_priority() const {
|
2019-03-12 00:30:50 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
void CollisionPolygon3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
|
2020-03-26 22:49:16 +01:00
|
|
|
CollisionPolygon3D *polygon = Object::cast_to<CollisionPolygon3D>(p_gizmo->get_spatial_node());
|
2017-12-14 12:59:46 +01:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
p_gizmo->clear();
|
2017-12-14 12:59:46 +01:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
Vector<Vector2> points = polygon->get_polygon();
|
|
|
|
float depth = polygon->get_depth() * 0.5;
|
2017-12-14 12:59:46 +01:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
Vector<Vector3> lines;
|
|
|
|
for (int i = 0; i < points.size(); i++) {
|
|
|
|
int n = (i + 1) % points.size();
|
|
|
|
lines.push_back(Vector3(points[i].x, points[i].y, depth));
|
|
|
|
lines.push_back(Vector3(points[n].x, points[n].y, depth));
|
|
|
|
lines.push_back(Vector3(points[i].x, points[i].y, -depth));
|
|
|
|
lines.push_back(Vector3(points[n].x, points[n].y, -depth));
|
|
|
|
lines.push_back(Vector3(points[i].x, points[i].y, depth));
|
|
|
|
lines.push_back(Vector3(points[i].x, points[i].y, -depth));
|
2017-12-14 12:59:46 +01:00
|
|
|
}
|
|
|
|
|
2019-08-21 15:27:02 +02:00
|
|
|
const Ref<Material> material =
|
|
|
|
get_material(!polygon->is_disabled() ? "shape_material" : "shape_material_disabled", p_gizmo);
|
2017-12-14 12:59:46 +01:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
p_gizmo->add_lines(lines, material);
|
|
|
|
p_gizmo->add_collision_segments(lines);
|
|
|
|
}
|
|
|
|
|
|
|
|
////
|
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
NavigationRegion3DGizmoPlugin::NavigationRegion3DGizmoPlugin() {
|
2019-02-20 14:53:22 +01:00
|
|
|
create_material("navigation_edge_material", EDITOR_DEF("editors/3d_gizmos/gizmo_colors/navigation_edge", Color(0.5, 1, 1)));
|
|
|
|
create_material("navigation_edge_material_disabled", EDITOR_DEF("editors/3d_gizmos/gizmo_colors/navigation_edge_disabled", Color(0.7, 0.7, 0.7)));
|
|
|
|
create_material("navigation_solid_material", EDITOR_DEF("editors/3d_gizmos/gizmo_colors/navigation_solid", Color(0.5, 1, 1, 0.4)));
|
|
|
|
create_material("navigation_solid_material_disabled", EDITOR_DEF("editors/3d_gizmos/gizmo_colors/navigation_solid_disabled", Color(0.7, 0.7, 0.7, 0.4)));
|
2018-07-25 00:08:49 +02:00
|
|
|
}
|
2017-12-14 12:59:46 +01:00
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
bool NavigationRegion3DGizmoPlugin::has_gizmo(Node3D *p_spatial) {
|
2020-04-02 01:20:12 +02:00
|
|
|
return Object::cast_to<NavigationRegion3D>(p_spatial) != nullptr;
|
2017-12-14 12:59:46 +01:00
|
|
|
}
|
|
|
|
|
2020-07-23 00:39:21 +02:00
|
|
|
String NavigationRegion3DGizmoPlugin::get_gizmo_name() const {
|
2020-03-30 18:22:57 +02:00
|
|
|
return "NavigationRegion3D";
|
2017-12-14 12:59:46 +01:00
|
|
|
}
|
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
int NavigationRegion3DGizmoPlugin::get_priority() const {
|
2019-03-12 00:30:50 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
void NavigationRegion3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
|
2020-03-26 22:49:16 +01:00
|
|
|
NavigationRegion3D *navmesh = Object::cast_to<NavigationRegion3D>(p_gizmo->get_spatial_node());
|
2017-08-26 05:40:45 +02:00
|
|
|
|
2019-02-20 14:53:22 +01:00
|
|
|
Ref<Material> edge_material = get_material("navigation_edge_material", p_gizmo);
|
|
|
|
Ref<Material> edge_material_disabled = get_material("navigation_edge_material_disabled", p_gizmo);
|
|
|
|
Ref<Material> solid_material = get_material("navigation_solid_material", p_gizmo);
|
|
|
|
Ref<Material> solid_material_disabled = get_material("navigation_solid_material_disabled", p_gizmo);
|
2018-07-25 00:08:49 +02:00
|
|
|
|
|
|
|
p_gizmo->clear();
|
2015-10-08 20:00:40 +02:00
|
|
|
Ref<NavigationMesh> navmeshie = navmesh->get_navigation_mesh();
|
2020-05-14 16:41:43 +02:00
|
|
|
if (navmeshie.is_null()) {
|
2015-10-08 20:00:40 +02:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2020-02-17 22:06:54 +01:00
|
|
|
Vector<Vector3> vertices = navmeshie->get_vertices();
|
|
|
|
const Vector3 *vr = vertices.ptr();
|
2015-10-08 20:00:40 +02:00
|
|
|
List<Face3> faces;
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < navmeshie->get_polygon_count(); i++) {
|
2015-10-08 20:00:40 +02:00
|
|
|
Vector<int> p = navmeshie->get_polygon(i);
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int j = 2; j < p.size(); j++) {
|
2015-10-08 20:00:40 +02:00
|
|
|
Face3 f;
|
2017-03-05 16:44:50 +01:00
|
|
|
f.vertex[0] = vr[p[0]];
|
|
|
|
f.vertex[1] = vr[p[j - 1]];
|
|
|
|
f.vertex[2] = vr[p[j]];
|
2015-10-08 20:00:40 +02:00
|
|
|
|
|
|
|
faces.push_back(f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-14 16:41:43 +02:00
|
|
|
if (faces.empty()) {
|
2015-12-12 18:06:27 +01:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Map<_EdgeKey, bool> edge_map;
|
2020-02-17 22:06:54 +01:00
|
|
|
Vector<Vector3> tmeshfaces;
|
2017-03-05 16:44:50 +01:00
|
|
|
tmeshfaces.resize(faces.size() * 3);
|
2015-10-08 20:00:40 +02:00
|
|
|
|
|
|
|
{
|
2020-02-17 22:06:54 +01:00
|
|
|
Vector3 *tw = tmeshfaces.ptrw();
|
2017-03-05 16:44:50 +01:00
|
|
|
int tidx = 0;
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (List<Face3>::Element *E = faces.front(); E; E = E->next()) {
|
2015-10-08 20:00:40 +02:00
|
|
|
const Face3 &f = E->get();
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int j = 0; j < 3; j++) {
|
|
|
|
tw[tidx++] = f.vertex[j];
|
2015-10-08 20:00:40 +02:00
|
|
|
_EdgeKey ek;
|
2017-06-30 20:47:17 +02:00
|
|
|
ek.from = f.vertex[j].snapped(Vector3(CMP_EPSILON, CMP_EPSILON, CMP_EPSILON));
|
|
|
|
ek.to = f.vertex[(j + 1) % 3].snapped(Vector3(CMP_EPSILON, CMP_EPSILON, CMP_EPSILON));
|
2020-05-14 16:41:43 +02:00
|
|
|
if (ek.from < ek.to) {
|
2017-03-05 16:44:50 +01:00
|
|
|
SWAP(ek.from, ek.to);
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2019-02-12 21:10:08 +01:00
|
|
|
Map<_EdgeKey, bool>::Element *F = edge_map.find(ek);
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2019-02-12 21:10:08 +01:00
|
|
|
if (F) {
|
|
|
|
F->get() = false;
|
2015-10-08 20:00:40 +02:00
|
|
|
|
|
|
|
} else {
|
2017-03-05 16:44:50 +01:00
|
|
|
edge_map[ek] = true;
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Vector<Vector3> lines;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (Map<_EdgeKey, bool>::Element *E = edge_map.front(); E; E = E->next()) {
|
2015-10-08 20:00:40 +02:00
|
|
|
if (E->get()) {
|
|
|
|
lines.push_back(E->key().from);
|
|
|
|
lines.push_back(E->key().to);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Ref<TriangleMesh> tmesh = memnew(TriangleMesh);
|
2015-10-08 20:00:40 +02:00
|
|
|
tmesh->create(tmeshfaces);
|
|
|
|
|
2020-05-14 16:41:43 +02:00
|
|
|
if (lines.size()) {
|
2018-07-25 00:08:49 +02:00
|
|
|
p_gizmo->add_lines(lines, navmesh->is_enabled() ? edge_material : edge_material_disabled);
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2018-07-25 00:08:49 +02:00
|
|
|
p_gizmo->add_collision_triangles(tmesh);
|
2017-06-07 23:18:55 +02:00
|
|
|
Ref<ArrayMesh> m = memnew(ArrayMesh);
|
2015-10-08 20:00:40 +02:00
|
|
|
Array a;
|
|
|
|
a.resize(Mesh::ARRAY_MAX);
|
2017-03-05 16:44:50 +01:00
|
|
|
a[0] = tmeshfaces;
|
|
|
|
m->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, a);
|
2017-08-26 05:40:45 +02:00
|
|
|
m->surface_set_material(0, navmesh->is_enabled() ? solid_material : solid_material_disabled);
|
2018-07-25 00:08:49 +02:00
|
|
|
p_gizmo->add_mesh(m);
|
|
|
|
p_gizmo->add_collision_segments(lines);
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
|
2018-08-21 21:28:06 +02:00
|
|
|
//////
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2017-12-16 14:05:19 +01:00
|
|
|
#define BODY_A_RADIUS 0.25
|
|
|
|
#define BODY_B_RADIUS 0.27
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2017-12-16 14:05:19 +01:00
|
|
|
Basis JointGizmosDrawer::look_body(const Transform &p_joint_transform, const Transform &p_body_transform) {
|
|
|
|
const Vector3 &p_eye(p_joint_transform.origin);
|
|
|
|
const Vector3 &p_target(p_body_transform.origin);
|
2017-08-26 05:40:45 +02:00
|
|
|
|
2017-12-16 14:05:19 +01:00
|
|
|
Vector3 v_x, v_y, v_z;
|
2017-08-26 05:40:45 +02:00
|
|
|
|
2017-12-16 14:05:19 +01:00
|
|
|
// Look the body with X
|
|
|
|
v_x = p_target - p_eye;
|
|
|
|
v_x.normalize();
|
|
|
|
|
|
|
|
v_z = v_x.cross(Vector3(0, 1, 0));
|
|
|
|
v_z.normalize();
|
|
|
|
|
|
|
|
v_y = v_z.cross(v_x);
|
|
|
|
v_y.normalize();
|
|
|
|
|
|
|
|
Basis base;
|
|
|
|
base.set(v_x, v_y, v_z);
|
|
|
|
|
|
|
|
// Absorb current joint transform
|
|
|
|
base = p_joint_transform.basis.inverse() * base;
|
|
|
|
|
|
|
|
return base;
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
|
2017-12-16 14:05:19 +01:00
|
|
|
Basis JointGizmosDrawer::look_body_toward(Vector3::Axis p_axis, const Transform &joint_transform, const Transform &body_transform) {
|
|
|
|
switch (p_axis) {
|
|
|
|
case Vector3::AXIS_X:
|
|
|
|
return look_body_toward_x(joint_transform, body_transform);
|
|
|
|
case Vector3::AXIS_Y:
|
|
|
|
return look_body_toward_y(joint_transform, body_transform);
|
|
|
|
case Vector3::AXIS_Z:
|
|
|
|
return look_body_toward_z(joint_transform, body_transform);
|
|
|
|
default:
|
|
|
|
return Basis();
|
|
|
|
}
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
|
2017-12-16 14:05:19 +01:00
|
|
|
Basis JointGizmosDrawer::look_body_toward_x(const Transform &p_joint_transform, const Transform &p_body_transform) {
|
|
|
|
const Vector3 &p_eye(p_joint_transform.origin);
|
|
|
|
const Vector3 &p_target(p_body_transform.origin);
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2017-12-16 14:05:19 +01:00
|
|
|
const Vector3 p_front(p_joint_transform.basis.get_axis(0));
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2017-12-16 14:05:19 +01:00
|
|
|
Vector3 v_x, v_y, v_z;
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2017-12-16 14:05:19 +01:00
|
|
|
// Look the body with X
|
|
|
|
v_x = p_target - p_eye;
|
|
|
|
v_x.normalize();
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2017-12-16 14:05:19 +01:00
|
|
|
v_y = p_front.cross(v_x);
|
|
|
|
v_y.normalize();
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2017-12-16 14:05:19 +01:00
|
|
|
v_z = v_y.cross(p_front);
|
|
|
|
v_z.normalize();
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2017-12-16 14:05:19 +01:00
|
|
|
// Clamp X to FRONT axis
|
|
|
|
v_x = p_front;
|
|
|
|
v_x.normalize();
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2017-12-16 14:05:19 +01:00
|
|
|
Basis base;
|
|
|
|
base.set(v_x, v_y, v_z);
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2017-12-16 14:05:19 +01:00
|
|
|
// Absorb current joint transform
|
|
|
|
base = p_joint_transform.basis.inverse() * base;
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2017-12-16 14:05:19 +01:00
|
|
|
return base;
|
|
|
|
}
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2017-12-16 14:05:19 +01:00
|
|
|
Basis JointGizmosDrawer::look_body_toward_y(const Transform &p_joint_transform, const Transform &p_body_transform) {
|
|
|
|
const Vector3 &p_eye(p_joint_transform.origin);
|
|
|
|
const Vector3 &p_target(p_body_transform.origin);
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2017-12-16 14:05:19 +01:00
|
|
|
const Vector3 p_up(p_joint_transform.basis.get_axis(1));
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2017-12-16 14:05:19 +01:00
|
|
|
Vector3 v_x, v_y, v_z;
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2017-12-16 14:05:19 +01:00
|
|
|
// Look the body with X
|
|
|
|
v_x = p_target - p_eye;
|
|
|
|
v_x.normalize();
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2017-12-16 14:05:19 +01:00
|
|
|
v_z = v_x.cross(p_up);
|
|
|
|
v_z.normalize();
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2017-12-16 14:05:19 +01:00
|
|
|
v_x = p_up.cross(v_z);
|
|
|
|
v_x.normalize();
|
2017-08-26 05:40:45 +02:00
|
|
|
|
2017-12-16 14:05:19 +01:00
|
|
|
// Clamp Y to UP axis
|
|
|
|
v_y = p_up;
|
|
|
|
v_y.normalize();
|
2017-08-26 05:40:45 +02:00
|
|
|
|
2017-12-16 14:05:19 +01:00
|
|
|
Basis base;
|
|
|
|
base.set(v_x, v_y, v_z);
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2017-12-16 14:05:19 +01:00
|
|
|
// Absorb current joint transform
|
|
|
|
base = p_joint_transform.basis.inverse() * base;
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2017-12-16 14:05:19 +01:00
|
|
|
return base;
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
|
2017-12-16 14:05:19 +01:00
|
|
|
Basis JointGizmosDrawer::look_body_toward_z(const Transform &p_joint_transform, const Transform &p_body_transform) {
|
|
|
|
const Vector3 &p_eye(p_joint_transform.origin);
|
|
|
|
const Vector3 &p_target(p_body_transform.origin);
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2017-12-16 14:05:19 +01:00
|
|
|
const Vector3 p_lateral(p_joint_transform.basis.get_axis(2));
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2017-12-16 14:05:19 +01:00
|
|
|
Vector3 v_x, v_y, v_z;
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2017-12-16 14:05:19 +01:00
|
|
|
// Look the body with X
|
|
|
|
v_x = p_target - p_eye;
|
|
|
|
v_x.normalize();
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2017-12-16 14:05:19 +01:00
|
|
|
v_z = p_lateral;
|
|
|
|
v_z.normalize();
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2017-12-16 14:05:19 +01:00
|
|
|
v_y = v_z.cross(v_x);
|
|
|
|
v_y.normalize();
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2017-12-16 14:05:19 +01:00
|
|
|
// Clamp X to Z axis
|
|
|
|
v_x = v_y.cross(v_z);
|
|
|
|
v_x.normalize();
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2017-12-16 14:05:19 +01:00
|
|
|
Basis base;
|
|
|
|
base.set(v_x, v_y, v_z);
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2017-12-16 14:05:19 +01:00
|
|
|
// Absorb current joint transform
|
|
|
|
base = p_joint_transform.basis.inverse() * base;
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2017-12-16 14:05:19 +01:00
|
|
|
return base;
|
|
|
|
}
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2017-12-16 14:05:19 +01:00
|
|
|
void JointGizmosDrawer::draw_circle(Vector3::Axis p_axis, real_t p_radius, const Transform &p_offset, const Basis &p_base, real_t p_limit_lower, real_t p_limit_upper, Vector<Vector3> &r_points, bool p_inverse) {
|
|
|
|
if (p_limit_lower == p_limit_upper) {
|
|
|
|
r_points.push_back(p_offset.translated(Vector3()).origin);
|
|
|
|
r_points.push_back(p_offset.translated(p_base.xform(Vector3(0.5, 0, 0))).origin);
|
2015-10-08 20:00:40 +02:00
|
|
|
|
|
|
|
} else {
|
2017-12-16 14:05:19 +01:00
|
|
|
if (p_limit_lower > p_limit_upper) {
|
|
|
|
p_limit_lower = -Math_PI;
|
|
|
|
p_limit_upper = Math_PI;
|
|
|
|
}
|
|
|
|
|
2015-10-08 20:00:40 +02:00
|
|
|
const int points = 32;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < points; i++) {
|
2017-12-16 14:05:19 +01:00
|
|
|
real_t s = p_limit_lower + i * (p_limit_upper - p_limit_lower) / points;
|
|
|
|
real_t n = p_limit_lower + (i + 1) * (p_limit_upper - p_limit_lower) / points;
|
|
|
|
|
|
|
|
Vector3 from;
|
|
|
|
Vector3 to;
|
|
|
|
switch (p_axis) {
|
|
|
|
case Vector3::AXIS_X:
|
|
|
|
if (p_inverse) {
|
|
|
|
from = p_base.xform(Vector3(0, Math::sin(s), Math::cos(s))) * p_radius;
|
|
|
|
to = p_base.xform(Vector3(0, Math::sin(n), Math::cos(n))) * p_radius;
|
|
|
|
} else {
|
|
|
|
from = p_base.xform(Vector3(0, -Math::sin(s), Math::cos(s))) * p_radius;
|
|
|
|
to = p_base.xform(Vector3(0, -Math::sin(n), Math::cos(n))) * p_radius;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Vector3::AXIS_Y:
|
|
|
|
if (p_inverse) {
|
|
|
|
from = p_base.xform(Vector3(Math::cos(s), 0, -Math::sin(s))) * p_radius;
|
|
|
|
to = p_base.xform(Vector3(Math::cos(n), 0, -Math::sin(n))) * p_radius;
|
|
|
|
} else {
|
|
|
|
from = p_base.xform(Vector3(Math::cos(s), 0, Math::sin(s))) * p_radius;
|
|
|
|
to = p_base.xform(Vector3(Math::cos(n), 0, Math::sin(n))) * p_radius;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Vector3::AXIS_Z:
|
|
|
|
from = p_base.xform(Vector3(Math::cos(s), Math::sin(s), 0)) * p_radius;
|
|
|
|
to = p_base.xform(Vector3(Math::cos(n), Math::sin(n), 0)) * p_radius;
|
|
|
|
break;
|
|
|
|
}
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2017-12-16 14:05:19 +01:00
|
|
|
if (i == points - 1) {
|
|
|
|
r_points.push_back(p_offset.translated(to).origin);
|
|
|
|
r_points.push_back(p_offset.translated(Vector3()).origin);
|
|
|
|
}
|
|
|
|
if (i == 0) {
|
|
|
|
r_points.push_back(p_offset.translated(from).origin);
|
|
|
|
r_points.push_back(p_offset.translated(Vector3()).origin);
|
|
|
|
}
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2017-12-16 14:05:19 +01:00
|
|
|
r_points.push_back(p_offset.translated(from).origin);
|
|
|
|
r_points.push_back(p_offset.translated(to).origin);
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
2017-08-26 05:40:45 +02:00
|
|
|
|
2017-12-16 14:05:19 +01:00
|
|
|
r_points.push_back(p_offset.translated(Vector3(0, p_radius * 1.5, 0)).origin);
|
|
|
|
r_points.push_back(p_offset.translated(Vector3()).origin);
|
|
|
|
}
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
|
2017-12-16 14:05:19 +01:00
|
|
|
void JointGizmosDrawer::draw_cone(const Transform &p_offset, const Basis &p_base, real_t p_swing, real_t p_twist, Vector<Vector3> &r_points) {
|
2015-10-08 20:00:40 +02:00
|
|
|
float r = 1.0;
|
2017-12-16 14:05:19 +01:00
|
|
|
float w = r * Math::sin(p_swing);
|
|
|
|
float d = r * Math::cos(p_swing);
|
2015-10-08 20:00:40 +02:00
|
|
|
|
|
|
|
//swing
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < 360; i += 10) {
|
|
|
|
float ra = Math::deg2rad((float)i);
|
|
|
|
float rb = Math::deg2rad((float)i + 10);
|
|
|
|
Point2 a = Vector2(Math::sin(ra), Math::cos(ra)) * w;
|
|
|
|
Point2 b = Vector2(Math::sin(rb), Math::cos(rb)) * w;
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2017-12-16 14:05:19 +01:00
|
|
|
r_points.push_back(p_offset.translated(p_base.xform(Vector3(d, a.x, a.y))).origin);
|
|
|
|
r_points.push_back(p_offset.translated(p_base.xform(Vector3(d, b.x, b.y))).origin);
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (i % 90 == 0) {
|
2017-12-16 14:05:19 +01:00
|
|
|
r_points.push_back(p_offset.translated(p_base.xform(Vector3(d, a.x, a.y))).origin);
|
|
|
|
r_points.push_back(p_offset.translated(p_base.xform(Vector3())).origin);
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-16 14:05:19 +01:00
|
|
|
r_points.push_back(p_offset.translated(p_base.xform(Vector3())).origin);
|
|
|
|
r_points.push_back(p_offset.translated(p_base.xform(Vector3(1, 0, 0))).origin);
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2017-12-16 14:05:19 +01:00
|
|
|
/// Twist
|
|
|
|
float ts = Math::rad2deg(p_twist);
|
2017-03-05 16:44:50 +01:00
|
|
|
ts = MIN(ts, 720);
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int i = 0; i < int(ts); i += 5) {
|
|
|
|
float ra = Math::deg2rad((float)i);
|
|
|
|
float rb = Math::deg2rad((float)i + 5);
|
|
|
|
float c = i / 720.0;
|
|
|
|
float cn = (i + 5) / 720.0;
|
|
|
|
Point2 a = Vector2(Math::sin(ra), Math::cos(ra)) * w * c;
|
|
|
|
Point2 b = Vector2(Math::sin(rb), Math::cos(rb)) * w * cn;
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2017-12-16 14:05:19 +01:00
|
|
|
r_points.push_back(p_offset.translated(p_base.xform(Vector3(c, a.x, a.y))).origin);
|
|
|
|
r_points.push_back(p_offset.translated(p_base.xform(Vector3(cn, b.x, b.y))).origin);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
////
|
2017-12-16 14:05:19 +01:00
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
Joint3DGizmoPlugin::Joint3DGizmoPlugin() {
|
2018-07-25 00:08:49 +02:00
|
|
|
create_material("joint_material", EDITOR_DEF("editors/3d_gizmos/gizmo_colors/joint", Color(0.5, 0.8, 1)));
|
|
|
|
create_material("joint_body_a_material", EDITOR_DEF("editors/3d_gizmos/gizmo_colors/joint_body_a", Color(0.6, 0.8, 1)));
|
|
|
|
create_material("joint_body_b_material", EDITOR_DEF("editors/3d_gizmos/gizmo_colors/joint_body_b", Color(0.6, 0.9, 1)));
|
2020-03-20 12:41:07 +01:00
|
|
|
|
|
|
|
update_timer = memnew(Timer);
|
|
|
|
update_timer->set_name("JointGizmoUpdateTimer");
|
|
|
|
update_timer->set_wait_time(1.0 / 120.0);
|
|
|
|
update_timer->connect("timeout", callable_mp(this, &Joint3DGizmoPlugin::incremental_update_gizmos));
|
|
|
|
update_timer->set_autostart(true);
|
|
|
|
EditorNode::get_singleton()->call_deferred("add_child", update_timer);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Joint3DGizmoPlugin::incremental_update_gizmos() {
|
|
|
|
if (!current_gizmos.empty()) {
|
|
|
|
update_idx++;
|
|
|
|
update_idx = update_idx % current_gizmos.size();
|
|
|
|
redraw(current_gizmos[update_idx]);
|
|
|
|
}
|
2017-12-16 14:05:19 +01:00
|
|
|
}
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
bool Joint3DGizmoPlugin::has_gizmo(Node3D *p_spatial) {
|
2020-04-02 01:20:12 +02:00
|
|
|
return Object::cast_to<Joint3D>(p_spatial) != nullptr;
|
2018-07-25 00:08:49 +02:00
|
|
|
}
|
2017-12-16 14:05:19 +01:00
|
|
|
|
2020-07-23 00:39:21 +02:00
|
|
|
String Joint3DGizmoPlugin::get_gizmo_name() const {
|
2020-04-06 12:40:52 +02:00
|
|
|
return "Joint3D";
|
2018-07-25 00:08:49 +02:00
|
|
|
}
|
2017-12-16 14:05:19 +01:00
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
int Joint3DGizmoPlugin::get_priority() const {
|
2019-03-12 00:30:50 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
void Joint3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) {
|
2020-03-26 22:49:16 +01:00
|
|
|
Joint3D *joint = Object::cast_to<Joint3D>(p_gizmo->get_spatial_node());
|
2017-12-16 14:05:19 +01:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
p_gizmo->clear();
|
2017-12-16 14:05:19 +01:00
|
|
|
|
2020-04-02 01:20:12 +02:00
|
|
|
Node3D *node_body_a = nullptr;
|
2019-12-05 19:27:57 +01:00
|
|
|
if (!joint->get_node_a().is_empty()) {
|
2020-03-26 22:49:16 +01:00
|
|
|
node_body_a = Object::cast_to<Node3D>(joint->get_node(joint->get_node_a()));
|
2019-12-05 19:27:57 +01:00
|
|
|
}
|
|
|
|
|
2020-04-02 01:20:12 +02:00
|
|
|
Node3D *node_body_b = nullptr;
|
2019-12-05 19:27:57 +01:00
|
|
|
if (!joint->get_node_b().is_empty()) {
|
2020-03-26 22:49:16 +01:00
|
|
|
node_body_b = Object::cast_to<Node3D>(joint->get_node(joint->get_node_b()));
|
2019-12-05 19:27:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!node_body_a && !node_body_b) {
|
|
|
|
return;
|
|
|
|
}
|
2017-12-16 14:05:19 +01:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
Ref<Material> common_material = get_material("joint_material", p_gizmo);
|
|
|
|
Ref<Material> body_a_material = get_material("joint_body_a_material", p_gizmo);
|
|
|
|
Ref<Material> body_b_material = get_material("joint_body_b_material", p_gizmo);
|
2017-12-16 14:05:19 +01:00
|
|
|
|
2018-07-25 00:08:49 +02:00
|
|
|
Vector<Vector3> points;
|
|
|
|
Vector<Vector3> body_a_points;
|
|
|
|
Vector<Vector3> body_b_points;
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
if (Object::cast_to<PinJoint3D>(joint)) {
|
2018-07-25 00:08:49 +02:00
|
|
|
CreatePinJointGizmo(Transform(), points);
|
|
|
|
p_gizmo->add_collision_segments(points);
|
|
|
|
p_gizmo->add_lines(points, common_material);
|
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
HingeJoint3D *hinge = Object::cast_to<HingeJoint3D>(joint);
|
2018-07-25 00:08:49 +02:00
|
|
|
if (hinge) {
|
|
|
|
CreateHingeJointGizmo(
|
|
|
|
Transform(),
|
|
|
|
hinge->get_global_transform(),
|
|
|
|
node_body_a ? node_body_a->get_global_transform() : Transform(),
|
|
|
|
node_body_b ? node_body_b->get_global_transform() : Transform(),
|
2020-03-26 22:49:16 +01:00
|
|
|
hinge->get_param(HingeJoint3D::PARAM_LIMIT_LOWER),
|
|
|
|
hinge->get_param(HingeJoint3D::PARAM_LIMIT_UPPER),
|
|
|
|
hinge->get_flag(HingeJoint3D::FLAG_USE_LIMIT),
|
2018-07-25 00:08:49 +02:00
|
|
|
points,
|
2020-04-02 01:20:12 +02:00
|
|
|
node_body_a ? &body_a_points : nullptr,
|
|
|
|
node_body_b ? &body_b_points : nullptr);
|
2018-07-25 00:08:49 +02:00
|
|
|
|
|
|
|
p_gizmo->add_collision_segments(points);
|
|
|
|
p_gizmo->add_collision_segments(body_a_points);
|
|
|
|
p_gizmo->add_collision_segments(body_b_points);
|
|
|
|
|
|
|
|
p_gizmo->add_lines(points, common_material);
|
|
|
|
p_gizmo->add_lines(body_a_points, body_a_material);
|
|
|
|
p_gizmo->add_lines(body_b_points, body_b_material);
|
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
SliderJoint3D *slider = Object::cast_to<SliderJoint3D>(joint);
|
2018-07-25 00:08:49 +02:00
|
|
|
if (slider) {
|
|
|
|
CreateSliderJointGizmo(
|
|
|
|
Transform(),
|
|
|
|
slider->get_global_transform(),
|
|
|
|
node_body_a ? node_body_a->get_global_transform() : Transform(),
|
|
|
|
node_body_b ? node_body_b->get_global_transform() : Transform(),
|
2020-03-26 22:49:16 +01:00
|
|
|
slider->get_param(SliderJoint3D::PARAM_ANGULAR_LIMIT_LOWER),
|
|
|
|
slider->get_param(SliderJoint3D::PARAM_ANGULAR_LIMIT_UPPER),
|
|
|
|
slider->get_param(SliderJoint3D::PARAM_LINEAR_LIMIT_LOWER),
|
|
|
|
slider->get_param(SliderJoint3D::PARAM_LINEAR_LIMIT_UPPER),
|
2018-07-25 00:08:49 +02:00
|
|
|
points,
|
2020-04-02 01:20:12 +02:00
|
|
|
node_body_a ? &body_a_points : nullptr,
|
|
|
|
node_body_b ? &body_b_points : nullptr);
|
2018-07-25 00:08:49 +02:00
|
|
|
|
|
|
|
p_gizmo->add_collision_segments(points);
|
|
|
|
p_gizmo->add_collision_segments(body_a_points);
|
|
|
|
p_gizmo->add_collision_segments(body_b_points);
|
|
|
|
|
|
|
|
p_gizmo->add_lines(points, common_material);
|
|
|
|
p_gizmo->add_lines(body_a_points, body_a_material);
|
|
|
|
p_gizmo->add_lines(body_b_points, body_b_material);
|
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
ConeTwistJoint3D *cone = Object::cast_to<ConeTwistJoint3D>(joint);
|
2018-07-25 00:08:49 +02:00
|
|
|
if (cone) {
|
|
|
|
CreateConeTwistJointGizmo(
|
|
|
|
Transform(),
|
|
|
|
cone->get_global_transform(),
|
|
|
|
node_body_a ? node_body_a->get_global_transform() : Transform(),
|
|
|
|
node_body_b ? node_body_b->get_global_transform() : Transform(),
|
2020-03-26 22:49:16 +01:00
|
|
|
cone->get_param(ConeTwistJoint3D::PARAM_SWING_SPAN),
|
|
|
|
cone->get_param(ConeTwistJoint3D::PARAM_TWIST_SPAN),
|
2020-04-02 01:20:12 +02:00
|
|
|
node_body_a ? &body_a_points : nullptr,
|
|
|
|
node_body_b ? &body_b_points : nullptr);
|
2018-07-25 00:08:49 +02:00
|
|
|
|
|
|
|
p_gizmo->add_collision_segments(body_a_points);
|
|
|
|
p_gizmo->add_collision_segments(body_b_points);
|
|
|
|
|
|
|
|
p_gizmo->add_lines(body_a_points, body_a_material);
|
|
|
|
p_gizmo->add_lines(body_b_points, body_b_material);
|
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
Generic6DOFJoint3D *gen = Object::cast_to<Generic6DOFJoint3D>(joint);
|
2018-07-25 00:08:49 +02:00
|
|
|
if (gen) {
|
|
|
|
CreateGeneric6DOFJointGizmo(
|
|
|
|
Transform(),
|
|
|
|
gen->get_global_transform(),
|
|
|
|
node_body_a ? node_body_a->get_global_transform() : Transform(),
|
|
|
|
node_body_b ? node_body_b->get_global_transform() : Transform(),
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
gen->get_param_x(Generic6DOFJoint3D::PARAM_ANGULAR_LOWER_LIMIT),
|
|
|
|
gen->get_param_x(Generic6DOFJoint3D::PARAM_ANGULAR_UPPER_LIMIT),
|
|
|
|
gen->get_param_x(Generic6DOFJoint3D::PARAM_LINEAR_LOWER_LIMIT),
|
|
|
|
gen->get_param_x(Generic6DOFJoint3D::PARAM_LINEAR_UPPER_LIMIT),
|
|
|
|
gen->get_flag_x(Generic6DOFJoint3D::FLAG_ENABLE_ANGULAR_LIMIT),
|
|
|
|
gen->get_flag_x(Generic6DOFJoint3D::FLAG_ENABLE_LINEAR_LIMIT),
|
|
|
|
|
|
|
|
gen->get_param_y(Generic6DOFJoint3D::PARAM_ANGULAR_LOWER_LIMIT),
|
|
|
|
gen->get_param_y(Generic6DOFJoint3D::PARAM_ANGULAR_UPPER_LIMIT),
|
|
|
|
gen->get_param_y(Generic6DOFJoint3D::PARAM_LINEAR_LOWER_LIMIT),
|
|
|
|
gen->get_param_y(Generic6DOFJoint3D::PARAM_LINEAR_UPPER_LIMIT),
|
|
|
|
gen->get_flag_y(Generic6DOFJoint3D::FLAG_ENABLE_ANGULAR_LIMIT),
|
|
|
|
gen->get_flag_y(Generic6DOFJoint3D::FLAG_ENABLE_LINEAR_LIMIT),
|
|
|
|
|
|
|
|
gen->get_param_z(Generic6DOFJoint3D::PARAM_ANGULAR_LOWER_LIMIT),
|
|
|
|
gen->get_param_z(Generic6DOFJoint3D::PARAM_ANGULAR_UPPER_LIMIT),
|
|
|
|
gen->get_param_z(Generic6DOFJoint3D::PARAM_LINEAR_LOWER_LIMIT),
|
|
|
|
gen->get_param_z(Generic6DOFJoint3D::PARAM_LINEAR_UPPER_LIMIT),
|
|
|
|
gen->get_flag_z(Generic6DOFJoint3D::FLAG_ENABLE_ANGULAR_LIMIT),
|
|
|
|
gen->get_flag_z(Generic6DOFJoint3D::FLAG_ENABLE_LINEAR_LIMIT),
|
2018-07-25 00:08:49 +02:00
|
|
|
|
|
|
|
points,
|
2020-04-02 01:20:12 +02:00
|
|
|
node_body_a ? &body_a_points : nullptr,
|
|
|
|
node_body_a ? &body_b_points : nullptr);
|
2018-07-25 00:08:49 +02:00
|
|
|
|
|
|
|
p_gizmo->add_collision_segments(points);
|
|
|
|
p_gizmo->add_collision_segments(body_a_points);
|
|
|
|
p_gizmo->add_collision_segments(body_b_points);
|
|
|
|
|
|
|
|
p_gizmo->add_lines(points, common_material);
|
|
|
|
p_gizmo->add_lines(body_a_points, body_a_material);
|
|
|
|
p_gizmo->add_lines(body_b_points, body_b_material);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
void Joint3DGizmoPlugin::CreatePinJointGizmo(const Transform &p_offset, Vector<Vector3> &r_cursor_points) {
|
2018-07-25 00:08:49 +02:00
|
|
|
float cs = 0.25;
|
|
|
|
|
|
|
|
r_cursor_points.push_back(p_offset.translated(Vector3(+cs, 0, 0)).origin);
|
|
|
|
r_cursor_points.push_back(p_offset.translated(Vector3(-cs, 0, 0)).origin);
|
|
|
|
r_cursor_points.push_back(p_offset.translated(Vector3(0, +cs, 0)).origin);
|
|
|
|
r_cursor_points.push_back(p_offset.translated(Vector3(0, -cs, 0)).origin);
|
|
|
|
r_cursor_points.push_back(p_offset.translated(Vector3(0, 0, +cs)).origin);
|
|
|
|
r_cursor_points.push_back(p_offset.translated(Vector3(0, 0, -cs)).origin);
|
|
|
|
}
|
2017-12-16 14:05:19 +01:00
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
void Joint3DGizmoPlugin::CreateHingeJointGizmo(const Transform &p_offset, const Transform &p_trs_joint, const Transform &p_trs_body_a, const Transform &p_trs_body_b, real_t p_limit_lower, real_t p_limit_upper, bool p_use_limit, Vector<Vector3> &r_common_points, Vector<Vector3> *r_body_a_points, Vector<Vector3> *r_body_b_points) {
|
2017-12-16 14:05:19 +01:00
|
|
|
r_common_points.push_back(p_offset.translated(Vector3(0, 0, 0.5)).origin);
|
|
|
|
r_common_points.push_back(p_offset.translated(Vector3(0, 0, -0.5)).origin);
|
|
|
|
|
|
|
|
if (!p_use_limit) {
|
|
|
|
p_limit_upper = -1;
|
|
|
|
p_limit_lower = 0;
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
|
2017-12-16 14:05:19 +01:00
|
|
|
if (r_body_a_points) {
|
|
|
|
JointGizmosDrawer::draw_circle(Vector3::AXIS_Z,
|
|
|
|
BODY_A_RADIUS,
|
|
|
|
p_offset,
|
|
|
|
JointGizmosDrawer::look_body_toward_z(p_trs_joint, p_trs_body_a),
|
|
|
|
p_limit_lower,
|
|
|
|
p_limit_upper,
|
|
|
|
*r_body_a_points);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (r_body_b_points) {
|
|
|
|
JointGizmosDrawer::draw_circle(Vector3::AXIS_Z,
|
|
|
|
BODY_B_RADIUS,
|
|
|
|
p_offset,
|
|
|
|
JointGizmosDrawer::look_body_toward_z(p_trs_joint, p_trs_body_b),
|
|
|
|
p_limit_lower,
|
|
|
|
p_limit_upper,
|
|
|
|
*r_body_b_points);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
void Joint3DGizmoPlugin::CreateSliderJointGizmo(const Transform &p_offset, const Transform &p_trs_joint, const Transform &p_trs_body_a, const Transform &p_trs_body_b, real_t p_angular_limit_lower, real_t p_angular_limit_upper, real_t p_linear_limit_lower, real_t p_linear_limit_upper, Vector<Vector3> &r_points, Vector<Vector3> *r_body_a_points, Vector<Vector3> *r_body_b_points) {
|
2017-12-16 14:05:19 +01:00
|
|
|
p_linear_limit_lower = -p_linear_limit_lower;
|
|
|
|
p_linear_limit_upper = -p_linear_limit_upper;
|
|
|
|
|
|
|
|
float cs = 0.25;
|
|
|
|
r_points.push_back(p_offset.translated(Vector3(0, 0, 0.5)).origin);
|
|
|
|
r_points.push_back(p_offset.translated(Vector3(0, 0, -0.5)).origin);
|
|
|
|
|
|
|
|
if (p_linear_limit_lower >= p_linear_limit_upper) {
|
|
|
|
r_points.push_back(p_offset.translated(Vector3(p_linear_limit_upper, 0, 0)).origin);
|
|
|
|
r_points.push_back(p_offset.translated(Vector3(p_linear_limit_lower, 0, 0)).origin);
|
|
|
|
|
|
|
|
r_points.push_back(p_offset.translated(Vector3(p_linear_limit_upper, -cs, -cs)).origin);
|
|
|
|
r_points.push_back(p_offset.translated(Vector3(p_linear_limit_upper, -cs, cs)).origin);
|
|
|
|
r_points.push_back(p_offset.translated(Vector3(p_linear_limit_upper, -cs, cs)).origin);
|
|
|
|
r_points.push_back(p_offset.translated(Vector3(p_linear_limit_upper, cs, cs)).origin);
|
|
|
|
r_points.push_back(p_offset.translated(Vector3(p_linear_limit_upper, cs, cs)).origin);
|
|
|
|
r_points.push_back(p_offset.translated(Vector3(p_linear_limit_upper, cs, -cs)).origin);
|
|
|
|
r_points.push_back(p_offset.translated(Vector3(p_linear_limit_upper, cs, -cs)).origin);
|
|
|
|
r_points.push_back(p_offset.translated(Vector3(p_linear_limit_upper, -cs, -cs)).origin);
|
|
|
|
|
|
|
|
r_points.push_back(p_offset.translated(Vector3(p_linear_limit_lower, -cs, -cs)).origin);
|
|
|
|
r_points.push_back(p_offset.translated(Vector3(p_linear_limit_lower, -cs, cs)).origin);
|
|
|
|
r_points.push_back(p_offset.translated(Vector3(p_linear_limit_lower, -cs, cs)).origin);
|
|
|
|
r_points.push_back(p_offset.translated(Vector3(p_linear_limit_lower, cs, cs)).origin);
|
|
|
|
r_points.push_back(p_offset.translated(Vector3(p_linear_limit_lower, cs, cs)).origin);
|
|
|
|
r_points.push_back(p_offset.translated(Vector3(p_linear_limit_lower, cs, -cs)).origin);
|
|
|
|
r_points.push_back(p_offset.translated(Vector3(p_linear_limit_lower, cs, -cs)).origin);
|
|
|
|
r_points.push_back(p_offset.translated(Vector3(p_linear_limit_lower, -cs, -cs)).origin);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
r_points.push_back(p_offset.translated(Vector3(+cs * 2, 0, 0)).origin);
|
|
|
|
r_points.push_back(p_offset.translated(Vector3(-cs * 2, 0, 0)).origin);
|
|
|
|
}
|
|
|
|
|
2020-05-14 16:41:43 +02:00
|
|
|
if (r_body_a_points) {
|
2017-12-16 14:05:19 +01:00
|
|
|
JointGizmosDrawer::draw_circle(
|
|
|
|
Vector3::AXIS_X,
|
|
|
|
BODY_A_RADIUS,
|
|
|
|
p_offset,
|
|
|
|
JointGizmosDrawer::look_body_toward(Vector3::AXIS_X, p_trs_joint, p_trs_body_a),
|
|
|
|
p_angular_limit_lower,
|
|
|
|
p_angular_limit_upper,
|
|
|
|
*r_body_a_points);
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2017-12-16 14:05:19 +01:00
|
|
|
|
2020-05-14 16:41:43 +02:00
|
|
|
if (r_body_b_points) {
|
2017-12-16 14:05:19 +01:00
|
|
|
JointGizmosDrawer::draw_circle(
|
|
|
|
Vector3::AXIS_X,
|
|
|
|
BODY_B_RADIUS,
|
|
|
|
p_offset,
|
|
|
|
JointGizmosDrawer::look_body_toward(Vector3::AXIS_X, p_trs_joint, p_trs_body_b),
|
|
|
|
p_angular_limit_lower,
|
|
|
|
p_angular_limit_upper,
|
|
|
|
*r_body_b_points,
|
|
|
|
true);
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2017-12-16 14:05:19 +01:00
|
|
|
}
|
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
void Joint3DGizmoPlugin::CreateConeTwistJointGizmo(const Transform &p_offset, const Transform &p_trs_joint, const Transform &p_trs_body_a, const Transform &p_trs_body_b, real_t p_swing, real_t p_twist, Vector<Vector3> *r_body_a_points, Vector<Vector3> *r_body_b_points) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (r_body_a_points) {
|
2017-12-16 14:05:19 +01:00
|
|
|
JointGizmosDrawer::draw_cone(
|
|
|
|
p_offset,
|
|
|
|
JointGizmosDrawer::look_body(p_trs_joint, p_trs_body_a),
|
|
|
|
p_swing,
|
|
|
|
p_twist,
|
|
|
|
*r_body_a_points);
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2017-12-16 14:05:19 +01:00
|
|
|
|
2020-05-14 16:41:43 +02:00
|
|
|
if (r_body_b_points) {
|
2017-12-16 14:05:19 +01:00
|
|
|
JointGizmosDrawer::draw_cone(
|
|
|
|
p_offset,
|
|
|
|
JointGizmosDrawer::look_body(p_trs_joint, p_trs_body_b),
|
|
|
|
p_swing,
|
|
|
|
p_twist,
|
|
|
|
*r_body_b_points);
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2017-12-16 14:05:19 +01:00
|
|
|
}
|
|
|
|
|
2020-04-06 12:40:52 +02:00
|
|
|
void Joint3DGizmoPlugin::CreateGeneric6DOFJointGizmo(
|
2017-12-16 14:05:19 +01:00
|
|
|
const Transform &p_offset,
|
|
|
|
const Transform &p_trs_joint,
|
|
|
|
const Transform &p_trs_body_a,
|
|
|
|
const Transform &p_trs_body_b,
|
|
|
|
real_t p_angular_limit_lower_x,
|
|
|
|
real_t p_angular_limit_upper_x,
|
|
|
|
real_t p_linear_limit_lower_x,
|
|
|
|
real_t p_linear_limit_upper_x,
|
|
|
|
bool p_enable_angular_limit_x,
|
|
|
|
bool p_enable_linear_limit_x,
|
|
|
|
real_t p_angular_limit_lower_y,
|
|
|
|
real_t p_angular_limit_upper_y,
|
|
|
|
real_t p_linear_limit_lower_y,
|
|
|
|
real_t p_linear_limit_upper_y,
|
|
|
|
bool p_enable_angular_limit_y,
|
|
|
|
bool p_enable_linear_limit_y,
|
|
|
|
real_t p_angular_limit_lower_z,
|
|
|
|
real_t p_angular_limit_upper_z,
|
|
|
|
real_t p_linear_limit_lower_z,
|
|
|
|
real_t p_linear_limit_upper_z,
|
|
|
|
bool p_enable_angular_limit_z,
|
|
|
|
bool p_enable_linear_limit_z,
|
|
|
|
Vector<Vector3> &r_points,
|
|
|
|
Vector<Vector3> *r_body_a_points,
|
|
|
|
Vector<Vector3> *r_body_b_points) {
|
2015-10-08 20:00:40 +02:00
|
|
|
float cs = 0.25;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
for (int ax = 0; ax < 3; ax++) {
|
2018-10-04 18:54:20 +02:00
|
|
|
float ll = 0;
|
|
|
|
float ul = 0;
|
|
|
|
float lll = 0;
|
|
|
|
float lul = 0;
|
|
|
|
|
|
|
|
int a1 = 0;
|
|
|
|
int a2 = 0;
|
|
|
|
int a3 = 0;
|
|
|
|
bool enable_ang = false;
|
|
|
|
bool enable_lin = false;
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
switch (ax) {
|
2015-10-08 20:00:40 +02:00
|
|
|
case 0:
|
2017-12-16 14:05:19 +01:00
|
|
|
ll = p_angular_limit_lower_x;
|
|
|
|
ul = p_angular_limit_upper_x;
|
|
|
|
lll = -p_linear_limit_lower_x;
|
|
|
|
lul = -p_linear_limit_upper_x;
|
|
|
|
enable_ang = p_enable_angular_limit_x;
|
|
|
|
enable_lin = p_enable_linear_limit_x;
|
2017-03-05 16:44:50 +01:00
|
|
|
a1 = 0;
|
|
|
|
a2 = 1;
|
|
|
|
a3 = 2;
|
|
|
|
break;
|
2015-10-08 20:00:40 +02:00
|
|
|
case 1:
|
2017-12-16 14:05:19 +01:00
|
|
|
ll = p_angular_limit_lower_y;
|
|
|
|
ul = p_angular_limit_upper_y;
|
|
|
|
lll = -p_linear_limit_lower_y;
|
|
|
|
lul = -p_linear_limit_upper_y;
|
|
|
|
enable_ang = p_enable_angular_limit_y;
|
|
|
|
enable_lin = p_enable_linear_limit_y;
|
2017-12-09 15:01:00 +01:00
|
|
|
a1 = 1;
|
|
|
|
a2 = 2;
|
|
|
|
a3 = 0;
|
2017-03-05 16:44:50 +01:00
|
|
|
break;
|
2015-10-08 20:00:40 +02:00
|
|
|
case 2:
|
2017-12-16 14:05:19 +01:00
|
|
|
ll = p_angular_limit_lower_z;
|
|
|
|
ul = p_angular_limit_upper_z;
|
|
|
|
lll = -p_linear_limit_lower_z;
|
|
|
|
lul = -p_linear_limit_upper_z;
|
|
|
|
enable_ang = p_enable_angular_limit_z;
|
|
|
|
enable_lin = p_enable_linear_limit_z;
|
2017-12-09 15:01:00 +01:00
|
|
|
a1 = 2;
|
|
|
|
a2 = 0;
|
|
|
|
a3 = 1;
|
2017-03-05 16:44:50 +01:00
|
|
|
break;
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
|
2017-12-16 14:05:19 +01:00
|
|
|
#define ADD_VTX(x, y, z) \
|
|
|
|
{ \
|
|
|
|
Vector3 v; \
|
|
|
|
v[a1] = (x); \
|
|
|
|
v[a2] = (y); \
|
|
|
|
v[a3] = (z); \
|
|
|
|
r_points.push_back(p_offset.translated(v).origin); \
|
2017-03-05 16:44:50 +01:00
|
|
|
}
|
|
|
|
|
2017-12-16 14:05:19 +01:00
|
|
|
if (enable_lin && lll >= lul) {
|
2017-03-05 16:44:50 +01:00
|
|
|
ADD_VTX(lul, 0, 0);
|
|
|
|
ADD_VTX(lll, 0, 0);
|
|
|
|
|
|
|
|
ADD_VTX(lul, -cs, -cs);
|
|
|
|
ADD_VTX(lul, -cs, cs);
|
|
|
|
ADD_VTX(lul, -cs, cs);
|
|
|
|
ADD_VTX(lul, cs, cs);
|
|
|
|
ADD_VTX(lul, cs, cs);
|
|
|
|
ADD_VTX(lul, cs, -cs);
|
|
|
|
ADD_VTX(lul, cs, -cs);
|
|
|
|
ADD_VTX(lul, -cs, -cs);
|
|
|
|
|
|
|
|
ADD_VTX(lll, -cs, -cs);
|
|
|
|
ADD_VTX(lll, -cs, cs);
|
|
|
|
ADD_VTX(lll, -cs, cs);
|
|
|
|
ADD_VTX(lll, cs, cs);
|
|
|
|
ADD_VTX(lll, cs, cs);
|
|
|
|
ADD_VTX(lll, cs, -cs);
|
|
|
|
ADD_VTX(lll, cs, -cs);
|
|
|
|
ADD_VTX(lll, -cs, -cs);
|
2015-10-08 20:00:40 +02:00
|
|
|
|
|
|
|
} else {
|
2017-03-05 16:44:50 +01:00
|
|
|
ADD_VTX(+cs * 2, 0, 0);
|
|
|
|
ADD_VTX(-cs * 2, 0, 0);
|
2015-10-08 20:00:40 +02:00
|
|
|
}
|
|
|
|
|
2017-12-16 14:05:19 +01:00
|
|
|
if (!enable_ang) {
|
|
|
|
ll = 0;
|
|
|
|
ul = -1;
|
|
|
|
}
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2020-05-14 16:41:43 +02:00
|
|
|
if (r_body_a_points) {
|
2017-12-16 14:05:19 +01:00
|
|
|
JointGizmosDrawer::draw_circle(
|
|
|
|
static_cast<Vector3::Axis>(ax),
|
|
|
|
BODY_A_RADIUS,
|
|
|
|
p_offset,
|
|
|
|
JointGizmosDrawer::look_body_toward(static_cast<Vector3::Axis>(ax), p_trs_joint, p_trs_body_a),
|
|
|
|
ll,
|
|
|
|
ul,
|
|
|
|
*r_body_a_points,
|
|
|
|
true);
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2017-12-16 14:05:19 +01:00
|
|
|
|
2020-05-14 16:41:43 +02:00
|
|
|
if (r_body_b_points) {
|
2017-12-16 14:05:19 +01:00
|
|
|
JointGizmosDrawer::draw_circle(
|
|
|
|
static_cast<Vector3::Axis>(ax),
|
|
|
|
BODY_B_RADIUS,
|
|
|
|
p_offset,
|
|
|
|
JointGizmosDrawer::look_body_toward(static_cast<Vector3::Axis>(ax), p_trs_joint, p_trs_body_b),
|
|
|
|
ll,
|
|
|
|
ul,
|
|
|
|
*r_body_b_points);
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2017-12-16 14:05:19 +01:00
|
|
|
}
|
2015-10-08 20:00:40 +02:00
|
|
|
|
2017-12-16 14:05:19 +01:00
|
|
|
#undef ADD_VTX
|
|
|
|
}
|