@aethervtt/shard-mesh 0.0.1 → 0.1.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/dist/index.d.ts +1 -1
- package/dist/index.js +12 -1
- package/dist/mesh.d.ts +2 -0
- package/dist/mesh.js +2 -0
- package/dist/primitives.d.ts +10 -0
- package/dist/primitives.js +89 -0
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { decodeMesh, encodeMesh } from './codec.js';
|
|
2
2
|
export { type GpuMeshDescriptor, MAX_MORPH_TARGETS, MESH_ATTRIBUTE_WIDTH, MESH_ATTRIBUTES, Mesh, type MeshAttribute, type MeshData, type MorphTarget, } from './mesh.js';
|
|
3
|
-
export { box, capsule, cone, cube, cylinder, plane, sphere, torus } from './primitives.js';
|
|
3
|
+
export { bevelBox, box, capsule, cone, cube, cylinder, plane, sphere, torus, } from './primitives.js';
|
package/dist/index.js
CHANGED
|
@@ -5,12 +5,23 @@ import {
|
|
|
5
5
|
MESH_ATTRIBUTES,
|
|
6
6
|
Mesh
|
|
7
7
|
} from "./mesh.js";
|
|
8
|
-
import {
|
|
8
|
+
import {
|
|
9
|
+
bevelBox,
|
|
10
|
+
box,
|
|
11
|
+
capsule,
|
|
12
|
+
cone,
|
|
13
|
+
cube,
|
|
14
|
+
cylinder,
|
|
15
|
+
plane,
|
|
16
|
+
sphere,
|
|
17
|
+
torus
|
|
18
|
+
} from "./primitives.js";
|
|
9
19
|
export {
|
|
10
20
|
MAX_MORPH_TARGETS,
|
|
11
21
|
MESH_ATTRIBUTES,
|
|
12
22
|
MESH_ATTRIBUTE_WIDTH,
|
|
13
23
|
Mesh,
|
|
24
|
+
bevelBox,
|
|
14
25
|
box,
|
|
15
26
|
capsule,
|
|
16
27
|
cone,
|
package/dist/mesh.d.ts
CHANGED
|
@@ -75,6 +75,8 @@ export declare class Mesh {
|
|
|
75
75
|
readonly bounds: Float32Array<ArrayBufferLike>;
|
|
76
76
|
/** Increments on `update`, so GPU copies know to re-upload. */
|
|
77
77
|
version: number;
|
|
78
|
+
/** The stand-in for a mesh that failed to load (0061): drawn with the missing material. */
|
|
79
|
+
missing: boolean;
|
|
78
80
|
/**
|
|
79
81
|
* Set for meshes the GPU writes (`Mesh.gpu`): their vertex buffers are storage buffers with no
|
|
80
82
|
* CPU copy; `positions` is empty.
|
package/dist/mesh.js
CHANGED
|
@@ -36,6 +36,8 @@ class Mesh {
|
|
|
36
36
|
bounds = aabb.create();
|
|
37
37
|
/** Increments on `update`, so GPU copies know to re-upload. */
|
|
38
38
|
version = 0;
|
|
39
|
+
/** The stand-in for a mesh that failed to load (0061): drawn with the missing material. */
|
|
40
|
+
missing = false;
|
|
39
41
|
/**
|
|
40
42
|
* Set for meshes the GPU writes (`Mesh.gpu`): their vertex buffers are storage buffers with no
|
|
41
43
|
* CPU copy; `positions` is empty.
|
package/dist/primitives.d.ts
CHANGED
|
@@ -46,3 +46,13 @@ export declare function torus(options?: {
|
|
|
46
46
|
radialSegments?: number;
|
|
47
47
|
tubularSegments?: number;
|
|
48
48
|
}): Mesh;
|
|
49
|
+
/**
|
|
50
|
+
* A box with chamfered edges and corners: the stand-in for a mesh that failed to load (0061).
|
|
51
|
+
* `bevel` is the chamfer width, clamped below half the smallest side.
|
|
52
|
+
*/
|
|
53
|
+
export declare function bevelBox(options?: {
|
|
54
|
+
x?: number;
|
|
55
|
+
y?: number;
|
|
56
|
+
z?: number;
|
|
57
|
+
bevel?: number;
|
|
58
|
+
}): Mesh;
|
package/dist/primitives.js
CHANGED
|
@@ -229,7 +229,96 @@ function torus(options = {}) {
|
|
|
229
229
|
}
|
|
230
230
|
return b.build();
|
|
231
231
|
}
|
|
232
|
+
function bevelBox(options = {}) {
|
|
233
|
+
const h = [(options.x ?? 1) / 2, (options.y ?? 1) / 2, (options.z ?? 1) / 2];
|
|
234
|
+
const bevel = Math.min(options.bevel ?? 0.08, Math.min(h[0], h[1], h[2]) * 0.9);
|
|
235
|
+
const inner = h.map((v) => v - bevel);
|
|
236
|
+
const b = new Builder();
|
|
237
|
+
const unit = (v) => {
|
|
238
|
+
const l = Math.hypot(v[0], v[1], v[2]);
|
|
239
|
+
return v.map((c) => c / l);
|
|
240
|
+
};
|
|
241
|
+
const polygon = (points, n) => {
|
|
242
|
+
const [a, c, d] = [points[0], points[1], points[2]];
|
|
243
|
+
const e1 = [c[0] - a[0], c[1] - a[1], c[2] - a[2]];
|
|
244
|
+
const e2 = [d[0] - a[0], d[1] - a[1], d[2] - a[2]];
|
|
245
|
+
const cross = [
|
|
246
|
+
e1[1] * e2[2] - e1[2] * e2[1],
|
|
247
|
+
e1[2] * e2[0] - e1[0] * e2[2],
|
|
248
|
+
e1[0] * e2[1] - e1[1] * e2[0]
|
|
249
|
+
];
|
|
250
|
+
const ordered = cross[0] * n[0] + cross[1] * n[1] + cross[2] * n[2] < 0 ? [...points].reverse() : points;
|
|
251
|
+
const axis = n.map((c2) => Math.abs(c2)).indexOf(Math.max(...n.map((c2) => Math.abs(c2))));
|
|
252
|
+
const [ua, va] = axis === 0 ? [2, 1] : axis === 1 ? [0, 2] : [0, 1];
|
|
253
|
+
const ids = ordered.map(
|
|
254
|
+
(p) => b.vertex(p, n, [0.5 + p[ua] / (2 * h[ua]), 0.5 - p[va] / (2 * h[va])])
|
|
255
|
+
);
|
|
256
|
+
for (let i = 1; i + 1 < ids.length; i++) b.triangle(ids[0], ids[i], ids[i + 1]);
|
|
257
|
+
};
|
|
258
|
+
const point = (axis, value) => [0, 1, 2].map((k) => axis[k] * value[k]);
|
|
259
|
+
const signs = [-1, 1];
|
|
260
|
+
for (let a = 0; a < 3; a++) {
|
|
261
|
+
for (const s of signs) {
|
|
262
|
+
const u = (a + 1) % 3;
|
|
263
|
+
const v = (a + 2) % 3;
|
|
264
|
+
const n = [0, 0, 0];
|
|
265
|
+
n[a] = s;
|
|
266
|
+
const corners = [
|
|
267
|
+
[-1, -1],
|
|
268
|
+
[1, -1],
|
|
269
|
+
[1, 1],
|
|
270
|
+
[-1, 1]
|
|
271
|
+
].map(([su, sv]) => {
|
|
272
|
+
const p = [0, 0, 0];
|
|
273
|
+
p[a] = s * h[a];
|
|
274
|
+
p[u] = su * inner[u];
|
|
275
|
+
p[v] = sv * inner[v];
|
|
276
|
+
return p;
|
|
277
|
+
});
|
|
278
|
+
polygon(corners, n);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
for (let a = 0; a < 3; a++) {
|
|
282
|
+
const u = (a + 1) % 3;
|
|
283
|
+
const v = (a + 2) % 3;
|
|
284
|
+
for (const sa of signs) {
|
|
285
|
+
for (const su of signs) {
|
|
286
|
+
const n = [0, 0, 0];
|
|
287
|
+
n[a] = sa;
|
|
288
|
+
n[u] = su;
|
|
289
|
+
const quad = [-1, 1].flatMap((sv) => {
|
|
290
|
+
const p1 = [0, 0, 0];
|
|
291
|
+
p1[a] = sa * h[a];
|
|
292
|
+
p1[u] = su * inner[u];
|
|
293
|
+
p1[v] = sv * inner[v];
|
|
294
|
+
const p2 = [0, 0, 0];
|
|
295
|
+
p2[a] = sa * inner[a];
|
|
296
|
+
p2[u] = su * h[u];
|
|
297
|
+
p2[v] = sv * inner[v];
|
|
298
|
+
return [p1, p2];
|
|
299
|
+
});
|
|
300
|
+
polygon([quad[0], quad[1], quad[3], quad[2]], unit(n));
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
for (const sx of signs) {
|
|
305
|
+
for (const sy of signs) {
|
|
306
|
+
for (const sz of signs) {
|
|
307
|
+
const s = [sx, sy, sz];
|
|
308
|
+
const tri = [0, 1, 2].map(
|
|
309
|
+
(k) => point(
|
|
310
|
+
s,
|
|
311
|
+
k === 0 ? [h[0], inner[1], inner[2]] : k === 1 ? [inner[0], h[1], inner[2]] : [inner[0], inner[1], h[2]]
|
|
312
|
+
)
|
|
313
|
+
);
|
|
314
|
+
polygon(tri, unit(s));
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
return b.build();
|
|
319
|
+
}
|
|
232
320
|
export {
|
|
321
|
+
bevelBox,
|
|
233
322
|
box,
|
|
234
323
|
capsule,
|
|
235
324
|
cone,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aethervtt/shard-mesh",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"README.md"
|
|
17
17
|
],
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@aethervtt/shard-core": "0.0
|
|
19
|
+
"@aethervtt/shard-core": "0.1.0"
|
|
20
20
|
},
|
|
21
21
|
"repository": {
|
|
22
22
|
"type": "git",
|
|
@@ -28,6 +28,6 @@
|
|
|
28
28
|
"provenance": true
|
|
29
29
|
},
|
|
30
30
|
"shard": {
|
|
31
|
-
"buildSha": "
|
|
31
|
+
"buildSha": "8e14c9896f82a3554b156f1ffdd68f2cc3e7d78a"
|
|
32
32
|
}
|
|
33
33
|
}
|