Skip to content
Draft
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
14 changes: 14 additions & 0 deletions modeling-cmds/openapi/api.json
Original file line number Diff line number Diff line change
Expand Up @@ -4134,6 +4134,13 @@
}
]
},
"imported_files": {
"description": "Original imported files to embed in glTF source metadata. Paths are relative to the source project. Other export formats ignore these files.",
"type": "array",
"items": {
"$ref": "#/components/schemas/ImportFile"
}
},
"kcl_source": {
"nullable": true,
"description": "KCL source to embed in formats that support source metadata.",
Expand Down Expand Up @@ -4176,6 +4183,13 @@
}
]
},
"imported_files": {
"description": "Original imported files to embed in glTF source metadata. Paths are relative to the source project. Other export formats ignore these files.",
"type": "array",
"items": {
"$ref": "#/components/schemas/ImportFile"
}
},
"kcl_source": {
"nullable": true,
"description": "KCL source to embed in formats that support source metadata.",
Expand Down
10 changes: 10 additions & 0 deletions modeling-cmds/src/def_enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,11 @@ define_modeling_cmd_enum! {
/// KCL source to embed in formats that support source metadata.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub kcl_source: Option<KclProject>,
/// Original imported files to embed in glTF source metadata.
/// Paths are relative to the source project. Other export formats ignore these files.
#[builder(default)]
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub imported_files: Vec<super::ImportFile>,
}

/// Export the scene to a file.
Expand All @@ -715,6 +720,11 @@ define_modeling_cmd_enum! {
/// KCL source to embed in formats that support source metadata.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub kcl_source: Option<KclProject>,
/// Original imported files to embed in glTF source metadata.
/// Paths are relative to the source project. Other export formats ignore these files.
#[builder(default)]
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub imported_files: Vec<super::ImportFile>,
}

/// What is this entity's parent?
Expand Down
63 changes: 63 additions & 0 deletions modeling-cmds/tests/export_imported_files.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
//! Compatibility and byte-preservation tests for original files supplied with exports.

use kittycad_modeling_cmds::{
each_cmd::{Export, Export3d},
format::{gltf::export::Options, OutputFormat3d},
ImportFile, ModelingCmd,
};
use serde_json::json;

#[test]
fn old_export_requests_and_builders_omit_imported_files() {
let format = OutputFormat3d::Gltf(Options::default());
for command in [
ModelingCmd::from(Export3d::builder().format(format.clone()).build()),
ModelingCmd::from(Export::builder().format(format.clone()).build()),
] {
let value = serde_json::to_value(&command).unwrap();
assert!(value.get("imported_files").is_none());
assert_eq!(serde_json::from_value::<ModelingCmd>(value).unwrap(), command);
}
}

#[test]
fn both_export_commands_round_trip_original_binary_files() {
let files = vec![
ImportFile::builder()
.path("parts/reference.step".to_owned())
.data(vec![0, 255, 128, 13, 10])
.build(),
ImportFile::builder()
.path("parts/empty.bin".to_owned())
.data(Vec::new())
.build(),
];
let format = OutputFormat3d::Gltf(Options::default());
for command in [
ModelingCmd::from(
Export3d::builder()
.format(format.clone())
.imported_files(files.clone())
.build(),
),
ModelingCmd::from(
Export::builder()
.format(format.clone())
.imported_files(files.clone())
.build(),
),
] {
let value = serde_json::to_value(&command).unwrap();
assert_eq!(
value["imported_files"],
json!([
{"path": "parts/reference.step", "data": [0, 255, 128, 13, 10]},
{"path": "parts/empty.bin", "data": []}
])
);
assert_eq!(serde_json::from_value::<ModelingCmd>(value).unwrap(), command);
let bson = bson::to_vec(&command).unwrap();
assert_eq!(bson::from_slice::<ModelingCmd>(&bson).unwrap(), command);
assert!(format!("{command:?}").contains("<redacted>"));
}
}
Loading