Remove import function from std (#6241)
Signed-off-by: Nick Cameron <nrc@ncameron.org>
This commit is contained in:
File diff suppressed because one or more lines are too long
@ -99073,387 +99073,6 @@
|
|||||||
"// Hollow a sketch on face object.\nsize = 100\ncase = startSketchOn(-XZ)\n |> startProfileAt([-size, -size], %)\n |> line(end = [2 * size, 0])\n |> line(end = [0, 2 * size])\n |> tangentialArcTo([-size, size], %)\n |> close()\n |> extrude(length = 65)\n\nthing1 = startSketchOn(case, 'end')\n |> circle(center = [-size / 2, -size / 2], radius = 25)\n |> extrude(length = 50)\n\nthing2 = startSketchOn(case, 'end')\n |> circle(center = [size / 2, -size / 2], radius = 25)\n |> extrude(length = 50)\n\nhollow(0.5, case)"
|
"// Hollow a sketch on face object.\nsize = 100\ncase = startSketchOn(-XZ)\n |> startProfileAt([-size, -size], %)\n |> line(end = [2 * size, 0])\n |> line(end = [0, 2 * size])\n |> tangentialArcTo([-size, size], %)\n |> close()\n |> extrude(length = 65)\n\nthing1 = startSketchOn(case, 'end')\n |> circle(center = [-size / 2, -size / 2], radius = 25)\n |> extrude(length = 50)\n\nthing2 = startSketchOn(case, 'end')\n |> circle(center = [size / 2, -size / 2], radius = 25)\n |> extrude(length = 50)\n\nhollow(0.5, case)"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"name": "import",
|
|
||||||
"summary": "Import a CAD file.",
|
|
||||||
"description": "**DEPRECATED** Prefer to use import statements.\n\nFor formats lacking unit data (such as STL, OBJ, or PLY files), the default unit of measurement is millimeters. Alternatively you may specify the unit by passing your desired measurement unit in the options parameter. When importing a GLTF file, the bin file will be imported as well. Import paths are relative to the current project directory.\n\nNote: The import command currently only works when using the native Design Studio.",
|
|
||||||
"tags": [],
|
|
||||||
"keywordArguments": false,
|
|
||||||
"args": [
|
|
||||||
{
|
|
||||||
"name": "filePath",
|
|
||||||
"type": "String",
|
|
||||||
"schema": {
|
|
||||||
"$schema": "https://spec.openapis.org/oas/3.0/schema/2019-04-02#/definitions/Schema",
|
|
||||||
"title": "String",
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"required": true,
|
|
||||||
"includeInSnippet": true,
|
|
||||||
"labelRequired": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "options",
|
|
||||||
"type": "ImportFormat",
|
|
||||||
"schema": {
|
|
||||||
"$schema": "https://spec.openapis.org/oas/3.0/schema/2019-04-02#/definitions/Schema",
|
|
||||||
"title": "Nullable_ImportFormat",
|
|
||||||
"allOf": [
|
|
||||||
{
|
|
||||||
"$ref": "#/components/schemas/ImportFormat"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"nullable": true,
|
|
||||||
"definitions": {
|
|
||||||
"ImportFormat": {
|
|
||||||
"description": "Import format specifier",
|
|
||||||
"oneOf": [
|
|
||||||
{
|
|
||||||
"description": "Autodesk Filmbox (FBX) format",
|
|
||||||
"type": "object",
|
|
||||||
"required": [
|
|
||||||
"format"
|
|
||||||
],
|
|
||||||
"properties": {
|
|
||||||
"format": {
|
|
||||||
"type": "string",
|
|
||||||
"enum": [
|
|
||||||
"fbx"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"description": "Binary glTF 2.0. We refer to this as glTF since that is how our customers refer to it, but this can also import binary glTF (glb).",
|
|
||||||
"type": "object",
|
|
||||||
"required": [
|
|
||||||
"format"
|
|
||||||
],
|
|
||||||
"properties": {
|
|
||||||
"format": {
|
|
||||||
"type": "string",
|
|
||||||
"enum": [
|
|
||||||
"gltf"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"description": "Wavefront OBJ format.",
|
|
||||||
"type": "object",
|
|
||||||
"required": [
|
|
||||||
"format",
|
|
||||||
"units"
|
|
||||||
],
|
|
||||||
"properties": {
|
|
||||||
"format": {
|
|
||||||
"type": "string",
|
|
||||||
"enum": [
|
|
||||||
"obj"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"coords": {
|
|
||||||
"description": "Co-ordinate system of input data. Defaults to the [KittyCAD co-ordinate system.",
|
|
||||||
"allOf": [
|
|
||||||
{
|
|
||||||
"$ref": "#/components/schemas/System"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"nullable": true
|
|
||||||
},
|
|
||||||
"units": {
|
|
||||||
"description": "The units of the input data. This is very important for correct scaling and when calculating physics properties like mass, etc. Defaults to millimeters.",
|
|
||||||
"allOf": [
|
|
||||||
{
|
|
||||||
"$ref": "#/components/schemas/UnitLength"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"description": "The PLY Polygon File Format.",
|
|
||||||
"type": "object",
|
|
||||||
"required": [
|
|
||||||
"format",
|
|
||||||
"units"
|
|
||||||
],
|
|
||||||
"properties": {
|
|
||||||
"format": {
|
|
||||||
"type": "string",
|
|
||||||
"enum": [
|
|
||||||
"ply"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"coords": {
|
|
||||||
"description": "Co-ordinate system of input data. Defaults to the [KittyCAD co-ordinate system.",
|
|
||||||
"allOf": [
|
|
||||||
{
|
|
||||||
"$ref": "#/components/schemas/System"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"nullable": true
|
|
||||||
},
|
|
||||||
"units": {
|
|
||||||
"description": "The units of the input data. This is very important for correct scaling and when calculating physics properties like mass, etc. Defaults to millimeters.",
|
|
||||||
"allOf": [
|
|
||||||
{
|
|
||||||
"$ref": "#/components/schemas/UnitLength"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"description": "SolidWorks part (SLDPRT) format.",
|
|
||||||
"type": "object",
|
|
||||||
"required": [
|
|
||||||
"format"
|
|
||||||
],
|
|
||||||
"properties": {
|
|
||||||
"format": {
|
|
||||||
"type": "string",
|
|
||||||
"enum": [
|
|
||||||
"sldprt"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"description": "ISO 10303-21 (STEP) format.",
|
|
||||||
"type": "object",
|
|
||||||
"required": [
|
|
||||||
"format"
|
|
||||||
],
|
|
||||||
"properties": {
|
|
||||||
"format": {
|
|
||||||
"type": "string",
|
|
||||||
"enum": [
|
|
||||||
"step"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"description": "ST**ereo**L**ithography format.",
|
|
||||||
"type": "object",
|
|
||||||
"required": [
|
|
||||||
"format",
|
|
||||||
"units"
|
|
||||||
],
|
|
||||||
"properties": {
|
|
||||||
"format": {
|
|
||||||
"type": "string",
|
|
||||||
"enum": [
|
|
||||||
"stl"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"coords": {
|
|
||||||
"description": "Co-ordinate system of input data. Defaults to the [KittyCAD co-ordinate system.",
|
|
||||||
"allOf": [
|
|
||||||
{
|
|
||||||
"$ref": "#/components/schemas/System"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"nullable": true
|
|
||||||
},
|
|
||||||
"units": {
|
|
||||||
"description": "The units of the input data. This is very important for correct scaling and when calculating physics properties like mass, etc. Defaults to millimeters.",
|
|
||||||
"allOf": [
|
|
||||||
{
|
|
||||||
"$ref": "#/components/schemas/UnitLength"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"System": {
|
|
||||||
"description": "Co-ordinate system definition.\n\nThe `up` axis must be orthogonal to the `forward` axis.\n\nSee [cglearn.eu] for background reading.\n\n[cglearn.eu](https://cglearn.eu/pub/computer-graphics/introduction-to-geometry#material-coordinate-systems-1)",
|
|
||||||
"type": "object",
|
|
||||||
"required": [
|
|
||||||
"forward",
|
|
||||||
"up"
|
|
||||||
],
|
|
||||||
"properties": {
|
|
||||||
"forward": {
|
|
||||||
"description": "Axis the front face of a model looks along.",
|
|
||||||
"allOf": [
|
|
||||||
{
|
|
||||||
"$ref": "#/components/schemas/AxisDirectionPair"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"up": {
|
|
||||||
"description": "Axis pointing up and away from a model.",
|
|
||||||
"allOf": [
|
|
||||||
{
|
|
||||||
"$ref": "#/components/schemas/AxisDirectionPair"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"AxisDirectionPair": {
|
|
||||||
"description": "An [`Axis`] paired with a [`Direction`].",
|
|
||||||
"type": "object",
|
|
||||||
"required": [
|
|
||||||
"axis",
|
|
||||||
"direction"
|
|
||||||
],
|
|
||||||
"properties": {
|
|
||||||
"axis": {
|
|
||||||
"description": "Axis specifier.",
|
|
||||||
"allOf": [
|
|
||||||
{
|
|
||||||
"$ref": "#/components/schemas/Axis"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"direction": {
|
|
||||||
"description": "Specifies which direction the axis is pointing.",
|
|
||||||
"allOf": [
|
|
||||||
{
|
|
||||||
"$ref": "#/components/schemas/Direction"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"Axis": {
|
|
||||||
"description": "Co-ordinate axis specifier.\n\nSee [cglearn.eu] for background reading.\n\n[cglearn.eu]: https://cglearn.eu/pub/computer-graphics/introduction-to-geometry#material-coordinate-systems-1",
|
|
||||||
"oneOf": [
|
|
||||||
{
|
|
||||||
"description": "'Y' axis.",
|
|
||||||
"type": "string",
|
|
||||||
"enum": [
|
|
||||||
"y"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"description": "'Z' axis.",
|
|
||||||
"type": "string",
|
|
||||||
"enum": [
|
|
||||||
"z"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"Direction": {
|
|
||||||
"description": "Specifies the sign of a co-ordinate axis.",
|
|
||||||
"oneOf": [
|
|
||||||
{
|
|
||||||
"description": "Increasing numbers.",
|
|
||||||
"type": "string",
|
|
||||||
"enum": [
|
|
||||||
"positive"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"description": "Decreasing numbers.",
|
|
||||||
"type": "string",
|
|
||||||
"enum": [
|
|
||||||
"negative"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"UnitLength": {
|
|
||||||
"description": "The valid types of length units.",
|
|
||||||
"oneOf": [
|
|
||||||
{
|
|
||||||
"description": "Centimeters <https://en.wikipedia.org/wiki/Centimeter>",
|
|
||||||
"type": "string",
|
|
||||||
"enum": [
|
|
||||||
"cm"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"description": "Feet <https://en.wikipedia.org/wiki/Foot_(unit)>",
|
|
||||||
"type": "string",
|
|
||||||
"enum": [
|
|
||||||
"ft"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"description": "Inches <https://en.wikipedia.org/wiki/Inch>",
|
|
||||||
"type": "string",
|
|
||||||
"enum": [
|
|
||||||
"in"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"description": "Meters <https://en.wikipedia.org/wiki/Meter>",
|
|
||||||
"type": "string",
|
|
||||||
"enum": [
|
|
||||||
"m"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"description": "Millimeters <https://en.wikipedia.org/wiki/Millimeter>",
|
|
||||||
"type": "string",
|
|
||||||
"enum": [
|
|
||||||
"mm"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"description": "Yards <https://en.wikipedia.org/wiki/Yard>",
|
|
||||||
"type": "string",
|
|
||||||
"enum": [
|
|
||||||
"yd"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"required": false,
|
|
||||||
"labelRequired": true
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"returnValue": {
|
|
||||||
"name": "",
|
|
||||||
"type": "ImportedGeometry",
|
|
||||||
"schema": {
|
|
||||||
"$schema": "https://spec.openapis.org/oas/3.0/schema/2019-04-02#/definitions/Schema",
|
|
||||||
"title": "ImportedGeometry",
|
|
||||||
"description": "Data for an imported geometry.",
|
|
||||||
"type": "object",
|
|
||||||
"required": [
|
|
||||||
"id",
|
|
||||||
"value"
|
|
||||||
],
|
|
||||||
"properties": {
|
|
||||||
"id": {
|
|
||||||
"description": "The ID of the imported geometry.",
|
|
||||||
"type": "string",
|
|
||||||
"format": "uuid"
|
|
||||||
},
|
|
||||||
"value": {
|
|
||||||
"description": "The original file paths.",
|
|
||||||
"type": "array",
|
|
||||||
"items": {
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"required": true,
|
|
||||||
"includeInSnippet": true,
|
|
||||||
"labelRequired": true
|
|
||||||
},
|
|
||||||
"unpublished": false,
|
|
||||||
"deprecated": true,
|
|
||||||
"examples": [
|
|
||||||
"model = import(\"tests/inputs/cube.obj\")",
|
|
||||||
"model = import(\"tests/inputs/cube.obj\", { format = \"obj\", units = \"m\" })",
|
|
||||||
"model = import(\"tests/inputs/cube.gltf\")",
|
|
||||||
"model = import(\"tests/inputs/cube.sldprt\")",
|
|
||||||
"model = import(\"tests/inputs/cube.step\")",
|
|
||||||
"import height, buildSketch from \"common.kcl\"\n\nplane = XZ\nmargin = 2\ns1 = buildSketch(plane, [0, 0])\ns2 = buildSketch(plane, [0, height() + margin])"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"name": "int",
|
"name": "int",
|
||||||
"summary": "Convert a number to an integer.",
|
"summary": "Convert a number to an integer.",
|
||||||
|
@ -252,7 +252,7 @@ Data for an imported geometry.
|
|||||||
|
|
||||||
| Property | Type | Description | Required |
|
| Property | Type | Description | Required |
|
||||||
|----------|------|-------------|----------|
|
|----------|------|-------------|----------|
|
||||||
| `type` |enum: [`ImportedGeometry`](/docs/kcl/types/ImportedGeometry)| | No |
|
| `type` |enum: `ImportedGeometry`| | No |
|
||||||
| `id` |[`string`](/docs/kcl/types/string)| The ID of the imported geometry. | No |
|
| `id` |[`string`](/docs/kcl/types/string)| The ID of the imported geometry. | No |
|
||||||
| `value` |`[` [`string`](/docs/kcl/types/string) `]`| The original file paths. | No |
|
| `value` |`[` [`string`](/docs/kcl/types/string) `]`| The original file paths. | No |
|
||||||
|
|
||||||
|
@ -1144,7 +1144,7 @@ sketch001 = startSketchOn(XZ)
|
|||||||
)
|
)
|
||||||
|
|
||||||
test(
|
test(
|
||||||
`Can use the import stdlib function on a local OBJ file`,
|
`Can import a local OBJ file`,
|
||||||
{ tag: '@electron' },
|
{ tag: '@electron' },
|
||||||
async ({ page, context }, testInfo) => {
|
async ({ page, context }, testInfo) => {
|
||||||
test.fixme(orRunWhenFullSuiteEnabled())
|
test.fixme(orRunWhenFullSuiteEnabled())
|
||||||
@ -1194,7 +1194,7 @@ sketch001 = startSketchOn(XZ)
|
|||||||
.toBeLessThan(15)
|
.toBeLessThan(15)
|
||||||
})
|
})
|
||||||
await test.step(`Write the import function line`, async () => {
|
await test.step(`Write the import function line`, async () => {
|
||||||
await u.codeLocator.fill(`import('cube.obj')`)
|
await u.codeLocator.fill(`import 'cube.obj'\ncube`)
|
||||||
await page.waitForTimeout(800)
|
await page.waitForTimeout(800)
|
||||||
})
|
})
|
||||||
await test.step(`Reset the camera before checking`, async () => {
|
await test.step(`Reset the camera before checking`, async () => {
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 58 KiB After Width: | Height: | Size: 57 KiB |
@ -11,9 +11,7 @@ pub use cache::{bust_cache, clear_mem_cache};
|
|||||||
pub use cad_op::Operation;
|
pub use cad_op::Operation;
|
||||||
pub use geometry::*;
|
pub use geometry::*;
|
||||||
pub use id_generator::IdGenerator;
|
pub use id_generator::IdGenerator;
|
||||||
pub(crate) use import::{
|
pub(crate) use import::PreImportedGeometry;
|
||||||
import_foreign, send_to_engine as send_import_to_engine, PreImportedGeometry, ZOO_COORD_SYSTEM,
|
|
||||||
};
|
|
||||||
use indexmap::IndexMap;
|
use indexmap::IndexMap;
|
||||||
pub use kcl_value::{KclObjectFields, KclValue};
|
pub use kcl_value::{KclObjectFields, KclValue};
|
||||||
use kcmc::{
|
use kcmc::{
|
||||||
|
@ -664,10 +664,6 @@ impl Args {
|
|||||||
FromArgs::from_args(self, 0)
|
FromArgs::from_args(self, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn get_import_data(&self) -> Result<(String, Option<crate::std::import::ImportFormat>), KclError> {
|
|
||||||
FromArgs::from_args(self, 0)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn get_sketch_data_and_optional_tag(
|
pub(crate) fn get_sketch_data_and_optional_tag(
|
||||||
&self,
|
&self,
|
||||||
) -> Result<(super::sketch::SketchData, Option<FaceTag>), KclError> {
|
) -> Result<(super::sketch::SketchData, Option<FaceTag>), KclError> {
|
||||||
@ -1077,35 +1073,6 @@ macro_rules! let_field_of {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> FromKclValue<'a> for crate::std::import::ImportFormat {
|
|
||||||
fn from_kcl_val(arg: &'a KclValue) -> Option<Self> {
|
|
||||||
let obj = arg.as_object()?;
|
|
||||||
let_field_of!(obj, typ "format");
|
|
||||||
match typ {
|
|
||||||
"fbx" => Some(Self::Fbx {}),
|
|
||||||
"gltf" => Some(Self::Gltf {}),
|
|
||||||
"sldprt" => Some(Self::Sldprt {}),
|
|
||||||
"step" => Some(Self::Step {}),
|
|
||||||
"stl" => {
|
|
||||||
let_field_of!(obj, coords?);
|
|
||||||
let_field_of!(obj, units);
|
|
||||||
Some(Self::Stl { coords, units })
|
|
||||||
}
|
|
||||||
"obj" => {
|
|
||||||
let_field_of!(obj, coords?);
|
|
||||||
let_field_of!(obj, units);
|
|
||||||
Some(Self::Obj { coords, units })
|
|
||||||
}
|
|
||||||
"ply" => {
|
|
||||||
let_field_of!(obj, coords?);
|
|
||||||
let_field_of!(obj, units);
|
|
||||||
Some(Self::Ply { coords, units })
|
|
||||||
}
|
|
||||||
_ => None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> FromKclValue<'a> for super::sketch::AngledLineThatIntersectsData {
|
impl<'a> FromKclValue<'a> for super::sketch::AngledLineThatIntersectsData {
|
||||||
fn from_kcl_val(arg: &'a KclValue) -> Option<Self> {
|
fn from_kcl_val(arg: &'a KclValue) -> Option<Self> {
|
||||||
let obj = arg.as_object()?;
|
let obj = arg.as_object()?;
|
||||||
|
@ -1,181 +0,0 @@
|
|||||||
//! Standard library functions involved in importing files.
|
|
||||||
|
|
||||||
use anyhow::Result;
|
|
||||||
use kcl_derive_docs::stdlib;
|
|
||||||
use kcmc::{coord::System, format::InputFormat3d, units::UnitLength};
|
|
||||||
use kittycad_modeling_cmds as kcmc;
|
|
||||||
|
|
||||||
use crate::{
|
|
||||||
errors::{KclError, KclErrorDetails},
|
|
||||||
execution::{import_foreign, send_import_to_engine, ExecState, ImportedGeometry, KclValue, ZOO_COORD_SYSTEM},
|
|
||||||
std::Args,
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Import format specifier
|
|
||||||
#[derive(serde :: Serialize, serde :: Deserialize, PartialEq, Debug, Clone, schemars :: JsonSchema)]
|
|
||||||
#[cfg_attr(feature = "tabled", derive(tabled::Tabled))]
|
|
||||||
#[serde(tag = "format")]
|
|
||||||
pub enum ImportFormat {
|
|
||||||
/// Autodesk Filmbox (FBX) format
|
|
||||||
#[serde(rename = "fbx")]
|
|
||||||
Fbx {},
|
|
||||||
/// Binary glTF 2.0. We refer to this as glTF since that is how our customers refer to
|
|
||||||
/// it, but this can also import binary glTF (glb).
|
|
||||||
#[serde(rename = "gltf")]
|
|
||||||
Gltf {},
|
|
||||||
/// Wavefront OBJ format.
|
|
||||||
#[serde(rename = "obj")]
|
|
||||||
Obj {
|
|
||||||
/// Co-ordinate system of input data.
|
|
||||||
/// Defaults to the [KittyCAD co-ordinate system.
|
|
||||||
coords: Option<System>,
|
|
||||||
/// The units of the input data. This is very important for correct scaling and when
|
|
||||||
/// calculating physics properties like mass, etc.
|
|
||||||
/// Defaults to millimeters.
|
|
||||||
units: UnitLength,
|
|
||||||
},
|
|
||||||
/// The PLY Polygon File Format.
|
|
||||||
#[serde(rename = "ply")]
|
|
||||||
Ply {
|
|
||||||
/// Co-ordinate system of input data.
|
|
||||||
/// Defaults to the [KittyCAD co-ordinate system.
|
|
||||||
coords: Option<System>,
|
|
||||||
/// The units of the input data. This is very important for correct scaling and when
|
|
||||||
/// calculating physics properties like mass, etc.
|
|
||||||
/// Defaults to millimeters.
|
|
||||||
units: UnitLength,
|
|
||||||
},
|
|
||||||
/// SolidWorks part (SLDPRT) format.
|
|
||||||
#[serde(rename = "sldprt")]
|
|
||||||
Sldprt {},
|
|
||||||
/// ISO 10303-21 (STEP) format.
|
|
||||||
#[serde(rename = "step")]
|
|
||||||
Step {},
|
|
||||||
/// *ST**ereo**L**ithography format.
|
|
||||||
#[serde(rename = "stl")]
|
|
||||||
Stl {
|
|
||||||
/// Co-ordinate system of input data.
|
|
||||||
/// Defaults to the [KittyCAD co-ordinate system.
|
|
||||||
coords: Option<System>,
|
|
||||||
/// The units of the input data. This is very important for correct scaling and when
|
|
||||||
/// calculating physics properties like mass, etc.
|
|
||||||
/// Defaults to millimeters.
|
|
||||||
units: UnitLength,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<ImportFormat> for InputFormat3d {
|
|
||||||
fn from(format: ImportFormat) -> Self {
|
|
||||||
match format {
|
|
||||||
ImportFormat::Fbx {} => InputFormat3d::Fbx(Default::default()),
|
|
||||||
ImportFormat::Gltf {} => InputFormat3d::Gltf(Default::default()),
|
|
||||||
ImportFormat::Obj { coords, units } => InputFormat3d::Obj(kcmc::format::obj::import::Options {
|
|
||||||
coords: coords.unwrap_or(ZOO_COORD_SYSTEM),
|
|
||||||
units,
|
|
||||||
}),
|
|
||||||
ImportFormat::Ply { coords, units } => InputFormat3d::Ply(kcmc::format::ply::import::Options {
|
|
||||||
coords: coords.unwrap_or(ZOO_COORD_SYSTEM),
|
|
||||||
units,
|
|
||||||
}),
|
|
||||||
ImportFormat::Sldprt {} => InputFormat3d::Sldprt(kcmc::format::sldprt::import::Options {
|
|
||||||
split_closed_faces: false,
|
|
||||||
}),
|
|
||||||
ImportFormat::Step {} => InputFormat3d::Step(kcmc::format::step::import::Options {
|
|
||||||
split_closed_faces: false,
|
|
||||||
}),
|
|
||||||
ImportFormat::Stl { coords, units } => InputFormat3d::Stl(kcmc::format::stl::import::Options {
|
|
||||||
coords: coords.unwrap_or(ZOO_COORD_SYSTEM),
|
|
||||||
units,
|
|
||||||
}),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Import a CAD file.
|
|
||||||
/// For formats lacking unit data (STL, OBJ, PLY), the default import unit is millimeters.
|
|
||||||
/// Otherwise you can specify the unit by passing in the options parameter.
|
|
||||||
/// If you import a gltf file, we will try to find the bin file and import it as well.
|
|
||||||
///
|
|
||||||
/// Import paths are relative to the current project directory. This only works in the desktop app
|
|
||||||
/// not in browser.
|
|
||||||
pub async fn import(exec_state: &mut ExecState, args: Args) -> Result<KclValue, KclError> {
|
|
||||||
let (file_path, options): (String, Option<ImportFormat>) = args.get_import_data()?;
|
|
||||||
|
|
||||||
let imported_geometry = inner_import(file_path, options, exec_state, args).await?;
|
|
||||||
Ok(KclValue::ImportedGeometry(imported_geometry))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Import a CAD file.
|
|
||||||
///
|
|
||||||
/// **DEPRECATED** Prefer to use import statements.
|
|
||||||
///
|
|
||||||
/// For formats lacking unit data (such as STL, OBJ, or PLY files), the default
|
|
||||||
/// unit of measurement is millimeters. Alternatively you may specify the unit
|
|
||||||
/// by passing your desired measurement unit in the options parameter. When
|
|
||||||
/// importing a GLTF file, the bin file will be imported as well. Import paths
|
|
||||||
/// are relative to the current project directory.
|
|
||||||
///
|
|
||||||
/// Note: The import command currently only works when using the native
|
|
||||||
/// Design Studio.
|
|
||||||
///
|
|
||||||
/// ```no_run
|
|
||||||
/// model = import("tests/inputs/cube.obj")
|
|
||||||
/// ```
|
|
||||||
///
|
|
||||||
/// ```no_run
|
|
||||||
/// model = import("tests/inputs/cube.obj", {format: "obj", units: "m"})
|
|
||||||
/// ```
|
|
||||||
///
|
|
||||||
/// ```no_run
|
|
||||||
/// model = import("tests/inputs/cube.gltf")
|
|
||||||
/// ```
|
|
||||||
///
|
|
||||||
/// ```no_run
|
|
||||||
/// model = import("tests/inputs/cube.sldprt")
|
|
||||||
/// ```
|
|
||||||
///
|
|
||||||
/// ```no_run
|
|
||||||
/// model = import("tests/inputs/cube.step")
|
|
||||||
/// ```
|
|
||||||
///
|
|
||||||
/// ```no_run
|
|
||||||
/// import height, buildSketch from 'common.kcl'
|
|
||||||
///
|
|
||||||
/// plane = 'XZ'
|
|
||||||
/// margin = 2
|
|
||||||
/// s1 = buildSketch(plane, [0, 0])
|
|
||||||
/// s2 = buildSketch(plane, [0, height() + margin])
|
|
||||||
/// ```
|
|
||||||
#[stdlib {
|
|
||||||
name = "import",
|
|
||||||
feature_tree_operation = true,
|
|
||||||
deprecated = true,
|
|
||||||
tags = [],
|
|
||||||
}]
|
|
||||||
async fn inner_import(
|
|
||||||
file_path: String,
|
|
||||||
options: Option<ImportFormat>,
|
|
||||||
exec_state: &mut ExecState,
|
|
||||||
args: Args,
|
|
||||||
) -> Result<ImportedGeometry, KclError> {
|
|
||||||
if file_path.is_empty() {
|
|
||||||
return Err(KclError::Semantic(KclErrorDetails {
|
|
||||||
message: "No file path was provided.".to_string(),
|
|
||||||
source_ranges: vec![args.source_range],
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
let format = options.map(InputFormat3d::from);
|
|
||||||
send_import_to_engine(
|
|
||||||
import_foreign(
|
|
||||||
std::path::Path::new(&file_path),
|
|
||||||
format,
|
|
||||||
exec_state,
|
|
||||||
&args.ctx,
|
|
||||||
args.source_range,
|
|
||||||
)
|
|
||||||
.await?,
|
|
||||||
&args.ctx,
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
}
|
|
@ -12,7 +12,6 @@ pub mod edge;
|
|||||||
pub mod extrude;
|
pub mod extrude;
|
||||||
pub mod fillet;
|
pub mod fillet;
|
||||||
pub mod helix;
|
pub mod helix;
|
||||||
pub mod import;
|
|
||||||
pub mod loft;
|
pub mod loft;
|
||||||
pub mod math;
|
pub mod math;
|
||||||
pub mod mirror;
|
pub mod mirror;
|
||||||
@ -111,7 +110,6 @@ lazy_static! {
|
|||||||
Box::new(crate::std::sweep::Sweep),
|
Box::new(crate::std::sweep::Sweep),
|
||||||
Box::new(crate::std::loft::Loft),
|
Box::new(crate::std::loft::Loft),
|
||||||
Box::new(crate::std::planes::OffsetPlane),
|
Box::new(crate::std::planes::OffsetPlane),
|
||||||
Box::new(crate::std::import::Import),
|
|
||||||
Box::new(crate::std::math::Acos),
|
Box::new(crate::std::math::Acos),
|
||||||
Box::new(crate::std::math::Asin),
|
Box::new(crate::std::math::Asin),
|
||||||
Box::new(crate::std::math::Atan),
|
Box::new(crate::std::math::Atan),
|
||||||
|
Reference in New Issue
Block a user