Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
47662fe4ba | ||
|
|
445f249153 | ||
|
|
30477254e5 |
@@ -0,0 +1,45 @@
|
||||
name: CI
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
pull_request:
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
build-and-test:
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 15
|
||||
steps:
|
||||
- name: Check out source
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install Rust toolchain
|
||||
run: |
|
||||
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | \
|
||||
sh -s -- -y --profile minimal
|
||||
echo "$HOME/.cargo/bin" >> "$GITHUB_PATH"
|
||||
"$HOME/.cargo/bin/rustup" toolchain install nightly --profile minimal
|
||||
|
||||
- name: Install Linux dependencies
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install --no-install-recommends -y \
|
||||
clang \
|
||||
libasound2-dev \
|
||||
libudev-dev \
|
||||
libusb-1.0-0-dev \
|
||||
libwayland-dev \
|
||||
libx11-dev \
|
||||
libxkbcommon-dev \
|
||||
libxkbcommon-x11-0 \
|
||||
mesa-vulkan-drivers \
|
||||
mold \
|
||||
pkg-config
|
||||
|
||||
- name: Build
|
||||
run: cargo build --locked -j 4
|
||||
|
||||
- name: Run unit tests
|
||||
run: cargo test --locked --lib -j 4
|
||||
@@ -3,6 +3,7 @@
|
||||
use std::{
|
||||
collections::{HashMap, HashSet},
|
||||
io,
|
||||
path::Path,
|
||||
};
|
||||
|
||||
use bevy::{
|
||||
@@ -517,6 +518,7 @@ struct FighterBakeDeclaration {
|
||||
#[derive(Asset, TypePath)]
|
||||
struct FighterBakeSource {
|
||||
model_bytes: Vec<u8>,
|
||||
buffers: Vec<Vec<u8>>,
|
||||
animations: HashMap<AnimKind, String>,
|
||||
}
|
||||
|
||||
@@ -550,8 +552,31 @@ impl AssetLoader for FighterBakeSourceLoader {
|
||||
.read_asset_bytes(&manifest.model_path)
|
||||
.await
|
||||
.map_err(|error| io::Error::other(error.to_string()))?;
|
||||
|
||||
let gltf = gltf::Gltf::from_slice(&model_bytes)
|
||||
.map_err(|error| io::Error::new(io::ErrorKind::InvalidData, error))?;
|
||||
let mut buffers = Vec::with_capacity(gltf.buffers().len());
|
||||
for buffer in gltf.buffers() {
|
||||
let bytes = match buffer.source() {
|
||||
gltf::buffer::Source::Uri(uri) => load_context
|
||||
.read_asset_bytes(AssetPath::from_path_buf(
|
||||
Path::new(&manifest.model_path)
|
||||
.parent()
|
||||
.unwrap_or_else(|| Path::new(""))
|
||||
.join(uri),
|
||||
))
|
||||
.await
|
||||
.map_err(|error| io::Error::other(error.to_string()))?,
|
||||
gltf::buffer::Source::Bin => gltf.blob.clone().ok_or_else(|| {
|
||||
io::Error::new(io::ErrorKind::InvalidData, "missing glTF binary blob")
|
||||
})?,
|
||||
};
|
||||
buffers.push(bytes);
|
||||
}
|
||||
|
||||
Ok(FighterBakeSource {
|
||||
model_bytes,
|
||||
buffers,
|
||||
animations: manifest.animations,
|
||||
})
|
||||
}
|
||||
@@ -600,7 +625,7 @@ impl AssetTransformer for FighterBakeTransformer {
|
||||
source: TransformedAsset<Self::AssetInput>,
|
||||
_: &'a Self::Settings,
|
||||
) -> Result<TransformedAsset<Self::AssetOutput>, Self::Error> {
|
||||
let baked = bake_gltf(&source.model_bytes, &source.animations)?;
|
||||
let baked = bake_gltf(&source.model_bytes, &source.buffers, &source.animations)?;
|
||||
Ok(source.replace_asset(baked))
|
||||
}
|
||||
}
|
||||
@@ -656,10 +681,43 @@ impl Plugin for BakedAnimationPlugin {
|
||||
|
||||
fn bake_gltf(
|
||||
bytes: &[u8],
|
||||
buffer_bytes: &[Vec<u8>],
|
||||
animations: &HashMap<AnimKind, String>,
|
||||
) -> io::Result<BakedFighterAnimations> {
|
||||
let (document, buffers, _) = gltf::import_slice(bytes)
|
||||
let gltf = gltf::Gltf::from_slice(bytes)
|
||||
.map_err(|error| io::Error::new(io::ErrorKind::InvalidData, error))?;
|
||||
let buffers = gltf
|
||||
.buffers()
|
||||
.zip(buffer_bytes)
|
||||
.map(|(buffer, bytes)| {
|
||||
if bytes.len() < buffer.length() {
|
||||
return Err(io::Error::new(
|
||||
io::ErrorKind::InvalidData,
|
||||
format!(
|
||||
"glTF buffer {} is too short: expected {}, got {}",
|
||||
buffer.index(),
|
||||
buffer.length(),
|
||||
bytes.len()
|
||||
),
|
||||
));
|
||||
}
|
||||
Ok(gltf::buffer::Data(bytes.clone()))
|
||||
})
|
||||
.collect::<io::Result<Vec<_>>>()?;
|
||||
if buffers.len() != gltf.buffers().len() {
|
||||
return Err(io::Error::new(
|
||||
io::ErrorKind::InvalidData,
|
||||
"glTF buffer data is incomplete",
|
||||
));
|
||||
}
|
||||
bake_gltf_document(gltf.document, buffers, animations)
|
||||
}
|
||||
|
||||
fn bake_gltf_document(
|
||||
document: gltf::Document,
|
||||
buffers: Vec<gltf::buffer::Data>,
|
||||
animations: &HashMap<AnimKind, String>,
|
||||
) -> io::Result<BakedFighterAnimations> {
|
||||
let nodes: Vec<_> = document.nodes().collect();
|
||||
if nodes.is_empty() {
|
||||
return Err(io::Error::new(
|
||||
@@ -933,11 +991,12 @@ mod tests {
|
||||
fn configured_fighter_clips_bake_to_fixed_point_frames() {
|
||||
let manifest: FighterManifest =
|
||||
ron::from_str(include_str!("../../assets/fighters/test/test.fighter.ron")).unwrap();
|
||||
let baked = bake_gltf(
|
||||
include_bytes!("../../assets/fighters/test/test-fighter-2.glb"),
|
||||
&manifest.animations,
|
||||
)
|
||||
let (document, buffers, _) = gltf::import(concat!(
|
||||
env!("CARGO_MANIFEST_DIR"),
|
||||
"/assets/fighters/test/test_fighter.gltf"
|
||||
))
|
||||
.unwrap();
|
||||
let baked = bake_gltf_document(document, buffers, &manifest.animations).unwrap();
|
||||
|
||||
assert_eq!(baked.frame_rate, BAKED_ANIMATION_FPS);
|
||||
assert_eq!(baked.frame_count(AnimKind::Wait), Some(121));
|
||||
|
||||
Reference in New Issue
Block a user