Skip to content

Commit

Permalink
fixed prefab instantiation preview for 2d
Browse files Browse the repository at this point in the history
  • Loading branch information
mrDIMAS committed Oct 6, 2022
1 parent bec4b76 commit 1ca98b2
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions editor/src/scene_viewer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -659,17 +659,26 @@ impl SceneViewer {
.local_transform_mut()
.set_position(result.position);
} else {
// In case of empty space, check intersection with oXZ plane.
let plane = Plane::from_normal_and_point(
&Vector3::new(0.0, 1.0, 0.0),
&Default::default(),
)
.unwrap_or_default();

// In case of empty space, check intersection with oXZ plane (3D) or oXY (2D).
if let Some(camera) = graph
[editor_scene.camera_controller.camera]
.cast::<Camera>()
{
let normal = match camera.projection() {
Projection::Perspective(_) => {
Vector3::new(0.0, 1.0, 0.0)
}
Projection::Orthographic(_) => {
Vector3::new(0.0, 0.0, 1.0)
}
};

let plane = Plane::from_normal_and_point(
&normal,
&Default::default(),
)
.unwrap_or_default();

let ray = camera.make_ray(rel_pos, frame_size);

if let Some(point) = ray.plane_intersection_point(&plane) {
Expand Down

0 comments on commit 1ca98b2

Please sign in to comment.