Skip to content

Commit

Permalink
Read hierarchy from crate file
Browse files Browse the repository at this point in the history
  • Loading branch information
mxpv committed Jan 7, 2024
1 parent e4efb84 commit ae5088a
Show file tree
Hide file tree
Showing 7 changed files with 691 additions and 124 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ anyhow = "1.0.79"
bytemuck = { version = "1.14.0", features = ["derive"] }
strum = { version = "0.25.0", features = ["derive"] }
lz4_flex = "0.11.1"
glam = { version = "0.25.0", features = ["bytemuck"] }
2 changes: 1 addition & 1 deletion examples/dump_usdc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fn main() -> Result<()> {
.context("Missing path to usdc file, use: cargo run --example dump_usdc {PATH_TO_FILE}.usdc")?;

let reader = fs::File::open(path).context("Failed to read crate file")?;
let file = CrateFile::from_reader(reader).context("Failed to read crate file")?;
let file = CrateFile::open(reader).context("Failed to read crate file")?;

println!("-- Bootrap header");
println!("Magic: {:?}", file.bootstrap.ident);
Expand Down
108 changes: 107 additions & 1 deletion src/sdf/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
use strum::{Display, EnumCount, FromRepr};

mod path;
mod variant;

pub use path::Path;
pub use variant::Variant;

/// An enum that specifies the type of an object.
/// Objects are entities that have fields and are addressable by path.
#[repr(u32)]
#[derive(Default, Clone, Copy, PartialEq, Eq, FromRepr, EnumCount, Display)]
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, FromRepr, EnumCount, Display)]
pub enum SpecType {
// The unknown type has a value of 0 so that SdfSpecType() is unknown.
#[default]
Expand All @@ -28,3 +30,107 @@ pub enum SpecType {
Variant = 10,
VariantSet = 11,
}

#[repr(i32)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, FromRepr)]
pub enum Specifier {
Def,
Over,
Class,
}

/// An enum that defines permission levels.
///
/// Permissions control which layers may refer to or express
/// opinions about a prim. Opinions expressed about a prim, or
/// relationships to that prim, by layers that are not allowed
/// permission to access the prim will be ignored.
#[repr(i32)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, FromRepr)]
pub enum Permission {
Public,
Private,
}

/// An enum that identifies variability types for attributes.
/// Variability indicates whether the attribute may vary over time and
/// value coordinates, and if its value comes through authoring or
/// or from its owner.
#[repr(i32)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, FromRepr)]
pub enum Variability {
Varying,
Uniform,
}

/// Represents a time offset and scale between layers.
#[derive(Debug, Clone, Copy)]
pub struct LayerOffset {
/// Time offset.
pub offset: f64,
/// Scale factor.
pub scale: f64,
}

impl Default for LayerOffset {
fn default() -> Self {
Self {
offset: 0.0,
scale: 1.0,
}
}
}

impl LayerOffset {
#[inline]
pub fn new(offset: f64, scale: f64) -> Self {
Self { offset, scale }
}

#[inline]
pub fn is_valid(&self) -> bool {
self.offset.is_finite() && self.scale.is_finite()
}
}

/// Represents a payload and all its meta data.
///
/// A payload represents a prim reference to an external layer. A payload
/// is similar to a prim reference (see SdfReference) with the major
/// difference that payloads are explicitly loaded by the user.
///
/// Unloaded payloads represent a boundary that lazy composition and
/// system behaviors will not traverse across, providing a user-visible
/// way to manage the working set of the scene.
#[derive(Debug)]
pub struct Payload {
/// The asset path to the external layer.
pub asset_path: String,
pub prim_path: Path,
pub layer_offset: LayerOffset,
}

/// Value type representing a list-edit operation.
///
/// `ListOp`` is a value type representing an operation that edits a list.
/// It may add or remove items, reorder them, or replace the list entirely.
#[derive(Default, Debug)]
pub struct ListOp<T: Default> {
pub explicit: bool,
pub explicit_items: Vec<T>,
pub added_items: Vec<T>,
pub prepended_items: Vec<T>,
pub appended_items: Vec<T>,
pub deleted_items: Vec<T>,
pub ordered_items: Vec<T>,
}

pub type IntListOp = ListOp<i32>;
pub type UintListOp = ListOp<u32>;

pub type Int64ListOp = ListOp<i64>;
pub type Uint64ListOp = ListOp<u64>;

pub type StringListOp = ListOp<String>;
pub type TokenListOp = ListOp<String>;
pub type PathListOp = ListOp<Path>;
84 changes: 84 additions & 0 deletions src/sdf/variant.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
use glam::*;

use super::*;

/// Variant is a type that can hold any of the SDF types.
///
/// Suffixes:
/// - d: double
/// - f: float
/// - h: half
/// - i: int
///
/// NOTE: Halfs are not supported in Rust by default, so floats are used instead.
#[derive(Debug)]
pub enum Variant {
Bool(bool),
Uchar(u8),
Int(i32),
Uint(u32),
Int64(i64),
Uint64(u64),

Half(f32),
Float(f32),
Double(f64),

String(String),
Token(String),
AssetPath(String),

Quatd(DQuat),
Quatf(Quat),

Vec2d(DVec2),
Vec2f(Vec2),
Vec2i(IVec2),

Vec3d(DVec3),
Vec3f(Vec3),
Vec3i(IVec3),

Vec4d(DVec4),
Vec4f(Vec4),
Vec4i(IVec4),

Matrix2d(DMat2),
Matrix3d(DMat3),
Matrix4d(DMat4),

Dictionary,
TokenListOp(TokenListOp),
StringListOp(StringListOp),
PathListOp(PathListOp),
ReferenceListOp,
IntListOp(IntListOp),
Int64ListOp(Int64ListOp),
UIntListOp(UintListOp),
UInt64ListOp(Uint64ListOp),

PathVector,
TokenVector(Vec<String>),
Specifier(Specifier),
Permission(Permission),
Variability(Variability),

VariantSelectionMap,
TimeSamples,
Payload(Payload),
DoubleVector(Vec<f32>),
LayerOffsetVector(Vec<LayerOffset>),
StringVector(Vec<String>),
ValueBlock,
Value,

UnregisteredValue,
UnregisteredValueListOp,
PayloadListOp,

TimeCode(f64),
PathExpression,

/// Values not yet supported.
Unimplemented,
}
Loading

0 comments on commit ae5088a

Please sign in to comment.