@code3d/core 0.0.1-alpha.0
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.
- package/LICENSE +22 -0
- package/README.md +824 -0
- package/THIRD_PARTY.md +28 -0
- package/bld/library/alignment-geometry.d.ts +50 -0
- package/bld/library/alignment-geometry.d.ts.map +1 -0
- package/bld/library/alignment-geometry.js +322 -0
- package/bld/library/alignment-geometry.js.map +1 -0
- package/bld/library/bound-solver.d.ts +33 -0
- package/bld/library/bound-solver.d.ts.map +1 -0
- package/bld/library/bound-solver.js +252 -0
- package/bld/library/bound-solver.js.map +1 -0
- package/bld/library/extrude.d.ts +8 -0
- package/bld/library/extrude.d.ts.map +1 -0
- package/bld/library/extrude.js +28 -0
- package/bld/library/extrude.js.map +1 -0
- package/bld/library/index.d.ts +7 -0
- package/bld/library/index.d.ts.map +1 -0
- package/bld/library/index.js +3 -0
- package/bld/library/index.js.map +1 -0
- package/bld/library/kernel-artifact-codec.d.ts +3 -0
- package/bld/library/kernel-artifact-codec.d.ts.map +1 -0
- package/bld/library/kernel-artifact-codec.js +148 -0
- package/bld/library/kernel-artifact-codec.js.map +1 -0
- package/bld/library/kernel-cache.d.ts +63 -0
- package/bld/library/kernel-cache.d.ts.map +1 -0
- package/bld/library/kernel-cache.js +245 -0
- package/bld/library/kernel-cache.js.map +1 -0
- package/bld/library/kernel-shapes.d.ts +20 -0
- package/bld/library/kernel-shapes.d.ts.map +1 -0
- package/bld/library/kernel-shapes.js +108 -0
- package/bld/library/kernel-shapes.js.map +1 -0
- package/bld/library/loft.d.ts +7 -0
- package/bld/library/loft.d.ts.map +1 -0
- package/bld/library/loft.js +161 -0
- package/bld/library/loft.js.map +1 -0
- package/bld/library/material.d.ts +12 -0
- package/bld/library/material.d.ts.map +1 -0
- package/bld/library/material.js +176 -0
- package/bld/library/material.js.map +1 -0
- package/bld/library/model-color.d.ts +8 -0
- package/bld/library/model-color.d.ts.map +1 -0
- package/bld/library/model-color.js +36 -0
- package/bld/library/model-color.js.map +1 -0
- package/bld/library/open-cascade-error.d.ts +2 -0
- package/bld/library/open-cascade-error.d.ts.map +1 -0
- package/bld/library/open-cascade-error.js +22 -0
- package/bld/library/open-cascade-error.js.map +1 -0
- package/bld/library/relation-solver.d.ts +29 -0
- package/bld/library/relation-solver.d.ts.map +1 -0
- package/bld/library/relation-solver.js +258 -0
- package/bld/library/relation-solver.js.map +1 -0
- package/bld/library/replicad.d.ts +17 -0
- package/bld/library/replicad.d.ts.map +1 -0
- package/bld/library/replicad.js +24 -0
- package/bld/library/replicad.js.map +1 -0
- package/bld/library/retained-memory.d.ts +7 -0
- package/bld/library/retained-memory.d.ts.map +1 -0
- package/bld/library/retained-memory.js +27 -0
- package/bld/library/retained-memory.js.map +1 -0
- package/bld/library/runtime.d.ts +775 -0
- package/bld/library/runtime.d.ts.map +1 -0
- package/bld/library/runtime.js +2954 -0
- package/bld/library/runtime.js.map +1 -0
- package/bld/library/shell.d.ts +7 -0
- package/bld/library/shell.d.ts.map +1 -0
- package/bld/library/shell.js +221 -0
- package/bld/library/shell.js.map +1 -0
- package/bld/library/sketch-curve-intersections.d.ts +13 -0
- package/bld/library/sketch-curve-intersections.d.ts.map +1 -0
- package/bld/library/sketch-curve-intersections.js +117 -0
- package/bld/library/sketch-curve-intersections.js.map +1 -0
- package/bld/library/sketch-curves.d.ts +31 -0
- package/bld/library/sketch-curves.d.ts.map +1 -0
- package/bld/library/sketch-curves.js +89 -0
- package/bld/library/sketch-curves.js.map +1 -0
- package/bld/library/sketch-drag-rules.d.ts +35 -0
- package/bld/library/sketch-drag-rules.d.ts.map +1 -0
- package/bld/library/sketch-drag-rules.js +522 -0
- package/bld/library/sketch-drag-rules.js.map +1 -0
- package/bld/library/sketch-face.d.ts +4 -0
- package/bld/library/sketch-face.d.ts.map +1 -0
- package/bld/library/sketch-face.js +72 -0
- package/bld/library/sketch-face.js.map +1 -0
- package/bld/library/sketch-incidence.d.ts +26 -0
- package/bld/library/sketch-incidence.d.ts.map +1 -0
- package/bld/library/sketch-incidence.js +114 -0
- package/bld/library/sketch-incidence.js.map +1 -0
- package/bld/library/sketch-precision.d.ts +19 -0
- package/bld/library/sketch-precision.d.ts.map +1 -0
- package/bld/library/sketch-precision.js +55 -0
- package/bld/library/sketch-precision.js.map +1 -0
- package/bld/library/sketch-regions.d.ts +12 -0
- package/bld/library/sketch-regions.d.ts.map +1 -0
- package/bld/library/sketch-regions.js +193 -0
- package/bld/library/sketch-regions.js.map +1 -0
- package/bld/library/sketch-solver.d.ts +97 -0
- package/bld/library/sketch-solver.d.ts.map +1 -0
- package/bld/library/sketch-solver.js +578 -0
- package/bld/library/sketch-solver.js.map +1 -0
- package/bld/library/sketch.d.ts +142 -0
- package/bld/library/sketch.d.ts.map +1 -0
- package/bld/library/sketch.js +650 -0
- package/bld/library/sketch.js.map +1 -0
- package/bld/library/spatial.d.ts +28 -0
- package/bld/library/spatial.d.ts.map +1 -0
- package/bld/library/spatial.js +195 -0
- package/bld/library/spatial.js.map +1 -0
- package/bld/library/three.d.ts +3 -0
- package/bld/library/three.d.ts.map +1 -0
- package/bld/library/three.js +3 -0
- package/bld/library/three.js.map +1 -0
- package/bld/library/topology-id.d.ts +24 -0
- package/bld/library/topology-id.d.ts.map +1 -0
- package/bld/library/topology-id.js +67 -0
- package/bld/library/topology-id.js.map +1 -0
- package/bld/library/topology-inspection.d.ts +64 -0
- package/bld/library/topology-inspection.d.ts.map +1 -0
- package/bld/library/topology-inspection.js +267 -0
- package/bld/library/topology-inspection.js.map +1 -0
- package/bld/library/topology.d.ts +94 -0
- package/bld/library/topology.d.ts.map +1 -0
- package/bld/library/topology.js +455 -0
- package/bld/library/topology.js.map +1 -0
- package/bld/node/index.d.ts +2 -0
- package/bld/node/index.d.ts.map +1 -0
- package/bld/node/index.js +14 -0
- package/bld/node/index.js.map +1 -0
- package/bld/node/replicad.d.ts +3 -0
- package/bld/node/replicad.d.ts.map +1 -0
- package/bld/node/replicad.js +3 -0
- package/bld/node/replicad.js.map +1 -0
- package/bld/tooling/index.d.ts +26 -0
- package/bld/tooling/index.d.ts.map +1 -0
- package/bld/tooling/index.js +19 -0
- package/bld/tooling/index.js.map +1 -0
- package/package.json +53 -0
- package/src/library/alignment-geometry.ts +431 -0
- package/src/library/bound-solver.ts +410 -0
- package/src/library/extrude.ts +38 -0
- package/src/library/index.ts +88 -0
- package/src/library/kernel-artifact-codec.ts +166 -0
- package/src/library/kernel-cache.ts +337 -0
- package/src/library/kernel-shapes.ts +135 -0
- package/src/library/loft.ts +196 -0
- package/src/library/material.ts +228 -0
- package/src/library/model-color.ts +47 -0
- package/src/library/open-cascade-error.ts +26 -0
- package/src/library/relation-solver.ts +479 -0
- package/src/library/replicad.ts +40 -0
- package/src/library/retained-memory.ts +23 -0
- package/src/library/runtime.ts +5146 -0
- package/src/library/shell.ts +281 -0
- package/src/library/sketch-curve-intersections.ts +154 -0
- package/src/library/sketch-curves.ts +161 -0
- package/src/library/sketch-drag-rules.ts +767 -0
- package/src/library/sketch-face.ts +89 -0
- package/src/library/sketch-incidence.ts +204 -0
- package/src/library/sketch-precision.ts +81 -0
- package/src/library/sketch-regions.ts +271 -0
- package/src/library/sketch-solver.ts +973 -0
- package/src/library/sketch.ts +977 -0
- package/src/library/spatial.ts +254 -0
- package/src/library/three.ts +2 -0
- package/src/library/topology-id.ts +81 -0
- package/src/library/topology-inspection.ts +368 -0
- package/src/library/topology.ts +776 -0
- package/src/library/tsconfig.json +11 -0
- package/src/node/index.ts +20 -0
- package/src/node/replicad.ts +3 -0
- package/src/node/tsconfig.json +16 -0
- package/src/tooling/index.ts +160 -0
- package/src/tooling/tsconfig.json +15 -0
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Material,
|
|
3
|
+
MaterialLoader,
|
|
4
|
+
type JSONMeta,
|
|
5
|
+
type MaterialJSON,
|
|
6
|
+
type SerializedImage,
|
|
7
|
+
type Texture,
|
|
8
|
+
type TypedArray,
|
|
9
|
+
} from './three.js';
|
|
10
|
+
import {parseModelColor} from './model-color.js';
|
|
11
|
+
|
|
12
|
+
/** A color selects the default material for each geometry kind. */
|
|
13
|
+
export type ModelMaterialSnapshot = string | Readonly<MaterialJSON>;
|
|
14
|
+
|
|
15
|
+
/** Capture the authored value before mutable Three.js instances can change. */
|
|
16
|
+
export function captureModelMaterial(
|
|
17
|
+
input: Material | string,
|
|
18
|
+
): ModelMaterialSnapshot {
|
|
19
|
+
if (typeof input === 'string') {
|
|
20
|
+
parseModelColor(input);
|
|
21
|
+
return input;
|
|
22
|
+
}
|
|
23
|
+
const restored = MaterialLoader.createMaterialFromType(input.type);
|
|
24
|
+
if (
|
|
25
|
+
restored.type !== input.type ||
|
|
26
|
+
restored.constructor !== input.constructor
|
|
27
|
+
) {
|
|
28
|
+
throw new Error(
|
|
29
|
+
`material() cannot restore the Three.js material type ${JSON.stringify(input.type)}. Import native material classes from @code3d/core/three; custom classes and separate Three.js instances are not supported.`,
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
if (
|
|
33
|
+
input.onBeforeCompile !== Material.prototype.onBeforeCompile ||
|
|
34
|
+
input.onBeforeRender !== Material.prototype.onBeforeRender ||
|
|
35
|
+
input.customProgramCacheKey !== Material.prototype.customProgramCacheKey
|
|
36
|
+
) {
|
|
37
|
+
throw new Error(
|
|
38
|
+
'material() cannot transfer custom material callbacks between the modeling worker and viewport. Use a serializable Three.js material.',
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
for (const field of [
|
|
42
|
+
'clippingPlanes',
|
|
43
|
+
'clipIntersection',
|
|
44
|
+
'clipShadows',
|
|
45
|
+
'shadowSide',
|
|
46
|
+
'precision',
|
|
47
|
+
] as const) {
|
|
48
|
+
if (input[field] !== restored[field]) {
|
|
49
|
+
throw new Error(
|
|
50
|
+
`material() cannot capture ${field}: Three.js material JSON does not serialize this property.`,
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
if ('isShaderMaterial' in input) {
|
|
55
|
+
const shader = input as import('./three.js').ShaderMaterial;
|
|
56
|
+
if (
|
|
57
|
+
shader.uniformsGroups.length ||
|
|
58
|
+
shader.index0AttributeName !== undefined ||
|
|
59
|
+
JSON.stringify(shader.defaultAttributeValues) !==
|
|
60
|
+
JSON.stringify(
|
|
61
|
+
(restored as import('./three.js').ShaderMaterial)
|
|
62
|
+
.defaultAttributeValues,
|
|
63
|
+
)
|
|
64
|
+
) {
|
|
65
|
+
throw new Error(
|
|
66
|
+
'material() cannot capture shader uniform groups, index0AttributeName or custom defaultAttributeValues through Three.js JSON.',
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
for (const {value} of Object.values(shader.uniforms)) {
|
|
70
|
+
// Native JSON handles these types only as direct uniform values.
|
|
71
|
+
if (
|
|
72
|
+
value &&
|
|
73
|
+
[
|
|
74
|
+
'isTexture',
|
|
75
|
+
'isColor',
|
|
76
|
+
'isVector2',
|
|
77
|
+
'isVector3',
|
|
78
|
+
'isVector4',
|
|
79
|
+
'isMatrix3',
|
|
80
|
+
'isMatrix4',
|
|
81
|
+
].some(flag => value[flag])
|
|
82
|
+
)
|
|
83
|
+
continue;
|
|
84
|
+
validatePlainUniform(value);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
restored.dispose();
|
|
88
|
+
|
|
89
|
+
const meta: JSONMeta = {
|
|
90
|
+
geometries: {},
|
|
91
|
+
materials: {},
|
|
92
|
+
textures: {},
|
|
93
|
+
images: {},
|
|
94
|
+
shapes: {},
|
|
95
|
+
skeletons: {},
|
|
96
|
+
animations: {},
|
|
97
|
+
nodes: {},
|
|
98
|
+
};
|
|
99
|
+
for (const texture of materialTextures(input)) {
|
|
100
|
+
if (
|
|
101
|
+
texture.isRenderTargetTexture ||
|
|
102
|
+
texture.mipmaps.length ||
|
|
103
|
+
'isVideoTexture' in texture ||
|
|
104
|
+
'isCompressedTexture' in texture ||
|
|
105
|
+
'isData3DTexture' in texture ||
|
|
106
|
+
'isDataArrayTexture' in texture
|
|
107
|
+
) {
|
|
108
|
+
throw new Error(
|
|
109
|
+
'material() supports loaded image, data and cube textures; live, render-target, compressed and layered textures cannot be captured.',
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
const source = texture.source;
|
|
113
|
+
meta.images[source.uuid] = {
|
|
114
|
+
uuid: source.uuid,
|
|
115
|
+
url: Array.isArray(source.data)
|
|
116
|
+
? source.data.map(image =>
|
|
117
|
+
captureImage(image.isDataTexture ? image.image : image),
|
|
118
|
+
)
|
|
119
|
+
: captureImage(source.data),
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
const data = input.toJSON(meta);
|
|
123
|
+
const textures = Object.values(meta.textures);
|
|
124
|
+
const images = Object.values(meta.images);
|
|
125
|
+
if (textures.length) data.textures = textures as MaterialJSON['textures'];
|
|
126
|
+
if (images.length) data.images = images as MaterialJSON['images'];
|
|
127
|
+
// Three.js JSON may still reference userData or shader uniform arrays.
|
|
128
|
+
return JSON.parse(
|
|
129
|
+
JSON.stringify(data, (_key, value: unknown) => {
|
|
130
|
+
if (
|
|
131
|
+
typeof value === 'function' ||
|
|
132
|
+
typeof value === 'symbol' ||
|
|
133
|
+
typeof value === 'bigint'
|
|
134
|
+
) {
|
|
135
|
+
throw new Error(
|
|
136
|
+
'material() requires serializable material data, including uniforms and userData.',
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
if (ArrayBuffer.isView(value) && !(value instanceof DataView))
|
|
140
|
+
return Array.from(value as TypedArray);
|
|
141
|
+
return value;
|
|
142
|
+
}),
|
|
143
|
+
) as MaterialJSON;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function validatePlainUniform(value: unknown): void {
|
|
147
|
+
if (!value || typeof value !== 'object' || ArrayBuffer.isView(value)) return;
|
|
148
|
+
if (
|
|
149
|
+
!Array.isArray(value) &&
|
|
150
|
+
Object.getPrototypeOf(value) !== Object.prototype
|
|
151
|
+
) {
|
|
152
|
+
throw new Error(
|
|
153
|
+
'material() requires shader uniform arrays and structs to contain plain values; Three.js JSON cannot restore nested native objects.',
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
for (const item of Object.values(value)) validatePlainUniform(item);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function* materialTextures(material: Material): Iterable<Texture> {
|
|
160
|
+
for (const value of Object.values(material)) {
|
|
161
|
+
if (value?.isTexture) yield value as Texture;
|
|
162
|
+
}
|
|
163
|
+
if ('uniforms' in material) {
|
|
164
|
+
const uniforms = material.uniforms as Record<string, {value: unknown}>;
|
|
165
|
+
for (const {value} of Object.values(uniforms)) {
|
|
166
|
+
for (const item of Array.isArray(value) ? value : [value]) {
|
|
167
|
+
if (item && typeof item === 'object' && 'isTexture' in item)
|
|
168
|
+
yield item as Texture;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function captureImage(image: Texture['image']): SerializedImage {
|
|
175
|
+
if (!image)
|
|
176
|
+
throw new Error(
|
|
177
|
+
'material() requires textures to finish loading before assignment.',
|
|
178
|
+
);
|
|
179
|
+
if (typeof image === 'object' && 'data' in image) {
|
|
180
|
+
const pixels = image as {data: TypedArray; width: number; height: number};
|
|
181
|
+
if (!pixels.data || !(pixels.width > 0 && pixels.height > 0))
|
|
182
|
+
throw new Error('material() requires a loaded texture image.');
|
|
183
|
+
return {
|
|
184
|
+
data: Array.from(pixels.data),
|
|
185
|
+
width: pixels.width,
|
|
186
|
+
height: pixels.height,
|
|
187
|
+
type: pixels.data.constructor.name,
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
const source = image as
|
|
191
|
+
HTMLImageElement | HTMLCanvasElement | ImageBitmap | OffscreenCanvas;
|
|
192
|
+
const width = 'naturalWidth' in source ? source.naturalWidth : source.width;
|
|
193
|
+
const height =
|
|
194
|
+
'naturalHeight' in source ? source.naturalHeight : source.height;
|
|
195
|
+
if (!(width > 0 && height > 0))
|
|
196
|
+
throw new Error('material() requires a loaded texture image.');
|
|
197
|
+
const canvas =
|
|
198
|
+
typeof OffscreenCanvas !== 'undefined'
|
|
199
|
+
? new OffscreenCanvas(width, height)
|
|
200
|
+
: document.createElement('canvas');
|
|
201
|
+
canvas.width = width;
|
|
202
|
+
canvas.height = height;
|
|
203
|
+
const context = canvas.getContext('2d') as
|
|
204
|
+
CanvasRenderingContext2D | OffscreenCanvasRenderingContext2D;
|
|
205
|
+
context.drawImage(source, 0, 0);
|
|
206
|
+
return {
|
|
207
|
+
data: Array.from(context.getImageData(0, 0, width, height).data),
|
|
208
|
+
width,
|
|
209
|
+
height,
|
|
210
|
+
type: 'Uint8Array',
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/** Base color for CAD formats that cannot encode a complete rendering material. */
|
|
215
|
+
export function modelMaterialColor(snapshot: ModelMaterialSnapshot) {
|
|
216
|
+
if (typeof snapshot === 'string') return parseModelColor(snapshot);
|
|
217
|
+
if (snapshot.color === undefined) return undefined;
|
|
218
|
+
const rgb = '#' + snapshot.color.toString(16).padStart(6, '0');
|
|
219
|
+
const alpha = snapshot.transparent ? (snapshot.opacity ?? 1) : 1;
|
|
220
|
+
const hex =
|
|
221
|
+
alpha === 1
|
|
222
|
+
? rgb
|
|
223
|
+
: rgb +
|
|
224
|
+
Math.round(alpha * 255)
|
|
225
|
+
.toString(16)
|
|
226
|
+
.padStart(2, '0');
|
|
227
|
+
return {rgb, alpha, hex};
|
|
228
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import {TinyColor} from '@ctrl/tinycolor';
|
|
2
|
+
|
|
3
|
+
export type ModelColor = Readonly<{
|
|
4
|
+
rgb: string;
|
|
5
|
+
alpha: number;
|
|
6
|
+
hex: string;
|
|
7
|
+
}>;
|
|
8
|
+
|
|
9
|
+
/** Resolve authored colors identically for previews and exported materials. */
|
|
10
|
+
export function parseModelColor(input: string): ModelColor {
|
|
11
|
+
const invalid = () =>
|
|
12
|
+
new Error(`Invalid material color: ${JSON.stringify(input)}`);
|
|
13
|
+
const rgb = /^rgba?\((.*)\)$/is.exec(input.trim());
|
|
14
|
+
let color: TinyColor;
|
|
15
|
+
if (rgb) {
|
|
16
|
+
// TinyColor's legacy function parser ignores slash alpha and alpha percentages.
|
|
17
|
+
const channels = rgb[1].trim().split(/[\s,/]+/);
|
|
18
|
+
if (
|
|
19
|
+
(channels.length !== 3 && channels.length !== 4) ||
|
|
20
|
+
channels.some(
|
|
21
|
+
channel =>
|
|
22
|
+
!/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?%?$/i.test(channel),
|
|
23
|
+
)
|
|
24
|
+
)
|
|
25
|
+
throw invalid();
|
|
26
|
+
const component = (value: string, scale: number): number =>
|
|
27
|
+
value.endsWith('%')
|
|
28
|
+
? (parseFloat(value) / 100) * scale
|
|
29
|
+
: parseFloat(value);
|
|
30
|
+
const alpha = channels[3] === undefined ? 1 : component(channels[3], 1);
|
|
31
|
+
color = new TinyColor({
|
|
32
|
+
r: component(channels[0], 255),
|
|
33
|
+
g: component(channels[1], 255),
|
|
34
|
+
b: component(channels[2], 255),
|
|
35
|
+
a: Math.max(0, Math.min(1, alpha)),
|
|
36
|
+
});
|
|
37
|
+
} else {
|
|
38
|
+
color = new TinyColor(input);
|
|
39
|
+
}
|
|
40
|
+
if (!color.isValid) throw invalid();
|
|
41
|
+
const alpha = color.getAlpha();
|
|
42
|
+
return {
|
|
43
|
+
rgb: color.toHexString(),
|
|
44
|
+
alpha,
|
|
45
|
+
hex: alpha === 1 ? color.toHexString() : color.toHex8String(),
|
|
46
|
+
};
|
|
47
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import {getOC} from 'replicad';
|
|
2
|
+
|
|
3
|
+
export function describeOpenCascadeException(
|
|
4
|
+
error: unknown,
|
|
5
|
+
): string | undefined {
|
|
6
|
+
if (
|
|
7
|
+
typeof WebAssembly === 'undefined' ||
|
|
8
|
+
typeof WebAssembly.Exception !== 'function' ||
|
|
9
|
+
!(error instanceof WebAssembly.Exception)
|
|
10
|
+
) {
|
|
11
|
+
return undefined;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
try {
|
|
15
|
+
const [name, message] = getOC().getExceptionMessage(error);
|
|
16
|
+
const description = [name, message]
|
|
17
|
+
.map(part => part?.trim())
|
|
18
|
+
.filter((part, index, parts) => part && parts.indexOf(part) === index)
|
|
19
|
+
.join(': ');
|
|
20
|
+
return description
|
|
21
|
+
? `OpenCascade error (${description})`
|
|
22
|
+
: 'OpenCascade operation failed.';
|
|
23
|
+
} catch {
|
|
24
|
+
return 'OpenCascade operation failed.';
|
|
25
|
+
}
|
|
26
|
+
}
|