use bon::Builder;
use parse_display::{Display, FromStr};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
pub mod import {
use super::*;
#[derive(Clone, Debug, Default, Eq, Hash, PartialEq, Serialize, Deserialize, JsonSchema, Builder)]
#[serde(rename = "GltfImportOptions")]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
#[cfg_attr(
feature = "python",
pyo3_stub_gen::derive::gen_stub_pyclass,
pyo3::pyclass(name = "GltfImportOptions", from_py_object)
)]
#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
pub struct Options {}
#[cfg(feature = "python")]
#[pyo3_stub_gen::derive::gen_stub_pymethods]
#[pyo3::pymethods]
impl Options {
#[new]
pub fn new() -> Self {
Default::default()
}
}
}
pub mod export {
use super::*;
#[derive(Default, Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize, JsonSchema, Builder)]
#[serde(rename = "GltfExportOptions")]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(
feature = "python",
pyo3_stub_gen::derive::gen_stub_pyclass,
pyo3::pyclass(name = "GltfExportOptions", from_py_object)
)]
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
pub struct Options {
#[builder(default)]
pub storage: Storage,
#[builder(default)]
pub presentation: Presentation,
#[serde(default)]
#[builder(default)]
pub include_uuids: bool,
}
#[cfg(feature = "python")]
#[pyo3_stub_gen::derive::gen_stub_pymethods]
#[pyo3::pymethods]
impl Options {
#[new]
pub fn new() -> Self {
Default::default()
}
}
#[derive(
Default, Clone, Copy, Debug, Eq, Hash, PartialEq, Serialize, Deserialize, JsonSchema, Display, FromStr,
)]
#[display(style = "snake_case")]
#[serde(rename = "GltfStorage", rename_all = "snake_case")]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
#[cfg_attr(
feature = "python",
pyo3_stub_gen::derive::gen_stub_pyclass_enum,
pyo3::pyclass(name = "GltfStorage", from_py_object)
)]
#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
pub enum Storage {
Binary,
Standard,
#[default]
Embedded,
}
#[derive(
Default, Clone, Copy, Debug, Eq, Hash, PartialEq, Serialize, Deserialize, JsonSchema, Display, FromStr,
)]
#[display(style = "snake_case")]
#[serde(rename = "GltfPresentation", rename_all = "snake_case")]
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
pub enum Presentation {
Compact,
#[default]
Pretty,
}
}
#[cfg(test)]
mod tests {
use super::export::{Options, Presentation, Storage};
#[test]
fn uuid_metadata_is_opt_in() {
let options: Options = serde_json::from_str(r#"{"storage":"binary","presentation":"compact"}"#).unwrap();
assert_eq!(
options,
Options::builder()
.storage(Storage::Binary)
.presentation(Presentation::Compact)
.build()
);
assert!(!options.include_uuids);
assert!(!Options::default().include_uuids);
assert_eq!(Options::builder().build(), Options::default());
}
#[test]
fn uuid_option_round_trips() {
for include_uuids in [false, true] {
let json = serde_json::json!({
"storage": "binary",
"presentation": "compact",
"include_uuids": include_uuids
});
let options: Options = serde_json::from_value(json.clone()).unwrap();
assert_eq!(options.include_uuids, include_uuids);
assert_eq!(serde_json::to_value(options).unwrap(), json);
}
}
}