feat: update stereokit
This commit is contained in:
@@ -44,8 +44,8 @@ global_counter = "0.2.2"
|
||||
|
||||
[dependencies.stereokit]
|
||||
default-features = false
|
||||
features = ["linux-egl"]
|
||||
version = "0.9.0"
|
||||
features = ["linux-egl", "color_named", "prisma"]
|
||||
version = "0.10.0"
|
||||
|
||||
[dependencies.smithay]
|
||||
git = "https://github.com/technobaboo/smithay.git" # Until we get stereokit to understand OES samplers and external textures
|
||||
|
||||
10
src/main.rs
10
src/main.rs
@@ -17,9 +17,11 @@ use directories::ProjectDirs;
|
||||
use std::sync::Arc;
|
||||
use stereokit::input::Handed;
|
||||
use stereokit::lifecycle::DepthMode;
|
||||
use stereokit::lifecycle::DisplayMode;
|
||||
use stereokit::render::SphericalHarmonics;
|
||||
use stereokit::render::StereoKitRender;
|
||||
use stereokit::texture::Texture;
|
||||
use stereokit::{lifecycle::DisplayMode, Settings};
|
||||
use stereokit::time::StereoKitTime;
|
||||
use tokio::{runtime::Handle, sync::oneshot};
|
||||
use tracing::info;
|
||||
|
||||
@@ -44,7 +46,7 @@ fn main() -> Result<()> {
|
||||
let project_dirs = ProjectDirs::from("", "", "stardust").unwrap();
|
||||
let cli_args = Arc::new(CliArgs::parse());
|
||||
|
||||
let mut stereokit = Settings::default()
|
||||
let stereokit = stereokit::Settings::default()
|
||||
.app_name("Stardust XR")
|
||||
.overlay_app(cli_args.overlay_priority.is_some())
|
||||
.overlay_priority(cli_args.overlay_priority.unwrap_or(u32::MAX))
|
||||
@@ -108,7 +110,7 @@ fn main() -> Result<()> {
|
||||
let mut wayland = wayland::Wayland::new()?;
|
||||
info!("Stardust ready!");
|
||||
stereokit.run(
|
||||
|sk, draw_ctx| {
|
||||
|sk| {
|
||||
hmd::frame(sk);
|
||||
#[cfg(feature = "wayland")]
|
||||
wayland.frame(sk);
|
||||
@@ -127,7 +129,7 @@ fn main() -> Result<()> {
|
||||
}
|
||||
input::process_input();
|
||||
nodes::root::Root::logic_step(sk.time_elapsed());
|
||||
drawable::draw(sk, draw_ctx);
|
||||
drawable::draw(sk);
|
||||
|
||||
#[cfg(feature = "wayland")]
|
||||
wayland.make_context_current();
|
||||
|
||||
@@ -9,11 +9,11 @@ use color_eyre::eyre::{ensure, Result};
|
||||
use glam::Vec3A;
|
||||
use mint::Vector3;
|
||||
use parking_lot::Mutex;
|
||||
use prisma::{Flatten, Lerp};
|
||||
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::DrawContext, lines::LinePoint as SkLinePoint, values::Color32};
|
||||
use stereokit::{lifecycle::StereoKitDraw, lines::LinePoint as SkLinePoint, values::Color128};
|
||||
|
||||
static LINES_REGISTRY: Registry<Lines> = Registry::new();
|
||||
|
||||
@@ -52,21 +52,21 @@ impl Lines {
|
||||
Ok(lines)
|
||||
}
|
||||
|
||||
fn draw(&self, draw_ctx: &DrawContext) {
|
||||
fn draw(&self, draw_ctx: &StereoKitDraw) {
|
||||
let transform_mat = self.space.global_transform();
|
||||
let data = self.data.lock().clone();
|
||||
let mut points: VecDeque<SkLinePoint> = data
|
||||
.points
|
||||
.into_iter()
|
||||
.iter()
|
||||
.map(|p| SkLinePoint {
|
||||
point: transform_mat.transform_point3a(Vec3A::from(p.point)).into(),
|
||||
thickness: p.thickness,
|
||||
color: Color32::from_slice(p.color.map(|c| (c * 255.0) as u8).as_slice()),
|
||||
color: p.color.map(|c| (c * 255.0) as u8).into(),
|
||||
})
|
||||
.collect();
|
||||
if data.cyclic && !points.is_empty() {
|
||||
let first = points.front().unwrap();
|
||||
let last = points.back().unwrap();
|
||||
let first = data.points.first().unwrap();
|
||||
let last = data.points.last().unwrap();
|
||||
let connect_point = SkLinePoint {
|
||||
point: Vector3 {
|
||||
x: (first.point.x + last.point.x) * 0.5,
|
||||
@@ -74,7 +74,10 @@ impl Lines {
|
||||
z: (first.point.z + last.point.z) * 0.5,
|
||||
},
|
||||
thickness: (first.thickness + last.thickness) * 0.5,
|
||||
color: first.color.lerp(&last.color, 0.5),
|
||||
color: Color128::from(
|
||||
Rgba::from_slice(&first.color).lerp(&Rgba::from_slice(&last.color), 0.5),
|
||||
)
|
||||
.into(),
|
||||
};
|
||||
points.push_front(connect_point.clone());
|
||||
points.push_back(connect_point);
|
||||
@@ -103,7 +106,7 @@ impl Drop for Lines {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn draw_all(draw_ctx: &DrawContext) {
|
||||
pub fn draw_all(draw_ctx: &StereoKitDraw) {
|
||||
for lines in LINES_REGISTRY.get_valid_contents() {
|
||||
lines.draw(draw_ctx);
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ use parking_lot::Mutex;
|
||||
use serde::Deserialize;
|
||||
use stardust_xr::schemas::flex::deserialize;
|
||||
use std::{path::PathBuf, sync::Arc};
|
||||
use stereokit::{lifecycle::DrawContext, texture::Texture, StereoKit};
|
||||
use stereokit::{lifecycle::StereoKitDraw, render::StereoKitRender, texture::Texture};
|
||||
|
||||
pub fn create_interface(client: &Arc<Client>) {
|
||||
let node = Node::create(client, "", "drawable", false);
|
||||
@@ -20,10 +20,10 @@ pub fn create_interface(client: &Arc<Client>) {
|
||||
node.add_to_scenegraph();
|
||||
}
|
||||
|
||||
pub fn draw(sk: &mut StereoKit, draw_ctx: &DrawContext) {
|
||||
lines::draw_all(draw_ctx);
|
||||
model::draw_all(sk, draw_ctx);
|
||||
text::draw_all(sk, draw_ctx);
|
||||
pub fn draw(sk: &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();
|
||||
|
||||
@@ -7,7 +7,6 @@ use crate::nodes::spatial::{find_spatial_parent, parse_transform, Spatial};
|
||||
use color_eyre::eyre::{ensure, eyre, Result};
|
||||
use once_cell::sync::OnceCell;
|
||||
use parking_lot::Mutex;
|
||||
use prisma::{Rgb, Rgba};
|
||||
use rustc_hash::FxHashMap;
|
||||
use send_wrapper::SendWrapper;
|
||||
use serde::Deserialize;
|
||||
@@ -17,12 +16,12 @@ use std::ffi::OsStr;
|
||||
use std::fmt::Error;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::Arc;
|
||||
use stereokit::lifecycle::DrawContext;
|
||||
use stereokit::color_named::WHITE;
|
||||
use stereokit::lifecycle::StereoKitDraw;
|
||||
use stereokit::material::Material;
|
||||
use stereokit::model::Model as SKModel;
|
||||
use stereokit::render::RenderLayer;
|
||||
use stereokit::texture::Texture;
|
||||
use stereokit::StereoKit;
|
||||
|
||||
static MODEL_REGISTRY: Registry<Model> = Registry::new();
|
||||
|
||||
@@ -102,17 +101,14 @@ impl Model {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn draw(&self, sk: &StereoKit, draw_ctx: &DrawContext) {
|
||||
fn draw(&self, sk: &StereoKitDraw) {
|
||||
let sk_model = self
|
||||
.sk_model
|
||||
.get_or_try_init(|| {
|
||||
self.pending_model_path
|
||||
.get()
|
||||
.and_then(|path| SKModel::from_file(sk, path.as_path(), None))
|
||||
.as_ref()
|
||||
.cloned()
|
||||
.map(SendWrapper::new)
|
||||
.ok_or(Error)
|
||||
.get_or_try_init(|| -> color_eyre::eyre::Result<SendWrapper<SKModel>> {
|
||||
let pending_model_path = self.pending_model_path.get().ok_or(Error)?;
|
||||
let model = SKModel::from_file(sk, pending_model_path.as_path(), None)?;
|
||||
|
||||
Ok(SendWrapper::new(model.clone()))
|
||||
})
|
||||
.ok();
|
||||
|
||||
@@ -120,7 +116,7 @@ impl Model {
|
||||
{
|
||||
let mut material_replacements = self.pending_material_replacements.lock();
|
||||
for (material_idx, replacement_material) in material_replacements.iter() {
|
||||
sk_model.set_material(*material_idx as i32, replacement_material);
|
||||
sk_model.set_material(sk, *material_idx as i32, replacement_material);
|
||||
}
|
||||
material_replacements.clear();
|
||||
}
|
||||
@@ -133,7 +129,7 @@ impl Model {
|
||||
match parameter_value {
|
||||
MaterialParameter::Texture(path) => {
|
||||
if let Some(tex) = Texture::from_file(sk, path.as_path(), true, 0) {
|
||||
material.set_parameter(parameter_name.as_str(), &tex);
|
||||
material.set_parameter(sk, parameter_name.as_str(), &tex);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -143,12 +139,7 @@ impl Model {
|
||||
}
|
||||
|
||||
let global_transform = self.space.global_transform().into();
|
||||
sk_model.draw(
|
||||
draw_ctx,
|
||||
global_transform,
|
||||
Rgba::new(Rgb::new(1_f32, 1_f32, 1_f32), 1_f32),
|
||||
RenderLayer::Layer0,
|
||||
);
|
||||
sk_model.draw(sk, global_transform, WHITE, RenderLayer::Layer0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -161,9 +152,9 @@ impl Drop for Model {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn draw_all(sk: &StereoKit, draw_ctx: &DrawContext) {
|
||||
pub fn draw_all(sk: &StereoKitDraw) {
|
||||
for model in MODEL_REGISTRY.get_valid_contents() {
|
||||
model.draw(sk, draw_ctx);
|
||||
model.draw(sk);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,16 +10,17 @@ use glam::{vec3, Mat4, Vec2};
|
||||
use mint::Vector2;
|
||||
use once_cell::sync::OnceCell;
|
||||
use parking_lot::Mutex;
|
||||
use prisma::{Flatten, Rgb, Rgba};
|
||||
use prisma::{Flatten, Rgba};
|
||||
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::DrawContext,
|
||||
lifecycle::StereoKitDraw,
|
||||
text::{self, TextAlign, TextFit, TextStyle},
|
||||
StereoKit,
|
||||
values::Color128,
|
||||
};
|
||||
|
||||
static TEXT_REGISTRY: Registry<Text> = Registry::new();
|
||||
@@ -91,7 +92,7 @@ impl Text {
|
||||
Ok(text)
|
||||
}
|
||||
|
||||
fn draw(&self, sk: &StereoKit, draw_ctx: &DrawContext) {
|
||||
fn draw(&self, sk: &StereoKitDraw) {
|
||||
let style = self.style.get_or_try_init(
|
||||
|| -> Result<SendWrapper<TextStyle>, color_eyre::eyre::Error> {
|
||||
let font = self
|
||||
@@ -99,12 +100,7 @@ impl Text {
|
||||
.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,
|
||||
Rgba::new(Rgb::new(1.0, 1.0, 1.0), 1.0),
|
||||
)))
|
||||
Ok(SendWrapper::new(TextStyle::new(sk, font, 1.0, WHITE)))
|
||||
},
|
||||
);
|
||||
|
||||
@@ -118,7 +114,7 @@ impl Text {
|
||||
));
|
||||
if let Some(bounds) = data.bounds {
|
||||
text::draw_in(
|
||||
draw_ctx,
|
||||
sk,
|
||||
&data.text,
|
||||
transform,
|
||||
bounds / data.character_height,
|
||||
@@ -127,11 +123,11 @@ impl Text {
|
||||
data.bounds_align,
|
||||
data.text_align,
|
||||
vec3(0.0, 0.0, 0.0),
|
||||
data.color,
|
||||
Color128::from(data.color),
|
||||
);
|
||||
} else {
|
||||
text::draw_at(
|
||||
draw_ctx,
|
||||
sk,
|
||||
&data.text,
|
||||
transform,
|
||||
style,
|
||||
@@ -169,9 +165,9 @@ impl Drop for Text {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn draw_all(sk: &StereoKit, draw_ctx: &DrawContext) {
|
||||
pub fn draw_all(sk: &StereoKitDraw) {
|
||||
for text in TEXT_REGISTRY.get_valid_contents() {
|
||||
text.draw(sk, draw_ctx);
|
||||
text.draw(sk);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ use crate::{
|
||||
};
|
||||
use glam::{vec3, Mat4};
|
||||
use std::sync::Arc;
|
||||
use stereokit::StereoKit;
|
||||
use stereokit::input::StereoKitInput;
|
||||
|
||||
lazy_static::lazy_static! {
|
||||
static ref HMD: Arc<Node> = create();
|
||||
@@ -18,7 +18,7 @@ fn create() -> Arc<Node> {
|
||||
node
|
||||
}
|
||||
|
||||
pub fn frame(sk: &StereoKit) {
|
||||
pub fn frame(sk: &impl StereoKitInput) {
|
||||
let spatial = HMD.spatial.get().unwrap();
|
||||
let hmd_pose = sk.input_head();
|
||||
*spatial.transform.lock() = Mat4::from_scale_rotation_translation(
|
||||
|
||||
@@ -12,10 +12,7 @@ use glam::{vec3, Mat4};
|
||||
use nanoid::nanoid;
|
||||
use stardust_xr::{schemas::flat::Datamap, values::Transform};
|
||||
use std::{convert::TryFrom, sync::Arc};
|
||||
use stereokit::{
|
||||
input::{ButtonState, Key, Ray as SkRay},
|
||||
StereoKit,
|
||||
};
|
||||
use stereokit::input::{ButtonState, Key, Ray as SkRay, StereoKitInput};
|
||||
|
||||
const SK_KEYMAP: &str = include_str!("sk.kmp");
|
||||
|
||||
@@ -48,7 +45,7 @@ impl MousePointer {
|
||||
keyboard_sender,
|
||||
}
|
||||
}
|
||||
pub fn update(&self, sk: &StereoKit) {
|
||||
pub fn update(&self, sk: &impl StereoKitInput) {
|
||||
let mouse = sk.input_mouse();
|
||||
|
||||
if let Some(ray) = SkRay::from_mouse(mouse) {
|
||||
@@ -90,7 +87,7 @@ impl MousePointer {
|
||||
self.send_keyboard_input(sk);
|
||||
}
|
||||
|
||||
fn send_keyboard_input(&self, sk: &StereoKit) {
|
||||
fn send_keyboard_input(&self, sk: &impl StereoKitInput) {
|
||||
let rx = PULSE_RECEIVER_REGISTRY
|
||||
.get_valid_contents()
|
||||
.into_iter()
|
||||
|
||||
@@ -5,10 +5,7 @@ use crate::nodes::{
|
||||
use glam::Mat4;
|
||||
use stardust_xr::{schemas::flat::Datamap, values::Transform};
|
||||
use std::sync::{Arc, Weak};
|
||||
use stereokit::{
|
||||
input::{ButtonState, Handed},
|
||||
StereoKit,
|
||||
};
|
||||
use stereokit::input::{ButtonState, Handed, StereoKitInput};
|
||||
|
||||
pub struct SkController {
|
||||
tip: Arc<InputMethod>,
|
||||
@@ -24,7 +21,7 @@ impl SkController {
|
||||
handed,
|
||||
}
|
||||
}
|
||||
pub fn update(&mut self, sk: &StereoKit) {
|
||||
pub fn update(&mut self, sk: &impl StereoKitInput) {
|
||||
let controller = sk.input_controller(self.handed);
|
||||
*self.tip.enabled.lock() = controller.tracked.contains(ButtonState::Active);
|
||||
if *self.tip.enabled.lock() {
|
||||
|
||||
@@ -6,8 +6,8 @@ use glam::Mat4;
|
||||
use stardust_xr::schemas::flat::{Datamap, Hand as FlatHand, Joint};
|
||||
use std::sync::{Arc, Weak};
|
||||
use stereokit::{
|
||||
input::{ButtonState, Handed, Joint as SkJoint},
|
||||
StereoKit,
|
||||
input::{ButtonState, Handed, Joint as SkJoint, StereoKitInput},
|
||||
lifecycle::StereoKitDraw,
|
||||
};
|
||||
|
||||
fn convert_joint(joint: SkJoint) -> Joint {
|
||||
@@ -37,7 +37,7 @@ impl SkHand {
|
||||
handed,
|
||||
}
|
||||
}
|
||||
pub fn update(&mut self, sk: &StereoKit) {
|
||||
pub fn update(&mut self, sk: &StereoKitDraw) {
|
||||
let sk_hand = sk.input_hand(self.handed);
|
||||
if let InputType::Hand(hand) = &mut *self.hand.specialization.lock() {
|
||||
let controller = sk.input_controller(self.handed);
|
||||
|
||||
@@ -15,6 +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 slog::Drain;
|
||||
use smithay::{
|
||||
backend::{egl::EGLContext, renderer::gles2::Gles2Renderer},
|
||||
@@ -27,7 +28,6 @@ use std::{
|
||||
sync::Arc,
|
||||
};
|
||||
use stereokit as sk;
|
||||
use stereokit::StereoKit;
|
||||
use tokio::{
|
||||
io::unix::AsyncFd, net::UnixListener as AsyncUnixListener, sync::mpsc, task::JoinHandle,
|
||||
};
|
||||
@@ -148,7 +148,7 @@ impl Wayland {
|
||||
}))
|
||||
}
|
||||
|
||||
pub fn frame(&mut self, sk: &StereoKit) {
|
||||
pub fn frame(&mut self, sk: &StereoKitDraw) {
|
||||
for core_surface in CORE_SURFACES.get_valid_contents() {
|
||||
let state = self.state.lock();
|
||||
let output = state.output.clone();
|
||||
|
||||
@@ -26,10 +26,11 @@ use std::{
|
||||
time::Duration,
|
||||
};
|
||||
use stereokit::{
|
||||
lifecycle::StereoKitDraw,
|
||||
material::{Material, Transparency},
|
||||
shader::Shader,
|
||||
texture::{Texture as SKTexture, TextureAddress, TextureFormat, TextureSample, TextureType},
|
||||
StereoKit,
|
||||
time::StereoKitTime,
|
||||
};
|
||||
|
||||
pub static CORE_SURFACES: Registry<CoreSurface> = Registry::new();
|
||||
@@ -104,7 +105,7 @@ impl CoreSurface {
|
||||
|
||||
pub fn process(
|
||||
&self,
|
||||
sk: &StereoKit,
|
||||
sk: &StereoKitDraw,
|
||||
renderer: &mut Gles2Renderer,
|
||||
output: Output,
|
||||
log: &Logger,
|
||||
@@ -119,8 +120,8 @@ impl CoreSurface {
|
||||
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("diffuse", &**sk_tex);
|
||||
mat.set_transparency(Transparency::Blend);
|
||||
mat.set_parameter(sk, "diffuse", &**sk_tex);
|
||||
mat.set_transparency(sk, Transparency::Blend);
|
||||
Arc::new(SendWrapper::new(mat))
|
||||
});
|
||||
|
||||
@@ -171,7 +172,7 @@ impl CoreSurface {
|
||||
sk_tex.set_address_mode(TextureAddress::Clamp);
|
||||
}
|
||||
if let Some(material_offset) = self.material_offset.lock().delta() {
|
||||
sk_mat.set_queue_offset(*material_offset as i32);
|
||||
sk_mat.set_queue_offset(sk, *material_offset as i32);
|
||||
}
|
||||
// if let Some(geometry) = self.geometry.lock().delta().cloned().unwrap_or_default() {
|
||||
// let buffer_size = renderer_surface_state.buffer_size().unwrap();
|
||||
|
||||
Reference in New Issue
Block a user