Skip to main content

occt_wasm/
types.rs

1//! Data types for the occt-wasm Rust API.
2//!
3//! These mirror the TypeScript types in `ts/src/types.ts`.
4
5/// Opaque handle to a shape in the WASM arena.
6///
7/// Handles are created by kernel methods (e.g. `make_box`) and consumed by
8/// operations (e.g. `fuse`). They are valid until released or the kernel is
9/// dropped.
10#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
11pub struct ShapeHandle(pub(crate) u32);
12
13impl ShapeHandle {
14    /// Returns the raw arena ID. Useful for debugging.
15    #[must_use]
16    pub const fn id(self) -> u32 {
17        self.0
18    }
19}
20
21/// A 3D vector or point.
22#[derive(Debug, Clone, Copy, PartialEq)]
23pub struct Vec3 {
24    /// X component.
25    pub x: f64,
26    /// Y component.
27    pub y: f64,
28    /// Z component.
29    pub z: f64,
30}
31
32/// Axis-aligned bounding box.
33#[derive(Debug, Clone, Copy, PartialEq)]
34pub struct BoundingBox {
35    /// Minimum corner.
36    pub min: Vec3,
37    /// Maximum corner.
38    pub max: Vec3,
39}
40
41/// Triangle mesh data from tessellation.
42#[derive(Debug, Clone)]
43pub struct Mesh {
44    /// Vertex positions, xyz interleaved. Length = `vertex_count * 3`.
45    pub positions: Vec<f32>,
46    /// Vertex normals, xyz interleaved. Length = `vertex_count * 3`.
47    pub normals: Vec<f32>,
48    /// Triangle indices. Length = `triangle_count * 3`.
49    pub indices: Vec<u32>,
50    /// Per-face groups: `[tri_start, tri_count, face_hash]` repeated.
51    pub face_groups: Vec<i32>,
52}
53
54/// Batched mesh data for multiple shapes.
55#[derive(Debug, Clone)]
56pub struct MeshBatch {
57    /// Concatenated vertex positions.
58    pub positions: Vec<f32>,
59    /// Concatenated vertex normals.
60    pub normals: Vec<f32>,
61    /// Concatenated triangle indices.
62    pub indices: Vec<u32>,
63    /// Per-shape offsets: `[pos_start, pos_count, idx_start, idx_count]` repeated.
64    pub shape_offsets: Vec<i32>,
65}
66
67/// Wireframe edge data.
68#[derive(Debug, Clone)]
69pub struct EdgeData {
70    /// Edge points, xyz interleaved.
71    pub points: Vec<f32>,
72    /// Per-edge groups: `[point_start, point_count, edge_hash]` repeated.
73    pub edge_groups: Vec<i32>,
74}
75
76/// NURBS/BSpline curve data.
77#[derive(Debug, Clone)]
78pub struct NurbsCurveData {
79    /// Polynomial degree.
80    pub degree: i32,
81    /// Whether the curve is rational.
82    pub rational: bool,
83    /// Whether the curve is periodic.
84    pub periodic: bool,
85    /// Knot values.
86    pub knots: Vec<f64>,
87    /// Knot multiplicities.
88    pub multiplicities: Vec<i32>,
89    /// Control point coordinates, xyz interleaved.
90    pub poles: Vec<f64>,
91    /// Control point weights (empty if not rational).
92    pub weights: Vec<f64>,
93}
94
95/// Shape evolution data from operations with history tracking.
96#[derive(Debug, Clone)]
97pub struct EvolutionData {
98    /// The result shape handle ID.
99    pub result_id: u32,
100    /// Modified face tracking data.
101    pub modified: Vec<i32>,
102    /// Generated face tracking data.
103    pub generated: Vec<i32>,
104    /// Deleted face hashes.
105    pub deleted: Vec<i32>,
106}
107
108/// Hidden line removal projection result.
109#[derive(Debug, Clone)]
110pub struct ProjectionData {
111    /// Visible outline edges.
112    pub visible_outline: ShapeHandle,
113    /// Visible smooth edges.
114    pub visible_smooth: ShapeHandle,
115    /// Visible sharp edges.
116    pub visible_sharp: ShapeHandle,
117    /// Hidden outline edges.
118    pub hidden_outline: ShapeHandle,
119    /// Hidden smooth edges.
120    pub hidden_smooth: ShapeHandle,
121    /// Hidden sharp edges.
122    pub hidden_sharp: ShapeHandle,
123}
124
125/// XCAF document label information.
126#[derive(Debug, Clone)]
127pub struct LabelInfo {
128    /// Label ID within the document.
129    pub label_id: i32,
130    /// Label name.
131    pub name: String,
132    /// Whether this label has a color assigned.
133    pub has_color: bool,
134    /// Red component (0.0-1.0).
135    pub r: f64,
136    /// Green component (0.0-1.0).
137    pub g: f64,
138    /// Blue component (0.0-1.0).
139    pub b: f64,
140    /// Whether this label represents an assembly.
141    pub is_assembly: bool,
142    /// Whether this label represents a component instance.
143    pub is_component: bool,
144    /// Shape handle ID (0 if no shape).
145    pub shape_id: u32,
146}