diff --git a/blade-render/src/render/mod.rs b/blade-render/src/render/mod.rs index ce138b59..e68664a5 100644 --- a/blade-render/src/render/mod.rs +++ b/blade-render/src/render/mod.rs @@ -108,6 +108,8 @@ pub struct SelectionInfo { pub std_deviation_history: u32, pub custom_index: u32, pub depth: f32, + pub position: mint::Vector3, + pub normal: mint::Vector3, pub tex_coords: mint::Vector2, pub base_color_texture: Option>, pub normal_texture: Option>, @@ -119,6 +121,8 @@ impl Default for SelectionInfo { std_deviation_history: 0, custom_index: 0, depth: 0.0, + position: [0.0; 3].into(), + normal: [0.0; 3].into(), tex_coords: [0.0; 2].into(), base_color_texture: None, normal_texture: None, @@ -1563,6 +1567,8 @@ impl Renderer { std_deviation_history: db_v.count, custom_index: db_e.custom_index, depth: db_e.depth, + position: db_e.position.into(), + normal: db_e.normal.into(), tex_coords: db_e.tex_coords.into(), base_color_texture: self .texture_resource_lookup diff --git a/examples/scene/main.rs b/examples/scene/main.rs index 6735038f..e6d63552 100644 --- a/examples/scene/main.rs +++ b/examples/scene/main.rs @@ -246,7 +246,10 @@ impl Example { depth: 0.0, }, fly_speed: 0.0, - debug: blade_render::DebugConfig::default(), + debug: blade_render::DebugConfig { + draw_flags: blade_render::DebugDrawFlags::SPACE, + ..Default::default() + }, track_hot_reloads: false, need_accumulation_reset: true, is_debug_drawing: false, @@ -946,6 +949,22 @@ impl Example { if self.scene_load_task.is_some() { return false; } + + let transform = if self.debug.mouse_pos.is_some() { + let selection = self.renderer.read_debug_selection_info(); + //Note: assuming the object is Y-up + let rotation = glam::Quat::from_rotation_arc(glam::Vec3::Y, selection.normal.into()); + let m = glam::Mat4::from_rotation_translation(rotation, selection.position.into()) + .transpose(); + gpu::Transform { + x: m.x_axis.into(), + y: m.y_axis.into(), + z: m.z_axis.into(), + } + } else { + gpu::IDENTITY_TRANSFORM + }; + let (model, model_task) = self.asset_hub.models.load( file_path, blade_render::model::Meta { @@ -953,10 +972,7 @@ impl Example { }, ); self.scene_load_task = Some(model_task.clone()); - self.objects.push(blade_render::Object { - transform: gpu::IDENTITY_TRANSFORM, - model, - }); + self.objects.push(blade_render::Object { transform, model }); self.object_extras.push(ObjectExtra { path: file_path.to_owned(), });