@babylonjs/serializers 9.18.1 → 9.18.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,227 +2,268 @@ import { type Matrix3d, ThreeMfModel, ThreeMfObject } from "./3mf.js";
2
2
  import { type I3mfBaseMaterials, type I3mfModel, type I3mfObject, type I3mfTriangle, type I3mfVertex, type ST_ResourceID, type ST_ResourceIndex, type ST_Unit, ST_ObjectType } from "./3mf.interfaces.js";
3
3
  import { type I3mfDocument, type I3mfContentType, type I3mfRelationship } from "./3mf.opc.interfaces.js";
4
4
  import { type I3mfRGBAColor, type I3mfVertexData } from "./3mf.types.js";
5
+ /**
6
+ * Handler invoked for every vertex generated by a {@link ThreeMfMeshBuilder}, allowing it to be transformed before export.
7
+ */
5
8
  export type VertexHandler = (vertex: I3mfVertex) => I3mfVertex;
9
+ /**
10
+ * Handler invoked for every triangle generated by a {@link ThreeMfMeshBuilder}, allowing it to be transformed before export.
11
+ */
6
12
  export type TriangleHandler = (triangle: I3mfTriangle) => I3mfTriangle;
7
- /** */
13
+ /**
14
+ * Fluent builder for a 3MF object resource.
15
+ * An object is the base resource of a 3MF model and is either a mesh or a set of components.
16
+ */
8
17
  export declare class ThreeMfObjectBuilder {
9
18
  /**
10
- *
19
+ * The 3MF object resource currently being built.
11
20
  */
12
21
  protected _object: ThreeMfObject;
13
22
  /**
14
- *
15
- * @param id
16
- * @param type
23
+ * Creates a new object builder.
24
+ * @param id The unique resource id of the object within the model.
25
+ * @param type The 3MF object type (model, support, solidsupport, surface or other).
17
26
  */
18
27
  constructor(id: ST_ResourceID, type: ST_ObjectType);
19
28
  /**
20
- *
21
- * @param name
22
- * @returns
29
+ * Sets the human readable name of the object.
30
+ * @param name The name to assign to the object.
31
+ * @returns This builder, to allow chaining.
23
32
  */
24
33
  withName(name: string): ThreeMfObjectBuilder;
25
34
  /**
26
- *
27
- * @param thumbnail
28
- * @returns
35
+ * Sets the thumbnail of the object.
36
+ * @param thumbnail The package relative path of the thumbnail part.
37
+ * @returns This builder, to allow chaining.
29
38
  */
30
39
  withThumbnail(thumbnail: string): ThreeMfObjectBuilder;
31
40
  /**
32
- *
33
- * @param id
34
- * @param index
35
- * @returns
41
+ * Assigns the property resource used by the object.
42
+ * @param id The resource id of the property group (for example a base materials group).
43
+ * @param index The zero based index of the property within the group. Defaults to 0.
44
+ * @returns This builder, to allow chaining.
36
45
  */
37
46
  withProperty(id: ST_ResourceIndex, index?: number): ThreeMfObjectBuilder;
38
47
  /**
39
- *
40
- * @returns
48
+ * Returns the object that has been built.
49
+ * @returns The built 3MF object resource.
41
50
  */
42
51
  build(): I3mfObject;
43
52
  /**
44
- *
45
- * @param id
46
- * @param type
53
+ * Discards the current object and starts building a new one.
54
+ * @param id The unique resource id of the new object.
55
+ * @param type The 3MF object type of the new object.
47
56
  */
48
57
  reset(id: ST_ResourceID, type: ST_ObjectType): void;
49
58
  }
50
59
  /**
51
- *
60
+ * Fluent builder for a 3MF object made of components.
61
+ * A components object references other objects instead of defining its own geometry.
52
62
  */
53
63
  export declare class ThreeMfComponentsBuilder extends ThreeMfObjectBuilder {
54
64
  /**
55
- *
56
- * @param id
57
- * @param type
65
+ * Creates a new components object builder.
66
+ * @param id The unique resource id of the object within the model.
67
+ * @param type The 3MF object type. Defaults to `ST_ObjectType.model`.
58
68
  */
59
69
  constructor(id: ST_ResourceID, type?: ST_ObjectType);
60
70
  /**
61
- *
62
- * @param id
63
- * @param t
64
- * @returns
71
+ * Adds a component referencing another object resource.
72
+ * @param id The resource id of the referenced object.
73
+ * @param t The optional transform applied to the referenced object.
74
+ * @returns This builder, to allow chaining.
65
75
  */
66
76
  withComponent(id: ST_ResourceID, t?: Matrix3d): ThreeMfComponentsBuilder;
67
77
  }
68
78
  /**
69
- *
79
+ * Fluent builder for a 3MF object holding a mesh.
80
+ * Vertices and triangles are generated from Babylon vertex data and can be post processed through handlers.
70
81
  */
71
82
  export declare class ThreeMfMeshBuilder extends ThreeMfObjectBuilder {
72
83
  /**
73
- *
84
+ * Optional handler invoked for every vertex before it is added to the mesh.
74
85
  */
75
86
  _vh?: VertexHandler;
76
87
  /**
77
- *
88
+ * Optional handler invoked for every triangle before it is added to the mesh.
78
89
  */
79
90
  _th?: TriangleHandler;
80
91
  /**
81
- *
82
- * @param id
92
+ * Creates a new mesh object builder.
93
+ * @param id The unique resource id of the object within the model.
83
94
  */
84
95
  constructor(id: ST_ResourceID);
85
96
  /**
86
- *
87
- * @param vertex
88
- * @param triangle
89
- * @returns
97
+ * Registers the handlers used to post process the generated geometry.
98
+ * @param vertex The handler invoked for every generated vertex.
99
+ * @param triangle The optional handler invoked for every generated triangle.
100
+ * @returns This builder, to allow chaining.
90
101
  */
91
102
  withPostProcessHandlers(vertex: VertexHandler, triangle?: TriangleHandler): ThreeMfMeshBuilder;
92
103
  /**
93
- *
94
- * @param data
95
- * @returns
104
+ * Builds the mesh content of the object from the provided vertex data.
105
+ * @param data The positions and indices used to generate the mesh.
106
+ * @returns This builder, to allow chaining.
96
107
  */
97
108
  withData(data: I3mfVertexData): ThreeMfMeshBuilder;
98
109
  /**
99
- *
100
- * @param id
101
- * @param i
102
- * @returns
110
+ * Assigns the material used by the mesh.
111
+ * @param id The resource id of the base materials group.
112
+ * @param i The zero based index of the material within the group.
113
+ * @returns This builder, to allow chaining.
103
114
  */
104
115
  withMaterial(id: ST_ResourceID, i: number): ThreeMfMeshBuilder;
105
116
  /**
106
- *
107
- * @param data
108
- * @returns
117
+ * Converts vertex data into a 3MF mesh.
118
+ * @param data The positions and indices used to generate the mesh.
119
+ * @returns The generated 3MF mesh.
109
120
  */
110
121
  private _buildMesh;
122
+ /**
123
+ * Converts a flat position array into a 3MF vertex list, applying the vertex handler when one is registered.
124
+ * @param p The flat array of x, y and z positions.
125
+ * @returns The generated 3MF vertex list.
126
+ */
111
127
  private _buildVertices;
128
+ /**
129
+ * Converts a flat index array into a 3MF triangle list, applying the triangle handler when one is registered.
130
+ * @param indice The flat array of vertex indices, three per triangle.
131
+ * @returns The generated 3MF triangle list.
132
+ */
112
133
  private _buildTriangle;
113
134
  }
114
135
  /**
115
- *
136
+ * Fluent builder for a 3MF base materials resource.
137
+ * Colors are stored as sRGB hexadecimal strings as required by the 3MF specification.
116
138
  */
117
139
  export declare class ThreeMfMaterialBuilder {
118
140
  private _m;
141
+ /**
142
+ * Creates a new base materials builder.
143
+ * @param id The unique resource id of the base materials group within the model.
144
+ */
119
145
  constructor(id: ST_ResourceID);
120
146
  /**
121
- *
122
- * @param name
123
- * @param color
124
- * @returns
147
+ * Adds a named color to the group, or updates it when the name already exists.
148
+ * @param name The name of the material. The lookup is case insensitive.
149
+ * @param color The linear RGBA color, converted to an sRGB hexadecimal string.
150
+ * @returns This builder, to allow chaining.
125
151
  */
126
152
  withColor(name: string, color: I3mfRGBAColor): ThreeMfMaterialBuilder;
127
153
  /**
128
- *
129
- * @returns
154
+ * Returns the base materials group that has been built.
155
+ * @returns The built base materials resource.
130
156
  */
131
157
  build(): I3mfBaseMaterials;
158
+ /**
159
+ * Converts a linear color into the sRGB hexadecimal string used by 3MF.
160
+ * @param c The linear color to convert. The alpha channel is optional.
161
+ * @returns The color as `#RRGGBB`, or `#RRGGBBAA` when an alpha channel is provided.
162
+ */
132
163
  private _rgbaToHex;
133
164
  }
134
165
  /**
135
- *
166
+ * Fluent builder for a 3MF model, the root part of a 3MF document.
167
+ * It aggregates the resources (materials, meshes and components) and the build items that reference them.
136
168
  */
137
169
  export declare class ThreeMfModelBuilder {
138
170
  /**
139
- *
171
+ * The lower cased set of the metadata names defined by the 3MF specification.
140
172
  */
141
173
  static KnownMetaSet: Set<string>;
142
174
  /**
143
- *
175
+ * The 3MF model currently being built.
144
176
  */
145
177
  _model: ThreeMfModel;
146
178
  /**
147
- *
179
+ * The object resources added to the model, indexed by resource id.
148
180
  */
149
181
  _objects: Map<string, I3mfObject>;
150
182
  /**
151
- *
152
- * @param name
153
- * @param value
154
- * @param preserve
155
- * @param type
156
- * @returns
183
+ * Adds a metadata entry to the model.
184
+ * @param name The metadata name. Names outside of the 3MF specification must be namespace qualified.
185
+ * @param value The metadata value.
186
+ * @param preserve Whether consumers must preserve this entry when editing the document.
187
+ * @param type The XML schema type of the value. Defaults to `xs:string`.
188
+ * @returns This builder, to allow chaining.
157
189
  */
158
190
  withMetaData(name: string, value: string, preserve?: boolean, type?: string): ThreeMfModelBuilder;
159
191
  /**
160
- *
161
- * @param material
162
- * @returns
192
+ * Adds a base materials group to the model resources.
193
+ * @param material The base materials resource, or a builder that produces one.
194
+ * @returns This builder, to allow chaining.
163
195
  */
164
196
  withMaterial(material: I3mfBaseMaterials | ThreeMfMaterialBuilder): ThreeMfModelBuilder;
165
197
  /**
166
- *
167
- * @param object
168
- * @returns
198
+ * Adds a mesh object to the model resources.
199
+ * @param object The object resource, or a builder that produces one.
200
+ * @returns This builder, to allow chaining.
169
201
  */
170
202
  withMesh(object: I3mfObject | ThreeMfMeshBuilder): ThreeMfModelBuilder;
171
203
  /**
172
- *
173
- * @param components
174
- * @returns
204
+ * Adds a components object to the model resources.
205
+ * @param components The object resource, or a builder that produces one.
206
+ * @returns This builder, to allow chaining.
175
207
  */
176
208
  withComponents(components: I3mfObject | ThreeMfComponentsBuilder): ThreeMfModelBuilder;
177
209
  /**
178
- *
179
- * @param objectid
180
- * @param transform
181
- * @param partnumber
182
- * @returns
210
+ * Adds a build item, which places an object resource in the build plate.
211
+ * @param objectid The resource id of the object to place.
212
+ * @param transform The optional transform applied to the object.
213
+ * @param partnumber The optional part number identifying the produced part.
214
+ * @returns This builder, to allow chaining.
183
215
  */
184
216
  withBuild(objectid: ST_ResourceID, transform?: Matrix3d, partnumber?: string): ThreeMfModelBuilder;
185
217
  /**
186
- *
187
- * @param unit
188
- * @returns
218
+ * Sets the unit in which the model coordinates are expressed.
219
+ * @param unit The 3MF unit (micron, millimeter, centimeter, inch, foot or meter).
220
+ * @returns This builder, to allow chaining.
189
221
  */
190
222
  withUnit(unit: ST_Unit): ThreeMfModelBuilder;
191
223
  /**
192
- *
193
- * @returns
224
+ * Discards the current model and starts building a new one.
225
+ * @returns This builder, to allow chaining.
194
226
  */
195
227
  reset(): ThreeMfModelBuilder;
196
228
  /**
197
- *
198
- * @returns
229
+ * Validates and returns the model that has been built.
230
+ * @returns The built 3MF model.
231
+ * @throws When the model has no object resource or no build item.
199
232
  */
200
233
  build(): ThreeMfModel;
201
234
  }
202
235
  /**
203
- *
236
+ * Fluent builder for a 3MF document, the OPC package that wraps the model.
237
+ * It gathers the content types, the relationships and the model part.
204
238
  */
205
239
  export declare class ThreeMfDocumentBuilder {
206
240
  private _cts?;
207
241
  private _rs?;
208
242
  private _m?;
209
243
  /**
210
- *
211
- * @param type
212
- * @returns
244
+ * Declares an OPC content type. Duplicate declarations are ignored.
245
+ * @param type The extension to content type mapping to declare.
246
+ * @returns This builder, to allow chaining.
213
247
  */
214
248
  withContentType(type: I3mfContentType): ThreeMfDocumentBuilder;
215
249
  /**
216
- *
217
- * @param rel
218
- * @returns
250
+ * Adds an OPC relationship and ensures the relationships content type is declared.
251
+ * Relationships with an already registered id are ignored.
252
+ * @param rel The relationship to add.
253
+ * @returns This builder, to allow chaining.
219
254
  */
220
255
  withRelationship(rel: I3mfRelationship): ThreeMfDocumentBuilder;
221
256
  /**
222
- *
223
- * @param m
224
- * @returns
257
+ * Sets the model part of the document and ensures the model content type is declared.
258
+ * @param m The model resource, or a builder that produces one.
259
+ * @returns This builder, to allow chaining.
225
260
  */
226
261
  withModel(m: I3mfModel | ThreeMfModelBuilder): ThreeMfDocumentBuilder;
262
+ /**
263
+ * Validates and returns the document that has been built.
264
+ * A default relationship pointing at the model part is generated when none was provided.
265
+ * @returns The built 3MF document.
266
+ * @throws When no model has been set.
267
+ */
227
268
  build(): I3mfDocument;
228
269
  }
@@ -3,39 +3,42 @@ import { ThreeMfBase, ThreeMfBaseMaterials, ThreeMfBuild, ThreeMfComponent, Thre
3
3
  import { ST_ObjectType, } from "./3mf.interfaces.js";
4
4
  import { ThreeMfContentType, ThreeMfContentTypes, ThreeMfDocument, ThreeMfRelationship, ThreeMfRelationships } from "./3mf.opc.js";
5
5
  import { Known3mfRelationshipTypes, KnownI3mfContentType, ModelFileName, Object3dDirName, } from "./3mf.opc.interfaces.js";
6
- /** */
6
+ /**
7
+ * Fluent builder for a 3MF object resource.
8
+ * An object is the base resource of a 3MF model and is either a mesh or a set of components.
9
+ */
7
10
  export class ThreeMfObjectBuilder {
8
11
  /**
9
- *
10
- * @param id
11
- * @param type
12
+ * Creates a new object builder.
13
+ * @param id The unique resource id of the object within the model.
14
+ * @param type The 3MF object type (model, support, solidsupport, surface or other).
12
15
  */
13
16
  constructor(id, type) {
14
17
  this._object = new ThreeMfObject(id, type);
15
18
  }
16
19
  /**
17
- *
18
- * @param name
19
- * @returns
20
+ * Sets the human readable name of the object.
21
+ * @param name The name to assign to the object.
22
+ * @returns This builder, to allow chaining.
20
23
  */
21
24
  withName(name) {
22
25
  this._object.name = name;
23
26
  return this;
24
27
  }
25
28
  /**
26
- *
27
- * @param thumbnail
28
- * @returns
29
+ * Sets the thumbnail of the object.
30
+ * @param thumbnail The package relative path of the thumbnail part.
31
+ * @returns This builder, to allow chaining.
29
32
  */
30
33
  withThumbnail(thumbnail) {
31
34
  this._object.thumbnail = thumbnail;
32
35
  return this;
33
36
  }
34
37
  /**
35
- *
36
- * @param id
37
- * @param index
38
- * @returns
38
+ * Assigns the property resource used by the object.
39
+ * @param id The resource id of the property group (for example a base materials group).
40
+ * @param index The zero based index of the property within the group. Defaults to 0.
41
+ * @returns This builder, to allow chaining.
39
42
  */
40
43
  withProperty(id, index = 0) {
41
44
  this._object.pid = id;
@@ -43,39 +46,40 @@ export class ThreeMfObjectBuilder {
43
46
  return this;
44
47
  }
45
48
  /**
46
- *
47
- * @returns
49
+ * Returns the object that has been built.
50
+ * @returns The built 3MF object resource.
48
51
  */
49
52
  build() {
50
53
  return this._object;
51
54
  }
52
55
  /**
53
- *
54
- * @param id
55
- * @param type
56
+ * Discards the current object and starts building a new one.
57
+ * @param id The unique resource id of the new object.
58
+ * @param type The 3MF object type of the new object.
56
59
  */
57
60
  reset(id, type) {
58
61
  this._object = new ThreeMfObject(id, type);
59
62
  }
60
63
  }
61
64
  /**
62
- *
65
+ * Fluent builder for a 3MF object made of components.
66
+ * A components object references other objects instead of defining its own geometry.
63
67
  */
64
68
  export class ThreeMfComponentsBuilder extends ThreeMfObjectBuilder {
65
69
  /**
66
- *
67
- * @param id
68
- * @param type
70
+ * Creates a new components object builder.
71
+ * @param id The unique resource id of the object within the model.
72
+ * @param type The 3MF object type. Defaults to `ST_ObjectType.model`.
69
73
  */
70
74
  constructor(id, type = ST_ObjectType.model) {
71
75
  super(id, type);
72
76
  this._object.content = new ThreeMfComponents();
73
77
  }
74
78
  /**
75
- *
76
- * @param id
77
- * @param t
78
- * @returns
79
+ * Adds a component referencing another object resource.
80
+ * @param id The resource id of the referenced object.
81
+ * @param t The optional transform applied to the referenced object.
82
+ * @returns This builder, to allow chaining.
79
83
  */
80
84
  withComponent(id, t) {
81
85
  this._object.content.component.push(new ThreeMfComponent(id, t));
@@ -83,21 +87,22 @@ export class ThreeMfComponentsBuilder extends ThreeMfObjectBuilder {
83
87
  }
84
88
  }
85
89
  /**
86
- *
90
+ * Fluent builder for a 3MF object holding a mesh.
91
+ * Vertices and triangles are generated from Babylon vertex data and can be post processed through handlers.
87
92
  */
88
93
  export class ThreeMfMeshBuilder extends ThreeMfObjectBuilder {
89
94
  /**
90
- *
91
- * @param id
95
+ * Creates a new mesh object builder.
96
+ * @param id The unique resource id of the object within the model.
92
97
  */
93
98
  constructor(id) {
94
99
  super(id, ST_ObjectType.model);
95
100
  }
96
101
  /**
97
- *
98
- * @param vertex
99
- * @param triangle
100
- * @returns
102
+ * Registers the handlers used to post process the generated geometry.
103
+ * @param vertex The handler invoked for every generated vertex.
104
+ * @param triangle The optional handler invoked for every generated triangle.
105
+ * @returns This builder, to allow chaining.
101
106
  */
102
107
  withPostProcessHandlers(vertex, triangle) {
103
108
  this._vh = vertex;
@@ -105,19 +110,19 @@ export class ThreeMfMeshBuilder extends ThreeMfObjectBuilder {
105
110
  return this;
106
111
  }
107
112
  /**
108
- *
109
- * @param data
110
- * @returns
113
+ * Builds the mesh content of the object from the provided vertex data.
114
+ * @param data The positions and indices used to generate the mesh.
115
+ * @returns This builder, to allow chaining.
111
116
  */
112
117
  withData(data) {
113
118
  this._object.content = this._buildMesh(data);
114
119
  return this;
115
120
  }
116
121
  /**
117
- *
118
- * @param id
119
- * @param i
120
- * @returns
122
+ * Assigns the material used by the mesh.
123
+ * @param id The resource id of the base materials group.
124
+ * @param i The zero based index of the material within the group.
125
+ * @returns This builder, to allow chaining.
121
126
  */
122
127
  withMaterial(id, i) {
123
128
  this._object.pid = id;
@@ -125,15 +130,20 @@ export class ThreeMfMeshBuilder extends ThreeMfObjectBuilder {
125
130
  return this;
126
131
  }
127
132
  /**
128
- *
129
- * @param data
130
- * @returns
133
+ * Converts vertex data into a 3MF mesh.
134
+ * @param data The positions and indices used to generate the mesh.
135
+ * @returns The generated 3MF mesh.
131
136
  */
132
137
  _buildMesh(data) {
133
138
  const vertices = this._buildVertices(data.positions);
134
139
  const triangles = this._buildTriangle(data.indices);
135
140
  return new ThreeMfMesh(vertices, triangles);
136
141
  }
142
+ /**
143
+ * Converts a flat position array into a 3MF vertex list, applying the vertex handler when one is registered.
144
+ * @param p The flat array of x, y and z positions.
145
+ * @returns The generated 3MF vertex list.
146
+ */
137
147
  _buildVertices(p) {
138
148
  const container = new ThreeMfVertices();
139
149
  if (p) {
@@ -151,6 +161,11 @@ export class ThreeMfMeshBuilder extends ThreeMfObjectBuilder {
151
161
  }
152
162
  return container;
153
163
  }
164
+ /**
165
+ * Converts a flat index array into a 3MF triangle list, applying the triangle handler when one is registered.
166
+ * @param indice The flat array of vertex indices, three per triangle.
167
+ * @returns The generated 3MF triangle list.
168
+ */
154
169
  _buildTriangle(indice) {
155
170
  const container = new ThreeMfTriangles();
156
171
  if (indice) {
@@ -170,17 +185,22 @@ export class ThreeMfMeshBuilder extends ThreeMfObjectBuilder {
170
185
  }
171
186
  }
172
187
  /**
173
- *
188
+ * Fluent builder for a 3MF base materials resource.
189
+ * Colors are stored as sRGB hexadecimal strings as required by the 3MF specification.
174
190
  */
175
191
  export class ThreeMfMaterialBuilder {
192
+ /**
193
+ * Creates a new base materials builder.
194
+ * @param id The unique resource id of the base materials group within the model.
195
+ */
176
196
  constructor(id) {
177
197
  this._m = new ThreeMfBaseMaterials(id);
178
198
  }
179
199
  /**
180
- *
181
- * @param name
182
- * @param color
183
- * @returns
200
+ * Adds a named color to the group, or updates it when the name already exists.
201
+ * @param name The name of the material. The lookup is case insensitive.
202
+ * @param color The linear RGBA color, converted to an sRGB hexadecimal string.
203
+ * @returns This builder, to allow chaining.
184
204
  */
185
205
  withColor(name, color) {
186
206
  this._m.base = this._m.base ?? [];
@@ -194,12 +214,17 @@ export class ThreeMfMaterialBuilder {
194
214
  return this;
195
215
  }
196
216
  /**
197
- *
198
- * @returns
217
+ * Returns the base materials group that has been built.
218
+ * @returns The built base materials resource.
199
219
  */
200
220
  build() {
201
221
  return this._m;
202
222
  }
223
+ /**
224
+ * Converts a linear color into the sRGB hexadecimal string used by 3MF.
225
+ * @param c The linear color to convert. The alpha channel is optional.
226
+ * @returns The color as `#RRGGBB`, or `#RRGGBBAA` when an alpha channel is provided.
227
+ */
203
228
  _rgbaToHex(c) {
204
229
  const toSRGB = (c) => Math.round(Math.min(255, Math.max(0, Math.pow(c, 1 / 2.2) * 255)));
205
230
  const r = toSRGB(c.r).toString(16).padStart(2, "0").toUpperCase();
@@ -216,26 +241,27 @@ export class ThreeMfMaterialBuilder {
216
241
  }
217
242
  }
218
243
  /**
219
- *
244
+ * Fluent builder for a 3MF model, the root part of a 3MF document.
245
+ * It aggregates the resources (materials, meshes and components) and the build items that reference them.
220
246
  */
221
247
  export class ThreeMfModelBuilder {
222
248
  constructor() {
223
249
  /**
224
- *
250
+ * The 3MF model currently being built.
225
251
  */
226
252
  this._model = new ThreeMfModel();
227
253
  /**
228
- *
254
+ * The object resources added to the model, indexed by resource id.
229
255
  */
230
256
  this._objects = new Map();
231
257
  }
232
258
  /**
233
- *
234
- * @param name
235
- * @param value
236
- * @param preserve
237
- * @param type
238
- * @returns
259
+ * Adds a metadata entry to the model.
260
+ * @param name The metadata name. Names outside of the 3MF specification must be namespace qualified.
261
+ * @param value The metadata value.
262
+ * @param preserve Whether consumers must preserve this entry when editing the document.
263
+ * @param type The XML schema type of the value. Defaults to `xs:string`.
264
+ * @returns This builder, to allow chaining.
239
265
  */
240
266
  withMetaData(name, value, preserve, type) {
241
267
  if (!this._model.metadata) {
@@ -248,9 +274,9 @@ export class ThreeMfModelBuilder {
248
274
  return this;
249
275
  }
250
276
  /**
251
- *
252
- * @param material
253
- * @returns
277
+ * Adds a base materials group to the model resources.
278
+ * @param material The base materials resource, or a builder that produces one.
279
+ * @returns This builder, to allow chaining.
254
280
  */
255
281
  withMaterial(material) {
256
282
  if (material instanceof ThreeMfMaterialBuilder) {
@@ -264,9 +290,9 @@ export class ThreeMfModelBuilder {
264
290
  return this;
265
291
  }
266
292
  /**
267
- *
268
- * @param object
269
- * @returns
293
+ * Adds a mesh object to the model resources.
294
+ * @param object The object resource, or a builder that produces one.
295
+ * @returns This builder, to allow chaining.
270
296
  */
271
297
  withMesh(object) {
272
298
  if (object instanceof ThreeMfMeshBuilder) {
@@ -277,9 +303,9 @@ export class ThreeMfModelBuilder {
277
303
  return this;
278
304
  }
279
305
  /**
280
- *
281
- * @param components
282
- * @returns
306
+ * Adds a components object to the model resources.
307
+ * @param components The object resource, or a builder that produces one.
308
+ * @returns This builder, to allow chaining.
283
309
  */
284
310
  withComponents(components) {
285
311
  if (components instanceof ThreeMfComponentsBuilder) {
@@ -290,11 +316,11 @@ export class ThreeMfModelBuilder {
290
316
  return this;
291
317
  }
292
318
  /**
293
- *
294
- * @param objectid
295
- * @param transform
296
- * @param partnumber
297
- * @returns
319
+ * Adds a build item, which places an object resource in the build plate.
320
+ * @param objectid The resource id of the object to place.
321
+ * @param transform The optional transform applied to the object.
322
+ * @param partnumber The optional part number identifying the produced part.
323
+ * @returns This builder, to allow chaining.
298
324
  */
299
325
  withBuild(objectid, transform, partnumber) {
300
326
  this._model.build = this._model.build ?? new ThreeMfBuild();
@@ -302,17 +328,17 @@ export class ThreeMfModelBuilder {
302
328
  return this;
303
329
  }
304
330
  /**
305
- *
306
- * @param unit
307
- * @returns
331
+ * Sets the unit in which the model coordinates are expressed.
332
+ * @param unit The 3MF unit (micron, millimeter, centimeter, inch, foot or meter).
333
+ * @returns This builder, to allow chaining.
308
334
  */
309
335
  withUnit(unit) {
310
336
  this._model.unit = unit;
311
337
  return this;
312
338
  }
313
339
  /**
314
- *
315
- * @returns
340
+ * Discards the current model and starts building a new one.
341
+ * @returns This builder, to allow chaining.
316
342
  */
317
343
  reset() {
318
344
  this._model = new ThreeMfModel();
@@ -320,8 +346,9 @@ export class ThreeMfModelBuilder {
320
346
  return this;
321
347
  }
322
348
  /**
323
- *
324
- * @returns
349
+ * Validates and returns the model that has been built.
350
+ * @returns The built 3MF model.
351
+ * @throws When the model has no object resource or no build item.
325
352
  */
326
353
  build() {
327
354
  // quick surface check..
@@ -335,17 +362,18 @@ export class ThreeMfModelBuilder {
335
362
  }
336
363
  }
337
364
  /**
338
- *
365
+ * The lower cased set of the metadata names defined by the 3MF specification.
339
366
  */
340
367
  ThreeMfModelBuilder.KnownMetaSet = new Set(ThreeMfModel.KnownMeta.map((m) => m.toLowerCase()));
341
368
  /**
342
- *
369
+ * Fluent builder for a 3MF document, the OPC package that wraps the model.
370
+ * It gathers the content types, the relationships and the model part.
343
371
  */
344
372
  export class ThreeMfDocumentBuilder {
345
373
  /**
346
- *
347
- * @param type
348
- * @returns
374
+ * Declares an OPC content type. Duplicate declarations are ignored.
375
+ * @param type The extension to content type mapping to declare.
376
+ * @returns This builder, to allow chaining.
349
377
  */
350
378
  withContentType(type) {
351
379
  if (!this._cts) {
@@ -358,9 +386,10 @@ export class ThreeMfDocumentBuilder {
358
386
  return this;
359
387
  }
360
388
  /**
361
- *
362
- * @param rel
363
- * @returns
389
+ * Adds an OPC relationship and ensures the relationships content type is declared.
390
+ * Relationships with an already registered id are ignored.
391
+ * @param rel The relationship to add.
392
+ * @returns This builder, to allow chaining.
364
393
  */
365
394
  withRelationship(rel) {
366
395
  if (!this._rs) {
@@ -375,9 +404,9 @@ export class ThreeMfDocumentBuilder {
375
404
  return this;
376
405
  }
377
406
  /**
378
- *
379
- * @param m
380
- * @returns
407
+ * Sets the model part of the document and ensures the model content type is declared.
408
+ * @param m The model resource, or a builder that produces one.
409
+ * @returns This builder, to allow chaining.
381
410
  */
382
411
  withModel(m) {
383
412
  if (m instanceof ThreeMfModelBuilder) {
@@ -388,6 +417,12 @@ export class ThreeMfDocumentBuilder {
388
417
  this.withContentType(new ThreeMfContentType("model", KnownI3mfContentType.Model));
389
418
  return this;
390
419
  }
420
+ /**
421
+ * Validates and returns the document that has been built.
422
+ * A default relationship pointing at the model part is generated when none was provided.
423
+ * @returns The built 3MF document.
424
+ * @throws When no model has been set.
425
+ */
391
426
  build() {
392
427
  if (!this._m) {
393
428
  throw new Error("Invalid state: you Must provide at least a model.");
@@ -1 +1 @@
1
- {"version":3,"file":"3mf.builder.js","sourceRoot":"","sources":["../../../../../../dev/serializers/src/3MF/core/model/3mf.builder.ts"],"names":[],"mappings":"AAAA,MAAM;AACN,OAAO,EAEH,WAAW,EACX,oBAAoB,EACpB,YAAY,EACZ,gBAAgB,EAChB,iBAAiB,EACjB,WAAW,EACX,WAAW,EACX,WAAW,EACX,YAAY,EACZ,aAAa,EACb,gBAAgB,EAChB,eAAe,EACf,gBAAgB,EAChB,aAAa,EACb,eAAe,GAClB,MAAM,OAAO,CAAC;AACf,OAAO,EAcH,aAAa,GAChB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,eAAe,EAAE,m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MfBase,\r\n ThreeMfBaseMaterials,\r\n ThreeMfBuild,\r\n ThreeMfComponent,\r\n ThreeMfComponents,\r\n ThreeMfItem,\r\n ThreeMfMesh,\r\n ThreeMfMeta,\r\n ThreeMfModel,\r\n ThreeMfObject,\r\n ThreeMfResources,\r\n ThreeMfTriangle,\r\n ThreeMfTriangles,\r\n ThreeMfVertex,\r\n ThreeMfVertices,\r\n} from \"./3mf\";\r\nimport {\r\n type I3mfBaseMaterials,\r\n type I3mfComponents,\r\n type I3mfMesh,\r\n type I3mfMetadata,\r\n type I3mfModel,\r\n type I3mfObject,\r\n type I3mfTriangle,\r\n type I3mfTriangles,\r\n type I3mfVertex,\r\n type I3mfVertices,\r\n type ST_ResourceID,\r\n type ST_ResourceIndex,\r\n type ST_Unit,\r\n ST_ObjectType,\r\n} from \"./3mf.interfaces\";\r\nimport { ThreeMfContentType, ThreeMfContentTypes, ThreeMfDocument, ThreeMfRelationship, ThreeMfRelationships } from \"./3mf.opc\";\r\nimport {\r\n type I3mfDocument,\r\n Known3mfRelationshipTypes,\r\n KnownI3mfContentType,\r\n ModelFileName,\r\n Object3dDirName,\r\n type I3mfContentType,\r\n type I3mfContentTypes,\r\n type I3mfRelationship,\r\n type I3mfRelationships,\r\n} from \"./3mf.opc.interfaces\";\r\nimport { type I3mfRGBAColor, type I3mfVertexData, type ThreeMfFloatArray, type ThreeMfIndicesArray } from \"./3mf.types\";\r\n\r\nexport type VertexHandler = (vertex: I3mfVertex) => I3mfVertex;\r\nexport type TriangleHandler = (triangle: I3mfTriangle) => I3mfTriangle;\r\n\r\n/** */\r\nexport class ThreeMfObjectBuilder {\r\n /**\r\n *\r\n */\r\n protected _object: ThreeMfObject;\r\n\r\n /**\r\n *\r\n * @param id\r\n * @param type\r\n */\r\n public constructor(id: ST_ResourceID, type: ST_ObjectType) {\r\n this._object = new ThreeMfObject(id, type);\r\n }\r\n\r\n /**\r\n *\r\n * @param name\r\n * @returns\r\n */\r\n public withName(name: string): ThreeMfObjectBuilder {\r\n this._object.name = name;\r\n return this;\r\n }\r\n\r\n /**\r\n *\r\n * @param thumbnail\r\n * @returns\r\n */\r\n public withThumbnail(thumbnail: string): ThreeMfObjectBuilder {\r\n this._object.thumbnail = thumbnail;\r\n return this;\r\n }\r\n\r\n /**\r\n *\r\n * @param id\r\n * @param index\r\n * @returns\r\n */\r\n public withProperty(id: ST_ResourceIndex, index: number = 0): ThreeMfObjectBuilder {\r\n this._object.pid = id;\r\n this._object.id = index;\r\n return this;\r\n }\r\n\r\n /**\r\n *\r\n * @returns\r\n */\r\n public build(): I3mfObject {\r\n return this._object;\r\n }\r\n\r\n /**\r\n *\r\n * @param id\r\n * @param type\r\n */\r\n public reset(id: ST_ResourceID, type: ST_ObjectType) {\r\n this._object = new ThreeMfObject(id, type);\r\n }\r\n}\r\n\r\n/**\r\n *\r\n */\r\nexport class ThreeMfComponentsBuilder extends ThreeMfObjectBuilder {\r\n /**\r\n *\r\n * @param id\r\n * @param type\r\n */\r\n public constructor(id: ST_ResourceID, type: ST_ObjectType = ST_ObjectType.model) {\r\n super(id, type);\r\n this._object.content = new ThreeMfComponents();\r\n }\r\n\r\n /**\r\n *\r\n * @param id\r\n * @param t\r\n * @returns\r\n */\r\n public withComponent(id: ST_ResourceID, t?: Matrix3d): ThreeMfComponentsBuilder {\r\n (this._object.content as I3mfComponents).component.push(new ThreeMfComponent(id, t));\r\n return this;\r\n }\r\n}\r\n\r\n/**\r\n *\r\n */\r\nexport class ThreeMfMeshBuilder extends ThreeMfObjectBuilder {\r\n /**\r\n *\r\n */\r\n _vh?: VertexHandler;\r\n /**\r\n *\r\n */\r\n _th?: TriangleHandler;\r\n\r\n /**\r\n *\r\n * @param id\r\n */\r\n public constructor(id: ST_ResourceID) {\r\n super(id, ST_ObjectType.model);\r\n }\r\n\r\n /**\r\n *\r\n * @param vertex\r\n * @param triangle\r\n * @returns\r\n */\r\n public withPostProcessHandlers(vertex: VertexHandler, triangle?: TriangleHandler): ThreeMfMeshBuilder {\r\n this._vh = vertex;\r\n this._th = triangle;\r\n return this;\r\n }\r\n\r\n /**\r\n *\r\n * @param data\r\n * @returns\r\n */\r\n withData(data: I3mfVertexData): ThreeMfMeshBuilder {\r\n this._object.content = this._buildMesh(data);\r\n return this;\r\n }\r\n\r\n /**\r\n *\r\n * @param id\r\n * @param i\r\n * @returns\r\n */\r\n withMaterial(id: ST_ResourceID, i: number): ThreeMfMeshBuilder {\r\n this._object.pid = id;\r\n this._object.pindex = i;\r\n return this;\r\n }\r\n\r\n /**\r\n *\r\n * @param data\r\n * @returns\r\n */\r\n private _buildMesh(data: I3mfVertexData): I3mfMesh {\r\n const vertices = this._buildVertices(data.positions);\r\n const triangles = this._buildTriangle(data.indices);\r\n return new ThreeMfMesh(vertices, triangles);\r\n }\r\n\r\n private _buildVertices(p: ThreeMfFloatArray | null): I3mfVertices {\r\n const container = new ThreeMfVertices();\r\n if (p) {\r\n for (let i = 0; i < p.length; ) {\r\n const x = p[i++];\r\n const y = p[i++];\r\n const z = p[i++];\r\n let v = new ThreeMfVertex(x, y, z);\r\n // might be optimized....\r\n if (this._vh) {\r\n v = this._vh(v);\r\n }\r\n container.vertex.push(v);\r\n }\r\n }\r\n return container;\r\n }\r\n\r\n private _buildTriangle(indice: ThreeMfIndicesArray | null): I3mfTriangles {\r\n const container = new ThreeMfTriangles();\r\n if (indice) {\r\n for (let i = 0; i < indice.length; ) {\r\n const a = indice[i++];\r\n const b = indice[i++];\r\n const c = indice[i++];\r\n let t = new ThreeMfTriangle(a, b, c);\r\n // might be optimized....\r\n if (this._th) {\r\n t = this._th(t);\r\n }\r\n container.triangle.push(t);\r\n }\r\n }\r\n return container;\r\n }\r\n}\r\n\r\n/**\r\n *\r\n */\r\nexport class ThreeMfMaterialBuilder {\r\n private _m: I3mfBaseMaterials;\r\n\r\n public constructor(id: ST_ResourceID) {\r\n this._m = new ThreeMfBaseMaterials(id);\r\n }\r\n\r\n /**\r\n *\r\n * @param name\r\n * @param color\r\n * @returns\r\n */\r\n public withColor(name: string, color: I3mfRGBAColor): ThreeMfMaterialBuilder {\r\n this._m.base = this._m.base ?? [];\r\n let m = this._m.base.find((m) => m.name.toLowerCase() === name.toLowerCase());\r\n if (m) {\r\n m.displaycolor = this._rgbaToHex(color);\r\n return this;\r\n }\r\n m = new ThreeMfBase(name, this._rgbaToHex(color));\r\n this._m.base.push(m);\r\n return this;\r\n }\r\n\r\n /**\r\n *\r\n * @returns\r\n */\r\n public build(): I3mfBaseMaterials {\r\n return this._m;\r\n }\r\n\r\n private _rgbaToHex(c: I3mfRGBAColor | { r: number; g: number; b: number; a?: number }): string {\r\n const toSRGB = (c: number) => Math.round(Math.min(255, Math.max(0, Math.pow(c, 1 / 2.2) * 255)));\r\n\r\n const r = toSRGB(c.r).toString(16).padStart(2, \"0\").toUpperCase();\r\n const g = toSRGB(c.g).toString(16).padStart(2, \"0\").toUpperCase();\r\n const b = toSRGB(c.b).toString(16).padStart(2, \"0\").toUpperCase();\r\n\r\n if (typeof (c as any).a === \"number\") {\r\n const a = Math.round(Math.min(255, Math.max(0, c.a! * 255)))\r\n .toString(16)\r\n .padStart(2, \"0\")\r\n .toUpperCase();\r\n return `#${r}${g}${b}${a}`;\r\n }\r\n\r\n return `#${r}${g}${b}`;\r\n }\r\n}\r\n\r\n/**\r\n *\r\n */\r\nexport class ThreeMfModelBuilder {\r\n /**\r\n *\r\n */\r\n static KnownMetaSet = new Set(ThreeMfModel.KnownMeta.map((m) => m.toLowerCase()));\r\n\r\n /**\r\n *\r\n */\r\n _model: ThreeMfModel = new ThreeMfModel();\r\n /**\r\n *\r\n */\r\n _objects = new Map<string, I3mfObject>();\r\n\r\n /**\r\n *\r\n * @param name\r\n * @param value\r\n * @param preserve\r\n * @param type\r\n * @returns\r\n */\r\n public withMetaData(name: string, value: string, preserve?: boolean, type?: string): ThreeMfModelBuilder {\r\n if (!this._model.metadata) {\r\n // lazzy\r\n this._model.metadata = new Array<I3mfMetadata>();\r\n }\r\n //const isKnownMeta = (s: string): boolean => TMFBuilder.knownMetaSet.has(s.toLowerCase());\r\n //const qn:IQName = xmlNameToParts(name);\r\n this._model.metadata.push(new ThreeMfMeta(name, value, preserve, type));\r\n return this;\r\n }\r\n\r\n /**\r\n *\r\n * @param material\r\n * @returns\r\n */\r\n public withMaterial(material: I3mfBaseMaterials | ThreeMfMaterialBuilder): ThreeMfModelBuilder {\r\n if (material instanceof ThreeMfMaterialBuilder) {\r\n material = material.build();\r\n }\r\n if (material) {\r\n this._model.resources = this._model.resources ?? new ThreeMfResources();\r\n this._model.resources.basematerials = this._model.resources.basematerials ?? [];\r\n this._model.resources.basematerials.push(material);\r\n }\r\n return this;\r\n }\r\n\r\n /**\r\n *\r\n * @param object\r\n * @returns\r\n */\r\n public withMesh(object: I3mfObject | ThreeMfMeshBuilder): ThreeMfModelBuilder {\r\n if (object instanceof ThreeMfMeshBuilder) {\r\n object = object.build();\r\n }\r\n this._model.resources = this._model.resources ?? new ThreeMfResources();\r\n this._model.resources.object.push(object);\r\n return this;\r\n }\r\n\r\n /**\r\n *\r\n * @param components\r\n * @returns\r\n */\r\n public withComponents(components: I3mfObject | ThreeMfComponentsBuilder): ThreeMfModelBuilder {\r\n if (components instanceof ThreeMfComponentsBuilder) {\r\n components = components.build();\r\n }\r\n this._model.resources = this._model.resources ?? new ThreeMfResources();\r\n this._model.resources.object.push(components);\r\n return this;\r\n }\r\n\r\n /**\r\n *\r\n * @param objectid\r\n * @param transform\r\n * @param partnumber\r\n * @returns\r\n */\r\n public withBuild(objectid: ST_ResourceID, transform?: Matrix3d, partnumber?: string): ThreeMfModelBuilder {\r\n this._model.build = this._model.build ?? new ThreeMfBuild();\r\n this._model.build.item?.push(new ThreeMfItem(objectid, transform, partnumber));\r\n return this;\r\n }\r\n\r\n /**\r\n *\r\n * @param unit\r\n * @returns\r\n */\r\n public withUnit(unit: ST_Unit): ThreeMfModelBuilder {\r\n this._model.unit = unit;\r\n return this;\r\n }\r\n\r\n /**\r\n *\r\n * @returns\r\n */\r\n public reset(): ThreeMfModelBuilder {\r\n this._model = new ThreeMfModel();\r\n this._objects = new Map<string, I3mfObject>();\r\n return this;\r\n }\r\n\r\n /**\r\n *\r\n * @returns\r\n */\r\n public build(): ThreeMfModel {\r\n // quick surface check..\r\n if (!this._model.resources?.object?.length) {\r\n throw new Error(\"Invalid state: resources MUST be defined \");\r\n }\r\n if (!this._model.build?.item?.length) {\r\n throw new Error(\"Invalid state: Build MUST be defined \");\r\n }\r\n return this._model;\r\n }\r\n}\r\n\r\n/**\r\n *\r\n */\r\nexport class ThreeMfDocumentBuilder {\r\n private _cts?: I3mfContentTypes;\r\n private _rs?: I3mfRelationships;\r\n private _m?: I3mfModel;\r\n\r\n /**\r\n *\r\n * @param type\r\n * @returns\r\n */\r\n public withContentType(type: I3mfContentType): ThreeMfDocumentBuilder {\r\n if (!this._cts) {\r\n this._cts = new ThreeMfContentTypes();\r\n }\r\n const arr = this._cts.items;\r\n if (!arr.some((x) => x.ext === type.ext && x.ct === type.ct)) {\r\n arr.push(type);\r\n }\r\n return this;\r\n }\r\n\r\n /**\r\n *\r\n * @param rel\r\n * @returns\r\n */\r\n public withRelationship(rel: I3mfRelationship): ThreeMfDocumentBuilder {\r\n if (!this._rs) {\r\n this._rs = new ThreeMfRelationships();\r\n }\r\n const arr = this._rs.items;\r\n if (!arr.some((x) => x.id === rel.id)) {\r\n arr.push(rel);\r\n }\r\n // here we ensure that the content type is declared.\r\n this.withContentType(new ThreeMfContentType(\"rels\", KnownI3mfContentType.Relationships));\r\n return this;\r\n }\r\n\r\n /**\r\n *\r\n * @param m\r\n * @returns\r\n */\r\n public withModel(m: I3mfModel | ThreeMfModelBuilder): ThreeMfDocumentBuilder {\r\n if (m instanceof ThreeMfModelBuilder) {\r\n m = m.build();\r\n }\r\n this._m = m;\r\n // here we ensure that the content type is declared.\r\n this.withContentType(new ThreeMfContentType(\"model\", KnownI3mfContentType.Model));\r\n return this;\r\n }\r\n\r\n public build(): I3mfDocument {\r\n if (!this._m) {\r\n throw new Error(\"Invalid state: you Must provide at least a model.\");\r\n }\r\n\r\n // we automate the build of the relationship if not provided..\r\n const path = `${Object3dDirName}${ModelFileName}`;\r\n if (!this._rs) {\r\n const absolutePath = `/${path}`;\r\n this.withRelationship(new ThreeMfRelationship(`rel${0}`, Known3mfRelationshipTypes.ThreeDimModel, absolutePath));\r\n }\r\n\r\n return new ThreeMfDocument(this._cts!, this._rs!, this._m);\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"3mf.builder.js","sourceRoot":"","sources":["../../../../../../dev/serializers/src/3MF/core/model/3mf.builder.ts"],"names":[],"mappings":"AAAA,MAAM;AACN,OAAO,EAEH,WAAW,EACX,oBAAoB,EACpB,YAAY,EACZ,gBAAgB,EAChB,iBAAiB,EACjB,WAAW,EACX,WAAW,EACX,WAAW,EACX,YAAY,EACZ,aAAa,EACb,gBAAgB,EAChB,eAAe,EACf,gBAAgB,EAChB,aAAa,EACb,eAAe,GAClB,MAAM,OAAO,CAAC;AACf,OAAO,EAcH,aAAa,GAChB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,eAAe,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAChI,OAAO,EAEH,yBAAyB,EACzB,oBAAoB,EACpB,aAAa,EACb,eAAe,GAKlB,MAAM,sBAAsB,CAAC;AAY9B;;;GAGG;AACH,MAAM,OAAO,oBAAoB;IAM7B;;;;OAIG;IACH,YAAmB,EAAiB,EAAE,IAAmB;QACrD,IAAI,CAAC,OAAO,GAAG,IAAI,aAAa,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;IAC/C,CAAC;IAED;;;;OAIG;IACI,QAAQ,CAAC,IAAY;QACxB,IAAI,CAAC,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC;QACzB,OAAO,IAAI,CAAC;IAChB,CAAC;IAED;;;;OAIG;IACI,aAAa,CAAC,SAAiB;QAClC,IAAI,CAAC,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AAI,CAAC,EAAE,GAAG,CAAC,CAAC;QACZ,oDAAoD;QACpD,IAAI,CAAC,eAAe,CAAC,IAAI,kBAAkB,CAAC,OAAO,EAAE,oBAAoB,CAAC,KAAK,CAAC,CAAC,CAAC;QAClF,OAAO,IAAI,CAAC;IAChB,CAAC;IAED;;;;;OAKG;IACI,KAAK;QACR,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC;YACX,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;QACzE,CAAC;QAED,8DAA8D;QAC9D,MAAM,IAAI,GAAG,GAAG,eAAe,GAAG,aAAa,EAAE,CAAC;QAClD,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC;YACZ,MAAM,YAAY,GAAG,IAAI,IAAI,EAAE,CAAC;YAChC,IAAI,CAAC,gBAAgB,CAAC,IAAI,mBAAmB,CAAC,MAAM,CAAC,EAAE,EAAE,yBAAyB,CAAC,aAAa,EAAE,YAAY,CAAC,CAAC,CAAC;QACrH,CAAC;QAED,OAAO,IAAI,eAAe,CAAC,IAAI,CAAC,IAAK,EAAE,IAAI,CAAC,GAAI,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC;IAC/D,CAAC;CACJ","sourcesContent":["// 3MF\r\nimport {\r\n type Matrix3d,\r\n ThreeMfBase,\r\n ThreeMfBaseMaterials,\r\n ThreeMfBuild,\r\n ThreeMfComponent,\r\n ThreeMfComponents,\r\n ThreeMfItem,\r\n ThreeMfMesh,\r\n ThreeMfMeta,\r\n ThreeMfModel,\r\n ThreeMfObject,\r\n ThreeMfResources,\r\n ThreeMfTriangle,\r\n ThreeMfTriangles,\r\n ThreeMfVertex,\r\n ThreeMfVertices,\r\n} from \"./3mf\";\r\nimport {\r\n type I3mfBaseMaterials,\r\n type I3mfComponents,\r\n type I3mfMesh,\r\n type I3mfMetadata,\r\n type I3mfModel,\r\n type I3mfObject,\r\n type I3mfTriangle,\r\n type I3mfTriangles,\r\n type I3mfVertex,\r\n type I3mfVertices,\r\n type ST_ResourceID,\r\n type ST_ResourceIndex,\r\n type ST_Unit,\r\n ST_ObjectType,\r\n} from \"./3mf.interfaces\";\r\nimport { ThreeMfContentType, ThreeMfContentTypes, ThreeMfDocument, ThreeMfRelationship, ThreeMfRelationships } from \"./3mf.opc\";\r\nimport {\r\n type I3mfDocument,\r\n Known3mfRelationshipTypes,\r\n KnownI3mfContentType,\r\n ModelFileName,\r\n Object3dDirName,\r\n type I3mfContentType,\r\n type I3mfContentTypes,\r\n type I3mfRelationship,\r\n type I3mfRelationships,\r\n} from \"./3mf.opc.interfaces\";\r\nimport { type I3mfRGBAColor, type I3mfVertexData, type ThreeMfFloatArray, type ThreeMfIndicesArray } from \"./3mf.types\";\r\n\r\n/**\r\n * Handler invoked for every vertex generated by a {@link ThreeMfMeshBuilder}, allowing it to be transformed before export.\r\n */\r\nexport type VertexHandler = (vertex: I3mfVertex) => I3mfVertex;\r\n/**\r\n * Handler invoked for every triangle generated by a {@link ThreeMfMeshBuilder}, allowing it to be transformed before export.\r\n */\r\nexport type TriangleHandler = (triangle: I3mfTriangle) => I3mfTriangle;\r\n\r\n/**\r\n * Fluent builder for a 3MF object resource.\r\n * An object is the base resource of a 3MF model and is either a mesh or a set of components.\r\n */\r\nexport class ThreeMfObjectBuilder {\r\n /**\r\n * The 3MF object resource currently being built.\r\n */\r\n protected _object: ThreeMfObject;\r\n\r\n /**\r\n * Creates a new object builder.\r\n * @param id The unique resource id of the object within the model.\r\n * @param type The 3MF object type (model, support, solidsupport, surface or other).\r\n */\r\n public constructor(id: ST_ResourceID, type: ST_ObjectType) {\r\n this._object = new ThreeMfObject(id, type);\r\n }\r\n\r\n /**\r\n * Sets the human readable name of the object.\r\n * @param name The name to assign to the object.\r\n * @returns This builder, to allow chaining.\r\n */\r\n public withName(name: string): ThreeMfObjectBuilder {\r\n this._object.name = name;\r\n return this;\r\n }\r\n\r\n /**\r\n * Sets the thumbnail of the object.\r\n * @param thumbnail The package relative path of the thumbnail part.\r\n * @returns This builder, to allow chaining.\r\n */\r\n public withThumbnail(thumbnail: string): ThreeMfObjectBuilder {\r\n this._object.thumbnail = thumbnail;\r\n return this;\r\n }\r\n\r\n /**\r\n * Assigns the property resource used by the object.\r\n * @param id The resource id of the property group (for example a base materials group).\r\n * @param index The zero based index of the property within the group. Defaults to 0.\r\n * @returns This builder, to allow chaining.\r\n */\r\n public withProperty(id: ST_ResourceIndex, index: number = 0): ThreeMfObjectBuilder {\r\n this._object.pid = id;\r\n this._object.id = index;\r\n return this;\r\n }\r\n\r\n /**\r\n * Returns the object that has been built.\r\n * @returns The built 3MF object resource.\r\n */\r\n public build(): I3mfObject {\r\n return this._object;\r\n }\r\n\r\n /**\r\n * Discards the current object and starts building a new one.\r\n * @param id The unique resource id of the new object.\r\n * @param type The 3MF object type of the new object.\r\n */\r\n public reset(id: ST_ResourceID, type: ST_ObjectType) {\r\n this._object = new ThreeMfObject(id, type);\r\n }\r\n}\r\n\r\n/**\r\n * Fluent builder for a 3MF object made of components.\r\n * A components object references other objects instead of defining its own geometry.\r\n */\r\nexport class ThreeMfComponentsBuilder extends ThreeMfObjectBuilder {\r\n /**\r\n * Creates a new components object builder.\r\n * @param id The unique resource id of the object within the model.\r\n * @param type The 3MF object type. Defaults to `ST_ObjectType.model`.\r\n */\r\n public constructor(id: ST_ResourceID, type: ST_ObjectType = ST_ObjectType.model) {\r\n super(id, type);\r\n this._object.content = new ThreeMfComponents();\r\n }\r\n\r\n /**\r\n * Adds a component referencing another object resource.\r\n * @param id The resource id of the referenced object.\r\n * @param t The optional transform applied to the referenced object.\r\n * @returns This builder, to allow chaining.\r\n */\r\n public withComponent(id: ST_ResourceID, t?: Matrix3d): ThreeMfComponentsBuilder {\r\n (this._object.content as I3mfComponents).component.push(new ThreeMfComponent(id, t));\r\n return this;\r\n }\r\n}\r\n\r\n/**\r\n * Fluent builder for a 3MF object holding a mesh.\r\n * Vertices and triangles are generated from Babylon vertex data and can be post processed through handlers.\r\n */\r\nexport class ThreeMfMeshBuilder extends ThreeMfObjectBuilder {\r\n /**\r\n * Optional handler invoked for every vertex before it is added to the mesh.\r\n */\r\n _vh?: VertexHandler;\r\n /**\r\n * Optional handler invoked for every triangle before it is added to the mesh.\r\n */\r\n _th?: TriangleHandler;\r\n\r\n /**\r\n * Creates a new mesh object builder.\r\n * @param id The unique resource id of the object within the model.\r\n */\r\n public constructor(id: ST_ResourceID) {\r\n super(id, ST_ObjectType.model);\r\n }\r\n\r\n /**\r\n * Registers the handlers used to post process the generated geometry.\r\n * @param vertex The handler invoked for every generated vertex.\r\n * @param triangle The optional handler invoked for every generated triangle.\r\n * @returns This builder, to allow chaining.\r\n */\r\n public withPostProcessHandlers(vertex: VertexHandler, triangle?: TriangleHandler): ThreeMfMeshBuilder {\r\n this._vh = vertex;\r\n this._th = triangle;\r\n return this;\r\n }\r\n\r\n /**\r\n * Builds the mesh content of the object from the provided vertex data.\r\n * @param data The positions and indices used to generate the mesh.\r\n * @returns This builder, to allow chaining.\r\n */\r\n withData(data: I3mfVertexData): ThreeMfMeshBuilder {\r\n this._object.content = this._buildMesh(data);\r\n return this;\r\n }\r\n\r\n /**\r\n * Assigns the material used by the mesh.\r\n * @param id The resource id of the base materials group.\r\n * @param i The zero based index of the material within the group.\r\n * @returns This builder, to allow chaining.\r\n */\r\n withMaterial(id: ST_ResourceID, i: number): ThreeMfMeshBuilder {\r\n this._object.pid = id;\r\n this._object.pindex = i;\r\n return this;\r\n }\r\n\r\n /**\r\n * Converts vertex data into a 3MF mesh.\r\n * @param data The positions and indices used to generate the mesh.\r\n * @returns The generated 3MF mesh.\r\n */\r\n private _buildMesh(data: I3mfVertexData): I3mfMesh {\r\n const vertices = this._buildVertices(data.positions);\r\n const triangles = this._buildTriangle(data.indices);\r\n return new ThreeMfMesh(vertices, triangles);\r\n }\r\n\r\n /**\r\n * Converts a flat position array into a 3MF vertex list, applying the vertex handler when one is registered.\r\n * @param p The flat array of x, y and z positions.\r\n * @returns The generated 3MF vertex list.\r\n */\r\n private _buildVertices(p: ThreeMfFloatArray | null): I3mfVertices {\r\n const container = new ThreeMfVertices();\r\n if (p) {\r\n for (let i = 0; i < p.length;) {\r\n const x = p[i++];\r\n const y = p[i++];\r\n const z = p[i++];\r\n let v = new ThreeMfVertex(x, y, z);\r\n // might be optimized....\r\n if (this._vh) {\r\n v = this._vh(v);\r\n }\r\n container.vertex.push(v);\r\n }\r\n }\r\n return container;\r\n }\r\n\r\n /**\r\n * Converts a flat index array into a 3MF triangle list, applying the triangle handler when one is registered.\r\n * @param indice The flat array of vertex indices, three per triangle.\r\n * @returns The generated 3MF triangle list.\r\n */\r\n private _buildTriangle(indice: ThreeMfIndicesArray | null): I3mfTriangles {\r\n const container = new ThreeMfTriangles();\r\n if (indice) {\r\n for (let i = 0; i < indice.length;) {\r\n const a = indice[i++];\r\n const b = indice[i++];\r\n const c = indice[i++];\r\n let t = new ThreeMfTriangle(a, b, c);\r\n // might be optimized....\r\n if (this._th) {\r\n t = this._th(t);\r\n }\r\n container.triangle.push(t);\r\n }\r\n }\r\n return container;\r\n }\r\n}\r\n\r\n/**\r\n * Fluent builder for a 3MF base materials resource.\r\n * Colors are stored as sRGB hexadecimal strings as required by the 3MF specification.\r\n */\r\nexport class ThreeMfMaterialBuilder {\r\n private _m: I3mfBaseMaterials;\r\n\r\n /**\r\n * Creates a new base materials builder.\r\n * @param id The unique resource id of the base materials group within the model.\r\n */\r\n public constructor(id: ST_ResourceID) {\r\n this._m = new ThreeMfBaseMaterials(id);\r\n }\r\n\r\n /**\r\n * Adds a named color to the group, or updates it when the name already exists.\r\n * @param name The name of the material. The lookup is case insensitive.\r\n * @param color The linear RGBA color, converted to an sRGB hexadecimal string.\r\n * @returns This builder, to allow chaining.\r\n */\r\n public withColor(name: string, color: I3mfRGBAColor): ThreeMfMaterialBuilder {\r\n this._m.base = this._m.base ?? [];\r\n let m = this._m.base.find((m) => m.name.toLowerCase() === name.toLowerCase());\r\n if (m) {\r\n m.displaycolor = this._rgbaToHex(color);\r\n return this;\r\n }\r\n m = new ThreeMfBase(name, this._rgbaToHex(color));\r\n this._m.base.push(m);\r\n return this;\r\n }\r\n\r\n /**\r\n * Returns the base materials group that has been built.\r\n * @returns The built base materials resource.\r\n */\r\n public build(): I3mfBaseMaterials {\r\n return this._m;\r\n }\r\n\r\n /**\r\n * Converts a linear color into the sRGB hexadecimal string used by 3MF.\r\n * @param c The linear color to convert. The alpha channel is optional.\r\n * @returns The color as `#RRGGBB`, or `#RRGGBBAA` when an alpha channel is provided.\r\n */\r\n private _rgbaToHex(c: I3mfRGBAColor | { r: number; g: number; b: number; a?: number }): string {\r\n const toSRGB = (c: number) => Math.round(Math.min(255, Math.max(0, Math.pow(c, 1 / 2.2) * 255)));\r\n\r\n const r = toSRGB(c.r).toString(16).padStart(2, \"0\").toUpperCase();\r\n const g = toSRGB(c.g).toString(16).padStart(2, \"0\").toUpperCase();\r\n const b = toSRGB(c.b).toString(16).padStart(2, \"0\").toUpperCase();\r\n\r\n if (typeof (c as any).a === \"number\") {\r\n const a = Math.round(Math.min(255, Math.max(0, c.a! * 255)))\r\n .toString(16)\r\n .padStart(2, \"0\")\r\n .toUpperCase();\r\n return `#${r}${g}${b}${a}`;\r\n }\r\n\r\n return `#${r}${g}${b}`;\r\n }\r\n}\r\n\r\n/**\r\n * Fluent builder for a 3MF model, the root part of a 3MF document.\r\n * It aggregates the resources (materials, meshes and components) and the build items that reference them.\r\n */\r\nexport class ThreeMfModelBuilder {\r\n /**\r\n * The lower cased set of the metadata names defined by the 3MF specification.\r\n */\r\n static KnownMetaSet = new Set(ThreeMfModel.KnownMeta.map((m) => m.toLowerCase()));\r\n\r\n /**\r\n * The 3MF model currently being built.\r\n */\r\n _model: ThreeMfModel = new ThreeMfModel();\r\n /**\r\n * The object resources added to the model, indexed by resource id.\r\n */\r\n _objects = new Map<string, I3mfObject>();\r\n\r\n /**\r\n * Adds a metadata entry to the model.\r\n * @param name The metadata name. Names outside of the 3MF specification must be namespace qualified.\r\n * @param value The metadata value.\r\n * @param preserve Whether consumers must preserve this entry when editing the document.\r\n * @param type The XML schema type of the value. Defaults to `xs:string`.\r\n * @returns This builder, to allow chaining.\r\n */\r\n public withMetaData(name: string, value: string, preserve?: boolean, type?: string): ThreeMfModelBuilder {\r\n if (!this._model.metadata) {\r\n // lazzy\r\n this._model.metadata = new Array<I3mfMetadata>();\r\n }\r\n //const isKnownMeta = (s: string): boolean => TMFBuilder.knownMetaSet.has(s.toLowerCase());\r\n //const qn:IQName = xmlNameToParts(name);\r\n this._model.metadata.push(new ThreeMfMeta(name, value, preserve, type));\r\n return this;\r\n }\r\n\r\n /**\r\n * Adds a base materials group to the model resources.\r\n * @param material The base materials resource, or a builder that produces one.\r\n * @returns This builder, to allow chaining.\r\n */\r\n public withMaterial(material: I3mfBaseMaterials | ThreeMfMaterialBuilder): ThreeMfModelBuilder {\r\n if (material instanceof ThreeMfMaterialBuilder) {\r\n material = material.build();\r\n }\r\n if (material) {\r\n this._model.resources = this._model.resources ?? new ThreeMfResources();\r\n this._model.resources.basematerials = this._model.resources.basematerials ?? [];\r\n this._model.resources.basematerials.push(material);\r\n }\r\n return this;\r\n }\r\n\r\n /**\r\n * Adds a mesh object to the model resources.\r\n * @param object The object resource, or a builder that produces one.\r\n * @returns This builder, to allow chaining.\r\n */\r\n public withMesh(object: I3mfObject | ThreeMfMeshBuilder): ThreeMfModelBuilder {\r\n if (object instanceof ThreeMfMeshBuilder) {\r\n object = object.build();\r\n }\r\n this._model.resources = this._model.resources ?? new ThreeMfResources();\r\n this._model.resources.object.push(object);\r\n return this;\r\n }\r\n\r\n /**\r\n * Adds a components object to the model resources.\r\n * @param components The object resource, or a builder that produces one.\r\n * @returns This builder, to allow chaining.\r\n */\r\n public withComponents(components: I3mfObject | ThreeMfComponentsBuilder): ThreeMfModelBuilder {\r\n if (components instanceof ThreeMfComponentsBuilder) {\r\n components = components.build();\r\n }\r\n this._model.resources = this._model.resources ?? new ThreeMfResources();\r\n this._model.resources.object.push(components);\r\n return this;\r\n }\r\n\r\n /**\r\n * Adds a build item, which places an object resource in the build plate.\r\n * @param objectid The resource id of the object to place.\r\n * @param transform The optional transform applied to the object.\r\n * @param partnumber The optional part number identifying the produced part.\r\n * @returns This builder, to allow chaining.\r\n */\r\n public withBuild(objectid: ST_ResourceID, transform?: Matrix3d, partnumber?: string): ThreeMfModelBuilder {\r\n this._model.build = this._model.build ?? new ThreeMfBuild();\r\n this._model.build.item?.push(new ThreeMfItem(objectid, transform, partnumber));\r\n return this;\r\n }\r\n\r\n /**\r\n * Sets the unit in which the model coordinates are expressed.\r\n * @param unit The 3MF unit (micron, millimeter, centimeter, inch, foot or meter).\r\n * @returns This builder, to allow chaining.\r\n */\r\n public withUnit(unit: ST_Unit): ThreeMfModelBuilder {\r\n this._model.unit = unit;\r\n return this;\r\n }\r\n\r\n /**\r\n * Discards the current model and starts building a new one.\r\n * @returns This builder, to allow chaining.\r\n */\r\n public reset(): ThreeMfModelBuilder {\r\n this._model = new ThreeMfModel();\r\n this._objects = new Map<string, I3mfObject>();\r\n return this;\r\n }\r\n\r\n /**\r\n * Validates and returns the model that has been built.\r\n * @returns The built 3MF model.\r\n * @throws When the model has no object resource or no build item.\r\n */\r\n public build(): ThreeMfModel {\r\n // quick surface check..\r\n if (!this._model.resources?.object?.length) {\r\n throw new Error(\"Invalid state: resources MUST be defined \");\r\n }\r\n if (!this._model.build?.item?.length) {\r\n throw new Error(\"Invalid state: Build MUST be defined \");\r\n }\r\n return this._model;\r\n }\r\n}\r\n\r\n/**\r\n * Fluent builder for a 3MF document, the OPC package that wraps the model.\r\n * It gathers the content types, the relationships and the model part.\r\n */\r\nexport class ThreeMfDocumentBuilder {\r\n private _cts?: I3mfContentTypes;\r\n private _rs?: I3mfRelationships;\r\n private _m?: I3mfModel;\r\n\r\n /**\r\n * Declares an OPC content type. Duplicate declarations are ignored.\r\n * @param type The extension to content type mapping to declare.\r\n * @returns This builder, to allow chaining.\r\n */\r\n public withContentType(type: I3mfContentType): ThreeMfDocumentBuilder {\r\n if (!this._cts) {\r\n this._cts = new ThreeMfContentTypes();\r\n }\r\n const arr = this._cts.items;\r\n if (!arr.some((x) => x.ext === type.ext && x.ct === type.ct)) {\r\n arr.push(type);\r\n }\r\n return this;\r\n }\r\n\r\n /**\r\n * Adds an OPC relationship and ensures the relationships content type is declared.\r\n * Relationships with an already registered id are ignored.\r\n * @param rel The relationship to add.\r\n * @returns This builder, to allow chaining.\r\n */\r\n public withRelationship(rel: I3mfRelationship): ThreeMfDocumentBuilder {\r\n if (!this._rs) {\r\n this._rs = new ThreeMfRelationships();\r\n }\r\n const arr = this._rs.items;\r\n if (!arr.some((x) => x.id === rel.id)) {\r\n arr.push(rel);\r\n }\r\n // here we ensure that the content type is declared.\r\n this.withContentType(new ThreeMfContentType(\"rels\", KnownI3mfContentType.Relationships));\r\n return this;\r\n }\r\n\r\n /**\r\n * Sets the model part of the document and ensures the model content type is declared.\r\n * @param m The model resource, or a builder that produces one.\r\n * @returns This builder, to allow chaining.\r\n */\r\n public withModel(m: I3mfModel | ThreeMfModelBuilder): ThreeMfDocumentBuilder {\r\n if (m instanceof ThreeMfModelBuilder) {\r\n m = m.build();\r\n }\r\n this._m = m;\r\n // here we ensure that the content type is declared.\r\n this.withContentType(new ThreeMfContentType(\"model\", KnownI3mfContentType.Model));\r\n return this;\r\n }\r\n\r\n /**\r\n * Validates and returns the document that has been built.\r\n * A default relationship pointing at the model part is generated when none was provided.\r\n * @returns The built 3MF document.\r\n * @throws When no model has been set.\r\n */\r\n public build(): I3mfDocument {\r\n if (!this._m) {\r\n throw new Error(\"Invalid state: you Must provide at least a model.\");\r\n }\r\n\r\n // we automate the build of the relationship if not provided..\r\n const path = `${Object3dDirName}${ModelFileName}`;\r\n if (!this._rs) {\r\n const absolutePath = `/${path}`;\r\n this.withRelationship(new ThreeMfRelationship(`rel${0}`, Known3mfRelationshipTypes.ThreeDimModel, absolutePath));\r\n }\r\n\r\n return new ThreeMfDocument(this._cts!, this._rs!, this._m);\r\n }\r\n}\r\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@babylonjs/serializers",
3
- "version": "9.18.1",
3
+ "version": "9.18.2",
4
4
  "main": "index.js",
5
5
  "module": "index.js",
6
6
  "types": "index.d.ts",
@@ -18,10 +18,10 @@
18
18
  "postcompile": "build-tools -c add-js-to-es6"
19
19
  },
20
20
  "devDependencies": {
21
- "@babylonjs/core": "9.18.1",
21
+ "@babylonjs/core": "9.18.2",
22
22
  "@dev/build-tools": "^1.0.0",
23
23
  "@dev/serializers": "^1.0.0",
24
- "babylonjs-gltf2interface": "9.18.1"
24
+ "babylonjs-gltf2interface": "9.18.2"
25
25
  },
26
26
  "peerDependencies": {
27
27
  "@babylonjs/core": "^9.0.0",