-
-
Notifications
You must be signed in to change notification settings - Fork 11
Serialization #124
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
Merged
Merged
Serialization #124
Changes from 18 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
33a9b29
Initial `motiongfx_scene`
nixonyh 890315b
Add action resolvers keyed via `TypeId` & `OpRef`
nixonyh 576b89d
Use typarena to simplify some type erasures
nixonyh 47990e0
Collapse `field` maps in `SceneRegistry` into `TypeTable`
nixonyh 5f1ab87
Doc improvements
nixonyh 417cf8c
Generalize motiongfx_scene over a single SceneBackend type
nixonyh f26e18a
Enforce serialization trait bound for backend types
nixonyh 41189f0
Add `Storable` trait
nixonyh 2ebc008
Human readable `Duration` serialization
nixonyh b03d7e9
Drop bevy_math from motiongfx core, fixing no_std for motiongfx_scene
nixonyh bfba43e
Replace SceneBackend::Value with a per-backend ValuePool
nixonyh f4f0058
Implement the Bevy scene backend end to end
nixonyh 65a66ed
Simplify field registry and add better guarantees
nixonyh 07881d7
Add more helper functions for `SceneRegistryExt`
nixonyh ada9156
Add bundle registrations
nixonyh d62c2c6
Sync SceneUidMap via component lifecycle observers
nixonyh 1f2447f
Support multiple subject id kinds via IntoSubjectId
nixonyh 1ec01e6
Include serialization of the bevy scene alongside!
nixonyh 098a577
Clippy fmt fixes
nixonyh a201b32
Remove `Delayed` variant from `Node` enum
nixonyh 2feafe5
Replace `sparse_map` with `indexmap` & `hashbrown`
nixonyh 8564f01
Fix stage to include all fields!
nixonyh f6f4158
Add `Scene::stage` to seed initial values
nixonyh 513f171
Gate duplicate/corrupted `EntityUid`
nixonyh 7d899ca
Update Cargo.toml
nixonyh 74c72b5
Remove custom duration serialization
nixonyh 044f8aa
Improve asset test
nixonyh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| //! Serializable scenes for Bevy: a [`SceneBackend`](motiongfx_scene::backend::SceneBackend) | ||
| //! implementation, plus loading one as a Bevy [`Asset`](bevy_asset::Asset). | ||
| //! Gated behind the `scene` feature. | ||
|
|
||
| use asset::{MotionGfxScene, SceneAssetLoader}; | ||
| use bevy_app::prelude::*; | ||
| use bevy_asset::AssetApp as _; | ||
| use id::{EntityUid, SceneUidMap, on_add_entity_uid, on_remove_entity_uid}; | ||
|
|
||
| pub mod asset; | ||
| pub mod backend; | ||
| pub mod id; | ||
| pub mod value_pool; | ||
|
|
||
| pub struct MotionGfxScenePlugin; | ||
|
|
||
| impl Plugin for MotionGfxScenePlugin { | ||
| fn build(&self, app: &mut App) { | ||
| app.register_type::<EntityUid>() | ||
| .init_resource::<SceneUidMap>() | ||
| .init_asset::<MotionGfxScene>() | ||
| .register_asset_loader(SceneAssetLoader) | ||
| .add_observer(on_add_entity_uid) | ||
| .add_observer(on_remove_entity_uid); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| //! Loads a [`Scene`] as a Bevy [`Asset`] from a `.mgx.ron` file. | ||
|
|
||
| use alloc::vec::Vec; | ||
|
|
||
| use bevy_asset::io::Reader; | ||
| use bevy_asset::{Asset, AssetLoader, LoadContext}; | ||
| use bevy_ecs::error::BevyError; | ||
| use bevy_reflect::TypePath; | ||
| use motiongfx_scene::error::CompileError; | ||
| use motiongfx_scene::scene::Scene; | ||
|
|
||
| use crate::manager::{MotionGfxManager, TimelineId}; | ||
| use crate::scene::backend::{Backend, BackendRegistry}; | ||
|
|
||
| /// A [`Scene<BevyBackend>`], loadable as a Bevy asset. | ||
| /// | ||
| /// A newtype rather than a blanket impl on `Scene` itself: `Asset`/ | ||
| /// `TypePath` are foreign traits and `Scene` is a foreign type from | ||
| /// this crate's perspective, so the orphan rule requires a local | ||
| /// wrapper. | ||
| #[derive(Asset, TypePath)] | ||
| pub struct MotionGfxScene(pub Scene<Backend>); | ||
|
|
||
| impl MotionGfxScene { | ||
| /// Compiles this scene into a `BevyTimeline` through | ||
| /// `scene_registry`, then registers it on `motiongfx` exactly | ||
| /// like [`MotionGfxManager::add_timeline`]. This scene's subjects | ||
| /// must already be materialized - however the app chooses to do | ||
| /// that - so their [`EntityUid`](crate::scene::id::EntityUid)s | ||
| /// resolve through the world's | ||
| /// [`SceneUidMap`](crate::scene::id::SceneUidMap). | ||
| pub fn compile( | ||
| &self, | ||
| scene_registry: &BackendRegistry, | ||
| motiongfx: &mut MotionGfxManager, | ||
| ) -> Result<TimelineId, CompileError<Backend>> { | ||
| let timeline = motiongfx_scene::compile::compile( | ||
| &self.0, | ||
| scene_registry, | ||
| motiongfx.registry_mut(), | ||
| )?; | ||
| Ok(motiongfx.add_timeline(timeline)) | ||
| } | ||
| } | ||
|
|
||
| #[derive(Default, TypePath)] | ||
| pub struct SceneAssetLoader; | ||
|
|
||
| impl AssetLoader for SceneAssetLoader { | ||
| type Asset = MotionGfxScene; | ||
| type Settings = (); | ||
| type Error = BevyError; | ||
|
|
||
| async fn load( | ||
| &self, | ||
| reader: &mut dyn Reader, | ||
| _settings: &Self::Settings, | ||
| _load_context: &mut LoadContext<'_>, | ||
| ) -> Result<Self::Asset, Self::Error> { | ||
| let mut bytes = Vec::new(); | ||
| reader.read_to_end(&mut bytes).await?; | ||
| let scene = ron::de::from_bytes(&bytes)?; | ||
| Ok(MotionGfxScene(scene)) | ||
| } | ||
|
|
||
| fn extensions(&self) -> &[&str] { | ||
| &["mgx.ron"] | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.