Skip to content

Commit fbe0166

Browse files
authored
Add 3D assets for each KCL example (#7995)
Each KCL example will generate a GLTF file and store it in the repo. This will be used for adding 3D interactive models to the KCL docs pages. Once this has merged, follow-up PRs will: - Include the models in the handlebars template for generating each KCL function's markdown doc - In the `website` repo, copy the models from the `documentation` submodule to a public static assets dir.
1 parent 596698b commit fbe0166

File tree

184 files changed

+727825
-4
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

184 files changed

+727825
-4
lines changed

.github/workflows/generate-website-docs.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,11 @@ jobs:
4040
# cleanup old
4141
rm -rf documentation/content/pages/docs/kcl-std
4242
rm -rf documentation/content/pages/docs/kcl-lang
43+
rm -rf documentation/content/kcl-test-outputs
4344
# move new
4445
mv -f docs/kcl-std documentation/content/pages/docs
4546
mv -f docs/kcl-lang documentation/content/pages/docs
47+
mv -f rust/kcl-lib/tests/outputs documentation/content/kcl-test-outputs
4648
# We don't need the README
4749
rm documentation/content/pages/docs/kcl-std/README.md
4850
- name: move kcl-samples

docs/kcl-std/functions/std-transform-mirror2d.md

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

rust/justfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cnr := "cargo nextest run"
1+
cnr := "cargo nextest run --no-fail-fast"
22
cita := "cargo insta test --accept"
33
kcl_lib_flags := "-p kcl-lib --features artifact-graph"
44

rust/kcl-lib/src/docs/kcl_doc.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1344,7 +1344,7 @@ mod test {
13441344
if i != number {
13451345
continue;
13461346
}
1347-
let result = match crate::test_server::execute_and_snapshot(&eg.0, None).await {
1347+
let result = match crate::test_server::execute_and_snapshot_3d(&eg.0, None).await {
13481348
Err(crate::errors::ExecError::Kcl(e)) => {
13491349
panic!("Error testing example {}{i}: {}", d.name, e.error.message());
13501350
}
@@ -1359,9 +1359,18 @@ mod test {
13591359
"tests/outputs/serial_test_example_fn_{}{i}.png",
13601360
qualname.replace("::", "-")
13611361
),
1362-
&result,
1362+
&result.image,
13631363
0.99,
13641364
);
1365+
for gltf_file in result.gltf {
1366+
let path = format!(
1367+
"tests/outputs/models/serial_test_example_fn_{}{i}_{}",
1368+
qualname.replace("::", "-"),
1369+
gltf_file.name,
1370+
);
1371+
let mut f = std::fs::File::create(path).expect("could not create file");
1372+
std::io::Write::write_all(&mut f, &gltf_file.contents).expect("could not write to file");
1373+
}
13651374
return;
13661375
}
13671376

rust/kcl-lib/src/test_server.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
33
use std::path::PathBuf;
44

5+
use kittycad_modeling_cmds::websocket::RawFile;
6+
57
use crate::{
68
ConnectionError, ExecError, KclError, KclErrorWithOutputs, Program,
79
engine::new_zoo_client,
@@ -29,6 +31,35 @@ pub async fn execute_and_snapshot(code: &str, current_file: Option<PathBuf>) ->
2931
res
3032
}
3133

34+
pub struct Snapshot3d {
35+
/// Bytes of the snapshot.
36+
pub image: image::DynamicImage,
37+
/// Various GLTF files for the resulting export.
38+
pub gltf: Vec<RawFile>,
39+
}
40+
41+
/// Executes a kcl program and takes a snapshot of the result.
42+
pub async fn execute_and_snapshot_3d(code: &str, current_file: Option<PathBuf>) -> Result<Snapshot3d, ExecError> {
43+
let ctx = new_context(true, current_file).await?;
44+
let program = Program::parse_no_errs(code).map_err(KclErrorWithOutputs::no_outputs)?;
45+
let image = do_execute_and_snapshot(&ctx, program)
46+
.await
47+
.map(|(_, _, snap)| snap)
48+
.map_err(|err| err.error)?;
49+
let gltf_res = ctx
50+
.export(kittycad_modeling_cmds::format::OutputFormat3d::Gltf(Default::default()))
51+
.await;
52+
let gltf = match gltf_res {
53+
Err(err) if err.message() == "Nothing to export" => Vec::new(),
54+
Err(err) => {
55+
eprintln!("Error exporting: {}", err.message());
56+
Vec::new()
57+
}
58+
Ok(x) => x,
59+
};
60+
ctx.close().await;
61+
Ok(Snapshot3d { image, gltf })
62+
}
3263
/// Executes a kcl program and takes a snapshot of the result.
3364
/// This returns the bytes of the snapshot.
3465
#[cfg(test)]

rust/kcl-lib/tests/outputs/models/serial_test_example_fn_std-appearance-hexString0_output.gltf

Lines changed: 617 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)