@fusion.dev/helix-graph 0.124.0 → 0.125.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.
@@ -255,6 +255,42 @@ const framed = (geometry) => {
255
255
  geometry.setAttribute('frame', new BufferAttribute(frame, 4));
256
256
  return geometry;
257
257
  };
258
+ const SMOOTH = { surface: 3, ways: 6 };
259
+ const neighborsOf = (index, count) => {
260
+ const sets = Array.from({ length: count }, () => new Set());
261
+ for (let at = 0; at < index.count; at += 3) {
262
+ const a = index.getX(at);
263
+ const b = index.getX(at + 1);
264
+ const c = index.getX(at + 2);
265
+ sets[a]?.add(b).add(c);
266
+ sets[b]?.add(a).add(c);
267
+ sets[c]?.add(a).add(b);
268
+ }
269
+ return sets.map((set) => Int32Array.from(set));
270
+ };
271
+ const averaged = (values, neighbors, share) => {
272
+ const out = new Float32Array(values.length);
273
+ neighbors.forEach((around, at) => {
274
+ let x = 0;
275
+ let y = 0;
276
+ let z = 0;
277
+ for (const other of around) {
278
+ x += values[other * 3];
279
+ y += values[other * 3 + 1];
280
+ z += values[other * 3 + 2];
281
+ }
282
+ const many = around.length || 1;
283
+ for (const [axis, sum] of [
284
+ [0, x],
285
+ [1, y],
286
+ [2, z],
287
+ ]) {
288
+ const value = values[at * 3 + axis];
289
+ out[at * 3 + axis] = around.length ? value + share * (sum / many - value) : value;
290
+ }
291
+ });
292
+ return out;
293
+ };
258
294
  const channels = (color) => {
259
295
  const [red = 128, green = 128, blue = 128] = color.match(/[\d.]+/g)?.map(Number) ?? [];
260
296
  return [red / 255, green / 255, blue / 255];
@@ -403,17 +439,31 @@ export const threeDriver = (container, options = {}) => {
403
439
  geometry.setIndex(new BufferAttribute(field.mesh.triangles, 1));
404
440
  geometry = mergeVertices(geometry);
405
441
  const place = geometry.getAttribute('position');
442
+ const count = place.count;
443
+ const neighbors = neighborsOf(geometry.getIndex(), count);
406
444
  const step = Math.max(field.width, field.height, field.depth) / 64;
407
- for (let at = 0; at < place.count; at++) {
445
+ let way = new Float32Array(count * 3);
446
+ for (let at = 0; at < count; at++) {
408
447
  const x = place.getX(at);
409
448
  const y = place.getY(at);
410
449
  const z = place.getZ(at);
411
- const gx = field.distance(x + step, y, z) - field.distance(x - step, y, z);
412
- const gy = field.distance(x, y + step, z) - field.distance(x, y - step, z);
413
- const gz = field.distance(x, y, z + step) - field.distance(x, y, z - step);
414
- const length = Math.hypot(gx, gy, gz) || 1;
415
- place.setXYZ(at, x - (gx / length) * inset, y - (gy / length) * inset, z - (gz / length) * inset);
450
+ way[at * 3] = field.distance(x + step, y, z) - field.distance(x - step, y, z);
451
+ way[at * 3 + 1] = field.distance(x, y + step, z) - field.distance(x, y - step, z);
452
+ way[at * 3 + 2] = field.distance(x, y, z + step) - field.distance(x, y, z - step);
453
+ }
454
+ for (let pass = 0; pass < SMOOTH.ways; pass++) {
455
+ way = averaged(way, neighbors, 0.5);
456
+ }
457
+ for (let at = 0; at < count; at++) {
458
+ const length = Math.hypot(way[at * 3], way[at * 3 + 1], way[at * 3 + 2]) ||
459
+ 1;
460
+ place.setXYZ(at, place.getX(at) - (way[at * 3] / length) * inset, place.getY(at) - (way[at * 3 + 1] / length) * inset, place.getZ(at) - (way[at * 3 + 2] / length) * inset);
461
+ }
462
+ let corners = place.array;
463
+ for (let pass = 0; pass < SMOOTH.surface; pass++) {
464
+ corners = averaged(averaged(corners, neighbors, 0.5), neighbors, -0.53);
416
465
  }
466
+ place.array.set(corners);
417
467
  }
418
468
  else {
419
469
  const { corners, triangles } = surfaceOf(field, { at: -inset });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@fusion.dev/helix-graph",
3
3
  "description": "Connects the Helix Graph frame to a graph renderer: Sigma.js, cosmos.gl, three.js, or a driver of your own.",
4
- "version": "0.124.0",
4
+ "version": "0.125.0",
5
5
  "license": "MIT",
6
6
  "author": "Ross Sheppard <ross.sheppard@fusion.dev>",
7
7
  "repository": {
@@ -47,12 +47,12 @@
47
47
  },
48
48
  "bugs": "https://github.com/project-fusion/fusion/issues",
49
49
  "dependencies": {
50
- "@fusion.dev/helix-core": "0.124.0"
50
+ "@fusion.dev/helix-core": "0.125.0"
51
51
  },
52
52
  "devDependencies": {
53
53
  "@cosmos.gl/graph": "^3.4.2",
54
- "@fusion.dev/helix-headless": "0.124.0",
55
- "@fusion.dev/helix-testing": "0.124.0",
54
+ "@fusion.dev/helix-headless": "0.125.0",
55
+ "@fusion.dev/helix-testing": "0.125.0",
56
56
  "@types/bun": "^1.3.0",
57
57
  "@types/three": "^0.186.0",
58
58
  "d3-force-3d": "^3.0.6",