Skip to content

Commit

Permalink
Add serde support via typetag
Browse files Browse the repository at this point in the history
  • Loading branch information
thatcomputerguy0101 committed Dec 12, 2024
1 parent 59b6940 commit 68c5a3d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,13 @@ pcd = ["pcd-rs"]

vol = []

serde = ["dep:serde", "half/serde", "cgmath/serde"]
serde = ["dep:serde", "dep:typetag", "half/serde", "cgmath/serde"]

[dependencies]
cgmath = "0.18"
half = {version="2", features=["std", "num-traits", "zerocopy"]}
thiserror = "2"
dyn-clone = { version = "1.0" }
reqwest = {version = "0.12", optional = true, default-features = false }
gltf = { version = "1", optional = true, features=["KHR_materials_ior", "KHR_materials_transmission"] }
wavefront_obj = { version = "10", optional = true }
Expand All @@ -56,7 +57,7 @@ resvg = { version = "0.44", optional = true }
pcd-rs = { version = "0.12", optional = true, features = ["derive"] }
data-url = {version = "0.3", optional = true }
serde = {version= "1", optional = true, features = ["derive", "rc"] }
dyn-clone = { version = "1.0" }
typetag = { version = "0.2", optional = true }

[target.'cfg(target_arch = "wasm32")'.dependencies]
web-sys = { version = "0.3", features = ['Document', 'Window'] }
2 changes: 2 additions & 0 deletions src/camera.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ impl Frustum {
///
/// A general 3D to 2D projection, as used by [`Camera`](Camera::set_custom_projection). Custom projections should implement this trait.
///
#[cfg_attr(feature = "serde", typetag::serde)]
pub trait Projection: DynClone + Any + Debug {
///
/// Generates a projection matrix from the provided zoom factor (if required), aspect ratio, and near/far plane distances
Expand Down Expand Up @@ -275,6 +276,7 @@ pub enum ProjectionType {
},
}

#[cfg_attr(feature = "serde", typetag::serde)]
impl Projection for ProjectionType {
fn generate(&self, zoom: Option<f32>, aspect: f32, z_near: f32, z_far: f32) -> Mat4 {
match self {
Expand Down

0 comments on commit 68c5a3d

Please sign in to comment.