@needle-tools/three-mesh-effects 0.2.3 → 0.3.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.
- package/CHANGELOG.md +25 -8
- package/README.md +68 -1
- package/SKILL.md +9 -1
- package/build/box-impostor-runtime.js +1298 -0
- package/build/box-impostor-runtime.js.map +7 -0
- package/build/deformation-runtime.js +30 -19
- package/build/deformation-runtime.js.map +3 -3
- package/build/hull-effects.js +60 -28
- package/build/hull-effects.js.map +3 -3
- package/build/impostor-runtime.js +152 -87
- package/build/impostor-runtime.js.map +3 -3
- package/build/index.js +4 -0
- package/build/index.js.map +2 -2
- package/build/internal/box-impostor/box-impostor-display-settings.js +50 -0
- package/build/internal/box-impostor/box-impostor-display-settings.js.map +7 -0
- package/build/internal/box-impostor/box-impostor-display.js +1005 -0
- package/build/internal/box-impostor/box-impostor-display.js.map +7 -0
- package/build/internal/box-impostor/box-impostor-face-axes.js +15 -0
- package/build/internal/box-impostor/box-impostor-face-axes.js.map +7 -0
- package/build/internal/box-impostor/box-impostor-faces.js +125 -0
- package/build/internal/box-impostor/box-impostor-faces.js.map +7 -0
- package/build/internal/box-impostor/box-impostor-geometry.js +230 -0
- package/build/internal/box-impostor/box-impostor-geometry.js.map +7 -0
- package/build/internal/box-impostor/box-impostor-material.js +964 -0
- package/build/internal/box-impostor/box-impostor-material.js.map +7 -0
- package/build/internal/box-impostor/box-impostor-metadata.js +108 -0
- package/build/internal/box-impostor/box-impostor-metadata.js.map +7 -0
- package/build/internal/box-impostor/box-impostor-projection.js +256 -0
- package/build/internal/box-impostor/box-impostor-projection.js.map +7 -0
- package/build/internal/box-impostor/box-impostor-runtime.js +1252 -0
- package/build/internal/box-impostor/box-impostor-runtime.js.map +7 -0
- package/build/internal/box-impostor/box-impostor-surface-search.js +21 -0
- package/build/internal/box-impostor/box-impostor-surface-search.js.map +7 -0
- package/build/internal/deformation/cloth-surface.js +23 -17
- package/build/internal/deformation/cloth-surface.js.map +3 -3
- package/build/internal/deformation/pin-cloth.js +7 -2
- package/build/internal/deformation/pin-cloth.js.map +2 -2
- package/build/internal/deformation/rig-runtime.js +30 -19
- package/build/internal/deformation/rig-runtime.js.map +3 -3
- package/build/internal/impostor/impostor-node-material.js +152 -87
- package/build/internal/impostor/impostor-node-material.js.map +3 -3
- package/build/internal/rendering/hull-effect-runtime.js +59 -27
- package/build/internal/rendering/hull-effect-runtime.js.map +3 -3
- package/build/internal/rendering/wireframe.js +41 -9
- package/build/internal/rendering/wireframe.js.map +2 -2
- package/build/internal/rendering/wrap-preview.js +59 -27
- package/build/internal/rendering/wrap-preview.js.map +3 -3
- package/build/types/box-impostor/box-impostor-display-settings.d.ts +30 -0
- package/build/types/box-impostor/box-impostor-display-settings.js +1 -0
- package/build/types/box-impostor/box-impostor-display.d.ts +5 -0
- package/build/types/box-impostor/box-impostor-display.js +1 -0
- package/build/types/box-impostor/box-impostor-face-axes.d.ts +5 -0
- package/build/types/box-impostor/box-impostor-face-axes.js +1 -0
- package/build/types/box-impostor/box-impostor-faces.d.ts +11 -0
- package/build/types/box-impostor/box-impostor-faces.js +1 -0
- package/build/types/box-impostor/box-impostor-geometry.d.ts +5 -0
- package/build/types/box-impostor/box-impostor-geometry.js +1 -0
- package/build/types/box-impostor/box-impostor-material.d.ts +10 -0
- package/build/types/box-impostor/box-impostor-material.js +1 -0
- package/build/types/box-impostor/box-impostor-metadata.d.ts +31 -0
- package/build/types/box-impostor/box-impostor-metadata.js +1 -0
- package/build/types/box-impostor/box-impostor-projection.d.ts +19 -0
- package/build/types/box-impostor/box-impostor-projection.js +1 -0
- package/build/types/box-impostor/box-impostor-runtime.d.ts +25 -0
- package/build/types/box-impostor/box-impostor-runtime.js +1 -0
- package/build/types/box-impostor/box-impostor-surface-search.d.ts +13 -0
- package/build/types/box-impostor/box-impostor-surface-search.js +1 -0
- package/build/types/deformation/cloth-surface.d.ts +1 -0
- package/build/types/deformation/pin-cloth.d.ts +1 -0
- package/build/types/public/box-impostor-runtime.d.ts +6 -0
- package/build/types/public/box-impostor-runtime.js +1 -0
- package/build/types/public/hull-effects.d.ts +1 -0
- package/build/types/public/index.d.ts +1 -1
- package/build/types/rendering/wireframe.d.ts +2 -2
- package/package.json +27 -6
- package/src/box-impostor/box-impostor-display-settings.js +54 -0
- package/src/box-impostor/box-impostor-display.js +38 -0
- package/src/box-impostor/box-impostor-face-axes.js +11 -0
- package/src/box-impostor/box-impostor-faces.js +118 -0
- package/src/box-impostor/box-impostor-geometry.js +140 -0
- package/src/box-impostor/box-impostor-material.js +721 -0
- package/src/box-impostor/box-impostor-metadata.js +122 -0
- package/src/box-impostor/box-impostor-projection.js +287 -0
- package/src/box-impostor/box-impostor-runtime.js +122 -0
- package/src/box-impostor/box-impostor-surface-search.js +11 -0
- package/src/deformation/cloth-surface.ts +28 -17
- package/src/deformation/pin-cloth.ts +9 -3
- package/src/impostor/impostor-node-material.js +177 -117
- package/src/public/box-impostor-runtime.js +14 -0
- package/src/public/hull-effects.js +1 -0
- package/src/public/index.js +5 -1
- package/src/rendering/wireframe.js +51 -13
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
import {
|
|
3
|
+
BufferGeometry,
|
|
4
|
+
Float32BufferAttribute,
|
|
5
|
+
InterleavedBuffer,
|
|
6
|
+
InterleavedBufferAttribute,
|
|
7
|
+
} from 'three';
|
|
8
|
+
import {
|
|
9
|
+
BOX_FACE_AXES,
|
|
10
|
+
parseBoxImpostorDescriptor,
|
|
11
|
+
} from './box-impostor-metadata.js';
|
|
12
|
+
|
|
13
|
+
/** Portable six-face boxes (or a front card) with atlas UVs. Runtime attributes
|
|
14
|
+
* repeat each box's transform so all boxes can use a single material and draw.
|
|
15
|
+
* @param {import('./box-impostor-metadata.js').BoxImpostorDescriptor} input */
|
|
16
|
+
export function createBoxImpostorGeometry(input) {
|
|
17
|
+
const d = parseBoxImpostorDescriptor(input);
|
|
18
|
+
const depths = /** @type {number[][]} */ ([[], [], []]);
|
|
19
|
+
const positions = [],
|
|
20
|
+
normals = [],
|
|
21
|
+
uvs = [],
|
|
22
|
+
indices = [],
|
|
23
|
+
centers = [],
|
|
24
|
+
halves = [],
|
|
25
|
+
axisX = [],
|
|
26
|
+
axisY = [],
|
|
27
|
+
axisZ = [],
|
|
28
|
+
boxIds = [],
|
|
29
|
+
faces = [],
|
|
30
|
+
corners = [];
|
|
31
|
+
for (const [id, b] of d.boxes.entries())
|
|
32
|
+
for (const f of d.mode !== 'fitted' ? [4] : [0, 1, 2, 3, 4, 5]) {
|
|
33
|
+
const face = BOX_FACE_AXES[f],
|
|
34
|
+
base = positions.length / 3,
|
|
35
|
+
r = b.views[f],
|
|
36
|
+
p = d.padding;
|
|
37
|
+
for (const [x, y] of [
|
|
38
|
+
[-1, -1],
|
|
39
|
+
[1, -1],
|
|
40
|
+
[1, 1],
|
|
41
|
+
[-1, 1],
|
|
42
|
+
]) {
|
|
43
|
+
const local = face.normal.map(
|
|
44
|
+
(n, a) => (n + face.right[a] * x + face.up[a] * y) * b.halfSize[a],
|
|
45
|
+
);
|
|
46
|
+
positions.push(
|
|
47
|
+
...b.center.map(
|
|
48
|
+
(c, a) => c + local.reduce((s, v, i) => s + v * b.axes[i][a], 0),
|
|
49
|
+
),
|
|
50
|
+
);
|
|
51
|
+
normals.push(
|
|
52
|
+
...[0, 1, 2].map((a) =>
|
|
53
|
+
face.normal.reduce((s, v, i) => s + v * b.axes[i][a], 0),
|
|
54
|
+
),
|
|
55
|
+
);
|
|
56
|
+
uvs.push(
|
|
57
|
+
(r[0] + p + (x + 1) * 0.5 * (r[2] - 2 * p)) / d.atlasResolution,
|
|
58
|
+
(r[1] + p + (y + 1) * 0.5 * (r[3] - 2 * p)) / d.atlasResolution,
|
|
59
|
+
);
|
|
60
|
+
centers.push(...b.center);
|
|
61
|
+
halves.push(...b.halfSize);
|
|
62
|
+
axisX.push(...b.axes[0]);
|
|
63
|
+
axisY.push(...b.axes[1]);
|
|
64
|
+
axisZ.push(...b.axes[2]);
|
|
65
|
+
for (let axis = 0; axis < 3; axis++)
|
|
66
|
+
depths[axis].push(
|
|
67
|
+
...(
|
|
68
|
+
b.depthBounds?.slice(axis * 4, axis * 4 + 4) ?? [
|
|
69
|
+
0, 65535, 0, 65535,
|
|
70
|
+
]
|
|
71
|
+
).map((v) => v / 65535),
|
|
72
|
+
);
|
|
73
|
+
boxIds.push(id);
|
|
74
|
+
faces.push(f);
|
|
75
|
+
corners.push(x, y);
|
|
76
|
+
}
|
|
77
|
+
indices.push(base, base + 1, base + 2, base, base + 2, base + 3);
|
|
78
|
+
}
|
|
79
|
+
const geometry = new BufferGeometry();
|
|
80
|
+
for (const [name, data, size] of /** @type {[string,number[],number][]} */ ([
|
|
81
|
+
['position', positions, 3],
|
|
82
|
+
['normal', normals, 3],
|
|
83
|
+
['uv', uvs, 2],
|
|
84
|
+
['boxCenter', centers, 3],
|
|
85
|
+
['boxHalfSize', halves, 3],
|
|
86
|
+
['boxAxisX', axisX, 3],
|
|
87
|
+
['boxAxisY', axisY, 3],
|
|
88
|
+
['boxAxisZ', axisZ, 3],
|
|
89
|
+
['boxDepthX', depths[0], 4],
|
|
90
|
+
['boxDepthY', depths[1], 4],
|
|
91
|
+
['boxDepthZ', depths[2], 4],
|
|
92
|
+
['boxId', boxIds, 1],
|
|
93
|
+
['boxFace', faces, 1],
|
|
94
|
+
['cardCorner', corners, 2],
|
|
95
|
+
]))
|
|
96
|
+
geometry.setAttribute(name, new Float32BufferAttribute(data, size));
|
|
97
|
+
const names = [
|
|
98
|
+
'boxCenter',
|
|
99
|
+
'boxHalfSize',
|
|
100
|
+
'boxAxisX',
|
|
101
|
+
'boxAxisY',
|
|
102
|
+
'boxAxisZ',
|
|
103
|
+
'boxDepthX',
|
|
104
|
+
'boxDepthY',
|
|
105
|
+
'boxDepthZ',
|
|
106
|
+
'boxId',
|
|
107
|
+
'boxFace',
|
|
108
|
+
'cardCorner',
|
|
109
|
+
];
|
|
110
|
+
const stride = names.reduce(
|
|
111
|
+
(sum, name) => sum + geometry.getAttribute(name).itemSize,
|
|
112
|
+
0,
|
|
113
|
+
);
|
|
114
|
+
const data = new Float32Array((centers.length / 3) * stride),
|
|
115
|
+
buffer = new InterleavedBuffer(data, stride);
|
|
116
|
+
let offset = 0;
|
|
117
|
+
for (const name of names) {
|
|
118
|
+
const attribute = geometry.getAttribute(name);
|
|
119
|
+
for (let vertex = 0; vertex < attribute.count; vertex++)
|
|
120
|
+
for (let component = 0; component < attribute.itemSize; component++)
|
|
121
|
+
data[vertex * stride + offset + component] = attribute.getComponent(
|
|
122
|
+
vertex,
|
|
123
|
+
component,
|
|
124
|
+
);
|
|
125
|
+
geometry.setAttribute(
|
|
126
|
+
name,
|
|
127
|
+
new InterleavedBufferAttribute(buffer, attribute.itemSize, offset),
|
|
128
|
+
);
|
|
129
|
+
offset += attribute.itemSize;
|
|
130
|
+
}
|
|
131
|
+
// Barycentric components face the opposite triangle edge. Mask the shared
|
|
132
|
+
// 0–2 diagonal of each quad while retaining all four carrier boundaries.
|
|
133
|
+
geometry.userData.previewWireframeEdgeMasks = Float32Array.from(
|
|
134
|
+
{ length: indices.length }, (_, i) => [1, 0, 1, 1, 1, 0][i % 6],
|
|
135
|
+
);
|
|
136
|
+
geometry.setIndex(indices);
|
|
137
|
+
geometry.computeBoundingBox();
|
|
138
|
+
geometry.computeBoundingSphere();
|
|
139
|
+
return geometry;
|
|
140
|
+
}
|