@harpern/edu-modelhub-viewer-core 0.1.0-beta.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/CHANGELOG.md +31 -0
- package/LICENSE +201 -0
- package/README.md +88 -0
- package/dist/announce.d.ts +25 -0
- package/dist/backgrounds.d.ts +40 -0
- package/dist/camera.d.ts +77 -0
- package/dist/coordinates.d.ts +40 -0
- package/dist/dispose.d.ts +10 -0
- package/dist/framing.d.ts +31 -0
- package/dist/index.cjs +21 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.js +625 -0
- package/dist/lighting.d.ts +64 -0
- package/dist/markers.d.ts +75 -0
- package/dist/metadata.d.ts +85 -0
- package/dist/normalize.d.ts +76 -0
- package/dist/occlusion.d.ts +38 -0
- package/dist/regions.d.ts +52 -0
- package/dist/transcript.d.ts +26 -0
- package/package.json +77 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to `@osuecampus/edu-modelhub-viewer-core` are documented
|
|
4
|
+
here.
|
|
5
|
+
|
|
6
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
7
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
8
|
+
|
|
9
|
+
## [Unreleased]
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- Metadata loading with the spec's source precedence: embedded extension,
|
|
14
|
+
then `.modelhub.json` sidecar, then a fail-closed result carrying a reason.
|
|
15
|
+
The GLB is fetched once and its bytes returned for the host's own loader.
|
|
16
|
+
- Payload normalization: unique annotation ids, reading order, lookups by id
|
|
17
|
+
and by region, regions in display order, and marker anchors with positions
|
|
18
|
+
already converted to renderer space.
|
|
19
|
+
- Coordinate handling, where a payload with no `coordinateSpace` is glTF Y-up
|
|
20
|
+
and only an explicit `"blender"` is converted.
|
|
21
|
+
- Region-to-geometry binding from `primitive.extras.modelhubRegionId`, with
|
|
22
|
+
highlight and restore, and `visibilityDefault` applied on load.
|
|
23
|
+
- Annotation markers as numbered sprites, or projected to screen positions so
|
|
24
|
+
a host can draw focusable HTML buttons over the canvas.
|
|
25
|
+
- Optional marker occlusion through `three-mesh-bvh`, degrading to a no-op
|
|
26
|
+
when the host has not installed it.
|
|
27
|
+
- Model framing that measures skinned meshes through their bind-pose bounds,
|
|
28
|
+
so rigged models no longer frame several times too small.
|
|
29
|
+
- Camera placement preferring an authored camera, with an eased flight that
|
|
30
|
+
becomes a jump cut under reduced motion.
|
|
31
|
+
- A spoken model summary, a throttled announcer, and a Markdown transcript.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
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,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to the Licensor for inclusion in the Work by the copyright
|
|
52
|
+
owner or by an individual or Legal Entity authorized to submit on behalf
|
|
53
|
+
of the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Oregon State University
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# @osuecampus/edu-modelhub-viewer-core
|
|
2
|
+
|
|
3
|
+
The parts of an EDU_modelhub viewer that should not be written twice.
|
|
4
|
+
|
|
5
|
+
This package holds the behaviour two viewers of the same model must agree on:
|
|
6
|
+
how metadata is found, what happens when it is missing, how annotations are
|
|
7
|
+
numbered, where markers sit, which geometry a region owns, and where the
|
|
8
|
+
camera goes when someone selects an annotation.
|
|
9
|
+
|
|
10
|
+
It renders nothing and owns no scene. Bring your own three.js renderer and
|
|
11
|
+
your own interface.
|
|
12
|
+
|
|
13
|
+
## Why it exists
|
|
14
|
+
|
|
15
|
+
Two viewers of the same models drifted apart until each was correct about its
|
|
16
|
+
own content and wrong about the other's. The costly divergences were not
|
|
17
|
+
visual: they were a coordinate rule, a metadata precedence order, and an
|
|
18
|
+
annotation numbering scheme. Those belong in one place.
|
|
19
|
+
|
|
20
|
+
## Install
|
|
21
|
+
|
|
22
|
+
The official package is not yet on npm. Publishing under the `@osuecampus`
|
|
23
|
+
scope waits on the same npm org access that holds up the extractor. Once it
|
|
24
|
+
lands:
|
|
25
|
+
|
|
26
|
+
```sh
|
|
27
|
+
yarn add @osuecampus/edu-modelhub-viewer-core three
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Until then it is published under the maintainer’s personal scope. It is this
|
|
31
|
+
exact build with the same API:
|
|
32
|
+
|
|
33
|
+
```sh
|
|
34
|
+
yarn add @harpern/edu-modelhub-viewer-core@beta three
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
When the official package appears, change the package name in your install
|
|
38
|
+
and import lines; nothing else changes. The `@harpern` package will be
|
|
39
|
+
deprecated at that point with a message pointing at the new name, so your
|
|
40
|
+
package manager tells you when to switch.
|
|
41
|
+
|
|
42
|
+
`three` is a peer dependency. `three-mesh-bvh` is an optional peer: install
|
|
43
|
+
it to get marker occlusion, leave it out and markers simply never dim.
|
|
44
|
+
|
|
45
|
+
## What it does
|
|
46
|
+
|
|
47
|
+
**Metadata, with the precedence the spec requires.** One fetch, embedded
|
|
48
|
+
extension first, `.modelhub.json` sidecar second, and a fail-closed result
|
|
49
|
+
carrying a reason when neither has anything. The same bytes come back for your
|
|
50
|
+
own loader, so the scene and the metadata can never disagree about which file
|
|
51
|
+
they came from.
|
|
52
|
+
|
|
53
|
+
```js
|
|
54
|
+
import { loadModel, normalizeModel } from "@osuecampus/edu-modelhub-viewer-core";
|
|
55
|
+
|
|
56
|
+
const { payload, source, bytes, problem } = await loadModel(url);
|
|
57
|
+
if (!payload) showAccessibleError(problem);
|
|
58
|
+
const model = normalizeModel(payload);
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
**Normalization.** `normalizeModel` returns regions in display order,
|
|
62
|
+
annotations in reading order with unique ids, lookups by id and by region, and
|
|
63
|
+
marker anchors whose positions are already in renderer space.
|
|
64
|
+
|
|
65
|
+
**Coordinate space.** A payload is glTF Y-up unless it explicitly says
|
|
66
|
+
`"blender"`. Reading a Blender-authored file into a Y-up renderer without
|
|
67
|
+
converting is the most common integration bug in this format, and silence
|
|
68
|
+
used to mean the opposite, so this rule is enforced in one function.
|
|
69
|
+
|
|
70
|
+
**Regions bound to geometry.** Built from `primitive.extras.modelhubRegionId`,
|
|
71
|
+
which three.js copies onto the geometry's `userData` rather than the mesh's.
|
|
72
|
+
`applyVisibilityDefaults` honours a region authored as hidden.
|
|
73
|
+
|
|
74
|
+
**Markers.** Numbered from reading order, so the visual order and the
|
|
75
|
+
announced order cannot disagree. Use sprites in the scene, or project anchors
|
|
76
|
+
to screen positions and draw real HTML buttons, which is the accessible
|
|
77
|
+
option because a sprite cannot be focused.
|
|
78
|
+
|
|
79
|
+
**Camera.** `computeTourPlacement` prefers an authored camera and falls back
|
|
80
|
+
to a computed standoff. `flyCamera` eases, or cuts straight there when the
|
|
81
|
+
viewer prefers reduced motion.
|
|
82
|
+
|
|
83
|
+
**Text.** A spoken model summary, a throttled announcer so held keys do not
|
|
84
|
+
flood a live region, and a Markdown transcript of everything the model says.
|
|
85
|
+
|
|
86
|
+
## Licence
|
|
87
|
+
|
|
88
|
+
Apache-2.0.
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the viewer says out loud.
|
|
3
|
+
*
|
|
4
|
+
* Screen reader announcements are part of the interface, not decoration, so
|
|
5
|
+
* the wording lives here rather than being retyped in each app. Camera moves
|
|
6
|
+
* are throttled: a held arrow key would otherwise flood the live region and
|
|
7
|
+
* drown out everything else.
|
|
8
|
+
*/
|
|
9
|
+
import type { EduModelHub } from "@osuecampus/edu-modelhub-extractor";
|
|
10
|
+
/** Default gap between camera announcements, in milliseconds. */
|
|
11
|
+
export declare const CAMERA_ANNOUNCE_INTERVAL = 500;
|
|
12
|
+
/** A one-line summary spoken when a model finishes loading. */
|
|
13
|
+
export declare function modelSummary(payload: EduModelHub | null): string;
|
|
14
|
+
/** What to say when an annotation becomes the active one. */
|
|
15
|
+
export declare function annotationSummary(title: string | undefined, index: number, total: number): string;
|
|
16
|
+
/**
|
|
17
|
+
* Rate-limit announcements to one per `interval`.
|
|
18
|
+
*
|
|
19
|
+
* The most recent message wins: when keys are held down, what the user wants
|
|
20
|
+
* to hear is where the camera ended up, not every step along the way.
|
|
21
|
+
*/
|
|
22
|
+
export declare function createAnnouncer(emit: (message: string) => void, interval?: number, now?: () => number): {
|
|
23
|
+
announce: (message: string) => void;
|
|
24
|
+
flush: () => void;
|
|
25
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Viewer background colours.
|
|
3
|
+
*
|
|
4
|
+
* Which background a model sits on changes how readable it is: a pale bone
|
|
5
|
+
* specimen disappears on white and reads clearly on dark grey. Offering the
|
|
6
|
+
* same choices in every viewer means an instructor who picked one for a
|
|
7
|
+
* collection gets it wherever the model is shown.
|
|
8
|
+
*/
|
|
9
|
+
/** One background choice. */
|
|
10
|
+
export interface BackgroundOption {
|
|
11
|
+
id: string;
|
|
12
|
+
label: string;
|
|
13
|
+
/** Canonical `#rrggbb`. */
|
|
14
|
+
hex: string;
|
|
15
|
+
/** True when the colour is light enough that dark overlays read better. */
|
|
16
|
+
light: boolean;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* The standard swatches. Dark grey is the reference background, and gallery
|
|
20
|
+
* thumbnails are captured against it.
|
|
21
|
+
*/
|
|
22
|
+
export declare const BACKGROUND_OPTIONS: readonly BackgroundOption[];
|
|
23
|
+
/** The swatch used when nothing else is chosen. */
|
|
24
|
+
export declare const DEFAULT_BACKGROUND = "dark-grey";
|
|
25
|
+
/**
|
|
26
|
+
* Accept `#rgb` or `#rrggbb`, with or without the hash, and return canonical
|
|
27
|
+
* `#rrggbb`. Anything else returns an empty string, so a viewer falls back to
|
|
28
|
+
* a known swatch rather than handing an invalid colour to the renderer.
|
|
29
|
+
*/
|
|
30
|
+
export declare function normalizeHexColor(value: unknown): string;
|
|
31
|
+
/** Perceived brightness, 0 to 1, using the usual luma weights. */
|
|
32
|
+
export declare function luminance(hex: string): number;
|
|
33
|
+
/**
|
|
34
|
+
* The background actually in force.
|
|
35
|
+
*
|
|
36
|
+
* A custom colour, typically chosen per collection or per model, wins over
|
|
37
|
+
* the named swatch, and its `light` flag is measured rather than declared so
|
|
38
|
+
* overlays stay readable on a colour nobody anticipated.
|
|
39
|
+
*/
|
|
40
|
+
export declare function resolveBackground(backgroundId?: string, custom?: string): BackgroundOption;
|
package/dist/camera.d.ts
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Moving the camera to an annotation.
|
|
3
|
+
*
|
|
4
|
+
* Two jobs: work out where the camera should be for a given annotation, and
|
|
5
|
+
* get it there. They are separate because the placement is worth testing on
|
|
6
|
+
* its own, while the movement is a render loop.
|
|
7
|
+
*
|
|
8
|
+
* Authored cameras win. When a payload carries one, the camera flies to the
|
|
9
|
+
* exact eye the author framed. Sources like Sketchfab encode the look
|
|
10
|
+
* direction as a point right beside the eye, so the raw target is useless as
|
|
11
|
+
* an orbit pivot: the pivot is placed at the anchor's depth along the
|
|
12
|
+
* authored direction instead, which keeps orbiting sane after the flight.
|
|
13
|
+
*/
|
|
14
|
+
import { Vector3 } from "three";
|
|
15
|
+
import type { Object3D, PerspectiveCamera } from "three";
|
|
16
|
+
import type { MarkerAnchor } from "./normalize.js";
|
|
17
|
+
/** Where the camera should sit to view one annotation. */
|
|
18
|
+
export interface CameraPlacement {
|
|
19
|
+
position: Vector3;
|
|
20
|
+
target: Vector3;
|
|
21
|
+
/** Vertical field of view in degrees, when the annotation authored one. */
|
|
22
|
+
fov?: number;
|
|
23
|
+
}
|
|
24
|
+
/** Tuning for the computed fallback placement. */
|
|
25
|
+
export interface TourPlacementOptions {
|
|
26
|
+
/**
|
|
27
|
+
* `true` puts the camera between the model centre and the annotation,
|
|
28
|
+
* looking outward, which suits interior walkthrough scenes. `false` puts it
|
|
29
|
+
* beyond the annotation looking back at the centre, which suits a single
|
|
30
|
+
* specimen and needs a real standoff or the camera lands inside the mesh.
|
|
31
|
+
*/
|
|
32
|
+
outward?: boolean;
|
|
33
|
+
outwardDistance?: number;
|
|
34
|
+
inwardDistance?: number;
|
|
35
|
+
}
|
|
36
|
+
/** Default standoffs, in normalized model units (longest axis 2). */
|
|
37
|
+
export declare const TOUR_DISTANCE_OUTWARD = 0.5;
|
|
38
|
+
export declare const TOUR_DISTANCE_INWARD = 1.5;
|
|
39
|
+
/**
|
|
40
|
+
* Work out where to put the camera for one annotation.
|
|
41
|
+
*
|
|
42
|
+
* @param anchor - The marker anchor, positions already in renderer space.
|
|
43
|
+
* @param model - The loaded model, for its world transform.
|
|
44
|
+
*/
|
|
45
|
+
export declare function computeTourPlacement(anchor: MarkerAnchor, model: Object3D, options?: TourPlacementOptions): CameraPlacement;
|
|
46
|
+
/** Minimal orbit-controls surface this module drives. */
|
|
47
|
+
export interface ControlsLike {
|
|
48
|
+
target: Vector3;
|
|
49
|
+
update(): void;
|
|
50
|
+
}
|
|
51
|
+
/** Options for {@link flyCamera}. */
|
|
52
|
+
export interface FlyOptions {
|
|
53
|
+
camera: {
|
|
54
|
+
position: Vector3;
|
|
55
|
+
};
|
|
56
|
+
controls: ControlsLike;
|
|
57
|
+
to: CameraPlacement;
|
|
58
|
+
/** Jump straight there instead of animating. */
|
|
59
|
+
reducedMotion?: boolean;
|
|
60
|
+
durationMs?: number;
|
|
61
|
+
/** Called after each step so the host can request a render. */
|
|
62
|
+
onFrame?: () => void;
|
|
63
|
+
/** Called once the move finishes or is cancelled. */
|
|
64
|
+
onDone?: () => void;
|
|
65
|
+
}
|
|
66
|
+
/** Handle for an in-flight camera move. */
|
|
67
|
+
export interface Flight {
|
|
68
|
+
cancel(): void;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Move the camera to a placement, easing unless the user prefers reduced
|
|
72
|
+
* motion, in which case it cuts straight there. Returns a handle so a new
|
|
73
|
+
* move, or a teardown, can cancel one already running.
|
|
74
|
+
*/
|
|
75
|
+
export declare function flyCamera(options: FlyOptions): Flight;
|
|
76
|
+
/** Apply a placement's field of view, or fall back to the viewer default. */
|
|
77
|
+
export declare function applyFov(camera: PerspectiveCamera, fov: number | undefined, defaultFov: number): void;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Coordinate space handling.
|
|
3
|
+
*
|
|
4
|
+
* EDU_modelhub payloads store marker and camera positions in one of two
|
|
5
|
+
* spaces, named by the root `coordinateSpace` field. Web renderers are Y-up,
|
|
6
|
+
* Blender is Z-up, and getting this wrong puts every annotation marker in the
|
|
7
|
+
* wrong place, which is the single most common integration bug.
|
|
8
|
+
*
|
|
9
|
+
* The rule: a payload is glTF Y-up unless it explicitly says `"blender"`.
|
|
10
|
+
* Silence used to mean Blender Z-up, on the assumption that an undeclared
|
|
11
|
+
* file was an old one. The published content says otherwise, so an
|
|
12
|
+
* undeclared payload is now read as Y-up and only an explicit marker is
|
|
13
|
+
* converted.
|
|
14
|
+
*/
|
|
15
|
+
import type { EduModelHub } from "@osuecampus/edu-modelhub-extractor";
|
|
16
|
+
/** A position as stored in a payload, or as handed to a renderer. */
|
|
17
|
+
export type Vec3 = [number, number, number];
|
|
18
|
+
/** True when `value` is three finite numbers. */
|
|
19
|
+
export declare function isVec3(value: unknown): value is Vec3;
|
|
20
|
+
/**
|
|
21
|
+
* Whether a payload's positions need converting before a Y-up renderer uses
|
|
22
|
+
* them. Only an explicit `"blender"` does.
|
|
23
|
+
*/
|
|
24
|
+
export declare function needsConversion(coordinateSpace: EduModelHub["coordinateSpace"]): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Convert one stored position into renderer (glTF Y-up) space.
|
|
27
|
+
*
|
|
28
|
+
* Returns `null` when `position` is not three finite numbers, rather than
|
|
29
|
+
* throwing: a payload that failed validation can still reach a viewer, and
|
|
30
|
+
* one bad marker must not take down every other marker with it.
|
|
31
|
+
*
|
|
32
|
+
* @param position - Position as stored in the payload.
|
|
33
|
+
* @param coordinateSpace - The payload's root `coordinateSpace`.
|
|
34
|
+
*/
|
|
35
|
+
export declare function toViewerPosition(position: unknown, coordinateSpace?: EduModelHub["coordinateSpace"]): Vec3 | null;
|
|
36
|
+
/**
|
|
37
|
+
* Convert a position from renderer space back to the payload's space, for
|
|
38
|
+
* tools that write positions rather than read them.
|
|
39
|
+
*/
|
|
40
|
+
export declare function fromViewerPosition(position: unknown, coordinateSpace?: EduModelHub["coordinateSpace"]): Vec3 | null;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Freeing a model.
|
|
3
|
+
*
|
|
4
|
+
* Switching models without disposing leaks GPU memory a frame at a time until
|
|
5
|
+
* the context is lost, which on a gallery of hundreds of models happens well
|
|
6
|
+
* inside one session.
|
|
7
|
+
*/
|
|
8
|
+
import type { Object3D } from "three";
|
|
9
|
+
/** Free every geometry, material, and texture under `root`. */
|
|
10
|
+
export declare function disposeSceneGraph(root: Object3D | null | undefined): void;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fitting a model into view.
|
|
3
|
+
*
|
|
4
|
+
* Models arrive at wildly different scales, so every viewer normalizes them
|
|
5
|
+
* to a known size and centres them at the origin. Doing it the same way in
|
|
6
|
+
* both apps means an authored camera means the same thing in each.
|
|
7
|
+
*/
|
|
8
|
+
import { Box3 } from "three";
|
|
9
|
+
import type { Object3D } from "three";
|
|
10
|
+
/** Size the longest axis is normalized to. */
|
|
11
|
+
export declare const NORMALIZED_SIZE = 2;
|
|
12
|
+
/**
|
|
13
|
+
* World bounding box of a model as it will actually render.
|
|
14
|
+
*
|
|
15
|
+
* `Box3.setFromObject` measures raw geometry, which for a skinned mesh
|
|
16
|
+
* ignores the armature's bone transforms. A rigged model carrying a scaled
|
|
17
|
+
* armature then measures several times wrong and frames far too small, so
|
|
18
|
+
* skinned meshes are measured through their own bind-pose bounds instead.
|
|
19
|
+
*/
|
|
20
|
+
export declare function computeDisplayBox(root: Object3D): Box3;
|
|
21
|
+
/**
|
|
22
|
+
* Scale a model so its longest axis is `size`, then centre it at the origin.
|
|
23
|
+
* Mutates the model's transform and returns the scale factor applied.
|
|
24
|
+
*/
|
|
25
|
+
export declare function frameModel(root: Object3D, size?: number): number;
|
|
26
|
+
/**
|
|
27
|
+
* Camera distance that frames a normalized model at a given vertical field of
|
|
28
|
+
* view. Narrow fields of view need to sit much further back, which is why a
|
|
29
|
+
* fixed distance looks wrong as soon as a model overrides the default.
|
|
30
|
+
*/
|
|
31
|
+
export declare function distanceForFov(fovDegrees: number, margin?: number): number;
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("@osuecampus/edu-modelhub-extractor"),m=require("three");function R(e){return e.filter(t=>t.severity==="error")}function v(e){const[t,i=""]=e.split("?",2);if(!/\.glb$/i.test(t))return null;const n=t.replace(/\.glb$/i,".modelhub.json");return i?`${n}?${i}`:n}function K(e,t){var o;if(!e||e.startsWith("blob:")||e.startsWith("data:"))return"";const i=t??((o=globalThis.location)==null?void 0:o.href),n=i?new URL(e,i).href:e,r=n.lastIndexOf("/");return r===-1?"":n.slice(0,r+1)}async function $(e,t=fetch){const i=await t(e);if(!i.ok)throw new Error(`Failed to fetch ${e} (HTTP ${i.status}).`);return i.arrayBuffer()}function _(e){const t=h.parseGlb(e);if(!t)return{payload:null,source:"none",findings:[],problem:"This model carries no EDU_modelhub metadata."};const i=h.validate(t);return{payload:t,source:"embedded",findings:i,problem:null}}async function q(e,t={}){const i=t.fetchImpl??fetch,n=await $(e,i),r=_(n);if(r.payload)return{...r,bytes:n};if(t.sidecar===!1)return{...r,bytes:n};const s=(t.sidecarUrl??v)(e);if(!s)return{...r,bytes:n};try{const c=await i(s);if(c.ok){const u=h.adaptSidecar(await c.json());return{payload:u,source:"sidecar",findings:h.validate(u),problem:null,bytes:n}}}catch{}return{payload:null,source:"none",findings:[],problem:"This model has no EDU_modelhub metadata, either embedded in the file or in a sidecar beside it.",bytes:n}}function j(e,t="EDU_modelhub",i=console){if(!(e!=null&&e.length))return;const n=R(e),r=e.filter(o=>o.severity!=="error");n.length&&i.warn(`${t}: ${n.length} validation error(s)`,n),r.length&&i.info(`${t}: ${r.length} validation warning(s)`,r)}function T(e){return Array.isArray(e)&&e.length===3&&e.every(t=>typeof t=="number"&&Number.isFinite(t))}function A(e){return e==="blender"}function x(e,t){if(!T(e))return null;const[i,n,r]=e;return A(t)?[i,r,-n]:[i,n,r]}function Z(e,t){if(!T(e))return null;const[i,n,r]=e;return A(t)?[i,-r,n]:[i,n,r]}function C(e){if(!Array.isArray(e))return[];const t=new Set;return e.map((i,n)=>{const o=(typeof(i==null?void 0:i.id)=="string"?i.id.trim():"")||`annotation-${n+1}`;let s=o,c=2;for(;t.has(s);)s=`${o}-${c++}`;return t.add(s),{...i??{},id:s}})}function M(e){const t=C(e==null?void 0:e.annotations),i=n=>Number.isFinite(n.readingOrder)?n.readingOrder:Number.MAX_SAFE_INTEGER;return t.map((n,r)=>({annotation:n,index:r})).sort((n,r)=>i(n.annotation)-i(r.annotation)||n.index-r.index).map(n=>n.annotation)}function S(e){return(Array.isArray(e==null?void 0:e.regions)?e.regions:[]).map((i,n)=>({region:i,index:n})).sort((i,n)=>(i.region.order??Number.MAX_SAFE_INTEGER)-(n.region.order??Number.MAX_SAFE_INTEGER)||i.index-n.index).map(i=>i.region)}function I(e){var t;return e?((t=e.label)==null?void 0:t.trim())||e.id||"Unnamed region":"Unknown region"}function X(e){if(!e)return[];const t=[],i=/\[([^\]]+)\]\((https?:\/\/[^\s)]+)\)/g;let n=0,r;for(;(r=i.exec(e))!==null;)r.index>n&&t.push({text:e.slice(n,r.index)}),t.push({text:r[1],url:r[2]}),n=r.index+r[0].length;return n<e.length&&t.push({text:e.slice(n)}),t.filter(o=>o.text.trim()||o.url)}function Q(e){const t=e==null?void 0:e.coordinateSpace,i=S(e),n=M(e),r=new Map(i.map(a=>[a.id,a])),o=new Map(n.map(a=>[a.id,a])),s=new Map;for(const a of n){const l=a.regionId;if(!l)continue;const d=s.get(l);d?d.push(a):s.set(l,[a])}const c=[];for(const a of n){const l=a.anchor;if(!l||l.type!=="marker")continue;const d=x(l.position,t);if(!d)continue;const f=a.camera,p=f?x(f.eye,t):null,g=f?x(f.target,t):null;c.push({annotation:a,position:d,...p&&g?{camera:{eye:p,target:g,...f!=null&&f.fov?{fov:f.fov}:{}}}:{}})}const u=new Set(i.filter(a=>a.visibilityDefault==="hidden").map(a=>a.id));return{payload:e,regions:i,regionsById:r,annotations:n,annotationsById:o,annotationsByRegion:s,markerAnchors:c,hiddenRegionIds:u}}function Y(e){return e.isMesh===!0}function J(e,t,i=[]){var u;const n=new Map,r=new Map,o=new Map,s=new Map;for(const[a,l]of((t==null?void 0:t.meshes)??[]).entries())for(const d of l.primitives??[]){const f=(u=d.extras)==null?void 0:u.modelhubRegionId;typeof f=="string"&&f&&(s.set(a,f),l.name&&r.set(l.name,f))}for(const a of(t==null?void 0:t.nodes)??[]){if(a.mesh===void 0||!a.name)continue;const l=s.get(a.mesh);l&&o.set(a.name,l)}const c=new Set(i.map(a=>a.id));return e.traverse(a=>{var p,g;if(!Y(a))return;const l=(g=(p=a.geometry)==null?void 0:p.userData)==null?void 0:g.modelhubRegionId,d=typeof l=="string"&&l||o.get(a.name)||r.get(a.name)||(c.has(a.name)?a.name:void 0);if(!d)return;const f=n.get(d);f?f.push(a):n.set(d,[a]),a.userData.modelhubOriginalMaterial===void 0&&(a.userData.modelhubOriginalMaterial=a.material)}),n}function ee(e){const t={};for(const[i,n]of e)t[i]=n.length;return t}function B(e,t,i){for(const n of e.get(t)??[])n.visible=i}function te(e,t){for(const i of e.keys())B(e,i,!t.has(i))}function ne(e,t,i){for(const n of e.get(t)??[])n.material=i}function ie(e,t){for(const i of e.get(t)??[]){const n=i.userData.modelhubOriginalMaterial;n&&(i.material=n)}}const k="#2196f3",re="#ff5722";function N(e,t={}){const{fill:i=k,text:n="#ffffff",textStroke:r="rgba(0, 0, 0, 0.45)"}=t,o=256,s=document.createElement("canvas");s.width=o,s.height=o;const c=s.getContext("2d");return c&&(c.beginPath(),c.arc(o/2,o/2,o/2-4,0,Math.PI*2),c.fillStyle=i,c.fill(),c.strokeStyle="#ffffff",c.lineWidth=8,c.stroke(),c.fillStyle=n,c.strokeStyle=r,c.lineWidth=10,c.font="bold 132px Arial, sans-serif",c.textAlign="center",c.textBaseline="middle",c.strokeText(String(e),o/2,o/2),c.fillText(String(e),o/2,o/2)),s}function D(e,t=.2,i){const n=new m.SpriteMaterial({map:new m.CanvasTexture(N(e,i)),transparent:!0,depthTest:!1}),r=new m.Sprite(n);return r.scale.set(t,t,1),r.renderOrder=999,r}function oe(e,t,i){var r;const n=e.material;(r=n.map)==null||r.dispose(),n.map=new m.CanvasTexture(N(t,{fill:i})),n.needsUpdate=!0}function se(e,t,i=.2,n){return t.map((r,o)=>{const s=D(o+1,i,n);return s.position.set(...r.position),s.name=`modelhub_marker_${r.annotation.id}`,s.userData.annotationId=r.annotation.id,s.userData.displayNumber=o+1,e.add(s),s})}function ae(e){const{camera:t,model:i,anchors:n,width:r,height:o,isOccluded:s}=e,c=e.referenceDistance??1,u=new m.Vector3,a={};i.updateMatrixWorld();for(const l of n){u.set(...l.position).applyMatrix4(i.matrixWorld);const d=u.distanceTo(t.position),f=s?s(u,d):!1,p=u.clone().project(t);a[l.annotation.id]={x:(p.x*.5+.5)*r,y:(-p.y*.5+.5)*o,scale:Math.min(1.6,Math.max(.55,c/Math.max(d,.001))),zIndex:Math.max(1,Math.round((1-p.z)*1e5))+(f?0:2e5),inView:p.z<1&&p.x>-1.05&&p.x<1.05&&p.y>-1.05&&p.y<1.05,occluded:f}}return a}const L=.03,ce={enabled:!1,isOccluded:()=>!1,dispose:()=>{}};async function le(e){var o;let t=[],i=[];if(e.traverse(s=>{if(!s.isMesh)return;const c=s.geometry;c!=null&&c.computeBoundsTree&&(t.push(c),i.push(s))}),!t.length)return ce;for(const s of t)s.boundsTree||(o=s.computeBoundsTree)==null||o.call(s,{maxLeafTris:8});const n=new m.Raycaster;n.firstHitOnly=!0;const r=new m.Vector3;return{enabled:!0,isOccluded(s,c,u){return r.subVectors(c,s.position).normalize(),n.set(s.position,r),n.near=0,n.far=Math.max(0,u-L),n.camera=s,n.intersectObjects(i,!1).length>0},dispose(){var s;for(const c of t)(s=c.disposeBoundsTree)==null||s.call(c);t=[],i=[]}}}const y={headlight:{ambient:.7,lights:[{color:[1,1,1],intensity:.9,position:[4,8,6]},{color:[1,1,1],intensity:2.4,position:[0,0,0],attach:!0,spot:!0}]},studio:{ambient:.85,lights:[{color:[.78,.8,1],intensity:1.45,position:[1.35,6.75,-7.26]},{color:[1,.88,.71],intensity:1.5,position:[-5.71,3.5,7.43]},{color:[.42,.74,1],intensity:.25,position:[7.23,6.78,1.29]}]},"dual-cam":{ambient:.6,lights:[{color:[.6,.48,.3],intensity:1.6,position:[-1,0,1],attach:!0},{color:[.42,.42,.6],intensity:1.6,position:[1,0,1],attach:!0}]},"studio-cam":{ambient:.7,lights:[{color:[.78,.8,1],intensity:1.35,position:[-1,.3,1],attach:!0},{color:[1,.88,.71],intensity:1.4,position:[1,.3,1],attach:!0},{color:[.42,.74,1],intensity:.25,position:[7.23,6.78,1.29]}]}},U="headlight";function ue(){return Object.keys(y)}function de(e){var t;(t=e.parent)==null||t.remove(e)}function fe(e){var c;const{scene:t,camera:i,exposure:n=1}=e;(c=e.previous)==null||c.remove();const r=y[e.preset??""]??y[U],o=[],s=new m.AmbientLight(16777215,r.ambient*n);t.add(s),o.push(s);for(const u of r.lights){let a;if(u.spot){const d=new m.SpotLight(new m.Color(...u.color));d.angle=.5,d.penumbra=.9,d.decay=0,a=d}else a=new m.DirectionalLight(new m.Color(...u.color));a.intensity=u.intensity,a.position.set(...u.position);const l=a.target;u.attach?(l==null||l.position.set(0,0,u.spot?-1:0),i.add(a),l&&i.add(l)):(t.add(a),l&&t.add(l)),o.push(a),l&&o.push(l)}return{lights:o,remove(){for(const u of o)de(u);o.length=0}}}const b=[{id:"white",label:"White",hex:"#ffffff",light:!0},{id:"light-grey",label:"Light grey",hex:"#d4d4d4",light:!0},{id:"medium-grey",label:"Medium grey",hex:"#808080",light:!1},{id:"dark-grey",label:"Dark grey",hex:"#252525",light:!1},{id:"black",label:"Black",hex:"#000000",light:!1}],F="dark-grey";function V(e){if(typeof e!="string")return"";const t=e.trim().replace(/^#/,"");return/^[0-9a-f]{6}$/i.test(t)?`#${t.toLowerCase()}`:/^[0-9a-f]{3}$/i.test(t)?`#${[...t].map(i=>i+i).join("").toLowerCase()}`:""}function P(e){const t=Number.parseInt(e.replace("#",""),16);return Number.isFinite(t)?(.299*(t>>16&255)+.587*(t>>8&255)+.114*(t&255))/255:0}function me(e,t){const i=V(t);return i?{id:"custom",label:"Custom",hex:i,light:P(i)>.5}:b.find(n=>n.id===e)??b.find(n=>n.id===F)??b[0]}const G=2;function w(e){e.updateMatrixWorld(!0);const t=new m.Box3,i=new m.Box3;return e.traverse(n=>{const r=n,o=n;r.isSkinnedMesh?(r.computeBoundingBox(),r.boundingBox&&(i.copy(r.boundingBox).applyMatrix4(r.matrixWorld),t.union(i))):o.isMesh&&o.geometry&&(o.geometry.boundingBox||o.geometry.computeBoundingBox(),o.geometry.boundingBox&&(i.copy(o.geometry.boundingBox).applyMatrix4(o.matrixWorld),t.union(i)))}),t.isEmpty()?new m.Box3().setFromObject(e):t}function pe(e,t=G){const n=w(e).getSize(new m.Vector3),r=Math.max(n.x,n.y,n.z)||1,o=t/r;e.scale.multiplyScalar(o);const s=w(e);return e.position.sub(s.getCenter(new m.Vector3)),o}function ge(e,t=1.3){return t/Math.tan(e*Math.PI/360)}const z=.5,W=1.5;function he(e,t,i={}){t.updateMatrixWorld();const n=new m.Vector3(...e.position).applyMatrix4(t.matrixWorld);if(e.camera){const u=new m.Vector3(...e.camera.eye).applyMatrix4(t.matrixWorld),l=new m.Vector3(...e.camera.target).applyMatrix4(t.matrixWorld).clone().sub(u);l.lengthSq()<1e-10&&l.copy(n).sub(u),l.normalize();const d=Math.max(n.distanceTo(u),.2);return{position:u,target:u.clone().addScaledVector(l,d),...e.camera.fov?{fov:e.camera.fov}:{}}}const r=i.outward??!0,o=new m.Vector3(n.x,0,n.z);o.lengthSq()<1e-8&&o.set(0,0,1),o.normalize();const s=r?-(i.outwardDistance??z):i.inwardDistance??W,c=n.clone().addScaledVector(o,s);return c.y=n.y,{position:c,target:n}}const xe={cancel:()=>{}};function be(e){const{camera:t,controls:i,to:n,onFrame:r,onDone:o}=e,s=()=>{r==null||r(),o==null||o()};if(e.reducedMotion)return t.position.copy(n.position),i.target.copy(n.target),i.update(),s(),xe;const c=e.durationMs??900,u=t.position.clone(),a=i.target.clone(),l=performance.now();let d=null;const f=p=>{const g=Math.min((p-l)/c,1),O=g*(2-g);t.position.lerpVectors(u,n.position,O),i.target.lerpVectors(a,n.target,O),i.update(),r==null||r(),g<1?d=requestAnimationFrame(f):(d=null,o==null||o())};return d=requestAnimationFrame(f),{cancel(){d!==null&&cancelAnimationFrame(d),d=null}}}function ye(e,t,i){const n=t||i;e.fov!==n&&(e.fov=n,e.updateProjectionMatrix())}const H=500;function Me(e){var r,o,s;if(!e)return"Model loaded, but it carries no educational metadata.";const t=[];(r=e.model)!=null&&r.title&&t.push(`${e.model.title} loaded`),(o=e.model)!=null&&o.altText&&t.push(e.model.altText);const i=((s=e.regions)==null?void 0:s.length)??0,n=M(e).length;return i&&t.push(`${i} labelled ${i===1?"region":"regions"}`),n&&t.push(`${n} ${n===1?"annotation":"annotations"}`),t.map(c=>c.replace(/\.$/,"")).join(". ")+"."}function Ie(e,t,i){return`Annotation ${t+1} of ${i}: ${e||"Untitled"}.`}function we(e,t=H,i=()=>Date.now()){let n=-1/0,r=null,o=null;const s=a=>{n=i(),r=null,e(a)};return{announce:a=>{const l=i()-n;if(l>=t){s(a);return}r=a,o||(o=setTimeout(()=>{o=null,r!==null&&s(r)},t-l))},flush:()=>{o&&(clearTimeout(o),o=null),r!==null&&s(r)}}}function E(e,t){return`## ${e}
|
|
2
|
+
${t}
|
|
3
|
+
|
|
4
|
+
`}function Te(e,t={}){const i=e.model??{},n=S(e),r=M(e);let o=`# ${i.title||"Untitled model"}
|
|
5
|
+
|
|
6
|
+
`;if(i.altText&&(o+=E(t.summaryHeading??"Summary",i.altText)),i.longDescription&&(o+=E("Full description",i.longDescription)),n.length){o+=`## Regions (${n.length})
|
|
7
|
+
|
|
8
|
+
`;for(const s of n)o+=`### ${I(s)}
|
|
9
|
+
${s.description||"No description."}
|
|
10
|
+
|
|
11
|
+
`}return r.length&&(o+=`## Annotations (${r.length})
|
|
12
|
+
|
|
13
|
+
`,r.forEach((s,c)=>{const u=s.regionId?` (${I(n.find(l=>l.id===s.regionId))})`:"",a=`${c+1}. ${s.title||"Untitled"}${u}`;o+=`### ${a}
|
|
14
|
+
${s.body||"No description."}
|
|
15
|
+
|
|
16
|
+
`})),o+=`## Licensing
|
|
17
|
+
`,o+=`- **License:** ${i.license||"Not specified"}
|
|
18
|
+
`,o+=`- **Attribution:** ${i.attribution||"Not specified"}
|
|
19
|
+
`,o+=`- **Creator:** ${i.creator||"Not specified"}
|
|
20
|
+
`,o+=`- **Source:** ${i.source||"Not specified"}
|
|
21
|
+
`,o}function Ae(e){var i;return`${(((i=e.model)==null?void 0:i.title)||"model").trim().replace(/[^\w\-. ]+/g,"").replace(/\s+/g,"_")||"model"}_transcript.md`}function Se(e){e&&e.traverse(t=>{var o,s;const i=t,n=i.geometry;n&&(n.boundsTree&&n.disposeBoundsTree&&n.disposeBoundsTree(),(o=n.dispose)==null||o.call(n));const r=[].concat(i.material??[]);for(const c of r)if(c){for(const u of Object.values(c)){const a=u;a&&a.isTexture&&a.dispose()}(s=c.dispose)==null||s.call(c)}})}Object.defineProperty(exports,"GlbParseError",{enumerable:!0,get:()=>h.GlbParseError});exports.BACKGROUND_OPTIONS=b;exports.CAMERA_ANNOUNCE_INTERVAL=H;exports.DEFAULT_BACKGROUND=F;exports.DEFAULT_LIGHTING=U;exports.LIGHTING_PRESETS=y;exports.MARKER_FILL=k;exports.MARKER_FILL_ACTIVE=re;exports.NORMALIZED_SIZE=G;exports.OCCLUSION_BIAS=L;exports.TOUR_DISTANCE_INWARD=W;exports.TOUR_DISTANCE_OUTWARD=z;exports.annotationSummary=Ie;exports.annotationsInReadingOrder=M;exports.applyFov=ye;exports.applyLighting=fe;exports.applyVisibilityDefaults=te;exports.buildRegionMeshMap=J;exports.buildTranscript=Te;exports.clearRegionHighlight=ie;exports.computeDisplayBox=w;exports.computeTourPlacement=he;exports.createAnnouncer=we;exports.createMarkerSprite=D;exports.createMarkerSprites=se;exports.createOcclusionIndex=le;exports.disposeSceneGraph=Se;exports.distanceForFov=ge;exports.drawMarkerCanvas=N;exports.errorsOf=R;exports.fetchBytes=$;exports.flyCamera=be;exports.frameModel=pe;exports.fromViewerPosition=Z;exports.highlightRegion=ne;exports.isVec3=T;exports.lightingPresetNames=ue;exports.loadModel=q;exports.logFindings=j;exports.luminance=P;exports.modelSummary=Me;exports.needsConversion=A;exports.normalizeAnnotationIds=C;exports.normalizeHexColor=V;exports.normalizeModel=Q;exports.parseBodySegments=X;exports.projectMarkers=ae;exports.readEmbedded=_;exports.regionBindingCounts=ee;exports.regionLabel=I;exports.regionsInOrder=S;exports.resolveBackground=me;exports.resourcePathFor=K;exports.setMarkerSpriteColor=oe;exports.setRegionVisible=B;exports.sidecarUrlFor=v;exports.toViewerPosition=x;exports.transcriptFileName=Ae;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @osuecampus/edu-modelhub-viewer-core
|
|
3
|
+
*
|
|
4
|
+
* The parts of an EDU_modelhub viewer that should not be written twice:
|
|
5
|
+
* loading metadata and failing closed without it, normalizing a payload into
|
|
6
|
+
* the shapes a UI binds to, binding regions to geometry, numbering and
|
|
7
|
+
* placing annotation markers, and moving the camera to them.
|
|
8
|
+
*
|
|
9
|
+
* Nothing here renders or owns a scene. A host brings its own three.js
|
|
10
|
+
* renderer and its own UI; this package supplies the behaviour underneath so
|
|
11
|
+
* two viewers of the same model agree about what it says.
|
|
12
|
+
*/
|
|
13
|
+
export { GlbParseError, errorsOf, fetchBytes, loadModel, logFindings, readEmbedded, resourcePathFor, sidecarUrlFor, type LoadOptions, type LoadedModel, type MetadataResult, type MetadataSource } from "./metadata.js";
|
|
14
|
+
export { fromViewerPosition, isVec3, needsConversion, toViewerPosition, type Vec3 } from "./coordinates.js";
|
|
15
|
+
export { annotationsInReadingOrder, normalizeAnnotationIds, normalizeModel, parseBodySegments, regionLabel, regionsInOrder, type BodySegment, type IdentifiedAnnotation, type MarkerAnchor, type NormalizedModel } from "./normalize.js";
|
|
16
|
+
export { applyVisibilityDefaults, buildRegionMeshMap, clearRegionHighlight, highlightRegion, regionBindingCounts, setRegionVisible, type GltfJsonLike, type RegionMeshMap } from "./regions.js";
|
|
17
|
+
export { MARKER_FILL, MARKER_FILL_ACTIVE, createMarkerSprite, createMarkerSprites, drawMarkerCanvas, projectMarkers, setMarkerSpriteColor, type MarkerColors, type MarkerScreenPosition, type ProjectMarkersOptions } from "./markers.js";
|
|
18
|
+
export { OCCLUSION_BIAS, createOcclusionIndex, type OcclusionIndex } from "./occlusion.js";
|
|
19
|
+
export { DEFAULT_LIGHTING, LIGHTING_PRESETS, applyLighting, lightingPresetNames, type LightSpec, type LightingHandle, type LightingOptions, type LightingPreset } from "./lighting.js";
|
|
20
|
+
export { BACKGROUND_OPTIONS, DEFAULT_BACKGROUND, luminance, normalizeHexColor, resolveBackground, type BackgroundOption } from "./backgrounds.js";
|
|
21
|
+
export { NORMALIZED_SIZE, computeDisplayBox, distanceForFov, frameModel } from "./framing.js";
|
|
22
|
+
export { TOUR_DISTANCE_INWARD, TOUR_DISTANCE_OUTWARD, applyFov, computeTourPlacement, flyCamera, type CameraPlacement, type ControlsLike, type Flight, type FlyOptions, type TourPlacementOptions } from "./camera.js";
|
|
23
|
+
export { CAMERA_ANNOUNCE_INTERVAL, annotationSummary, createAnnouncer, modelSummary } from "./announce.js";
|
|
24
|
+
export { buildTranscript, transcriptFileName, type TranscriptOptions } from "./transcript.js";
|
|
25
|
+
export { disposeSceneGraph } from "./dispose.js";
|