lecodes-gl-lite 2.0.0 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +4 -4
- package/src/index.ts +6 -0
- package/src/webgl/createViewerLite.ts +5 -2
- package/src/webgl/stores.ts +28 -0
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lecodes-gl-lite",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"main": "src/index.ts",
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"ogl": "^1.0.11",
|
|
7
|
-
"lecodes-sdk": "2.0.
|
|
8
|
-
"lecodes-web-runtime": "2.0.
|
|
9
|
-
"lecodes-web-shared": "2.0.
|
|
7
|
+
"lecodes-sdk": "2.0.2",
|
|
8
|
+
"lecodes-web-runtime": "2.0.2",
|
|
9
|
+
"lecodes-web-shared": "2.0.2"
|
|
10
10
|
},
|
|
11
11
|
"scripts": {
|
|
12
12
|
"dev": "vite",
|
package/src/index.ts
CHANGED
|
@@ -3,3 +3,9 @@
|
|
|
3
3
|
// library (an editor's viewport); the web host runs Filament, not this.
|
|
4
4
|
export { createViewerLite, basePropsLite } from './webgl/createViewerLite'
|
|
5
5
|
export type { ViewerOptions } from './webgl/createViewerLite'
|
|
6
|
+
// The stores of an engine on its own (what it fetched, what it captured), and their shape for a
|
|
7
|
+
// host that hands over its own.
|
|
8
|
+
export { ownStores } from './webgl/stores'
|
|
9
|
+
export type { EngineStores } from './webgl/stores'
|
|
10
|
+
// KTX2 as a picture (the basis transcoder, no GPU): an editor's thumbnails.
|
|
11
|
+
export { decodeKtx2Image, isKtx2Bytes } from './webgl/decoders'
|
|
@@ -20,8 +20,7 @@
|
|
|
20
20
|
// bloom (no-op). The headless backend records those instead (recording.ts).
|
|
21
21
|
|
|
22
22
|
import { Camera, Geometry, Mesh, GLTFSkin, Program, Renderer, RenderTarget, Texture, Transform, type OGLRenderingContext } from 'ogl'
|
|
23
|
-
import {
|
|
24
|
-
import { getPlayer, removePlayers } from 'lecodes-web-shared/src/utils/mediaplayer'
|
|
23
|
+
import { ownStores, type EngineStores } from './stores'
|
|
25
24
|
import type { CanvasHost } from 'lecodes-web-shared/src/canvas/createCanvasHost'
|
|
26
25
|
import {
|
|
27
26
|
identity, intersectRayBox, intersectRaySphere, invertTRS, multiply, orthographic,
|
|
@@ -66,6 +65,9 @@ export type ViewerOptions = {
|
|
|
66
65
|
/** Clear to transparent instead of the skybox color (and open the context with an alpha
|
|
67
66
|
* channel). Capture hosts use this so PNG thumbnails composite over any page theme. */
|
|
68
67
|
transparent?: boolean
|
|
68
|
+
/** The fetched buffers and the media players of the host the engine runs under (./stores.ts);
|
|
69
|
+
* absent = the engine's own. */
|
|
70
|
+
stores?: EngineStores
|
|
69
71
|
}
|
|
70
72
|
|
|
71
73
|
const FOV = 60 // vertical fov set by the native setViewport (scene.cpp) — matches the core default
|
|
@@ -110,6 +112,7 @@ const GLTF_UNIFORM_ALIAS: Record<string, string> = {
|
|
|
110
112
|
}
|
|
111
113
|
|
|
112
114
|
export const createViewerLite = async (canvas: HTMLCanvasElement, options: ViewerOptions = {}) => {
|
|
115
|
+
const { fetch: _fetch, getBlob, getBuffer: getFetchedBuffer, getLocalName, hasLocalBuffer, putBuffer, putLocalBuffer, getPlayer, removePlayers } = options.stores ?? ownStores
|
|
113
116
|
const renderer = new Renderer({
|
|
114
117
|
canvas,
|
|
115
118
|
dpr: 1, // set per-resize to the host's resolution factor (devicePixelRatio × CSS zoom); see _onResize
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// What the engine reads of whoever embeds it: the buffers that were fetched (a GLB, a texture, a
|
|
2
|
+
// shader — by the id the SDK holds) and the media players behind a video texture.
|
|
3
|
+
//
|
|
4
|
+
// An engine on its own (an editor's viewport with no host under it) keeps them itself: `ownStores`.
|
|
5
|
+
// An engine under a host (lecodes-web-host's `engine3d`) is HANDED the host's — the bundle fetches
|
|
6
|
+
// through the host, and the id it passes to the engine is an id of the host's store. The shape is
|
|
7
|
+
// written out here, with no type of another package in it: the host writes the same shape in its
|
|
8
|
+
// own contract.
|
|
9
|
+
import { _fetch, getBlob, getBuffer, getLocalName, hasLocalBuffer, putBuffer, putLocalBuffer } from 'lecodes-web-shared/src/utils/fetch'
|
|
10
|
+
import { getPlayer, removePlayers } from 'lecodes-web-shared/src/utils/mediaplayer'
|
|
11
|
+
|
|
12
|
+
export type EngineStores = {
|
|
13
|
+
fetch(url: string, options: any, onComplete: (systemId: number, statusCode: number) => void, onReject: (err: Error) => void): unknown
|
|
14
|
+
getBuffer(systemId: number): ArrayBuffer
|
|
15
|
+
getBlob(systemId: number): Blob
|
|
16
|
+
/** Store bytes; the id they are read back by. */
|
|
17
|
+
putBuffer(buffer: ArrayBuffer): number
|
|
18
|
+
/** A resource of the app's own, by name (what `fetchLocal` answers with). */
|
|
19
|
+
putLocalBuffer(name: string, buffer: ArrayBuffer): void
|
|
20
|
+
hasLocalBuffer(name: string): boolean
|
|
21
|
+
/** The name a local resource's id was made from. */
|
|
22
|
+
getLocalName(systemId: number): string | undefined
|
|
23
|
+
getPlayer(id: number): HTMLVideoElement | HTMLAudioElement | null | undefined
|
|
24
|
+
removePlayers(): void
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** The engine's own stores: what it uses when it is handed none. */
|
|
28
|
+
export const ownStores: EngineStores = { fetch: _fetch, getBuffer, getBlob, putBuffer, putLocalBuffer, hasLocalBuffer, getLocalName, getPlayer, removePlayers }
|