Skip to content

Commit

Permalink
Finalized implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
davids91 committed Aug 14, 2024
1 parent cd2eeac commit 1dcfb7c
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 134 deletions.
Binary file removed assets/models/minecraft_arc.vox
Binary file not shown.
Binary file removed assets/models/minecraft_tree.vox
Binary file not shown.
Binary file removed assets/models/minecraft_tree_stem.vox
Binary file not shown.
Binary file removed assets/models/monu1.vox
Binary file not shown.
Binary file removed assets/models/teapot.vox
Binary file not shown.
24 changes: 24 additions & 0 deletions assets/shaders/viewport_render.wgsl
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,30 @@ fn update(
rgb_result = result_with_lights.rgb;
}

/*// +++ DEBUG +++
// Display the xyz axes
let root_hit = cube_intersect_ray(
Cube(vec3(0.,0.,0.), f32(octreeMetaData.octree_size)), ray
);
if root_hit.hit == true {
if root_hit. impact_hit == true {
let axes_length = f32(octreeMetaData.octree_size) / 2.;
let axes_width = f32(octreeMetaData.octree_size) / 50.;
let entry_point = point_in_ray_at_distance(ray, root_hit.impact_distance);
if entry_point.x < axes_length && entry_point.y < axes_width && entry_point.z < axes_width {
rgb_result.r = 1.;
}
if entry_point.x < axes_width && entry_point.y < axes_length && entry_point.z < axes_width {
rgb_result.g = 1.;
}
if entry_point.x < axes_width && entry_point.y < axes_width && entry_point.z < axes_length {
rgb_result.b = 1.;
}
}

}
*/// --- DEBUG ---

textureStore(output_texture, pixel_location, vec4f(rgb_result, 1.));
}

Expand Down
27 changes: 10 additions & 17 deletions examples/minecraft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,11 @@ fn main() {
fn setup(mut commands: Commands, images: ResMut<Assets<Image>>) {
// fill octree with data
let tree;
let tree_path = "example_junk_minecraft_tree"; // instead of test_junk_octree
if false {
//std::path::Path::new(tree_path).exists() {
let tree_path = "example_junk_minecraft";
if std::path::Path::new(tree_path).exists() {
tree = Octree::<Albedo, 16>::load(&tree_path).ok().unwrap();
} else {
tree = match shocovox_rs::octree::Octree::<Albedo, 16>::load_magica_voxel_file(
tree = match shocovox_rs::octree::Octree::<Albedo, 16>::load_vox_file(
"assets/models/minecraft.vox",
) {
Ok(tree_) => tree_,
Expand All @@ -64,14 +63,14 @@ fn setup(mut commands: Commands, images: ResMut<Assets<Image>>) {
let viewing_glass = create_viewing_glass(
&Viewport {
origin: V3c {
x: 6.15997,
y: 5.9686174,
z: 5.3837276,
x: 0.,
y: 0.,
z: 0.,
},
direction: V3c {
x: -0.6286289,
y: -0.5966367,
z: -0.49884903,
x: 0.,
y: 0.,
z: -1.,
},
w_h_fov: V3c::new(10., 10., 3.),
},
Expand Down Expand Up @@ -109,7 +108,7 @@ fn rotate_camera(
let radius = angles_query.single().radius;
viewing_glass.viewport.origin = V3c::new(
radius / 2. + yaw.sin() * radius,
radius / 2. + roll.sin() * radius,
radius + roll.sin() * radius * 2.,
radius / 2. + yaw.cos() * radius,
);
viewing_glass.viewport.direction =
Expand All @@ -132,13 +131,9 @@ fn handle_zoom(
}
};
if keys.pressed(KeyCode::ArrowUp) {
// viewing_glass.viewport.w_h_fov.x *= 1.1;
// viewing_glass.viewport.w_h_fov.y *= 1.1;
angles_query.single_mut().roll = angle_update_fn(angles_query.single().roll, ADDITION);
}
if keys.pressed(KeyCode::ArrowDown) {
// viewing_glass.viewport.w_h_fov.x *= 0.9;
// viewing_glass.viewport.w_h_fov.y *= 0.9;
angles_query.single_mut().roll = angle_update_fn(angles_query.single().roll, -ADDITION);
}
if keys.pressed(KeyCode::ArrowLeft) {
Expand All @@ -151,11 +146,9 @@ fn handle_zoom(
}
if keys.pressed(KeyCode::PageUp) {
angles_query.single_mut().radius *= 0.9;
// println!("viewport: {:?}", viewing_glass.viewport);
}
if keys.pressed(KeyCode::PageDown) {
angles_query.single_mut().radius *= 1.1;
// println!("viewport: {:?}", viewing_glass.viewport);
}
}

Expand Down
Loading

0 comments on commit 1dcfb7c

Please sign in to comment.