@needle-tools/three-mesh-effects 0.1.0-alpha → 0.1.0-alpha.0
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/LICENSE +21 -21
- package/README.md +94 -88
- package/build/deformation-runtime.js.map +1 -1
- package/build/impostor-runtime-needle-engine.js.map +1 -1
- package/build/impostor-runtime.js.map +1 -1
- package/build/internal/deformation/cloth-surface.js.map +1 -1
- package/build/internal/deformation/fur-surface.js.map +1 -1
- package/build/internal/deformation/ik-constraints.js.map +1 -1
- package/build/internal/deformation/joints-json.js.map +1 -1
- package/build/internal/deformation/limits.js.map +1 -1
- package/build/internal/deformation/motion-settings.js.map +1 -1
- package/build/internal/deformation/pin-cloth.js.map +1 -1
- package/build/internal/deformation/pin-ik.js.map +1 -1
- package/build/internal/deformation/pin-types.js.map +1 -1
- package/build/internal/deformation/pin-wiggle.js.map +1 -1
- package/build/internal/deformation/pose-slots.js.map +1 -1
- package/build/internal/deformation/pose-timeline.js.map +1 -1
- package/build/internal/deformation/rig-drivers.js.map +1 -1
- package/build/internal/deformation/rig-extension.js.map +1 -1
- package/build/internal/deformation/rig-runtime.js.map +1 -1
- package/build/internal/deformation/wind.js.map +1 -1
- package/build/internal/impostor/impostor-metadata.js.map +1 -1
- package/build/internal/impostor/impostor-node-material.js.map +1 -1
- package/build/internal/impostor/impostor-runtime-support.js.map +1 -1
- package/build/internal/impostor/octahedral.js.map +1 -1
- package/build/internal/pixel-impostor/pixel-impostor-display.js.map +1 -1
- package/build/internal/pixel-impostor/pixel-impostor-metadata.js.map +1 -1
- package/build/internal/pixel-impostor/pixel-impostor-runtime.js.map +1 -1
- package/build/internal/rendering/skin-projection.js +52 -52
- package/build/internal/rendering/skin-projection.js.map +2 -2
- package/build/internal/rendering/surface-query.js +52 -52
- package/build/internal/rendering/surface-query.js.map +2 -2
- package/build/internal/rendering/wireframe.js.map +1 -1
- package/build/internal/rendering/wrap-preview-settings.js.map +1 -1
- package/build/internal/rendering/wrap-preview.js +52 -52
- package/build/internal/rendering/wrap-preview.js.map +2 -2
- package/build/internal/rendering/wrap-skin.js +52 -52
- package/build/internal/rendering/wrap-skin.js.map +2 -2
- package/build/pixel-impostor-runtime.js.map +1 -1
- package/build/wrap-effects.js +52 -52
- package/build/wrap-effects.js.map +2 -2
- package/package.json +107 -94
- package/src/deformation/cloth-surface.ts +223 -223
- package/src/deformation/fur-surface.ts +129 -129
- package/src/deformation/ik-constraints.ts +37 -37
- package/src/deformation/joints-json.ts +94 -94
- package/src/deformation/limits.ts +25 -25
- package/src/deformation/motion-settings.ts +9 -9
- package/src/deformation/pin-cloth.ts +149 -149
- package/src/deformation/pin-ik.ts +582 -582
- package/src/deformation/pin-types.ts +22 -22
- package/src/deformation/pin-wiggle.ts +119 -119
- package/src/deformation/pose-slots.ts +106 -106
- package/src/deformation/pose-timeline.ts +242 -242
- package/src/deformation/rig-drivers.ts +32 -32
- package/src/deformation/rig-extension.ts +87 -87
- package/src/deformation/rig-runtime.ts +416 -416
- package/src/deformation/wind.ts +36 -36
- package/src/impostor/impostor-metadata.js +137 -137
- package/src/impostor/impostor-node-material.js +1581 -1581
- package/src/impostor/impostor-runtime-support.js +139 -139
- package/src/impostor/octahedral.js +280 -280
- package/src/pixel-impostor/pixel-impostor-display.js +794 -794
- package/src/pixel-impostor/pixel-impostor-metadata.js +74 -74
- package/src/pixel-impostor/pixel-impostor-runtime.js +78 -78
- package/src/public/deformation-runtime.ts +3 -3
- package/src/public/impostor-runtime-needle-engine.js +56 -56
- package/src/public/impostor-runtime.js +21 -21
- package/src/public/pixel-impostor-runtime.js +5 -5
- package/src/public/wrap-effects.js +21 -21
- package/src/rendering/skin-projection.js +113 -113
- package/src/rendering/surface-query.js +88 -88
- package/src/rendering/wireframe.js +115 -115
- package/src/rendering/wrap-preview-settings.js +123 -123
- package/src/rendering/wrap-preview.js +645 -645
- package/src/rendering/wrap-skin.js +109 -109
- package/build/internal/public/deformation-runtime.js +0 -2143
- package/build/internal/public/deformation-runtime.js.map +0 -7
- package/build/internal/public/impostor-runtime-needle-engine.js +0 -42
- package/build/internal/public/impostor-runtime-needle-engine.js.map +0 -7
- package/build/internal/public/impostor-runtime.js +0 -1333
- package/build/internal/public/impostor-runtime.js.map +0 -7
- package/build/internal/public/pixel-impostor-runtime.js +0 -876
- package/build/internal/public/pixel-impostor-runtime.js.map +0 -7
- package/build/internal/public/wrap-effects.js +0 -5640
- package/build/internal/public/wrap-effects.js.map +0 -7
|
@@ -1,113 +1,113 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
import { Triangle, Vector3 } from 'three';
|
|
3
|
-
import { createSurfaceQuery } from './surface-query.js';
|
|
4
|
-
/** @typedef {{size: number, data: Float32Array}} SkinAttribute */
|
|
5
|
-
/** @typedef {{positions: Float32Array, indices: Uint32Array, attributes: Map<string, SkinAttribute>}} SkinGeometry */
|
|
6
|
-
|
|
7
|
-
/** @param {SkinGeometry[]} meshes @returns {SkinGeometry} */
|
|
8
|
-
export function mergeSkinGeometry(meshes) {
|
|
9
|
-
const semantics = new Set(meshes.flatMap(m => [...m.attributes.keys()]));
|
|
10
|
-
const count = meshes.reduce((s, m) => s + m.positions.length / 3, 0);
|
|
11
|
-
const attributes = new Map();
|
|
12
|
-
for (const semantic of semantics) {
|
|
13
|
-
const size = /** @type {SkinAttribute} */ (meshes.find(m => m.attributes.has(semantic))?.attributes.get(semantic)).size;
|
|
14
|
-
const data = new Float32Array(count * size);
|
|
15
|
-
if (semantic.startsWith('COLOR_')) data.fill(1);
|
|
16
|
-
let offset = 0;
|
|
17
|
-
for (const mesh of meshes) {
|
|
18
|
-
const attribute = mesh.attributes.get(semantic);
|
|
19
|
-
if (attribute) data.set(attribute.data, offset * size);
|
|
20
|
-
offset += mesh.positions.length / 3;
|
|
21
|
-
}
|
|
22
|
-
attributes.set(semantic, { size, data });
|
|
23
|
-
}
|
|
24
|
-
const indices = new Uint32Array(meshes.reduce((s, m) => s + m.indices.length, 0));
|
|
25
|
-
let vertexOffset = 0, indexOffset = 0;
|
|
26
|
-
for (const mesh of meshes) {
|
|
27
|
-
indices.set(mesh.indices.map(i => i + vertexOffset), indexOffset);
|
|
28
|
-
indexOffset += mesh.indices.length; vertexOffset += mesh.positions.length / 3;
|
|
29
|
-
}
|
|
30
|
-
return { positions: attributes.get('POSITION').data, indices, attributes };
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/** Reusable triangle barycentrics for both weight transfer and pose validation.
|
|
34
|
-
* @param {SkinGeometry} surface
|
|
35
|
-
* @param {{fastBuild?: boolean}} [options] A fast build suits a query made for a few thousand lookups.
|
|
36
|
-
*/
|
|
37
|
-
export function skinSurface(surface, options = {}) {
|
|
38
|
-
const query = createSurfaceQuery(surface, { fastBuild: options.fastBuild, geometryOnly: true });
|
|
39
|
-
const a = new Vector3(), b = new Vector3(), c = new Vector3(), p = new Vector3(), bary = new Vector3();
|
|
40
|
-
return {
|
|
41
|
-
dispose: () => query.dispose(),
|
|
42
|
-
/** @param {ArrayLike<number>} position */
|
|
43
|
-
closest(position) {
|
|
44
|
-
const hit = query.closestPoint(position);
|
|
45
|
-
if (!hit) throw new Error('Cannot project onto an empty surface.');
|
|
46
|
-
const vertices = Array.from(surface.indices.subarray(hit.faceIndex * 3, hit.faceIndex * 3 + 3));
|
|
47
|
-
a.fromArray(surface.positions, vertices[0] * 3); b.fromArray(surface.positions, vertices[1] * 3); c.fromArray(surface.positions, vertices[2] * 3);
|
|
48
|
-
if (!Triangle.getBarycoord(p.fromArray(hit.point), a, b, c, bary)) {
|
|
49
|
-
// Degenerate source triangles occur in collapsed supports and thin
|
|
50
|
-
// authored details. Use the closest segment, never stale barycentrics.
|
|
51
|
-
const corners = [a, b, c];
|
|
52
|
-
let distance = Infinity;
|
|
53
|
-
for (const [i, j] of [[0, 1], [1, 2], [2, 0]]) {
|
|
54
|
-
const delta = corners[j].clone().sub(corners[i]);
|
|
55
|
-
const t = Math.max(0, Math.min(1, p.clone().sub(corners[i]).dot(delta) / (delta.lengthSq() || 1)));
|
|
56
|
-
const squared = corners[i].clone().addScaledVector(delta, t).distanceToSquared(p);
|
|
57
|
-
if (squared < distance) { distance = squared; bary.set(0, 0, 0).setComponent(i, 1 - t).setComponent(j, t); }
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
return { vertices, bary: bary.toArray(), point: hit.point, face: hit.faceIndex };
|
|
61
|
-
},
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/** Transfer the closest source triangle's attributes. Joint IDs are categorical:
|
|
66
|
-
* accumulate contributions per ID, keep the strongest four, then normalize.
|
|
67
|
-
* Snapping is useful for point wraps, but reconstructed topology must retain
|
|
68
|
-
* its positions: independently snapping its vertices can invert or collapse
|
|
69
|
-
* triangles even though every individual vertex lands on the source.
|
|
70
|
-
* @param {SkinGeometry} source @param {{positions: Float32Array, indices: Uint32Array}} target
|
|
71
|
-
* @param {{snapPositions?: boolean}} [options]
|
|
72
|
-
* @returns {SkinGeometry}
|
|
73
|
-
*/
|
|
74
|
-
export function projectSkinGeometry(source, target, options = {}) {
|
|
75
|
-
const query = skinSurface(source), count = target.positions.length / 3;
|
|
76
|
-
const attributes = new Map([...source.attributes].map(([s, a]) => [s, { size: a.size, data: new Float32Array(count * a.size) }]));
|
|
77
|
-
const positions = /** @type {SkinAttribute} */ (attributes.get('POSITION')).data;
|
|
78
|
-
try {
|
|
79
|
-
for (let i = 0; i < count; i++) {
|
|
80
|
-
const hit = query.closest(target.positions.subarray(i * 3, i * 3 + 3));
|
|
81
|
-
for (const [semantic, dest] of attributes) {
|
|
82
|
-
if (semantic === 'JOINTS_0' || semantic === 'WEIGHTS_0') continue;
|
|
83
|
-
const original = /** @type {SkinAttribute} */ (source.attributes.get(semantic));
|
|
84
|
-
for (let k = 0; k < dest.size; k++) dest.data[i * dest.size + k] = hit.vertices.reduce((sum, v, j) => sum + hit.bary[j] * original.data[v * dest.size + k], 0);
|
|
85
|
-
if (semantic === 'NORMAL' || semantic === 'TANGENT') {
|
|
86
|
-
const normal = new Vector3().fromArray(dest.data, i * dest.size).normalize();
|
|
87
|
-
normal.toArray(dest.data, i * dest.size);
|
|
88
|
-
if (semantic === 'TANGENT') dest.data[i * 4 + 3] = dest.data[i * 4 + 3] < 0 ? -1 : 1;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
positions.set(options.snapPositions === false
|
|
92
|
-
? target.positions.subarray(i * 3, i * 3 + 3)
|
|
93
|
-
: hit.point, i * 3);
|
|
94
|
-
const joints = source.attributes.get('JOINTS_0'), weights = source.attributes.get('WEIGHTS_0');
|
|
95
|
-
if (joints && weights) {
|
|
96
|
-
/** @type {Map<number, number>} */
|
|
97
|
-
const contributions = new Map();
|
|
98
|
-
hit.vertices.forEach((v, j) => { for (let k = 0; k < 4; k++) {
|
|
99
|
-
const id = joints.data[v * 4 + k], w = Math.max(0, hit.bary[j]) * weights.data[v * 4 + k];
|
|
100
|
-
if (w > 0) contributions.set(id, (contributions.get(id) ?? 0) + w);
|
|
101
|
-
} });
|
|
102
|
-
const strongest = [...contributions].sort((a, b) => b[1] - a[1]).slice(0, 4);
|
|
103
|
-
const total = strongest.reduce((s, [, w]) => s + w, 0);
|
|
104
|
-
if (!(total > 0)) throw new Error('Weight projection produced no joint influence.');
|
|
105
|
-
strongest.forEach(([id, w], k) => {
|
|
106
|
-
/** @type {SkinAttribute} */ (attributes.get('JOINTS_0')).data[i * 4 + k] = id;
|
|
107
|
-
/** @type {SkinAttribute} */ (attributes.get('WEIGHTS_0')).data[i * 4 + k] = w / total;
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
} finally { query.dispose(); }
|
|
112
|
-
return { positions, indices: target.indices, attributes };
|
|
113
|
-
}
|
|
1
|
+
// @ts-check
|
|
2
|
+
import { Triangle, Vector3 } from 'three';
|
|
3
|
+
import { createSurfaceQuery } from './surface-query.js';
|
|
4
|
+
/** @typedef {{size: number, data: Float32Array}} SkinAttribute */
|
|
5
|
+
/** @typedef {{positions: Float32Array, indices: Uint32Array, attributes: Map<string, SkinAttribute>}} SkinGeometry */
|
|
6
|
+
|
|
7
|
+
/** @param {SkinGeometry[]} meshes @returns {SkinGeometry} */
|
|
8
|
+
export function mergeSkinGeometry(meshes) {
|
|
9
|
+
const semantics = new Set(meshes.flatMap(m => [...m.attributes.keys()]));
|
|
10
|
+
const count = meshes.reduce((s, m) => s + m.positions.length / 3, 0);
|
|
11
|
+
const attributes = new Map();
|
|
12
|
+
for (const semantic of semantics) {
|
|
13
|
+
const size = /** @type {SkinAttribute} */ (meshes.find(m => m.attributes.has(semantic))?.attributes.get(semantic)).size;
|
|
14
|
+
const data = new Float32Array(count * size);
|
|
15
|
+
if (semantic.startsWith('COLOR_')) data.fill(1);
|
|
16
|
+
let offset = 0;
|
|
17
|
+
for (const mesh of meshes) {
|
|
18
|
+
const attribute = mesh.attributes.get(semantic);
|
|
19
|
+
if (attribute) data.set(attribute.data, offset * size);
|
|
20
|
+
offset += mesh.positions.length / 3;
|
|
21
|
+
}
|
|
22
|
+
attributes.set(semantic, { size, data });
|
|
23
|
+
}
|
|
24
|
+
const indices = new Uint32Array(meshes.reduce((s, m) => s + m.indices.length, 0));
|
|
25
|
+
let vertexOffset = 0, indexOffset = 0;
|
|
26
|
+
for (const mesh of meshes) {
|
|
27
|
+
indices.set(mesh.indices.map(i => i + vertexOffset), indexOffset);
|
|
28
|
+
indexOffset += mesh.indices.length; vertexOffset += mesh.positions.length / 3;
|
|
29
|
+
}
|
|
30
|
+
return { positions: attributes.get('POSITION').data, indices, attributes };
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Reusable triangle barycentrics for both weight transfer and pose validation.
|
|
34
|
+
* @param {SkinGeometry} surface
|
|
35
|
+
* @param {{fastBuild?: boolean}} [options] A fast build suits a query made for a few thousand lookups.
|
|
36
|
+
*/
|
|
37
|
+
export function skinSurface(surface, options = {}) {
|
|
38
|
+
const query = createSurfaceQuery(surface, { fastBuild: options.fastBuild, geometryOnly: true });
|
|
39
|
+
const a = new Vector3(), b = new Vector3(), c = new Vector3(), p = new Vector3(), bary = new Vector3();
|
|
40
|
+
return {
|
|
41
|
+
dispose: () => query.dispose(),
|
|
42
|
+
/** @param {ArrayLike<number>} position */
|
|
43
|
+
closest(position) {
|
|
44
|
+
const hit = query.closestPoint(position);
|
|
45
|
+
if (!hit) throw new Error('Cannot project onto an empty surface.');
|
|
46
|
+
const vertices = Array.from(surface.indices.subarray(hit.faceIndex * 3, hit.faceIndex * 3 + 3));
|
|
47
|
+
a.fromArray(surface.positions, vertices[0] * 3); b.fromArray(surface.positions, vertices[1] * 3); c.fromArray(surface.positions, vertices[2] * 3);
|
|
48
|
+
if (!Triangle.getBarycoord(p.fromArray(hit.point), a, b, c, bary)) {
|
|
49
|
+
// Degenerate source triangles occur in collapsed supports and thin
|
|
50
|
+
// authored details. Use the closest segment, never stale barycentrics.
|
|
51
|
+
const corners = [a, b, c];
|
|
52
|
+
let distance = Infinity;
|
|
53
|
+
for (const [i, j] of [[0, 1], [1, 2], [2, 0]]) {
|
|
54
|
+
const delta = corners[j].clone().sub(corners[i]);
|
|
55
|
+
const t = Math.max(0, Math.min(1, p.clone().sub(corners[i]).dot(delta) / (delta.lengthSq() || 1)));
|
|
56
|
+
const squared = corners[i].clone().addScaledVector(delta, t).distanceToSquared(p);
|
|
57
|
+
if (squared < distance) { distance = squared; bary.set(0, 0, 0).setComponent(i, 1 - t).setComponent(j, t); }
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return { vertices, bary: bary.toArray(), point: hit.point, face: hit.faceIndex };
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** Transfer the closest source triangle's attributes. Joint IDs are categorical:
|
|
66
|
+
* accumulate contributions per ID, keep the strongest four, then normalize.
|
|
67
|
+
* Snapping is useful for point wraps, but reconstructed topology must retain
|
|
68
|
+
* its positions: independently snapping its vertices can invert or collapse
|
|
69
|
+
* triangles even though every individual vertex lands on the source.
|
|
70
|
+
* @param {SkinGeometry} source @param {{positions: Float32Array, indices: Uint32Array}} target
|
|
71
|
+
* @param {{snapPositions?: boolean}} [options]
|
|
72
|
+
* @returns {SkinGeometry}
|
|
73
|
+
*/
|
|
74
|
+
export function projectSkinGeometry(source, target, options = {}) {
|
|
75
|
+
const query = skinSurface(source), count = target.positions.length / 3;
|
|
76
|
+
const attributes = new Map([...source.attributes].map(([s, a]) => [s, { size: a.size, data: new Float32Array(count * a.size) }]));
|
|
77
|
+
const positions = /** @type {SkinAttribute} */ (attributes.get('POSITION')).data;
|
|
78
|
+
try {
|
|
79
|
+
for (let i = 0; i < count; i++) {
|
|
80
|
+
const hit = query.closest(target.positions.subarray(i * 3, i * 3 + 3));
|
|
81
|
+
for (const [semantic, dest] of attributes) {
|
|
82
|
+
if (semantic === 'JOINTS_0' || semantic === 'WEIGHTS_0') continue;
|
|
83
|
+
const original = /** @type {SkinAttribute} */ (source.attributes.get(semantic));
|
|
84
|
+
for (let k = 0; k < dest.size; k++) dest.data[i * dest.size + k] = hit.vertices.reduce((sum, v, j) => sum + hit.bary[j] * original.data[v * dest.size + k], 0);
|
|
85
|
+
if (semantic === 'NORMAL' || semantic === 'TANGENT') {
|
|
86
|
+
const normal = new Vector3().fromArray(dest.data, i * dest.size).normalize();
|
|
87
|
+
normal.toArray(dest.data, i * dest.size);
|
|
88
|
+
if (semantic === 'TANGENT') dest.data[i * 4 + 3] = dest.data[i * 4 + 3] < 0 ? -1 : 1;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
positions.set(options.snapPositions === false
|
|
92
|
+
? target.positions.subarray(i * 3, i * 3 + 3)
|
|
93
|
+
: hit.point, i * 3);
|
|
94
|
+
const joints = source.attributes.get('JOINTS_0'), weights = source.attributes.get('WEIGHTS_0');
|
|
95
|
+
if (joints && weights) {
|
|
96
|
+
/** @type {Map<number, number>} */
|
|
97
|
+
const contributions = new Map();
|
|
98
|
+
hit.vertices.forEach((v, j) => { for (let k = 0; k < 4; k++) {
|
|
99
|
+
const id = joints.data[v * 4 + k], w = Math.max(0, hit.bary[j]) * weights.data[v * 4 + k];
|
|
100
|
+
if (w > 0) contributions.set(id, (contributions.get(id) ?? 0) + w);
|
|
101
|
+
} });
|
|
102
|
+
const strongest = [...contributions].sort((a, b) => b[1] - a[1]).slice(0, 4);
|
|
103
|
+
const total = strongest.reduce((s, [, w]) => s + w, 0);
|
|
104
|
+
if (!(total > 0)) throw new Error('Weight projection produced no joint influence.');
|
|
105
|
+
strongest.forEach(([id, w], k) => {
|
|
106
|
+
/** @type {SkinAttribute} */ (attributes.get('JOINTS_0')).data[i * 4 + k] = id;
|
|
107
|
+
/** @type {SkinAttribute} */ (attributes.get('WEIGHTS_0')).data[i * 4 + k] = w / total;
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
} finally { query.dispose(); }
|
|
112
|
+
return { positions, indices: target.indices, attributes };
|
|
113
|
+
}
|
|
@@ -1,88 +1,88 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
import { BackSide, BufferAttribute, BufferGeometry, FrontSide, Ray, Vector3 } from 'three';
|
|
3
|
-
import { MeshBVH, SAH, AVERAGE } from 'three-mesh-bvh';
|
|
4
|
-
|
|
5
|
-
/** @typedef {{positions: Float32Array, indices: Uint32Array, normals?: Float32Array, uvs?: Float32Array}} QueryMesh */
|
|
6
|
-
/** @param {QueryMesh} mesh */
|
|
7
|
-
function assertQueryMesh(mesh) {
|
|
8
|
-
if (!(mesh.positions instanceof Float32Array) || mesh.positions.length % 3) throw new TypeError('Invalid mesh positions.');
|
|
9
|
-
if (!(mesh.indices instanceof Uint32Array) || mesh.indices.length % 3) throw new TypeError('Invalid mesh indices.');
|
|
10
|
-
const count = mesh.positions.length / 3;
|
|
11
|
-
for (const index of mesh.indices) if (index >= count) throw new RangeError('Mesh index exceeds vertex count.');
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* @param {QueryMesh} mesh
|
|
16
|
-
* @param {{fastBuild?:boolean, geometryOnly?:boolean}=} options Fast builds use centroid-average splits; geometry-only queries omit UV/normal interpolation in ray hits.
|
|
17
|
-
*/
|
|
18
|
-
export function createSurfaceQuery(mesh, options = {}) {
|
|
19
|
-
assertQueryMesh(mesh);
|
|
20
|
-
const geometry = new BufferGeometry();
|
|
21
|
-
geometry.setAttribute('position', new BufferAttribute(mesh.positions, 3));
|
|
22
|
-
if (mesh.normals && !options.geometryOnly) geometry.setAttribute('normal', new BufferAttribute(mesh.normals, 3));
|
|
23
|
-
if (mesh.uvs && !options.geometryOnly) geometry.setAttribute('uv', new BufferAttribute(mesh.uvs, 2));
|
|
24
|
-
geometry.setIndex(new BufferAttribute(mesh.indices, 1));
|
|
25
|
-
const bvh = new MeshBVH(geometry, {
|
|
26
|
-
strategy: options.fastBuild ? AVERAGE : SAH,
|
|
27
|
-
indirect: true,
|
|
28
|
-
verbose: false,
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
return createSurfaceQueryFromBvh(geometry, bvh);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Wraps a prebuilt BVH with the allocation-reusing query API used by the wrap skin preview and baker. The geometry and BVH must use indirect indexing so face IDs stay
|
|
36
|
-
* aligned with the source triangle arrays.
|
|
37
|
-
*
|
|
38
|
-
* @param {BufferGeometry} geometry
|
|
39
|
-
* @param {MeshBVH} bvh
|
|
40
|
-
*/
|
|
41
|
-
export function createSurfaceQueryFromBvh(geometry, bvh) {
|
|
42
|
-
|
|
43
|
-
const point = new Vector3();
|
|
44
|
-
const direction = new Vector3();
|
|
45
|
-
const ray = new Ray(point, direction);
|
|
46
|
-
const closestTarget = {
|
|
47
|
-
point: new Vector3(),
|
|
48
|
-
distance: Infinity,
|
|
49
|
-
faceIndex: -1,
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
return {
|
|
53
|
-
geometry,
|
|
54
|
-
bvh,
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* @param {ArrayLike<number>} value
|
|
58
|
-
* @param {number=} maxDistance
|
|
59
|
-
*/
|
|
60
|
-
closestPoint(value, maxDistance = Infinity) {
|
|
61
|
-
point.set(value[0], value[1], value[2]);
|
|
62
|
-
const hit = bvh.closestPointToPoint(point, closestTarget, 0, maxDistance);
|
|
63
|
-
if (!hit || hit.distance === undefined || hit.faceIndex === undefined || !hit.point) return null;
|
|
64
|
-
return {
|
|
65
|
-
point: [hit.point.x, hit.point.y, hit.point.z],
|
|
66
|
-
distance: hit.distance,
|
|
67
|
-
faceIndex: hit.faceIndex,
|
|
68
|
-
};
|
|
69
|
-
},
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* @param {ArrayLike<number>} origin
|
|
73
|
-
* @param {ArrayLike<number>} rayDirection
|
|
74
|
-
* @param {number} near
|
|
75
|
-
* @param {number} far
|
|
76
|
-
* @param {'front' | 'back'} side
|
|
77
|
-
*/
|
|
78
|
-
raycastFirst(origin, rayDirection, near, far, side = 'front') {
|
|
79
|
-
point.set(origin[0], origin[1], origin[2]);
|
|
80
|
-
direction.set(rayDirection[0], rayDirection[1], rayDirection[2]).normalize();
|
|
81
|
-
return bvh.raycastFirst(ray, side === 'front' ? FrontSide : BackSide, near, far);
|
|
82
|
-
},
|
|
83
|
-
|
|
84
|
-
dispose() {
|
|
85
|
-
geometry.dispose();
|
|
86
|
-
},
|
|
87
|
-
};
|
|
88
|
-
}
|
|
1
|
+
// @ts-check
|
|
2
|
+
import { BackSide, BufferAttribute, BufferGeometry, FrontSide, Ray, Vector3 } from 'three';
|
|
3
|
+
import { MeshBVH, SAH, AVERAGE } from 'three-mesh-bvh';
|
|
4
|
+
|
|
5
|
+
/** @typedef {{positions: Float32Array, indices: Uint32Array, normals?: Float32Array, uvs?: Float32Array}} QueryMesh */
|
|
6
|
+
/** @param {QueryMesh} mesh */
|
|
7
|
+
function assertQueryMesh(mesh) {
|
|
8
|
+
if (!(mesh.positions instanceof Float32Array) || mesh.positions.length % 3) throw new TypeError('Invalid mesh positions.');
|
|
9
|
+
if (!(mesh.indices instanceof Uint32Array) || mesh.indices.length % 3) throw new TypeError('Invalid mesh indices.');
|
|
10
|
+
const count = mesh.positions.length / 3;
|
|
11
|
+
for (const index of mesh.indices) if (index >= count) throw new RangeError('Mesh index exceeds vertex count.');
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @param {QueryMesh} mesh
|
|
16
|
+
* @param {{fastBuild?:boolean, geometryOnly?:boolean}=} options Fast builds use centroid-average splits; geometry-only queries omit UV/normal interpolation in ray hits.
|
|
17
|
+
*/
|
|
18
|
+
export function createSurfaceQuery(mesh, options = {}) {
|
|
19
|
+
assertQueryMesh(mesh);
|
|
20
|
+
const geometry = new BufferGeometry();
|
|
21
|
+
geometry.setAttribute('position', new BufferAttribute(mesh.positions, 3));
|
|
22
|
+
if (mesh.normals && !options.geometryOnly) geometry.setAttribute('normal', new BufferAttribute(mesh.normals, 3));
|
|
23
|
+
if (mesh.uvs && !options.geometryOnly) geometry.setAttribute('uv', new BufferAttribute(mesh.uvs, 2));
|
|
24
|
+
geometry.setIndex(new BufferAttribute(mesh.indices, 1));
|
|
25
|
+
const bvh = new MeshBVH(geometry, {
|
|
26
|
+
strategy: options.fastBuild ? AVERAGE : SAH,
|
|
27
|
+
indirect: true,
|
|
28
|
+
verbose: false,
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
return createSurfaceQueryFromBvh(geometry, bvh);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Wraps a prebuilt BVH with the allocation-reusing query API used by the wrap skin preview and baker. The geometry and BVH must use indirect indexing so face IDs stay
|
|
36
|
+
* aligned with the source triangle arrays.
|
|
37
|
+
*
|
|
38
|
+
* @param {BufferGeometry} geometry
|
|
39
|
+
* @param {MeshBVH} bvh
|
|
40
|
+
*/
|
|
41
|
+
export function createSurfaceQueryFromBvh(geometry, bvh) {
|
|
42
|
+
|
|
43
|
+
const point = new Vector3();
|
|
44
|
+
const direction = new Vector3();
|
|
45
|
+
const ray = new Ray(point, direction);
|
|
46
|
+
const closestTarget = {
|
|
47
|
+
point: new Vector3(),
|
|
48
|
+
distance: Infinity,
|
|
49
|
+
faceIndex: -1,
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
return {
|
|
53
|
+
geometry,
|
|
54
|
+
bvh,
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* @param {ArrayLike<number>} value
|
|
58
|
+
* @param {number=} maxDistance
|
|
59
|
+
*/
|
|
60
|
+
closestPoint(value, maxDistance = Infinity) {
|
|
61
|
+
point.set(value[0], value[1], value[2]);
|
|
62
|
+
const hit = bvh.closestPointToPoint(point, closestTarget, 0, maxDistance);
|
|
63
|
+
if (!hit || hit.distance === undefined || hit.faceIndex === undefined || !hit.point) return null;
|
|
64
|
+
return {
|
|
65
|
+
point: [hit.point.x, hit.point.y, hit.point.z],
|
|
66
|
+
distance: hit.distance,
|
|
67
|
+
faceIndex: hit.faceIndex,
|
|
68
|
+
};
|
|
69
|
+
},
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* @param {ArrayLike<number>} origin
|
|
73
|
+
* @param {ArrayLike<number>} rayDirection
|
|
74
|
+
* @param {number} near
|
|
75
|
+
* @param {number} far
|
|
76
|
+
* @param {'front' | 'back'} side
|
|
77
|
+
*/
|
|
78
|
+
raycastFirst(origin, rayDirection, near, far, side = 'front') {
|
|
79
|
+
point.set(origin[0], origin[1], origin[2]);
|
|
80
|
+
direction.set(rayDirection[0], rayDirection[1], rayDirection[2]).normalize();
|
|
81
|
+
return bvh.raycastFirst(ray, side === 'front' ? FrontSide : BackSide, near, far);
|
|
82
|
+
},
|
|
83
|
+
|
|
84
|
+
dispose() {
|
|
85
|
+
geometry.dispose();
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
}
|
|
@@ -1,115 +1,115 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
import * as THREE from 'three';
|
|
3
|
-
import { MeshBasicNodeMaterial } from 'three/webgpu';
|
|
4
|
-
import { attribute, fwidth, min, vec3, uniform, float } from 'three/tsl';
|
|
5
|
-
/** @typedef {'black' | 'white' | 'invert'} WireframeBlendMode */
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Produces a triangle overlay with a screen-space barycentric edge mask. Unlike
|
|
9
|
-
* hardware line primitives this supports stable, adjustable pixel thickness.
|
|
10
|
-
* @param {THREE.Material} sourceMaterial
|
|
11
|
-
* @param {boolean} isImpostor
|
|
12
|
-
* @param {number} thickness
|
|
13
|
-
* @param {WireframeBlendMode} blendMode
|
|
14
|
-
*/
|
|
15
|
-
export function createPreviewWireframeMaterial(sourceMaterial, isImpostor, thickness, blendMode) {
|
|
16
|
-
const thicknessNode = uniform(thickness);
|
|
17
|
-
const barycentric = attribute('previewBarycentric', /** @type {'vec3'} */ ('vec3'));
|
|
18
|
-
const edgeMask = attribute('previewWireframeEdgeMask', /** @type {'vec3'} */ ('vec3'));
|
|
19
|
-
const derivative = fwidth(barycentric).max(vec3(1e-4));
|
|
20
|
-
const edgeDistanceVector = barycentric.div(derivative)
|
|
21
|
-
.add(vec3(1).sub(edgeMask).mul(1e4));
|
|
22
|
-
const edgeDistance = min(
|
|
23
|
-
edgeDistanceVector.x,
|
|
24
|
-
edgeDistanceVector.y,
|
|
25
|
-
edgeDistanceVector.z,
|
|
26
|
-
);
|
|
27
|
-
const halfWidth = thicknessNode.mul(0.5);
|
|
28
|
-
// Exact overlap of the requested line interval with a one-pixel box filter.
|
|
29
|
-
// The difference of the two ramps preserves integrated line energy for
|
|
30
|
-
// subpixel widths instead of quantizing or over-attenuating thin lines.
|
|
31
|
-
const coverage = halfWidth.add(0.5).sub(edgeDistance).clamp(0, 1).sub(
|
|
32
|
-
float(0.5).sub(halfWidth).sub(edgeDistance).clamp(0, 1),
|
|
33
|
-
);
|
|
34
|
-
const material = new MeshBasicNodeMaterial({
|
|
35
|
-
name: isImpostor ? 'Black impostor quad overlay' : 'Black mesh wireframe overlay',
|
|
36
|
-
color: 0x000000,
|
|
37
|
-
side: isImpostor ? THREE.DoubleSide : sourceMaterial.side,
|
|
38
|
-
depthTest: !isImpostor,
|
|
39
|
-
depthWrite: false,
|
|
40
|
-
polygonOffset: !isImpostor,
|
|
41
|
-
polygonOffsetFactor: -1,
|
|
42
|
-
polygonOffsetUnits: -1,
|
|
43
|
-
toneMapped: false,
|
|
44
|
-
});
|
|
45
|
-
material.transparent = true;
|
|
46
|
-
material.premultipliedAlpha = true;
|
|
47
|
-
material.opacityNode = coverage;
|
|
48
|
-
material.maskNode = coverage.greaterThan(1 / 1024);
|
|
49
|
-
if ('positionNode' in sourceMaterial) {
|
|
50
|
-
const sourceNodeMaterial = /** @type {import('three/webgpu').NodeMaterial} */ (sourceMaterial);
|
|
51
|
-
material.positionNode = sourceNodeMaterial.positionNode ?? null;
|
|
52
|
-
}
|
|
53
|
-
material.userData.previewWireframeThickness = thicknessNode;
|
|
54
|
-
applyPreviewWireframeBlendMode(material, blendMode);
|
|
55
|
-
return material;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/** @param {string} value @returns {WireframeBlendMode} */
|
|
59
|
-
export function parseWireframeBlendMode(value) {
|
|
60
|
-
return value === 'white' || value === 'invert' ? value : 'black';
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* @param {THREE.Material} material
|
|
65
|
-
* @param {WireframeBlendMode} mode
|
|
66
|
-
*/
|
|
67
|
-
export function applyPreviewWireframeBlendMode(material, mode) {
|
|
68
|
-
const basic = /** @type {import('three/webgpu').MeshBasicNodeMaterial} */ (material);
|
|
69
|
-
basic.color.set(mode === 'black' ? 0x000000 : 0xffffff);
|
|
70
|
-
if (mode === 'invert') {
|
|
71
|
-
basic.blending = THREE.CustomBlending;
|
|
72
|
-
basic.blendEquation = THREE.AddEquation;
|
|
73
|
-
basic.blendSrc = THREE.OneMinusDstColorFactor;
|
|
74
|
-
basic.blendDst = THREE.OneMinusSrcColorFactor;
|
|
75
|
-
basic.blendEquationAlpha = THREE.AddEquation;
|
|
76
|
-
basic.blendSrcAlpha = THREE.OneFactor;
|
|
77
|
-
basic.blendDstAlpha = THREE.OneMinusSrcAlphaFactor;
|
|
78
|
-
} else {
|
|
79
|
-
basic.blending = THREE.NormalBlending;
|
|
80
|
-
}
|
|
81
|
-
basic.userData.previewWireframeBlendMode = mode;
|
|
82
|
-
basic.needsUpdate = true;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* @param {THREE.BufferGeometry} source
|
|
87
|
-
* @returns {THREE.BufferGeometry}
|
|
88
|
-
*/
|
|
89
|
-
export function createBarycentricWireframeGeometry(source) {
|
|
90
|
-
const geometry = source.index ? source.toNonIndexed() : source.clone();
|
|
91
|
-
const vertexCount = geometry.getAttribute('position')?.count ?? 0;
|
|
92
|
-
const barycentric = new Float32Array(vertexCount * 3);
|
|
93
|
-
const edgeMask = new Float32Array(vertexCount * 3);
|
|
94
|
-
const triangleMasks = source.userData.previewWireframeEdgeMasks;
|
|
95
|
-
for (let vertex = 0; vertex + 2 < vertexCount; vertex += 3) {
|
|
96
|
-
barycentric[(vertex + 0) * 3 + 0] = 1;
|
|
97
|
-
barycentric[(vertex + 1) * 3 + 1] = 1;
|
|
98
|
-
barycentric[(vertex + 2) * 3 + 2] = 1;
|
|
99
|
-
const triangle = vertex / 3;
|
|
100
|
-
const x = triangleMasks?.[triangle * 3] ?? 1;
|
|
101
|
-
const y = triangleMasks?.[triangle * 3 + 1] ?? 1;
|
|
102
|
-
const z = triangleMasks?.[triangle * 3 + 2] ?? 1;
|
|
103
|
-
for (let corner = 0; corner < 3; corner++) {
|
|
104
|
-
edgeMask[(vertex + corner) * 3] = x;
|
|
105
|
-
edgeMask[(vertex + corner) * 3 + 1] = y;
|
|
106
|
-
edgeMask[(vertex + corner) * 3 + 2] = z;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
geometry.setAttribute('previewBarycentric', new THREE.BufferAttribute(barycentric, 3));
|
|
110
|
-
geometry.setAttribute(
|
|
111
|
-
'previewWireframeEdgeMask',
|
|
112
|
-
new THREE.BufferAttribute(edgeMask, 3),
|
|
113
|
-
);
|
|
114
|
-
return geometry;
|
|
115
|
-
}
|
|
1
|
+
// @ts-check
|
|
2
|
+
import * as THREE from 'three';
|
|
3
|
+
import { MeshBasicNodeMaterial } from 'three/webgpu';
|
|
4
|
+
import { attribute, fwidth, min, vec3, uniform, float } from 'three/tsl';
|
|
5
|
+
/** @typedef {'black' | 'white' | 'invert'} WireframeBlendMode */
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Produces a triangle overlay with a screen-space barycentric edge mask. Unlike
|
|
9
|
+
* hardware line primitives this supports stable, adjustable pixel thickness.
|
|
10
|
+
* @param {THREE.Material} sourceMaterial
|
|
11
|
+
* @param {boolean} isImpostor
|
|
12
|
+
* @param {number} thickness
|
|
13
|
+
* @param {WireframeBlendMode} blendMode
|
|
14
|
+
*/
|
|
15
|
+
export function createPreviewWireframeMaterial(sourceMaterial, isImpostor, thickness, blendMode) {
|
|
16
|
+
const thicknessNode = uniform(thickness);
|
|
17
|
+
const barycentric = attribute('previewBarycentric', /** @type {'vec3'} */ ('vec3'));
|
|
18
|
+
const edgeMask = attribute('previewWireframeEdgeMask', /** @type {'vec3'} */ ('vec3'));
|
|
19
|
+
const derivative = fwidth(barycentric).max(vec3(1e-4));
|
|
20
|
+
const edgeDistanceVector = barycentric.div(derivative)
|
|
21
|
+
.add(vec3(1).sub(edgeMask).mul(1e4));
|
|
22
|
+
const edgeDistance = min(
|
|
23
|
+
edgeDistanceVector.x,
|
|
24
|
+
edgeDistanceVector.y,
|
|
25
|
+
edgeDistanceVector.z,
|
|
26
|
+
);
|
|
27
|
+
const halfWidth = thicknessNode.mul(0.5);
|
|
28
|
+
// Exact overlap of the requested line interval with a one-pixel box filter.
|
|
29
|
+
// The difference of the two ramps preserves integrated line energy for
|
|
30
|
+
// subpixel widths instead of quantizing or over-attenuating thin lines.
|
|
31
|
+
const coverage = halfWidth.add(0.5).sub(edgeDistance).clamp(0, 1).sub(
|
|
32
|
+
float(0.5).sub(halfWidth).sub(edgeDistance).clamp(0, 1),
|
|
33
|
+
);
|
|
34
|
+
const material = new MeshBasicNodeMaterial({
|
|
35
|
+
name: isImpostor ? 'Black impostor quad overlay' : 'Black mesh wireframe overlay',
|
|
36
|
+
color: 0x000000,
|
|
37
|
+
side: isImpostor ? THREE.DoubleSide : sourceMaterial.side,
|
|
38
|
+
depthTest: !isImpostor,
|
|
39
|
+
depthWrite: false,
|
|
40
|
+
polygonOffset: !isImpostor,
|
|
41
|
+
polygonOffsetFactor: -1,
|
|
42
|
+
polygonOffsetUnits: -1,
|
|
43
|
+
toneMapped: false,
|
|
44
|
+
});
|
|
45
|
+
material.transparent = true;
|
|
46
|
+
material.premultipliedAlpha = true;
|
|
47
|
+
material.opacityNode = coverage;
|
|
48
|
+
material.maskNode = coverage.greaterThan(1 / 1024);
|
|
49
|
+
if ('positionNode' in sourceMaterial) {
|
|
50
|
+
const sourceNodeMaterial = /** @type {import('three/webgpu').NodeMaterial} */ (sourceMaterial);
|
|
51
|
+
material.positionNode = sourceNodeMaterial.positionNode ?? null;
|
|
52
|
+
}
|
|
53
|
+
material.userData.previewWireframeThickness = thicknessNode;
|
|
54
|
+
applyPreviewWireframeBlendMode(material, blendMode);
|
|
55
|
+
return material;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** @param {string} value @returns {WireframeBlendMode} */
|
|
59
|
+
export function parseWireframeBlendMode(value) {
|
|
60
|
+
return value === 'white' || value === 'invert' ? value : 'black';
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* @param {THREE.Material} material
|
|
65
|
+
* @param {WireframeBlendMode} mode
|
|
66
|
+
*/
|
|
67
|
+
export function applyPreviewWireframeBlendMode(material, mode) {
|
|
68
|
+
const basic = /** @type {import('three/webgpu').MeshBasicNodeMaterial} */ (material);
|
|
69
|
+
basic.color.set(mode === 'black' ? 0x000000 : 0xffffff);
|
|
70
|
+
if (mode === 'invert') {
|
|
71
|
+
basic.blending = THREE.CustomBlending;
|
|
72
|
+
basic.blendEquation = THREE.AddEquation;
|
|
73
|
+
basic.blendSrc = THREE.OneMinusDstColorFactor;
|
|
74
|
+
basic.blendDst = THREE.OneMinusSrcColorFactor;
|
|
75
|
+
basic.blendEquationAlpha = THREE.AddEquation;
|
|
76
|
+
basic.blendSrcAlpha = THREE.OneFactor;
|
|
77
|
+
basic.blendDstAlpha = THREE.OneMinusSrcAlphaFactor;
|
|
78
|
+
} else {
|
|
79
|
+
basic.blending = THREE.NormalBlending;
|
|
80
|
+
}
|
|
81
|
+
basic.userData.previewWireframeBlendMode = mode;
|
|
82
|
+
basic.needsUpdate = true;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* @param {THREE.BufferGeometry} source
|
|
87
|
+
* @returns {THREE.BufferGeometry}
|
|
88
|
+
*/
|
|
89
|
+
export function createBarycentricWireframeGeometry(source) {
|
|
90
|
+
const geometry = source.index ? source.toNonIndexed() : source.clone();
|
|
91
|
+
const vertexCount = geometry.getAttribute('position')?.count ?? 0;
|
|
92
|
+
const barycentric = new Float32Array(vertexCount * 3);
|
|
93
|
+
const edgeMask = new Float32Array(vertexCount * 3);
|
|
94
|
+
const triangleMasks = source.userData.previewWireframeEdgeMasks;
|
|
95
|
+
for (let vertex = 0; vertex + 2 < vertexCount; vertex += 3) {
|
|
96
|
+
barycentric[(vertex + 0) * 3 + 0] = 1;
|
|
97
|
+
barycentric[(vertex + 1) * 3 + 1] = 1;
|
|
98
|
+
barycentric[(vertex + 2) * 3 + 2] = 1;
|
|
99
|
+
const triangle = vertex / 3;
|
|
100
|
+
const x = triangleMasks?.[triangle * 3] ?? 1;
|
|
101
|
+
const y = triangleMasks?.[triangle * 3 + 1] ?? 1;
|
|
102
|
+
const z = triangleMasks?.[triangle * 3 + 2] ?? 1;
|
|
103
|
+
for (let corner = 0; corner < 3; corner++) {
|
|
104
|
+
edgeMask[(vertex + corner) * 3] = x;
|
|
105
|
+
edgeMask[(vertex + corner) * 3 + 1] = y;
|
|
106
|
+
edgeMask[(vertex + corner) * 3 + 2] = z;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
geometry.setAttribute('previewBarycentric', new THREE.BufferAttribute(barycentric, 3));
|
|
110
|
+
geometry.setAttribute(
|
|
111
|
+
'previewWireframeEdgeMask',
|
|
112
|
+
new THREE.BufferAttribute(edgeMask, 3),
|
|
113
|
+
);
|
|
114
|
+
return geometry;
|
|
115
|
+
}
|