summaryrefslogtreecommitdiff
path: root/editor/spatial_editor_gizmos.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'editor/spatial_editor_gizmos.cpp')
-rw-r--r--editor/spatial_editor_gizmos.cpp151
1 files changed, 129 insertions, 22 deletions
diff --git a/editor/spatial_editor_gizmos.cpp b/editor/spatial_editor_gizmos.cpp
index 0a8e7ea779..f540b386aa 100644
--- a/editor/spatial_editor_gizmos.cpp
+++ b/editor/spatial_editor_gizmos.cpp
@@ -324,7 +324,6 @@ void EditorSpatialGizmo::add_handles(const Vector<Vector3> &p_handles, const Ref
ERR_FAIL_COND(!spatial_node);
- ERR_FAIL_COND(!spatial_node);
Instance ins;
Ref<ArrayMesh> mesh = memnew(ArrayMesh);
@@ -805,6 +804,10 @@ String LightSpatialGizmoPlugin::get_name() const {
return "Lights";
}
+int LightSpatialGizmoPlugin::get_priority() const {
+ return -1;
+}
+
String LightSpatialGizmoPlugin::get_handle_name(const EditorSpatialGizmo *p_gizmo, int p_idx) const {
if (p_idx == 0)
@@ -1062,6 +1065,10 @@ String AudioStreamPlayer3DSpatialGizmoPlugin::get_name() const {
return "AudioStreamPlayer3D";
}
+int AudioStreamPlayer3DSpatialGizmoPlugin::get_priority() const {
+ return -1;
+}
+
String AudioStreamPlayer3DSpatialGizmoPlugin::get_handle_name(const EditorSpatialGizmo *p_gizmo, int p_idx) const {
return "Emission Radius";
@@ -1202,6 +1209,10 @@ String CameraSpatialGizmoPlugin::get_name() const {
return "Camera";
}
+int CameraSpatialGizmoPlugin::get_priority() const {
+ return -1;
+}
+
String CameraSpatialGizmoPlugin::get_handle_name(const EditorSpatialGizmo *p_gizmo, int p_idx) const {
Camera *camera = Object::cast_to<Camera>(p_gizmo->get_spatial_node());
@@ -1298,6 +1309,28 @@ void CameraSpatialGizmoPlugin::redraw(EditorSpatialGizmo *p_gizmo) {
Ref<Material> material = get_material("camera_material", p_gizmo);
Ref<Material> icon = get_material("camera_icon", p_gizmo);
+#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); \
+ }
+
switch (camera->get_projection()) {
case Camera::PROJECTION_PERSPECTIVE: {
@@ -1310,16 +1343,6 @@ void CameraSpatialGizmoPlugin::redraw(EditorSpatialGizmo *p_gizmo) {
nside.x = -nside.x;
Vector3 up = Vector3(0, side.x, 0);
-#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); \
- }
-
ADD_TRIANGLE(Vector3(), side + up, side - up);
ADD_TRIANGLE(Vector3(), nside + up, nside - up);
ADD_TRIANGLE(Vector3(), side + up, nside + up);
@@ -1334,17 +1357,6 @@ void CameraSpatialGizmoPlugin::redraw(EditorSpatialGizmo *p_gizmo) {
} break;
case Camera::PROJECTION_ORTHOGONAL: {
-#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); \
- }
float size = camera->get_size();
float hsize = size * 0.5;
@@ -1357,6 +1369,7 @@ void CameraSpatialGizmoPlugin::redraw(EditorSpatialGizmo *p_gizmo) {
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);
+
handles.push_back(right + back);
right.x *= 0.25;
@@ -1364,8 +1377,30 @@ void CameraSpatialGizmoPlugin::redraw(EditorSpatialGizmo *p_gizmo) {
ADD_TRIANGLE(tup, right + up + back, -right + up + back);
} break;
+ case Camera::PROJECTION_FRUSTUM: {
+ 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);
+ }
}
+#undef ADD_TRIANGLE
+#undef ADD_QUAD
+
p_gizmo->add_lines(lines, material);
p_gizmo->add_unscaled_billboard(icon, 0.05);
p_gizmo->add_handles(handles, get_material("handles"));
@@ -1425,6 +1460,10 @@ String MeshInstanceSpatialGizmoPlugin::get_name() const {
return "MeshInstance";
}
+int MeshInstanceSpatialGizmoPlugin::get_priority() const {
+ return -1;
+}
+
bool MeshInstanceSpatialGizmoPlugin::can_be_hidden() const {
return false;
}
@@ -1458,6 +1497,10 @@ String Sprite3DSpatialGizmoPlugin::get_name() const {
return "Sprite3D";
}
+int Sprite3DSpatialGizmoPlugin::get_priority() const {
+ return -1;
+}
+
bool Sprite3DSpatialGizmoPlugin::can_be_hidden() const {
return false;
}
@@ -1517,6 +1560,10 @@ String Position3DSpatialGizmoPlugin::get_name() const {
return "Position3D";
}
+int Position3DSpatialGizmoPlugin::get_priority() const {
+ return -1;
+}
+
void Position3DSpatialGizmoPlugin::redraw(EditorSpatialGizmo *p_gizmo) {
p_gizmo->clear();
@@ -1540,6 +1587,10 @@ String SkeletonSpatialGizmoPlugin::get_name() const {
return "Skeleton";
}
+int SkeletonSpatialGizmoPlugin::get_priority() const {
+ return -1;
+}
+
void SkeletonSpatialGizmoPlugin::redraw(EditorSpatialGizmo *p_gizmo) {
Skeleton *skel = Object::cast_to<Skeleton>(p_gizmo->get_spatial_node());
@@ -1743,6 +1794,10 @@ String PhysicalBoneSpatialGizmoPlugin::get_name() const {
return "PhysicalBones";
}
+int PhysicalBoneSpatialGizmoPlugin::get_priority() const {
+ return -1;
+}
+
void PhysicalBoneSpatialGizmoPlugin::redraw(EditorSpatialGizmo *p_gizmo) {
p_gizmo->clear();
@@ -1982,6 +2037,10 @@ String RayCastSpatialGizmoPlugin::get_name() const {
return "RayCast";
}
+int RayCastSpatialGizmoPlugin::get_priority() const {
+ return -1;
+}
+
void RayCastSpatialGizmoPlugin::redraw(EditorSpatialGizmo *p_gizmo) {
RayCast *raycast = Object::cast_to<RayCast>(p_gizmo->get_spatial_node());
@@ -2031,6 +2090,10 @@ String SpringArmSpatialGizmoPlugin::get_name() const {
return "SpringArm";
}
+int SpringArmSpatialGizmoPlugin::get_priority() const {
+ return -1;
+}
+
/////
VehicleWheelSpatialGizmoPlugin::VehicleWheelSpatialGizmoPlugin() {
@@ -2047,6 +2110,10 @@ String VehicleWheelSpatialGizmoPlugin::get_name() const {
return "VehicleWheel";
}
+int VehicleWheelSpatialGizmoPlugin::get_priority() const {
+ return -1;
+}
+
void VehicleWheelSpatialGizmoPlugin::redraw(EditorSpatialGizmo *p_gizmo) {
VehicleWheel *car_wheel = Object::cast_to<VehicleWheel>(p_gizmo->get_spatial_node());
@@ -2117,6 +2184,10 @@ String SoftBodySpatialGizmoPlugin::get_name() const {
return "SoftBody";
}
+int SoftBodySpatialGizmoPlugin::get_priority() const {
+ return -1;
+}
+
bool SoftBodySpatialGizmoPlugin::is_selectable_when_hidden() const {
return true;
}
@@ -2189,6 +2260,10 @@ String VisibilityNotifierGizmoPlugin::get_name() const {
return "VisibilityNotifier";
}
+int VisibilityNotifierGizmoPlugin::get_priority() const {
+ return -1;
+}
+
String VisibilityNotifierGizmoPlugin::get_handle_name(const EditorSpatialGizmo *p_gizmo, int p_idx) const {
switch (p_idx) {
@@ -2339,6 +2414,10 @@ String ParticlesGizmoPlugin::get_name() const {
return "Particles";
}
+int ParticlesGizmoPlugin::get_priority() const {
+ return -1;
+}
+
bool ParticlesGizmoPlugin::is_selectable_when_hidden() const {
return true;
}
@@ -2498,6 +2577,10 @@ String ReflectionProbeGizmoPlugin::get_name() const {
return "ReflectionProbe";
}
+int ReflectionProbeGizmoPlugin::get_priority() const {
+ return -1;
+}
+
String ReflectionProbeGizmoPlugin::get_handle_name(const EditorSpatialGizmo *p_gizmo, int p_idx) const {
switch (p_idx) {
@@ -2674,6 +2757,10 @@ String GIProbeGizmoPlugin::get_name() const {
return "GIProbe";
}
+int GIProbeGizmoPlugin::get_priority() const {
+ return -1;
+}
+
String GIProbeGizmoPlugin::get_handle_name(const EditorSpatialGizmo *p_gizmo, int p_idx) const {
switch (p_idx) {
@@ -2908,6 +2995,10 @@ String BakedIndirectLightGizmoPlugin::get_name() const {
return "BakedLightmap";
}
+int BakedIndirectLightGizmoPlugin::get_priority() const {
+ return -1;
+}
+
void BakedIndirectLightGizmoPlugin::redraw(EditorSpatialGizmo *p_gizmo) {
BakedLightmap *baker = Object::cast_to<BakedLightmap>(p_gizmo->get_spatial_node());
@@ -2965,6 +3056,10 @@ String CollisionShapeSpatialGizmoPlugin::get_name() const {
return "CollisionShape";
}
+int CollisionShapeSpatialGizmoPlugin::get_priority() const {
+ return -1;
+}
+
String CollisionShapeSpatialGizmoPlugin::get_handle_name(const EditorSpatialGizmo *p_gizmo, int p_idx) const {
const CollisionShape *cs = Object::cast_to<CollisionShape>(p_gizmo->get_spatial_node());
@@ -3557,6 +3652,10 @@ String CollisionPolygonSpatialGizmoPlugin::get_name() const {
return "CollisionPolygon";
}
+int CollisionPolygonSpatialGizmoPlugin::get_priority() const {
+ return -1;
+}
+
void CollisionPolygonSpatialGizmoPlugin::redraw(EditorSpatialGizmo *p_gizmo) {
CollisionPolygon *polygon = Object::cast_to<CollisionPolygon>(p_gizmo->get_spatial_node());
@@ -3601,6 +3700,10 @@ String NavigationMeshSpatialGizmoPlugin::get_name() const {
return "NavigationMeshInstance";
}
+int NavigationMeshSpatialGizmoPlugin::get_priority() const {
+ return -1;
+}
+
void NavigationMeshSpatialGizmoPlugin::redraw(EditorSpatialGizmo *p_gizmo) {
NavigationMeshInstance *navmesh = Object::cast_to<NavigationMeshInstance>(p_gizmo->get_spatial_node());
@@ -3961,6 +4064,10 @@ String JointSpatialGizmoPlugin::get_name() const {
return "Joints";
}
+int JointSpatialGizmoPlugin::get_priority() const {
+ return -1;
+}
+
void JointSpatialGizmoPlugin::redraw(EditorSpatialGizmo *p_gizmo) {
Joint *joint = Object::cast_to<Joint>(p_gizmo->get_spatial_node());