From 5ff9603ee3dbfcff1ab7d3f45ce916c1b954a0a9 Mon Sep 17 00:00:00 2001 From: David Harvey-Macaulay Date: Wed, 13 Sep 2017 15:32:38 +0100 Subject: [PATCH 1/6] Add size_hint to gltf::Images --- src/gltf.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/gltf.rs b/src/gltf.rs index 76838c56..a1a687aa 100644 --- a/src/gltf.rs +++ b/src/gltf.rs @@ -477,6 +477,10 @@ impl<'a> Iterator for Images<'a> { .next() .map(|(index, json)| Image::new(self.gltf, index, json)) } + + fn size_hint(&self) -> (usize, Option) { + self.iter.size_hint() + } } impl<'a> ExactSizeIterator for Materials<'a> {} From 85503079236209eb75072c97201c6fbe1338b1cf Mon Sep 17 00:00:00 2001 From: Benjamin Wasty Date: Mon, 18 Sep 2017 18:22:08 +0200 Subject: [PATCH 2/6] Add travis_wait to travis config might solve #38 --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index cc9fd2e7..50e1c527 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,11 +8,13 @@ rust: sudo: false script: + - "travis_wait 30 sleep 1800 &" - cargo build --verbose --all-features --all - cargo test --verbose --all-features --all os: - linux + - osx matrix: allow_failures: From 048c30ed8bb9f252f6e318f411b4142424b55605 Mon Sep 17 00:00:00 2001 From: David Harvey-Macaulay Date: Fri, 22 Sep 2017 12:02:00 +0100 Subject: [PATCH 3/6] InterpolationAlgorithm -> Interpolation TrsProperty -> Property --- gltf-json/src/animation.rs | 24 ++++++++++++------------ src/animation.rs | 2 +- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/gltf-json/src/animation.rs b/gltf-json/src/animation.rs index 1f124029..d9ddcba8 100644 --- a/gltf-json/src/animation.rs +++ b/gltf-json/src/animation.rs @@ -30,7 +30,7 @@ pub const VALID_TRS_PROPERTIES: &'static [&'static str] = &[ /// Specifies an interpolation algorithm. #[derive(Clone, Copy, Debug, Deserialize)] -pub enum InterpolationAlgorithm { +pub enum Interpolation { /// Linear interpolation. /// /// The animated values are linearly interpolated between keyframes. @@ -67,7 +67,7 @@ pub enum InterpolationAlgorithm { /// Specifies a TRS property. #[derive(Clone, Copy, Debug, Deserialize)] -pub enum TrsProperty { +pub enum Property { /// XYZ translation vector. Translation = 1, @@ -142,7 +142,7 @@ pub struct Target { /// The name of the node's TRS property to modify or the 'weights' of the /// morph targets it instantiates. - pub path: Checked, + pub path: Checked, } /// Defines a keyframe graph but not its target. @@ -161,7 +161,7 @@ pub struct Sampler { /// The interpolation algorithm. #[serde(default)] - pub interpolation: Checked, + pub interpolation: Checked, /// The index of an accessor containing keyframe output values. pub output: Index, @@ -183,19 +183,19 @@ impl Validate for Animation { } } -impl Default for InterpolationAlgorithm { +impl Default for Interpolation { fn default() -> Self { - InterpolationAlgorithm::Linear + Interpolation::Linear } } -impl<'de> de::Deserialize<'de> for Checked { +impl<'de> de::Deserialize<'de> for Checked { fn deserialize(deserializer: D) -> Result where D: de::Deserializer<'de> { struct Visitor; impl<'de> de::Visitor<'de> for Visitor { - type Value = Checked; + type Value = Checked; fn expecting(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "any of: {:?}", VALID_INTERPOLATION_ALGORITHMS) @@ -204,7 +204,7 @@ impl<'de> de::Deserialize<'de> for Checked { fn visit_str(self, value: &str) -> Result where E: de::Error { - use self::InterpolationAlgorithm::*; + use self::Interpolation::*; use validation::Checked::*; Ok(match value { "LINEAR" => Valid(Linear), @@ -219,13 +219,13 @@ impl<'de> de::Deserialize<'de> for Checked { } } -impl<'de> de::Deserialize<'de> for Checked { +impl<'de> de::Deserialize<'de> for Checked { fn deserialize(deserializer: D) -> Result where D: de::Deserializer<'de> { struct Visitor; impl<'de> de::Visitor<'de> for Visitor { - type Value = Checked; + type Value = Checked; fn expecting(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "any of: {:?}", VALID_TRS_PROPERTIES) @@ -234,7 +234,7 @@ impl<'de> de::Deserialize<'de> for Checked { fn visit_str(self, value: &str) -> Result where E: de::Error { - use self::TrsProperty::*; + use self::Property::*; use validation::Checked::*; Ok(match value { "translation" => Valid(Translation), diff --git a/src/animation.rs b/src/animation.rs index 217e0a7a..c78abcd7 100644 --- a/src/animation.rs +++ b/src/animation.rs @@ -10,7 +10,7 @@ use std::slice; use {accessor, json, scene, Gltf}; -pub use json::animation::{InterpolationAlgorithm, TrsProperty}; +pub use json::animation::{Interpolation, Property}; /// A keyframe animation. #[derive(Clone, Debug)] From aa9278fb31b41088299e11b2e71e387339142398 Mon Sep 17 00:00:00 2001 From: David Harvey-Macaulay Date: Fri, 22 Sep 2017 12:05:25 +0100 Subject: [PATCH 4/6] Bump crate version --- Cargo.toml | 4 ++-- gltf-derive/Cargo.toml | 2 +- gltf-importer/Cargo.toml | 6 +++--- gltf-json/Cargo.toml | 4 ++-- gltf-utils/Cargo.toml | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ce63a9fa..67be793e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "gltf" -version = "0.9.2" +version = "1.0.0" authors = ["David Harvey-Macaulay "] description = "glTF 2.0 loader" documentation = "https://docs.rs/gltf" @@ -26,7 +26,7 @@ members = ["gltf-derive", "gltf-json", "gltf-importer", "gltf-utils"] [dependencies] approx = "0.1.1" cgmath = "0.15" -gltf-json = { path = "gltf-json", version = "0.9.2" } +gltf-json = { path = "gltf-json", version = "1.0.0" } lazy_static = "0.2" [features] diff --git a/gltf-derive/Cargo.toml b/gltf-derive/Cargo.toml index 313a67f4..4cfbc9fb 100644 --- a/gltf-derive/Cargo.toml +++ b/gltf-derive/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "gltf-derive" -version = "0.9.2" +version = "1.0.0" authors = ["David Harvey-Macaulay "] description = "Internal macros for the gltf crate" repository = "https://github.com/gltf-rs/gltf" diff --git a/gltf-importer/Cargo.toml b/gltf-importer/Cargo.toml index 67392245..5c733265 100644 --- a/gltf-importer/Cargo.toml +++ b/gltf-importer/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "gltf-importer" -version = "0.9.2" +version = "1.0.0" authors = ["David Harvey-Macaulay "] description = "Reference importer for the gltf crate" repository = "https://github.com/gltf-rs/gltf" @@ -8,8 +8,8 @@ license = "MIT/Apache-2.0" [dependencies] base64 = "0.6" -gltf = { path = "..", version = "0.9.2" } -gltf-utils = { path = "../gltf-utils", version = "0.9.2" } +gltf = { path = "..", version = "1.0.0" } +gltf-utils = { path = "../gltf-utils", version = "1.0.0" } [features] default = [] diff --git a/gltf-json/Cargo.toml b/gltf-json/Cargo.toml index c720ebd5..7f264af2 100644 --- a/gltf-json/Cargo.toml +++ b/gltf-json/Cargo.toml @@ -1,13 +1,13 @@ [package] name = "gltf-json" -version = "0.9.2" +version = "1.0.0" authors = ["David Harvey-Macaulay "] description = "JSON parsing for the gltf crate" repository = "https://github.com/gltf-rs/gltf" license = "MIT/Apache-2.0" [dependencies] -gltf-derive = { path = "../gltf-derive", version = "0.9.2" } +gltf-derive = { path = "../gltf-derive", version = "1.0.0" } serde = "1.0" serde_derive = "1.0" serde_json = "1.0" diff --git a/gltf-utils/Cargo.toml b/gltf-utils/Cargo.toml index d68a832b..aa0b1855 100644 --- a/gltf-utils/Cargo.toml +++ b/gltf-utils/Cargo.toml @@ -1,13 +1,13 @@ [package] name = "gltf-utils" -version = "0.9.2" +version = "1.0.0" authors = ["David Harvey-Macaulay "] description = "Utilities to complement the gltf crate" repository = "https://github.com/gltf-rs/gltf" license = "MIT/Apache-2.0" [dependencies] -gltf = { path = "..", version = "0.9.2" } +gltf = { path = "..", version = "1.0.0" } [features] default = [] From 65f65b937eb3a3c484c8f80265657c310f413506 Mon Sep 17 00:00:00 2001 From: David Harvey-Macaulay Date: Fri, 22 Sep 2017 12:07:16 +0100 Subject: [PATCH 5/6] Update animation getters --- src/animation.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/animation.rs b/src/animation.rs index c78abcd7..eb98da68 100644 --- a/src/animation.rs +++ b/src/animation.rs @@ -197,7 +197,7 @@ impl<'a> Target<'a> { /// Returns the node's TRS property to modify or the 'weights' of the morph /// targets it instantiates. - pub fn path(&self) -> TrsProperty { + pub fn path(&self) -> Property { self.json.path.unwrap() } } @@ -246,7 +246,7 @@ impl<'a> Sampler<'a> { } /// Returns the keyframe interpolation algorithm. - pub fn interpolation(&self) -> InterpolationAlgorithm { + pub fn interpolation(&self) -> Interpolation { self.json.interpolation.unwrap() } From dc213884eff0122b53005c09faff2ab97d2f95db Mon Sep 17 00:00:00 2001 From: David Harvey-Macaulay Date: Fri, 22 Sep 2017 12:22:22 +0100 Subject: [PATCH 6/6] Add buffer::Data --- gltf-importer/src/lib.rs | 26 +++++++++++++++++--------- src/buffer.rs | 29 ++++++++++++++++++++++------- 2 files changed, 39 insertions(+), 16 deletions(-) diff --git a/gltf-importer/src/lib.rs b/gltf-importer/src/lib.rs index 3037940c..ef89e226 100644 --- a/gltf-importer/src/lib.rs +++ b/gltf-importer/src/lib.rs @@ -50,7 +50,7 @@ pub enum Error { /// Base 64 decoding error. Base64Decoding(base64::DecodeError), - + /// A glTF extension required by the asset has not been enabled by the user. ExtensionDisabled(String), @@ -69,6 +69,9 @@ pub enum Error { /// Failure when deserializing .gltf or .glb JSON. MalformedJson(json::Error), + /// The `BIN` section of binary `glTF` is required but not provided. + MissingBin, + /// The .gltf data is invalid. Validation(Vec<(json::Path, validation::Error)>), } @@ -154,14 +157,18 @@ fn load_external_buffers( ) -> Result>, Error> { let mut buffers = vec![]; for (index, buffer) in gltf.buffers().enumerate() { - let uri = buffer.uri(); - let data = if uri == "#bin" { - Ok(bin.take().unwrap()) - } else if uri.starts_with("data:") { - Ok(parse_data_uri(uri)?) - } else { - let path = base_path.parent().unwrap_or(Path::new("./")).join(uri); - read_to_end(&path) + let data = match buffer.data() { + gltf::buffer::Data::Bin => bin.take().ok_or(Error::MissingBin), + gltf::buffer::Data::Uri(uri) if uri.starts_with("data:") => { + parse_data_uri(uri) + }, + gltf::buffer::Data::Uri(uri) => { + let path = base_path + .parent() + .unwrap_or(Path::new("./")) + .join(uri); + read_to_end(&path) + }, }?; if data.len() < buffer.length() { let path = json::Path::new().field("buffers").index(index); @@ -312,6 +319,7 @@ impl StdError for Error { Io(_) => "I/O error", Gltf(_) => "Error from gltf crate", MalformedJson(_) => "Malformed .gltf / .glb JSON", + MissingBin => "`BIN` chunk of binary `glTF` required but not provided", Validation(_) => "Asset failed validation tests", } } diff --git a/src/buffer.rs b/src/buffer.rs index 3874398b..538dd202 100644 --- a/src/buffer.rs +++ b/src/buffer.rs @@ -13,6 +13,15 @@ use Gltf; pub use json::buffer::Target; +/// The data referenced by a `Buffer`. +pub enum Data<'a> { + /// Buffer data is contained in the `BIN` section of binary `glTF`. + Bin, + + /// Buffer data is contained in an external data source. + Uri(&'a str), +} + /// A buffer points to binary data representing geometry, animations, or skins. #[derive(Clone, Debug)] pub struct Buffer<'a> { @@ -67,15 +76,21 @@ impl<'a> Buffer<'a> { self.json } + /// Returns a reference to the buffer data. + pub fn data(&self) -> Data { + if let Some(uri) = self.uri() { + Data::Uri(uri) + } else { + Data::Bin + } + } + /// Returns the uniform resource identifier for the buffer data. /// - /// # Notes - /// - /// When the buffer is sourced from the `BIN` section of binary glTF, the - /// fragment `"#bin"` is returned. This is non-standard according to the - /// glTF specification. - pub fn uri(&self) -> &str { - self.json.uri.as_ref().map(String::as_str).unwrap_or("#bin") + /// Returns `None` when the buffer is sourced from the `BIN` section of + /// binary `glTF`. + fn uri(&self) -> Option<&str> { + self.json.uri.as_ref().map(String::as_str) } /// The length of the buffer in bytes.