kittycad_modeling_cmds/format/
ply.rs

1use parse_display::{Display, FromStr};
2use schemars::JsonSchema;
3use serde::{Deserialize, Serialize};
4
5use crate::{coord, format::Selection, units::UnitLength};
6
7/// Import models in PLY format.
8pub mod import {
9    use super::*;
10
11    /// Options for importing PLY.
12    #[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize, JsonSchema, Display, FromStr)]
13    #[display("coords: {coords}, units: {units}")]
14    #[serde(rename = "PlyImportOptions")]
15    #[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
16    #[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
17    pub struct Options {
18        /// Co-ordinate system of input data.
19        ///
20        /// Defaults to the [KittyCAD co-ordinate system].
21        ///
22        /// [KittyCAD co-ordinate system]: ../coord/constant.KITTYCAD.html
23        pub coords: coord::System,
24
25        /// The units of the input data.
26        ///
27        /// This is very important for correct scaling and when calculating physics properties like
28        /// mass, etc.
29        ///
30        /// Defaults to millimeters.
31        pub units: UnitLength,
32    }
33
34    impl Default for Options {
35        fn default() -> Self {
36            Self {
37                coords: *coord::KITTYCAD,
38                units: UnitLength::Millimeters,
39            }
40        }
41    }
42}
43
44/// Export models in PLY format.
45pub mod export {
46
47    use super::*;
48
49    /// Options for exporting PLY.
50    #[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize, JsonSchema, Display, FromStr)]
51    #[display("coords: {coords}, selection: {selection}, storage: {storage}, units: {units}")]
52    #[serde(rename = "PlyExportOptions")]
53    #[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
54    #[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
55    pub struct Options {
56        /// Co-ordinate system of output data.
57        ///
58        /// Defaults to the [KittyCAD co-ordinate system].
59        ///
60        /// [KittyCAD co-ordinate system]: ../coord/constant.KITTYCAD.html
61        pub coords: coord::System,
62
63        /// Export selection.
64        pub selection: Selection,
65
66        /// The storage for the output PLY file.
67        pub storage: Storage,
68
69        /// Export length unit.
70        ///
71        /// Defaults to millimeters.
72        pub units: UnitLength,
73    }
74
75    impl Default for Options {
76        fn default() -> Self {
77            Self {
78                coords: *coord::KITTYCAD,
79                selection: Default::default(),
80                storage: Default::default(),
81                units: UnitLength::Millimeters,
82            }
83        }
84    }
85
86    /// The storage for the output PLY file.
87    #[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize, JsonSchema, Display, FromStr, Default)]
88    #[display(style = "snake_case")]
89    #[serde(rename = "PlyStorage", rename_all = "snake_case")]
90    #[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
91    #[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
92    pub enum Storage {
93        /// Write numbers in their ascii representation (e.g. -13, 6.28, etc.). Properties are separated by spaces and elements are separated by line breaks.
94        #[default]
95        Ascii,
96        /// Encode payload as binary using little endian.
97        BinaryLittleEndian,
98        /// Encode payload as binary using big endian.
99        BinaryBigEndian,
100    }
101}