refactor use bevy_sk material and hands
Signed-off-by: Schmarni <marnistromer@gmail.com>
This commit is contained in:
11
Cargo.toml
11
Cargo.toml
@@ -57,10 +57,15 @@ bevy = { version = "0.15.1", features = [
|
|||||||
"wav",
|
"wav",
|
||||||
"trace_tracy",
|
"trace_tracy",
|
||||||
] }
|
] }
|
||||||
bevy_mod_xr = { git = "https://github.com/Schmarni-Dev/bevy_openxr", branch = "wgpu_feature_fix" }
|
bevy_mod_xr.git = "https://github.com/awtterpip/bevy_oxr"
|
||||||
bevy_mod_openxr = { git = "https://github.com/Schmarni-Dev/bevy_openxr", branch = "wgpu_feature_fix" }
|
bevy_mod_openxr.git = "https://github.com/awtterpip/bevy_oxr"
|
||||||
bevy_xr_utils = { git = "https://github.com/Schmarni-Dev/bevy_openxr", branch = "wgpu_feature_fix" }
|
bevy_xr_utils.git = "https://github.com/awtterpip/bevy_oxr"
|
||||||
|
# bevy_mod_xr = { git = "https://github.com/Schmarni-Dev/bevy_openxr", branch = "pbr" }
|
||||||
|
# bevy_mod_openxr = { git = "https://github.com/Schmarni-Dev/bevy_openxr", branch = "pbr" }
|
||||||
|
# bevy_xr_utils = { git = "https://github.com/Schmarni-Dev/bevy_openxr", branch = "pbr" }
|
||||||
bevy_mod_meshtext.git = "https://github.com/Schmarni-Dev/bevy_mod_meshtext"
|
bevy_mod_meshtext.git = "https://github.com/Schmarni-Dev/bevy_mod_meshtext"
|
||||||
|
# bevy_sk.path = "../bevy_sk"
|
||||||
|
bevy_sk.git = "https://github.com/MalekiRe/bevy_sk"
|
||||||
openxr = "0.19"
|
openxr = "0.19"
|
||||||
winit = { version = "0.30", default-features = false, features = [] }
|
winit = { version = "0.30", default-features = false, features = [] }
|
||||||
# small utility thingys
|
# small utility thingys
|
||||||
|
|||||||
@@ -4,7 +4,9 @@ use bevy::{
|
|||||||
app::MainScheduleOrder,
|
app::MainScheduleOrder,
|
||||||
ecs::schedule::{ExecutorKind, ScheduleLabel},
|
ecs::schedule::{ExecutorKind, ScheduleLabel},
|
||||||
math::bounding::Aabb3d,
|
math::bounding::Aabb3d,
|
||||||
|
pbr::{DefaultOpaqueRendererMethod, GpuMeshPreprocessPlugin, MeshRenderPlugin},
|
||||||
prelude::*,
|
prelude::*,
|
||||||
|
render::extract_resource::ExtractResourcePlugin,
|
||||||
};
|
};
|
||||||
use bevy_mod_openxr::session::OxrSession;
|
use bevy_mod_openxr::session::OxrSession;
|
||||||
use bevy_mod_xr::session::{session_available, XrFirst, XrSessionCreated};
|
use bevy_mod_xr::session::{session_available, XrFirst, XrSessionCreated};
|
||||||
@@ -12,6 +14,8 @@ use once_cell::sync::OnceCell;
|
|||||||
use openxr::ReferenceSpaceType;
|
use openxr::ReferenceSpaceType;
|
||||||
use stardust_xr::values::color::{color_space::LinearRgb, AlphaColor, Rgb};
|
use stardust_xr::values::color::{color_space::LinearRgb, AlphaColor, Rgb};
|
||||||
|
|
||||||
|
use crate::DefaultMaterial;
|
||||||
|
|
||||||
pub struct StardustBevyPlugin;
|
pub struct StardustBevyPlugin;
|
||||||
|
|
||||||
pub static DESTROY_ENTITY: DestroySender = DestroySender(OnceCell::new());
|
pub static DESTROY_ENTITY: DestroySender = DestroySender(OnceCell::new());
|
||||||
@@ -63,6 +67,20 @@ impl Plugin for StardustBevyPlugin {
|
|||||||
}
|
}
|
||||||
labels.insert(0, (StardustFirst).intern());
|
labels.insert(0, (StardustFirst).intern());
|
||||||
app.add_systems(First, yeet_entities);
|
app.add_systems(First, yeet_entities);
|
||||||
|
// app.add_observer(
|
||||||
|
// |trigger: Trigger<OnInsert, MeshMaterial3d<DefaultMaterial>>,
|
||||||
|
// query: Query<&MeshMaterial3d<DefaultMaterial>>,
|
||||||
|
// mut mats: ResMut<Assets<DefaultMaterial>>| {
|
||||||
|
// let Ok(handle) = query.get(trigger.entity()) else {
|
||||||
|
// return;
|
||||||
|
// };
|
||||||
|
// if let Some(mat) = mats.get_mut(handle) {
|
||||||
|
// if matches!(mat.alpha_mode, AlphaMode::Blend | AlphaMode::Mask(_)) {
|
||||||
|
// mat.alpha_mode = AlphaMode::AlphaToCoverage
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// },
|
||||||
|
// );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -155,3 +173,23 @@ pub struct TemporaryEntity;
|
|||||||
pub struct ViewLocation;
|
pub struct ViewLocation;
|
||||||
#[derive(Hash, Debug, Clone, Copy, PartialEq, Eq, Deref)]
|
#[derive(Hash, Debug, Clone, Copy, PartialEq, Eq, Deref)]
|
||||||
pub struct MainWorldEntity(pub Entity);
|
pub struct MainWorldEntity(pub Entity);
|
||||||
|
|
||||||
|
pub struct DummyPbrPlugin;
|
||||||
|
|
||||||
|
impl Plugin for DummyPbrPlugin {
|
||||||
|
fn build(&self, app: &mut App) {
|
||||||
|
let use_gpu_instance_buffer_builder = true;
|
||||||
|
app.init_asset::<StandardMaterial>();
|
||||||
|
app.add_plugins((
|
||||||
|
GpuMeshPreprocessPlugin {
|
||||||
|
use_gpu_instance_buffer_builder,
|
||||||
|
},
|
||||||
|
MeshRenderPlugin {
|
||||||
|
use_gpu_instance_buffer_builder,
|
||||||
|
},
|
||||||
|
));
|
||||||
|
app.register_type::<DefaultOpaqueRendererMethod>()
|
||||||
|
.init_resource::<DefaultOpaqueRendererMethod>()
|
||||||
|
.add_plugins(ExtractResourcePlugin::<DefaultOpaqueRendererMethod>::default());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
27
src/main.rs
27
src/main.rs
@@ -25,8 +25,7 @@ use bevy::gizmos::GizmoPlugin;
|
|||||||
use bevy::gltf::GltfPlugin;
|
use bevy::gltf::GltfPlugin;
|
||||||
use bevy::image::Image;
|
use bevy::image::Image;
|
||||||
use bevy::input::InputPlugin;
|
use bevy::input::InputPlugin;
|
||||||
use bevy::log::LogPlugin;
|
use bevy::pbr::PbrPlugin;
|
||||||
use bevy::pbr::{PbrPlugin, StandardMaterial};
|
|
||||||
use bevy::prelude::{
|
use bevy::prelude::{
|
||||||
on_event, resource_added, Camera3d, ClearColor, Commands, Entity, EventReader, HierarchyPlugin,
|
on_event, resource_added, Camera3d, ClearColor, Commands, Entity, EventReader, HierarchyPlugin,
|
||||||
ImagePlugin, IntoSystemConfigs, Local, Query, Res, ResMut, Resource, Transform,
|
ImagePlugin, IntoSystemConfigs, Local, Query, Res, ResMut, Resource, Transform,
|
||||||
@@ -35,9 +34,8 @@ use bevy::prelude::{
|
|||||||
use bevy::render::pipelined_rendering::PipelinedRenderingPlugin;
|
use bevy::render::pipelined_rendering::PipelinedRenderingPlugin;
|
||||||
use bevy::render::RenderPlugin;
|
use bevy::render::RenderPlugin;
|
||||||
use bevy::scene::ScenePlugin;
|
use bevy::scene::ScenePlugin;
|
||||||
use bevy::text::{Font, FontLoader, TextPlugin};
|
use bevy::text::{Font, FontLoader};
|
||||||
use bevy::time::Time;
|
use bevy::time::Time;
|
||||||
use bevy::utils::default;
|
|
||||||
use bevy::window::WindowPlugin;
|
use bevy::window::WindowPlugin;
|
||||||
use bevy::winit::{EventLoopProxyWrapper, WakeUp, WinitPlugin};
|
use bevy::winit::{EventLoopProxyWrapper, WakeUp, WinitPlugin};
|
||||||
use bevy::{DefaultPlugins, MinimalPlugins};
|
use bevy::{DefaultPlugins, MinimalPlugins};
|
||||||
@@ -52,9 +50,10 @@ use bevy_mod_openxr::session::OxrSession;
|
|||||||
use bevy_mod_openxr::spaces::OxrSpaceExt;
|
use bevy_mod_openxr::spaces::OxrSpaceExt;
|
||||||
use bevy_mod_openxr::types::{AppInfo, Version};
|
use bevy_mod_openxr::types::{AppInfo, Version};
|
||||||
use bevy_mod_openxr::{add_xr_plugins, openxr_session_running};
|
use bevy_mod_openxr::{add_xr_plugins, openxr_session_running};
|
||||||
use bevy_mod_xr::session::{XrFirst, XrPreDestroySession, XrSessionCreated, XrSessionPlugin};
|
use bevy_mod_xr::session::{XrFirst, XrPreDestroySession, XrSessionCreated};
|
||||||
use bevy_mod_xr::spaces::XrPrimaryReferenceSpace;
|
use bevy_mod_xr::spaces::XrPrimaryReferenceSpace;
|
||||||
use bevy_plugin::{DbusConnection, InputUpdate, StardustBevyPlugin, StardustFirst};
|
use bevy_plugin::{DbusConnection, DummyPbrPlugin, InputUpdate, StardustBevyPlugin, StardustFirst};
|
||||||
|
use bevy_sk::skytext::SphericalHarmonicsPlugin;
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use color_eyre::eyre::eyre;
|
use color_eyre::eyre::eyre;
|
||||||
use core::client::Client;
|
use core::client::Client;
|
||||||
@@ -76,7 +75,6 @@ use stardust_xr::server;
|
|||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::thread;
|
|
||||||
use tokio::net::UnixListener;
|
use tokio::net::UnixListener;
|
||||||
use tokio::sync::Notify;
|
use tokio::sync::Notify;
|
||||||
use tracing::level_filters::LevelFilter;
|
use tracing::level_filters::LevelFilter;
|
||||||
@@ -85,7 +83,7 @@ use tracing_subscriber::{fmt, prelude::*, EnvFilter};
|
|||||||
use zbus::fdo::ObjectManager;
|
use zbus::fdo::ObjectManager;
|
||||||
use zbus::Connection;
|
use zbus::Connection;
|
||||||
|
|
||||||
pub type DefaultMaterial = StandardMaterial;
|
pub type DefaultMaterial = bevy_sk::vr_materials::PbrMaterial;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Parser)]
|
#[derive(Debug, Clone, Parser)]
|
||||||
#[clap(author, version, about, long_about = None)]
|
#[clap(author, version, about, long_about = None)]
|
||||||
@@ -295,15 +293,20 @@ fn bevy_loop(
|
|||||||
.add(CorePipelinePlugin)
|
.add(CorePipelinePlugin)
|
||||||
// very unsure what is needed here
|
// very unsure what is needed here
|
||||||
.add(PbrPlugin {
|
.add(PbrPlugin {
|
||||||
// hoping that there is very little overdraw in stardust
|
|
||||||
prepass_enabled: false,
|
prepass_enabled: false,
|
||||||
add_default_deferred_lighting_plugin: true,
|
add_default_deferred_lighting_plugin: false,
|
||||||
use_gpu_instance_buffer_builder: true,
|
use_gpu_instance_buffer_builder: false,
|
||||||
})
|
})
|
||||||
|
// .add(DummyPbrPlugin)
|
||||||
.add(ScenePlugin)
|
.add(ScenePlugin)
|
||||||
.add(GltfPlugin::default())
|
.add(GltfPlugin::default())
|
||||||
.add(AudioPlugin::default())
|
.add(AudioPlugin::default())
|
||||||
.add(GizmoPlugin);
|
.add(GizmoPlugin)
|
||||||
|
.add(bevy_sk::vr_materials::SkMaterialPlugin {
|
||||||
|
replace_standard_material: true,
|
||||||
|
})
|
||||||
|
.add(bevy_sk::hand::HandPlugin)
|
||||||
|
.add(SphericalHarmonicsPlugin);
|
||||||
|
|
||||||
if args.pipelined_rendering {
|
if args.pipelined_rendering {
|
||||||
base = base.add(PipelinedRenderingPlugin);
|
base = base.add(PipelinedRenderingPlugin);
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
use super::{Line, LinesAspect};
|
use super::{Line, LinesAspect};
|
||||||
use crate::core::error::Result;
|
use crate::core::error::Result;
|
||||||
|
use crate::DefaultMaterial;
|
||||||
use crate::{
|
use crate::{
|
||||||
bevy_plugin::{StardustExtract, TemporaryEntity, ViewLocation},
|
bevy_plugin::{StardustExtract, TemporaryEntity, ViewLocation},
|
||||||
core::{client::Client, registry::Registry},
|
core::{client::Client, registry::Registry},
|
||||||
@@ -10,7 +11,7 @@ use bevy::{
|
|||||||
asset::{Assets, RenderAssetUsages},
|
asset::{Assets, RenderAssetUsages},
|
||||||
color::{Color, ColorToComponents, Srgba},
|
color::{Color, ColorToComponents, Srgba},
|
||||||
math::{bounding::Aabb3d, Isometry3d},
|
math::{bounding::Aabb3d, Isometry3d},
|
||||||
pbr::{MeshMaterial3d, StandardMaterial},
|
pbr::MeshMaterial3d,
|
||||||
prelude::{
|
prelude::{
|
||||||
AlphaMode, Commands, GlobalTransform, Mesh, Mesh3d, ResMut, Single, Transform, With,
|
AlphaMode, Commands, GlobalTransform, Mesh, Mesh3d, ResMut, Single, Transform, With,
|
||||||
},
|
},
|
||||||
@@ -72,9 +73,9 @@ impl Lines {
|
|||||||
.points
|
.points
|
||||||
.iter()
|
.iter()
|
||||||
.map(|p| BevyLinePoint {
|
.map(|p| BevyLinePoint {
|
||||||
pt: transform_mat.transform_point3(Vec3::from(p.point)).into(),
|
pt: transform_mat.transform_point3(Vec3::from(p.point)),
|
||||||
thickness: p.thickness,
|
thickness: p.thickness,
|
||||||
color: Srgba::new(p.color.c.r, p.color.c.g, p.color.c.b, p.color.a).into(),
|
color: Srgba::new(p.color.c.r, p.color.c.g, p.color.c.b, p.color.a),
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
if line.cyclic && !points.is_empty() {
|
if line.cyclic && !points.is_empty() {
|
||||||
@@ -88,11 +89,11 @@ impl Lines {
|
|||||||
alpha: first.color.a.lerp(&last.color.a, 0.5),
|
alpha: first.color.a.lerp(&last.color.a, 0.5),
|
||||||
};
|
};
|
||||||
let connect_point = BevyLinePoint {
|
let connect_point = BevyLinePoint {
|
||||||
pt: transform_mat
|
pt: transform_mat.transform_point3(
|
||||||
.transform_point3(Vec3::from(first.point).lerp(Vec3::from(last.point), 0.5))
|
Vec3::from(first.point).lerp(Vec3::from(last.point), 0.5),
|
||||||
.into(),
|
),
|
||||||
thickness: (first.thickness + last.thickness) * 0.5,
|
thickness: (first.thickness + last.thickness) * 0.5,
|
||||||
color: color.into(),
|
color,
|
||||||
};
|
};
|
||||||
points.push_front(connect_point);
|
points.push_front(connect_point);
|
||||||
points.push_back(connect_point);
|
points.push_back(connect_point);
|
||||||
@@ -160,13 +161,13 @@ impl Drop for Lines {
|
|||||||
|
|
||||||
pub fn draw_all(
|
pub fn draw_all(
|
||||||
mut meshes: ResMut<Assets<Mesh>>,
|
mut meshes: ResMut<Assets<Mesh>>,
|
||||||
mut materials: ResMut<Assets<StandardMaterial>>,
|
mut materials: ResMut<Assets<DefaultMaterial>>,
|
||||||
mut cmds: Commands,
|
mut cmds: Commands,
|
||||||
hmd: Option<Single<&GlobalTransform, With<ViewLocation>>>,
|
hmd: Option<Single<&GlobalTransform, With<ViewLocation>>>,
|
||||||
) {
|
) {
|
||||||
let Some(hmd) = hmd else { return };
|
let Some(hmd) = hmd else { return };
|
||||||
let material = StandardMaterial {
|
let material = DefaultMaterial {
|
||||||
base_color: Color::WHITE,
|
color: Color::WHITE,
|
||||||
alpha_mode: AlphaMode::Blend,
|
alpha_mode: AlphaMode::Blend,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ use crate::nodes::Node;
|
|||||||
use crate::DefaultMaterial;
|
use crate::DefaultMaterial;
|
||||||
use bevy::app::{Plugin, PostUpdate, PreUpdate, Update};
|
use bevy::app::{Plugin, PostUpdate, PreUpdate, Update};
|
||||||
use bevy::asset::{AssetServer, Assets, Handle};
|
use bevy::asset::{AssetServer, Assets, Handle};
|
||||||
use bevy::color::{Color, LinearRgba};
|
use bevy::color::{Color, LinearRgba, Srgba};
|
||||||
use bevy::core::Name;
|
use bevy::core::Name;
|
||||||
use bevy::gltf::GltfAssetLabel;
|
use bevy::gltf::GltfAssetLabel;
|
||||||
use bevy::image::Image;
|
use bevy::image::Image;
|
||||||
@@ -109,10 +109,10 @@ impl MaterialParameter {
|
|||||||
},
|
},
|
||||||
MaterialParameter::Color(val) => match parameter_name {
|
MaterialParameter::Color(val) => match parameter_name {
|
||||||
"color" => {
|
"color" => {
|
||||||
material.base_color = LinearRgba::new(val.c.r, val.c.g, val.c.b, val.a).into()
|
material.color = Srgba::new(val.c.r, val.c.g, val.c.b, val.a).into()
|
||||||
}
|
}
|
||||||
"emission_factor" => {
|
"emission_factor" => {
|
||||||
material.emissive = LinearRgba::new(val.c.r, val.c.g, val.c.b, val.a)
|
material.emission_factor = LinearRgba::new(val.c.r, val.c.g, val.c.b, val.a).into()
|
||||||
}
|
}
|
||||||
name => {
|
name => {
|
||||||
if let Some(field) = material.get_field_mut::<Color>(name) {
|
if let Some(field) = material.get_field_mut::<Color>(name) {
|
||||||
@@ -131,13 +131,14 @@ impl MaterialParameter {
|
|||||||
let image = asset_server.load::<Image>(texture_path);
|
let image = asset_server.load::<Image>(texture_path);
|
||||||
match parameter_name {
|
match parameter_name {
|
||||||
"diffuse" => {
|
"diffuse" => {
|
||||||
material.base_color_texture.replace(image);
|
material.diffuse_texture.replace(image);
|
||||||
}
|
}
|
||||||
"emission" => {
|
"emission" => {
|
||||||
material.emissive_texture.replace(image);
|
material.emission_texture.replace(image);
|
||||||
}
|
}
|
||||||
"normal" => {
|
"normal" => {
|
||||||
material.normal_map_texture.replace(image);
|
error!("TODO: implement Normal Map texture in bevy_sk");
|
||||||
|
// material.n.replace(image);
|
||||||
}
|
}
|
||||||
"occlusion" => {
|
"occlusion" => {
|
||||||
material.occlusion_texture.replace(image);
|
material.occlusion_texture.replace(image);
|
||||||
|
|||||||
@@ -81,8 +81,7 @@ fn spawn_text(
|
|||||||
let str = text.text.lock().clone();
|
let str = text.text.lock().clone();
|
||||||
drop(_span2);
|
drop(_span2);
|
||||||
let mat = mats.add(DefaultMaterial {
|
let mat = mats.add(DefaultMaterial {
|
||||||
base_color: convert_linear_rgba(data.color).into(),
|
color: convert_linear_rgba(data.color).into(),
|
||||||
unlit: true,
|
|
||||||
..Default::default()
|
..Default::default()
|
||||||
});
|
});
|
||||||
let font = text
|
let font = text
|
||||||
|
|||||||
@@ -17,7 +17,9 @@ use bevy::{
|
|||||||
color::LinearRgba,
|
color::LinearRgba,
|
||||||
gltf::GltfAssetLabel,
|
gltf::GltfAssetLabel,
|
||||||
pbr::MeshMaterial3d,
|
pbr::MeshMaterial3d,
|
||||||
prelude::{Children, Commands, Component, IntoSystemConfigs as _, Mesh, Query, Res, ResMut, Transform},
|
prelude::{
|
||||||
|
Children, Commands, Component, IntoSystemConfigs as _, Mesh, Query, Res, ResMut, Transform,
|
||||||
|
},
|
||||||
scene::SceneRoot,
|
scene::SceneRoot,
|
||||||
utils::default,
|
utils::default,
|
||||||
};
|
};
|
||||||
@@ -109,7 +111,7 @@ fn update_controllers(
|
|||||||
if input_node.enabled() {
|
if input_node.enabled() {
|
||||||
let world_transform = location;
|
let world_transform = location;
|
||||||
if let Some(mat) = controller.material.get().and_then(|v| mats.get_mut(v)) {
|
if let Some(mat) = controller.material.get().and_then(|v| mats.get_mut(v)) {
|
||||||
mat.base_color = if controller.capture_manager.capture.is_none() {
|
mat.color = if controller.capture_manager.capture.is_none() {
|
||||||
LinearRgba::rgb(1.0, 1.0, 1.0)
|
LinearRgba::rgb(1.0, 1.0, 1.0)
|
||||||
} else {
|
} else {
|
||||||
LinearRgba::rgb(0.0, 1.0, 0.75)
|
LinearRgba::rgb(0.0, 1.0, 0.75)
|
||||||
|
|||||||
Reference in New Issue
Block a user