@needle-tools/gltf-progressive 3.4.0-next.dbcee85 → 3.5.0-canary.4d42385
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 +3 -0
- package/LICENSE +21 -0
- package/README.md +9 -0
- package/gltf-progressive.js +745 -576
- package/gltf-progressive.min.js +9 -8
- package/gltf-progressive.umd.cjs +8 -7
- package/lib/extension.d.ts +64 -4
- package/lib/extension.js +160 -27
- package/lib/lods.manager.d.ts +63 -3
- package/lib/lods.manager.js +70 -2
- package/lib/utils.internal.d.ts +8 -2
- package/lib/utils.internal.js +95 -2
- package/lib/version.js +1 -1
- package/lib/worker/loader.mainthread.js +1 -1
- package/package.json +4 -2
- /package/lib/worker/{loader.worker.js → gltf-progressive.worker.js} +0 -0
package/lib/utils.internal.js
CHANGED
|
@@ -71,10 +71,11 @@ export class PromiseQueue {
|
|
|
71
71
|
_running = new Map();
|
|
72
72
|
_queue = [];
|
|
73
73
|
debug = false;
|
|
74
|
-
constructor(maxConcurrent
|
|
74
|
+
constructor(maxConcurrent, opts = {}) {
|
|
75
75
|
this.maxConcurrent = maxConcurrent;
|
|
76
76
|
this.debug = opts.debug ?? false;
|
|
77
|
-
window
|
|
77
|
+
if (typeof window !== "undefined")
|
|
78
|
+
window.requestAnimationFrame(this.tick);
|
|
78
79
|
}
|
|
79
80
|
tick = () => {
|
|
80
81
|
this.internalUpdate();
|
|
@@ -115,3 +116,95 @@ export class PromiseQueue {
|
|
|
115
116
|
}
|
|
116
117
|
}
|
|
117
118
|
}
|
|
119
|
+
// #region Texture Memory
|
|
120
|
+
export function determineTextureMemoryInBytes(texture) {
|
|
121
|
+
const width = texture.image?.width ?? 0;
|
|
122
|
+
const height = texture.image?.height ?? 0;
|
|
123
|
+
const depth = texture.image?.depth ?? 1;
|
|
124
|
+
const mipLevels = Math.floor(Math.log2(Math.max(width, height, depth))) + 1;
|
|
125
|
+
const bytesPerPixel = getBytesPerPixel(texture);
|
|
126
|
+
const totalBytes = (width * height * depth * bytesPerPixel * (1 - Math.pow(0.25, mipLevels))) / (1 - 0.25);
|
|
127
|
+
return totalBytes;
|
|
128
|
+
}
|
|
129
|
+
function getBytesPerPixel(texture) {
|
|
130
|
+
// Determine channel count from format
|
|
131
|
+
let channels = 4; // Default RGBA
|
|
132
|
+
const format = texture.format;
|
|
133
|
+
if (format === 1024)
|
|
134
|
+
channels = 1; // RedFormat
|
|
135
|
+
else if (format === 1025)
|
|
136
|
+
channels = 1; // RedIntegerFormat
|
|
137
|
+
else if (format === 1026)
|
|
138
|
+
channels = 2; // RGFormat
|
|
139
|
+
else if (format === 1027)
|
|
140
|
+
channels = 2; // RGIntegerFormat
|
|
141
|
+
else if (format === 1022)
|
|
142
|
+
channels = 3; // RGBFormat
|
|
143
|
+
else if (format === 1029)
|
|
144
|
+
channels = 3; // RGBIntegerFormat
|
|
145
|
+
else if (format === 1023)
|
|
146
|
+
channels = 4; // RGBAFormat
|
|
147
|
+
else if (format === 1033)
|
|
148
|
+
channels = 4; // RGBAIntegerFormat
|
|
149
|
+
// Determine bytes per channel from type
|
|
150
|
+
let bytesPerChannel = 1; // UnsignedByteType default
|
|
151
|
+
const type = texture.type;
|
|
152
|
+
if (type === 1009)
|
|
153
|
+
bytesPerChannel = 1; // UnsignedByteType
|
|
154
|
+
else if (type === 1010)
|
|
155
|
+
bytesPerChannel = 1; // ByteType
|
|
156
|
+
else if (type === 1011)
|
|
157
|
+
bytesPerChannel = 2; // ShortType
|
|
158
|
+
else if (type === 1012)
|
|
159
|
+
bytesPerChannel = 2; // UnsignedShortType
|
|
160
|
+
else if (type === 1013)
|
|
161
|
+
bytesPerChannel = 4; // IntType
|
|
162
|
+
else if (type === 1014)
|
|
163
|
+
bytesPerChannel = 4; // UnsignedIntType
|
|
164
|
+
else if (type === 1015)
|
|
165
|
+
bytesPerChannel = 4; // FloatType
|
|
166
|
+
else if (type === 1016)
|
|
167
|
+
bytesPerChannel = 2; // HalfFloatType
|
|
168
|
+
const bytesPerPixel = channels * bytesPerChannel;
|
|
169
|
+
return bytesPerPixel;
|
|
170
|
+
}
|
|
171
|
+
// #region GPU
|
|
172
|
+
let rendererInfo;
|
|
173
|
+
/**
|
|
174
|
+
* Detect the GPU memory of the current device. This is a very rough estimate based on the renderer information, and may not be accurate. It returns the estimated memory in MB, or `undefined` if it cannot be detected.
|
|
175
|
+
*/
|
|
176
|
+
export function detectGPUMemory() {
|
|
177
|
+
if (rendererInfo !== undefined) {
|
|
178
|
+
return rendererInfo?.estimatedMemory;
|
|
179
|
+
}
|
|
180
|
+
const canvas = document.createElement('canvas');
|
|
181
|
+
const powerPreference = "high-performance";
|
|
182
|
+
const gl = canvas.getContext('webgl', { powerPreference }) || canvas.getContext('experimental-webgl', { powerPreference });
|
|
183
|
+
if (!gl) {
|
|
184
|
+
return undefined;
|
|
185
|
+
}
|
|
186
|
+
if ("getExtension" in gl) {
|
|
187
|
+
const debugInfo = gl.getExtension('WEBGL_debug_renderer_info');
|
|
188
|
+
if (debugInfo) {
|
|
189
|
+
const vendor = gl.getParameter(debugInfo.UNMASKED_VENDOR_WEBGL);
|
|
190
|
+
const renderer = gl.getParameter(debugInfo.UNMASKED_RENDERER_WEBGL);
|
|
191
|
+
// Estimate memory based on renderer information (this is a very rough estimate)
|
|
192
|
+
let estimatedMemory = 512;
|
|
193
|
+
if (/NVIDIA/i.test(renderer)) {
|
|
194
|
+
estimatedMemory = 2048;
|
|
195
|
+
}
|
|
196
|
+
else if (/AMD/i.test(renderer)) {
|
|
197
|
+
estimatedMemory = 1024;
|
|
198
|
+
}
|
|
199
|
+
else if (/Intel/i.test(renderer)) {
|
|
200
|
+
estimatedMemory = 512;
|
|
201
|
+
}
|
|
202
|
+
rendererInfo = { vendor, renderer, estimatedMemory };
|
|
203
|
+
return estimatedMemory;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
else {
|
|
207
|
+
rendererInfo = null;
|
|
208
|
+
}
|
|
209
|
+
return undefined;
|
|
210
|
+
}
|
package/lib/version.js
CHANGED
|
@@ -21,7 +21,7 @@ export function getWorker(opts) {
|
|
|
21
21
|
class GLTFLoaderWorker {
|
|
22
22
|
worker;
|
|
23
23
|
static async createWorker(opts) {
|
|
24
|
-
const worker = new Worker(new URL(`./
|
|
24
|
+
const worker = new Worker(new URL(`./gltf-progressive.worker.js`, import.meta.url), {
|
|
25
25
|
type: 'module',
|
|
26
26
|
});
|
|
27
27
|
const instance = new GLTFLoaderWorker(worker, opts);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@needle-tools/gltf-progressive",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.5.0-canary.4d42385",
|
|
4
4
|
"description": "three.js support for loading glTF or GLB files that contain progressive loading data",
|
|
5
5
|
"homepage": "https://needle.tools",
|
|
6
6
|
"author": {
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
"type": "git",
|
|
13
13
|
"url": "git+https://github.com/needle-tools/gltf-progressive"
|
|
14
14
|
},
|
|
15
|
+
"license": "MIT",
|
|
15
16
|
"readme": "README.md",
|
|
16
17
|
"keywords": [
|
|
17
18
|
"three.js",
|
|
@@ -41,7 +42,8 @@
|
|
|
41
42
|
"gltf-progressive.js",
|
|
42
43
|
"gltf-progressive.min.js",
|
|
43
44
|
"gltf-progressive.umd.cjs",
|
|
44
|
-
"NEEDLE_progressive"
|
|
45
|
+
"NEEDLE_progressive",
|
|
46
|
+
"LICENSE"
|
|
45
47
|
],
|
|
46
48
|
"watch": {
|
|
47
49
|
"build:lib": {
|
|
File without changes
|