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

V1.0 #108

Closed
wants to merge 8 commits into from
Closed

V1.0 #108

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "gltf"
version = "0.9.2"
version = "1.0.0"
authors = ["David Harvey-Macaulay <[email protected]>"]
description = "glTF 2.0 loader"
documentation = "https://docs.rs/gltf"
Expand All @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion gltf-derive/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "gltf-derive"
version = "0.9.2"
version = "1.0.0"
authors = ["David Harvey-Macaulay <[email protected]>"]
description = "Internal macros for the gltf crate"
repository = "https://github.com/gltf-rs/gltf"
Expand Down
6 changes: 3 additions & 3 deletions gltf-importer/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
[package]
name = "gltf-importer"
version = "0.9.2"
version = "1.0.0"
authors = ["David Harvey-Macaulay <[email protected]>"]
description = "Reference importer for the gltf crate"
repository = "https://github.com/gltf-rs/gltf"
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 = []
Expand Down
26 changes: 17 additions & 9 deletions gltf-importer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),

Expand All @@ -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)>),
}
Expand Down Expand Up @@ -154,14 +157,18 @@ fn load_external_buffers(
) -> Result<Vec<Vec<u8>>, 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);
Expand Down Expand Up @@ -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",
}
}
Expand Down
4 changes: 2 additions & 2 deletions gltf-json/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[package]
name = "gltf-json"
version = "0.9.2"
version = "1.0.0"
authors = ["David Harvey-Macaulay <[email protected]>"]
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"
Expand Down
24 changes: 12 additions & 12 deletions gltf-json/src/animation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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,

Expand Down Expand Up @@ -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<TrsProperty>,
pub path: Checked<Property>,
}

/// Defines a keyframe graph but not its target.
Expand All @@ -161,7 +161,7 @@ pub struct Sampler {

/// The interpolation algorithm.
#[serde(default)]
pub interpolation: Checked<InterpolationAlgorithm>,
pub interpolation: Checked<Interpolation>,

/// The index of an accessor containing keyframe output values.
pub output: Index<accessor::Accessor>,
Expand All @@ -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<InterpolationAlgorithm> {
impl<'de> de::Deserialize<'de> for Checked<Interpolation> {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: de::Deserializer<'de>
{
struct Visitor;
impl<'de> de::Visitor<'de> for Visitor {
type Value = Checked<InterpolationAlgorithm>;
type Value = Checked<Interpolation>;

fn expecting(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "any of: {:?}", VALID_INTERPOLATION_ALGORITHMS)
Expand All @@ -204,7 +204,7 @@ impl<'de> de::Deserialize<'de> for Checked<InterpolationAlgorithm> {
fn visit_str<E>(self, value: &str) -> Result<Self::Value, E>
where E: de::Error
{
use self::InterpolationAlgorithm::*;
use self::Interpolation::*;
use validation::Checked::*;
Ok(match value {
"LINEAR" => Valid(Linear),
Expand All @@ -219,13 +219,13 @@ impl<'de> de::Deserialize<'de> for Checked<InterpolationAlgorithm> {
}
}

impl<'de> de::Deserialize<'de> for Checked<TrsProperty> {
impl<'de> de::Deserialize<'de> for Checked<Property> {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: de::Deserializer<'de>
{
struct Visitor;
impl<'de> de::Visitor<'de> for Visitor {
type Value = Checked<TrsProperty>;
type Value = Checked<Property>;

fn expecting(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "any of: {:?}", VALID_TRS_PROPERTIES)
Expand All @@ -234,7 +234,7 @@ impl<'de> de::Deserialize<'de> for Checked<TrsProperty> {
fn visit_str<E>(self, value: &str) -> Result<Self::Value, E>
where E: de::Error
{
use self::TrsProperty::*;
use self::Property::*;
use validation::Checked::*;
Ok(match value {
"translation" => Valid(Translation),
Expand Down
4 changes: 2 additions & 2 deletions gltf-utils/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[package]
name = "gltf-utils"
version = "0.9.2"
version = "1.0.0"
authors = ["David Harvey-Macaulay <[email protected]>"]
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 = []
Expand Down
6 changes: 3 additions & 3 deletions src/animation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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()
}
}
Expand Down Expand Up @@ -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()
}

Expand Down
29 changes: 22 additions & 7 deletions src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ use Gltf;

pub use json::buffer::Target;

/// The data referenced by a `Buffer`.
pub enum Data<'a> {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Closes #106

/// 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> {
Expand Down Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions src/gltf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<usize>) {
self.iter.size_hint()
}
}

impl<'a> ExactSizeIterator for Materials<'a> {}
Expand Down