@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.
@@ -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, frame);
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
- onBeforeRender(_scene, _camera, _stack, _frame) {
159
+ update(scene, camera) {
160
+ this.internalUpdate(scene, camera);
154
161
  }
155
- onAfterRender(scene, camera, _stack, frame) {
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.projectionScreenMatrix.multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse);
208
- this.cameraFrustrum.setFromProjectionMatrix(this.projectionScreenMatrix, this.renderer.coordinateSystem);
209
- const desiredDensity = this.targetTriangleDensity;
210
- // const isLowPerformanceDevice = false;// isMobileDevice();
211
- // Experiment: quick & dirty performance-adaptive LODs
212
- /*
213
- if (this.context.time.smoothedFps < 59) {
214
- currentAllowedDensity *= 0.5;
215
- }
216
- else if (this.context.time.smoothedFps >= 59) {
217
- currentAllowedDensity *= 1.25;
218
- }
219
- */
220
- for (const entry of opaque) {
221
- if (entry.material && (entry.geometry?.type === "BoxGeometry" || entry.geometry?.type === "BufferGeometry")) {
222
- // Ignore the skybox
223
- if (entry.material.name === "SphericalGaussianBlur" || entry.material.name == "BackgroundCubeMaterial" || entry.material.name === "CubemapFromEquirect" || entry.material.name === "EquirectangularToCubeUV") {
224
- if (debugProgressiveLoading) {
225
- if (!entry.material["NEEDLE_PROGRESSIVE:IGNORE-WARNING"]) {
226
- entry.material["NEEDLE_PROGRESSIVE:IGNORE-WARNING"] = true;
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
- switch (entry.material.type) {
234
- case "LineBasicMaterial":
235
- case "LineDashedMaterial":
236
- case "PointsMaterial":
237
- case "ShadowMaterial":
238
- case "MeshDistanceMaterial":
239
- case "MeshDepthMaterial":
240
- continue;
241
- }
242
- if (debugProgressiveLoading === "color") {
243
- if (entry.material) {
244
- if (!entry.object["progressive_debug_color"]) {
245
- entry.object["progressive_debug_color"] = true;
246
- const randomColor = Math.random() * 0xffffff;
247
- const newMaterial = new MeshStandardMaterial({ color: randomColor });
248
- entry.object.material = newMaterial;
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 transparent = renderList.transparent;
258
- for (const entry of transparent) {
259
- const object = entry.object;
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
- const transmissive = renderList.transmissive;
265
- for (const entry of transmissive) {
266
- const object = entry.object;
267
- if (object instanceof Mesh || (object.isMesh)) {
268
- this.updateLODs(scene, camera, object, desiredDensity, frame);
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, _frame) {
279
+ updateLODs(scene, camera, object, desiredDensity) {
275
280
  if (!object.userData) {
276
281
  object.userData = {};
277
282
  }
package/lib/version.js CHANGED
@@ -1,4 +1,4 @@
1
1
  // replaced at build time
2
- export const version = "1.2.3-beta";
2
+ export const version = "1.2.4-beta.1";
3
3
  globalThis["GLTF_PROGRESSIVE_VERSION"] = version;
4
4
  console.debug(`[gltf-progressive] version ${version}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@needle-tools/gltf-progressive",
3
- "version": "1.2.3-beta",
3
+ "version": "1.2.4-beta.1",
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": {