@needle-tools/gltf-progressive 1.2.3-beta → 1.2.4-beta.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 +7 -0
- package/gltf-progressive.js +470 -453
- package/gltf-progressive.min.js +7 -7
- package/gltf-progressive.umd.cjs +7 -7
- package/lib/loaders.d.ts +19 -1
- package/lib/loaders.js +8 -2
- package/lib/lods_manager.d.ts +14 -2
- package/lib/lods_manager.js +69 -64
- package/lib/version.js +1 -1
- package/package.json +1 -1
package/lib/lods_manager.js
CHANGED
|
@@ -84,13 +84,21 @@ export class LODsManager {
|
|
|
84
84
|
targetTriangleDensity = 200_000;
|
|
85
85
|
/**
|
|
86
86
|
* The update interval in frames. If set to 0, the LODs will be updated every frame. If set to 2, the LODs will be updated every second frame, etc.
|
|
87
|
+
* @default "auto"
|
|
87
88
|
*/
|
|
88
89
|
updateInterval = "auto";
|
|
89
90
|
#updateInterval = 1;
|
|
90
91
|
/**
|
|
91
92
|
* If set to true, the LODsManager will not update the LODs.
|
|
93
|
+
* @default false
|
|
92
94
|
*/
|
|
93
95
|
pause = false;
|
|
96
|
+
/**
|
|
97
|
+
* When set to true the LODsManager will not update the LODs. This can be used to manually update the LODs using the `update` method.
|
|
98
|
+
* Otherwise the LODs will be updated automatically when the renderer renders the scene.
|
|
99
|
+
* @default false
|
|
100
|
+
*/
|
|
101
|
+
manual = false;
|
|
94
102
|
_lodchangedlisteners = [];
|
|
95
103
|
addEventListener(evt, listener) {
|
|
96
104
|
if (evt === "changed") {
|
|
@@ -126,7 +134,7 @@ export class LODsManager {
|
|
|
126
134
|
// if it's rendering to a texture we don't want to update the LODs
|
|
127
135
|
// This might need to be loosened later - e.g. we might want to update LODs for a render texture - but then we need to store the last LOD level differently and we also might not want to perform all the plugin calls?
|
|
128
136
|
const renderTarget = self.renderer.getRenderTarget();
|
|
129
|
-
if (renderTarget == null) {
|
|
137
|
+
if (renderTarget == null || ("isXRRenderTarget" in renderTarget && renderTarget.isXRRenderTarget)) {
|
|
130
138
|
stack = 0;
|
|
131
139
|
self.#frame += 1;
|
|
132
140
|
self.#delta = self.#clock.getDelta();
|
|
@@ -137,11 +145,9 @@ export class LODsManager {
|
|
|
137
145
|
if (debugProgressiveLoading && self.#frame % 30 === 0)
|
|
138
146
|
console.log("FPS", Math.round(self.#fps), "Interval:", self.#updateInterval);
|
|
139
147
|
}
|
|
140
|
-
const frame = self.#frame;
|
|
141
148
|
const stack_level = stack++;
|
|
142
|
-
self.onBeforeRender(scene, camera, stack_level, frame);
|
|
143
149
|
self.#originalRender.call(this, scene, camera);
|
|
144
|
-
self.onAfterRender(scene, camera, stack_level
|
|
150
|
+
self.onAfterRender(scene, camera, stack_level);
|
|
145
151
|
};
|
|
146
152
|
}
|
|
147
153
|
disable() {
|
|
@@ -150,9 +156,10 @@ export class LODsManager {
|
|
|
150
156
|
this.renderer.render = this.#originalRender;
|
|
151
157
|
this.#originalRender = undefined;
|
|
152
158
|
}
|
|
153
|
-
|
|
159
|
+
update(scene, camera) {
|
|
160
|
+
this.internalUpdate(scene, camera);
|
|
154
161
|
}
|
|
155
|
-
onAfterRender(scene, camera, _stack
|
|
162
|
+
onAfterRender(scene, camera, _stack) {
|
|
156
163
|
if (this.pause)
|
|
157
164
|
return;
|
|
158
165
|
const renderList = this.renderer.renderLists.get(scene, 0);
|
|
@@ -201,77 +208,75 @@ export class LODsManager {
|
|
|
201
208
|
this.#updateInterval = this.updateInterval;
|
|
202
209
|
}
|
|
203
210
|
// Check if we should update LODs this frame
|
|
204
|
-
if (this.#updateInterval > 0 && frame % this.#updateInterval != 0) {
|
|
211
|
+
if (this.#updateInterval > 0 && this.#frame % this.#updateInterval != 0) {
|
|
205
212
|
return;
|
|
206
213
|
}
|
|
207
|
-
this.
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
if (
|
|
224
|
-
if (
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
console.warn("Ignoring skybox or BLIT object", entry, entry.material.name, entry.material.type);
|
|
228
|
-
}
|
|
214
|
+
this.internalUpdate(scene, camera);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Update LODs in a scene
|
|
219
|
+
*/
|
|
220
|
+
internalUpdate(scene, camera) {
|
|
221
|
+
const renderList = this.renderer.renderLists.get(scene, 0);
|
|
222
|
+
const opaque = renderList.opaque;
|
|
223
|
+
this.projectionScreenMatrix.multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse);
|
|
224
|
+
this.cameraFrustrum.setFromProjectionMatrix(this.projectionScreenMatrix, this.renderer.coordinateSystem);
|
|
225
|
+
const desiredDensity = this.targetTriangleDensity;
|
|
226
|
+
for (const entry of opaque) {
|
|
227
|
+
if (entry.material && (entry.geometry?.type === "BoxGeometry" || entry.geometry?.type === "BufferGeometry")) {
|
|
228
|
+
// Ignore the skybox
|
|
229
|
+
if (entry.material.name === "SphericalGaussianBlur" || entry.material.name == "BackgroundCubeMaterial" || entry.material.name === "CubemapFromEquirect" || entry.material.name === "EquirectangularToCubeUV") {
|
|
230
|
+
if (debugProgressiveLoading) {
|
|
231
|
+
if (!entry.material["NEEDLE_PROGRESSIVE:IGNORE-WARNING"]) {
|
|
232
|
+
entry.material["NEEDLE_PROGRESSIVE:IGNORE-WARNING"] = true;
|
|
233
|
+
console.warn("Ignoring skybox or BLIT object", entry, entry.material.name, entry.material.type);
|
|
229
234
|
}
|
|
230
|
-
continue;
|
|
231
235
|
}
|
|
236
|
+
continue;
|
|
232
237
|
}
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
238
|
+
}
|
|
239
|
+
switch (entry.material.type) {
|
|
240
|
+
case "LineBasicMaterial":
|
|
241
|
+
case "LineDashedMaterial":
|
|
242
|
+
case "PointsMaterial":
|
|
243
|
+
case "ShadowMaterial":
|
|
244
|
+
case "MeshDistanceMaterial":
|
|
245
|
+
case "MeshDepthMaterial":
|
|
246
|
+
continue;
|
|
247
|
+
}
|
|
248
|
+
if (debugProgressiveLoading === "color") {
|
|
249
|
+
if (entry.material) {
|
|
250
|
+
if (!entry.object["progressive_debug_color"]) {
|
|
251
|
+
entry.object["progressive_debug_color"] = true;
|
|
252
|
+
const randomColor = Math.random() * 0xffffff;
|
|
253
|
+
const newMaterial = new MeshStandardMaterial({ color: randomColor });
|
|
254
|
+
entry.object.material = newMaterial;
|
|
250
255
|
}
|
|
251
256
|
}
|
|
252
|
-
const object = entry.object;
|
|
253
|
-
if (object instanceof Mesh || (object.isMesh)) {
|
|
254
|
-
this.updateLODs(scene, camera, object, desiredDensity, frame);
|
|
255
|
-
}
|
|
256
257
|
}
|
|
257
|
-
const
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
if (object instanceof Mesh || (object.isMesh)) {
|
|
261
|
-
this.updateLODs(scene, camera, object, desiredDensity, frame);
|
|
262
|
-
}
|
|
258
|
+
const object = entry.object;
|
|
259
|
+
if (object instanceof Mesh || (object.isMesh)) {
|
|
260
|
+
this.updateLODs(scene, camera, object, desiredDensity);
|
|
263
261
|
}
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
262
|
+
}
|
|
263
|
+
const transparent = renderList.transparent;
|
|
264
|
+
for (const entry of transparent) {
|
|
265
|
+
const object = entry.object;
|
|
266
|
+
if (object instanceof Mesh || (object.isMesh)) {
|
|
267
|
+
this.updateLODs(scene, camera, object, desiredDensity);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
const transmissive = renderList.transmissive;
|
|
271
|
+
for (const entry of transmissive) {
|
|
272
|
+
const object = entry.object;
|
|
273
|
+
if (object instanceof Mesh || (object.isMesh)) {
|
|
274
|
+
this.updateLODs(scene, camera, object, desiredDensity);
|
|
270
275
|
}
|
|
271
276
|
}
|
|
272
277
|
}
|
|
273
278
|
/** Update the LOD levels for the renderer. */
|
|
274
|
-
updateLODs(scene, camera, object, desiredDensity
|
|
279
|
+
updateLODs(scene, camera, object, desiredDensity) {
|
|
275
280
|
if (!object.userData) {
|
|
276
281
|
object.userData = {};
|
|
277
282
|
}
|
package/lib/version.js
CHANGED
package/package.json
CHANGED