@d5techs/3dgs-lib 1.4.39 → 1.4.41

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/dist/3dgs-lib.cjs CHANGED
@@ -2111,7 +2111,8 @@ fn vs(@builtin(vertex_index) vi: u32) -> VSOut {
2111
2111
 
2112
2112
  @fragment
2113
2113
  fn fs(input: VSOut) -> @location(0) vec4<f32> {
2114
- return textureSample(cubeTexture, cubeSampler, normalize(input.dir));
2114
+ let color = textureSample(cubeTexture, cubeSampler, normalize(input.dir));
2115
+ return vec4<f32>(color.rgb, 1.0);
2115
2116
  }
2116
2117
  `
2117
2118
  );
@@ -2131,6 +2132,7 @@ class SkyboxRenderer {
2131
2132
  __publicField(this, "scratchInv", new Float32Array(16));
2132
2133
  __publicField(this, "cubeTexture", null);
2133
2134
  __publicField(this, "cubeBindGroup", null);
2135
+ __publicField(this, "uniformDirty", false);
2134
2136
  this.device = device;
2135
2137
  this.format = format;
2136
2138
  this.depthFormat = depthFormat;
@@ -2214,7 +2216,7 @@ class SkyboxRenderer {
2214
2216
  dimension: "2d",
2215
2217
  size: [width, height, 6],
2216
2218
  format: "rgba8unorm",
2217
- usage: GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.COPY_DST
2219
+ usage: GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.COPY_DST | GPUTextureUsage.RENDER_ATTACHMENT
2218
2220
  });
2219
2221
  for (let layer = 0; layer < 6; layer++) {
2220
2222
  this.device.queue.copyExternalImageToTexture(
@@ -2236,19 +2238,28 @@ class SkyboxRenderer {
2236
2238
  this.cubeTexture = tex;
2237
2239
  this.cubeBindGroup = bindGroup;
2238
2240
  }
2239
- render(pass, viewMatrix, projectionMatrix) {
2240
- if (!this.isActive || !this.cubeBindGroup) {
2241
- return;
2242
- }
2241
+ /**
2242
+ * Must be called BEFORE beginFrame() to write uniform data outside the render pass.
2243
+ */
2244
+ prepareFrame(viewMatrix, projectionMatrix) {
2245
+ if (!this.isActive) return;
2243
2246
  this.scratchViewNoTrans.set(viewMatrix);
2244
2247
  this.scratchViewNoTrans[12] = 0;
2245
2248
  this.scratchViewNoTrans[13] = 0;
2246
2249
  this.scratchViewNoTrans[14] = 0;
2247
2250
  SkyboxRenderer.multiplyMat4(this.scratchVp, projectionMatrix, this.scratchViewNoTrans);
2248
2251
  if (!SkyboxRenderer.invertMat4(this.scratchInv, this.scratchVp)) {
2252
+ this.uniformDirty = false;
2249
2253
  return;
2250
2254
  }
2251
2255
  this.device.queue.writeBuffer(this.uniformBuffer, 0, this.scratchInv);
2256
+ this.uniformDirty = true;
2257
+ }
2258
+ /**
2259
+ * Draw the skybox into the given render pass. Call prepareFrame() first.
2260
+ */
2261
+ draw(pass) {
2262
+ if (!this.uniformDirty || !this.cubeBindGroup) return;
2252
2263
  pass.setPipeline(this.pipeline);
2253
2264
  pass.setBindGroup(0, this.cubeBindGroup);
2254
2265
  pass.draw(3);
@@ -2259,6 +2270,7 @@ class SkyboxRenderer {
2259
2270
  this.cubeTexture = null;
2260
2271
  }
2261
2272
  this.cubeBindGroup = null;
2273
+ this.uniformDirty = false;
2262
2274
  }
2263
2275
  destroy() {
2264
2276
  this.clear();
@@ -18906,14 +18918,17 @@ class App {
18906
18918
  }
18907
18919
  }
18908
18920
  render() {
18909
- var _a2;
18921
+ var _a2, _b2;
18910
18922
  this.camera.setAspect(this.renderer.getAspectRatio());
18911
18923
  this.controls.update();
18912
18924
  this.updateAdaptivePerformance();
18913
18925
  this.hotspotManager.updateBillboards();
18914
- const pass = this.renderer.beginFrame();
18915
18926
  if ((_a2 = this.skyboxRenderer) == null ? void 0 : _a2.isActive) {
18916
- this.skyboxRenderer.render(pass, this.camera.viewMatrix, this.camera.projectionMatrix);
18927
+ this.skyboxRenderer.prepareFrame(this.camera.viewMatrix, this.camera.projectionMatrix);
18928
+ }
18929
+ const pass = this.renderer.beginFrame();
18930
+ if ((_b2 = this.skyboxRenderer) == null ? void 0 : _b2.isActive) {
18931
+ this.skyboxRenderer.draw(pass);
18917
18932
  }
18918
18933
  const gsRenderer = this.sceneManager.getGSRenderer();
18919
18934
  if (gsRenderer) {