-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
278 additions
and
18 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,15 @@ | ||
#![enable(implicit_some)] | ||
( | ||
version: 0, | ||
steps: [ | ||
( | ||
name: "Running Man", | ||
keyframes: [ | ||
(pose: "right-forward", orientation: Right), | ||
(pose: "left-up", orientation: Right), | ||
(pose: "left-forward", orientation: Right), | ||
(pose: "right-up", orientation: Right), | ||
] | ||
), | ||
] | ||
) |
This file contains 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 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 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,4 @@ | ||
pub(crate) struct Step { | ||
pub name: String, | ||
// TODO: add other fields | ||
} |
This file contains 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 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 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 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,74 @@ | ||
//! Defines the external format for defining steps, which are a combination of | ||
//! poses. | ||
//! | ||
//! Best practice: Don't use any of the type of this file outside of parsing | ||
//! logic. Instead, translate to internal types. This allows refactoring | ||
//! internal without changing the external formats. | ||
|
||
use crate::pose_file::ParseFileError; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
const CURRENT_VERSION: u16 = 0; | ||
|
||
/// Format for pose definition files. | ||
#[derive(Deserialize)] | ||
pub(crate) struct StepFile { | ||
pub version: u16, | ||
pub steps: Vec<Step>, | ||
} | ||
|
||
/// Description of a step. | ||
/// | ||
/// A step is a sequence of poses with timing and orientation information. | ||
/// This is the format for external files and loaded in at runtime. | ||
/// It is converted to a [`crate::step::Step`] for step detection. | ||
#[derive(Serialize, Deserialize, Debug, PartialEq)] | ||
pub(crate) struct Step { | ||
pub name: String, | ||
pub keyframes: Vec<StepPosition>, | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Debug, PartialEq)] | ||
pub(crate) struct StepPosition { | ||
/// Reference to the name of a pose | ||
pub pose: String, | ||
/// specify how the pose should be oriented | ||
#[serde(default, skip_serializing_if = "Orientation::any")] | ||
pub orientation: Orientation, | ||
} | ||
|
||
/// Define in which direction a pose should be oriented. | ||
#[derive(Serialize, Deserialize, Debug, PartialEq, Clone, Copy)] | ||
pub(crate) enum Orientation { | ||
ToCamera, | ||
Right, | ||
Away, | ||
Left, | ||
/// It doesn't matter in which direction the pose is done. | ||
Any, | ||
} | ||
|
||
impl StepFile { | ||
pub(crate) fn from_str(text: &str) -> Result<Self, ParseFileError> { | ||
let parsed: StepFile = ron::from_str(text)?; | ||
if parsed.version != CURRENT_VERSION { | ||
return Err(ParseFileError::VersionMismatch { | ||
expected: CURRENT_VERSION, | ||
found: parsed.version, | ||
}); | ||
} | ||
Ok(parsed) | ||
} | ||
} | ||
|
||
impl Orientation { | ||
fn any(&self) -> bool { | ||
matches!(self, Orientation::Any) | ||
} | ||
} | ||
|
||
impl Default for Orientation { | ||
fn default() -> Self { | ||
Self::Any | ||
} | ||
} |
This file contains 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 @@ | ||
use crate::intern::step::Step; | ||
use wasm_bindgen::prelude::wasm_bindgen; | ||
|
||
/// Information about a step for display in the frontend. | ||
#[derive(Debug)] | ||
#[wasm_bindgen] | ||
pub struct StepInfo { | ||
name: String, | ||
// TODO: other fields | ||
} | ||
|
||
#[wasm_bindgen] | ||
impl StepInfo { | ||
#[wasm_bindgen(getter)] | ||
pub fn name(&self) -> String { | ||
self.name.clone() | ||
} | ||
} | ||
|
||
impl From<&Step> for StepInfo { | ||
fn from(value: &Step) -> Self { | ||
Self { | ||
name: value.name.clone(), | ||
} | ||
} | ||
} |
This file contains 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 |
---|---|---|
@@ -1,15 +1,15 @@ | ||
#[macro_export] | ||
#[cfg(target_arch="wasm32")] | ||
#[cfg(target_arch = "wasm32")] | ||
macro_rules! println { | ||
( $( $t:tt )* ) => { | ||
web_sys::console::log_1(&format!( $( $t )* ).into()); | ||
} | ||
} | ||
|
||
#[macro_export] | ||
#[cfg(not(target_arch="wasm32"))] | ||
#[cfg(not(target_arch = "wasm32"))] | ||
macro_rules! println { | ||
( $( $t:tt )* ) => { | ||
println!( $( $t )* ); | ||
} | ||
} | ||
} |
Oops, something went wrong.