@needle-tools/three-mesh-effects 0.2.1 → 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.
- package/CHANGELOG.md +9 -0
- package/README.md +8 -0
- package/SKILL.md +70 -0
- package/build/deformation-runtime.js +55 -12
- package/build/deformation-runtime.js.map +3 -3
- package/build/impostor-runtime.js +83 -29
- package/build/impostor-runtime.js.map +3 -3
- package/build/internal/deformation/fur-surface.js +55 -12
- package/build/internal/deformation/fur-surface.js.map +3 -3
- package/build/internal/deformation/rig-runtime.js +55 -12
- package/build/internal/deformation/rig-runtime.js.map +3 -3
- package/build/internal/impostor/impostor-node-material.js +83 -29
- package/build/internal/impostor/impostor-node-material.js.map +3 -3
- package/build/internal/rendering/texture-slot.js +26 -0
- package/build/internal/rendering/texture-slot.js.map +7 -0
- package/build/types/rendering/texture-slot.d.ts +10 -0
- package/build/types/rendering/texture-slot.js +1 -0
- package/package.json +2 -2
- package/src/deformation/fur-surface.ts +22 -12
- package/src/impostor/impostor-node-material.js +61 -33
- package/src/rendering/texture-slot.js +27 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.2.3 - 2026-10-30
|
|
4
|
+
|
|
5
|
+
- Keep impostor shading and fur textures connected when progressive loading replaces a texture. Fur height preserves its UV channel and texture transforms; fur motion limits follow the loaded resolution.
|
|
6
|
+
- Sample resized impostor color and shading atlases using their loaded dimensions, with frame boundaries and safe mip levels respected. Packed geometry/depth and sparse pixel records still require their authored resolution.
|
|
7
|
+
|
|
8
|
+
## 0.2.2 - 2026-10-21
|
|
9
|
+
|
|
10
|
+
- Include a package-root `SKILL.md` with integration guidance for extension loading, compression decoders, runtime updates, and cleanup in Three.js and Needle Engine applications.
|
|
11
|
+
|
|
3
12
|
## 0.2.1 - 2026-10-21
|
|
4
13
|
|
|
5
14
|
- Put installation and features before the Quick start, and clarify that consumers configure compression decoders themselves when needed.
|
package/README.md
CHANGED
|
@@ -58,6 +58,14 @@ Rig animation still needs a per-frame update, pixel display modes remain availab
|
|
|
58
58
|
through `createPixelImpostorDisplay`. Hull effects load alone; optionally use
|
|
59
59
|
`bindHull` to add an original model and animation syncing.
|
|
60
60
|
|
|
61
|
+
When your loader also supports `NEEDLE_progressive`, impostor shading and fur
|
|
62
|
+
textures can change resolution in place. Material bindings and size-dependent
|
|
63
|
+
sampling update when a texture is replaced; fur height keeps its UV channel and
|
|
64
|
+
texture transforms. Resize impostor atlases per frame rather than filtering
|
|
65
|
+
across neighboring views. Compact shading alpha stores material data and needs
|
|
66
|
+
independent channel filtering and lossless PNG encoding. Packed depth/geometry
|
|
67
|
+
and sparse pixel-impostor records must retain their authored resolution.
|
|
68
|
+
|
|
61
69
|
## Hull effects
|
|
62
70
|
|
|
63
71
|
When exporting with a hull effect selected, Mesh Baker saves its mode and
|
package/SKILL.md
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: three-mesh-effects
|
|
3
|
+
description: Integrate Mesh Baker glTF models into Three.js or Needle Engine applications, including extension loading, hull effects, deformation rigs, and pixel impostor displays.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Three Mesh Effects
|
|
7
|
+
|
|
8
|
+
Use the public runtime package to reproduce a Mesh Baker export in an existing
|
|
9
|
+
viewer. Read [README.md](README.md) for effect-specific examples and supported
|
|
10
|
+
Three.js versions. Read `package.json` for the installed version and exports.
|
|
11
|
+
|
|
12
|
+
## Loader setup
|
|
13
|
+
|
|
14
|
+
Register `useLoader(loader, renderer)` from `@needle-tools/three-mesh-effects`
|
|
15
|
+
before loading or parsing an asset. Reuse the application's configured GLTFLoader
|
|
16
|
+
and renderer; preserve its Draco, Meshopt, KTX2, progressive-loading and other
|
|
17
|
+
plugins. Consumers configure compression decoders themselves.
|
|
18
|
+
|
|
19
|
+
The loader detects the asset's declared Needle extensions and dynamically
|
|
20
|
+
imports their handlers. Do not require callers to inspect extensions or invoke
|
|
21
|
+
separate registration functions. An optional typed third argument can disable
|
|
22
|
+
handlers, for example `{ disable: ['NEEDLE_hull_effect'] }`. Everything is enabled
|
|
23
|
+
by default. Disabled optional extensions retain their portable fallback;
|
|
24
|
+
disabled required extensions reject loading.
|
|
25
|
+
|
|
26
|
+
For Needle Engine, call `useLoader(loader, context.renderer)` in the engine's
|
|
27
|
+
custom extension `onImport` hook. Install the integration before creating viewers.
|
|
28
|
+
Use the existing render loop and model teardown hooks rather than starting an
|
|
29
|
+
independent animation loop.
|
|
30
|
+
|
|
31
|
+
## Runtime updates and ownership
|
|
32
|
+
|
|
33
|
+
- Deformation rigs: obtain `getDeformationRig(scene)` from `/deformation-runtime`.
|
|
34
|
+
Advance the application's AnimationMixer first, then `rig.update(deltaSeconds)`.
|
|
35
|
+
Dispose the rig before releasing its model.
|
|
36
|
+
- Hulls: the versioned scene extension restores the saved effect automatically.
|
|
37
|
+
Obtain `getHullEffect(scene)` from `/hull-effects`. An original model is optional.
|
|
38
|
+
`bindHull(hull, original, { animate: true })` attaches a borrowed original and
|
|
39
|
+
replaces the effect; `bindHull(hull, null)` detaches it. Fetch the current effect
|
|
40
|
+
after rebinding, call `syncAnimation()` after mixers and rig updates, and dispose
|
|
41
|
+
the current effect before unloading. Never dispose the borrowed original's
|
|
42
|
+
geometry, materials or textures as part of binding cleanup.
|
|
43
|
+
- Pixel impostors: extension loading restores atlas bindings. Custom display
|
|
44
|
+
modes still use `createPixelImpostorDisplay` from `/pixel-impostor-runtime`;
|
|
45
|
+
update its viewport and dispose it as documented in the README.
|
|
46
|
+
- Octahedral impostors: pass the actual renderer to `useLoader` so the handler
|
|
47
|
+
can choose the supported material implementation.
|
|
48
|
+
|
|
49
|
+
Hull and other TSL effects require a renderer supporting node materials. Ordinary
|
|
50
|
+
Three.js applications use WebGPURenderer from `three/webgpu`, with its WebGPU or
|
|
51
|
+
WebGL2 backend. Some hosts provide their own TSL integration; inspect it before
|
|
52
|
+
changing their renderer or disabling existing rendering features.
|
|
53
|
+
|
|
54
|
+
When a scene is cleared while asynchronous initialization is pending, dispose
|
|
55
|
+
any runtimes that finish afterward. Track scenes separately per viewer/context,
|
|
56
|
+
including assets with multiple scenes. Avoid loading optional runtime modules
|
|
57
|
+
just to poll ordinary models that have no corresponding extension.
|
|
58
|
+
|
|
59
|
+
## Verification
|
|
60
|
+
|
|
61
|
+
Exercise real GLTFLoader parsing and the host's update/clear lifecycle. Cover
|
|
62
|
+
ordinary assets, mixed extensions, opt-outs, disposal and asynchronous clear/load
|
|
63
|
+
races. Verify renderer compatibility when shader effects are involved; mocked
|
|
64
|
+
lifecycle tests alone do not establish visual correctness. Report checks that
|
|
65
|
+
were not run.
|
|
66
|
+
|
|
67
|
+
When extending this package, every new Needle glTF runtime extension must also
|
|
68
|
+
work through `useLoader`, including its typed disable key and lazy handler.
|
|
69
|
+
Preserve existing manual APIs. Use a versioned glTF extension for runtime data,
|
|
70
|
+
retain a portable fallback, and keep runtime contracts out of `extras`.
|
|
@@ -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
|
|
1563
|
-
const pixel =
|
|
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
|
|
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
|