Skip to content

Commit 21b40cf

Browse files
authored
New APIs for primitive indexing (#1046)
This lets you look up the index of a face or edge, and translate between indices and IDs (UUIDs). Part of KittyCAD/engine#4089
1 parent dc31582 commit 21b40cf

File tree

3 files changed

+177
-0
lines changed

3 files changed

+177
-0
lines changed

modeling-cmds/openapi/api.json

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2296,6 +2296,62 @@
22962296
"type"
22972297
]
22982298
},
2299+
{
2300+
"description": "What is the UUID of this body's n-th edge?",
2301+
"type": "object",
2302+
"properties": {
2303+
"edge_index": {
2304+
"description": "The primitive index of the edge being queried.",
2305+
"type": "integer",
2306+
"format": "uint32",
2307+
"minimum": 0
2308+
},
2309+
"object_id": {
2310+
"description": "The Solid3D parent who owns the edge",
2311+
"type": "string",
2312+
"format": "uuid"
2313+
},
2314+
"type": {
2315+
"type": "string",
2316+
"enum": [
2317+
"solid3d_get_edge_uuid"
2318+
]
2319+
}
2320+
},
2321+
"required": [
2322+
"edge_index",
2323+
"object_id",
2324+
"type"
2325+
]
2326+
},
2327+
{
2328+
"description": "What is the UUID of this body's n-th face?",
2329+
"type": "object",
2330+
"properties": {
2331+
"face_index": {
2332+
"description": "The primitive index of the face being queried.",
2333+
"type": "integer",
2334+
"format": "uint32",
2335+
"minimum": 0
2336+
},
2337+
"object_id": {
2338+
"description": "The Solid3D parent who owns the face",
2339+
"type": "string",
2340+
"format": "uuid"
2341+
},
2342+
"type": {
2343+
"type": "string",
2344+
"enum": [
2345+
"solid3d_get_face_uuid"
2346+
]
2347+
}
2348+
},
2349+
"required": [
2350+
"face_index",
2351+
"object_id",
2352+
"type"
2353+
]
2354+
},
22992355
{
23002356
"description": "Retrieves the body type.",
23012357
"type": "object",
@@ -2931,6 +2987,48 @@
29312987
"type"
29322988
]
29332989
},
2990+
{
2991+
"description": "What is this entity's child index within its parent",
2992+
"type": "object",
2993+
"properties": {
2994+
"entity_id": {
2995+
"description": "ID of the entity being queried.",
2996+
"type": "string",
2997+
"format": "uuid"
2998+
},
2999+
"type": {
3000+
"type": "string",
3001+
"enum": [
3002+
"entity_get_index"
3003+
]
3004+
}
3005+
},
3006+
"required": [
3007+
"entity_id",
3008+
"type"
3009+
]
3010+
},
3011+
{
3012+
"description": "What is this edge or face entity's primitive index within its parent body's edges or faces array respectively",
3013+
"type": "object",
3014+
"properties": {
3015+
"entity_id": {
3016+
"description": "ID of the entity being queried.",
3017+
"type": "string",
3018+
"format": "uuid"
3019+
},
3020+
"type": {
3021+
"type": "string",
3022+
"enum": [
3023+
"entity_get_primitive_index"
3024+
]
3025+
}
3026+
},
3027+
"required": [
3028+
"entity_id",
3029+
"type"
3030+
]
3031+
},
29343032
{
29353033
"description": "Attempts to delete children entity from an entity. Note that this API may change the body type of certain entities from Solid to Surface.",
29363034
"type": "object",

modeling-cmds/src/def_enum.rs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,36 @@ define_modeling_cmd_enum! {
303303
pub object_id: Uuid,
304304
}
305305

306+
/// What is the UUID of this body's n-th edge?
307+
#[derive(
308+
Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema, ModelingCmdVariant, Builder
309+
)]
310+
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
311+
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
312+
#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
313+
pub struct Solid3dGetEdgeUuid {
314+
/// The Solid3D parent who owns the edge
315+
pub object_id: Uuid,
316+
317+
/// The primitive index of the edge being queried.
318+
pub edge_index: u32,
319+
}
320+
321+
/// What is the UUID of this body's n-th face?
322+
#[derive(
323+
Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema, ModelingCmdVariant, Builder
324+
)]
325+
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
326+
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
327+
#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
328+
pub struct Solid3dGetFaceUuid {
329+
/// The Solid3D parent who owns the face
330+
pub object_id: Uuid,
331+
332+
/// The primitive index of the face being queried.
333+
pub face_index: u32,
334+
}
335+
306336
/// Retrieves the body type.
307337
#[derive(
308338
Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema, ModelingCmdVariant, Builder
@@ -573,6 +603,26 @@ define_modeling_cmd_enum! {
573603
pub child_index: u32,
574604
}
575605

606+
/// What is this entity's child index within its parent
607+
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema, ModelingCmdVariant, Builder)]
608+
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
609+
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
610+
#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
611+
pub struct EntityGetIndex {
612+
/// ID of the entity being queried.
613+
pub entity_id: Uuid,
614+
}
615+
616+
/// What is this edge or face entity's primitive index within its parent body's edges or faces array respectively
617+
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema, ModelingCmdVariant, Builder)]
618+
#[cfg_attr(feature = "ts-rs", derive(ts_rs::TS))]
619+
#[cfg_attr(feature = "ts-rs", ts(export_to = "ModelingCmd.ts"))]
620+
#[cfg_attr(not(feature = "unstable_exhaustive"), non_exhaustive)]
621+
pub struct EntityGetPrimitiveIndex {
622+
/// ID of the entity being queried.
623+
pub entity_id: Uuid,
624+
}
625+
576626
/// Attempts to delete children entity from an entity.
577627
/// Note that this API may change the body type of certain entities from Solid to Surface.
578628
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema, ModelingCmdVariant, Builder)]

modeling-cmds/src/ok_response.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,20 @@ define_ok_modeling_cmd_response_enum! {
8282
pub struct Solid3dJoin {
8383
}
8484

85+
/// The response from the `Solid3dGetEdgeUuid` endpoint.
86+
#[derive(Debug, Serialize, Deserialize, Clone, JsonSchema, ModelingCmdOutput)]
87+
pub struct Solid3dGetEdgeUuid {
88+
/// The UUID of the edge.
89+
pub edge_id: Uuid,
90+
}
91+
92+
/// The response from the `Solid3dGetFaceUuid` endpoint.
93+
#[derive(Debug, Serialize, Deserialize, Clone, JsonSchema, ModelingCmdOutput)]
94+
pub struct Solid3dGetFaceUuid {
95+
/// The UUID of the face.
96+
pub face_id: Uuid,
97+
}
98+
8599
/// The response from the `Solid3dGetBodyType` endpoint.
86100
#[derive(Debug, Serialize, Deserialize, Clone, JsonSchema, ModelingCmdOutput)]
87101
pub struct Solid3dGetBodyType {
@@ -365,6 +379,21 @@ define_ok_modeling_cmd_response_enum! {
365379
/// The UUID of the child entity.
366380
pub entity_id: Uuid,
367381
}
382+
/// The response from the `EntityGetIndex` command.
383+
#[derive(Debug, Serialize, Deserialize, Clone, JsonSchema, ModelingCmdOutput)]
384+
pub struct EntityGetIndex {
385+
/// The child index of the entity.
386+
pub entity_index: u32,
387+
}
388+
/// The response from the `EntityGetPrimitiveIndex` command.
389+
#[derive(Debug, Serialize, Deserialize, Clone, JsonSchema, ModelingCmdOutput)]
390+
pub struct EntityGetPrimitiveIndex {
391+
/// The primitive index of the entity.
392+
pub primitive_index: u32,
393+
394+
/// The type of this entity. Helps infer whether this is an edge or a face index.
395+
pub entity_type: EntityType,
396+
}
368397
/// The response from the `EntityDeleteChildren` command.
369398
#[derive(Debug, Serialize, Deserialize, Clone, JsonSchema, ModelingCmdOutput)]
370399
pub struct EntityDeleteChildren {

0 commit comments

Comments
 (0)