@needle-tools/gltf-progressive 1.0.0-alpha.4 → 1.0.0-alpha.6

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.
@@ -1,109 +1,109 @@
1
- import { BufferGeometry, Material, Mesh, Texture } from "three";
2
- import { type GLTF, type GLTFLoaderPlugin, GLTFParser } from "three/examples/jsm/loaders/GLTFLoader.js";
3
- export declare const EXTENSION_NAME = "NEEDLE_progressive";
4
- declare type NEEDLE_progressive_model_LOD = {
5
- path: string;
6
- hash?: string;
7
- };
8
- /** This is the data structure we have in the NEEDLE_progressive extension */
9
- declare type NEEDLE_progressive_model = {
10
- guid: string;
11
- lods: Array<NEEDLE_progressive_model_LOD>;
12
- };
13
- export declare type NEEDLE_progressive_texture_model = NEEDLE_progressive_model & {};
14
- export declare type NEEDLE_progressive_mesh_model = NEEDLE_progressive_model & {
15
- density: number;
16
- lods: Array<NEEDLE_progressive_model_LOD & {
17
- density: number;
18
- indexCount: number;
19
- vertexCount: number;
20
- }>;
21
- };
22
- /**
23
- * This is the result of a progressive texture loading event for a material's texture slot in {@link NEEDLE_progressive.assignTextureLOD}
24
- * @internal
25
- */
26
- export declare type ProgressiveMaterialTextureLoadingResult = {
27
- /** the material the progressive texture was loaded for */
28
- material: Material;
29
- /** the slot in the material where the texture was loaded */
30
- slot: string;
31
- /** the texture that was loaded (if any) */
32
- texture: Texture | null;
33
- /** the level of detail that was loaded */
34
- level: number;
35
- };
36
- /**
37
- * The NEEDLE_progressive extension for the GLTFLoader is responsible for loading progressive LODs for meshes and textures.
38
- * This extension can be used to load different resolutions of a mesh or texture at runtime (e.g. for LODs or progressive textures).
39
- * @example
40
- * ```javascript
41
- * const loader = new GLTFLoader();
42
- * loader.register(new NEEDLE_progressive());
43
- * loader.load("model.glb", (gltf) => {
44
- * const mesh = gltf.scene.children[0] as Mesh;
45
- * NEEDLE_progressive.assignMeshLOD(context, sourceId, mesh, 1).then(mesh => {
46
- * console.log("Mesh with LOD level 1 loaded", mesh);
47
- * });
48
- * });
49
- * ```
50
- */
51
- export declare class NEEDLE_progressive implements GLTFLoaderPlugin {
52
- /** The name of the extension */
53
- get name(): string;
54
- static getMeshLODInformation(geo: BufferGeometry): NEEDLE_progressive_mesh_model | null;
55
- /** Check if a LOD level is available for a mesh or a texture
56
- * @param obj the mesh or texture to check
57
- * @param level the level of detail to check for (0 is the highest resolution). If undefined, the function checks if any LOD level is available
58
- * @returns true if the LOD level is available (or if any LOD level is available if level is undefined)
59
- */
60
- static hasLODLevelAvailable(obj: Mesh | BufferGeometry | Texture | Material, level?: number): boolean;
61
- /** Load a different resolution of a mesh (if available)
62
- * @param context the context
63
- * @param source the sourceid of the file from which the mesh is loaded (this is usually the component's sourceId)
64
- * @param mesh the mesh to load the LOD for
65
- * @param level the level of detail to load (0 is the highest resolution)
66
- * @returns a promise that resolves to the mesh with the requested LOD level
67
- * @example
68
- * ```javascript
69
- * const mesh = this.gameObject as Mesh;
70
- * NEEDLE_progressive.assignMeshLOD(context, sourceId, mesh, 1).then(mesh => {
71
- * console.log("Mesh with LOD level 1 loaded", mesh);
72
- * });
73
- * ```
74
- */
75
- static assignMeshLOD(mesh: Mesh, level: number): Promise<BufferGeometry | null>;
76
- /** Load a different resolution of a texture (if available)
77
- * @param context the context
78
- * @param source the sourceid of the file from which the texture is loaded (this is usually the component's sourceId)
79
- * @param materialOrTexture the material or texture to load the LOD for (if passing in a material all textures in the material will be loaded)
80
- * @param level the level of detail to load (0 is the highest resolution) - currently only 0 is supported
81
- * @returns a promise that resolves to the material or texture with the requested LOD level
82
- */
83
- static assignTextureLOD(materialOrTexture: Material | Texture, level?: number): Promise<Array<ProgressiveMaterialTextureLoadingResult> | Texture | null>;
84
- private static assignTextureLODForSlot;
85
- private readonly parser;
86
- private readonly url;
87
- constructor(parser: GLTFParser, url: string);
88
- afterRoot(gltf: GLTF): null;
89
- /**
90
- * Register a texture with LOD information
91
- */
92
- static registerTexture: (url: string, tex: Texture, index: number, ext: NEEDLE_progressive_texture_model) => void;
93
- /**
94
- * Register a mesh with LOD information
95
- */
96
- static registerMesh: (url: string, key: string, mesh: Mesh, level: number, index: number | undefined, ext: NEEDLE_progressive_mesh_model) => void;
97
- /** A map of key = asset uuid and value = LOD information */
98
- private static readonly lodInfos;
99
- /** cache of already loaded mesh lods */
100
- private static readonly previouslyLoaded;
101
- /** this contains the geometry/textures that were originally loaded */
102
- private static readonly lowresCache;
103
- private static getOrLoadLOD;
104
- private static assignLODInformation;
105
- private static getAssignedLODInformation;
106
- private static readonly _copiedTextures;
107
- private static copySettings;
108
- }
109
- export {};
1
+ import { BufferGeometry, Material, Mesh, Texture } from "three";
2
+ import { type GLTF, type GLTFLoaderPlugin, GLTFParser } from "three/examples/jsm/loaders/GLTFLoader.js";
3
+ export declare const EXTENSION_NAME = "NEEDLE_progressive";
4
+ declare type NEEDLE_progressive_model_LOD = {
5
+ path: string;
6
+ hash?: string;
7
+ };
8
+ /** This is the data structure we have in the NEEDLE_progressive extension */
9
+ declare type NEEDLE_progressive_model = {
10
+ guid: string;
11
+ lods: Array<NEEDLE_progressive_model_LOD>;
12
+ };
13
+ export declare type NEEDLE_progressive_texture_model = NEEDLE_progressive_model & {};
14
+ export declare type NEEDLE_progressive_mesh_model = NEEDLE_progressive_model & {
15
+ density: number;
16
+ lods: Array<NEEDLE_progressive_model_LOD & {
17
+ density: number;
18
+ indexCount: number;
19
+ vertexCount: number;
20
+ }>;
21
+ };
22
+ /**
23
+ * This is the result of a progressive texture loading event for a material's texture slot in {@link NEEDLE_progressive.assignTextureLOD}
24
+ * @internal
25
+ */
26
+ export declare type ProgressiveMaterialTextureLoadingResult = {
27
+ /** the material the progressive texture was loaded for */
28
+ material: Material;
29
+ /** the slot in the material where the texture was loaded */
30
+ slot: string;
31
+ /** the texture that was loaded (if any) */
32
+ texture: Texture | null;
33
+ /** the level of detail that was loaded */
34
+ level: number;
35
+ };
36
+ /**
37
+ * The NEEDLE_progressive extension for the GLTFLoader is responsible for loading progressive LODs for meshes and textures.
38
+ * This extension can be used to load different resolutions of a mesh or texture at runtime (e.g. for LODs or progressive textures).
39
+ * @example
40
+ * ```javascript
41
+ * const loader = new GLTFLoader();
42
+ * loader.register(new NEEDLE_progressive());
43
+ * loader.load("model.glb", (gltf) => {
44
+ * const mesh = gltf.scene.children[0] as Mesh;
45
+ * NEEDLE_progressive.assignMeshLOD(context, sourceId, mesh, 1).then(mesh => {
46
+ * console.log("Mesh with LOD level 1 loaded", mesh);
47
+ * });
48
+ * });
49
+ * ```
50
+ */
51
+ export declare class NEEDLE_progressive implements GLTFLoaderPlugin {
52
+ /** The name of the extension */
53
+ get name(): string;
54
+ static getMeshLODInformation(geo: BufferGeometry): NEEDLE_progressive_mesh_model | null;
55
+ /** Check if a LOD level is available for a mesh or a texture
56
+ * @param obj the mesh or texture to check
57
+ * @param level the level of detail to check for (0 is the highest resolution). If undefined, the function checks if any LOD level is available
58
+ * @returns true if the LOD level is available (or if any LOD level is available if level is undefined)
59
+ */
60
+ static hasLODLevelAvailable(obj: Mesh | BufferGeometry | Texture | Material, level?: number): boolean;
61
+ /** Load a different resolution of a mesh (if available)
62
+ * @param context the context
63
+ * @param source the sourceid of the file from which the mesh is loaded (this is usually the component's sourceId)
64
+ * @param mesh the mesh to load the LOD for
65
+ * @param level the level of detail to load (0 is the highest resolution)
66
+ * @returns a promise that resolves to the mesh with the requested LOD level
67
+ * @example
68
+ * ```javascript
69
+ * const mesh = this.gameObject as Mesh;
70
+ * NEEDLE_progressive.assignMeshLOD(context, sourceId, mesh, 1).then(mesh => {
71
+ * console.log("Mesh with LOD level 1 loaded", mesh);
72
+ * });
73
+ * ```
74
+ */
75
+ static assignMeshLOD(mesh: Mesh, level: number): Promise<BufferGeometry | null>;
76
+ /** Load a different resolution of a texture (if available)
77
+ * @param context the context
78
+ * @param source the sourceid of the file from which the texture is loaded (this is usually the component's sourceId)
79
+ * @param materialOrTexture the material or texture to load the LOD for (if passing in a material all textures in the material will be loaded)
80
+ * @param level the level of detail to load (0 is the highest resolution) - currently only 0 is supported
81
+ * @returns a promise that resolves to the material or texture with the requested LOD level
82
+ */
83
+ static assignTextureLOD(materialOrTexture: Material | Texture, level?: number): Promise<Array<ProgressiveMaterialTextureLoadingResult> | Texture | null>;
84
+ private static assignTextureLODForSlot;
85
+ private readonly parser;
86
+ private readonly url;
87
+ constructor(parser: GLTFParser, url: string);
88
+ afterRoot(gltf: GLTF): null;
89
+ /**
90
+ * Register a texture with LOD information
91
+ */
92
+ static registerTexture: (url: string, tex: Texture, index: number, ext: NEEDLE_progressive_texture_model) => void;
93
+ /**
94
+ * Register a mesh with LOD information
95
+ */
96
+ static registerMesh: (url: string, key: string, mesh: Mesh, level: number, index: number | undefined, ext: NEEDLE_progressive_mesh_model) => void;
97
+ /** A map of key = asset uuid and value = LOD information */
98
+ private static readonly lodInfos;
99
+ /** cache of already loaded mesh lods */
100
+ private static readonly previouslyLoaded;
101
+ /** this contains the geometry/textures that were originally loaded */
102
+ private static readonly lowresCache;
103
+ private static getOrLoadLOD;
104
+ private static assignLODInformation;
105
+ private static getAssignedLODInformation;
106
+ private static readonly _copiedTextures;
107
+ private static copySettings;
108
+ }
109
+ export {};