From aefa6dc62f1fb41d5bd06145655d73f295644149 Mon Sep 17 00:00:00 2001 From: Nova Date: Sun, 30 Apr 2023 13:25:13 -0400 Subject: [PATCH] feat: new stereokit --- Cargo.lock | 288 +++++------------------------ Cargo.toml | 6 +- src/core/client.rs | 2 +- src/main.rs | 87 ++++----- src/nodes/audio.rs | 97 +++++----- src/nodes/data.rs | 4 +- src/nodes/drawable/lines.rs | 19 +- src/nodes/drawable/mod.rs | 28 +-- src/nodes/drawable/model.rs | 82 ++++---- src/nodes/drawable/text.rs | 44 +++-- src/nodes/hmd.rs | 4 +- src/nodes/items/mod.rs | 2 +- src/objects/input/mouse_pointer.rs | 17 +- src/objects/input/sk_controller.rs | 6 +- src/objects/input/sk_hand.rs | 25 ++- src/wayland/mod.rs | 6 +- src/wayland/surface.rs | 44 +++-- 17 files changed, 278 insertions(+), 483 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 57db07d..6042d41 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -23,17 +23,6 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" -[[package]] -name = "ahash" -version = "0.7.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" -dependencies = [ - "getrandom", - "once_cell", - "version_check", -] - [[package]] name = "aliasable" version = "0.1.3" @@ -167,7 +156,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "16e62a023e7c117e27523144c5d2459f4397fcc3cab0085af8e2224f643a0193" dependencies = [ "proc-macro2", - "quote 1.0.26", + "quote", "syn 2.0.15", ] @@ -178,7 +167,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b9ccdd8f2a161be9bd5c023df56f1b2a0bd1d83872ae53b71a84a12c9bf6e842" dependencies = [ "proc-macro2", - "quote 1.0.26", + "quote", "syn 2.0.15", ] @@ -268,7 +257,7 @@ dependencies = [ "log", "peeking_take_while", "proc-macro2", - "quote 1.0.26", + "quote", "regex", "rustc-hash", "shlex", @@ -282,16 +271,6 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" -[[package]] -name = "bitflags_serde_shim" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e678d043c18557c001a9f81be1c04e09339f9c990b8d5e20801e7ca4a1c6f244" -dependencies = [ - "bitflags", - "serde", -] - [[package]] name = "bumpalo" version = "3.12.1" @@ -410,9 +389,9 @@ version = "4.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9644cd56d6b87dbe899ef8b053e331c0637664e9e21a33dfcdc36093f5c5c4" dependencies = [ - "heck 0.4.1", + "heck", "proc-macro2", - "quote 1.0.26", + "quote", "syn 2.0.15", ] @@ -458,12 +437,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5a667583cca8c4f8436db8de46ea8233c42a7d9ae424a82d338f2e4675229204" dependencies = [ "backtrace", - "color-spantrace", "eyre", "indenter", "once_cell", "owo-colors", - "tracing-error", ] [[package]] @@ -479,24 +456,22 @@ dependencies = [ "serde_derive", ] -[[package]] -name = "color-spantrace" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ba75b3d9449ecdccb27ecbc479fdc0b87fa2dd43d2f8298f9bf0e59aacc8dce" -dependencies = [ - "once_cell", - "owo-colors", - "tracing-core", - "tracing-error", -] - [[package]] name = "colorchoice" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" +[[package]] +name = "concat-idents" +version = "1.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fe0e1d9f7de897d18e590a7496b5facbe87813f746cf4b8db596ba77e07e832" +dependencies = [ + "quote", + "syn 1.0.109", +] + [[package]] name = "console-api" version = "0.4.0" @@ -589,7 +564,7 @@ dependencies = [ "codespan-reporting", "once_cell", "proc-macro2", - "quote 1.0.26", + "quote", "scratch", "syn 2.0.15", ] @@ -607,45 +582,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2345488264226bf682893e25de0769f3360aac9957980ec49361b083ddaa5bc5" dependencies = [ "proc-macro2", - "quote 1.0.26", + "quote", "syn 2.0.15", ] -[[package]] -name = "darling" -version = "0.14.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b750cb3417fd1b327431a470f388520309479ab0bf5e323505daf0290cd3850" -dependencies = [ - "darling_core", - "darling_macro", -] - -[[package]] -name = "darling_core" -version = "0.14.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "109c1ca6e6b7f82cc233a97004ea8ed7ca123a9af07a8230878fcfda9b158bf0" -dependencies = [ - "fnv", - "ident_case", - "proc-macro2", - "quote 1.0.26", - "strsim", - "syn 1.0.109", -] - -[[package]] -name = "darling_macro" -version = "0.14.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4aab4dbc9f7611d8b55048a3a16d2d010c2c8334e46304b40ac1cc14bf3b48e" -dependencies = [ - "darling_core", - "quote 1.0.26", - "syn 1.0.109", -] - [[package]] name = "dashmap" version = "5.4.0" @@ -659,48 +599,6 @@ dependencies = [ "parking_lot_core 0.9.7", ] -[[package]] -name = "derive_builder" -version = "0.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d67778784b508018359cbc8696edb3db78160bab2c2a28ba7f56ef6932997f8" -dependencies = [ - "derive_builder_macro", -] - -[[package]] -name = "derive_builder_core" -version = "0.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c11bdc11a0c47bc7d37d582b5285da6849c96681023680b906673c5707af7b0f" -dependencies = [ - "darling", - "proc-macro2", - "quote 1.0.26", - "syn 1.0.109", -] - -[[package]] -name = "derive_builder_macro" -version = "0.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebcda35c7a396850a55ffeac740804b40ffec779b98fffbb1738f4033f0ee79e" -dependencies = [ - "derive_builder_core", - "syn 1.0.109", -] - -[[package]] -name = "derive_is_enum_variant" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0ac8859845146979953797f03cc5b282fb4396891807cdb3d04929a88418197" -dependencies = [ - "heck 0.3.3", - "quote 0.3.15", - "syn 0.11.11", -] - [[package]] name = "directories" version = "5.0.0" @@ -936,11 +834,12 @@ dependencies = [ [[package]] name = "glam" -version = "0.24.0" +version = "0.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad83ab008a4fa3b31dfa713dd41b5a9bdea1e94e4cf1e2fc274ffbd49b0271d3" +checksum = "8e4afd9ad95555081e109fe1d21f2a30c691b5f0919c67dfa690a2e1eb6bd51c" dependencies = [ "mint", + "serde", ] [[package]] @@ -1003,15 +902,6 @@ dependencies = [ "num-traits", ] -[[package]] -name = "heck" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c" -dependencies = [ - "unicode-segmentation", -] - [[package]] name = "heck" version = "0.4.1" @@ -1133,12 +1023,6 @@ dependencies = [ "cxx-build", ] -[[package]] -name = "ident_case" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" - [[package]] name = "indenter" version = "0.3.3" @@ -1431,17 +1315,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "num-derive" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "876a53fff98e03a936a674b29568b0e605f06b29372c2489ff4de23f1949743d" -dependencies = [ - "proc-macro2", - "quote 1.0.26", - "syn 1.0.109", -] - [[package]] name = "num-integer" version = "0.1.45" @@ -1497,7 +1370,7 @@ checksum = "dcbff9bc912032c62bf65ef1d5aea88983b420f4f839db1e9b0c281a25c9c799" dependencies = [ "proc-macro-crate", "proc-macro2", - "quote 1.0.26", + "quote", "syn 1.0.109", ] @@ -1509,7 +1382,7 @@ checksum = "96667db765a921f7b295ffee8b60472b686a51d4f21c2ee4ffdb94c7013b65a6" dependencies = [ "proc-macro-crate", "proc-macro2", - "quote 1.0.26", + "quote", "syn 2.0.15", ] @@ -1547,7 +1420,7 @@ dependencies = [ "Inflector", "proc-macro-error", "proc-macro2", - "quote 1.0.26", + "quote", "syn 1.0.109", ] @@ -1639,7 +1512,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "069bdb1e05adc7a8990dce9cc75370895fbe4e3d58b9b73bf1aee56359344a55" dependencies = [ "proc-macro2", - "quote 1.0.26", + "quote", "syn 1.0.109", ] @@ -1702,7 +1575,7 @@ checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" dependencies = [ "proc-macro-error-attr", "proc-macro2", - "quote 1.0.26", + "quote", "syn 1.0.109", "version_check", ] @@ -1714,7 +1587,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" dependencies = [ "proc-macro2", - "quote 1.0.26", + "quote", "version_check", ] @@ -1746,7 +1619,7 @@ dependencies = [ "anyhow", "itertools", "proc-macro2", - "quote 1.0.26", + "quote", "syn 1.0.109", ] @@ -1768,12 +1641,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "quote" -version = "0.3.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a" - [[package]] name = "quote" version = "1.0.26" @@ -1971,7 +1838,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "291a097c63d8497e00160b166a967a4a79c64f3facdd01cbd7502231688d77df" dependencies = [ "proc-macro2", - "quote 1.0.26", + "quote", "syn 2.0.15", ] @@ -1993,7 +1860,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bcec881020c684085e55a25f7fd888954d56609ef363479dc5a1305eb0d40cab" dependencies = [ "proc-macro2", - "quote 1.0.26", + "quote", "syn 2.0.15", ] @@ -2129,7 +1996,7 @@ dependencies = [ "console-subscriber", "dashmap", "directories", - "glam 0.24.0", + "glam 0.23.0", "global_counter", "lazy_static", "mint", @@ -2160,37 +2027,30 @@ checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" [[package]] name = "stereokit" -version = "0.15.3" +version = "0.16.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e1a6491c921ee4bb53bc41f08345d621769ea6802cd020cd308975a790487cb" +checksum = "f90dda01589858b2cbbff23b616bdf8b9d1c5119afd1b1f0463a3f44cebe5b46" dependencies = [ "bitflags", - "bitflags_serde_shim", - "color-eyre", - "derive_builder", - "derive_is_enum_variant", - "mint", + "concat-idents", + "glam 0.23.0", "ndk-context", - "num-derive", "num_enum 0.6.1", - "once_cell", "serde", "serde_repr", "stereokit-sys", - "tracing", - "ustr", + "thiserror", ] [[package]] name = "stereokit-sys" -version = "2.4.3" +version = "2.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c9dc98d29adb1bb9ba484de492c39afcd73f9bb51eb04e4c5bef50fe1d62447" +checksum = "9fa25848c4eba18fcf4cb9ad5988dbf25a4f6f21fcc5f1a85ee8c93088a3b5a0" dependencies = [ "bindgen", "cmake", - "mint", - "prisma", + "glam 0.23.0", ] [[package]] @@ -2199,17 +2059,6 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" -[[package]] -name = "syn" -version = "0.11.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3b891b9015c88c576343b9b3e41c2c11a51c219ef067b264bd9c8aa9b441dad" -dependencies = [ - "quote 0.3.15", - "synom", - "unicode-xid", -] - [[package]] name = "syn" version = "1.0.109" @@ -2217,7 +2066,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" dependencies = [ "proc-macro2", - "quote 1.0.26", + "quote", "unicode-ident", ] @@ -2228,7 +2077,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a34fcf3e8b60f57e6a14301a2e916d323af98b0ea63c599441eec8558660c822" dependencies = [ "proc-macro2", - "quote 1.0.26", + "quote", "unicode-ident", ] @@ -2238,15 +2087,6 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" -[[package]] -name = "synom" -version = "0.11.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a393066ed9010ebaed60b9eafa373d4b1baac186dd7e008555b0f702b51945b6" -dependencies = [ - "unicode-xid", -] - [[package]] name = "tempfile" version = "3.5.0" @@ -2285,7 +2125,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f" dependencies = [ "proc-macro2", - "quote 1.0.26", + "quote", "syn 2.0.15", ] @@ -2347,7 +2187,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "61a573bdc87985e9d6ddeed1b3d864e8a302c847e40d647746df2f1de209d1ce" dependencies = [ "proc-macro2", - "quote 1.0.26", + "quote", "syn 2.0.15", ] @@ -2476,7 +2316,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4017f8f45139870ca7e672686113917c71c7a6e02d4924eda67186083c03081a" dependencies = [ "proc-macro2", - "quote 1.0.26", + "quote", "syn 1.0.109", ] @@ -2501,16 +2341,6 @@ dependencies = [ "valuable", ] -[[package]] -name = "tracing-error" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d686ec1c0f384b1277f097b2f279a2ecc11afe8c133c1aabf036a27cb4cd206e" -dependencies = [ - "tracing", - "tracing-subscriber", -] - [[package]] name = "tracing-futures" version = "0.2.5" @@ -2562,36 +2392,12 @@ version = "1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5464a87b239f13a63a501f2701565754bae92d243d4bb7eb12f6d57d2269bf4" -[[package]] -name = "unicode-segmentation" -version = "1.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" - [[package]] name = "unicode-width" version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" -[[package]] -name = "unicode-xid" -version = "0.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c1f860d7d29cf02cb2f3f359fd35991af3d30bac52c57d265a3c461074cb4dc" - -[[package]] -name = "ustr" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "371436099f2980de56dc385b615696d3eabbdac9649a72b85f9d75f68474fa9c" -dependencies = [ - "ahash", - "byteorder", - "lazy_static", - "parking_lot 0.11.2", -] - [[package]] name = "utf8parse" version = "0.2.1" @@ -2658,7 +2464,7 @@ dependencies = [ "log", "once_cell", "proc-macro2", - "quote 1.0.26", + "quote", "syn 1.0.109", "wasm-bindgen-shared", ] @@ -2669,7 +2475,7 @@ version = "0.2.84" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4c21f77c0bedc37fd5dc21f897894a5ca01e7bb159884559461862ae90c0b4c5" dependencies = [ - "quote 1.0.26", + "quote", "wasm-bindgen-macro-support", ] @@ -2680,7 +2486,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2aff81306fcac3c7515ad4e177f521b5c9a15f2b08f4e32d823066102f35a5f6" dependencies = [ "proc-macro2", - "quote 1.0.26", + "quote", "syn 1.0.109", "wasm-bindgen-backend", "wasm-bindgen-shared", @@ -2753,7 +2559,7 @@ checksum = "4834c14b3edf1d9986c83ca79b1e7e3afbe9874c7c144702f6467063259ce45d" dependencies = [ "proc-macro2", "quick-xml", - "quote 1.0.26", + "quote", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index a4a2b90..e0544d8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,7 @@ homepage = "https://stardustxr.org" color-eyre = { version = "0.6.2", default-features = false } clap = { version = "4.2.4", features = ["derive"] } dashmap = "5.4.0" -glam = {version = "0.24.0", features = ["mint"]} +glam = {version = "0.23.0", features = ["mint"]} lazy_static = "1.4.0" mint = "0.5.9" nanoid = "0.4.0" @@ -34,8 +34,8 @@ rand = "0.8.5" [dependencies.stereokit] default-features = false -features = ["linux-egl", "color_named", "prisma"] -version = "0.15.3" +features = ["linux-egl"] +version = "0.16.7" [dependencies.smithay] # git = "https://github.com/technobaboo/smithay.git" # Until we get stereokit to understand OES samplers and external textures diff --git a/src/core/client.rs b/src/core/client.rs index eac7f07..986fa9c 100644 --- a/src/core/client.rs +++ b/src/core/client.rs @@ -80,7 +80,7 @@ impl Client { let (mut messenger_tx, mut messenger_rx) = messenger::create(connection); let scenegraph = Arc::new(Scenegraph::default()); - let startup_settings = env.as_ref().and_then(|env| startup_settings(env)); + let startup_settings = env.as_ref().and_then(startup_settings); let client = CLIENTS.add(Client { pid, diff --git a/src/main.rs b/src/main.rs index a36aaf9..72aba23 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,15 +20,11 @@ use std::path::PathBuf; use std::process::Command; use std::sync::Arc; use std::time::Duration; -use stereokit::input::Handed; -use stereokit::lifecycle::DisplayMode; -use stereokit::lifecycle::{DepthMode, LogFilter}; -use stereokit::material::Material; -use stereokit::render::SphericalHarmonics; -use stereokit::render::StereoKitRender; -use stereokit::shader::Shader; -use stereokit::texture::Texture; -use stereokit::time::StereoKitTime; +use stereokit::DisplayBlend; +use stereokit::{ + named_colors::BLACK, DepthMode, DisplayMode, Handed, LogLevel, StereoKitMultiThread, + TextureFormat, TextureType, +}; use tokio::{runtime::Handle, sync::oneshot}; use tracing::{debug_span, error, info}; use tracing_subscriber::{fmt, prelude::*, EnvFilter}; @@ -87,47 +83,52 @@ fn main() -> Result<()> { } let cli_args = Arc::new(CliArgs::parse()); - let stereokit = stereokit::Settings::default() - .app_name("Stardust XR") - .log_filter(LogFilter::None) - .overlay_app(cli_args.overlay_priority.is_some()) - .overlay_priority(cli_args.overlay_priority.unwrap_or(u32::MAX)) - .disable_desktop_input_window(true) - .display_preference(if cli_args.flatscreen { + let sk = stereokit::Settings { + app_name: "Stardust XR".to_string(), + display_preference: if cli_args.flatscreen { DisplayMode::Flatscreen } else { DisplayMode::MixedReality - }) - .depth_mode(DepthMode::D32) - .init() - .expect("StereoKit failed to initialize"); + }, + blend_preference: DisplayBlend::AnyTransparent, + depth_mode: DepthMode::D32, + log_filter: LogLevel::None, + overlay_app: cli_args.overlay_priority.is_some(), + overlay_priority: cli_args.overlay_priority.unwrap_or(u32::MAX), + disable_desktop_input_window: true, + ..Default::default() + } + .init() + .expect("StereoKit failed to initialize"); info!("Init StereoKit"); - Material::find(&stereokit, "default/material_pbr")? - .set_shader(Shader::from_name(&stereokit, "default/shader_pbr_clip")?); + sk.material_set_shader( + sk.material_find("default/material_pbr")?, + sk.shader_find("default/shader_pbr_clip")?, + ); // Skytex/light stuff { - if let Some((tex, light)) = project_dirs + if let Some((light, tex)) = project_dirs .as_ref() .and_then(|dirs| { let skytex_path = dirs.config_dir().join("skytex.hdr"); - skytex_path.exists().then(|| { - Texture::from_cubemap_equirectangular(&stereokit, &skytex_path, true, 100) - }) + skytex_path + .exists() + .then(|| sk.tex_create_cubemap_file(&skytex_path, true, 100).ok()) }) .flatten() { - stereokit.set_skytex(&tex); - stereokit.set_skylight(&light); - } else if let Some(tex) = Texture::cubemap_from_spherical_harmonics( - &stereokit, - &SphericalHarmonics::default(), - 16, - 0.0, - 0.0, - ) { - stereokit.set_skytex(&tex); + sk.render_set_skytex(&tex); + sk.render_set_skylight(light); + } else { + sk.render_set_skytex(sk.tex_gen_color( + BLACK, + 1, + 1, + TextureType::CUBEMAP, + TextureFormat::RGBA32, + )); } } @@ -148,10 +149,10 @@ fn main() -> Result<()> { .flatten(); if hands.is_none() { - unsafe { - stereokit::sys::input_hand_visible(stereokit::sys::handed__handed_left, false as i32); - stereokit::sys::input_hand_visible(stereokit::sys::handed__handed_right, false as i32); - } + // unsafe { + // stereokit::sys::input_hand_visible(stereokit::sys::handed__handed_left, false as i32); + // stereokit::sys::input_hand_visible(stereokit::sys::handed__handed_right, false as i32); + // } } let (event_stop_tx, event_stop_rx) = oneshot::channel::<()>(); @@ -187,7 +188,7 @@ fn main() -> Result<()> { let mut last_frame_delta = Duration::ZERO; let mut sleep_duration = Duration::ZERO; debug_span!("StereoKit").in_scope(|| { - stereokit.run( + sk.run( |sk| { let _span = debug_span!("StereoKit step"); let _span = _span.enter(); @@ -209,7 +210,7 @@ fn main() -> Result<()> { right_controller.update(sk); } input::process_input(); - nodes::root::Root::send_frame_events(sk.time_elapsed()); + nodes::root::Root::send_frame_events(sk.time_elapsed_unscaled()); { let frame_delta = Duration::from_secs_f64(sk.time_elapsed_unscaled()); if last_frame_delta < frame_delta { @@ -233,7 +234,7 @@ fn main() -> Result<()> { #[cfg(feature = "wayland")] wayland.update(sk); drawable::draw(sk); - audio::update(); + audio::update(sk); #[cfg(feature = "wayland")] wayland.make_context_current(); }, diff --git a/src/nodes/audio.rs b/src/nodes/audio.rs index c31ba49..cd22cfe 100644 --- a/src/nodes/audio.rs +++ b/src/nodes/audio.rs @@ -5,7 +5,7 @@ use crate::core::registry::Registry; use crate::core::resource::ResourceID; use crate::nodes::spatial::{find_spatial_parent, parse_transform, Spatial}; use color_eyre::eyre::{ensure, eyre, Result}; -use glam::{vec3a, Vec4Swizzles}; +use glam::{vec3, Vec4Swizzles}; use once_cell::sync::OnceCell; use parking_lot::Mutex; use send_wrapper::SendWrapper; @@ -13,19 +13,20 @@ use serde::Deserialize; use stardust_xr::schemas::flex::deserialize; use stardust_xr::values::Transform; use std::ops::DerefMut; -use std::{ffi::OsStr, fmt::Error, path::PathBuf, sync::Arc}; -use stereokit::sound::SoundInstance; -use stereokit::sound::{Sound as SKSound, SoundT}; +use std::{ffi::OsStr, path::PathBuf, sync::Arc}; +use stereokit::{Sound as SkSound, SoundInstance, StereoKitDraw}; static SOUND_REGISTRY: Registry = Registry::new(); pub struct Sound { space: Arc, - resource_id: ResourceID, - pending_audio_path: OnceCell, - instance: Mutex>, + volume: f32, - sk_sound: OnceCell>, + pending_audio_path: PathBuf, + sk_sound: OnceCell>, + instance: Mutex>, + stop: Mutex>, + play: Mutex>, } impl Sound { @@ -34,78 +35,70 @@ impl Sound { node.spatial.get().is_some(), "Internal: Node does not have a spatial attached!" ); + let pending_audio_path = resource_id + .get_file( + &node + .get_client() + .ok_or_else(|| eyre!("Client not found"))? + .base_resource_prefixes + .lock() + .clone(), + &[OsStr::new("wav"), OsStr::new("mp3")], + ) + .ok_or_else(|| eyre!("Resource not found"))?; let sound = Sound { space: node.spatial.get().unwrap().clone(), - resource_id, volume: 1.0, - instance: Mutex::new(None), - pending_audio_path: OnceCell::new(), + pending_audio_path, sk_sound: OnceCell::new(), + instance: Mutex::new(None), + stop: Mutex::new(None), + play: Mutex::new(None), }; let sound_arc = SOUND_REGISTRY.add(sound); node.add_local_signal("play", Sound::play_flex); node.add_local_signal("stop", Sound::stop_flex); - let _ = sound_arc.pending_audio_path.set( - sound_arc - .resource_id - .get_file( - &node - .get_client() - .ok_or_else(|| eyre!("Client not found"))? - .base_resource_prefixes - .lock() - .clone(), - &[OsStr::new("wav"), OsStr::new("mp3")], - ) - .ok_or_else(|| eyre!("Resource not found"))?, - ); let _ = node.sound.set(sound_arc.clone()); Ok(sound_arc) } - fn update(&self) { + fn update(&self, sk: &impl StereoKitDraw) { + let sound = self.sk_sound.get_or_init(|| { + SendWrapper::new(sk.sound_create(self.pending_audio_path.clone()).unwrap()) + }); + if self.stop.lock().take().is_some() { + if let Some(instance) = self.instance.lock().take() { + sk.sound_inst_stop(instance); + } + } + if self.play.lock().is_some() && self.instance.lock().is_none() { + self.instance.lock().replace(sk.sound_play( + sound.as_ref(), + vec3(0.0, 0.0, 0.0), + self.volume, + )); + } if let Some(instance) = self.instance.lock().deref_mut() { - instance.set_position(self.space.global_transform().w_axis.xyz()) + sk.sound_inst_set_pos(*instance, self.space.global_transform().w_axis.xyz()); } } fn play_flex(node: &Node, _calling_client: Arc, _data: &[u8]) -> Result<()> { let sound = node.sound.get().unwrap(); - let sk_sound = sound - .sk_sound - .get_or_try_init(|| -> color_eyre::eyre::Result> { - let pending_audio_path = sound.pending_audio_path.get().ok_or(Error)?; - let sound = SKSound::from_file(pending_audio_path.as_path()).ok_or(Error)?; - - Ok(SendWrapper::new(sound)) - }) - .ok(); - if let Some(sk_sound) = sk_sound { - let position = sound - .space - .global_transform() - .transform_point3a(vec3a(0.0, 0.0, 0.0)); - sound - .instance - .lock() - .replace(sk_sound.play_sound(position, sound.volume)); - } - + sound.play.lock().replace(()); Ok(()) } pub fn stop_flex(node: &Node, _calling_client: Arc, _data: &[u8]) -> Result<()> { let sound = node.sound.get().unwrap(); - if let Some(instance) = sound.instance.lock().take() { - instance.stop(); - } + sound.stop.lock().replace(()); Ok(()) } } -pub fn update() { +pub fn update(sk: &impl StereoKitDraw) { for sound in SOUND_REGISTRY.get_valid_contents() { - sound.update() + sound.update(sk) } } diff --git a/src/nodes/data.rs b/src/nodes/data.rs index f368230..792c985 100644 --- a/src/nodes/data.rs +++ b/src/nodes/data.rs @@ -125,8 +125,8 @@ impl PulseSender { } let (_, rotation, position) = Spatial::space_to_space_matrix( - rx_node.spatial.get().map(|s| &**s), - tx_node.spatial.get().map(|s| &**s), + rx_node.spatial.get().map(|s| s.as_ref()), + tx_node.spatial.get().map(|s| s.as_ref()), ) .to_scale_rotation_translation(); diff --git a/src/nodes/drawable/lines.rs b/src/nodes/drawable/lines.rs index 3405681..69d1b6c 100644 --- a/src/nodes/drawable/lines.rs +++ b/src/nodes/drawable/lines.rs @@ -14,7 +14,7 @@ use prisma::{Flatten, Lerp, Rgba}; use serde::Deserialize; use stardust_xr::{schemas::flex::deserialize, values::Transform}; use std::{collections::VecDeque, sync::Arc}; -use stereokit::{lifecycle::StereoKitDraw, lines::LinePoint as SkLinePoint, values::Color128}; +use stereokit::{Color128, LinePoint as SkLinePoint, StereoKitDraw}; use super::Drawable; @@ -57,14 +57,14 @@ impl Lines { Ok(lines) } - fn draw(&self, draw_ctx: &StereoKitDraw) { + fn draw(&self, draw_ctx: &impl StereoKitDraw) { let transform_mat = self.space.global_transform(); let data = self.data.lock().clone(); let mut points: VecDeque = data .points .iter() .map(|p| SkLinePoint { - point: transform_mat.transform_point3a(Vec3A::from(p.point)).into(), + pt: transform_mat.transform_point3a(Vec3A::from(p.point)).into(), thickness: p.thickness, color: p.color.map(|c| (c * 255.0) as u8).into(), }) @@ -72,20 +72,19 @@ impl Lines { if data.cyclic && !points.is_empty() { let first = data.points.first().unwrap(); let last = data.points.last().unwrap(); + let color = Rgba::from_slice(&first.color).lerp(&Rgba::from_slice(&last.color), 0.5); let connect_point = SkLinePoint { - point: transform_mat + pt: transform_mat .transform_point3a(Vec3A::from(first.point).lerp(Vec3A::from(last.point), 0.5)) .into(), thickness: (first.thickness + last.thickness) * 0.5, - color: Color128::from( - Rgba::from_slice(&first.color).lerp(&Rgba::from_slice(&last.color), 0.5), - ) - .into(), + color: Color128::from([color.red(), color.green(), color.blue(), color.alpha()]) + .into(), }; points.push_front(connect_point.clone()); points.push_back(connect_point); } - stereokit::lines::line_add_listv(draw_ctx, points.make_contiguous()); + draw_ctx.line_add_listv(points.make_contiguous()); } pub fn set_points_flex(node: &Node, _calling_client: Arc, data: &[u8]) -> Result<()> { @@ -113,7 +112,7 @@ impl Drop for Lines { } } -pub fn draw_all(draw_ctx: &StereoKitDraw) { +pub fn draw_all(draw_ctx: &impl StereoKitDraw) { for lines in LINES_REGISTRY.get_valid_contents() { if lines.enabled.load(Ordering::Relaxed) { lines.draw(draw_ctx); diff --git a/src/nodes/drawable/mod.rs b/src/nodes/drawable/mod.rs index 9a40ee1..8fac3e0 100644 --- a/src/nodes/drawable/mod.rs +++ b/src/nodes/drawable/mod.rs @@ -11,7 +11,7 @@ use parking_lot::Mutex; use serde::Deserialize; use stardust_xr::schemas::flex::deserialize; use std::{path::PathBuf, sync::Arc}; -use stereokit::{lifecycle::StereoKitDraw, render::StereoKitRender, texture::Texture}; +use stereokit::StereoKitDraw; use tracing::instrument; pub fn create_interface(client: &Arc) -> Result<()> { @@ -30,31 +30,19 @@ pub enum Drawable { } #[instrument(level = "debug", skip(sk))] -pub fn draw(sk: &StereoKitDraw) { +pub fn draw(sk: &impl StereoKitDraw) { lines::draw_all(sk); model::draw_all(sk); text::draw_all(sk); - let new_skytex = QUEUED_SKYTEX.lock().take(); - let mut new_skylight = QUEUED_SKYLIGHT.lock().take(); - let same_file = new_skytex == new_skylight; - - if let Some(skytex) = new_skytex { - if let Some((skytex, skylight)) = - Texture::from_cubemap_equirectangular(sk, &skytex, true, i32::MAX) - { - sk.set_skytex(&skytex); - if same_file { - sk.set_skylight(&skylight); - new_skylight = None; - } + if let Some(skytex) = QUEUED_SKYTEX.lock().take() { + if let Ok((_skylight, skytex)) = sk.tex_create_cubemap_file(&skytex, true, i32::MAX) { + sk.render_set_skytex(&skytex); } } - if let Some(skylight) = new_skylight { - if let Some((_, skylight)) = - Texture::from_cubemap_equirectangular(sk, &skylight, true, i32::MAX) - { - sk.set_skylight(&skylight); + if let Some(skylight) = QUEUED_SKYLIGHT.lock().take() { + if let Ok((skylight, _)) = sk.tex_create_cubemap_file(&skylight, true, i32::MAX) { + sk.render_set_skylight(skylight); } } } diff --git a/src/nodes/drawable/model.rs b/src/nodes/drawable/model.rs index b44eeff..4bb0184 100644 --- a/src/nodes/drawable/model.rs +++ b/src/nodes/drawable/model.rs @@ -6,6 +6,7 @@ use crate::core::resource::ResourceID; use crate::nodes::drawable::Drawable; use crate::nodes::spatial::{find_spatial_parent, parse_transform, Spatial}; use color_eyre::eyre::{bail, ensure, eyre, Result}; +use glam::Mat4; use mint::{ColumnMatrix4, Vector2, Vector3, Vector4}; use once_cell::sync::OnceCell; use parking_lot::Mutex; @@ -19,13 +20,10 @@ use std::ffi::OsStr; use std::fmt::Error; use std::path::PathBuf; use std::sync::Arc; -use stereokit::color_named::WHITE; -use stereokit::lifecycle::{StereoKitContext, StereoKitDraw}; -use stereokit::material::Material; -use stereokit::model::Model as SKModel; -use stereokit::render::RenderLayer; -use stereokit::texture::Texture; -use stereokit::values::Color128; +use stereokit::named_colors::WHITE; +use stereokit::{ + Color128, Material, Model as SKModel, RenderLayer, Shader, StereoKitDraw, StereoKitMultiThread, +}; static MODEL_REGISTRY: Registry = Registry::new(); @@ -53,63 +51,63 @@ impl MaterialParameter { fn apply_to_material( &self, client: &Client, - sk: &impl StereoKitContext, + sk: &impl StereoKitMultiThread, material: &Material, parameter_name: &str, ) { match self { MaterialParameter::Float(val) => { - material.set_parameter(sk, parameter_name, val); + sk.material_set_float(material, parameter_name, *val); } MaterialParameter::Vector2(val) => { - material.set_parameter(sk, parameter_name, val); + sk.material_set_vector2(material, parameter_name, *val); } MaterialParameter::Vector3(val) => { - material.set_parameter(sk, parameter_name, val); + sk.material_set_vector3(material, parameter_name, *val); } MaterialParameter::Vector4(val) => { - material.set_parameter(sk, parameter_name, val); + sk.material_set_vector4(material, parameter_name, *val); } MaterialParameter::Color(val) => { - material.set_parameter(sk, parameter_name, &Color128::from(val.clone())); + sk.material_set_color(material, parameter_name, Color128::from(val.clone())); } MaterialParameter::Int(val) => { - material.set_parameter(sk, parameter_name, val); + sk.material_set_int(material, parameter_name, *val); } MaterialParameter::Int2(val) => { - material.set_parameter(sk, parameter_name, val); + sk.material_set_int2(material, parameter_name, val.x, val.y); } MaterialParameter::Int3(val) => { - material.set_parameter(sk, parameter_name, val); + sk.material_set_int3(material, parameter_name, val.x, val.y, val.z); } MaterialParameter::Int4(val) => { - material.set_parameter(sk, parameter_name, val); + sk.material_set_int4(material, parameter_name, val.w, val.x, val.y, val.z); } MaterialParameter::Bool(val) => { - material.set_parameter(sk, parameter_name, val); + sk.material_set_bool(material, parameter_name, *val); } MaterialParameter::UInt(val) => { - material.set_parameter(sk, parameter_name, val); + sk.material_set_uint(material, parameter_name, *val); } MaterialParameter::UInt2(val) => { - material.set_parameter(sk, parameter_name, val); + sk.material_set_uint2(material, parameter_name, val.x, val.y); } MaterialParameter::UInt3(val) => { - material.set_parameter(sk, parameter_name, val); + sk.material_set_uint3(material, parameter_name, val.x, val.y, val.z); } MaterialParameter::UInt4(val) => { - material.set_parameter(sk, parameter_name, val); + sk.material_set_uint4(material, parameter_name, val.w, val.x, val.y, val.z); } MaterialParameter::Matrix(val) => { - material.set_parameter(sk, parameter_name, val); + sk.material_set_matrix(material, parameter_name, Mat4::from(*val)); } MaterialParameter::Texture(resource) => { let Some(texture_path) = resource.get_file( &client.base_resource_prefixes.lock().clone(), &[OsStr::new("png"), OsStr::new("jpg")], ) else {return}; - if let Some(tex) = Texture::from_file(sk, texture_path, true, 0) { - material.set_parameter(sk, parameter_name, &tex); + if let Ok(tex) = sk.tex_create_file(texture_path, true, 0) { + sk.material_set_texture(material, parameter_name, &tex); } } } @@ -188,14 +186,15 @@ impl Model { Ok(()) } - fn draw(&self, sk: &StereoKitDraw) { + fn draw(&self, sk: &impl StereoKitDraw) { let sk_model = self .sk_model .get_or_try_init(|| -> color_eyre::eyre::Result> { let pending_model_path = self.pending_model_path.get().ok_or(Error)?; - let model = SKModel::from_file(sk, pending_model_path.as_path(), None)?; + let model = + sk.model_create_file(pending_model_path.to_str().unwrap(), None::)?; - Ok(SendWrapper::new(model.clone())) + Ok(SendWrapper::new(sk.model_copy(model))) }) .ok(); @@ -203,8 +202,15 @@ impl Model { { let mut material_replacements = self.pending_material_replacements.lock(); for (material_idx, replacement_material) in material_replacements.iter() { - if sk_model.get_material(sk, *material_idx as i32).is_some() { - sk_model.set_material(sk, *material_idx as i32, replacement_material); + if sk + .model_get_material(sk_model.as_ref(), *material_idx as i32) + .is_some() + { + sk.model_set_material( + sk_model.as_ref(), + *material_idx as i32, + replacement_material.as_ref().as_ref(), + ); } } material_replacements.clear(); @@ -214,20 +220,24 @@ impl Model { let mut material_parameters = self.pending_material_parameters.lock(); for ((material_idx, parameter_name), parameter_value) in material_parameters.drain() { - let Some(material) = sk_model.get_material(sk, material_idx) else {continue}; - let new_material = material.clone(); + let Some(material) = sk.model_get_material(sk_model.as_ref(), material_idx) else {continue}; + let new_material = sk.material_copy(material); parameter_value.apply_to_material( &client, sk, &new_material, parameter_name.as_str(), ); - sk_model.set_material(sk, material_idx, &new_material); + sk.model_set_material(sk_model.as_ref(), material_idx, &new_material); } } - let global_transform = self.space.global_transform().into(); - sk_model.draw(sk, global_transform, WHITE, RenderLayer::Layer0); + sk.model_draw( + sk_model.as_ref(), + self.space.global_transform(), + WHITE, + RenderLayer::LAYER0, + ); } } } @@ -240,7 +250,7 @@ impl Drop for Model { } } -pub fn draw_all(sk: &StereoKitDraw) { +pub fn draw_all(sk: &impl StereoKitDraw) { for model in MODEL_REGISTRY.get_valid_contents() { if model.enabled.load(Ordering::Relaxed) { model.draw(sk); diff --git a/src/nodes/drawable/text.rs b/src/nodes/drawable/text.rs index 41f94c4..cefd5fa 100644 --- a/src/nodes/drawable/text.rs +++ b/src/nodes/drawable/text.rs @@ -17,13 +17,7 @@ use send_wrapper::SendWrapper; use serde::Deserialize; use stardust_xr::{schemas::flex::deserialize, values::Transform}; use std::{ffi::OsStr, path::PathBuf, sync::Arc}; -use stereokit::{ - color_named::WHITE, - font::Font, - lifecycle::StereoKitDraw, - text::{self, TextAlign, TextFit, TextStyle}, - values::Color128, -}; +use stereokit::{named_colors::WHITE, Color128, StereoKitDraw, TextAlign, TextFit, TextStyle}; static TEXT_REGISTRY: Registry = Registry::new(); @@ -96,15 +90,17 @@ impl Text { Ok(text) } - fn draw(&self, sk: &StereoKitDraw) { + fn draw(&self, sk: &impl StereoKitDraw) { let style = self.style.get_or_try_init( || -> Result, color_eyre::eyre::Error> { let font = self .font_path .as_deref() - .and_then(|path| Font::from_file(sk, path)) - .unwrap_or_else(|| Font::default(sk)); - Ok(SendWrapper::new(TextStyle::new(sk, font, 1.0, WHITE))) + .and_then(|path| sk.font_create(path).ok()) + .unwrap_or_else(|| sk.font_find("default/font").unwrap()); + Ok(SendWrapper::new(unsafe { + sk.text_make_style(font, 1.0, WHITE) + })) }, ); @@ -117,28 +113,36 @@ impl Text { data.character_height, )); if let Some(bounds) = data.bounds { - text::draw_in( - sk, + sk.text_add_in( &data.text, transform, bounds / data.character_height, data.fit, - style, + **style, data.bounds_align, data.text_align, vec3(0.0, 0.0, 0.0), - Color128::from(data.color), + Color128::from([ + data.color.red(), + data.color.green(), + data.color.blue(), + data.color.alpha(), + ]), ); } else { - text::draw_at( - sk, + sk.text_add_at( &data.text, transform, - style, + **style, data.bounds_align, data.text_align, vec3(0.0, 0.0, 0.0), - data.color, + Color128::from([ + data.color.red(), + data.color.green(), + data.color.blue(), + data.color.alpha(), + ]), ); } } @@ -171,7 +175,7 @@ impl Drop for Text { } } -pub fn draw_all(sk: &StereoKitDraw) { +pub fn draw_all(sk: &impl StereoKitDraw) { for text in TEXT_REGISTRY.get_valid_contents() { if text.enabled.load(Ordering::Relaxed) { text.draw(sk); diff --git a/src/nodes/hmd.rs b/src/nodes/hmd.rs index 5d94064..4384abf 100644 --- a/src/nodes/hmd.rs +++ b/src/nodes/hmd.rs @@ -6,7 +6,7 @@ use crate::{ use color_eyre::eyre::Result; use glam::{vec3, Mat4}; use std::sync::Arc; -use stereokit::input::StereoKitInput; +use stereokit::StereoKitMultiThread; use tracing::instrument; lazy_static::lazy_static! { @@ -21,7 +21,7 @@ fn create() -> Arc { } #[instrument(level = "debug", name = "Update HMD Pose", skip(sk))] -pub fn frame(sk: &impl StereoKitInput) { +pub fn frame(sk: &impl StereoKitMultiThread) { let spatial = HMD .spatial .get() diff --git a/src/nodes/items/mod.rs b/src/nodes/items/mod.rs index 252ce4a..e73c62f 100644 --- a/src/nodes/items/mod.rs +++ b/src/nodes/items/mod.rs @@ -186,7 +186,7 @@ impl Deref for ItemType { match self { ItemType::Environment(item) => item, #[cfg(feature = "wayland")] - ItemType::Panel(item) => &**item, + ItemType::Panel(item) => item.as_ref(), } } } diff --git a/src/objects/input/mouse_pointer.rs b/src/objects/input/mouse_pointer.rs index b308a67..8968b86 100644 --- a/src/objects/input/mouse_pointer.rs +++ b/src/objects/input/mouse_pointer.rs @@ -14,8 +14,7 @@ use nanoid::nanoid; use serde::Serialize; use stardust_xr::schemas::{flat::Datamap, flex::flexbuffers}; use std::{convert::TryFrom, sync::Arc}; -use stereokit::input::{ButtonState, Key, StereoKitInput}; -use stereokit::values::Ray as SkRay; +use stereokit::{ray_from_mouse, ButtonState, Key, StereoKitMultiThread}; use tracing::instrument; const SK_KEYMAP: &str = include_str!("sk.kmp"); @@ -58,10 +57,10 @@ impl MousePointer { }) } #[instrument(level = "debug", name = "Update Flatscreen Pointer Ray", skip_all)] - pub fn update(&self, sk: &impl StereoKitInput) { + pub fn update(&self, sk: &impl StereoKitMultiThread) { let mouse = sk.input_mouse(); - let ray = SkRay::from_mouse(&mouse); + let ray = ray_from_mouse(mouse.pos).unwrap(); self.spatial.set_local_transform( Mat4::look_to_rh(ray.pos.into(), -Vec3::from(ray.dir), vec3(0.0, 1.0, 0.0)).inverse(), ); @@ -71,7 +70,7 @@ impl MousePointer { let mut map = fbb.start_map(); map.push( "select", - if sk.input_key(Key::MouseLeft).contains(ButtonState::Active) { + if sk.input_key(Key::MouseLeft).contains(ButtonState::ACTIVE) { 1.0f32 } else { 0.0f32 @@ -79,7 +78,7 @@ impl MousePointer { ); map.push( "grab", - if sk.input_key(Key::MouseRight).contains(ButtonState::Active) { + if sk.input_key(Key::MouseRight).contains(ButtonState::ACTIVE) { 1.0f32 } else { 0.0f32 @@ -95,7 +94,7 @@ impl MousePointer { self.send_keyboard_input(sk); } - fn send_keyboard_input(&self, sk: &impl StereoKitInput) { + fn send_keyboard_input(&self, sk: &impl StereoKitMultiThread) { let rx = PULSE_RECEIVER_REGISTRY .get_valid_contents() .into_iter() @@ -127,9 +126,9 @@ impl MousePointer { .filter_map(|i| Some((i, Key::try_from(i).ok()?))) .map(|(i, k)| (i - 8, sk.input_key(k))); for (key, state) in keys { - if state.contains(ButtonState::JustActive) { + if state.contains(ButtonState::JUST_ACTIVE) { keys_down.push(key); - } else if state.contains(ButtonState::JustInactive) { + } else if state.contains(ButtonState::JUST_INACTIVE) { keys_up.push(key); } } diff --git a/src/objects/input/sk_controller.rs b/src/objects/input/sk_controller.rs index b3dc9d5..43cb52f 100644 --- a/src/objects/input/sk_controller.rs +++ b/src/objects/input/sk_controller.rs @@ -14,7 +14,7 @@ use stardust_xr::{ values::Transform, }; use std::sync::Arc; -use stereokit::input::{ButtonState, Handed, StereoKitInput}; +use stereokit::{ButtonState, Handed, StereoKitMultiThread}; use tracing::instrument; pub struct SkController { @@ -35,9 +35,9 @@ impl SkController { }) } #[instrument(level = "debug", name = "Update StereoKit Tip Input Method", skip_all)] - pub fn update(&mut self, sk: &impl StereoKitInput) { + pub fn update(&mut self, sk: &impl StereoKitMultiThread) { let controller = sk.input_controller(self.handed); - *self.input.enabled.lock() = controller.tracked.contains(ButtonState::Active); + *self.input.enabled.lock() = controller.tracked.contains(ButtonState::ACTIVE); if *self.input.enabled.lock() { self.input.spatial.set_local_transform_components( None, diff --git a/src/objects/input/sk_hand.rs b/src/objects/input/sk_hand.rs index fcb98d7..b1fa253 100644 --- a/src/objects/input/sk_hand.rs +++ b/src/objects/input/sk_hand.rs @@ -14,16 +14,13 @@ use stardust_xr::schemas::{ flex::flexbuffers, }; use std::sync::Arc; -use stereokit::{ - input::{ButtonState, Handed, Joint as SkJoint, StereoKitInput}, - lifecycle::StereoKitDraw, -}; +use stereokit::{ButtonState, HandJoint, Handed, StereoKitMultiThread}; use tracing::instrument; -fn convert_joint(joint: SkJoint) -> Joint { +fn convert_joint(joint: HandJoint) -> Joint { Joint { - position: joint.position, - rotation: joint.orientation, + position: joint.position.into(), + rotation: joint.orientation.into(), radius: joint.radius, } } @@ -51,12 +48,12 @@ impl SkHand { }) } #[instrument(level = "debug", name = "Update Hand Input Method", skip_all)] - pub fn update(&mut self, sk: &StereoKitDraw) { + pub fn update(&mut self, sk: &impl StereoKitMultiThread) { let sk_hand = sk.input_hand(self.handed); if let InputType::Hand(hand) = &mut *self.input.specialization.lock() { let controller = sk.input_controller(self.handed); - *self.input.enabled.lock() = controller.tracked.contains(ButtonState::Inactive) - && sk_hand.tracked_state.contains(ButtonState::Active); + *self.input.enabled.lock() = controller.tracked.contains(ButtonState::ACTIVE) + && sk_hand.tracked_state.contains(ButtonState::ACTIVE); if *self.input.enabled.lock() { hand.base.thumb.tip = convert_joint(sk_hand.fingers[0][4]); hand.base.thumb.distal = convert_joint(sk_hand.fingers[0][3]); @@ -76,13 +73,13 @@ impl SkHand { finger.metacarpal = convert_joint(sk_finger[0]); } - hand.base.palm.position = sk_hand.palm.position; - hand.base.palm.rotation = sk_hand.palm.orientation; + hand.base.palm.position = sk_hand.palm.position.into(); + hand.base.palm.rotation = sk_hand.palm.orientation.into(); hand.base.palm.radius = (sk_hand.fingers[2][0].radius + sk_hand.fingers[2][1].radius) * 0.5; - hand.base.wrist.position = sk_hand.wrist.position; - hand.base.wrist.rotation = sk_hand.wrist.orientation; + hand.base.wrist.position = sk_hand.wrist.position.into(); + hand.base.wrist.rotation = sk_hand.wrist.orientation.into(); hand.base.wrist.radius = (sk_hand.fingers[0][0].radius + sk_hand.fingers[4][0].radius) * 0.5; diff --git a/src/wayland/mod.rs b/src/wayland/mod.rs index 09a5f07..c534ec9 100644 --- a/src/wayland/mod.rs +++ b/src/wayland/mod.rs @@ -15,7 +15,7 @@ use color_eyre::eyre::{ensure, Result}; use global_counter::primitive::exact::CounterU32; use once_cell::sync::OnceCell; use parking_lot::Mutex; -use sk::lifecycle::StereoKitDraw; +use sk::StereoKitDraw; use smithay::backend::egl::EGLContext; use smithay::backend::renderer::gles::GlesRenderer; use smithay::reexports::wayland_server::{backend::GlobalId, Display, ListeningSocket}; @@ -149,7 +149,7 @@ impl Wayland { } #[instrument(level = "debug", name = "Wayland frame", skip(self, sk))] - pub fn update(&mut self, sk: &StereoKitDraw) { + pub fn update(&mut self, sk: &impl StereoKitDraw) { for core_surface in CORE_SURFACES.get_valid_contents() { core_surface.process(sk, &mut self.renderer); } @@ -157,7 +157,7 @@ impl Wayland { self.display.lock().flush_clients().unwrap(); } - pub fn frame_event(&self, sk: &StereoKitDraw) { + pub fn frame_event(&self, sk: &impl StereoKitDraw) { let state = self.state.lock(); for core_surface in CORE_SURFACES.get_valid_contents() { diff --git a/src/wayland/surface.rs b/src/wayland/surface.rs index 2e07d88..2816482 100644 --- a/src/wayland/surface.rs +++ b/src/wayland/surface.rs @@ -21,15 +21,13 @@ use smithay::{ wayland::compositor::{self, SurfaceData}, }; use std::{ + ffi::c_void, sync::{Arc, Weak}, time::Duration, }; use stereokit::{ - lifecycle::StereoKitDraw, - material::{Material, Transparency}, - shader::Shader, - texture::{Texture as SKTexture, TextureAddress, TextureFormat, TextureSample, TextureType}, - time::StereoKitTime, + Material, StereoKitDraw, Tex, TextureAddress, TextureFormat, TextureSample, TextureType, + Transparency, }; pub static CORE_SURFACES: Registry = Registry::new(); @@ -49,7 +47,7 @@ pub struct CoreSurface { pub dh: DisplayHandle, pub weak_surface: wayland_server::Weak, mapped_data: Mutex>, - sk_tex: OnceCell>, + sk_tex: OnceCell>, sk_mat: OnceCell>>, material_offset: Mutex>, on_commit: Box, @@ -90,19 +88,17 @@ impl CoreSurface { }) } - pub fn process(&self, sk: &StereoKitDraw, renderer: &mut GlesRenderer) { + pub fn process(&self, sk: &impl StereoKitDraw, renderer: &mut GlesRenderer) { let Some(wl_surface) = self.wl_surface() else { return }; let sk_tex = self.sk_tex.get_or_init(|| { - SendWrapper::new( - SKTexture::create(sk, TextureType::ImageNoMips, TextureFormat::RGBA32).unwrap(), - ) + SendWrapper::new(sk.tex_create(TextureType::IMAGE_NO_MIPS, TextureFormat::RGBA32)) }); self.sk_mat.get_or_init(|| { - let shader = Shader::from_mem(sk, PANEL_SHADER_BYTES).unwrap(); - let mat = Material::create(sk, &shader).unwrap(); - mat.set_parameter(sk, "diffuse", &**sk_tex); - mat.set_transparency(sk, Transparency::Blend); + let shader = sk.shader_create_mem(&PANEL_SHADER_BYTES).unwrap(); + let mat = sk.material_create(&shader); + sk.material_set_texture(&mat, "diffuse", sk_tex.as_ref()); + sk.material_set_transparency(&mat, Transparency::Blend); Arc::new(SendWrapper::new(mat)) }); @@ -141,19 +137,21 @@ impl CoreSurface { let sk_tex = self.sk_tex.get().unwrap(); let sk_mat = self.sk_mat.get().unwrap(); unsafe { - sk_tex.set_native( - smithay_tex.tex_id() as usize, + sk.tex_set_surface( + sk_tex.as_ref(), + smithay_tex.tex_id() as usize as *mut c_void, + TextureType::IMAGE_NO_MIPS, smithay::backend::renderer::gles::ffi::RGBA8.into(), - TextureType::ImageNoMips, - smithay_tex.width(), - smithay_tex.height(), + smithay_tex.width() as i32, + smithay_tex.height() as i32, + 1, false, ); - sk_tex.set_sample(TextureSample::Point); - sk_tex.set_address_mode(TextureAddress::Clamp); + sk.tex_set_sample(sk_tex.as_ref(), TextureSample::Point); + sk.tex_set_address(sk_tex.as_ref(), TextureAddress::Clamp); } if let Some(material_offset) = self.material_offset.lock().delta() { - sk_mat.set_queue_offset(sk, *material_offset as i32); + sk.material_set_queue_offset(sk_mat.as_ref().as_ref(), *material_offset as i32); } let surface_size = renderer_surface_state.surface_size().unwrap(); @@ -166,7 +164,7 @@ impl CoreSurface { self.apply_surface_materials(); } - pub fn frame(&self, sk: &StereoKitDraw, output: Output) { + pub fn frame(&self, sk: &impl StereoKitDraw, output: Output) { let Some(wl_surface) = self.wl_surface() else { return }; send_frames_surface_tree(