feat: update stereokit
This commit is contained in:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user