Skip to content

Commit

Permalink
Version 0.12.0
Browse files Browse the repository at this point in the history
  • Loading branch information
alteous committed Apr 21, 2019
1 parent acf33a9 commit 6c46bb7
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 48 deletions.
28 changes: 28 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,34 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).

The `gltf` crate adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [0.12.0] - 2019-04-21

### Added

- New image format variants `B8G8R8` and `B8G8R8A8`.
- New export example.

### Changed

- The crate now builds with Rust 2018 edition.
- `Extras` are now exposed as `RawValue`.
- `Index` now implements `Copy`.
- Meshes will no longer report a zero byte stride.
- Updated the following dependendies:
- approx
- base64
- cgmath
- image
- lazy_static
- proc_macro2
- quote
- syn

### Fixed

- Removed an unused field in `Accessor` which was a cause of poor performance.
- Borrow checker complaint regarding `Glb::from_reader`.

## [0.11.3] - 2019-02-21

### Added
Expand Down
96 changes: 48 additions & 48 deletions src/binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,52 @@ fn align_to_multiple_of_four(n: &mut usize) {
*n = (*n + 3) & !3;
}

fn split_binary_gltf<'a>(mut data: &'a [u8]) -> Result<(&'a [u8], Option<&'a [u8]>), Error> {
let (json, mut data) = ChunkHeader::from_reader(&mut data)
.and_then(|json_h| if let ChunkType::Json = json_h.ty {
Ok(json_h)
} else {
Err(Error::ChunkType(json_h.ty))
})
.and_then(|json_h| if json_h.length as usize <= data.len() {
Ok(json_h)
} else {
Err(Error::ChunkLength {
ty: json_h.ty,
length: json_h.length,
length_read: data.len(),
})
})
// We have verified that json_h.length is no greater than that of
// data.len().
.map(|json_h| data.split_at(json_h.length as usize))?;

let bin = if data.len() > 0 {
ChunkHeader::from_reader(&mut data)
.and_then(|bin_h| if let ChunkType::Bin = bin_h.ty {
Ok(bin_h)
} else {
Err(Error::ChunkType(bin_h.ty))
})
.and_then(|bin_h| if bin_h.length as usize <= data.len() {
Ok(bin_h)
} else {
Err(Error::ChunkLength {
ty: bin_h.ty,
length: bin_h.length,
length_read: data.len(),
})
})
// We have verified that bin_h.length is no greater than that
// of data.len().
.map(|bin_h| data.split_at(bin_h.length as usize))
.map(|(x, _)| Some(x))?
} else {
None
};
Ok((json, bin))
}

impl<'a> Glb<'a> {
/// Writes binary glTF to a writer.
pub fn to_writer<W>(&self, mut writer: W) -> Result<(), crate::Error>
Expand Down Expand Up @@ -203,7 +249,7 @@ impl<'a> Glb<'a> {
})
.map_err(crate::Error::Binary)?;
match header.version {
2 => Self::from_v2(data)
2 => split_binary_gltf(data)
.map(|(json, bin)| Glb { header, json: json.into(), bin: bin.map(Into::into) })
.map_err(crate::Error::Binary),
x => Err(crate::Error::Binary(Error::Version(x)))
Expand All @@ -222,7 +268,7 @@ impl<'a> Glb<'a> {
if let Err(e) = reader.read_exact(&mut buf).map_err(Error::Io) {
Err(crate::Error::Binary(e))
} else {
Self::from_v2(&buf)
split_binary_gltf(&buf)
.map(|(json, bin)| Glb {
header,
json: json.to_vec().into(),
Expand All @@ -234,52 +280,6 @@ impl<'a> Glb<'a> {
x => Err(crate::Error::Binary(Error::Version(x)))
}
}

fn from_v2(mut data: &'a [u8]) -> Result<(&'a [u8], Option<&'a [u8]>), Error> {
let (json, mut data) = ChunkHeader::from_reader(&mut data)
.and_then(|json_h| if let ChunkType::Json = json_h.ty {
Ok(json_h)
} else {
Err(Error::ChunkType(json_h.ty))
})
.and_then(|json_h| if json_h.length as usize <= data.len() {
Ok(json_h)
} else {
Err(Error::ChunkLength {
ty: json_h.ty,
length: json_h.length,
length_read: data.len(),
})
})
// We have verified that json_h.length is no greater than that of
// data.len().
.map(|json_h| data.split_at(json_h.length as usize))?;

let bin = if data.len() > 0 {
ChunkHeader::from_reader(&mut data)
.and_then(|bin_h| if let ChunkType::Bin = bin_h.ty {
Ok(bin_h)
} else {
Err(Error::ChunkType(bin_h.ty))
})
.and_then(|bin_h| if bin_h.length as usize <= data.len() {
Ok(bin_h)
} else {
Err(Error::ChunkLength {
ty: bin_h.ty,
length: bin_h.length,
length_read: data.len(),
})
})
// We have verified that bin_h.length is no greater than that
// of data.len().
.map(|bin_h| data.split_at(bin_h.length as usize))
.map(|(x, _)| Some(x))?
} else {
None
};
Ok((json, bin))
}
}

impl fmt::Display for Error {
Expand Down

0 comments on commit 6c46bb7

Please sign in to comment.