Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bevy 0.12 #58

Merged
merged 17 commits into from
Nov 16, 2023
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ jobs:
run: |
$VCINSTALLDIR = $(& "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" -latest -property installationPath)
Add-Content $env:GITHUB_ENV "LIBCLANG_PATH=${VCINSTALLDIR}\VC\Tools\LLVM\x64\bin`n"
Invoke-WebRequest "https://www.gyan.dev/ffmpeg/builds/ffmpeg-release-full-shared.7z" -OutFile ffmpeg-release-full-shared.7z
7z x ffmpeg-release-full-shared.7z
Invoke-WebRequest "https://www.gyan.dev/ffmpeg/builds/packages/ffmpeg-6.0-full_build-shared.7z" -OutFile ffmpeg-6.0-full_build-shared.7z
7z x ffmpeg-6.0-full_build-shared.7z
mkdir ffmpeg
mv ffmpeg-*/* ffmpeg/
Add-Content $env:GITHUB_ENV "FFMPEG_DIR=${pwd}\ffmpeg`n"
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,13 @@ jobs:
run: |
$VCINSTALLDIR = $(& "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" -latest -property installationPath)
Add-Content $env:GITHUB_ENV "LIBCLANG_PATH=${VCINSTALLDIR}\VC\Tools\LLVM\x64\bin`n"
Invoke-WebRequest "https://www.gyan.dev/ffmpeg/builds/ffmpeg-release-full-shared.7z" -OutFile ffmpeg-release-full-shared.7z
7z x ffmpeg-release-full-shared.7z
Invoke-WebRequest "https://www.gyan.dev/ffmpeg/builds/packages/ffmpeg-6.0-full_build-shared.7z" -OutFile ffmpeg-6.0-full_build-shared.7z
7z x ffmpeg-6.0-full_build-shared.7z
mkdir ffmpeg
mv ffmpeg-*/* ffmpeg/
Add-Content $env:GITHUB_ENV "FFMPEG_DIR=${pwd}\ffmpeg`n"
Add-Content $env:GITHUB_PATH "${pwd}\ffmpeg\bin`n"

Add-Content $env:GITHUB_PATH "${pwd}\ffmpeg\bin`n"
- name: Cargo build
run: cargo build --release
# run: cargo build --release ${{ matrix.target && '--target' }} ${{ matrix.target }}
Expand Down
14 changes: 7 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ dcl_component = { path="crates/dcl_component" }
restricted_actions = { path="crates/restricted_actions" }
wallet = { path="crates/wallet" }

bevy = { version = "0.11", features=["jpeg"] }
bevy_console = "0.8.0"
bevy_mod_billboard = "0.4"
bevy_egui = "0.21"
bevy = { version = "0.12", features=["jpeg"] }
bevy_console = { git = "https://github.com/msklosak/bevy-console", branch = "bevy_0.12_update" }
bevy_mod_billboard = { git = "https://github.com/robtfm/bevy_mod_billboard", branch = "bevy12" }
bevy_egui = "0.23"

serde = "1.0.152"
serde_json = { version = "1.0.92", features = ["raw_value"] }
Expand All @@ -54,7 +54,7 @@ async-std = "1.12.0"
# todo: use isahc 2.0 when it's released
isahc = { git = "https://github.com/sagebind/isahc", rev="096aff7b13f4ff5bb474fdc27bc30b297a2968f6", default-features = false, features = ["json", "text-decoding", "http2", "rustls-tls-native-certs"] }
kira = "0.8.4"
bevy_kira_audio = { version= "0.16", features=["flac", "mp3", "ogg", "wav"] }
bevy_kira_audio = { git = "https://github.com/robtfm/bevy_kira_audio", branch = "pub-mod-12", features=["flac", "mp3", "ogg", "wav"] }

[dependencies]
common = { workspace = true }
Expand Down Expand Up @@ -87,8 +87,8 @@ pico-args = "0.5.0"
prost-build = "0.11.8"

[patch.crates-io]
bevy = { git = "https://github.com/robtfm/bevy", branch = "release-0.11.2-hotfix" }
bevy_kira_audio = { git = "https://github.com/robtfm/bevy_kira_audio", branch = "pub-manager" }
bevy = { git = "https://github.com/robtfm/bevy", branch = "release-0.12-hotfix2" }
# bevy_kira_audio = { git = "https://github.com/robtfm/bevy_kira_audio", branch = "pub-manager" }
ffmpeg-next = { git = "https://github.com/robtfm/rust-ffmpeg", branch = "audio-linesize-0" }
parry3d-f64 = { git = "https://github.com/robtfm/parry", branch = "try_convex" }
rapier3d-f64 = { git = "https://github.com/robtfm/rapier", branch = "master" }
28 changes: 23 additions & 5 deletions assets/shaders/mask_material.wgsl
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#import bevy_pbr::mesh_vertex_output MeshVertexOutput
#import bevy_pbr::{
forward_io::{VertexOutput, FragmentOutput},
pbr_fragment::pbr_input_from_vertex_output,
pbr_functions::{apply_pbr_lighting, main_pass_post_lighting_processing},
}

struct MaskMaterial {
color: vec4<f32>,
Expand All @@ -17,11 +21,25 @@ var mask_sampler: sampler;

@fragment
fn fragment(
in: MeshVertexOutput
) -> @location(0) vec4<f32> {
in: VertexOutput,
@builtin(front_facing) is_front: bool,
) -> FragmentOutput {
var pbr_input = pbr_input_from_vertex_output(in, is_front, false);

let mask = textureSample(mask_texture, mask_sampler, in.uv);
let base = textureSample(base_texture, base_sampler, in.uv);
let color_amt = mask.r * mask.a;
// TODO: proper lighting - easy after https://github.com/bevyengine/bevy/pull/7820 lands
return vec4<f32>(mix(material.color, vec4<f32>(1.0), color_amt) * base);

let color = mix(material.color, vec4<f32>(1.0), color_amt) * base;

pbr_input.material.base_color = color;

var out: FragmentOutput;
// apply lighting
out.color = apply_pbr_lighting(pbr_input);
// apply in-shader post processing (fog, alpha-premultiply, and also tonemapping, debanding if the camera is non-hdr)
// note this does not include fullscreen postprocessing effects like bloom.
out.color = main_pass_post_lighting_processing(pbr_input, out.color);

return out;
}
5 changes: 1 addition & 4 deletions crates/av/src/audio_sink.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use bevy::prelude::*;
use common::{
structs::{AudioDecoderError, PrimaryCamera, PrimaryUser},
util::TryInsertEx,
};
use common::structs::{AudioDecoderError, PrimaryCamera, PrimaryUser};
use comms::global_crdt::ForeignAudioSource;
use kira::{manager::backend::DefaultBackend, sound::streaming::StreamingSoundData, tween::Tween};
use scene_runner::{ContainingScene, SceneEntity};
Expand Down
7 changes: 3 additions & 4 deletions crates/av/src/audio_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ use bevy_kira_audio::{
use common::{
sets::{SceneSets, SetupSets},
structs::{PrimaryCameraRes, PrimaryUser},
util::TryInsertEx,
};
use dcl::interface::ComponentPosition;
use dcl_component::{proto_components::sdk::components::PbAudioSource, SceneComponentId};
use ipfs::IpfsLoaderExt;
use ipfs::IpfsAssetServer;
use scene_runner::{
renderer_context::RendererSceneContext, update_world::AddCrdtInterfaceExt, ContainingScene,
SceneEntity,
Expand Down Expand Up @@ -60,7 +59,7 @@ fn update_audio(
>,
scenes: Query<&RendererSceneContext>,
audio: Res<bevy_kira_audio::Audio>,
asset_server: Res<AssetServer>,
ipfas: IpfsAssetServer,
mut audio_instances: ResMut<Assets<AudioInstance>>,
containing_scene: ContainingScene,
player: Query<Entity, With<PrimaryUser>>,
Expand All @@ -82,7 +81,7 @@ fn update_audio(
};

let Ok(handle) =
asset_server.load_content_file(&audio_source.0.audio_clip_url, &scene.hash)
ipfas.load_content_file(&audio_source.0.audio_clip_url, &scene.hash)
else {
warn!("failed to load content file");
continue;
Expand Down
7 changes: 4 additions & 3 deletions crates/av/src/video_player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ use bevy::{
prelude::*,
render::render_resource::{Extent3d, TextureDimension, TextureFormat, TextureUsages},
};
use common::{sets::SceneSets, util::TryInsertEx};
use common::sets::SceneSets;
use dcl::interface::{ComponentPosition, CrdtType};
use dcl_component::{
proto_components::sdk::components::{PbAudioStream, PbVideoEvent, PbVideoPlayer},
SceneComponentId,
};
use ipfs::IpfsResource;
use scene_runner::{
renderer_context::RendererSceneContext,
update_world::{material::VideoTextureOutput, AddCrdtInterfaceExt},
Expand Down Expand Up @@ -146,7 +147,7 @@ pub fn update_video_players(
Changed<AVPlayer>,
>,
mut images: ResMut<Assets<Image>>,
asset_server: Res<AssetServer>,
ipfs: Res<IpfsResource>,
scenes: Query<&RendererSceneContext>,
) {
for (ent, container, player, maybe_sink, maybe_texture) in video_players.iter() {
Expand Down Expand Up @@ -175,7 +176,7 @@ pub fn update_video_players(
};

let (video_sink, audio_sink) = av_sinks(
asset_server.clone(),
ipfs.clone(),
player.source.src.clone(),
context.hash.clone(),
image_handle,
Expand Down
18 changes: 9 additions & 9 deletions crates/av/src/video_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use bevy::prelude::*;
use common::structs::AudioDecoderError;
use dcl_component::proto_components::sdk::components::VideoState;
use ffmpeg_next::format::input;
use ipfs::IpfsLoaderExt;
use ipfs::{IpfsIo, IpfsResource};
use isahc::ReadResponseExt;
use kira::sound::streaming::StreamingSoundData;

Expand All @@ -28,7 +28,7 @@ pub struct VideoSink {
}

pub fn av_sinks(
asset_server: AssetServer,
ipfs: IpfsResource,
source: String,
hash: String,
image: Handle<Image>,
Expand All @@ -41,7 +41,7 @@ pub fn av_sinks(
let (audio_sender, audio_receiver) = tokio::sync::mpsc::channel(10);

spawn_av_thread(
asset_server,
ipfs,
command_receiver,
video_sender,
audio_sender,
Expand Down Expand Up @@ -71,25 +71,25 @@ pub fn av_sinks(
}

pub fn spawn_av_thread(
asset_server: AssetServer,
ipfs: IpfsResource,
commands: tokio::sync::mpsc::Receiver<AVCommand>,
frames: tokio::sync::mpsc::Sender<VideoData>,
audio: tokio::sync::mpsc::Sender<StreamingSoundData<AudioDecoderError>>,
path: String,
hash: String,
) {
std::thread::spawn(move || av_thread(asset_server, commands, frames, audio, path, hash));
std::thread::spawn(move || av_thread(ipfs, commands, frames, audio, path, hash));
}

fn av_thread(
asset_server: AssetServer,
ipfs: IpfsResource,
commands: tokio::sync::mpsc::Receiver<AVCommand>,
frames: tokio::sync::mpsc::Sender<VideoData>,
audio: tokio::sync::mpsc::Sender<StreamingSoundData<AudioDecoderError>>,
path: String,
hash: String,
) {
if let Err(e) = av_thread_inner(asset_server, commands, frames.clone(), audio, path, hash) {
if let Err(e) = av_thread_inner(&ipfs, commands, frames.clone(), audio, path, hash) {
let _ = frames.blocking_send(VideoData::State(VideoState::VsError));
warn!("av error: {e}");
} else {
Expand All @@ -98,7 +98,7 @@ fn av_thread(
}

pub fn av_thread_inner(
asset_server: AssetServer,
ipfas: &IpfsIo,
commands: tokio::sync::mpsc::Receiver<AVCommand>,
video: tokio::sync::mpsc::Sender<VideoData>,
audio: tokio::sync::mpsc::Sender<StreamingSoundData<AudioDecoderError>>,
Expand All @@ -121,7 +121,7 @@ pub fn av_thread_inner(
};

// source might be a content map file or a url
if let Some(content_url) = asset_server.ipfs().content_url(&path, &hash) {
if let Some(content_url) = ipfas.content_url(&path, &hash) {
// check if it changed as content_url will return Some(path) when not found and path is url-compliant.
// if it is a raw url we don't want to download initially as some servers reject http get requests on videos.
if content_url != path {
Expand Down
77 changes: 51 additions & 26 deletions crates/avatar/src/animate.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
use std::{collections::VecDeque, time::Duration};

use bevy::{gltf::Gltf, math::Vec3Swizzles, prelude::*, utils::HashMap};
use bevy::{
animation::RepeatAnimation,
asset::{LoadState, LoadedFolder},
gltf::Gltf,
math::Vec3Swizzles,
prelude::*,
utils::HashMap,
};
use bevy_console::ConsoleCommand;
use common::{
rpc::{RpcCall, RpcEventSender},
sets::SceneSets,
structs::PrimaryUser,
util::TryInsertEx,
};
use comms::{
chat_marker_things, global_crdt::ChatEvent, profile::UserProfile, NetworkMessage, Transport,
Expand Down Expand Up @@ -121,35 +127,54 @@ impl Plugin for AvatarAnimationPlugin {
}
}

#[derive(Default)]
enum AnimLoadState {
#[default]
Init,
WaitingForFolder(Handle<LoadedFolder>),
WaitingForGltfs(Vec<Handle<Gltf>>),
Done,
}

#[allow(clippy::type_complexity)]
fn load_animations(
asset_server: Res<AssetServer>,
gltfs: Res<Assets<Gltf>>,
mut builtin_animations: Local<Option<Vec<Handle<Gltf>>>>,
mut state: Local<AnimLoadState>,
folders: Res<Assets<LoadedFolder>>,
mut animations: ResMut<AvatarAnimations>,
) {
if builtin_animations.is_none() {
*builtin_animations = Some(
asset_server
.load_folder("animations")
.unwrap()
.into_iter()
.map(|h| h.typed())
.collect(),
);
} else {
builtin_animations.as_mut().unwrap().retain(|h_gltf| {
match gltfs.get(h_gltf).map(|gltf| &gltf.named_animations) {
Some(anims) => {
for (name, h_clip) in anims {
animations.0.insert(name.clone(), h_clip.clone());
debug!("added animation {name}");
match &mut *state {
AnimLoadState::Init => {
*state = AnimLoadState::WaitingForFolder(asset_server.load_folder("animations"));
}
AnimLoadState::WaitingForFolder(h_folder) => {
if asset_server.load_state(h_folder.id()) == LoadState::Loaded {
let folder = folders.get(h_folder.id()).unwrap();
*state = AnimLoadState::WaitingForGltfs(
folder.handles.iter().map(|h| h.clone().typed()).collect(),
)
}
}
AnimLoadState::WaitingForGltfs(ref mut h_gltfs) => {
h_gltfs.retain(
|h_gltf| match gltfs.get(h_gltf).map(|gltf| &gltf.named_animations) {
Some(anims) => {
for (name, h_clip) in anims {
animations.0.insert(name.clone(), h_clip.clone());
debug!("added animation {name}");
}
false
}
false
}
None => true,
None => true,
},
);

if h_gltfs.is_empty() {
*state = AnimLoadState::Done;
}
})
}
AnimLoadState::Done => {}
}
}

Expand Down Expand Up @@ -188,7 +213,7 @@ fn broadcast_emote(
mut subscribe_events: EventReader<RpcCall>,
) {
// gather any event receivers
for sender in subscribe_events.iter().filter_map(|ev| match ev {
for sender in subscribe_events.read().filter_map(|ev| match ev {
RpcCall::SubscribePlayerExpression { sender } => Some(sender),
_ => None,
}) {
Expand Down Expand Up @@ -232,7 +257,7 @@ fn broadcast_emote(

fn receive_emotes(mut commands: Commands, mut chat_events: EventReader<ChatEvent>) {
for ev in chat_events
.iter()
.read()
.filter(|e| e.message.starts_with(chat_marker_things::EMOTE))
{
if let Some(emote_urn) = ev
Expand Down Expand Up @@ -280,7 +305,7 @@ fn animate(
if repeat {
player.repeat();
} else {
player.stop_repeating();
player.set_repeat(RepeatAnimation::Never);
}
playing.insert(ent, anim.to_owned());
}
Expand Down
3 changes: 1 addition & 2 deletions crates/avatar/src/attach.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use bevy::prelude::*;
use common::{
sets::SceneSets,
structs::{AttachPoints, PrimaryUser},
util::TryInsertEx,
};
use dcl::interface::ComponentPosition;
use dcl_component::{
Expand Down Expand Up @@ -41,7 +40,7 @@ pub fn update_attached(
mut removed_attachments: RemovedComponents<AvatarAttachment>,
primary_user: Query<&AttachPoints, With<PrimaryUser>>,
) {
for removed in removed_attachments.iter() {
for removed in removed_attachments.read() {
if let Some(mut commands) = commands.get_entity(removed) {
commands.remove::<(ParentPositionSync, DisableCollisions)>();
}
Expand Down
Loading