Skip to content

Commit

Permalink
Use selection tangent space to pivot the spawning objects
Browse files Browse the repository at this point in the history
  • Loading branch information
kvark committed Nov 4, 2023
1 parent a92ef95 commit 277893e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
6 changes: 6 additions & 0 deletions blade-render/src/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ pub struct SelectionInfo {
pub std_deviation_history: u32,
pub custom_index: u32,
pub depth: f32,
pub position: mint::Vector3<f32>,
pub normal: mint::Vector3<f32>,
pub tex_coords: mint::Vector2<f32>,
pub base_color_texture: Option<blade_asset::Handle<crate::Texture>>,
pub normal_texture: Option<blade_asset::Handle<crate::Texture>>,
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand Down
26 changes: 21 additions & 5 deletions examples/scene/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -946,17 +949,30 @@ 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 {
generate_tangents: true,
},
);
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(),
});
Expand Down

0 comments on commit 277893e

Please sign in to comment.