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

Remove the dependency on lazy_static #386

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ The top-level `gltf` crate adheres to [Semantic Versioning](http://semver.org/sp

- Feature `image_jpeg_rayon` no longer needed, as `image 0.25.0` now uses `zune-jpeg` for jpeg decoding.

### Changed
- Update `image` to `0.25.0`.

### Removed
- Feature `image_jpeg_rayon` no longer needed, as `image 0.25.0` now uses `zune-jpeg` for jpeg decoding.

## [1.4.0] - 2023-12-17

### Added
Expand Down
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ approx = "0.5"
base64 = { optional = true, version = "0.13" }
byteorder = "1.3"
gltf-json = { path = "gltf-json", version = "=1.4.1" }
lazy_static = "1"
urlencoding = { optional = true, version = "2.1" }
serde_json = { features = ["raw_value"], version = "1.0" }

Expand Down
2 changes: 1 addition & 1 deletion gltf-json/src/extras.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub type Extras = Void;
#[derive(Clone, Default, Serialize, Deserialize, Validate)]
pub struct Void {
#[serde(default, skip_serializing)]
_allow_unknown_fields: (),
pub(crate) _allow_unknown_fields: (),
}

impl fmt::Debug for Void {
Expand Down
37 changes: 36 additions & 1 deletion gltf-json/src/material.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::validation::{Checked, Validate};
use crate::{extensions, texture, Extras, Index};
use crate::{extensions, extras::Void, texture, Extras, Index};
use gltf_derive::Validate;
use serde::{de, ser};
use serde_derive::{Deserialize, Serialize};
Expand Down Expand Up @@ -128,6 +128,41 @@ pub struct Material {
pub extras: Extras,
}

impl Material {
// A const version of the material returned when calling [`Material::default`]
pub const DEFAULT_MATERIAL: Material = Material {
alpha_cutoff: None,
alpha_mode: Checked::Valid(AlphaMode::Opaque),
double_sided: false,
name: None,
pbr_metallic_roughness: PbrMetallicRoughness {
base_color_factor: PbrBaseColorFactor([0.0, 0.0, 0.0, 0.0]),
base_color_texture: None,
metallic_factor: StrengthFactor(0.0),
roughness_factor: StrengthFactor(0.0),
metallic_roughness_texture: None,
extensions: None,
#[cfg(feature = "extras")]
extras: None,
#[cfg(not(feature = "extras"))]
extras: Void {
_allow_unknown_fields: (),
},
},
normal_texture: None,
occlusion_texture: None,
emissive_texture: None,
emissive_factor: EmissiveFactor([0.0, 0.0, 0.0]),
extensions: None,
#[cfg(feature = "extras")]
extras: None,
#[cfg(not(feature = "extras"))]
extras: Void {
_allow_unknown_fields: (),
},
};
}

/// A set of parameter values that are used to define the metallic-roughness
/// material model from Physically-Based Rendering (PBR) methodology.
#[derive(Clone, Debug, Default, Deserialize, Serialize, Validate)]
Expand Down
20 changes: 19 additions & 1 deletion gltf-json/src/texture.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::validation::{Checked, Validate};
use crate::{extensions, image, Extras, Index};
use crate::{extensions, extras::Void, image, Extras, Index};
use gltf_derive::Validate;
use serde::{de, ser};
use serde_derive::{Deserialize, Serialize};
Expand Down Expand Up @@ -165,6 +165,24 @@ pub struct Sampler {
#[cfg_attr(not(feature = "extras"), serde(skip_serializing))]
pub extras: Extras,
}

impl Sampler {
// A const version of the material returned when calling [`Sampler::default`]
pub const DEFAULT_SAMPLER: Sampler = Sampler {
mag_filter: None,
min_filter: None,
name: None,
wrap_s: Checked::Valid(WrappingMode::Repeat),
wrap_t: Checked::Valid(WrappingMode::Repeat),
extensions: None,
#[cfg(feature = "extras")]
extras: None,
#[cfg(not(feature = "extras"))]
extras: Void {
_allow_unknown_fields: (),
},
};
}

fn source_default() -> Index<image::Image> {
Index::new(u32::MAX)
Expand Down
2 changes: 0 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@
extern crate approx;
#[cfg(feature = "import")]
extern crate image as image_crate;
#[macro_use]
extern crate lazy_static;

/// Contains (de)serializable data structures that match the glTF JSON text.
pub extern crate gltf_json as json;
Expand Down
6 changes: 1 addition & 5 deletions src/material.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ pub use json::material::AlphaMode;
#[cfg(feature = "extensions")]
use serde_json::{Map, Value};

lazy_static! {
static ref DEFAULT_MATERIAL: json::material::Material = Default::default();
}

/// The material appearance of a primitive.
#[derive(Clone, Debug)]
pub struct Material<'a> {
Expand Down Expand Up @@ -40,7 +36,7 @@ impl<'a> Material<'a> {
Self {
document,
index: None,
json: &DEFAULT_MATERIAL,
json: &json::material::Material::DEFAULT_MATERIAL,
}
}

Expand Down
6 changes: 1 addition & 5 deletions src/texture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ pub use json::texture::{MagFilter, MinFilter, WrappingMode};
#[cfg(feature = "extensions")]
use serde_json::{Map, Value};

lazy_static! {
static ref DEFAULT_SAMPLER: json::texture::Sampler = Default::default();
}

/// A reference to a `Texture`.
#[derive(Clone, Debug)]
pub struct Info<'a> {
Expand Down Expand Up @@ -64,7 +60,7 @@ impl<'a> Sampler<'a> {
Self {
document,
index: None,
json: &DEFAULT_SAMPLER,
json: &json::texture::Sampler::DEFAULT_SAMPLER,
}
}

Expand Down