diff options
author | Juan Linietsky <reduzio@gmail.com> | 2016-11-19 13:23:37 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2016-11-19 13:23:37 -0300 |
commit | c39d2b3f429639803f4f4fe80eda6935659e9c51 (patch) | |
tree | a6c991d572d7dc0f0a59e9ac729ce52ac0331355 /tools/editor | |
parent | a7078a4be9f4c44a41e5c7e7a633169b53f78d48 (diff) |
working reflection probes!!
Diffstat (limited to 'tools/editor')
-rw-r--r-- | tools/editor/spatial_editor_gizmos.cpp | 167 | ||||
-rw-r--r-- | tools/editor/spatial_editor_gizmos.h | 23 |
2 files changed, 190 insertions, 0 deletions
diff --git a/tools/editor/spatial_editor_gizmos.cpp b/tools/editor/spatial_editor_gizmos.cpp index cdd56bbac5..a4a1aaedf0 100644 --- a/tools/editor/spatial_editor_gizmos.cpp +++ b/tools/editor/spatial_editor_gizmos.cpp @@ -245,6 +245,7 @@ void EditorSpatialGizmo::add_handles(const Vector<Vector3> &p_handles, bool p_bi Array a; a.resize(VS::ARRAY_MAX); a[VS::ARRAY_VERTEX]=p_handles; + print_line("handles?: "+itos(p_handles.size())); DVector<Color> colors; { colors.resize(p_handles.size()); @@ -2238,6 +2239,164 @@ VisibilityNotifierGizmo::VisibilityNotifierGizmo(VisibilityNotifier* p_notifier) //////// +/// + + +String ReflectionProbeGizmo::get_handle_name(int p_idx) const { + + switch(p_idx) { + 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"; + } + + return ""; +} +Variant ReflectionProbeGizmo::get_handle_value(int p_idx) const{ + + return AABB(probe->get_extents(),probe->get_origin_offset()); +} +void ReflectionProbeGizmo::set_handle(int p_idx,Camera *p_camera, const Point2& p_point){ + + Transform gt = probe->get_global_transform(); + //gt.orthonormalize(); + Transform gi = gt.affine_inverse(); + + + if (p_idx<3) { + Vector3 extents = probe->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; + Geometry::get_closest_points_between_segments(Vector3(),axis*16384,sg[0],sg[1],ra,rb); + float d = ra[p_idx]; + if (d<0.001) + d=0.001; + + extents[p_idx]=d; + probe->set_extents(extents); + } else { + + p_idx-=3; + + Vector3 origin = probe->get_origin_offset(); + origin[p_idx]=0; + + 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; + Geometry::get_closest_points_between_segments(origin-axis*16384,origin+axis*16384,sg[0],sg[1],ra,rb); + float d = ra[p_idx]; + d+=0.25; + + origin[p_idx]=d; + probe->set_origin_offset(origin); + + } +} + +void ReflectionProbeGizmo::commit_handle(int p_idx,const Variant& p_restore,bool p_cancel){ + + AABB restore = p_restore; + + if (p_cancel) { + probe->set_extents(restore.pos); + probe->set_origin_offset(restore.size); + return; + } + + UndoRedo *ur = SpatialEditor::get_singleton()->get_undo_redo(); + 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.pos); + ur->add_undo_method(probe,"set_origin_offset",restore.size); + ur->commit_action(); + +} + +void ReflectionProbeGizmo::redraw(){ + + clear(); + + Vector<Vector3> lines; + Vector<Vector3> internal_lines; + Vector3 extents = probe->get_extents(); + + AABB aabb; + aabb.pos=-extents; + aabb.size=extents*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); + } + + 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); + + + } + + Vector<Vector3> handles; + + + for(int i=0;i<3;i++) { + + Vector3 ax; + ax[i]=aabb.pos[i]+aabb.size[i]; + handles.push_back(ax); + } + + 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); + + orig_handle[i]+=0.5; + lines.push_back(orig_handle); + } + + add_lines(lines,SpatialEditorGizmos::singleton->reflection_probe_material); + add_lines(internal_lines,SpatialEditorGizmos::singleton->reflection_probe_material_internal); + //add_unscaled_billboard(SpatialEditorGizmos::singleton->visi,0.05); + add_collision_segments(lines); + add_handles(handles); + +} +ReflectionProbeGizmo::ReflectionProbeGizmo(ReflectionProbe* p_probe){ + + probe=p_probe; + set_spatial_node(p_probe); +} + +//////// + + + void NavigationMeshSpatialGizmo::redraw() { @@ -2929,6 +3088,12 @@ Ref<SpatialEditorGizmo> SpatialEditorGizmos::get_gizmo(Spatial *p_spatial) { return misg; } + if (p_spatial->cast_to<ReflectionProbe>()) { + + Ref<ReflectionProbeGizmo> misg = memnew( ReflectionProbeGizmo(p_spatial->cast_to<ReflectionProbe>()) ); + return misg; + } + if (p_spatial->cast_to<VehicleWheel>()) { Ref<VehicleWheelSpatialGizmo> misg = memnew( VehicleWheelSpatialGizmo(p_spatial->cast_to<VehicleWheel>()) ); @@ -3132,6 +3297,8 @@ SpatialEditorGizmos::SpatialEditorGizmos() { raycast_material = create_line_material(Color(1.0,0.8,0.6)); car_wheel_material = create_line_material(Color(0.6,0.8,1.0)); visibility_notifier_material = create_line_material(Color(1.0,0.5,1.0)); + reflection_probe_material = create_line_material(Color(0.5,1.0,0.7)); + reflection_probe_material_internal = create_line_material(Color(0.3,0.8,0.5,0.4)); joint_material = create_line_material(Color(0.6,0.8,1.0)); stream_player_icon = Ref<FixedSpatialMaterial>( memnew( FixedSpatialMaterial )); diff --git a/tools/editor/spatial_editor_gizmos.h b/tools/editor/spatial_editor_gizmos.h index 2c0033cdca..2cc1a7eab8 100644 --- a/tools/editor/spatial_editor_gizmos.h +++ b/tools/editor/spatial_editor_gizmos.h @@ -45,6 +45,7 @@ #include "scene/3d/portal.h" #include "scene/3d/ray_cast.h" #include "scene/3d/navigation_mesh.h" +#include "scene/3d/reflection_probe.h" #include "scene/3d/vehicle_body.h" #include "scene/3d/collision_polygon.h" @@ -307,6 +308,25 @@ public: }; +class ReflectionProbeGizmo : public EditorSpatialGizmo { + + OBJ_TYPE(ReflectionProbeGizmo ,EditorSpatialGizmo); + + + ReflectionProbe* probe; + +public: + + virtual String get_handle_name(int p_idx) const; + virtual Variant get_handle_value(int p_idx) const; + virtual void set_handle(int p_idx,Camera *p_camera, const Point2& p_point); + virtual void commit_handle(int p_idx,const Variant& p_restore,bool p_cancel=false); + + void redraw(); + ReflectionProbeGizmo(ReflectionProbe* p_notifier=NULL); + +}; + class CollisionShapeSpatialGizmo : public EditorSpatialGizmo { @@ -339,6 +359,7 @@ public: }; + class RayCastSpatialGizmo : public EditorSpatialGizmo { OBJ_TYPE(RayCastSpatialGizmo,EditorSpatialGizmo); @@ -473,6 +494,8 @@ public: Ref<FixedSpatialMaterial> light_material_directional_icon; Ref<FixedSpatialMaterial> camera_material; Ref<FixedSpatialMaterial> skeleton_material; + Ref<FixedSpatialMaterial> reflection_probe_material; + Ref<FixedSpatialMaterial> reflection_probe_material_internal; Ref<FixedSpatialMaterial> room_material; Ref<FixedSpatialMaterial> portal_material; Ref<FixedSpatialMaterial> raycast_material; |