From 66724e89465f76d652ad3e0c7c170f5511006135 Mon Sep 17 00:00:00 2001 From: Joe Ardent Date: Thu, 13 Jun 2024 14:50:41 -0700 Subject: [PATCH] still not showing the color/textures --- Cargo.lock | 43 ++++++++++++++++++++ Cargo.toml | 1 + src/action/systems.rs | 2 +- src/bike/body.rs | 9 ++--- src/bike/wheels.rs | 42 +------------------ src/lights.rs | 83 ++++++++------------------------------ src/planet.rs | 93 +++++-------------------------------------- 7 files changed, 77 insertions(+), 196 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 023d679..a7d4178 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -834,8 +834,10 @@ dependencies = [ "hexasphere 10.0.0", "image 0.24.9", "js-sys", + "ktx2", "naga", "naga_oil", + "ruzstd", "serde", "thiserror", "thread_local", @@ -1537,6 +1539,17 @@ version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e8566979429cf69b49a5c740c60791108e86440e8be149bbea4fe54d2c32d6e2" +[[package]] +name = "derive_more" +version = "0.99.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fb810d30a7c1953f91334de7244731fc3f3c10d7fe163338a35b9f640960321" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "dispatch" version = "0.2.0" @@ -2404,6 +2417,15 @@ version = "3.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2db585e1d738fc771bf08a151420d3ed193d9d895a36df7f6f8a9456b911ddc" +[[package]] +name = "ktx2" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87d65e08a9ec02e409d27a0139eaa6b9756b4d81fe7cde71f6941a83730ce838" +dependencies = [ + "bitflags 1.3.2", +] + [[package]] name = "lazy_static" version = "1.4.0" @@ -3393,6 +3415,17 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "ruzstd" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "58c4eb8a81997cf040a091d1f7e1938aeab6749d3a0dfa73af43cdc32393483d" +dependencies = [ + "byteorder", + "derive_more", + "twox-hash", +] + [[package]] name = "ryu" version = "1.0.18" @@ -3857,6 +3890,16 @@ version = "0.21.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2c591d83f69777866b9126b24c6dd9a18351f177e49d625920d19f989fd31cf8" +[[package]] +name = "twox-hash" +version = "1.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97fee6b57c6a41524a810daee9286c02d7752c4253064d0b05472833a438f675" +dependencies = [ + "cfg-if", + "static_assertions", +] + [[package]] name = "typeid" version = "1.0.0" diff --git a/Cargo.toml b/Cargo.toml index 9b28b66..6a6baa2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,6 +27,7 @@ features = [ "bevy_text", "bevy_gltf", "bevy_sprite", + "tonemapping_luts" ] [dependencies.bevy_rapier3d] diff --git a/src/action/systems.rs b/src/action/systems.rs index 825d198..134757e 100644 --- a/src/action/systems.rs +++ b/src/action/systems.rs @@ -61,7 +61,7 @@ pub(super) fn gravity( } } - rapier_config.gravity = xform.translation.normalize() * -settings.gravity; + rapier_config.gravity = Vec3::Y * -settings.gravity; forces.force = Vec3::ZERO; forces.torque = Vec3::ZERO; } diff --git a/src/bike/body.rs b/src/bike/body.rs index 98b4229..bbf1b9d 100644 --- a/src/bike/body.rs +++ b/src/bike/body.rs @@ -16,13 +16,12 @@ pub(super) fn spawn_cyberbike( wheel_conf: Res, mut meshterials: Meshterial, ) { - let altitude = PLANET_RADIUS - 10.0; + let altitude = 53.0; - let mut xform = Transform::from_translation(Vec3::X * altitude) - .with_rotation(Quat::from_axis_angle(Vec3::Z, -89.0f32.to_radians())); + let mut xform = Transform::from_translation(Vec3::Y * altitude); - let right = xform.right() * 350.0; - xform.translation += right; + // let right = xform.right() * 350.0; + // xform.translation += right; let damping = Damping { angular_damping: 2.0, diff --git a/src/bike/wheels.rs b/src/bike/wheels.rs index ef15ae3..871a43c 100644 --- a/src/bike/wheels.rs +++ b/src/bike/wheels.rs @@ -131,47 +131,9 @@ pub fn spawn_wheels( // do mesh shit fn gen_tires(conf: &WheelConfig) -> (Mesh, Collider) { let wheel_rad = conf.radius; - let tire_thickness = conf.thickness; - let tire = Tire { - radius: wheel_rad, - ring_radius: tire_thickness, - ..Default::default() - }; - + let tire = Sphere::new(wheel_rad); let mut mesh = Mesh::from(tire); - let tire_verts = mesh - .attribute(Mesh::ATTRIBUTE_POSITION) - .unwrap() - .as_float3() - .unwrap() - .iter() - .map(|v| { - // - let v = Vec3::from_array(*v); - let m = Mat3::from_rotation_z(90.0f32.to_radians()); - let p = m.mul_vec3(v); - p.to_array() - }) - .collect::>(); - mesh.remove_attribute(Mesh::ATTRIBUTE_POSITION); - mesh.insert_attribute(Mesh::ATTRIBUTE_POSITION, tire_verts); - - let mut idxs = Vec::new(); - let indices = mesh.indices().unwrap().iter().collect::>(); - for idx in indices.as_slice().chunks_exact(3) { - idxs.push([idx[0] as u32, idx[1] as u32, idx[2] as u32]); - } - let wheel_collider = Collider::convex_decomposition( - &mesh - .attribute(Mesh::ATTRIBUTE_POSITION) - .unwrap() - .as_float3() - .unwrap() - .iter() - .map(|v| Vec3::from_array(*v)) - .collect::>(), - &idxs, - ); + let wheel_collider = Collider::ball(wheel_rad); (mesh, wheel_collider) } diff --git a/src/lights.rs b/src/lights.rs index b3e14d0..66eabae 100644 --- a/src/lights.rs +++ b/src/lights.rs @@ -2,7 +2,7 @@ use bevy::{pbr::CascadeShadowConfigBuilder, prelude::*}; use crate::planet::PLANET_RADIUS; -pub const LIGHT_RANGE: f32 = 90.0; +pub const LIGHT_RANGE: f32 = 900.0; fn spawn_static_lights( mut commands: Commands, @@ -10,83 +10,32 @@ fn spawn_static_lights( mut materials: ResMut>, ) { let pink_light = PointLight { - intensity: 1_00.0, + //intensity: 1_00.0, range: LIGHT_RANGE, - color: Color::PINK, - radius: 1.0, - shadows_enabled: true, - ..Default::default() - }; - - let blue_light = PointLight { - intensity: 1_000.0, - range: LIGHT_RANGE, - color: Color::BLUE, - radius: 1.0, + color: Color::WHITE, + radius: 10.0, shadows_enabled: true, ..Default::default() }; commands.insert_resource(AmbientLight { color: Color::WHITE, - brightness: 0.2, + brightness: 1.0, }); - let _cascade_shadow_config = CascadeShadowConfigBuilder { - first_cascade_far_bound: 0.3, - maximum_distance: 3.0, - ..default() - } - .build(); + // let _cascade_shadow_config = CascadeShadowConfigBuilder { + // first_cascade_far_bound: 0.3, + // maximum_distance: 3.0, + // ..default() + // } + // .build(); // up light - commands - .spawn(PointLightBundle { - transform: Transform::from_xyz(0.0, PLANET_RADIUS + 30.0, 0.0), - point_light: pink_light, - ..Default::default() - }) - .with_children(|builder| { - builder.spawn(PbrBundle { - mesh: meshes.add( - Mesh::try_from(shape::Icosphere { - radius: 10.0, - subdivisions: 2, - }) - .unwrap(), - ), - material: materials.add(StandardMaterial { - base_color: Color::BLUE, - emissive: Color::PINK, - ..Default::default() - }), - ..Default::default() - }); - }); - // down light - commands - .spawn(PointLightBundle { - transform: Transform::from_xyz(0.0, -PLANET_RADIUS - 30.0, 0.0), - point_light: blue_light, - ..Default::default() - }) - .with_children(|builder| { - builder.spawn(PbrBundle { - mesh: meshes.add( - Mesh::try_from(shape::Icosphere { - radius: 10.0, - subdivisions: 2, - }) - .unwrap(), - ), - material: materials.add(StandardMaterial { - base_color: Color::PINK, - emissive: Color::BLUE, - ..Default::default() - }), - ..Default::default() - }); - }); + commands.spawn(PointLightBundle { + transform: Transform::from_xyz(0.0, 100.0, 0.0), + point_light: pink_light, + ..Default::default() + }); } pub struct CyberSpaceLightsPlugin; diff --git a/src/planet.rs b/src/planet.rs index f2c0186..35c098e 100644 --- a/src/planet.rs +++ b/src/planet.rs @@ -8,7 +8,7 @@ use noise::{HybridMulti, NoiseFn, SuperSimplex}; use rand::{Rng, SeedableRng}; use wgpu::PrimitiveTopology; -pub const PLANET_RADIUS: f32 = 4_000.0; +pub const PLANET_RADIUS: f32 = 2_000.0; pub const PLANET_HUE: f32 = 31.0; pub const PLANET_SATURATION: f32 = 1.0; @@ -21,12 +21,8 @@ fn spawn_planet( mut materials: ResMut>, ) { //let color = Color::rgb(0.74, 0.5334, 0.176); - let isphere = Icosphere { - radius: PLANET_RADIUS, - subdivisions: 88, - }; - let (mesh, shape) = gen_planet(isphere); + let (mesh, shape) = gen_planet(999.9); let pbody = (RigidBody::Fixed, Ccd { enabled: true }); @@ -42,7 +38,10 @@ fn spawn_planet( commands .spawn(PbrBundle { mesh: meshes.add(mesh), - material: materials.add(Color::WHITE), + material: materials.add(StandardMaterial { + base_color: Color::GREEN, + ..Default::default() + }), ..Default::default() }) .insert(pbody) @@ -61,82 +60,10 @@ impl Plugin for CyberPlanetPlugin { // utils //--------------------------------------------------------------------- -fn gen_planet(sphere: Icosphere) -> (Mesh, Collider) { - // straight-up stolen from Bevy's impl of Mesh from Icosphere, so I can do the - // displacement before normals are calculated. - let generated = IcoSphere::new(sphere.subdivisions, |point| { - let inclination = point.y.acos(); - let azimuth = point.z.atan2(point.x); +fn gen_planet(span: f32) -> (Mesh, Collider) { + let mesh = Cuboid::new(span, 50.0, span); - let norm_inclination = inclination / std::f32::consts::PI; - let norm_azimuth = 0.5 - (azimuth / std::f32::consts::TAU); + let collider = Collider::cuboid(span, 50.0, span); - [norm_azimuth, norm_inclination] - }); - - let noise = HybridMulti::::default(); - - let (mut min, mut max) = (f32::MAX, f32::MIN); - - let noisy_points = generated - .raw_points() - .iter() - .map(|&p| { - let disp = (noise.get(p.as_dvec3().into()) * 0.03f64) as f32; - let pt = p + (p.normalize() * disp); - pt.into() - }) - .collect::>(); - - let points = noisy_points - .iter() - .map(|&p| (Vec3::from_slice(&p) * sphere.radius).into()) - .collect::>(); - - for p in &points { - let v = Vec3::new(p[0], p[1], p[2]); - let v = v.length(); - min = v.min(min); - max = v.max(max); - } - - let indices = generated.get_all_indices(); - - let mut idxs = Vec::new(); - for idx in indices.chunks_exact(3) { - idxs.push([idx[0], idx[1], idx[2]]); - } - - let indices = Indices::U32(indices); - let collider = Collider::trimesh(points.iter().map(|p| Vect::from_slice(p)).collect(), idxs); - - let mut mesh = Mesh::new(PrimitiveTopology::TriangleList, RenderAssetUsages::all()); - mesh.insert_indices(indices); - mesh.insert_attribute(Mesh::ATTRIBUTE_POSITION, points); - //mesh.insert_attribute(Mesh::ATTRIBUTE_UV_0, uvs); - mesh.duplicate_vertices(); - mesh.compute_flat_normals(); - - let tri_list = mesh - .attribute(Mesh::ATTRIBUTE_POSITION) - .unwrap() - .as_float3() - .unwrap(); - - let mut rng = rand::rngs::StdRng::seed_from_u64(57); - let mut colors = Vec::new(); - for _triangle in tri_list.chunks_exact(3) { - let l = 0.41; - let jitter = rng.gen_range(-0.0..=360.0f32); - let h = jitter; - let color = Color::hsl(h, PLANET_SATURATION, l).as_linear_rgba_f32(); - for _ in 0..3 { - colors.push(color); - } - } - - dbg!(&colors.len()); - mesh.insert_attribute(Mesh::ATTRIBUTE_COLOR, colors); - - (mesh, collider) + (mesh.mesh(), collider) }