@vulfram/gltf-loader 0.22.5-alpha → 0.23.0-beta

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/README.md CHANGED
@@ -3,4 +3,25 @@
3
3
  Loads `.gltf` and `.glb` content into `@vulfram/engine` 3D worlds.
4
4
 
5
5
  The loader follows the engine host-side math convention and exposes transforms as
6
- `gl-matrix` `vec3` / `quat`.
6
+ `@vulfram/engine/math` `vec3` / `quat`.
7
+
8
+ ## Example
9
+
10
+ ```ts
11
+ import { loadGltfAsset } from '@vulfram/gltf-loader';
12
+
13
+ const asset = await loadGltfAsset({
14
+ worldId,
15
+ data: glbBytes
16
+ });
17
+
18
+ const instance = asset.instantiate({
19
+ rootTransform: {
20
+ position: [0, 0, 0]
21
+ }
22
+ });
23
+
24
+ // Later:
25
+ instance.disposeEntities();
26
+ asset.disposeAll();
27
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vulfram/gltf-loader",
3
- "version": "0.22.5-alpha",
3
+ "version": "0.23.0-beta",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -19,12 +19,11 @@
19
19
  },
20
20
  "devDependencies": {
21
21
  "@types/bun": "^1.3.11",
22
- "@vulfram/engine": "^0.22.5-alpha"
22
+ "@vulfram/engine": "^0.23.0-beta"
23
23
  },
24
24
  "dependencies": {
25
25
  "@gltf-transform/core": "^4.3.0",
26
26
  "@gltf-transform/extensions": "^4.3.0",
27
- "@gltf-transform/functions": "^4.3.0",
28
- "gl-matrix": "^3.4.4"
27
+ "@gltf-transform/functions": "^4.3.0"
29
28
  }
30
29
  }
package/src/convert.ts CHANGED
@@ -1,12 +1,5 @@
1
1
  import { Accessor, TextureInfo } from '@gltf-transform/core';
2
- import {
3
- quat,
4
- vec3,
5
- vec4,
6
- type quat as Quat,
7
- type vec3 as Vec3,
8
- type vec4 as Vec4
9
- } from 'gl-matrix';
2
+ import { quat, vec3, vec4, type Quat, type Vec3, type Vec4 } from '@vulfram/engine/math';
10
3
  import type { GeometryPrimitiveEntry, SamplerMode } from '@vulfram/engine/types';
11
4
  import { U16_MAX } from './constants';
12
5
  import { GltfLoaderError } from './errors';
package/src/errors.ts CHANGED
@@ -1,6 +1,21 @@
1
1
  import type { GltfLoaderErrorCode } from './types';
2
2
 
3
- /** Loader error with stable error code for callers. */
3
+ /**
4
+ * Loader error with a stable error code for caller handling.
5
+ *
6
+ * @example
7
+ * ```ts
8
+ * import { GltfLoaderError, loadGltfAsset } from '@vulfram/gltf-loader';
9
+ *
10
+ * try {
11
+ * await loadGltfAsset({ worldId, data });
12
+ * } catch (error) {
13
+ * if (error instanceof GltfLoaderError) {
14
+ * console.error(error.code, error.message);
15
+ * }
16
+ * }
17
+ * ```
18
+ */
4
19
  export class GltfLoaderError extends Error {
5
20
  constructor(
6
21
  public readonly code: GltfLoaderErrorCode,
package/src/index.ts CHANGED
@@ -32,6 +32,22 @@ export { GltfLoaderError } from './errors';
32
32
  *
33
33
  * The returned asset can instantiate entity graphs multiple times, reusing
34
34
  * uploaded textures/materials/geometries across instances.
35
+ *
36
+ * @example
37
+ * ```ts
38
+ * import { loadGltfAsset } from '@vulfram/gltf-loader';
39
+ *
40
+ * const asset = await loadGltfAsset({
41
+ * worldId,
42
+ * data: glbBytes
43
+ * });
44
+ *
45
+ * const instance = asset.instantiate({
46
+ * rootTransform: {
47
+ * position: [0, 0, 0]
48
+ * }
49
+ * });
50
+ * ```
35
51
  */
36
52
  export async function loadGltfAsset(input: GltfLoadInput): Promise<LoadedGltfAsset> {
37
53
  const document = await readDocument(input);
@@ -107,6 +123,19 @@ export async function loadGltfAsset(input: GltfLoadInput): Promise<LoadedGltfAss
107
123
  * Legacy one-shot API.
108
124
  *
109
125
  * Loads resources and immediately instantiates one entity graph.
126
+ *
127
+ * Use this when you only need one scene instance and do not need to keep the
128
+ * reusable asset template around.
129
+ *
130
+ * @example
131
+ * ```ts
132
+ * import { loadGltfScene } from '@vulfram/gltf-loader';
133
+ *
134
+ * const result = await loadGltfScene({
135
+ * worldId,
136
+ * data: glbBytes
137
+ * });
138
+ * ```
110
139
  */
111
140
  export async function loadGltfScene(input: GltfLoadInput): Promise<GltfLoadResult> {
112
141
  const asset = await loadGltfAsset(input);
package/src/resources.ts CHANGED
@@ -7,7 +7,7 @@ import {
7
7
  type MaterialId,
8
8
  type TextureId
9
9
  } from '@vulfram/engine/world3d';
10
- import { vec4 } from 'gl-matrix';
10
+ import { vec4 } from '@vulfram/engine/math';
11
11
  import type { GeometryPrimitiveEntry } from '@vulfram/engine/types';
12
12
  import { uploadBytes } from './context';
13
13
  import {
package/src/scene.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { Node, Scene } from '@gltf-transform/core';
2
- import type { quat as Quat, vec3 as Vec3 } from 'gl-matrix';
2
+ import type { Quat, Vec3 } from '@vulfram/engine/math';
3
3
  import {
4
4
  create3DEntity,
5
5
  create3DModel,
package/src/types.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { Accessor, Material, Node, Primitive, Texture } from '@gltf-transform/core';
2
- import type { quat, vec3 } from 'gl-matrix';
2
+ import type { Quat as quat, Vec3 as vec3 } from '@vulfram/engine/math';
3
3
  import type {
4
4
  EntityId,
5
5
  GeometryId,
@@ -26,7 +26,12 @@ export interface GltfInstantiateOptions {
26
26
  rootTransform?: RootTransform;
27
27
  }
28
28
 
29
- /** One instantiated scene graph from a loaded glTF asset. */
29
+ /**
30
+ * One instantiated scene graph from a loaded glTF asset.
31
+ *
32
+ * The instance owns only its created entities. Shared resources remain owned by
33
+ * the parent `LoadedGltfAsset` until `disposeAll()` is called there.
34
+ */
30
35
  export interface GltfInstance {
31
36
  rootEntityId: EntityId;
32
37
  entityIds: EntityId[];
@@ -59,7 +64,13 @@ export interface LoadedResourceIds {
59
64
  textures: TextureId[];
60
65
  }
61
66
 
62
- /** Loaded glTF asset with reusable resources and instantiation API. */
67
+ /**
68
+ * Loaded glTF asset with reusable resources and instantiation API.
69
+ *
70
+ * Use `instantiate()` to create one or more entity graphs, `disposeEntities()`
71
+ * to remove only active instances, and `disposeAll()` to also release the shared
72
+ * textures, materials, and geometries created for this asset.
73
+ */
63
74
  export interface LoadedGltfAsset {
64
75
  worldId: World3DId;
65
76
  warnings: string[];
@@ -70,7 +81,13 @@ export interface LoadedGltfAsset {
70
81
  disposeAll(): void;
71
82
  }
72
83
 
73
- /** Input descriptor for glTF/GLB loading. */
84
+ /**
85
+ * Input descriptor for glTF/GLB loading.
86
+ *
87
+ * `data` is the main `.glb` or `.gltf` payload. When loading external-buffer or
88
+ * external-texture `.gltf` files, provide the extra file contents in `resources`
89
+ * keyed by their URI.
90
+ */
74
91
  export interface GltfLoadInput {
75
92
  worldId: World3DId;
76
93
  data: BinaryLike;
@@ -81,7 +98,7 @@ export interface GltfLoadInput {
81
98
  labelPrefix?: string;
82
99
  }
83
100
 
84
- /** Result summary for a loaded glTF scene. */
101
+ /** Result summary for the legacy one-shot `loadGltfScene()` API. */
85
102
  export interface GltfLoadResult {
86
103
  rootEntityId: EntityId;
87
104
  entityCount: number;