still not showing the color/textures

This commit is contained in:
Joe Ardent 2024-06-13 14:50:41 -07:00
parent 63ed962155
commit 66724e8946
7 changed files with 77 additions and 196 deletions

43
Cargo.lock generated
View file

@ -834,8 +834,10 @@ dependencies = [
"hexasphere 10.0.0", "hexasphere 10.0.0",
"image 0.24.9", "image 0.24.9",
"js-sys", "js-sys",
"ktx2",
"naga", "naga",
"naga_oil", "naga_oil",
"ruzstd",
"serde", "serde",
"thiserror", "thiserror",
"thread_local", "thread_local",
@ -1537,6 +1539,17 @@ version = "2.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e8566979429cf69b49a5c740c60791108e86440e8be149bbea4fe54d2c32d6e2" 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]] [[package]]
name = "dispatch" name = "dispatch"
version = "0.2.0" version = "0.2.0"
@ -2404,6 +2417,15 @@ version = "3.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2db585e1d738fc771bf08a151420d3ed193d9d895a36df7f6f8a9456b911ddc" 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]] [[package]]
name = "lazy_static" name = "lazy_static"
version = "1.4.0" version = "1.4.0"
@ -3393,6 +3415,17 @@ dependencies = [
"windows-sys 0.52.0", "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]] [[package]]
name = "ryu" name = "ryu"
version = "1.0.18" version = "1.0.18"
@ -3857,6 +3890,16 @@ version = "0.21.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2c591d83f69777866b9126b24c6dd9a18351f177e49d625920d19f989fd31cf8" 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]] [[package]]
name = "typeid" name = "typeid"
version = "1.0.0" version = "1.0.0"

View file

@ -27,6 +27,7 @@ features = [
"bevy_text", "bevy_text",
"bevy_gltf", "bevy_gltf",
"bevy_sprite", "bevy_sprite",
"tonemapping_luts"
] ]
[dependencies.bevy_rapier3d] [dependencies.bevy_rapier3d]

View file

@ -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.force = Vec3::ZERO;
forces.torque = Vec3::ZERO; forces.torque = Vec3::ZERO;
} }

View file

@ -16,13 +16,12 @@ pub(super) fn spawn_cyberbike(
wheel_conf: Res<WheelConfig>, wheel_conf: Res<WheelConfig>,
mut meshterials: Meshterial, mut meshterials: Meshterial,
) { ) {
let altitude = PLANET_RADIUS - 10.0; let altitude = 53.0;
let mut xform = Transform::from_translation(Vec3::X * altitude) let mut xform = Transform::from_translation(Vec3::Y * altitude);
.with_rotation(Quat::from_axis_angle(Vec3::Z, -89.0f32.to_radians()));
let right = xform.right() * 350.0; // let right = xform.right() * 350.0;
xform.translation += right; // xform.translation += right;
let damping = Damping { let damping = Damping {
angular_damping: 2.0, angular_damping: 2.0,

View file

@ -131,47 +131,9 @@ pub fn spawn_wheels(
// do mesh shit // do mesh shit
fn gen_tires(conf: &WheelConfig) -> (Mesh, Collider) { fn gen_tires(conf: &WheelConfig) -> (Mesh, Collider) {
let wheel_rad = conf.radius; let wheel_rad = conf.radius;
let tire_thickness = conf.thickness; let tire = Sphere::new(wheel_rad);
let tire = Tire {
radius: wheel_rad,
ring_radius: tire_thickness,
..Default::default()
};
let mut mesh = Mesh::from(tire); let mut mesh = Mesh::from(tire);
let tire_verts = mesh let wheel_collider = Collider::ball(wheel_rad);
.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::<Vec<[f32; 3]>>();
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::<Vec<_>>();
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::<Vec<_>>(),
&idxs,
);
(mesh, wheel_collider) (mesh, wheel_collider)
} }

View file

@ -2,7 +2,7 @@ use bevy::{pbr::CascadeShadowConfigBuilder, prelude::*};
use crate::planet::PLANET_RADIUS; use crate::planet::PLANET_RADIUS;
pub const LIGHT_RANGE: f32 = 90.0; pub const LIGHT_RANGE: f32 = 900.0;
fn spawn_static_lights( fn spawn_static_lights(
mut commands: Commands, mut commands: Commands,
@ -10,83 +10,32 @@ fn spawn_static_lights(
mut materials: ResMut<Assets<StandardMaterial>>, mut materials: ResMut<Assets<StandardMaterial>>,
) { ) {
let pink_light = PointLight { let pink_light = PointLight {
intensity: 1_00.0, //intensity: 1_00.0,
range: LIGHT_RANGE, range: LIGHT_RANGE,
color: Color::PINK, color: Color::WHITE,
radius: 1.0, radius: 10.0,
shadows_enabled: true,
..Default::default()
};
let blue_light = PointLight {
intensity: 1_000.0,
range: LIGHT_RANGE,
color: Color::BLUE,
radius: 1.0,
shadows_enabled: true, shadows_enabled: true,
..Default::default() ..Default::default()
}; };
commands.insert_resource(AmbientLight { commands.insert_resource(AmbientLight {
color: Color::WHITE, color: Color::WHITE,
brightness: 0.2, brightness: 1.0,
}); });
let _cascade_shadow_config = CascadeShadowConfigBuilder { // let _cascade_shadow_config = CascadeShadowConfigBuilder {
first_cascade_far_bound: 0.3, // first_cascade_far_bound: 0.3,
maximum_distance: 3.0, // maximum_distance: 3.0,
..default() // ..default()
} // }
.build(); // .build();
// up light // up light
commands commands.spawn(PointLightBundle {
.spawn(PointLightBundle { transform: Transform::from_xyz(0.0, 100.0, 0.0),
transform: Transform::from_xyz(0.0, PLANET_RADIUS + 30.0, 0.0), point_light: pink_light,
point_light: pink_light, ..Default::default()
..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()
});
});
} }
pub struct CyberSpaceLightsPlugin; pub struct CyberSpaceLightsPlugin;

View file

@ -8,7 +8,7 @@ use noise::{HybridMulti, NoiseFn, SuperSimplex};
use rand::{Rng, SeedableRng}; use rand::{Rng, SeedableRng};
use wgpu::PrimitiveTopology; 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_HUE: f32 = 31.0;
pub const PLANET_SATURATION: f32 = 1.0; pub const PLANET_SATURATION: f32 = 1.0;
@ -21,12 +21,8 @@ fn spawn_planet(
mut materials: ResMut<Assets<StandardMaterial>>, mut materials: ResMut<Assets<StandardMaterial>>,
) { ) {
//let color = Color::rgb(0.74, 0.5334, 0.176); //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 }); let pbody = (RigidBody::Fixed, Ccd { enabled: true });
@ -42,7 +38,10 @@ fn spawn_planet(
commands commands
.spawn(PbrBundle { .spawn(PbrBundle {
mesh: meshes.add(mesh), mesh: meshes.add(mesh),
material: materials.add(Color::WHITE), material: materials.add(StandardMaterial {
base_color: Color::GREEN,
..Default::default()
}),
..Default::default() ..Default::default()
}) })
.insert(pbody) .insert(pbody)
@ -61,82 +60,10 @@ impl Plugin for CyberPlanetPlugin {
// utils // utils
//--------------------------------------------------------------------- //---------------------------------------------------------------------
fn gen_planet(sphere: Icosphere) -> (Mesh, Collider) { fn gen_planet(span: f32) -> (Mesh, Collider) {
// straight-up stolen from Bevy's impl of Mesh from Icosphere, so I can do the let mesh = Cuboid::new(span, 50.0, span);
// displacement before normals are calculated.
let generated = IcoSphere::new(sphere.subdivisions, |point| {
let inclination = point.y.acos();
let azimuth = point.z.atan2(point.x);
let norm_inclination = inclination / std::f32::consts::PI; let collider = Collider::cuboid(span, 50.0, span);
let norm_azimuth = 0.5 - (azimuth / std::f32::consts::TAU);
[norm_azimuth, norm_inclination] (mesh.mesh(), collider)
});
let noise = HybridMulti::<SuperSimplex>::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::<Vec<[f32; 3]>>();
let points = noisy_points
.iter()
.map(|&p| (Vec3::from_slice(&p) * sphere.radius).into())
.collect::<Vec<[f32; 3]>>();
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)
} }