@needle-tools/three-mesh-effects 0.3.3 → 0.3.5

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.
Files changed (47) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/README.md +3 -2
  3. package/build/box-impostor-runtime.js +27 -2
  4. package/build/box-impostor-runtime.js.map +3 -3
  5. package/build/deformation-runtime.js +11 -9
  6. package/build/deformation-runtime.js.map +2 -2
  7. package/build/impostor-runtime.js +41 -19
  8. package/build/impostor-runtime.js.map +3 -3
  9. package/build/internal/box-impostor/box-impostor-display.js +10 -2
  10. package/build/internal/box-impostor/box-impostor-display.js.map +2 -2
  11. package/build/internal/box-impostor/box-impostor-faces.js.map +1 -1
  12. package/build/internal/box-impostor/box-impostor-geometry.js +4 -0
  13. package/build/internal/box-impostor/box-impostor-geometry.js.map +2 -2
  14. package/build/internal/box-impostor/box-impostor-material.js +10 -2
  15. package/build/internal/box-impostor/box-impostor-material.js.map +2 -2
  16. package/build/internal/box-impostor/box-impostor-metadata.js +4 -0
  17. package/build/internal/box-impostor/box-impostor-metadata.js.map +2 -2
  18. package/build/internal/box-impostor/box-impostor-projection.js.map +1 -1
  19. package/build/internal/box-impostor/box-impostor-runtime.js +27 -2
  20. package/build/internal/box-impostor/box-impostor-runtime.js.map +3 -3
  21. package/build/internal/deformation/pin-ik.js +11 -9
  22. package/build/internal/deformation/pin-ik.js.map +2 -2
  23. package/build/internal/deformation/pin-wiggle.js.map +1 -1
  24. package/build/internal/deformation/rig-extension.js.map +1 -1
  25. package/build/internal/deformation/rig-runtime.js +11 -9
  26. package/build/internal/deformation/rig-runtime.js.map +2 -2
  27. package/build/internal/impostor/impostor-node-material.js +41 -19
  28. package/build/internal/impostor/impostor-node-material.js.map +3 -3
  29. package/build/internal/pixel-impostor/pixel-impostor-display.js +9 -7
  30. package/build/internal/pixel-impostor/pixel-impostor-display.js.map +2 -2
  31. package/build/internal/rendering/classic-webgl-support.js +12 -0
  32. package/build/internal/rendering/classic-webgl-support.js.map +7 -0
  33. package/build/internal/rendering/renderer-support.js +13 -0
  34. package/build/internal/rendering/renderer-support.js.map +3 -3
  35. package/build/pixel-impostor-runtime.js +9 -7
  36. package/build/pixel-impostor-runtime.js.map +2 -2
  37. package/build/types/box-impostor/box-impostor-metadata.d.ts +3 -1
  38. package/build/types/rendering/classic-webgl-support.d.ts +9 -0
  39. package/build/types/rendering/classic-webgl-support.js +1 -0
  40. package/package.json +2 -2
  41. package/src/box-impostor/box-impostor-material.js +10 -2
  42. package/src/box-impostor/box-impostor-metadata.js +5 -1
  43. package/src/deformation/pin-ik.ts +13 -9
  44. package/src/impostor/impostor-node-material.js +31 -15
  45. package/src/pixel-impostor/pixel-impostor-display.js +18 -7
  46. package/src/rendering/classic-webgl-support.js +15 -0
  47. package/src/rendering/renderer-support.js +5 -0
@@ -1,7 +1,17 @@
1
1
  // @ts-nocheck
2
2
 
3
3
  // src/rendering/renderer-support.js
4
+ import { REVISION } from "three";
4
5
  import * as TSL from "three/tsl";
6
+
7
+ // src/rendering/classic-webgl-support.js
8
+ function classicWebGLSupportsNodeMaterials(revision) {
9
+ const fork = /^186\.2-alpha\.(\d+)$/.exec(revision);
10
+ if (fork) return Number(fork[1]) >= 2;
11
+ return Number.parseInt(revision, 10) >= 187;
12
+ }
13
+
14
+ // src/rendering/renderer-support.js
5
15
  function rendererSupportsImpostorNodeMaterials(renderer) {
6
16
  if (typeof Reflect.get(TSL, "struct") !== "function") return false;
7
17
  return renderer?.isWebGPURenderer === true || renderer?.capabilities?.supportsNodeMaterials === true;
@@ -13,6 +23,9 @@ async function enableRendererNodeMaterials(renderer) {
13
23
  if (!setup) {
14
24
  setup = import("three/addons/tsl/WebGLNodesHandler.js").then(({ WebGLNodesHandler }) => {
15
25
  if (rendererSupportsImpostorNodeMaterials(renderer)) return;
26
+ if (!classicWebGLSupportsNodeMaterials(REVISION)) {
27
+ console.warn(`Mesh Effects: WebGLRenderer from three r${REVISION} stops drawing node materials after about a dozen are in use. Use three r187 or later, or WebGPURenderer.`);
28
+ }
16
29
  renderer.setNodesHandler?.(new WebGLNodesHandler());
17
30
  renderer.capabilities ??= {};
18
31
  renderer.capabilities.supportsNodeMaterials = true;
@@ -766,7 +779,7 @@ function createPbrImpostorNodeMaterial(descriptor, maps, inputFeatures = {}, ren
766
779
  const padding = float(descriptor.padding);
767
780
  const radius = float(descriptor.radius);
768
781
  const captureAlphaCutoff = float(descriptor.captureAlphaCutoff);
769
- const reprojectionSurfaceCutoff = descriptor.coverageEncoding === "sdf-base-alpha" ? float(0.5) : min(captureAlphaCutoff, float(0.25));
782
+ const reprojectionSurfaceCutoff = descriptor.coverageEncoding === "sdf-base-alpha" ? float(0.5) : float(Math.min(Number(descriptor.captureAlphaCutoff), 0.25));
770
783
  const blendCutoff = float((1 - profile.blendZone) * 0.5);
771
784
  const coarseSearchSteps = profile.raySamples;
772
785
  const fullSphere = descriptor.mapping === "full";
@@ -1254,26 +1267,35 @@ function createPbrImpostorNodeMaterial(descriptor, maps, inputFeatures = {}, ren
1254
1267
  footprint
1255
1268
  );
1256
1269
  };
1257
- const sampleFrame = Fn2(buildFrameSample).setLayout({
1258
- name: withReprojection ? "sampleReprojectedImpostorFrame" : "samplePlanarImpostorFrame",
1259
- type: "ImpostorFrameSample",
1260
- inputs: [
1261
- { name: "frame", type: "vec2" },
1262
- { name: "planePosition", type: "vec3" },
1263
- { name: "rayDirection", type: "vec3" },
1264
- { name: "bounds", type: "vec4" }
1265
- ]
1266
- });
1267
- return (frame, planePosition, rayDirection) => sampleFrame(
1268
- frame,
1269
- planePosition,
1270
- rayDirection,
1271
- viewBounds.element(int(frame.y.mul(frames).add(frame.x)))
1272
- );
1270
+ const functions = /* @__PURE__ */ new WeakMap();
1271
+ return (builder) => {
1272
+ let sampleFrame = functions.get(builder);
1273
+ if (!sampleFrame) {
1274
+ sampleFrame = Fn2(buildFrameSample).setLayout({
1275
+ name: withReprojection ? "sampleReprojectedImpostorFrame" : "samplePlanarImpostorFrame",
1276
+ type: "ImpostorFrameSample",
1277
+ inputs: [
1278
+ { name: "frame", type: "vec2" },
1279
+ { name: "planePosition", type: "vec3" },
1280
+ { name: "rayDirection", type: "vec3" },
1281
+ { name: "bounds", type: "vec4" }
1282
+ ]
1283
+ });
1284
+ functions.set(builder, sampleFrame);
1285
+ }
1286
+ return (frame, planePosition, rayDirection) => sampleFrame(
1287
+ frame,
1288
+ planePosition,
1289
+ rayDirection,
1290
+ viewBounds.element(int(frame.y.mul(frames).add(frame.x)))
1291
+ );
1292
+ };
1273
1293
  };
1274
- const samplePlanarFrame = createFrameSampler(false);
1275
- const sampleReprojectedFrame = features.reprojection ? createFrameSampler(true) : null;
1294
+ const planarFrameSamplers = createFrameSampler(false);
1295
+ const reprojectedFrameSamplers = features.reprojection ? createFrameSampler(true) : null;
1276
1296
  const buildBlendedSample = ([], builder) => {
1297
+ const samplePlanarFrame = planarFrameSamplers(builder);
1298
+ const sampleReprojectedFrame = reprojectedFrameSamplers ? reprojectedFrameSamplers(builder) : null;
1277
1299
  const samplingCameraLocal = samplingCamera;
1278
1300
  const centerViewDirection = samplingCameraLocal.normalize();
1279
1301
  const usePerspectiveCorrection = features.perspectiveCorrection && builder.camera.isPerspectiveCamera;