diff --git a/Cargo.lock b/Cargo.lock index c148d1d7a13..8b6192908cd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -24,12 +24,6 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" -[[package]] -name = "adler32" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aae1277d39aeec15cb388266ecc24b11c80469deae6067e17a1a7aa9e5c1f234" - [[package]] name = "ahash" version = "0.7.6" @@ -89,9 +83,9 @@ dependencies = [ [[package]] name = "arboard" -version = "2.1.1" +version = "3.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc120354d1b5ec6d7aaf4876b602def75595937b5e15d356eb554ab5177e08bb" +checksum = "79e8af4eff708b72e371acd4625ad3d01a88c946b9e8d6868cb5bb6e4d0d923c" dependencies = [ "clipboard-win", "core-graphics", @@ -100,6 +94,7 @@ dependencies = [ "objc", "objc-foundation", "objc_id", + "once_cell", "parking_lot", "thiserror", "winapi", @@ -180,12 +175,6 @@ version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7b7e4c2464d97fe331d41de9d5db0def0a96f4d823b8b32a2efd503578988973" -[[package]] -name = "base64" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3441f0f7b02788e948e47f457ca01f1d7e6d92c693bc132c22b087d3141c03ff" - [[package]] name = "base64" version = "0.13.0" @@ -781,16 +770,6 @@ dependencies = [ "syn", ] -[[package]] -name = "deflate" -version = "0.8.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73770f8e1fe7d64df17ca66ad28994a0a623ea497fa69486e14984e715c5d174" -dependencies = [ - "adler32", - "byteorder", -] - [[package]] name = "digest" version = "0.10.3" @@ -860,7 +839,7 @@ dependencies = [ [[package]] name = "eframe" version = "0.19.0" -source = "git+https://github.com/emilk/egui?rev=311eb66cae5d0a029e2f19dc60b9010872aa25db#311eb66cae5d0a029e2f19dc60b9010872aa25db" +source = "git+https://github.com/emilk/egui?rev=12dc61ed0f1a23b45e336799005d62e0a6f47e4f#12dc61ed0f1a23b45e336799005d62e0a6f47e4f" dependencies = [ "bytemuck", "directories-next", @@ -885,7 +864,7 @@ dependencies = [ [[package]] name = "egui" version = "0.19.0" -source = "git+https://github.com/emilk/egui?rev=311eb66cae5d0a029e2f19dc60b9010872aa25db#311eb66cae5d0a029e2f19dc60b9010872aa25db" +source = "git+https://github.com/emilk/egui?rev=12dc61ed0f1a23b45e336799005d62e0a6f47e4f#12dc61ed0f1a23b45e336799005d62e0a6f47e4f" dependencies = [ "ahash 0.8.0", "epaint", @@ -898,7 +877,7 @@ dependencies = [ [[package]] name = "egui-winit" version = "0.19.0" -source = "git+https://github.com/emilk/egui?rev=311eb66cae5d0a029e2f19dc60b9010872aa25db#311eb66cae5d0a029e2f19dc60b9010872aa25db" +source = "git+https://github.com/emilk/egui?rev=12dc61ed0f1a23b45e336799005d62e0a6f47e4f#12dc61ed0f1a23b45e336799005d62e0a6f47e4f" dependencies = [ "arboard", "egui", @@ -923,7 +902,7 @@ dependencies = [ [[package]] name = "egui_extras" version = "0.19.0" -source = "git+https://github.com/emilk/egui?rev=311eb66cae5d0a029e2f19dc60b9010872aa25db#311eb66cae5d0a029e2f19dc60b9010872aa25db" +source = "git+https://github.com/emilk/egui?rev=12dc61ed0f1a23b45e336799005d62e0a6f47e4f#12dc61ed0f1a23b45e336799005d62e0a6f47e4f" dependencies = [ "egui", "tracing", @@ -932,7 +911,7 @@ dependencies = [ [[package]] name = "egui_glow" version = "0.19.0" -source = "git+https://github.com/emilk/egui?rev=311eb66cae5d0a029e2f19dc60b9010872aa25db#311eb66cae5d0a029e2f19dc60b9010872aa25db" +source = "git+https://github.com/emilk/egui?rev=12dc61ed0f1a23b45e336799005d62e0a6f47e4f#12dc61ed0f1a23b45e336799005d62e0a6f47e4f" dependencies = [ "bytemuck", "egui", @@ -954,7 +933,7 @@ checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797" [[package]] name = "emath" version = "0.19.0" -source = "git+https://github.com/emilk/egui?rev=311eb66cae5d0a029e2f19dc60b9010872aa25db#311eb66cae5d0a029e2f19dc60b9010872aa25db" +source = "git+https://github.com/emilk/egui?rev=12dc61ed0f1a23b45e336799005d62e0a6f47e4f#12dc61ed0f1a23b45e336799005d62e0a6f47e4f" dependencies = [ "bytemuck", "serde", @@ -963,7 +942,7 @@ dependencies = [ [[package]] name = "epaint" version = "0.19.0" -source = "git+https://github.com/emilk/egui?rev=311eb66cae5d0a029e2f19dc60b9010872aa25db#311eb66cae5d0a029e2f19dc60b9010872aa25db" +source = "git+https://github.com/emilk/egui?rev=12dc61ed0f1a23b45e336799005d62e0a6f47e4f#12dc61ed0f1a23b45e336799005d62e0a6f47e4f" dependencies = [ "ab_glyph", "ahash 0.8.0", @@ -1034,7 +1013,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f82b0f4c27ad9f8bfd1f3208d882da2b09c301bc1c828fd3a00d0216d2fbbff6" dependencies = [ "crc32fast", - "miniz_oxide 0.5.4", + "miniz_oxide", ] [[package]] @@ -1319,16 +1298,6 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" -[[package]] -name = "gloo-timers" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5fb7d06c1c8cc2a29bee7ec961009a0b2caa0793ee4900c2ffb348734ba1c8f9" -dependencies = [ - "js-sys", - "wasm-bindgen", -] - [[package]] name = "glow" version = "0.11.2" @@ -1344,21 +1313,20 @@ dependencies = [ [[package]] name = "gltf" version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00e0a0eace786193fc83644907097285396360e9e82e30f81a21e9b1ba836a3e" +source = "git+https://github.com/rerun-io/gltf?rev=3c14ded73755d1ce9e47010edb06db63cb7e2cca#3c14ded73755d1ce9e47010edb06db63cb7e2cca" dependencies = [ - "base64 0.12.3", + "base64", "byteorder", "gltf-json", "image", "lazy_static", + "urlencoding", ] [[package]] name = "gltf-derive" version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bdd53d6e284bb2bf02a6926e4cc4984978c1990914d6cd9deae4e31cf37cd113" +source = "git+https://github.com/rerun-io/gltf?rev=3c14ded73755d1ce9e47010edb06db63cb7e2cca#3c14ded73755d1ce9e47010edb06db63cb7e2cca" dependencies = [ "inflections", "proc-macro2", @@ -1369,8 +1337,7 @@ dependencies = [ [[package]] name = "gltf-json" version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9949836a9ec5e7f83f76fb9bbcbc77f254a577ebbdb0820867bc11979ef97cad" +source = "git+https://github.com/rerun-io/gltf?rev=3c14ded73755d1ce9e47010edb06db63cb7e2cca#3c14ded73755d1ce9e47010edb06db63cb7e2cca" dependencies = [ "gltf-derive", "serde", @@ -1498,7 +1465,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eabb4a44450da02c90444cf74558da904edde8fb4e9035a9a6a4e15445af0bd7" dependencies = [ "num-traits", - "serde", "zerocopy", ] @@ -1623,18 +1589,17 @@ dependencies = [ [[package]] name = "image" -version = "0.23.14" +version = "0.24.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24ffcb7e7244a9bf19d35bf2883b9c080c4ced3c07a9895572178cdb8f13f6a1" +checksum = "7e30ca2ecf7666107ff827a8e481de6a132a9b687ed3bb20bb1c144a36c00964" dependencies = [ "bytemuck", "byteorder", "color_quant", "jpeg-decoder", - "num-iter", "num-rational", "num-traits", - "png 0.16.8", + "png", "tiff", ] @@ -1724,9 +1689,9 @@ dependencies = [ [[package]] name = "jpeg-decoder" -version = "0.1.22" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "229d53d58899083193af11e15917b5640cd40b29ff475a1fe4ef725deb02d0f2" +checksum = "9478aa10f73e7528198d75109c8be5cd7d15fb530238040148d5f9a22d4c5b3b" [[package]] name = "js-sys" @@ -1905,25 +1870,6 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" -[[package]] -name = "miniz_oxide" -version = "0.3.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "791daaae1ed6889560f8c4359194f56648355540573244a5448a83ba1ecc7435" -dependencies = [ - "adler32", -] - -[[package]] -name = "miniz_oxide" -version = "0.4.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a92518e98c078586bc6c934028adcca4c92a53d6a958196de835170a01d84e4b" -dependencies = [ - "adler", - "autocfg", -] - [[package]] name = "miniz_oxide" version = "0.5.4" @@ -2059,19 +2005,6 @@ dependencies = [ "jni-sys", ] -[[package]] -name = "nix" -version = "0.22.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e4916f159ed8e5de0082076562152a76b7a1f64a01fd9d1e0fea002c37624faf" -dependencies = [ - "bitflags", - "cc", - "cfg-if", - "libc", - "memoffset", -] - [[package]] name = "nix" version = "0.24.2" @@ -2131,22 +2064,11 @@ dependencies = [ "num-traits", ] -[[package]] -name = "num-iter" -version = "0.1.43" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d03e6c028c5dc5cac6e2dec0efda81fc887605bb3d884578bb6d6bf7514e252" -dependencies = [ - "autocfg", - "num-integer", - "num-traits", -] - [[package]] name = "num-rational" -version = "0.3.2" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12ac428b1cb17fce6f731001d307d351ec70a6d202fc2e60f7d4c5e42d8f4f07" +checksum = "0638a1c9d0a3c0914158145bc76cff373a75a627e6ecbfb71cbe6f453a5a19b0" dependencies = [ "autocfg", "num-integer", @@ -2388,18 +2310,6 @@ dependencies = [ "plotters-backend", ] -[[package]] -name = "png" -version = "0.16.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c3287920cb847dee3de33d301c463fba14dda99db24214ddf93f83d3021f4c6" -dependencies = [ - "bitflags", - "crc32fast", - "deflate", - "miniz_oxide 0.3.7", -] - [[package]] name = "png" version = "0.17.6" @@ -2409,7 +2319,7 @@ dependencies = [ "bitflags", "crc32fast", "flate2", - "miniz_oxide 0.5.4", + "miniz_oxide", ] [[package]] @@ -2951,7 +2861,7 @@ version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "300a51053b1cb55c80b7a9fde4120726ddf25ca241a1cbb926626f62fb136bff" dependencies = [ - "base64 0.13.0", + "base64", "bitflags", "serde", ] @@ -3312,28 +3222,24 @@ dependencies = [ [[package]] name = "three-d" -version = "0.12.2" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8cc0ef660c02244f00fc2d1759e67d30a3c282541458490de641f0e832c8d3c9" +checksum = "f7a5a1017829335f6761bdbae2daf3021a88314a1f8d5f188c9b62ce62e2fd31" dependencies = [ "cgmath", - "gloo-timers", "glow", - "half 1.8.2", - "js-sys", - "serde", + "instant", "thiserror", "three-d-asset", "wasm-bindgen", - "wasm-bindgen-futures", "web-sys", ] [[package]] name = "three-d-asset" -version = "0.1.1" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af1886553d8b51093705b6d1a02ec2c41ac78260f68b40682d94d9976960d689" +checksum = "e953f34aa4169e098621a1ff23a68c47b7798711f7c769bf741248e850e93fbe" dependencies = [ "cgmath", "gltf", @@ -3346,12 +3252,12 @@ dependencies = [ [[package]] name = "tiff" -version = "0.6.1" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a53f4706d65497df0c4349241deddf35f84cee19c87ed86ea8ca590f4464437" +checksum = "7259662e32d1e219321eb309d5f9d898b779769d81b76e762c07c8e5d38fcb65" dependencies = [ + "flate2", "jpeg-decoder", - "miniz_oxide 0.4.4", "weezl", ] @@ -3376,7 +3282,7 @@ dependencies = [ "arrayvec", "bytemuck", "cfg-if", - "png 0.17.6", + "png", "safe_arch", "tiny-skia-path", ] @@ -3589,7 +3495,7 @@ version = "0.17.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e27992fd6a8c29ee7eef28fc78349aa244134e10ad447ce3b9f0ac0ed0fa4ce0" dependencies = [ - "base64 0.13.0", + "base64", "byteorder", "bytes", "http", @@ -3678,6 +3584,12 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "urlencoding" +version = "2.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8db7427f936968176eaa7cdf81b7f98b980b18495ec28f1b5791ac3bfe3eea9" + [[package]] name = "utf-8" version = "0.7.6" @@ -3764,8 +3676,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fc7652e3f6c4706c8d9cd54832c4a4ccb9b5336e2c3bd154d5cccfbf1c1f5f7d" dependencies = [ "cfg-if", - "serde", - "serde_json", "wasm-bindgen-macro", ] @@ -4153,14 +4063,24 @@ dependencies = [ [[package]] name = "x11rb" -version = "0.9.0" +version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e99be55648b3ae2a52342f9a870c0e138709a3493261ce9b469afe6e4df6d8a" +checksum = "592b4883219f345e712b3209c62654ebda0bb50887f330cbd018d0f654bfd507" dependencies = [ "gethostname", - "nix 0.22.3", + "nix 0.24.2", "winapi", "winapi-wsapoll", + "x11rb-protocol", +] + +[[package]] +name = "x11rb-protocol" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56b245751c0ac9db0e006dc812031482784e434630205a93c73cfefcaabeac67" +dependencies = [ + "nix 0.24.2", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index a22b33c26b2..0019a27c3bd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,8 +14,11 @@ exclude = ["examples/nyud"] debug = true [patch.crates-io] -# 2022-09-20 -eframe = { git = "https://github.com/emilk/egui", rev = "311eb66cae5d0a029e2f19dc60b9010872aa25db" } -egui = { git = "https://github.com/emilk/egui", rev = "311eb66cae5d0a029e2f19dc60b9010872aa25db" } -egui_extras = { git = "https://github.com/emilk/egui", rev = "311eb66cae5d0a029e2f19dc60b9010872aa25db" } -egui_glow = { git = "https://github.com/emilk/egui", rev = "311eb66cae5d0a029e2f19dc60b9010872aa25db" } +# 2022-09-21 (updated arboard) +eframe = { git = "https://github.com/emilk/egui", rev = "12dc61ed0f1a23b45e336799005d62e0a6f47e4f" } +egui = { git = "https://github.com/emilk/egui", rev = "12dc61ed0f1a23b45e336799005d62e0a6f47e4f" } +egui_extras = { git = "https://github.com/emilk/egui", rev = "12dc61ed0f1a23b45e336799005d62e0a6f47e4f" } +egui_glow = { git = "https://github.com/emilk/egui", rev = "12dc61ed0f1a23b45e336799005d62e0a6f47e4f" } + +# Because gltf hasn't published a new version: https://github.com/gltf-rs/gltf/issues/357 +gltf = { git = "https://github.com/rerun-io/gltf", rev = "3c14ded73755d1ce9e47010edb06db63cb7e2cca" } diff --git a/crates/re_viewer/Cargo.toml b/crates/re_viewer/Cargo.toml index c249ea19bd6..4d6c442f87c 100644 --- a/crates/re_viewer/Cargo.toml +++ b/crates/re_viewer/Cargo.toml @@ -39,7 +39,7 @@ egui_dock = { git = "https://github.com/rerun-io/egui_dock", rev = "096be40cc9fc fixed = { version = "1.17", features = ["serde"] } glam = { version = "0.20", features = ["mint"] } # can't update to 0.21 until a new version of `macaw` is released glow = "0.11" -image = { version = "0.23", default-features = false, features = ["png"] } +image = { version = "0.24", default-features = false, features = ["jpeg", "png"] } instant = { version = "0.1", features = ["wasm-bindgen"] } itertools = "0.10" macaw = { version = "0.17", features = ["with_serde"] } @@ -49,18 +49,20 @@ rand = { version = "0.8", features = ["small_rng"] } rfd = "0.10" serde = { version = "1", features = ["derive"] } serde_json = "1" -three-d = { version = "0.12.2", default-features = false } -typenum = "1.15" -three-d-asset = { version = "0.1.0", default-features = false, features = [ +three-d = { version = "0.13.0", default-features = false } +three-d-asset = { version = "0.3.0", default-features = false, features = [ "gltf", "image", + "jpeg", "obj", + "png", ] } +typenum = "1.15" vec1 = "1.8" # native: [target.'cfg(not(target_arch = "wasm32"))'.dependencies] -arboard = { version = "2.1", default-features = false, features = [ +arboard = { version = "3.1", default-features = false, features = [ "image-data", ] } ctrlc = { version = "3.0", features = ["termination"] } diff --git a/crates/re_viewer/src/app.rs b/crates/re_viewer/src/app.rs index f7663d7ecb1..9a1b34ecafe 100644 --- a/crates/re_viewer/src/app.rs +++ b/crates/re_viewer/src/app.rs @@ -107,11 +107,6 @@ impl App { } impl eframe::App for App { - #[cfg(target_arch = "wasm32")] - fn as_any_mut(&mut self) -> &mut dyn std::any::Any { - &mut *self - } - fn save(&mut self, storage: &mut dyn eframe::Storage) { eframe::set_value(storage, eframe::APP_KEY, &self.state); } diff --git a/crates/re_viewer/src/misc/mesh_loader.rs b/crates/re_viewer/src/misc/mesh_loader.rs index 02c5cae55ae..d2d98283455 100644 --- a/crates/re_viewer/src/misc/mesh_loader.rs +++ b/crates/re_viewer/src/misc/mesh_loader.rs @@ -1,4 +1,4 @@ -use anyhow::{anyhow, Context as _}; +use anyhow::Context as _; use re_log_types::{EncodedMesh3D, Mesh3D, MeshFormat, RawMesh3D}; use three_d::*; @@ -134,7 +134,7 @@ impl CpuMesh { let mut materials = Vec::new(); for m in &self.materials { - materials.push(PhysicalMaterial::new(three_d, m).map_err(|err| anyhow!("{}", err))?); + materials.push(PhysicalMaterial::new(three_d, m)); } let mut meshes = Vec::new(); @@ -146,8 +146,7 @@ impl CpuMesh { .clone(); let gm = Gm::new( - InstancedMesh::new(three_d, &Default::default(), mesh) - .map_err(|err| anyhow!("{}", err))?, + InstancedMesh::new(three_d, &Default::default(), mesh), material, ); meshes.push(gm); diff --git a/crates/re_viewer/src/remote_viewer_app.rs b/crates/re_viewer/src/remote_viewer_app.rs index 949053d6463..588685bf288 100644 --- a/crates/re_viewer/src/remote_viewer_app.rs +++ b/crates/re_viewer/src/remote_viewer_app.rs @@ -52,11 +52,6 @@ impl RemoteViewerApp { } impl eframe::App for RemoteViewerApp { - #[cfg(target_arch = "wasm32")] - fn as_any_mut(&mut self) -> &mut dyn std::any::Any { - &mut *self - } - fn save(&mut self, storage: &mut dyn eframe::Storage) { if let Some((_, app)) = &mut self.app { app.save(storage); diff --git a/crates/re_viewer/src/ui/image_ui.rs b/crates/re_viewer/src/ui/image_ui.rs index cb6c4af156c..a4dfcd6bd91 100644 --- a/crates/re_viewer/src/ui/image_ui.rs +++ b/crates/re_viewer/src/ui/image_ui.rs @@ -76,7 +76,6 @@ fn show_zoomed_image_region( meter: Option, ) { use egui::*; - use image::GenericImageView as _; let (_id, zoom_rect) = tooltip_ui.allocate_space(vec2(192.0, 192.0)); let w = dynamic_image.width() as _; @@ -209,8 +208,9 @@ fn show_zoomed_image_region( } DynamicImage::ImageRgb8(_) - | DynamicImage::ImageBgr8(_) - | DynamicImage::ImageRgb16(_) => { + | DynamicImage::ImageRgb16(_) + | DynamicImage::ImageRgb32F(_) => { + // TODO(emilk): show 16-bit and 32f values differently format!( "R: {}\nG: {}\nB: {}\n\n#{:02X}{:02X}{:02X}", r, g, b, r, g, b @@ -218,8 +218,17 @@ fn show_zoomed_image_region( } DynamicImage::ImageRgba8(_) - | DynamicImage::ImageBgra8(_) - | DynamicImage::ImageRgba16(_) => { + | DynamicImage::ImageRgba16(_) + | DynamicImage::ImageRgba32F(_) => { + // TODO(emilk): show 16-bit and 32f values differently + format!( + "R: {}\nG: {}\nB: {}\nA: {}\n\n#{:02X}{:02X}{:02X}{:02X}", + r, g, b, a, r, g, b, a + ) + } + + _ => { + re_log::warn_once!("Unknown image color type: {:?}", dynamic_image.color()); format!( "R: {}\nG: {}\nB: {}\nA: {}\n\n#{:02X}{:02X}{:02X}{:02X}", r, g, b, a, r, g, b, a diff --git a/crates/re_viewer/src/ui/view3d.rs b/crates/re_viewer/src/ui/view3d.rs index bed68fc69ac..eaffd12e4c5 100644 --- a/crates/re_viewer/src/ui/view3d.rs +++ b/crates/re_viewer/src/ui/view3d.rs @@ -419,7 +419,9 @@ pub(crate) fn view_3d( rect, callback: std::sync::Arc::new(egui_glow::CallbackFn::new(move |info, painter| { with_three_d_context(painter.gl(), |rendering| { - paint_with_three_d(rendering, &eye, &info, &scene, dark_mode, show_axes).unwrap(); + paint_with_three_d( + rendering, &eye, &info, &scene, dark_mode, show_axes, painter, + ); }); })), }; diff --git a/crates/re_viewer/src/ui/view3d/mesh_cache.rs b/crates/re_viewer/src/ui/view3d/mesh_cache.rs index a374c58914f..1e607211fa7 100644 --- a/crates/re_viewer/src/ui/view3d/mesh_cache.rs +++ b/crates/re_viewer/src/ui/view3d/mesh_cache.rs @@ -64,17 +64,12 @@ impl GpuMeshCache { }); } - pub fn set_instances( - &mut self, - mesh_id: u64, - instances: &three_d::Instances, - ) -> three_d::ThreeDResult<()> { + pub fn set_instances(&mut self, mesh_id: u64, instances: &three_d::Instances) { if let Some(Some(gpu_mesh)) = self.0.get_mut(&mesh_id) { for model in &mut gpu_mesh.meshes { - model.set_instances(instances)?; + model.set_instances(instances); } } - Ok(()) } pub fn get(&self, mesh_id: u64) -> Option<&GpuMesh> { diff --git a/crates/re_viewer/src/ui/view3d/rendering.rs b/crates/re_viewer/src/ui/view3d/rendering.rs index eba09d07baf..aee2726d68a 100644 --- a/crates/re_viewer/src/ui/view3d/rendering.rs +++ b/crates/re_viewer/src/ui/view3d/rendering.rs @@ -4,6 +4,8 @@ use super::{eye::Eye, mesh_cache::GpuMeshCache, scene::*}; type LineMaterial = three_d::ColorMaterial; +type ThreeDResult = Result; + pub struct RenderingContext { three_d: three_d::Context, skybox_dark: three_d::Skybox, @@ -15,11 +17,11 @@ pub struct RenderingContext { } impl RenderingContext { - pub fn new(gl: &std::sync::Arc) -> three_d::ThreeDResult { + pub fn new(gl: &std::sync::Arc) -> ThreeDResult { let three_d = three_d::Context::from_gl_context(gl.clone())?; - let skybox_dark = load_skybox_texture(&three_d, skybox_dark).unwrap(); - let skybox_light = load_skybox_texture(&three_d, skybox_light).unwrap(); + let skybox_dark = load_skybox_texture(&three_d, skybox_dark); + let skybox_light = load_skybox_texture(&three_d, skybox_light); let ambient_light_intensity = 5.0; let ambient_dark = three_d::AmbientLight::new_with_environment( @@ -27,15 +29,13 @@ impl RenderingContext { ambient_light_intensity, three_d::Color::WHITE, skybox_dark.texture(), - ) - .unwrap(); + ); let ambient_light = three_d::AmbientLight::new_with_environment( &three_d, ambient_light_intensity, three_d::Color::WHITE, skybox_light.texture(), - ) - .unwrap(); + ); let gpu_scene = GpuScene::new(&three_d); @@ -65,16 +65,14 @@ impl GpuScene { Default::default(), &three_d::CpuMesh::sphere(3), // fast default_material(), - ) - .unwrap(); + ); let lines_cache = three_d::Gm::new( three_d::InstancedMesh::new( three_d, &Default::default(), &three_d::CpuMesh::cylinder(10), - ) - .unwrap(), + ), Default::default(), ); @@ -98,11 +96,10 @@ impl GpuScene { line_radius_from_distance: _, } = scene; - self.points.set_instances(allocate_points(points)).unwrap(); + self.points.set_instances(allocate_points(points)); self.lines - .set_instances(&allocate_line_segments(line_segments)) - .unwrap(); + .set_instances(&allocate_line_segments(line_segments)); self.mesh_instances.clear(); @@ -127,7 +124,7 @@ impl GpuScene { } for (mesh_id, instances) in &self.mesh_instances { - self.gpu_meshes.set_instances(*mesh_id, instances).unwrap(); + self.gpu_meshes.set_instances(*mesh_id, instances); } } @@ -157,7 +154,7 @@ impl GpuScene { fn load_skybox_texture( three_d: &three_d::Context, color_from_dir: fn(glam::Vec3) -> [u8; 3], -) -> three_d::ThreeDResult { +) -> three_d::Skybox { crate::profile_function!(); let resolution = 64; @@ -314,7 +311,8 @@ pub fn paint_with_three_d( scene: &Scene, dark_mode: bool, show_axes: bool, // TODO(emilk): less bool arguments -) -> three_d::ThreeDResult<()> { + painter: &egui_glow::Painter, +) { crate::profile_function!(); use three_d::*; let three_d = &rendering.three_d; @@ -329,12 +327,12 @@ pub fn paint_with_three_d( // Respect the egui clip region (e.g. if we are inside an `egui::ScrollArea`). let clip_rect = info.clip_rect_in_pixels(); - three_d.set_scissor(ScissorBox { + let scissor_box = ScissorBox { x: clip_rect.left_px.round() as _, y: clip_rect.from_bottom_px.round() as _, width: clip_rect.width_px.round() as _, height: clip_rect.height_px.round() as _, - }); + }; three_d.set_blend(three_d::Blend::TRANSPARENCY); let position = eye.world_from_view.translation(); @@ -342,7 +340,6 @@ pub fn paint_with_three_d( let up = eye.world_from_view.transform_vector3(glam::Vec3::Y); let far = 100_000.0; // TODO(emilk): infinity (https://github.com/rustgd/cgmath/pull/547) let three_d_camera = three_d::Camera::new_perspective( - three_d, viewport, mint::Vector3::from(position).into(), mint::Vector3::from(target).into(), @@ -350,7 +347,7 @@ pub fn paint_with_three_d( radians(eye.fov_y), eye.near(), far, - )?; + ); // ------------------- @@ -359,8 +356,8 @@ pub fn paint_with_three_d( } else { &rendering.ambient_light }; - let directional0 = DirectionalLight::new(three_d, 5.0, Color::WHITE, &vec3(-1.0, -1.0, -1.0))?; - let directional1 = DirectionalLight::new(three_d, 5.0, Color::WHITE, &vec3(1.0, 1.0, 1.0))?; + let directional0 = DirectionalLight::new(three_d, 5.0, Color::WHITE, &vec3(-1.0, -1.0, -1.0)); + let directional1 = DirectionalLight::new(three_d, 5.0, Color::WHITE, &vec3(1.0, 1.0, 1.0)); let lights: &[&dyn Light] = &[ambient, &directional0, &directional1]; // ------------------- @@ -377,17 +374,22 @@ pub fn paint_with_three_d( objects.push(&rendering.skybox_light); } - let axes = three_d::Axes::new(three_d, 0.01, 1.0).unwrap(); + let axes = three_d::Axes::new(three_d, 0.01, 1.0); if show_axes { objects.push(&axes); } rendering.gpu_scene.collect_objects(&mut objects); - crate::profile_scope!("render_pass"); - render_pass(&three_d_camera, &objects, lights)?; + let (width, height) = (info.viewport.width() as u32, info.viewport.height() as u32); + + let render_target = painter.intermediate_fbo().map_or_else( + || RenderTarget::screen(three_d, width, height), + |fbo| RenderTarget::from_framebuffer(three_d, width, height, fbo), + ); - Ok(()) + crate::profile_scope!("render"); + render_target.render_partially(scissor_box, &three_d_camera, &objects, lights); } fn color_to_three_d([r, g, b, a]: [u8; 4]) -> three_d::Color { diff --git a/crates/re_viewer/src/ui/view3d/rendering/sphere_renderer.rs b/crates/re_viewer/src/ui/view3d/rendering/sphere_renderer.rs index 05221648be2..2fd427e1f08 100644 --- a/crates/re_viewer/src/ui/view3d/rendering/sphere_renderer.rs +++ b/crates/re_viewer/src/ui/view3d/rendering/sphere_renderer.rs @@ -20,11 +20,11 @@ impl InstancedSpheres { instances: SphereInstances, cpu_mesh: &CpuMesh, material: M, - ) -> ThreeDResult { - Ok(Self { - geometry: InstancedSperesGeom::new(context, instances, cpu_mesh)?, + ) -> Self { + Self { + geometry: InstancedSperesGeom::new(context, instances, cpu_mesh), material, - }) + } } } @@ -38,18 +38,18 @@ impl Geometry for InstancedSpheres { material: &dyn Material, camera: &Camera, lights: &[&dyn Light], - ) -> ThreeDResult<()> { - self.geometry.render_with_material(material, camera, lights) + ) { + self.geometry.render_with_material(material, camera, lights); } } impl Object for InstancedSpheres { - fn render(&self, camera: &Camera, lights: &[&dyn Light]) -> ThreeDResult<()> { - self.render_with_material(&self.material, camera, lights) + fn render(&self, camera: &Camera, lights: &[&dyn Light]) { + self.render_with_material(&self.material, camera, lights); } - fn is_transparent(&self) -> bool { - self.material.is_transparent() + fn material_type(&self) -> MaterialType { + self.material.material_type() } } @@ -81,42 +81,37 @@ pub struct InstancedSperesGeom { } impl InstancedSperesGeom { - pub fn new( - context: &Context, - instances: SphereInstances, - cpu_mesh: &CpuMesh, - ) -> ThreeDResult { + pub fn new(context: &Context, instances: SphereInstances, cpu_mesh: &CpuMesh) -> Self { let mut model = Self { context: context.clone(), - index_buffer: index_buffer_from_mesh(context, cpu_mesh)?, - vertex_buffers: vertex_buffers_from_mesh(context, cpu_mesh)?, - translation_scale_buffer: InstanceBuffer::new(context)?, - color_buffer: InstanceBuffer::new(context)?, + index_buffer: index_buffer_from_mesh(context, cpu_mesh), + vertex_buffers: vertex_buffers_from_mesh(context, cpu_mesh), + translation_scale_buffer: InstanceBuffer::new(context), + color_buffer: InstanceBuffer::new(context), aabb: AxisAlignedBoundingBox::EMPTY, transformation: Mat4::identity(), instances: Default::default(), }; - model.set_instances(instances)?; - Ok(model) + model.set_instances(instances); + model } pub fn instance_count(&self) -> u32 { self.instances.count() } - pub fn set_instances(&mut self, instances: SphereInstances) -> ThreeDResult<()> { + pub fn set_instances(&mut self, instances: SphereInstances) { crate::profile_function!(); - instances.validate()?; + instances.validate(); self.translation_scale_buffer - .fill(&instances.translations_and_scale)?; + .fill(&instances.translations_and_scale); if let Some(instance_colors) = &instances.colors { - self.color_buffer.fill(instance_colors)?; + self.color_buffer.fill(instance_colors); } self.instances = instances; self.update_aabb(); - Ok(()) } fn update_aabb(&mut self) { @@ -137,13 +132,13 @@ impl InstancedSperesGeom { ]); } - fn vertex_shader_source(&self, fragment_shader_source: &str) -> ThreeDResult { + fn vertex_shader_source(&self, fragment_shader_source: &str) -> String { crate::profile_function!(); let use_positions = fragment_shader_source.contains("in vec3 pos;"); let use_normals = fragment_shader_source.contains("in vec3 nor;"); let use_tangents = fragment_shader_source.contains("in vec3 tang;"); let use_colors = fragment_shader_source.contains("in vec4 col;"); - Ok(format!( + format!( "{}{}{}{}{}", if use_positions { "#define USE_POSITIONS\n" @@ -156,9 +151,10 @@ impl InstancedSperesGeom { "" }, if use_tangents { - if fragment_shader_source.contains("in vec3 bitang;") { - return Err(CoreError::MissingBitangent.into()); - } + assert!( + !fragment_shader_source.contains("in vec3 bitang;"), + "Missing bitangent" + ); "#define USE_TANGENTS\n" } else { "" @@ -243,7 +239,7 @@ void main() #endif } "#, - )) + ) } } @@ -257,63 +253,67 @@ impl Geometry for InstancedSperesGeom { material: &dyn Material, camera: &Camera, lights: &[&dyn Light], - ) -> ThreeDResult<()> { + ) { crate::profile_function!(); let fragment_shader_source = material.fragment_shader_source( self.vertex_buffers.contains_key("color") || self.instances.colors.is_some(), lights, ); - self.context.program( - &self.vertex_shader_source(&fragment_shader_source)?, - &fragment_shader_source, - |program| { - crate::profile_scope!("rendering"); - material.use_uniforms(program, camera, lights)?; - program.use_uniform("viewProjection", camera.projection() * camera.view())?; - program.use_uniform("modelMatrix", &self.transformation)?; - program.use_uniform_if_required( - "normalMatrix", - &self.transformation.invert().unwrap().transpose(), - )?; - - for attribute_name in ["position", "normal", "tangent", "color", "uv_coordinates"] { - if program.requires_attribute(attribute_name) { - program.use_vertex_attribute( - attribute_name, - self.vertex_buffers.get(attribute_name).ok_or_else(|| { - CoreError::MissingMeshBuffer(attribute_name.to_owned()) - })?, - )?; + self.context + .program( + &self.vertex_shader_source(&fragment_shader_source), + &fragment_shader_source, + |program| { + crate::profile_scope!("rendering"); + material.use_uniforms(program, camera, lights); + program.use_uniform("viewProjection", camera.projection() * camera.view()); + program.use_uniform("modelMatrix", &self.transformation); + program.use_uniform_if_required( + "normalMatrix", + &self.transformation.invert().unwrap().transpose(), + ); + + for attribute_name in + ["position", "normal", "tangent", "color", "uv_coordinates"] + { + if program.requires_attribute(attribute_name) { + program.use_vertex_attribute( + attribute_name, + self.vertex_buffers + .get(attribute_name) + .unwrap_or_else(|| panic!("Missing {attribute_name:?}")), + ); + } } - } - if program.requires_attribute("instance_translation_scale") { - program.use_instance_attribute( - "instance_translation_scale", - &self.translation_scale_buffer, - )?; - } - if program.requires_attribute("instance_color") { - program.use_instance_attribute("instance_color", &self.color_buffer)?; - } + if program.requires_attribute("instance_translation_scale") { + program.use_instance_attribute( + "instance_translation_scale", + &self.translation_scale_buffer, + ); + } + if program.requires_attribute("instance_color") { + program.use_instance_attribute("instance_color", &self.color_buffer); + } - if let Some(ref index_buffer) = self.index_buffer { - program.draw_elements_instanced( - material.render_states(), - camera.viewport(), - index_buffer, - self.instances.count(), - ) - } else { - program.draw_arrays_instanced( - material.render_states(), - camera.viewport(), - self.vertex_buffers.get("position").unwrap().vertex_count(), - self.instances.count(), - ) - } - }, - ) + if let Some(ref index_buffer) = self.index_buffer { + program.draw_elements_instanced( + material.render_states(), + camera.viewport(), + index_buffer, + self.instances.count(), + ); + } else { + program.draw_arrays_instanced( + material.render_states(), + camera.viewport(), + self.vertex_buffers.get("position").unwrap().vertex_count(), + self.instances.count(), + ); + } + }, + ) + .unwrap(); } } @@ -327,19 +327,10 @@ pub struct SphereInstances { } impl SphereInstances { - pub fn validate(&self) -> ThreeDResult<()> { + pub fn validate(&self) { if let Some(colors) = &self.colors { - if colors.len() != self.translations_and_scale.len() { - return Err(CoreError::InvalidBufferLength( - "colors".to_owned(), - self.translations_and_scale.len(), - colors.len(), - ) - .into()); - } + assert_eq!(colors.len(), self.translations_and_scale.len()); } - - Ok(()) } pub fn count(&self) -> u32 { @@ -350,25 +341,25 @@ impl SphereInstances { fn vertex_buffers_from_mesh( context: &Context, cpu_mesh: &CpuMesh, -) -> ThreeDResult> { +) -> HashMap { #[cfg(debug_assertions)] - cpu_mesh.validate()?; + cpu_mesh.validate().unwrap(); let mut buffers = HashMap::new(); buffers.insert( "position".to_owned(), - VertexBuffer::new_with_data(context, &cpu_mesh.positions.to_f32())?, + VertexBuffer::new_with_data(context, &cpu_mesh.positions.to_f32()), ); if let Some(ref normals) = cpu_mesh.normals { buffers.insert( "normal".to_owned(), - VertexBuffer::new_with_data(context, normals)?, + VertexBuffer::new_with_data(context, normals), ); }; if let Some(ref tangents) = cpu_mesh.tangents { buffers.insert( "tangent".to_owned(), - VertexBuffer::new_with_data(context, tangents)?, + VertexBuffer::new_with_data(context, tangents), ); }; if let Some(ref uvs) = cpu_mesh.uvs { @@ -379,29 +370,22 @@ fn vertex_buffers_from_mesh( &uvs.iter() .map(|uv| vec2(uv.x, 1.0 - uv.y)) .collect::>(), - )?, + ), ); }; if let Some(ref colors) = cpu_mesh.colors { buffers.insert( "color".to_owned(), - VertexBuffer::new_with_data(context, colors)?, + VertexBuffer::new_with_data(context, colors), ); }; - Ok(buffers) + buffers } -fn index_buffer_from_mesh( - context: &Context, - cpu_mesh: &CpuMesh, -) -> ThreeDResult> { - Ok(if let Some(ref indices) = cpu_mesh.indices { - Some(match indices { - Indices::U8(ind) => ElementBuffer::new_with_data(context, ind)?, - Indices::U16(ind) => ElementBuffer::new_with_data(context, ind)?, - Indices::U32(ind) => ElementBuffer::new_with_data(context, ind)?, - }) - } else { - None +fn index_buffer_from_mesh(context: &Context, cpu_mesh: &CpuMesh) -> Option { + cpu_mesh.indices.as_ref().map(|indices| match indices { + Indices::U8(ind) => ElementBuffer::new_with_data(context, ind), + Indices::U16(ind) => ElementBuffer::new_with_data(context, ind), + Indices::U32(ind) => ElementBuffer::new_with_data(context, ind), }) } diff --git a/deny.toml b/deny.toml index ef88f96648d..aa2df42c412 100644 --- a/deny.toml +++ b/deny.toml @@ -26,7 +26,6 @@ deny = [ skip = [ { name = "ahash" }, # Old version via dark-light - { name = "base64" }, # Old version via gltf { name = "miniz_oxide" }, # Old version from old png crate, because we are stuck on old version of image crate { name = "nix" }, # Too many to protect against ] diff --git a/examples/objectron/Cargo.toml b/examples/objectron/Cargo.toml index 8858e98203d..d25384e5095 100644 --- a/examples/objectron/Cargo.toml +++ b/examples/objectron/Cargo.toml @@ -20,7 +20,7 @@ re_viewer = { path = "../../crates/re_viewer" } anyhow = "1" clap = { version = "3.1.6", features = ["derive"] } glam = "0.20" # to convert rotation matrices to quaternions -image = { version = "0.23", default-features = false, features = ["jpeg"] } +image = { version = "0.24", default-features = false, features = ["jpeg"] } itertools = "0.10" mimalloc = "0.1.29" prost = "0.10"