@needle-tools/three-mesh-effects 0.2.2 → 0.2.3

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.
@@ -1,9 +1,32 @@
1
1
  // @ts-nocheck
2
2
 
3
3
  // src/deformation/fur-surface.ts
4
- import { BufferAttribute, MeshPhysicalMaterial, MeshStandardMaterial, SkinnedMesh } from "three";
4
+ import { BufferAttribute, MeshPhysicalMaterial, MeshStandardMaterial, SkinnedMesh, Vector2 } from "three";
5
5
  import { MeshPhysicalNodeMaterial, MeshStandardNodeMaterial } from "three/webgpu";
6
6
  import { attribute, float, mix, normalMap, positionLocal, texture, uniform, uv, varying, vec2, vec3, vec4 } from "three/tsl";
7
+
8
+ // src/rendering/texture-slot.js
9
+ function bindTextureSlot(material, slot, initial, nodes, onChange) {
10
+ let current = initial;
11
+ Object.defineProperty(material, slot, {
12
+ configurable: true,
13
+ enumerable: true,
14
+ get: () => current,
15
+ set: (value) => {
16
+ value.channel = current.channel;
17
+ value.offset = current.offset;
18
+ value.repeat = current.repeat;
19
+ value.center = current.center;
20
+ value.rotation = current.rotation;
21
+ current = value;
22
+ for (const node of nodes) node.value = value;
23
+ onChange?.(value);
24
+ material.needsUpdate = true;
25
+ }
26
+ });
27
+ }
28
+
29
+ // src/deformation/fur-surface.ts
7
30
  var FurSurface = class {
8
31
  surfaces = [];
9
32
  height = null;
@@ -80,30 +103,50 @@ var FurSurface = class {
80
103
  if (!signal) return material;
81
104
  const depth = attribute("furDepth", "float").mul(5).clamp(0, 1);
82
105
  const skinnedDelta = varying(positionLocal.sub(attribute("position", "vec3")), "furSkinDelta");
83
- const dimensions = signal.image;
84
- const pixel = vec2(1 / Math.max(1, dimensions?.width ?? 1024), 1 / Math.max(1, dimensions?.height ?? 1024));
106
+ const signalSlot = ["map", "normalMap", "roughnessMap", "metalnessMap", "emissiveMap", "aoMap", "alphaMap"].find((slot) => Reflect.get(source, slot) === signal) ?? "furHeightMap";
107
+ const pixel = uniform(new Vector2());
108
+ const updatePixel = (map) => {
109
+ const dimensions = map.image;
110
+ pixel.value.set(1 / Math.max(1, dimensions?.width ?? 1024), 1 / Math.max(1, dimensions?.height ?? 1024));
111
+ };
112
+ updatePixel(signal);
85
113
  const movement = projectMotionToUv(skinnedDelta, coordinates).clamp(pixel.mul(-1.5), pixel.mul(1.5));
86
- const height = this.height ? texture(this.height, uv(this.height.channel)).r : float(0.5);
114
+ const heightNode = this.height ? texture(this.height, uv(this.height.channel)) : null;
115
+ if (heightNode && this.height) bindTextureSlot(
116
+ material,
117
+ "furHeightMap",
118
+ this.height,
119
+ [heightNode],
120
+ (value) => {
121
+ this.height = value;
122
+ if (signalSlot === "furHeightMap") updatePixel(value);
123
+ }
124
+ );
125
+ const height = heightNode ? heightNode.r : float(0.5);
87
126
  const raised = mix(0.65, 1.35, height);
88
127
  const phase = coordinates.dot(vec2(31, 43)).add(height.sub(0.5).mul(2.4)).add(this.clock.mul(this.wind).mul(1.7));
89
128
  const gust = vec2(phase.sin(), phase.mul(1.31).cos()).mul(pixel).mul(this.wind.mul(0.65));
90
129
  const shift = movement.add(gust).mul(depth).mul(raised).clamp(pixel.mul(-2), pixel.mul(2)).toVar("furTextureShift");
91
- const sample = (map) => {
130
+ const sample = (map, slot) => {
92
131
  const node = texture(map, uv(map.channel).add(shift));
93
132
  node.updateMatrix = true;
133
+ bindTextureSlot(material, slot, map, [node], (value) => {
134
+ Reflect.set(source, slot, value);
135
+ if (signalSlot === slot) updatePixel(value);
136
+ });
94
137
  return node;
95
138
  };
96
- const base = source.map ? sample(source.map) : vec4(1);
139
+ const base = source.map ? sample(source.map, "map") : vec4(1);
97
140
  material.colorNode = base.mul(vec4(source.color.r, source.color.g, source.color.b, 1));
98
- if (source.alphaMap) material.opacityNode = sample(source.alphaMap).g;
141
+ if (source.alphaMap) material.opacityNode = sample(source.alphaMap, "alphaMap").g;
99
142
  if (source.normalMap) material.normalNode = normalMap(
100
- sample(source.normalMap).xyz,
143
+ sample(source.normalMap, "normalMap").xyz,
101
144
  vec2(source.normalScale.x, source.normalScale.y)
102
145
  );
103
- material.roughnessNode = source.roughnessMap ? sample(source.roughnessMap).g.mul(source.roughness) : float(source.roughness);
104
- material.metalnessNode = source.metalnessMap ? sample(source.metalnessMap).b.mul(source.metalness) : float(source.metalness);
105
- if (source.aoMap) material.aoNode = float(1).sub(float(1).sub(sample(source.aoMap).r).mul(source.aoMapIntensity));
106
- if (source.emissiveMap) material.emissiveNode = sample(source.emissiveMap).rgb.mul(vec3(
146
+ material.roughnessNode = source.roughnessMap ? sample(source.roughnessMap, "roughnessMap").g.mul(source.roughness) : float(source.roughness);
147
+ material.metalnessNode = source.metalnessMap ? sample(source.metalnessMap, "metalnessMap").b.mul(source.metalness) : float(source.metalness);
148
+ if (source.aoMap) material.aoNode = float(1).sub(float(1).sub(sample(source.aoMap, "aoMap").r).mul(source.aoMapIntensity));
149
+ if (source.emissiveMap) material.emissiveNode = sample(source.emissiveMap, "emissiveMap").rgb.mul(vec3(
107
150
  source.emissive.r * source.emissiveIntensity,
108
151
  source.emissive.g * source.emissiveIntensity,
109
152
  source.emissive.b * source.emissiveIntensity
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../../../src/deformation/fur-surface.ts"],
4
- "sourcesContent": ["import { BufferAttribute, MeshPhysicalMaterial, MeshStandardMaterial, SkinnedMesh, type BufferGeometry, type Material, type Object3D, type Texture } from 'three';\nimport { MeshPhysicalNodeMaterial, MeshStandardNodeMaterial, type Node } from 'three/webgpu';\nimport { attribute, float, mix, normalMap, positionLocal, texture, uniform, uv, varying, vec2, vec3, vec4 } from 'three/tsl';\nimport type { RigDescriptor } from './rig-extension.js';\n\ninterface Surface { mesh: SkinnedMesh; geometry: BufferGeometry; modified: BufferGeometry; material: Material | Material[]; variants: MeshStandardNodeMaterial[] }\n\n/** Optional GPU detail for a portable skinned GLB. Nothing is written into its\n * fallback material or geometry, and the variant is absent without Fur pins. */\nexport class FurSurface {\n readonly surfaces: Surface[] = [];\n private height: Texture | null = null;\n private clock = uniform(0);\n private wind = uniform(0);\n\n constructor(scene: Object3D, descriptor: RigDescriptor, nodes: readonly Object3D[], helpers: readonly Object3D[]) {\n const depth = new Map<Object3D, number>();\n descriptor.pins.forEach((pin, i) => depth.set(nodes[i], pin.fur ? (pin.furDepth ?? .1) : 0));\n descriptor.helpers?.forEach((helper, i) => depth.set(helpers[i], helper.influences.reduce((sum, influence) => {\n const index = descriptor.joints.findIndex(joint => joint.node === influence.node);\n const pin = descriptor.pins[index];\n return sum + (pin?.fur ? (pin.furDepth ?? .1) * influence.weight : 0);\n }, 0)));\n scene.traverse(object => {\n if (!(object instanceof SkinnedMesh)) return;\n const geometry = object.geometry, indices = geometry.getAttribute('skinIndex'), weights = geometry.getAttribute('skinWeight');\n if (!indices || !weights || !geometry.getAttribute('uv') || !geometry.getAttribute('normal')) return;\n if ((Array.isArray(object.material) ? object.material : [object.material]).some(material => !(material instanceof MeshStandardMaterial))) return;\n const values = new Float32Array(indices.count);\n for (let v = 0; v < values.length; v++) for (let lane = 0; lane < 4; lane++) {\n values[v] += (depth.get(object.skeleton.bones[indices.getComponent(v, lane)]) ?? 0) * weights.getComponent(v, lane);\n }\n if (!values.some(value => value > 1e-5)) return;\n const modified = geometry.clone();\n modified.setAttribute('furDepth', new BufferAttribute(values, 1));\n const surface: Surface = { mesh: object, geometry, modified, material: object.material, variants: [] };\n object.geometry = modified;\n this.surfaces.push(surface);\n });\n this.rebuild();\n }\n\n setHeightMap(height: Texture | null) { if (this.height !== height) { this.height = height; this.rebuild(); } }\n update(seconds: number, windStrength: number) {\n this.clock.value += Math.max(0, Math.min(seconds, .1));\n this.wind.value = windStrength;\n }\n /** GLTFExporter must only see standard portable materials and attributes. */\n setPortable(portable: boolean) {\n for (const surface of this.surfaces) {\n surface.mesh.geometry = portable ? surface.geometry : surface.modified;\n surface.mesh.material = portable ? surface.material : Array.isArray(surface.material) ? surface.variants : surface.variants[0];\n }\n }\n dispose() {\n this.setPortable(true);\n for (const surface of this.surfaces) {\n surface.modified.dispose(); surface.mesh.geometry = surface.geometry;\n for (const variant of surface.variants) variant.dispose();\n }\n this.surfaces.length = 0;\n }\n private rebuild() {\n for (const surface of this.surfaces) {\n const sources = Array.isArray(surface.material) ? surface.material : [surface.material];\n const variants = sources.map(source => this.material(source as MeshStandardMaterial));\n this.setPortable(true);\n for (const old of surface.variants) old.dispose();\n surface.variants = variants;\n }\n this.setPortable(false);\n }\n private material(source: MeshStandardMaterial) {\n const material = source instanceof MeshPhysicalMaterial ? new MeshPhysicalNodeMaterial() : new MeshStandardNodeMaterial();\n material.copy(source);\n material.name = `${source.name || 'Material'} \u00B7 Fur texture motion`;\n const coordinates = uv();\n const signal = source.map ?? source.normalMap ?? source.roughnessMap ?? source.metalnessMap ?? source.emissiveMap ?? source.aoMap ?? source.alphaMap ?? this.height;\n if (!signal) return material;\n const depth = attribute('furDepth', 'float' as const).mul(5).clamp(0, 1);\n const skinnedDelta = varying(positionLocal.sub(attribute('position', 'vec3' as const)), 'furSkinDelta') as Node<'vec3'>;\n const dimensions = signal.image as { width?: number; height?: number } | undefined;\n const pixel = vec2(1 / Math.max(1, dimensions?.width ?? 1024), 1 / Math.max(1, dimensions?.height ?? 1024));\n const movement = projectMotionToUv(skinnedDelta, coordinates).clamp(pixel.mul(-1.5), pixel.mul(1.5));\n const height = this.height ? texture(this.height, uv(this.height.channel)).r : float(.5);\n const raised = mix(.65, 1.35, height);\n const phase = coordinates.dot(vec2(31, 43)).add(height.sub(.5).mul(2.4)).add(this.clock.mul(this.wind).mul(1.7));\n const gust = vec2(phase.sin(), phase.mul(1.31).cos()).mul(pixel).mul(this.wind.mul(.65));\n // A shared subpixel-to-two-pixel UV flow keeps color, normal, ORM, AO and\n // opacity aligned. The field follows the skinned surface and can shimmer\n // with wind; height modulates movement rather than drawing synthetic hair.\n const shift = movement.add(gust).mul(depth).mul(raised)\n .clamp(pixel.mul(-2), pixel.mul(2)).toVar('furTextureShift');\n const sample = (map: Texture) => {\n const node = texture(map, uv(map.channel).add(shift));\n node.updateMatrix = true;\n return node;\n };\n const base = source.map ? sample(source.map) : vec4(1);\n material.colorNode = base.mul(vec4(source.color.r, source.color.g, source.color.b, 1));\n if (source.alphaMap) material.opacityNode = sample(source.alphaMap).g;\n if (source.normalMap) material.normalNode = normalMap(sample(source.normalMap).xyz,\n vec2(source.normalScale.x, source.normalScale.y));\n material.roughnessNode = source.roughnessMap ? sample(source.roughnessMap).g.mul(source.roughness) : float(source.roughness);\n material.metalnessNode = source.metalnessMap ? sample(source.metalnessMap).b.mul(source.metalness) : float(source.metalness);\n if (source.aoMap) material.aoNode = float(1).sub(float(1).sub(sample(source.aoMap).r).mul(source.aoMapIntensity));\n if (source.emissiveMap) material.emissiveNode = sample(source.emissiveMap).rgb.mul(vec3(\n source.emissive.r * source.emissiveIntensity,\n source.emissive.g * source.emissiveIntensity,\n source.emissive.b * source.emissiveIntensity));\n material.userData.furSurface = { heightMapped: Boolean(this.height), motionMapped: true };\n return material;\n }\n}\n\n/** Convert the current skin displacement into a local UV offset. The metric\n * inversion avoids assuming that U/V align with world X/Y or have equal scale. */\nfunction projectMotionToUv(movement: Node<'vec3'>, coordinates: Node<'vec2'>) {\n const dUvDx = coordinates.dFdx(), dUvDy = coordinates.dFdy();\n const dPosDx = positionLocal.dFdx(), dPosDy = positionLocal.dFdy();\n const determinant = dUvDx.x.mul(dUvDy.y).sub(dUvDx.y.mul(dUvDy.x));\n const safe = determinant.abs().max(1e-10).mul(determinant.lessThan(0).select(-1, 1));\n const dPosDu = dPosDx.mul(dUvDy.y).sub(dPosDy.mul(dUvDx.y)).div(safe);\n const dPosDv = dPosDy.mul(dUvDx.x).sub(dPosDx.mul(dUvDx.y)).div(safe);\n const uu = dPosDu.dot(dPosDu), vv = dPosDv.dot(dPosDv), uvMetric = dPosDu.dot(dPosDv);\n const metric = uu.mul(vv).sub(uvMetric.mul(uvMetric)).max(1e-12);\n const u = movement.dot(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,GAAG,IAAI,EAAE,EAAE,IAAI,SAAS,IAAI,QAAQ,CAAC,EAAE,IAAI,KAAK;AAC/D,QAAM,IAAI,SAAS,IAAI,MAAM,GAAG,IAAI,SAAS,IAAI,MAAM;AACvD,SAAO,KAAK,GAAG,IAAI,CAAC,EAAE,IAAI,SAAS,IAAI,CAAC,CAAC,EAAE,IAAI,MAAM,GAAG,GAAG,IAAI,CAAC,EAAE,IAAI,SAAS,IAAI,CAAC,CAAC,EAAE,IAAI,MAAM,CAAC;AACpG;",
3
+ "sources": ["../../../src/deformation/fur-surface.ts", "../../../src/rendering/texture-slot.js"],
4
+ "sourcesContent": ["import { BufferAttribute, MeshPhysicalMaterial, MeshStandardMaterial, SkinnedMesh, Vector2, type BufferGeometry, type Material, type Object3D, type Texture } from 'three';\nimport { MeshPhysicalNodeMaterial, MeshStandardNodeMaterial, type Node } from 'three/webgpu';\nimport { attribute, float, mix, normalMap, positionLocal, texture, uniform, uv, varying, vec2, vec3, vec4 } from 'three/tsl';\nimport { bindTextureSlot } from '../rendering/texture-slot.js';\nimport type { RigDescriptor } from './rig-extension.js';\n\ninterface Surface { mesh: SkinnedMesh; geometry: BufferGeometry; modified: BufferGeometry; material: Material | Material[]; variants: MeshStandardNodeMaterial[] }\n\n/** Optional GPU detail for a portable skinned GLB. Nothing is written into its\n * fallback material or geometry, and the variant is absent without Fur pins. */\nexport class FurSurface {\n readonly surfaces: Surface[] = [];\n private height: Texture | null = null;\n private clock = uniform(0);\n private wind = uniform(0);\n\n constructor(scene: Object3D, descriptor: RigDescriptor, nodes: readonly Object3D[], helpers: readonly Object3D[]) {\n const depth = new Map<Object3D, number>();\n descriptor.pins.forEach((pin, i) => depth.set(nodes[i], pin.fur ? (pin.furDepth ?? .1) : 0));\n descriptor.helpers?.forEach((helper, i) => depth.set(helpers[i], helper.influences.reduce((sum, influence) => {\n const index = descriptor.joints.findIndex(joint => joint.node === influence.node);\n const pin = descriptor.pins[index];\n return sum + (pin?.fur ? (pin.furDepth ?? .1) * influence.weight : 0);\n }, 0)));\n scene.traverse(object => {\n if (!(object instanceof SkinnedMesh)) return;\n const geometry = object.geometry, indices = geometry.getAttribute('skinIndex'), weights = geometry.getAttribute('skinWeight');\n if (!indices || !weights || !geometry.getAttribute('uv') || !geometry.getAttribute('normal')) return;\n if ((Array.isArray(object.material) ? object.material : [object.material]).some(material => !(material instanceof MeshStandardMaterial))) return;\n const values = new Float32Array(indices.count);\n for (let v = 0; v < values.length; v++) for (let lane = 0; lane < 4; lane++) {\n values[v] += (depth.get(object.skeleton.bones[indices.getComponent(v, lane)]) ?? 0) * weights.getComponent(v, lane);\n }\n if (!values.some(value => value > 1e-5)) return;\n const modified = geometry.clone();\n modified.setAttribute('furDepth', new BufferAttribute(values, 1));\n const surface: Surface = { mesh: object, geometry, modified, material: object.material, variants: [] };\n object.geometry = modified;\n this.surfaces.push(surface);\n });\n this.rebuild();\n }\n\n setHeightMap(height: Texture | null) { if (this.height !== height) { this.height = height; this.rebuild(); } }\n update(seconds: number, windStrength: number) {\n this.clock.value += Math.max(0, Math.min(seconds, .1));\n this.wind.value = windStrength;\n }\n /** GLTFExporter must only see standard portable materials and attributes. */\n setPortable(portable: boolean) {\n for (const surface of this.surfaces) {\n surface.mesh.geometry = portable ? surface.geometry : surface.modified;\n surface.mesh.material = portable ? surface.material : Array.isArray(surface.material) ? surface.variants : surface.variants[0];\n }\n }\n dispose() {\n this.setPortable(true);\n for (const surface of this.surfaces) {\n surface.modified.dispose(); surface.mesh.geometry = surface.geometry;\n for (const variant of surface.variants) variant.dispose();\n }\n this.surfaces.length = 0;\n }\n private rebuild() {\n for (const surface of this.surfaces) {\n const sources = Array.isArray(surface.material) ? surface.material : [surface.material];\n const variants = sources.map(source => this.material(source as MeshStandardMaterial));\n this.setPortable(true);\n for (const old of surface.variants) old.dispose();\n surface.variants = variants;\n }\n this.setPortable(false);\n }\n private material(source: MeshStandardMaterial) {\n const material = source instanceof MeshPhysicalMaterial ? new MeshPhysicalNodeMaterial() : new MeshStandardNodeMaterial();\n material.copy(source);\n material.name = `${source.name || 'Material'} \u00B7 Fur texture motion`;\n const coordinates = uv();\n const signal = source.map ?? source.normalMap ?? source.roughnessMap ?? source.metalnessMap ?? source.emissiveMap ?? source.aoMap ?? source.alphaMap ?? this.height;\n if (!signal) return material;\n const depth = attribute('furDepth', 'float' as const).mul(5).clamp(0, 1);\n const skinnedDelta = varying(positionLocal.sub(attribute('position', 'vec3' as const)), 'furSkinDelta') as Node<'vec3'>;\n const signalSlot = ['map', 'normalMap', 'roughnessMap', 'metalnessMap', 'emissiveMap', 'aoMap', 'alphaMap'].find(slot => Reflect.get(source, slot) === signal) ?? 'furHeightMap';\n const pixel = uniform(new Vector2());\n const updatePixel = (map: Texture) => {\n const dimensions = map.image as { width?: number; height?: number } | undefined;\n pixel.value.set(1 / Math.max(1, dimensions?.width ?? 1024), 1 / Math.max(1, dimensions?.height ?? 1024));\n };\n updatePixel(signal);\n const movement = projectMotionToUv(skinnedDelta, coordinates).clamp(pixel.mul(-1.5), pixel.mul(1.5));\n const heightNode = this.height ? texture(this.height, uv(this.height.channel)) : null;\n if (heightNode && this.height) bindTextureSlot(material, 'furHeightMap', this.height,\n [heightNode], value => { this.height = value; if (signalSlot === 'furHeightMap') updatePixel(value); });\n const height = heightNode ? heightNode.r : float(.5);\n const raised = mix(.65, 1.35, height);\n const phase = coordinates.dot(vec2(31, 43)).add(height.sub(.5).mul(2.4)).add(this.clock.mul(this.wind).mul(1.7));\n const gust = vec2(phase.sin(), phase.mul(1.31).cos()).mul(pixel).mul(this.wind.mul(.65));\n // A shared subpixel-to-two-pixel UV flow keeps color, normal, ORM, AO and\n // opacity aligned. The field follows the skinned surface and can shimmer\n // with wind; height modulates movement rather than drawing synthetic hair.\n const shift = movement.add(gust).mul(depth).mul(raised)\n .clamp(pixel.mul(-2), pixel.mul(2)).toVar('furTextureShift');\n const sample = (map: Texture, slot: string) => {\n const node = texture(map, uv(map.channel).add(shift));\n node.updateMatrix = true;\n bindTextureSlot(material, slot, map, [node], value => { Reflect.set(source, slot, value); if (signalSlot === slot) updatePixel(value); });\n return node;\n };\n const base = source.map ? sample(source.map, 'map') : vec4(1);\n material.colorNode = base.mul(vec4(source.color.r, source.color.g, source.color.b, 1));\n if (source.alphaMap) material.opacityNode = sample(source.alphaMap, 'alphaMap').g;\n if (source.normalMap) material.normalNode = normalMap(sample(source.normalMap, 'normalMap').xyz,\n vec2(source.normalScale.x, source.normalScale.y));\n material.roughnessNode = source.roughnessMap ? sample(source.roughnessMap, 'roughnessMap').g.mul(source.roughness) : float(source.roughness);\n material.metalnessNode = source.metalnessMap ? sample(source.metalnessMap, 'metalnessMap').b.mul(source.metalness) : float(source.metalness);\n if (source.aoMap) material.aoNode = float(1).sub(float(1).sub(sample(source.aoMap, 'aoMap').r).mul(source.aoMapIntensity));\n if (source.emissiveMap) material.emissiveNode = sample(source.emissiveMap, 'emissiveMap').rgb.mul(vec3(\n source.emissive.r * source.emissiveIntensity,\n source.emissive.g * source.emissiveIntensity,\n source.emissive.b * source.emissiveIntensity));\n material.userData.furSurface = { heightMapped: Boolean(this.height), motionMapped: true };\n return material;\n }\n}\n\n/** Convert the current skin displacement into a local UV offset. The metric\n * inversion avoids assuming that U/V align with world X/Y or have equal scale. */\nfunction projectMotionToUv(movement: Node<'vec3'>, coordinates: Node<'vec2'>) {\n const dUvDx = coordinates.dFdx(), dUvDy = coordinates.dFdy();\n const dPosDx = positionLocal.dFdx(), dPosDy = positionLocal.dFdy();\n const determinant = dUvDx.x.mul(dUvDy.y).sub(dUvDx.y.mul(dUvDy.x));\n const safe = determinant.abs().max(1e-10).mul(determinant.lessThan(0).select(-1, 1));\n const dPosDu = dPosDx.mul(dUvDy.y).sub(dPosDy.mul(dUvDx.y)).div(safe);\n const dPosDv = dPosDy.mul(dUvDx.x).sub(dPosDx.mul(dUvDx.y)).div(safe);\n const uu = dPosDu.dot(dPosDu), vv = dPosDv.dot(dPosDv), uvMetric = dPosDu.dot(dPosDv);\n const metric = uu.mul(vv).sub(uvMetric.mul(uvMetric)).max(1e-12);\n const u = movement.dot(dPosDu), v = movement.dot(dPosDv);\n return vec2(vv.mul(u).sub(uvMetric.mul(v)).div(metric), uu.mul(v).sub(uvMetric.mul(u)).div(metric));\n}\n", "// @ts-check\n\n/** Keep material-slot texture replacement connected to the shader nodes.\n * @param {import('three').Material} material\n * @param {string} slot\n * @param {import('three').Texture} initial\n * @param {{value: import('three').Texture}[]} nodes\n * @param {((value: import('three').Texture) => void)=} onChange\n */\nexport function bindTextureSlot(material, slot, initial, nodes, onChange) {\n let current = initial;\n Object.defineProperty(material, slot, {\n configurable: true, enumerable: true,\n get: () => current,\n set: (/** @type {import('three').Texture} */ value) => {\n value.channel = current.channel;\n value.offset = current.offset;\n value.repeat = current.repeat;\n value.center = current.center;\n value.rotation = current.rotation;\n current = value;\n for (const node of nodes) node.value = value;\n onChange?.(value);\n material.needsUpdate = true;\n },\n });\n}\n"],
5
+ "mappings": ";;;AAAA,SAAS,iBAAiB,sBAAsB,sBAAsB,aAAa,eAAgF;AACnK,SAAS,0BAA0B,gCAA2C;AAC9E,SAAS,WAAW,OAAO,KAAK,WAAW,eAAe,SAAS,SAAS,IAAI,SAAS,MAAM,MAAM,YAAY;;;ACO1G,SAAS,gBAAgB,UAAU,MAAM,SAAS,OAAO,UAAU;AACxE,MAAI,UAAU;AACd,SAAO,eAAe,UAAU,MAAM;AAAA,IACpC,cAAc;AAAA,IAAM,YAAY;AAAA,IAChC,KAAK,MAAM;AAAA,IACX,KAAK,CAAwC,UAAU;AACrD,YAAM,UAAU,QAAQ;AACxB,YAAM,SAAS,QAAQ;AACvB,YAAM,SAAS,QAAQ;AACvB,YAAM,SAAS,QAAQ;AACvB,YAAM,WAAW,QAAQ;AACzB,gBAAU;AACV,iBAAW,QAAQ,MAAO,MAAK,QAAQ;AACvC,iBAAW,KAAK;AAChB,eAAS,cAAc;AAAA,IACzB;AAAA,EACF,CAAC;AACH;;;ADhBO,IAAM,aAA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AY,SAAS,CAAC,EAAE,OAAO,IAAI,CAAC,CAAC;AACnF,QAAM,SAAS,OAAO,IAAI,MAAM,CAAC,EAAE,IAAI,OAAO,IAAI,MAAM,CAAC,CAAC,EAAE,IAAI,IAAI;AACpE,QAAM,SAAS,OAAO,IAAI,MAAM,CAAC,EAAE,IAAI,OAAO,IAAI,MAAM,CAAC,CAAC,EAAE,IAAI,IAAI;AACpE,QAAM,KAAK,OAAO,IAAI,MAAM,GAAG,KAAK,OAAO,IAAI,MAAM,GAAG,WAAW,OAAO,IAAI,MAAM;AACpF,QAAM,SAAS,GAAG,IAAI,EAAE,EAAE,IAAI,SAAS,IAAI,QAAQ,CAAC,EAAE,IAAI,KAAK;AAC/D,QAAM,IAAI,SAAS,IAAI,MAAM,GAAG,IAAI,SAAS,IAAI,MAAM;AACvD,SAAO,KAAK,GAAG,IAAI,CAAC,EAAE,IAAI,SAAS,IAAI,CAAC,CAAC,EAAE,IAAI,MAAM,GAAG,GAAG,IAAI,CAAC,EAAE,IAAI,SAAS,IAAI,CAAC,CAAC,EAAE,IAAI,MAAM,CAAC;AACpG;",
6
6
  "names": []
7
7
  }
@@ -1480,9 +1480,32 @@ function driveRig(pins, reference, drivers) {
1480
1480
  }
1481
1481
 
1482
1482
  // src/deformation/fur-surface.ts
1483
- import { BufferAttribute, MeshPhysicalMaterial, MeshStandardMaterial, SkinnedMesh } from "three";
1483
+ import { BufferAttribute, MeshPhysicalMaterial, MeshStandardMaterial, SkinnedMesh, Vector2 } from "three";
1484
1484
  import { MeshPhysicalNodeMaterial, MeshStandardNodeMaterial } from "three/webgpu";
1485
1485
  import { attribute, float, mix, normalMap, positionLocal, texture, uniform, uv, varying, vec2, vec3, vec4 } from "three/tsl";
1486
+
1487
+ // src/rendering/texture-slot.js
1488
+ function bindTextureSlot(material, slot, initial, nodes, onChange) {
1489
+ let current = initial;
1490
+ Object.defineProperty(material, slot, {
1491
+ configurable: true,
1492
+ enumerable: true,
1493
+ get: () => current,
1494
+ set: (value) => {
1495
+ value.channel = current.channel;
1496
+ value.offset = current.offset;
1497
+ value.repeat = current.repeat;
1498
+ value.center = current.center;
1499
+ value.rotation = current.rotation;
1500
+ current = value;
1501
+ for (const node of nodes) node.value = value;
1502
+ onChange?.(value);
1503
+ material.needsUpdate = true;
1504
+ }
1505
+ });
1506
+ }
1507
+
1508
+ // src/deformation/fur-surface.ts
1486
1509
  var FurSurface = class {
1487
1510
  surfaces = [];
1488
1511
  height = null;
@@ -1559,30 +1582,50 @@ var FurSurface = class {
1559
1582
  if (!signal) return material;
1560
1583
  const depth = attribute("furDepth", "float").mul(5).clamp(0, 1);
1561
1584
  const skinnedDelta = varying(positionLocal.sub(attribute("position", "vec3")), "furSkinDelta");
1562
- const dimensions = signal.image;
1563
- const pixel = vec2(1 / Math.max(1, dimensions?.width ?? 1024), 1 / Math.max(1, dimensions?.height ?? 1024));
1585
+ const signalSlot = ["map", "normalMap", "roughnessMap", "metalnessMap", "emissiveMap", "aoMap", "alphaMap"].find((slot) => Reflect.get(source, slot) === signal) ?? "furHeightMap";
1586
+ const pixel = uniform(new Vector2());
1587
+ const updatePixel = (map) => {
1588
+ const dimensions = map.image;
1589
+ pixel.value.set(1 / Math.max(1, dimensions?.width ?? 1024), 1 / Math.max(1, dimensions?.height ?? 1024));
1590
+ };
1591
+ updatePixel(signal);
1564
1592
  const movement = projectMotionToUv(skinnedDelta, coordinates).clamp(pixel.mul(-1.5), pixel.mul(1.5));
1565
- const height = this.height ? texture(this.height, uv(this.height.channel)).r : float(0.5);
1593
+ const heightNode = this.height ? texture(this.height, uv(this.height.channel)) : null;
1594
+ if (heightNode && this.height) bindTextureSlot(
1595
+ material,
1596
+ "furHeightMap",
1597
+ this.height,
1598
+ [heightNode],
1599
+ (value) => {
1600
+ this.height = value;
1601
+ if (signalSlot === "furHeightMap") updatePixel(value);
1602
+ }
1603
+ );
1604
+ const height = heightNode ? heightNode.r : float(0.5);
1566
1605
  const raised = mix(0.65, 1.35, height);
1567
1606
  const phase = coordinates.dot(vec2(31, 43)).add(height.sub(0.5).mul(2.4)).add(this.clock.mul(this.wind).mul(1.7));
1568
1607
  const gust = vec2(phase.sin(), phase.mul(1.31).cos()).mul(pixel).mul(this.wind.mul(0.65));
1569
1608
  const shift = movement.add(gust).mul(depth).mul(raised).clamp(pixel.mul(-2), pixel.mul(2)).toVar("furTextureShift");
1570
- const sample = (map) => {
1609
+ const sample = (map, slot) => {
1571
1610
  const node = texture(map, uv(map.channel).add(shift));
1572
1611
  node.updateMatrix = true;
1612
+ bindTextureSlot(material, slot, map, [node], (value) => {
1613
+ Reflect.set(source, slot, value);
1614
+ if (signalSlot === slot) updatePixel(value);
1615
+ });
1573
1616
  return node;
1574
1617
  };
1575
- const base = source.map ? sample(source.map) : vec4(1);
1618
+ const base = source.map ? sample(source.map, "map") : vec4(1);
1576
1619
  material.colorNode = base.mul(vec4(source.color.r, source.color.g, source.color.b, 1));
1577
- if (source.alphaMap) material.opacityNode = sample(source.alphaMap).g;
1620
+ if (source.alphaMap) material.opacityNode = sample(source.alphaMap, "alphaMap").g;
1578
1621
  if (source.normalMap) material.normalNode = normalMap(
1579
- sample(source.normalMap).xyz,
1622
+ sample(source.normalMap, "normalMap").xyz,
1580
1623
  vec2(source.normalScale.x, source.normalScale.y)
1581
1624
  );
1582
- material.roughnessNode = source.roughnessMap ? sample(source.roughnessMap).g.mul(source.roughness) : float(source.roughness);
1583
- material.metalnessNode = source.metalnessMap ? sample(source.metalnessMap).b.mul(source.metalness) : float(source.metalness);
1584
- if (source.aoMap) material.aoNode = float(1).sub(float(1).sub(sample(source.aoMap).r).mul(source.aoMapIntensity));
1585
- if (source.emissiveMap) material.emissiveNode = sample(source.emissiveMap).rgb.mul(vec3(
1625
+ material.roughnessNode = source.roughnessMap ? sample(source.roughnessMap, "roughnessMap").g.mul(source.roughness) : float(source.roughness);
1626
+ material.metalnessNode = source.metalnessMap ? sample(source.metalnessMap, "metalnessMap").b.mul(source.metalness) : float(source.metalness);
1627
+ if (source.aoMap) material.aoNode = float(1).sub(float(1).sub(sample(source.aoMap, "aoMap").r).mul(source.aoMapIntensity));
1628
+ if (source.emissiveMap) material.emissiveNode = sample(source.emissiveMap, "emissiveMap").rgb.mul(vec3(
1586
1629
  source.emissive.r * source.emissiveIntensity,
1587
1630
  source.emissive.g * source.emissiveIntensity,
1588
1631
  source.emissive.b * source.emissiveIntensity