refactor use bevy_sk material and hands

Signed-off-by: Schmarni <marnistromer@gmail.com>
This commit is contained in:
Schmarni
2025-01-17 06:25:15 +01:00
parent a832266989
commit 4ea0d60310
7 changed files with 84 additions and 35 deletions

View File

@@ -57,10 +57,15 @@ bevy = { version = "0.15.1", features = [
"wav",
"trace_tracy",
] }
bevy_mod_xr = { git = "https://github.com/Schmarni-Dev/bevy_openxr", branch = "wgpu_feature_fix" }
bevy_mod_openxr = { git = "https://github.com/Schmarni-Dev/bevy_openxr", branch = "wgpu_feature_fix" }
bevy_xr_utils = { 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/awtterpip/bevy_oxr"
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_sk.path = "../bevy_sk"
bevy_sk.git = "https://github.com/MalekiRe/bevy_sk"
openxr = "0.19"
winit = { version = "0.30", default-features = false, features = [] }
# small utility thingys

View File

@@ -4,7 +4,9 @@ use bevy::{
app::MainScheduleOrder,
ecs::schedule::{ExecutorKind, ScheduleLabel},
math::bounding::Aabb3d,
pbr::{DefaultOpaqueRendererMethod, GpuMeshPreprocessPlugin, MeshRenderPlugin},
prelude::*,
render::extract_resource::ExtractResourcePlugin,
};
use bevy_mod_openxr::session::OxrSession;
use bevy_mod_xr::session::{session_available, XrFirst, XrSessionCreated};
@@ -12,6 +14,8 @@ use once_cell::sync::OnceCell;
use openxr::ReferenceSpaceType;
use stardust_xr::values::color::{color_space::LinearRgb, AlphaColor, Rgb};
use crate::DefaultMaterial;
pub struct StardustBevyPlugin;
pub static DESTROY_ENTITY: DestroySender = DestroySender(OnceCell::new());
@@ -63,6 +67,20 @@ impl Plugin for StardustBevyPlugin {
}
labels.insert(0, (StardustFirst).intern());
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;
#[derive(Hash, Debug, Clone, Copy, PartialEq, Eq, Deref)]
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());
}
}

View File

@@ -25,8 +25,7 @@ use bevy::gizmos::GizmoPlugin;
use bevy::gltf::GltfPlugin;
use bevy::image::Image;
use bevy::input::InputPlugin;
use bevy::log::LogPlugin;
use bevy::pbr::{PbrPlugin, StandardMaterial};
use bevy::pbr::PbrPlugin;
use bevy::prelude::{
on_event, resource_added, Camera3d, ClearColor, Commands, Entity, EventReader, HierarchyPlugin,
ImagePlugin, IntoSystemConfigs, Local, Query, Res, ResMut, Resource, Transform,
@@ -35,9 +34,8 @@ use bevy::prelude::{
use bevy::render::pipelined_rendering::PipelinedRenderingPlugin;
use bevy::render::RenderPlugin;
use bevy::scene::ScenePlugin;
use bevy::text::{Font, FontLoader, TextPlugin};
use bevy::text::{Font, FontLoader};
use bevy::time::Time;
use bevy::utils::default;
use bevy::window::WindowPlugin;
use bevy::winit::{EventLoopProxyWrapper, WakeUp, WinitPlugin};
use bevy::{DefaultPlugins, MinimalPlugins};
@@ -52,9 +50,10 @@ use bevy_mod_openxr::session::OxrSession;
use bevy_mod_openxr::spaces::OxrSpaceExt;
use bevy_mod_openxr::types::{AppInfo, Version};
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_plugin::{DbusConnection, InputUpdate, StardustBevyPlugin, StardustFirst};
use bevy_plugin::{DbusConnection, DummyPbrPlugin, InputUpdate, StardustBevyPlugin, StardustFirst};
use bevy_sk::skytext::SphericalHarmonicsPlugin;
use clap::Parser;
use color_eyre::eyre::eyre;
use core::client::Client;
@@ -76,7 +75,6 @@ use stardust_xr::server;
use std::ops::Deref;
use std::path::PathBuf;
use std::sync::Arc;
use std::thread;
use tokio::net::UnixListener;
use tokio::sync::Notify;
use tracing::level_filters::LevelFilter;
@@ -85,7 +83,7 @@ use tracing_subscriber::{fmt, prelude::*, EnvFilter};
use zbus::fdo::ObjectManager;
use zbus::Connection;
pub type DefaultMaterial = StandardMaterial;
pub type DefaultMaterial = bevy_sk::vr_materials::PbrMaterial;
#[derive(Debug, Clone, Parser)]
#[clap(author, version, about, long_about = None)]
@@ -295,15 +293,20 @@ fn bevy_loop(
.add(CorePipelinePlugin)
// very unsure what is needed here
.add(PbrPlugin {
// hoping that there is very little overdraw in stardust
prepass_enabled: false,
add_default_deferred_lighting_plugin: true,
use_gpu_instance_buffer_builder: true,
add_default_deferred_lighting_plugin: false,
use_gpu_instance_buffer_builder: false,
})
// .add(DummyPbrPlugin)
.add(ScenePlugin)
.add(GltfPlugin::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 {
base = base.add(PipelinedRenderingPlugin);

View File

@@ -1,5 +1,6 @@
use super::{Line, LinesAspect};
use crate::core::error::Result;
use crate::DefaultMaterial;
use crate::{
bevy_plugin::{StardustExtract, TemporaryEntity, ViewLocation},
core::{client::Client, registry::Registry},
@@ -10,7 +11,7 @@ use bevy::{
asset::{Assets, RenderAssetUsages},
color::{Color, ColorToComponents, Srgba},
math::{bounding::Aabb3d, Isometry3d},
pbr::{MeshMaterial3d, StandardMaterial},
pbr::MeshMaterial3d,
prelude::{
AlphaMode, Commands, GlobalTransform, Mesh, Mesh3d, ResMut, Single, Transform, With,
},
@@ -72,9 +73,9 @@ impl Lines {
.points
.iter()
.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,
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();
if line.cyclic && !points.is_empty() {
@@ -88,11 +89,11 @@ impl Lines {
alpha: first.color.a.lerp(&last.color.a, 0.5),
};
let connect_point = BevyLinePoint {
pt: transform_mat
.transform_point3(Vec3::from(first.point).lerp(Vec3::from(last.point), 0.5))
.into(),
pt: transform_mat.transform_point3(
Vec3::from(first.point).lerp(Vec3::from(last.point), 0.5),
),
thickness: (first.thickness + last.thickness) * 0.5,
color: color.into(),
color,
};
points.push_front(connect_point);
points.push_back(connect_point);
@@ -160,13 +161,13 @@ impl Drop for Lines {
pub fn draw_all(
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
mut materials: ResMut<Assets<DefaultMaterial>>,
mut cmds: Commands,
hmd: Option<Single<&GlobalTransform, With<ViewLocation>>>,
) {
let Some(hmd) = hmd else { return };
let material = StandardMaterial {
base_color: Color::WHITE,
let material = DefaultMaterial {
color: Color::WHITE,
alpha_mode: AlphaMode::Blend,
..Default::default()
};

View File

@@ -10,7 +10,7 @@ use crate::nodes::Node;
use crate::DefaultMaterial;
use bevy::app::{Plugin, PostUpdate, PreUpdate, Update};
use bevy::asset::{AssetServer, Assets, Handle};
use bevy::color::{Color, LinearRgba};
use bevy::color::{Color, LinearRgba, Srgba};
use bevy::core::Name;
use bevy::gltf::GltfAssetLabel;
use bevy::image::Image;
@@ -109,10 +109,10 @@ impl MaterialParameter {
},
MaterialParameter::Color(val) => match parameter_name {
"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" => {
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 => {
if let Some(field) = material.get_field_mut::<Color>(name) {
@@ -131,13 +131,14 @@ impl MaterialParameter {
let image = asset_server.load::<Image>(texture_path);
match parameter_name {
"diffuse" => {
material.base_color_texture.replace(image);
material.diffuse_texture.replace(image);
}
"emission" => {
material.emissive_texture.replace(image);
material.emission_texture.replace(image);
}
"normal" => {
material.normal_map_texture.replace(image);
error!("TODO: implement Normal Map texture in bevy_sk");
// material.n.replace(image);
}
"occlusion" => {
material.occlusion_texture.replace(image);

View File

@@ -81,8 +81,7 @@ fn spawn_text(
let str = text.text.lock().clone();
drop(_span2);
let mat = mats.add(DefaultMaterial {
base_color: convert_linear_rgba(data.color).into(),
unlit: true,
color: convert_linear_rgba(data.color).into(),
..Default::default()
});
let font = text

View File

@@ -17,7 +17,9 @@ use bevy::{
color::LinearRgba,
gltf::GltfAssetLabel,
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,
utils::default,
};
@@ -109,7 +111,7 @@ fn update_controllers(
if input_node.enabled() {
let world_transform = location;
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)
} else {
LinearRgba::rgb(0.0, 1.0, 0.75)