Skip to content

Commit

Permalink
Update three-d-asset (#510)
Browse files Browse the repository at this point in the history
* Update three-d-asset

* Support advanced mip map settings

* Improve texture example with texture settings

* Update three-d-asset to 0.8

* Fix texture example on web

* Fix texture example on web
  • Loading branch information
asny authored Nov 20, 2024
1 parent f23beec commit 69e2997
Show file tree
Hide file tree
Showing 65 changed files with 290 additions and 173 deletions.
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ text = ["swash", "lyon"] # Text mesh generation features
[dependencies]
glow = "0.14"
cgmath = "0.18"
three-d-asset = {version = "0.7"}
three-d-asset = "0.8"
thiserror = "2"
open-enum = "0.5"
winit = {version = "0.28", optional = true}
Expand All @@ -51,7 +51,7 @@ instant = "0.1.11"

[dev-dependencies]
rand = "0.7"
three-d-asset = {version = "0.7", features = ["hdr", "gltf", "obj", "vol", "pcd", "png", "jpeg", "http", "data-url"] }
three-d-asset = {version = "0.8", features = ["hdr", "gltf", "obj", "vol", "pcd", "png", "jpeg", "http", "data-url"] }
noise = {version = "0.6", default-features = false}
winit = "0.28"

Expand Down Expand Up @@ -118,6 +118,7 @@ path = "examples/sprites/src/main.rs"
[[example]]
name = "texture"
path = "examples/texture/src/main.rs"
required-features = ["egui-gui"]

[[example]]
name = "volume"
Expand Down
2 changes: 1 addition & 1 deletion examples/animation/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ crate-type = ["cdylib"]

[dependencies]
three-d = { path = "../../" }
three-d-asset = {version = "0.7", features = ["gltf", "png", "jpeg", "http", "data-url"] }
three-d-asset = {version = "0.8", features = ["gltf", "png", "jpeg", "http", "data-url"] }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
Expand Down
6 changes: 3 additions & 3 deletions examples/animation/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub async fn run() {
0.1,
1000.0,
);
let mut control = OrbitControl::new(*camera.target(), 1.0, 1000.0);
let mut control = OrbitControl::new(camera.target(), 1.0, 1000.0);

// Source: https://github.com/KhronosGroup/glTF-Sample-Models/tree/master/2.0
let mut loaded = if let Ok(loaded) =
Expand All @@ -47,8 +47,8 @@ pub async fn run() {
.for_each(|part| part.compute_normals());
let mut model = Model::<PhysicalMaterial>::new(&context, &cpu_model).unwrap();

let light0 = DirectionalLight::new(&context, 1.0, Srgba::WHITE, &vec3(0.0, -0.5, -0.5));
let light1 = DirectionalLight::new(&context, 1.0, Srgba::WHITE, &vec3(0.0, 0.5, 0.5));
let light0 = DirectionalLight::new(&context, 1.0, Srgba::WHITE, vec3(0.0, -0.5, -0.5));
let light1 = DirectionalLight::new(&context, 1.0, Srgba::WHITE, vec3(0.0, 0.5, 0.5));

// main loop
window.render_loop(move |mut frame_input| {
Expand Down
Binary file added examples/assets/checkerboard.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion examples/environment/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ crate-type = ["cdylib"]

[dependencies]
three-d = { path = "../../", features=["egui-gui"] }
three-d-asset = {version = "0.7",features = ["hdr", "http"] }
three-d-asset = {version = "0.8",features = ["hdr", "http"] }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
Expand Down
2 changes: 1 addition & 1 deletion examples/environment/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub async fn run() {
0.1,
1000.0,
);
let mut control = OrbitControl::new(*camera.target(), 1.0, 100.0);
let mut control = OrbitControl::new(camera.target(), 1.0, 100.0);

// Source: https://polyhaven.com/
let mut loaded = if let Ok(loaded) =
Expand Down
2 changes: 1 addition & 1 deletion examples/fireworks/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ pub fn run() {
Srgba::new_opaque(40, 178, 222),
];
let mut square = CpuMesh::square();
square.transform(&Mat4::from_scale(0.6)).unwrap();
square.transform(Mat4::from_scale(0.6)).unwrap();

// A particle system is created with an acceleration of -9.82 in the y direction to simulate gravity.
let particles = ParticleSystem::new(
Expand Down
2 changes: 1 addition & 1 deletion examples/fog/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ crate-type = ["cdylib"]

[dependencies]
three-d = { path = "../../" }
three-d-asset = {version = "0.7",features = ["obj", "http"] }
three-d-asset = {version = "0.8",features = ["obj", "http"] }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
Expand Down
2 changes: 1 addition & 1 deletion examples/fog/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub async fn run() {
.for_each(|m| m.material.render_states.cull = Cull::Back);

let ambient = AmbientLight::new(&context, 0.4, Srgba::WHITE);
let directional = DirectionalLight::new(&context, 2.0, Srgba::WHITE, &vec3(-1.0, -1.0, -1.0));
let directional = DirectionalLight::new(&context, 2.0, Srgba::WHITE, vec3(-1.0, -1.0, -1.0));

// Fog
let mut fog_effect = FogEffect {
Expand Down
2 changes: 1 addition & 1 deletion examples/forest/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ crate-type = ["cdylib"]

[dependencies]
three-d = { path = "../../" }
three-d-asset = {version = "0.7",features = ["obj", "jpeg", "http"] }
three-d-asset = {version = "0.8",features = ["obj", "jpeg", "http"] }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
Expand Down
4 changes: 2 additions & 2 deletions examples/forest/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ pub async fn run() {

// Lights
let ambient = AmbientLight::new(&context, 0.3, Srgba::WHITE);
let directional = DirectionalLight::new(&context, 4.0, Srgba::WHITE, &vec3(-1.0, -1.0, -1.0));
let directional = DirectionalLight::new(&context, 4.0, Srgba::WHITE, vec3(-1.0, -1.0, -1.0));

// Imposters
let mut aabb = AxisAlignedBoundingBox::EMPTY;
model.iter().for_each(|m| {
aabb.expand_with_aabb(&m.aabb());
aabb.expand_with_aabb(m.aabb());
});
let size = aabb.size();
let t = 100;
Expand Down
2 changes: 1 addition & 1 deletion examples/headless/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ crate-type = ["cdylib"]

[dependencies]
three-d = { path = "../../", features=["headless"] }
three-d-asset = {version = "0.7", features=["png"]}
three-d-asset = {version = "0.8", features=["png"]}

[target.'cfg(target_arch = "wasm32")'.dependencies]
log = "0.4"
Expand Down
2 changes: 1 addition & 1 deletion examples/image/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ crate-type = ["cdylib"]

[dependencies]
three-d = { path = "../../", features=["egui-gui"] }
three-d-asset = {version = "0.7",features = ["hdr", "http"] }
three-d-asset = {version = "0.8",features = ["hdr", "http"] }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
Expand Down
4 changes: 2 additions & 2 deletions examples/instanced_draw_order/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub fn main() {

let mut thin_cube = CpuMesh::cube();
thin_cube
.transform(&Mat4::from_nonuniform_scale(1.0, 1.0, 0.04))
.transform(Mat4::from_nonuniform_scale(1.0, 1.0, 0.04))
.unwrap();

let transparent_models = Gm::new(
Expand Down Expand Up @@ -116,7 +116,7 @@ pub fn main() {
);
opaque_model.set_transformation(Mat4::from_translation(vec3(0.0, -0.4, -3.0)));

let light0 = DirectionalLight::new(&context, 1.0, Srgba::WHITE, &vec3(0.0, -0.5, -0.5));
let light0 = DirectionalLight::new(&context, 1.0, Srgba::WHITE, vec3(0.0, -0.5, -0.5));
let ambient_light = three_d::renderer::light::AmbientLight::new(&context, 0.8, Srgba::WHITE);

window.render_loop(move |mut frame_input| {
Expand Down
4 changes: 2 additions & 2 deletions examples/instanced_shapes/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ pub fn main() {
);
let mut control = OrbitControl::new(vec3(0.0, 0.0, 0.0), 1.0, 1000.0);

let light0 = DirectionalLight::new(&context, 1.0, Srgba::WHITE, &vec3(0.0, -0.5, -0.5));
let light1 = DirectionalLight::new(&context, 1.0, Srgba::WHITE, &vec3(0.0, 0.5, 0.5));
let light0 = DirectionalLight::new(&context, 1.0, Srgba::WHITE, vec3(0.0, -0.5, -0.5));
let light1 = DirectionalLight::new(&context, 1.0, Srgba::WHITE, vec3(0.0, 0.5, 0.5));

// Container for non instanced meshes.
let mut non_instanced_meshes = Vec::new();
Expand Down
2 changes: 1 addition & 1 deletion examples/lighting/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ crate-type = ["cdylib"]

[dependencies]
three-d = { path = "../../", features=["egui-gui"] }
three-d-asset = {version = "0.7",features = ["gltf", "jpeg", "http"] }
three-d-asset = {version = "0.8",features = ["gltf", "jpeg", "http"] }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
Expand Down
19 changes: 9 additions & 10 deletions examples/lighting/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub async fn run() {
0.1,
30.0,
);
let mut control = OrbitControl::new(*camera.target(), 1.0, 100.0);
let mut control = OrbitControl::new(camera.target(), 1.0, 100.0);
let mut gui = three_d::GUI::new(&context);

// Source: https://github.com/KhronosGroup/glTF-Sample-Models/tree/master/2.0
Expand All @@ -60,9 +60,9 @@ pub async fn run() {
let mut cpu_plane = CpuMesh::square();
cpu_plane
.transform(
&(Mat4::from_translation(vec3(0.0, -1.0, 0.0))
Mat4::from_translation(vec3(0.0, -1.0, 0.0))
* Mat4::from_scale(10.0)
* Mat4::from_angle_x(degrees(-90.0))),
* Mat4::from_angle_x(degrees(-90.0)),
)
.unwrap();
let mut plane = Gm::new(
Expand All @@ -81,15 +81,14 @@ pub async fn run() {
);

let mut ambient = AmbientLight::new(&context, 0.2, Srgba::WHITE);
let mut directional0 = DirectionalLight::new(&context, 1.0, Srgba::RED, &vec3(0.0, -1.0, 0.0));
let mut directional1 =
DirectionalLight::new(&context, 1.0, Srgba::GREEN, &vec3(0.0, -1.0, 0.0));
let mut directional0 = DirectionalLight::new(&context, 1.0, Srgba::RED, vec3(0.0, -1.0, 0.0));
let mut directional1 = DirectionalLight::new(&context, 1.0, Srgba::GREEN, vec3(0.0, -1.0, 0.0));
let mut spot0 = SpotLight::new(
&context,
2.0,
Srgba::BLUE,
&vec3(0.0, 0.0, 0.0),
&vec3(0.0, -1.0, 0.0),
vec3(0.0, 0.0, 0.0),
vec3(0.0, -1.0, 0.0),
degrees(25.0),
Attenuation {
constant: 0.1,
Expand All @@ -101,7 +100,7 @@ pub async fn run() {
&context,
1.0,
Srgba::GREEN,
&vec3(0.0, 0.0, 0.0),
vec3(0.0, 0.0, 0.0),
Attenuation {
constant: 0.5,
linear: 0.05,
Expand All @@ -112,7 +111,7 @@ pub async fn run() {
&context,
1.0,
Srgba::RED,
&vec3(0.0, 0.0, 0.0),
vec3(0.0, 0.0, 0.0),
Attenuation {
constant: 0.5,
linear: 0.05,
Expand Down
2 changes: 1 addition & 1 deletion examples/lights/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ crate-type = ["cdylib"]

[dependencies]
three-d = { path = "../../", features=["egui-gui"] }
three-d-asset = {version = "0.7",features = ["gltf", "png", "jpeg", "http"] }
three-d-asset = {version = "0.8",features = ["gltf", "png", "jpeg", "http"] }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
rand = "0.7"
Expand Down
4 changes: 2 additions & 2 deletions examples/lights/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub async fn run() {

let mut aabb = AxisAlignedBoundingBox::EMPTY;
for m in model.iter() {
aabb.expand_with_aabb(&m.aabb());
aabb.expand_with_aabb(m.aabb());
}

let size = aabb.size();
Expand Down Expand Up @@ -154,7 +154,7 @@ impl Glow {
);
Self {
aabb,
light: PointLight::new(&context, 1.0, Srgba::WHITE, &pos, Attenuation::default()),
light: PointLight::new(&context, 1.0, Srgba::WHITE, pos, Attenuation::default()),
velocity: vec3(
rng.gen::<f32>() * 2.0 - 1.0,
rng.gen::<f32>() * 2.0 - 1.0,
Expand Down
2 changes: 1 addition & 1 deletion examples/logo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ crate-type = ["cdylib"]

[dependencies]
three-d = { path = "../../" }
three-d-asset = {version = "0.7",features = ["png", "http"] }
three-d-asset = {version = "0.8",features = ["png", "http"] }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
Expand Down
7 changes: 3 additions & 4 deletions examples/mandelbrot/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,8 @@ pub fn main() {
if button == Some(MouseButton::Left) {
let speed = 0.003 * camera.position().z.abs();
let right = camera.right_direction();
let up = right.cross(camera.view_direction());
let delta = -right * speed * delta.0 + up * speed * delta.1;
camera.translate(&delta);
let up = camera.up_orthogonal();
camera.translate(-right * speed * delta.0 + up * speed * delta.1);
redraw = true;
}
}
Expand All @@ -94,7 +93,7 @@ pub fn main() {
let distance = camera.position().z.abs();
let mut target = camera.position_at_pixel(position);
target.z = 0.0;
camera.zoom_towards(&target, distance * 0.05 * delta.1, 0.00001, 10.0);
camera.zoom_towards(target, distance * 0.05 * delta.1, 0.00001, 10.0);
redraw = true;
}
_ => {}
Expand Down
2 changes: 1 addition & 1 deletion examples/normals/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ crate-type = ["cdylib"]

[dependencies]
three-d = { path = "../../" }
three-d-asset = {version = "0.7",features = ["gltf", "png", "http"] }
three-d-asset = {version = "0.8",features = ["gltf", "png", "http"] }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
Expand Down
4 changes: 2 additions & 2 deletions examples/normals/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ pub async fn run() {
0.1,
1000.0,
);
let mut control = OrbitControl::new(*camera.target(), 1.0, 100.0);
let mut control = OrbitControl::new(camera.target(), 1.0, 100.0);

let ambient = AmbientLight::new(&context, 0.4, Srgba::WHITE);
let directional = DirectionalLight::new(&context, 2.0, Srgba::WHITE, &vec3(0.0, -1.0, 0.0));
let directional = DirectionalLight::new(&context, 2.0, Srgba::WHITE, vec3(0.0, -1.0, 0.0));

// main loop
window.render_loop(move |mut frame_input| {
Expand Down
2 changes: 1 addition & 1 deletion examples/pbr/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ crate-type = ["cdylib"]

[dependencies]
three-d = { path = "../../", features=["egui-gui"] }
three-d-asset = {version = "0.7",features = ["gltf", "hdr", "jpeg", "http"] }
three-d-asset = {version = "0.8",features = ["gltf", "hdr", "jpeg", "http"] }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
Expand Down
2 changes: 1 addition & 1 deletion examples/pbr/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub async fn run() {
0.1,
1000.0,
);
let mut control = OrbitControl::new(*camera.target(), 1.0, 100.0);
let mut control = OrbitControl::new(camera.target(), 1.0, 100.0);
let mut gui = three_d::GUI::new(&context);

let mut loaded = if let Ok(loaded) = three_d_asset::io::load_async(&[
Expand Down
2 changes: 1 addition & 1 deletion examples/picking/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ crate-type = ["cdylib"]

[dependencies]
three-d = { path = "../../" }
three-d-asset = {version = "0.7",features = ["obj", "http"] }
three-d-asset = {version = "0.8",features = ["obj", "http"] }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
Expand Down
6 changes: 3 additions & 3 deletions examples/picking/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ pub async fn run() {
0.1,
1000.0,
);
let mut control = OrbitControl::new(*camera.target(), 1.0, 100.0);
let mut control = OrbitControl::new(camera.target(), 1.0, 100.0);

let mut sphere = CpuMesh::sphere(8);
sphere.transform(&Mat4::from_scale(0.1)).unwrap();
sphere.transform(Mat4::from_scale(0.1)).unwrap();
let mut pick_mesh = Gm::new(
Mesh::new(&context, &sphere),
PhysicalMaterial::new_opaque(
Expand All @@ -41,7 +41,7 @@ pub async fn run() {
);

let ambient = AmbientLight::new(&context, 0.4, Srgba::WHITE);
let directional = DirectionalLight::new(&context, 2.0, Srgba::WHITE, &vec3(-1.0, -1.0, -1.0));
let directional = DirectionalLight::new(&context, 2.0, Srgba::WHITE, vec3(-1.0, -1.0, -1.0));

let mut loaded = three_d_asset::io::load_async(&["examples/assets/suzanne.obj"])
.await
Expand Down
2 changes: 1 addition & 1 deletion examples/point_cloud/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ crate-type = ["cdylib"]

[dependencies]
three-d = { path = "../../" }
three-d-asset = {version = "0.7",features = ["pcd", "http"] }
three-d-asset = {version = "0.8",features = ["pcd", "http"] }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
tokio = { version = "1.16", features = ["macros", "rt-multi-thread"] }
Expand Down
4 changes: 2 additions & 2 deletions examples/point_cloud/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub async fn run() {
0.01,
100.0,
);
let mut control = OrbitControl::new(*camera.target(), 0.1, 3.0);
let mut control = OrbitControl::new(camera.target(), 0.1, 3.0);

// Load point cloud
let mut loaded = three_d_asset::io::load_async(&["examples/assets/hand.pcd"])
Expand All @@ -34,7 +34,7 @@ pub async fn run() {
let cpu_point_cloud: PointCloud = loaded.deserialize("hand.pcd").unwrap();

let mut point_mesh = CpuMesh::sphere(4);
point_mesh.transform(&Mat4::from_scale(0.001)).unwrap();
point_mesh.transform(Mat4::from_scale(0.001)).unwrap();

let mut point_cloud = Gm {
geometry: InstancedMesh::new(&context, &cpu_point_cloud.into(), &point_mesh),
Expand Down
Loading

0 comments on commit 69e2997

Please sign in to comment.