@needle-tools/gltf-progressive 1.0.0-alpha.9 → 1.1.0-alpha.1
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 +39 -0
- package/README.md +92 -0
- package/examples/modelviewer.html +27 -0
- package/examples/react-three-fiber/.prettierrc +10 -0
- package/examples/react-three-fiber/favicon.png +0 -0
- package/examples/react-three-fiber/index.html +24 -0
- package/examples/react-three-fiber/package-lock.json +4023 -0
- package/examples/react-three-fiber/package.json +34 -0
- package/examples/react-three-fiber/tsconfig.json +22 -0
- package/examples/react-three-fiber/vite.config.js +39 -0
- package/examples/threejs/index.html +51 -0
- package/examples/threejs/main.js +76 -0
- package/gltf-progressive.js +462 -316
- package/gltf-progressive.min.js +5 -3
- package/gltf-progressive.umd.cjs +5 -3
- package/lib/extension.d.ts +8 -2
- package/lib/extension.js +102 -11
- package/lib/index.d.ts +5 -4
- package/lib/index.js +6 -4
- package/lib/loaders.d.ts +10 -0
- package/lib/loaders.js +21 -2
- package/lib/lods_manager.d.ts +50 -3
- package/lib/lods_manager.js +354 -219
- package/lib/plugins/index.d.ts +1 -1
- package/lib/plugins/index.js +0 -1
- package/lib/plugins/modelviewer.js +7 -3
- package/lib/plugins/plugin.d.ts +4 -5
- package/lib/plugins/plugin.js +0 -6
- package/lib/utils.d.ts +13 -0
- package/lib/utils.js +24 -0
- package/package.json +1 -1
package/lib/lods_manager.d.ts
CHANGED
|
@@ -1,10 +1,37 @@
|
|
|
1
1
|
import { Frustum, Matrix4, Object3D, Vector3, WebGLRenderer } from "three";
|
|
2
2
|
import { NEEDLE_progressive_plugin } from "./plugins/plugin.js";
|
|
3
|
+
export declare type LOD_Results = {
|
|
4
|
+
mesh_lod: number;
|
|
5
|
+
texture_lod: number;
|
|
6
|
+
};
|
|
3
7
|
/**
|
|
4
8
|
* The LODsManager class is responsible for managing the LODs and progressive assets in the scene. It will automatically update the LODs based on the camera position, screen coverage and mesh density of the objects.
|
|
5
9
|
* It must be enabled by calling the `enable` method.
|
|
6
10
|
*
|
|
7
11
|
* Instead of using the LODs manager directly you can also call `useNeedleProgressive` to enable progressive loading for a GLTFLoader
|
|
12
|
+
*
|
|
13
|
+
* ### Plugins
|
|
14
|
+
* Use {@link LODsManager.addPlugin} to add a plugin to the LODsManager. A plugin can be used to hook into the LOD update process and modify the LOD levels or perform other actions.
|
|
15
|
+
*
|
|
16
|
+
* @example Adding a LODsManager to a Three.js scene:
|
|
17
|
+
* ```ts
|
|
18
|
+
* import { LODsManager } from "@needle-tools/gltf-progressive";
|
|
19
|
+
* import { WebGLRenderer, Scene, Camera, Mesh } from "three";
|
|
20
|
+
*
|
|
21
|
+
* const renderer = new WebGLRenderer();
|
|
22
|
+
* const lodsManager = LODsManager.get(renderer);
|
|
23
|
+
* lodsManager.enable();
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* @example Using the LODsManager with a GLTFLoader:
|
|
27
|
+
* ```ts
|
|
28
|
+
* import { useNeedleProgressive } from "@needle-tools/gltf-progressive";
|
|
29
|
+
* import { GLTFLoader } from "three/examples/jsm/loaders/GLTFLoader.js";
|
|
30
|
+
*
|
|
31
|
+
* const url = 'https://yourdomain.com/yourmodel.glb';
|
|
32
|
+
* const loader = new GLTFLoader();
|
|
33
|
+
* const lodsManager = useNeedleProgressive(url, renderer, loader);
|
|
34
|
+
* ```
|
|
8
35
|
*/
|
|
9
36
|
export declare class LODsManager {
|
|
10
37
|
/** Assign a function to draw debug lines for the LODs. This function will be called with the start and end position of the line and the color of the line when the `debugprogressive` query parameter is set.
|
|
@@ -12,9 +39,24 @@ export declare class LODsManager {
|
|
|
12
39
|
static debugDrawLine?: (a: Vector3, b: Vector3, color: number) => void;
|
|
13
40
|
/** @internal */
|
|
14
41
|
static getObjectLODState(object: Object3D): LOD_state | undefined;
|
|
42
|
+
static addPlugin(plugin: NEEDLE_progressive_plugin): void;
|
|
43
|
+
static removePlugin(plugin: NEEDLE_progressive_plugin): void;
|
|
44
|
+
/**
|
|
45
|
+
* Gets the LODsManager for the given renderer. If the LODsManager does not exist yet, it will be created.
|
|
46
|
+
* @param renderer The renderer to get the LODsManager for.
|
|
47
|
+
* @returns The LODsManager instance.
|
|
48
|
+
*/
|
|
49
|
+
static get(renderer: WebGLRenderer): LODsManager;
|
|
15
50
|
readonly renderer: WebGLRenderer;
|
|
16
51
|
readonly projectionScreenMatrix: Matrix4;
|
|
17
52
|
readonly cameraFrustrum: Frustum;
|
|
53
|
+
/** @deprecated use static `LODsManager.addPlugin()` method. This getter will be removed in later versions */
|
|
54
|
+
get plugins(): NEEDLE_progressive_plugin[];
|
|
55
|
+
/**
|
|
56
|
+
* The target triangle density is the desired max amount of triangles on screen when the mesh is filling the screen.
|
|
57
|
+
* @default 200_000
|
|
58
|
+
*/
|
|
59
|
+
targetTriangleDensity: number;
|
|
18
60
|
/**
|
|
19
61
|
* The update interval in frames. If set to 0, the LODs will be updated every frame. If set to 1, the LODs will be updated every second frame, etc.
|
|
20
62
|
*/
|
|
@@ -23,8 +65,8 @@ export declare class LODsManager {
|
|
|
23
65
|
* If set to true, the LODsManager will not update the LODs.
|
|
24
66
|
*/
|
|
25
67
|
pause: boolean;
|
|
26
|
-
|
|
27
|
-
|
|
68
|
+
private constructor();
|
|
69
|
+
private _frame;
|
|
28
70
|
private _originalRender?;
|
|
29
71
|
/**
|
|
30
72
|
* Enable the LODsManager. This will replace the render method of the renderer with a method that updates the LODs.
|
|
@@ -50,6 +92,7 @@ export declare class LODsManager {
|
|
|
50
92
|
private loadProgressiveMeshes;
|
|
51
93
|
private readonly _sphere;
|
|
52
94
|
private readonly _tempBox;
|
|
95
|
+
private readonly _tempBox2;
|
|
53
96
|
private readonly tempMatrix;
|
|
54
97
|
private readonly _tempWorldPosition;
|
|
55
98
|
private readonly _tempBoxSize;
|
|
@@ -58,10 +101,14 @@ export declare class LODsManager {
|
|
|
58
101
|
private static corner1;
|
|
59
102
|
private static corner2;
|
|
60
103
|
private static corner3;
|
|
104
|
+
private static readonly _tempPtInside;
|
|
105
|
+
private static isInside;
|
|
61
106
|
private calculateLodLevel;
|
|
62
107
|
}
|
|
63
108
|
declare class LOD_state {
|
|
64
|
-
|
|
109
|
+
frames: number;
|
|
110
|
+
lastLodLevel_Mesh: number;
|
|
111
|
+
lasLodLevel_Texture: number;
|
|
65
112
|
lastScreenCoverage: number;
|
|
66
113
|
readonly lastScreenspaceVolume: Vector3;
|
|
67
114
|
lastCentrality: number;
|