@file-viewer/geometry-engine 2.0.11
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 +160 -0
- package/README.en.md +24 -0
- package/README.md +24 -0
- package/dist/index.d.ts +36 -0
- package/dist/index.js +194 -0
- package/package.json +67 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction, and
|
|
10
|
+
distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by the copyright
|
|
13
|
+
owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all other entities
|
|
16
|
+
that control, are controlled by, or are under common control with that entity.
|
|
17
|
+
For the purposes of this definition, "control" means (i) the power, direct or
|
|
18
|
+
indirect, to cause the direction or management of such entity, whether by
|
|
19
|
+
contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
20
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
21
|
+
|
|
22
|
+
"You" (or "Your") shall mean an individual or Legal Entity exercising
|
|
23
|
+
permissions granted by this License.
|
|
24
|
+
|
|
25
|
+
"Source" form shall mean the preferred form for making modifications, including
|
|
26
|
+
but not limited to software source code, documentation source, and configuration
|
|
27
|
+
files.
|
|
28
|
+
|
|
29
|
+
"Object" form shall mean any form resulting from mechanical transformation or
|
|
30
|
+
translation of a Source form, including but not limited to compiled object code,
|
|
31
|
+
generated documentation, and conversions to other media types.
|
|
32
|
+
|
|
33
|
+
"Work" shall mean the work of authorship, whether in Source or Object form,
|
|
34
|
+
made available under the License, as indicated by a copyright notice that is
|
|
35
|
+
included in or attached to the work.
|
|
36
|
+
|
|
37
|
+
"Derivative Works" shall mean any work, whether in Source or Object form, that
|
|
38
|
+
is based on (or derived from) the Work and for which the editorial revisions,
|
|
39
|
+
annotations, elaborations, or other modifications represent, as a whole, an
|
|
40
|
+
original work of authorship. For the purposes of this License, Derivative Works
|
|
41
|
+
shall not include works that remain separable from, or merely link (or bind by
|
|
42
|
+
name) to the interfaces of, the Work and Derivative Works thereof.
|
|
43
|
+
|
|
44
|
+
"Contribution" shall mean any work of authorship, including the original version
|
|
45
|
+
of the Work and any modifications or additions to that Work or Derivative Works
|
|
46
|
+
thereof, that is intentionally submitted to Licensor for inclusion in the Work by
|
|
47
|
+
the copyright owner or by an individual or Legal Entity authorized to submit on
|
|
48
|
+
behalf of the copyright owner. For the purposes of this definition, "submitted"
|
|
49
|
+
means any form of electronic, verbal, or written communication sent to the
|
|
50
|
+
Licensor or its representatives, including but not limited to communication on
|
|
51
|
+
electronic mailing lists, source code control systems, and issue tracking systems
|
|
52
|
+
that are managed by, or on behalf of, the Licensor for the purpose of discussing
|
|
53
|
+
and improving the Work, but excluding communication that is conspicuously marked
|
|
54
|
+
or otherwise designated in writing by the copyright owner as "Not a
|
|
55
|
+
Contribution."
|
|
56
|
+
|
|
57
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf
|
|
58
|
+
of whom a Contribution has been received by Licensor and subsequently
|
|
59
|
+
incorporated within the Work.
|
|
60
|
+
|
|
61
|
+
2. Grant of Copyright License. Subject to the terms and conditions of this
|
|
62
|
+
License, each Contributor hereby grants to You a perpetual, worldwide,
|
|
63
|
+
non-exclusive, no-charge, royalty-free, irrevocable copyright license to
|
|
64
|
+
reproduce, prepare Derivative Works of, publicly display, publicly perform,
|
|
65
|
+
sublicense, and distribute the Work and such Derivative Works in Source or
|
|
66
|
+
Object form.
|
|
67
|
+
|
|
68
|
+
3. Grant of Patent License. Subject to the terms and conditions of this License,
|
|
69
|
+
each Contributor hereby grants to You a perpetual, worldwide, non-exclusive,
|
|
70
|
+
no-charge, royalty-free, irrevocable (except as stated in this section) patent
|
|
71
|
+
license to make, have made, use, offer to sell, sell, import, and otherwise
|
|
72
|
+
transfer the Work, where such license applies only to those patent claims
|
|
73
|
+
licensable by such Contributor that are necessarily infringed by their
|
|
74
|
+
Contribution(s) alone or by combination of their Contribution(s) with the Work to
|
|
75
|
+
which such Contribution(s) was submitted. If You institute patent litigation
|
|
76
|
+
against any entity (including a cross-claim or counterclaim in a lawsuit)
|
|
77
|
+
alleging that the Work or a Contribution incorporated within the Work
|
|
78
|
+
constitutes direct or contributory patent infringement, then any patent licenses
|
|
79
|
+
granted to You under this License for that Work shall terminate as of the date
|
|
80
|
+
such litigation is filed.
|
|
81
|
+
|
|
82
|
+
4. Redistribution. You may reproduce and distribute copies of the Work or
|
|
83
|
+
Derivative Works thereof in any medium, with or without modifications, and in
|
|
84
|
+
Source or Object form, provided that You meet the following conditions:
|
|
85
|
+
|
|
86
|
+
(a) You must give any other recipients of the Work or Derivative Works a copy of
|
|
87
|
+
this License; and
|
|
88
|
+
|
|
89
|
+
(b) You must cause any modified files to carry prominent notices stating that
|
|
90
|
+
You changed the files; and
|
|
91
|
+
|
|
92
|
+
(c) You must retain, in the Source form of any Derivative Works that You
|
|
93
|
+
distribute, all copyright, patent, trademark, and attribution notices from the
|
|
94
|
+
Source form of the Work, excluding those notices that do not pertain to any part
|
|
95
|
+
of the Derivative Works; and
|
|
96
|
+
|
|
97
|
+
(d) If the Work includes a "NOTICE" text file as part of its distribution, then
|
|
98
|
+
any Derivative Works that You distribute must include a readable copy of the
|
|
99
|
+
attribution notices contained within such NOTICE file, excluding those notices
|
|
100
|
+
that do not pertain to any part of the Derivative Works, in at least one of the
|
|
101
|
+
following places: within a NOTICE text file distributed as part of the Derivative
|
|
102
|
+
Works; within the Source form or documentation, if provided along with the
|
|
103
|
+
Derivative Works; or, within a display generated by the Derivative Works, if and
|
|
104
|
+
wherever such third-party notices normally appear. The contents of the NOTICE
|
|
105
|
+
file are for informational purposes only and do not modify the License. You may
|
|
106
|
+
add Your own attribution notices within Derivative Works that You distribute,
|
|
107
|
+
alongside or as an addendum to the NOTICE text from the Work, provided that such
|
|
108
|
+
additional attribution notices cannot be construed as modifying the License.
|
|
109
|
+
|
|
110
|
+
You may add Your own copyright statement to Your modifications and may provide
|
|
111
|
+
additional or different license terms and conditions for use, reproduction, or
|
|
112
|
+
distribution of Your modifications, or for any such Derivative Works as a whole,
|
|
113
|
+
provided Your use, reproduction, and distribution of the Work otherwise complies
|
|
114
|
+
with the conditions stated in this License.
|
|
115
|
+
|
|
116
|
+
5. Submission of Contributions. Unless You explicitly state otherwise, any
|
|
117
|
+
Contribution intentionally submitted for inclusion in the Work by You to the
|
|
118
|
+
Licensor shall be under the terms and conditions of this License, without any
|
|
119
|
+
additional terms or conditions. Notwithstanding the above, nothing herein shall
|
|
120
|
+
supersede or modify the terms of any separate license agreement you may have
|
|
121
|
+
executed with Licensor regarding such Contributions.
|
|
122
|
+
|
|
123
|
+
6. Trademarks. This License does not grant permission to use the trade names,
|
|
124
|
+
trademarks, service marks, or product names of the Licensor, except as required
|
|
125
|
+
for reasonable and customary use in describing the origin of the Work and
|
|
126
|
+
reproducing the content of the NOTICE file.
|
|
127
|
+
|
|
128
|
+
7. Disclaimer of Warranty. Unless required by applicable law or agreed to in
|
|
129
|
+
writing, Licensor provides the Work (and each Contributor provides its
|
|
130
|
+
Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
131
|
+
KIND, either express or implied, including, without limitation, any warranties or
|
|
132
|
+
conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
133
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
134
|
+
appropriateness of using or redistributing the Work and assume any risks
|
|
135
|
+
associated with Your exercise of permissions under this License.
|
|
136
|
+
|
|
137
|
+
8. Limitation of Liability. In no event and under no legal theory, whether in
|
|
138
|
+
tort (including negligence), contract, or otherwise, unless required by
|
|
139
|
+
applicable law (such as deliberate and grossly negligent acts) or agreed to in
|
|
140
|
+
writing, shall any Contributor be liable to You for damages, including any
|
|
141
|
+
direct, indirect, special, incidental, or consequential damages of any character
|
|
142
|
+
arising as a result of this License or out of the use or inability to use the
|
|
143
|
+
Work (including but not limited to damages for loss of goodwill, work stoppage,
|
|
144
|
+
computer failure or malfunction, or any and all other commercial damages or
|
|
145
|
+
losses), even if such Contributor has been advised of the possibility of such
|
|
146
|
+
damages.
|
|
147
|
+
|
|
148
|
+
9. Accepting Warranty or Additional Liability. While redistributing the Work or
|
|
149
|
+
Derivative Works thereof, You may choose to offer, and charge a fee for,
|
|
150
|
+
acceptance of support, warranty, indemnity, or other liability obligations and/or
|
|
151
|
+
rights consistent with this License. However, in accepting such obligations, You
|
|
152
|
+
may act only on Your own behalf and on Your sole responsibility, not on behalf of
|
|
153
|
+
any other Contributor, and only if You agree to indemnify, defend, and hold each
|
|
154
|
+
Contributor harmless for any liability incurred by, or claims asserted against,
|
|
155
|
+
such Contributor by reason of your accepting any such warranty or additional
|
|
156
|
+
liability.
|
|
157
|
+
|
|
158
|
+
END OF TERMS AND CONDITIONS
|
|
159
|
+
|
|
160
|
+
Copyright 2026 Flyfish Viewer
|
package/README.en.md
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# @file-viewer/geometry-engine
|
|
2
|
+
|
|
3
|
+
Framework-neutral geometry-kernel boundary package for Flyfish File Viewer. It does not bundle heavy OpenCascade, web-ifc, or rhino3dm WASM runtimes by default. It currently provides STEP, IGES, IFC, 3DM, and BREP detection, signature inspection, recommended engine routes, and user-facing notices.
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
import {
|
|
7
|
+
inspectGeometryKernelFile,
|
|
8
|
+
formatGeometryKernelNotice,
|
|
9
|
+
} from '@file-viewer/geometry-engine'
|
|
10
|
+
|
|
11
|
+
const inspection = inspectGeometryKernelFile(new Uint8Array(buffer), 'step')
|
|
12
|
+
const notice = formatGeometryKernelNotice(inspection.format, 'en-US')
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Scope
|
|
16
|
+
|
|
17
|
+
- `inspectGeometryKernelFile()` reads a small file prefix and detects common STEP / IGES / IFC / 3DM / BREP signatures.
|
|
18
|
+
- `geometryKernelRoutes` documents the recommended WASM path: OpenCascade / OCCT for STEP, IGES, and BREP; `web-ifc` / That Open for IFC; McNeel `rhino3dm` for Rhino 3DM.
|
|
19
|
+
- `@file-viewer/renderer-3d` consumes this package for accurate conversion guidance without pulling CAD/BIM kernels into core or the default 3D install path.
|
|
20
|
+
- Full visual rendering can evolve here later, or split into focused packages such as `@file-viewer/geometry-occt`, `@file-viewer/geometry-ifc`, and `@file-viewer/geometry-3dm`.
|
|
21
|
+
|
|
22
|
+
## Why This Package Exists
|
|
23
|
+
|
|
24
|
+
STEP, IGES, IFC, and 3DM are not lightweight formats that ordinary Three.js loaders can faithfully decode. They need CAD/BIM kernels, worker isolation, WASM asset hosting, license review, and real-world sample regression. Keeping the boundary in a separate package lets `@file-viewer/core` stay fast to install while engineering-format fidelity can evolve independently, the same way the native PPTX engine does.
|
package/README.md
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# @file-viewer/geometry-engine
|
|
2
|
+
|
|
3
|
+
Flyfish File Viewer 的独立几何内核边界包。它不包含 UI,也不默认打包 OpenCascade、web-ifc 或 rhino3dm 这类重型 WASM 运行时;当前负责 STEP、IGES、IFC、3DM 和 BREP 的格式识别、文件头检查、推荐内核路线和对外提示文本。
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
import {
|
|
7
|
+
inspectGeometryKernelFile,
|
|
8
|
+
formatGeometryKernelNotice,
|
|
9
|
+
} from '@file-viewer/geometry-engine'
|
|
10
|
+
|
|
11
|
+
const inspection = inspectGeometryKernelFile(new Uint8Array(buffer), 'step')
|
|
12
|
+
const notice = formatGeometryKernelNotice(inspection.format)
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## 定位
|
|
16
|
+
|
|
17
|
+
- `inspectGeometryKernelFile()` 读取文件前缀,识别 STEP / IGES / IFC / 3DM / BREP 的常见签名。
|
|
18
|
+
- `geometryKernelRoutes` 明确每个格式的推荐 WASM 路线:STEP / IGES / BREP 走 OpenCascade / OCCT,IFC 走 `web-ifc` / That Open,3DM 走 McNeel `rhino3dm`。
|
|
19
|
+
- `@file-viewer/renderer-3d` 使用本包展示专业、准确的转换说明;core 和普通 3D 预览不会因此安装 CAD/BIM 几何内核。
|
|
20
|
+
- 后续完整可视渲染可以继续在这个包中分层演进,或拆出更细的 `@file-viewer/geometry-occt`、`@file-viewer/geometry-ifc`、`@file-viewer/geometry-3dm`。
|
|
21
|
+
|
|
22
|
+
## 为什么单独拆包
|
|
23
|
+
|
|
24
|
+
STEP、IGES、IFC 和 3DM 都不是普通 Three.js loader 可以完整还原的轻量格式。它们需要 CAD/BIM 专业内核、Worker 隔离、WASM 资产托管、许可证边界和真实样本长期回归。把这条路线单独固定下来,可以让 `@file-viewer/core` 保持快速安装,让工程格式能力像 PPTX 一样独立维护、独立发布。
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export type GeometryKernelFormat = 'step' | 'iges' | 'ifc' | '3dm' | 'brep';
|
|
2
|
+
export type GeometryKernelFamily = 'cad-brep' | 'bim-ifc' | 'rhino-3dm';
|
|
3
|
+
export type GeometryKernelOutput = 'three-object' | 'mesh' | 'fragments';
|
|
4
|
+
export type GeometryKernelConfidence = 'none' | 'low' | 'medium' | 'high';
|
|
5
|
+
export type GeometryKernelLocale = 'zh-CN' | 'en-US';
|
|
6
|
+
export interface GeometryKernelCapability {
|
|
7
|
+
readonly renderer: string;
|
|
8
|
+
readonly packageName: string;
|
|
9
|
+
readonly wasm: true;
|
|
10
|
+
readonly output: readonly GeometryKernelOutput[];
|
|
11
|
+
readonly note: string;
|
|
12
|
+
readonly url: string;
|
|
13
|
+
}
|
|
14
|
+
export interface GeometryKernelRoute {
|
|
15
|
+
readonly format: GeometryKernelFormat;
|
|
16
|
+
readonly aliases: readonly string[];
|
|
17
|
+
readonly label: string;
|
|
18
|
+
readonly family: GeometryKernelFamily;
|
|
19
|
+
readonly recommended: readonly GeometryKernelCapability[];
|
|
20
|
+
readonly serverConversionTargets: readonly string[];
|
|
21
|
+
readonly licenseNotes: readonly string[];
|
|
22
|
+
}
|
|
23
|
+
export interface GeometryKernelInspection {
|
|
24
|
+
readonly format?: GeometryKernelFormat;
|
|
25
|
+
readonly route?: GeometryKernelRoute;
|
|
26
|
+
readonly confidence: GeometryKernelConfidence;
|
|
27
|
+
readonly byteLength: number;
|
|
28
|
+
readonly signature?: string;
|
|
29
|
+
readonly warnings: readonly string[];
|
|
30
|
+
}
|
|
31
|
+
export declare const geometryKernelRoutes: readonly GeometryKernelRoute[];
|
|
32
|
+
export declare const normalizeGeometryKernelFormat: (type?: string) => GeometryKernelFormat | undefined;
|
|
33
|
+
export declare const getGeometryKernelRoute: (type?: string) => GeometryKernelRoute | undefined;
|
|
34
|
+
export declare const isGeometryKernelFormat: (type?: string) => boolean;
|
|
35
|
+
export declare const inspectGeometryKernelFile: (input: ArrayBuffer | Uint8Array, type?: string) => GeometryKernelInspection;
|
|
36
|
+
export declare const formatGeometryKernelNotice: (type?: string, locale?: GeometryKernelLocale) => string;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
const textDecoder = typeof TextDecoder === 'function'
|
|
2
|
+
? new TextDecoder('utf-8', { fatal: false })
|
|
3
|
+
: undefined;
|
|
4
|
+
const normalizeToken = (value) => {
|
|
5
|
+
return String(value || '')
|
|
6
|
+
.trim()
|
|
7
|
+
.toLowerCase()
|
|
8
|
+
.replace(/^\./, '')
|
|
9
|
+
.replace(/^model\//, '')
|
|
10
|
+
.replace(/^application\//, '')
|
|
11
|
+
.replace(/^x-/, '');
|
|
12
|
+
};
|
|
13
|
+
export const geometryKernelRoutes = [
|
|
14
|
+
{
|
|
15
|
+
format: 'step',
|
|
16
|
+
aliases: ['step', 'stp', 'p21', 'iso-10303-21'],
|
|
17
|
+
label: 'STEP / ISO 10303',
|
|
18
|
+
family: 'cad-brep',
|
|
19
|
+
recommended: [
|
|
20
|
+
{
|
|
21
|
+
renderer: 'OpenCascade / OCCT import',
|
|
22
|
+
packageName: 'occt-import-js',
|
|
23
|
+
wasm: true,
|
|
24
|
+
output: ['three-object', 'mesh'],
|
|
25
|
+
note: 'Imports STEP into mesh/JSON data in the browser; suitable as the first full preview path.',
|
|
26
|
+
url: 'https://github.com/kovacsv/occt-import-js',
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
renderer: 'OpenCascade.js',
|
|
30
|
+
packageName: 'opencascade.js',
|
|
31
|
+
wasm: true,
|
|
32
|
+
output: ['three-object', 'mesh'],
|
|
33
|
+
note: 'Full OpenCascade geometry kernel port for richer CAD workflows.',
|
|
34
|
+
url: 'https://ocjs.org/',
|
|
35
|
+
},
|
|
36
|
+
],
|
|
37
|
+
serverConversionTargets: ['glb', 'gltf', 'stl', 'obj'],
|
|
38
|
+
licenseNotes: ['OCCT-based packages can have LGPL or custom distribution requirements; keep them opt-in.'],
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
format: 'iges',
|
|
42
|
+
aliases: ['iges', 'igs'],
|
|
43
|
+
label: 'IGES',
|
|
44
|
+
family: 'cad-brep',
|
|
45
|
+
recommended: [
|
|
46
|
+
{
|
|
47
|
+
renderer: 'OpenCascade / OCCT import',
|
|
48
|
+
packageName: 'occt-import-js',
|
|
49
|
+
wasm: true,
|
|
50
|
+
output: ['three-object', 'mesh'],
|
|
51
|
+
note: 'Uses OCCT importers for IGES/BREP geometry and keeps the heavy runtime behind a dedicated package.',
|
|
52
|
+
url: 'https://github.com/kovacsv/occt-import-js',
|
|
53
|
+
},
|
|
54
|
+
],
|
|
55
|
+
serverConversionTargets: ['glb', 'gltf', 'stl', 'obj'],
|
|
56
|
+
licenseNotes: ['Treat CAD kernel licensing separately from the lightweight viewer core.'],
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
format: 'brep',
|
|
60
|
+
aliases: ['brep'],
|
|
61
|
+
label: 'BREP',
|
|
62
|
+
family: 'cad-brep',
|
|
63
|
+
recommended: [
|
|
64
|
+
{
|
|
65
|
+
renderer: 'OpenCascade / OCCT import',
|
|
66
|
+
packageName: 'occt-import-js',
|
|
67
|
+
wasm: true,
|
|
68
|
+
output: ['three-object', 'mesh'],
|
|
69
|
+
note: 'BREP is closest to the native OCCT topology model and should share the STEP/IGES engine.',
|
|
70
|
+
url: 'https://github.com/kovacsv/occt-import-js',
|
|
71
|
+
},
|
|
72
|
+
],
|
|
73
|
+
serverConversionTargets: ['glb', 'gltf', 'stl', 'obj'],
|
|
74
|
+
licenseNotes: ['Keep OCCT WASM as an explicit renderer dependency.'],
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
format: 'ifc',
|
|
78
|
+
aliases: ['ifc', 'ifczip', 'ifcxml'],
|
|
79
|
+
label: 'IFC / BuildingSMART',
|
|
80
|
+
family: 'bim-ifc',
|
|
81
|
+
recommended: [
|
|
82
|
+
{
|
|
83
|
+
renderer: 'That Open web-ifc',
|
|
84
|
+
packageName: 'web-ifc',
|
|
85
|
+
wasm: true,
|
|
86
|
+
output: ['fragments', 'mesh'],
|
|
87
|
+
note: 'Reads IFC at native speed in the browser and can be paired with Fragments for large BIM models.',
|
|
88
|
+
url: 'https://github.com/thatopen/engine_web-ifc',
|
|
89
|
+
},
|
|
90
|
+
],
|
|
91
|
+
serverConversionTargets: ['glb', 'gltf', 'fragments'],
|
|
92
|
+
licenseNotes: ['Large IFC models often need preprocessing, fragments, worker isolation, and property paging.'],
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
format: '3dm',
|
|
96
|
+
aliases: ['3dm', 'rhino'],
|
|
97
|
+
label: 'Rhino 3DM / OpenNURBS',
|
|
98
|
+
family: 'rhino-3dm',
|
|
99
|
+
recommended: [
|
|
100
|
+
{
|
|
101
|
+
renderer: 'McNeel rhino3dm.js',
|
|
102
|
+
packageName: 'rhino3dm',
|
|
103
|
+
wasm: true,
|
|
104
|
+
output: ['three-object', 'mesh'],
|
|
105
|
+
note: 'Official OpenNURBS WASM binding; Three.js provides Rhino3dmLoader on top of it.',
|
|
106
|
+
url: 'https://github.com/mcneel/rhino3dm',
|
|
107
|
+
},
|
|
108
|
+
],
|
|
109
|
+
serverConversionTargets: ['glb', 'gltf', 'obj'],
|
|
110
|
+
licenseNotes: ['Ship rhino3dm.wasm only in the dedicated 3DM renderer path.'],
|
|
111
|
+
},
|
|
112
|
+
];
|
|
113
|
+
const routeByAlias = new Map();
|
|
114
|
+
geometryKernelRoutes.forEach(route => {
|
|
115
|
+
route.aliases.forEach(alias => routeByAlias.set(alias, route));
|
|
116
|
+
});
|
|
117
|
+
export const normalizeGeometryKernelFormat = (type) => {
|
|
118
|
+
var _a;
|
|
119
|
+
return (_a = routeByAlias.get(normalizeToken(type))) === null || _a === void 0 ? void 0 : _a.format;
|
|
120
|
+
};
|
|
121
|
+
export const getGeometryKernelRoute = (type) => {
|
|
122
|
+
return routeByAlias.get(normalizeToken(type));
|
|
123
|
+
};
|
|
124
|
+
export const isGeometryKernelFormat = (type) => {
|
|
125
|
+
return Boolean(getGeometryKernelRoute(type));
|
|
126
|
+
};
|
|
127
|
+
const toBytes = (input) => {
|
|
128
|
+
return input instanceof Uint8Array ? input : new Uint8Array(input);
|
|
129
|
+
};
|
|
130
|
+
const decodePrefix = (bytes, maxLength = 8192) => {
|
|
131
|
+
const slice = bytes.slice(0, Math.min(bytes.byteLength, maxLength));
|
|
132
|
+
if (textDecoder) {
|
|
133
|
+
return textDecoder.decode(slice);
|
|
134
|
+
}
|
|
135
|
+
let text = '';
|
|
136
|
+
for (let index = 0; index < slice.length; index += 1) {
|
|
137
|
+
text += String.fromCharCode(slice[index]);
|
|
138
|
+
}
|
|
139
|
+
return text;
|
|
140
|
+
};
|
|
141
|
+
const createInspection = (bytes, format, confidence, signature, warnings = []) => {
|
|
142
|
+
const route = format ? getGeometryKernelRoute(format) : undefined;
|
|
143
|
+
return {
|
|
144
|
+
format,
|
|
145
|
+
route,
|
|
146
|
+
confidence,
|
|
147
|
+
byteLength: bytes.byteLength,
|
|
148
|
+
signature,
|
|
149
|
+
warnings,
|
|
150
|
+
};
|
|
151
|
+
};
|
|
152
|
+
export const inspectGeometryKernelFile = (input, type) => {
|
|
153
|
+
const bytes = toBytes(input);
|
|
154
|
+
const explicitFormat = normalizeGeometryKernelFormat(type);
|
|
155
|
+
const prefix = decodePrefix(bytes);
|
|
156
|
+
const normalizedPrefix = prefix.toUpperCase();
|
|
157
|
+
const warnings = [];
|
|
158
|
+
if (bytes.byteLength === 0) {
|
|
159
|
+
return createInspection(bytes, explicitFormat, explicitFormat ? 'low' : 'none', undefined, ['Empty file.']);
|
|
160
|
+
}
|
|
161
|
+
if (/FILE_SCHEMA\s*\(\s*\(\s*'IFC/i.test(prefix) ||
|
|
162
|
+
(normalizedPrefix.includes('IFC') && normalizedPrefix.includes('FILE_SCHEMA'))) {
|
|
163
|
+
return createInspection(bytes, 'ifc', 'high', 'IFC-SPF', warnings);
|
|
164
|
+
}
|
|
165
|
+
if (/ISO-10303-21|HEADER;\s*FILE_DESCRIPTION|DATA;\s*#\d+=/i.test(prefix)) {
|
|
166
|
+
return createInspection(bytes, 'step', 'high', 'ISO-10303-21', warnings);
|
|
167
|
+
}
|
|
168
|
+
if (/3D GEOMETRY FILE FORMAT|OPENNURBS/i.test(prefix)) {
|
|
169
|
+
return createInspection(bytes, '3dm', 'high', 'OpenNURBS 3DM', warnings);
|
|
170
|
+
}
|
|
171
|
+
if (/DBRep_DrawableShape|CASCADE Topology V|BREP/i.test(prefix)) {
|
|
172
|
+
return createInspection(bytes, 'brep', 'medium', 'OpenCascade BREP', warnings);
|
|
173
|
+
}
|
|
174
|
+
const hasIgesStartSection = /^.{0,72}S\s*\d+/m.test(prefix);
|
|
175
|
+
const hasIgesGlobalSection = /^.{0,72}G\s*\d+/m.test(prefix);
|
|
176
|
+
if (hasIgesStartSection || hasIgesGlobalSection || /S\s+1\s*\n.{0,72}G\s+1/i.test(prefix)) {
|
|
177
|
+
return createInspection(bytes, 'iges', hasIgesStartSection && hasIgesGlobalSection ? 'high' : 'medium', 'IGES section marker', warnings);
|
|
178
|
+
}
|
|
179
|
+
if (explicitFormat) {
|
|
180
|
+
warnings.push('File signature was not fully recognized; using the provided extension or MIME hint.');
|
|
181
|
+
return createInspection(bytes, explicitFormat, 'low', undefined, warnings);
|
|
182
|
+
}
|
|
183
|
+
return createInspection(bytes, undefined, 'none', undefined, ['No supported geometry kernel signature was detected.']);
|
|
184
|
+
};
|
|
185
|
+
export const formatGeometryKernelNotice = (type, locale = 'zh-CN') => {
|
|
186
|
+
const route = getGeometryKernelRoute(type);
|
|
187
|
+
const formatLabel = (route === null || route === void 0 ? void 0 : route.label) || String(type || 'Engineering model').toUpperCase();
|
|
188
|
+
const engines = (route === null || route === void 0 ? void 0 : route.recommended.map(item => item.packageName).join(' / ')) || 'OpenCascade / web-ifc / rhino3dm';
|
|
189
|
+
const targets = (route === null || route === void 0 ? void 0 : route.serverConversionTargets.join(' / ')) || 'GLB / GLTF';
|
|
190
|
+
if (locale === 'en-US') {
|
|
191
|
+
return `${formatLabel} requires a dedicated WebAssembly geometry kernel (${engines}) for full browser preview. Flyfish Viewer keeps these heavy runtimes outside core and the default 3D renderer install path; use the dedicated geometry engine route or convert the model to ${targets} in a private pipeline.`;
|
|
192
|
+
}
|
|
193
|
+
return `${formatLabel} 需要独立 WebAssembly 几何内核(${engines})才能完整浏览器预览。Flyfish Viewer 不会把这类重型运行时塞进 core 或默认 3D renderer 安装路径;请通过独立几何内核路线接入,或在私有转换链路输出 ${targets} 后预览。`;
|
|
194
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@file-viewer/geometry-engine",
|
|
3
|
+
"version": "2.0.11",
|
|
4
|
+
"private": false,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"description": "Framework-neutral geometry kernel boundary package for STEP, IGES, IFC, 3DM, and BREP preview routes in Flyfish File Viewer.",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"file-viewer",
|
|
9
|
+
"geometry",
|
|
10
|
+
"cad",
|
|
11
|
+
"bim",
|
|
12
|
+
"step",
|
|
13
|
+
"iges",
|
|
14
|
+
"ifc",
|
|
15
|
+
"3dm",
|
|
16
|
+
"wasm",
|
|
17
|
+
"document-preview",
|
|
18
|
+
"file-preview",
|
|
19
|
+
"self-hosted"
|
|
20
|
+
],
|
|
21
|
+
"publishConfig": {
|
|
22
|
+
"access": "public",
|
|
23
|
+
"registry": "https://registry.npmjs.org/"
|
|
24
|
+
},
|
|
25
|
+
"author": {
|
|
26
|
+
"name": "Wangyu",
|
|
27
|
+
"email": "wybaby168@gmail.com"
|
|
28
|
+
},
|
|
29
|
+
"repository": {
|
|
30
|
+
"type": "git",
|
|
31
|
+
"url": "git+https://github.com/flyfish-dev/geometry-engine.git",
|
|
32
|
+
"directory": "packages/renderers/geometry-engine"
|
|
33
|
+
},
|
|
34
|
+
"homepage": "https://doc.file-viewer.app/guide/format-fidelity",
|
|
35
|
+
"bugs": {
|
|
36
|
+
"url": "https://github.com/flyfish-dev/geometry-engine/issues"
|
|
37
|
+
},
|
|
38
|
+
"funding": {
|
|
39
|
+
"type": "individual",
|
|
40
|
+
"url": "https://dev.flyfish.group/shop"
|
|
41
|
+
},
|
|
42
|
+
"main": "./dist/index.js",
|
|
43
|
+
"module": "./dist/index.js",
|
|
44
|
+
"types": "./dist/index.d.ts",
|
|
45
|
+
"exports": {
|
|
46
|
+
".": {
|
|
47
|
+
"types": "./dist/index.d.ts",
|
|
48
|
+
"import": "./dist/index.js",
|
|
49
|
+
"default": "./dist/index.js"
|
|
50
|
+
},
|
|
51
|
+
"./package.json": "./package.json"
|
|
52
|
+
},
|
|
53
|
+
"files": [
|
|
54
|
+
"dist",
|
|
55
|
+
"README.md",
|
|
56
|
+
"README.en.md",
|
|
57
|
+
"LICENSE"
|
|
58
|
+
],
|
|
59
|
+
"devDependencies": {
|
|
60
|
+
"typescript": "^6.0.3"
|
|
61
|
+
},
|
|
62
|
+
"license": "Apache-2.0",
|
|
63
|
+
"scripts": {
|
|
64
|
+
"build": "tsc -b tsconfig.json",
|
|
65
|
+
"type-check": "tsc -b tsconfig.json"
|
|
66
|
+
}
|
|
67
|
+
}
|