@neo4j-nvl/base 1.2.0-d671dd1f → 1.2.0-dbc13ec2

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.
Files changed (35) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/base.mjs +1 -1
  3. package/dist/types/index.d.ts +2 -2
  4. package/dist/types/layouts/forcedirectedlayout/{physlayout/PhysLayout.d.ts → PhysLayout.d.ts} +48 -19
  5. package/dist/types/layouts/forcedirectedlayout/{physlayout/clustering → clustering}/ClusterByMerger.d.ts +15 -14
  6. package/dist/types/layouts/forcedirectedlayout/{physlayout/clustering → clustering}/SolarMerger.d.ts +2 -1
  7. package/dist/types/layouts/forcedirectedlayout/{physlayout/clustering → clustering}/clustering-utils.d.ts +40 -9
  8. package/dist/types/layouts/forcedirectedlayout/{physlayout/clustering → clustering}/types.d.ts +6 -1
  9. package/dist/types/layouts/forcedirectedlayout/shaders/multilevel-fragment.d.ts +2 -0
  10. package/dist/types/layouts/forcedirectedlayout/shaders/multilevel-repulsive-fragment.d.ts +2 -0
  11. package/dist/types/layouts/hierarchicallayout/HierarchicalLayout.d.ts +5 -0
  12. package/dist/types/modules/NvlController.d.ts +49 -5
  13. package/dist/types/modules/state/types.d.ts +92 -21
  14. package/dist/types/modules/state/utils.d.ts +2 -2
  15. package/dist/types/renderers/ClusterOverlay.d.ts +80 -0
  16. package/dist/types/renderers/ClusterOverlay.test.d.ts +1 -0
  17. package/dist/types/renderers/webglrenderer/Controller.d.ts +3 -2
  18. package/dist/types/renderers/webglrenderer/Renderer.d.ts +10 -0
  19. package/dist/types/renderers/webglrenderer/rel-glsl-utils.d.ts +1 -0
  20. package/dist/types/renderers/webglrenderer/rel-vertex-arrow.d.ts +2 -0
  21. package/dist/types/renderers/webglrenderer/rel-vertex-line.d.ts +1 -1
  22. package/dist/types/utils/clusterGeometry.d.ts +14 -0
  23. package/dist/types/utils/clusterGeometry.test.d.ts +1 -0
  24. package/dist/types/utils/geometry.d.ts +13 -0
  25. package/package.json +2 -2
  26. package/dist/types/layouts/forcedirectedlayout/physlayout/shaders/multilevel-fragment.d.ts +0 -2
  27. package/dist/types/layouts/forcedirectedlayout/physlayout/shaders/multilevel-repulsive-fragment.d.ts +0 -2
  28. /package/dist/types/layouts/forcedirectedlayout/{physlayout/PhysLayout.test.d.ts → PhysLayout.test.d.ts} +0 -0
  29. /package/dist/types/layouts/forcedirectedlayout/{physlayout/clustering → clustering}/ClusterByMerger.test.d.ts +0 -0
  30. /package/dist/types/layouts/forcedirectedlayout/{physlayout/clustering → clustering}/SolarMerger.bench.d.ts +0 -0
  31. /package/dist/types/layouts/forcedirectedlayout/{physlayout/clustering → clustering}/SolarMerger.test.d.ts +0 -0
  32. /package/dist/types/layouts/forcedirectedlayout/{physlayout/clustering → clustering}/clustering-utils.test.d.ts +0 -0
  33. /package/dist/types/layouts/forcedirectedlayout/{physlayout/glwrapper.d.ts → glwrapper.d.ts} +0 -0
  34. /package/dist/types/layouts/forcedirectedlayout/{physlayout/shaders → shaders}/multilevel-update-fragment.d.ts +0 -0
  35. /package/dist/types/layouts/forcedirectedlayout/{physlayout/shaders → shaders}/sim-vertex.d.ts +0 -0
@@ -6,7 +6,7 @@ import type { NvlOptions } from './types';
6
6
  * If both caption and captions are provided, captions takes precedence.
7
7
  */
8
8
  export declare const processCaptions: (item: Partial<Node | Relationship>) => StyledCaption[];
9
- export declare const processColorStyles: (styling: NvlOptions["styling"]) => {
9
+ export declare const processColorStyles: (styling?: NvlOptions["styling"]) => {
10
10
  nodeBorderStyles: {
11
11
  default: {
12
12
  rings?: {
@@ -42,5 +42,5 @@ export declare const processColorStyles: (styling: NvlOptions["styling"]) => {
42
42
  };
43
43
  defaultNodeColor: string;
44
44
  defaultRelationshipColor: string;
45
- minimapViewportBoxColor: string;
45
+ overlayLineColor: string;
46
46
  };
@@ -0,0 +1,80 @@
1
+ import { type CoarsenedGraph } from '../layouts/forcedirectedlayout/clustering/types';
2
+ import { type NvlState } from '../modules/state/types';
3
+ import type { Node } from '../types/graph-element';
4
+ import { type Point } from '../utils/geometry';
5
+ type ClusterPositions = Readonly<Record<string, Point>> | (() => (Node & Point)[]);
6
+ /**
7
+ * Canvas2D overlay for cluster decorations.
8
+ */
9
+ export default class ClusterOverlay {
10
+ private readonly canvas;
11
+ private readonly context;
12
+ private readonly state;
13
+ private readonly stateDisposers;
14
+ private readonly clusterColors;
15
+ private clusterColorsDirty;
16
+ private cachedFirstSubGraphLevel;
17
+ private cachedIdToPosition;
18
+ private cachedPositionListVersion;
19
+ private readonly clusterGeometry;
20
+ private geometryPositionsVersion;
21
+ constructor(canvas: HTMLCanvasElement, context: CanvasRenderingContext2D, state: NvlState);
22
+ /** Clears the overlay. */
23
+ clear(): void;
24
+ /**
25
+ * Draws cluster decorations for a given multi-member first-level sun system and positions.
26
+ * @param subGraphs - Layout coarsening hierarchy (`subGraphs[1]` = first-level suns).
27
+ * @param positions - Node id to position map, or a getter for a lagged position list.
28
+ * @param cacheVersion - PhysLayout positions-cache version.
29
+ */
30
+ render(subGraphs: CoarsenedGraph[], positions: ClusterPositions, cacheVersion: number): void;
31
+ destroy(): void;
32
+ private resetClusterColorCache;
33
+ private resetGeometryCache;
34
+ private syncGeometryCacheVersion;
35
+ private resetPositionCache;
36
+ /**
37
+ * Returns an id to position map. Records are used as-is. Getters are converted once per `cacheVersion`.
38
+ * @param positions - Node id to position map, or a getter for a lagged position list.
39
+ * @param cacheVersion - PhysLayout positions-cache version; ignored for maps.
40
+ * @returns An id to position map.
41
+ */
42
+ private resolveIdToPosition;
43
+ /**
44
+ * Rebuilds {@link clusterColors} for every multi-member first-level sun.
45
+ * @param firstSubGraphLevel - `subGraphs[1]` from the current layout coarsening hierarchy.
46
+ */
47
+ private rebuildClusterColors;
48
+ /**
49
+ * Visits each multi-member first-level sun system.
50
+ * @param firstSubGraphLevel - `subGraphs[1]` from the current layout coarsening hierarchy.
51
+ * @param onCluster - Called with the sun and its original member node ids.
52
+ */
53
+ private forEachDecoratableCluster;
54
+ private collectMemberDisks;
55
+ /**
56
+ * Returns fitted world-space hull for a cluster, reusing the last fit while the
57
+ * positions cache version is unchanged (e.g. pan/zoom-only frames while layout is stable).
58
+ * @param sunId - Original id of the sun the hull belongs to.
59
+ * @param collectMembers - Builds the member disks to fit; only called on a cache miss.
60
+ * @returns The fitted hull, or null when the cluster cannot be fitted.
61
+ */
62
+ private getCachedHull;
63
+ private fillHalo;
64
+ private strokeOutline;
65
+ /**
66
+ * Traces a closed rounded path along the given points.
67
+ * @param points - The points to trace the path along.
68
+ */
69
+ private traceSmoothClosedPath;
70
+ private applyZoomAndPan;
71
+ /**
72
+ * Returns the shared member color when color is consistent; otherwise null.
73
+ * @param nodeIds - The IDs of the nodes in the cluster.
74
+ * @param idToItem - The map of node IDs to items.
75
+ * @param defaultNodeColor - The default node color.
76
+ * @returns The shared member color when color is consistent; otherwise null.
77
+ */
78
+ private resolveUnanimousClusterColor;
79
+ }
80
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -49,8 +49,9 @@ export default class Controller implements ControllerInterface {
49
49
  * insertion order.
50
50
  * @param map - The node-id-to-texel-index map, or null.
51
51
  *
52
- * @note The minimap renders from its own CPU-uploaded texture and
53
- * is left in insertion order.
52
+ * @note The minimap keeps insertion-order sampling and uploads lagged CPU
53
+ * positions (async PhysLayout cache) while the main scene may sample the
54
+ * shared GPU texture.
54
55
  */
55
56
  setPositionTexelIndices(map: Readonly<Record<string, number>> | null): void;
56
57
  renderMinimap(positionArray: Node[], positionsChanged?: boolean): void;
@@ -9,7 +9,10 @@ export default class Renderer {
9
9
  private readonly nodeShader;
10
10
  private readonly nodeAnimShader;
11
11
  private readonly relShader;
12
+ private readonly arrowShader;
12
13
  private relDataBuffer;
14
+ private arrowDataBuffer;
15
+ private arrowData;
13
16
  private readonly viewportBoxShader;
14
17
  private readonly defaultRelColor;
15
18
  private readonly defaultNodeColor;
@@ -27,6 +30,7 @@ export default class Renderer {
27
30
  private texelMapAtBuild;
28
31
  private lastNodes;
29
32
  private lastBundledRels;
33
+ private idToSize;
30
34
  private posBuffer;
31
35
  private positionsDirty;
32
36
  private numRels;
@@ -37,11 +41,13 @@ export default class Renderer {
37
41
  private viewportBoxBuffer;
38
42
  private readonly viewportBoxVertices;
39
43
  private relBuffer;
44
+ private arrowBuffer;
40
45
  private nodeBuffer;
41
46
  private posTexture;
42
47
  private iconTexture;
43
48
  private nodeVao;
44
49
  private relVao;
50
+ private arrowVao;
45
51
  private nodeAnimVao;
46
52
  private readonly iconLayers;
47
53
  private uploadedIconLayers;
@@ -64,6 +70,7 @@ export default class Renderer {
64
70
  render(positionArray: Node[], positionsChanged?: boolean): void;
65
71
  /** Renders using a GPU position texture directly as `u_positions` */
66
72
  renderFromGpuTexture(positionTexture: WebGLTexture): void;
73
+ private renderRelationships;
67
74
  renderViewbox(): void;
68
75
  updateNodes(updates: Node[]): void;
69
76
  updateRelationships(relItems: Relationship[]): void;
@@ -77,6 +84,9 @@ export default class Renderer {
77
84
  private resolveNodeColor;
78
85
  private setupNodeRendering;
79
86
  private setupRelationshipRendering;
87
+ private setupArrowRendering;
88
+ private getRelBufferAttributes;
89
+ private updateEndpointSizesForNode;
80
90
  private renderAnimations;
81
91
  destroy(): void;
82
92
  }
@@ -0,0 +1 @@
1
+ export declare const arrowShaderUtilsGLSL = "\nconst float CircleSize = 0.40;\nconst float HeadHalfWidthScale = 4.0;\nconst float HeadLengthScale = 2.5;\nconst float MaxHeadHalfWidthRatio = 0.6;\nconst float MaxHeadLengthRatio = 1.0;\n\n// Self-referencing relationships aren't supported in WebGL yet.\nbool relationshipIsSelfLoop(vec2 fromTexel, vec2 toTexel) {\n return all(equal(fromTexel, toTexel));\n}\n\nvec2 perpendicular(vec2 dir) {\n return vec2(-dir.y, dir.x);\n}\n\nfloat nodeRadiusFromSize(float size) {\n return size * u_glAdjust * CircleSize;\n}\n\nfloat relationshipHalfWidth(float width) {\n return width * u_glAdjust * 0.25;\n}\n\nfloat naturalArrowHeadHalfWidth(float lineHalfWidth) {\n return lineHalfWidth * HeadHalfWidthScale + u_glAdjust;\n}\n\nfloat naturalArrowHeadLength(float headHalfWidth) {\n return headHalfWidth * HeadLengthScale;\n}\n\nfloat clampArrowHeadHalfWidth(float lineHalfWidth, float nodeRadius) {\n float natural = naturalArrowHeadHalfWidth(lineHalfWidth);\n float minHalfWidth = lineHalfWidth;\n float maxHalfWidth = max(minHalfWidth, nodeRadius * MaxHeadHalfWidthRatio);\n return clamp(natural, minHalfWidth, maxHalfWidth);\n}\n\nfloat clampArrowHeadLength(float headHalfWidth, float nodeRadius) {\n float natural = naturalArrowHeadLength(headHalfWidth);\n float maxLength = nodeRadius * MaxHeadLengthRatio;\n return min(natural, maxLength);\n}\n\nfloat arrowHeadClearance(float lineHalfWidth, float nodeRadius) {\n float headHalfWidth = clampArrowHeadHalfWidth(lineHalfWidth, nodeRadius);\n return clampArrowHeadLength(headHalfWidth, nodeRadius);\n}\n";
@@ -0,0 +1,2 @@
1
+ declare const _default: "#version 300 es\nuniform mat4 u_projection;\nuniform sampler2D u_positions;\nuniform mediump float u_glAdjust;\n\nin vec2 a_from;\nin vec2 a_to;\nin lowp vec4 a_color;\nin float a_width;\nin float a_toSize;\n\nout lowp vec4 color;\n\n\nconst float CircleSize = 0.40;\nconst float HeadHalfWidthScale = 4.0;\nconst float HeadLengthScale = 2.5;\nconst float MaxHeadHalfWidthRatio = 0.6;\nconst float MaxHeadLengthRatio = 1.0;\n\n// Self-referencing relationships aren't supported in WebGL yet.\nbool relationshipIsSelfLoop(vec2 fromTexel, vec2 toTexel) {\n return all(equal(fromTexel, toTexel));\n}\n\nvec2 perpendicular(vec2 dir) {\n return vec2(-dir.y, dir.x);\n}\n\nfloat nodeRadiusFromSize(float size) {\n return size * u_glAdjust * CircleSize;\n}\n\nfloat relationshipHalfWidth(float width) {\n return width * u_glAdjust * 0.25;\n}\n\nfloat naturalArrowHeadHalfWidth(float lineHalfWidth) {\n return lineHalfWidth * HeadHalfWidthScale + u_glAdjust;\n}\n\nfloat naturalArrowHeadLength(float headHalfWidth) {\n return headHalfWidth * HeadLengthScale;\n}\n\nfloat clampArrowHeadHalfWidth(float lineHalfWidth, float nodeRadius) {\n float natural = naturalArrowHeadHalfWidth(lineHalfWidth);\n float minHalfWidth = lineHalfWidth;\n float maxHalfWidth = max(minHalfWidth, nodeRadius * MaxHeadHalfWidthRatio);\n return clamp(natural, minHalfWidth, maxHalfWidth);\n}\n\nfloat clampArrowHeadLength(float headHalfWidth, float nodeRadius) {\n float natural = naturalArrowHeadLength(headHalfWidth);\n float maxLength = nodeRadius * MaxHeadLengthRatio;\n return min(natural, maxLength);\n}\n\nfloat arrowHeadClearance(float lineHalfWidth, float nodeRadius) {\n float headHalfWidth = clampArrowHeadHalfWidth(lineHalfWidth, nodeRadius);\n return clampArrowHeadLength(headHalfWidth, nodeRadius);\n}\n\n\nvoid main(void) {\n vec4 from = texture(u_positions, a_from);\n vec4 to = texture(u_positions, a_to);\n\n if (relationshipIsSelfLoop(a_from, a_to)) {\n color = a_color;\n gl_Position = u_projection * vec4(from.xy, 0.0, 1.0);\n return;\n }\n\n vec2 delta = to.xy - from.xy;\n vec2 dir = normalize(delta);\n vec2 perp = perpendicular(dir);\n\n float toRadius = nodeRadiusFromSize(a_toSize);\n float lineHalfWidth = relationshipHalfWidth(a_width);\n float headHalfWidth = clampArrowHeadHalfWidth(lineHalfWidth, toRadius);\n float headLength = clampArrowHeadLength(headHalfWidth, toRadius);\n\n vec2 tip = to.xy - dir * toRadius;\n vec2 baseCenter = tip - dir * headLength;\n\n int corner = gl_VertexID % 3;\n float isTip = float(corner == 0);\n float perpSign = float(corner == 1) - float(corner == 2);\n vec2 basePos = mix(baseCenter, tip, isTip);\n vec2 vertexPosition = basePos + perp * (headHalfWidth * perpSign);\n\n color = a_color;\n gl_Position = u_projection * vec4(vertexPosition, 0.0, 1.0);\n}\n";
2
+ export default _default;
@@ -1,2 +1,2 @@
1
- declare const _default: "#version 300 es\nuniform mat4 u_projection;\nuniform sampler2D u_positions;\nuniform mediump float u_glAdjust;\n\nin vec2 a_from;\nin vec2 a_to;\nin lowp vec4 a_color;\nin lowp float a_triside;\nin float a_width;\n\nout lowp vec4 color;\n\nvoid main(void) {\n vec4 from = texture(u_positions, a_from);\n vec4 to = texture(u_positions, a_to);\n vec2 direction = normalize(to.xy - from.xy);\n vec2 perpendicular = vec2(-direction.y, direction.x);\n\n float halfWidth = a_width * u_glAdjust * 0.25;\n float sideSign = 1.0 - 2.0 * a_triside;\n from.xy += sideSign * halfWidth * perpendicular;\n\n color = a_color;\n gl_Position = u_projection * vec4(from.xy, 0.0, 1.0);\n}\n";
1
+ declare const _default: "#version 300 es\nuniform mat4 u_projection;\nuniform sampler2D u_positions;\nuniform mediump float u_glAdjust;\n\nin vec2 a_from;\nin vec2 a_to;\nin lowp vec4 a_color;\nin lowp float a_triside;\nin lowp float a_isTarget;\nin float a_endpointSize;\nin float a_otherEndpointSize;\nin float a_width;\n\nout lowp vec4 color;\n\n\nconst float CircleSize = 0.40;\nconst float HeadHalfWidthScale = 4.0;\nconst float HeadLengthScale = 2.5;\nconst float MaxHeadHalfWidthRatio = 0.6;\nconst float MaxHeadLengthRatio = 1.0;\n\n// Self-referencing relationships aren't supported in WebGL yet.\nbool relationshipIsSelfLoop(vec2 fromTexel, vec2 toTexel) {\n return all(equal(fromTexel, toTexel));\n}\n\nvec2 perpendicular(vec2 dir) {\n return vec2(-dir.y, dir.x);\n}\n\nfloat nodeRadiusFromSize(float size) {\n return size * u_glAdjust * CircleSize;\n}\n\nfloat relationshipHalfWidth(float width) {\n return width * u_glAdjust * 0.25;\n}\n\nfloat naturalArrowHeadHalfWidth(float lineHalfWidth) {\n return lineHalfWidth * HeadHalfWidthScale + u_glAdjust;\n}\n\nfloat naturalArrowHeadLength(float headHalfWidth) {\n return headHalfWidth * HeadLengthScale;\n}\n\nfloat clampArrowHeadHalfWidth(float lineHalfWidth, float nodeRadius) {\n float natural = naturalArrowHeadHalfWidth(lineHalfWidth);\n float minHalfWidth = lineHalfWidth;\n float maxHalfWidth = max(minHalfWidth, nodeRadius * MaxHeadHalfWidthRatio);\n return clamp(natural, minHalfWidth, maxHalfWidth);\n}\n\nfloat clampArrowHeadLength(float headHalfWidth, float nodeRadius) {\n float natural = naturalArrowHeadLength(headHalfWidth);\n float maxLength = nodeRadius * MaxHeadLengthRatio;\n return min(natural, maxLength);\n}\n\nfloat arrowHeadClearance(float lineHalfWidth, float nodeRadius) {\n float headHalfWidth = clampArrowHeadHalfWidth(lineHalfWidth, nodeRadius);\n return clampArrowHeadLength(headHalfWidth, nodeRadius);\n}\n\n\nvoid main(void) {\n vec4 from = texture(u_positions, a_from);\n vec4 to = texture(u_positions, a_to);\n\n if (relationshipIsSelfLoop(a_from, a_to)) {\n color = a_color;\n gl_Position = u_projection * vec4(from.xy, 0.0, 1.0);\n return;\n }\n\n vec2 delta = from.xy - to.xy;\n float halfWidth = relationshipHalfWidth(a_width);\n float ownRadius = nodeRadiusFromSize(a_endpointSize);\n float otherRadius = nodeRadiusFromSize(a_otherEndpointSize);\n float toRadius = mix(otherRadius, ownRadius, a_isTarget);\n float arrowClearance = arrowHeadClearance(halfWidth, toRadius);\n float endpointClearance = ownRadius + a_isTarget * arrowClearance;\n\n vec2 along = normalize(delta);\n from.xy -= along * endpointClearance;\n\n float sideSign = 1.0 - 2.0 * a_triside;\n from.xy += sideSign * halfWidth * perpendicular(along);\n\n color = a_color;\n gl_Position = u_projection * vec4(from.xy, 0.0, 1.0);\n}\n";
2
2
  export default _default;
@@ -0,0 +1,14 @@
1
+ import { type Point } from './geometry';
2
+ /** Extra world-space padding around each member disk before taking the cluster hull. */
3
+ export declare const ClusterHullPadding = 14;
4
+ /** Circumference samples per member disk before taking the convex hull. */
5
+ export declare const DiskSampleCount = 8;
6
+ export type ClusterMemberDisk = Point & {
7
+ radius: number;
8
+ };
9
+ /**
10
+ * Fits a convex hull around the given disks by sampling each member circumference.
11
+ * @param members - The cluster member disks to fit the hull around.
12
+ * @returns The fitted hull, or null if fewer than two members have a usable position/radius.
13
+ */
14
+ export declare const fitClusterHull: (members: ClusterMemberDisk[]) => Point[] | null;
@@ -0,0 +1 @@
1
+ export {};
@@ -134,6 +134,13 @@ export declare const getDistanceToQuadratic: (fromCoordinates: Point, toCoordina
134
134
  * @returns The point at that angle and radius from the centre.
135
135
  */
136
136
  export declare const pointOnCircle: (centre: Point, radius: number, angle: number) => Point;
137
+ /**
138
+ * Returns the point halfway between two points.
139
+ * @param a - The first point.
140
+ * @param b - The second point.
141
+ * @returns The midpoint of the segment from a to b.
142
+ */
143
+ export declare const getMidPoint: (a: Point, b: Point) => Point;
137
144
  /**
138
145
  * Places child points evenly spaced around a circle centred on a point.
139
146
  * @param centre - The centre of the circle.
@@ -142,3 +149,9 @@ export declare const pointOnCircle: (centre: Point, radius: number, angle: numbe
142
149
  * @returns The evenly spaced points.
143
150
  */
144
151
  export declare const calculateCirclePositions: (centre: Point, radius: number, noOfChildren: number) => Point[];
152
+ /**
153
+ * Andrew's monotone-chain convex hull.
154
+ * @param points - The points to get the convex hull of.
155
+ * @returns The convex hull of the points.
156
+ */
157
+ export declare const getConvexHull: (points: Point[]) => Point[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neo4j-nvl/base",
3
- "version": "1.2.0-d671dd1f",
3
+ "version": "1.2.0-dbc13ec2",
4
4
  "license": "SEE LICENSE IN 'LICENSE.txt'",
5
5
  "homepage": "https://neo4j.com/docs/nvl/current/",
6
6
  "description": "Base library for the Neo4j Visualization Library",
@@ -30,7 +30,7 @@
30
30
  "postpack": "rm LICENSE.txt && rm CHANGELOG.md"
31
31
  },
32
32
  "dependencies": {
33
- "@neo4j-nvl/layout-workers": "1.2.0-d671dd1f",
33
+ "@neo4j-nvl/layout-workers": "1.2.0-dbc13ec2",
34
34
  "@segment/analytics-next": "1.81.1",
35
35
  "color-string": "1.9.1",
36
36
  "d3-force": "3.0.0",
@@ -1,2 +0,0 @@
1
- declare const _default: "#version 300 es\nprecision mediump float;\n\nuniform sampler2D u_physData;\nuniform sampler2D u_connections;\nuniform sampler2D u_connectionOffsets;\nuniform sampler2D u_pinnedNodes;\nuniform sampler2D u_sizeTexture;\nuniform float u_baseLength;\nuniform float u_curIteration;\nuniform float u_iterationMultiplier;\nuniform vec2 u_gravityCenter;\nuniform float u_numNodes;\nuniform float u_gravity;\n\nuniform sampler2D u_clusterData;\nuniform sampler2D u_prevForce;\nuniform float u_collisionMultiplier;\nuniform float u_maxNodeSize;\nuniform float u_springForceMultiplier;\n\nout vec4 fragColor;\n\nfloat DAMP = 0.6;\nfloat COOL = 0.99998;\nfloat TIMESTEP = 1.0 / 30.0;\nfloat VELOCITYDECAY = 0.6;\nfloat accLimitLow = 500000.0;\nfloat accLimitHigh = 750000.0;\nfloat accLimitPosHigh = 10000000.0;\n\nconst float denseNodeThreshold = 1000.0;\nconst float MIN_DISTANCE = 0.00000001;\nconst float MAX_DISTANCE = 1000000000.0;\nconst float MAX_ACCELERATION = 50000.0;\n\nvec4 getTextureData(sampler2D tex, float index, float base) {\n float x = mod(index, base);\n float y = (index - x) / base;\n return texture(tex, vec2(x + 0.5, y + 0.5) / base);\n}\n\nbool isNan(float val) {\n return (val < 0.0 || 0.0 < val || val == 0.0) ? false : true;\n}\n\nconst float BIG_NUMBER = 999999999999999999.0;\nbool isInf(float val) {\n return val > BIG_NUMBER || val < -BIG_NUMBER;\n}\n\nvec2 getDelta(vec2 v1, vec2 v2) {\n vec2 delta = v1 - v2;\n float dist = length(delta);\n if (dist < MIN_DISTANCE || isNan(dist)) {\n return vec2(MIN_DISTANCE, MIN_DISTANCE);\n }\n if (dist > MAX_DISTANCE) {\n vec2 normDelta = delta / dist;\n return normDelta * MAX_DISTANCE;\n }\n return delta;\n}\n\nvec4 getOtherNodePosition(float i) {\n return getTextureData(u_physData, i, 256.0);\n}\n\nfloat getCombinedNodeSize(float i, float nodeSize) {\n float otherNodeSize = getTextureData(u_sizeTexture, i, 256.0).r;\n return nodeSize + otherNodeSize;\n}\n\nvec2 getSpringForce(float curConnection, float numConnections, float springFScale, vec4 myPosition, float i, float myClusterStartIndex) {\n float curSpring = getTextureData(u_connections, curConnection + i, 4096.0).r;\n\n vec4 otherPosition = getTextureData(u_physData, curSpring, 256.0);\n float otherDataPosition = getTextureData(u_connectionOffsets, curSpring, 256.0).r;\n float otherNumConnections = getTextureData(u_connections, otherDataPosition, 4096.0).r;\n float avgDegree = max((otherNumConnections + numConnections * 3.0) / 4.0, 4.0);\n\n vec2 delta = getDelta(myPosition.xy, otherPosition.xy);\n float dist = length(delta);\n\n float F = (dist * dist * springFScale) / (u_baseLength * avgDegree);\n if (u_collisionMultiplier > 0.0) {\n F *= u_collisionMultiplier;\n }\n\n // u_springForceMultiplier only damps edges that cross a cluster boundary\n if (u_springForceMultiplier < 1.0) {\n float otherClusterStartIndex = getTextureData(u_clusterData, curSpring, 256.0).y;\n F *= otherClusterStartIndex == myClusterStartIndex ? 1.0 : u_springForceMultiplier;\n }\n\n return (-delta / dist) * F;\n}\n\nvec2 getCollisionForce(float combinedNodeSize, float dist, float fScale, vec2 delta) {\n float collisionForce = (combinedNodeSize - dist) / (dist);\n if (u_collisionMultiplier > 0.0) {\n collisionForce *= u_collisionMultiplier;\n }\n return (delta * collisionForce * fScale * combinedNodeSize) / (combinedNodeSize + 1.0);\n}\n\nvec2 getRepulsionForce(float dist, float fScale, vec2 delta) {\n float F = (u_baseLength * u_baseLength * fScale) / (dist);\n return (delta / dist) * F * 0.05;\n}\n\nvoid main(void) {\n float textureSide = 256.0; //#TEXTURE_SIDE#;\n float index = (gl_FragCoord.x - 0.5) + (gl_FragCoord.y - 0.5) * textureSide;\n\n if (index >= u_numNodes) {\n discard;\n }\n\n vec4 clusterData = getTextureData(u_clusterData, index, 256.0);\n\n float clusterIndex = clusterData.x;\n float clusterStartIndex = clusterData.y;\n float clusterSize = clusterData.z;\n\n vec4 myPosition = getTextureData(u_physData, index, 256.0);\n vec4 previousForce = getTextureData(u_prevForce, clusterIndex, 256.0);\n\n vec2 acceleration = previousForce.xy;\n\n float isPinned = getTextureData(u_pinnedNodes, index, 256.0).r;\n float nodeSize = getTextureData(u_sizeTexture, index, 256.0).r;\n\n if (isPinned > 0.5) {\n fragColor = vec4(myPosition.xy, 0.0, 0.0);\n return;\n }\n\n float curConnection = getTextureData(u_connectionOffsets, index, 256.0).r;\n float numConnections = getTextureData(u_connections, curConnection, 4096.0).r;\n\n float fScale = 1.0 + sqrt(u_iterationMultiplier);\n float springFScale = fScale;\n\n if (numConnections > denseNodeThreshold) {\n springFScale = sqrt(fScale);\n }\n\n float numOfRels = 0.0;\n\n // Springs\n for (float i = 1.0; i <= 256.0 * 256.0; i++) {\n if (numOfRels >= numConnections) {\n break;\n }\n acceleration += getSpringForce(curConnection, numConnections, springFScale, myPosition, i, clusterStartIndex);\n numOfRels += 1.0;\n }\n\n // Repulsion && collision detection\n if (u_collisionMultiplier > 0.0) {\n float number_of_collisions = 0.0;\n for (float i = 0.0; i < 256.0 * 256.0; i++) {\n if (i >= u_numNodes) {\n break;\n }\n\n if (i == index) {\n continue;\n }\n\n vec4 otherPosition = getOtherNodePosition(i);\n vec2 delta = getDelta(myPosition.xy, otherPosition.xy);\n float dist = length(delta);\n\n if (number_of_collisions < 40.0 && dist < (nodeSize + u_maxNodeSize) * 2.0) {\n float combinedNodeSize = getCombinedNodeSize(i, nodeSize) * 2.0;\n if (dist < combinedNodeSize) {\n number_of_collisions++;\n acceleration += getCollisionForce(combinedNodeSize, dist, fScale, delta);\n }\n }\n\n if (i >= clusterStartIndex && i < clusterStartIndex + clusterSize) {\n acceleration += getRepulsionForce(dist, fScale, delta);\n }\n }\n } else {\n for (float i = 0.0; i < 256.0 * 256.0; i++) {\n if (i >= clusterStartIndex + clusterSize || i >= u_numNodes) {\n break;\n }\n\n if (i < clusterStartIndex || i == index) {\n continue;\n }\n\n vec4 otherPosition = getOtherNodePosition(i);\n vec2 delta = getDelta(myPosition.xy, otherPosition.xy);\n float dist = length(delta);\n float combinedNodeSize = getCombinedNodeSize(i, nodeSize);\n\n if (dist < combinedNodeSize) {\n acceleration += getCollisionForce(combinedNodeSize, dist, fScale, delta);\n }\n\n acceleration += getRepulsionForce(dist, fScale, delta);\n }\n }\n\n // Gravity\n vec2 delta = getDelta(u_gravityCenter, myPosition.xy);\n float dist = length(delta);\n\n vec2 grav = (delta / dist) * u_gravity * fScale * (dist / 1000.0);\n acceleration += grav;\n\n float accMagnitude = length(acceleration);\n acceleration *= min(MAX_ACCELERATION, accMagnitude) / accMagnitude;\n\n float iterationFrictionThreshold = 1000.0;\n\n if (u_curIteration > iterationFrictionThreshold) {\n float friction = 1.0 + pow((u_curIteration - iterationFrictionThreshold), 2.0) / 100.0;\n acceleration *= 1.0 / friction;\n }\n\n if (u_curIteration == 0.0) {\n fragColor = vec4(myPosition.xy, myPosition.zw);\n } else {\n float TEMP = max(0.02, pow(COOL, u_curIteration));\n vec2 prevVelocity = myPosition.zw;\n vec2 currentPos = myPosition.xy;\n\n vec2 newPos = currentPos + TEMP * ( DAMP * (prevVelocity) + acceleration * TIMESTEP * TIMESTEP);\n vec2 newVelocity = newPos - currentPos;\n fragColor = vec4(newPos, newVelocity);\n }\n}";
2
- export default _default;
@@ -1,2 +0,0 @@
1
- declare const _default: "#version 300 es\nprecision mediump float;\nuniform sampler2D u_physData;\nuniform sampler2D u_clusterData;\nuniform sampler2D u_finestIndexes;\nuniform sampler2D u_prevForce;\n\nuniform float u_baseLength;\nuniform float u_numNodes;\nuniform float u_iterationMultiplier;\nuniform float u_isTopLevel;\n\nout vec4 fragColor;\n\nfloat PI = 3.1415926535897932384626433832795;\nfloat TIMESTEP = 1.0 / 30.0;\nfloat VELOCITYDECAY = 1.0;\n\nvec4 getTextureData(sampler2D tex, float index, float base) {\n float x = mod(index, base);\n float y = (index - x) / base;\n return texture(tex, vec2(x + 0.5, y + 0.5) / base);\n}\n\nfloat getAdjustedClusterWeight(float clusterWeight) {\n return (clusterWeight * clusterWeight) / (clusterWeight + 1.0);\n}\n\nvoid main(void) {\n float index = (gl_FragCoord.x - 0.5) + (gl_FragCoord.y - 0.5) * 256.0;\n\n if (index >= u_numNodes) {\n discard;\n }\n\n vec4 clusterData = getTextureData(u_clusterData, index, 256.0);\n\n float clusterIndex = clusterData.x;\n float clusterStartIndex = clusterData.y;\n float clusterSize = clusterData.z;\n float clusterArea = pow(clusterSize + u_baseLength * 2.0, 2.0);\n\n float finestIndex = getTextureData(u_finestIndexes, index, 256.0).r;\n vec4 myPosition = getTextureData(u_physData, finestIndex, 256.0);\n vec4 previousForce = getTextureData(u_prevForce, clusterIndex, 256.0);\n float fScale = 1.0 + sqrt(u_iterationMultiplier);\n\n vec2 acceleration = previousForce.xy;\n\n // Repulsion & Collision Detection\n for (float i = 0.0; i < 256.0 * 256.0; i++) {\n if (i >= clusterStartIndex + clusterSize || i >= u_numNodes) {\n break;\n }\n if (i < clusterStartIndex || i == index) {\n continue;\n }\n\n vec4 otherClusterData = getTextureData(u_clusterData, i, 256.0);\n float otherClusterWeight = getAdjustedClusterWeight(otherClusterData.w);\n\n float otherFinestIndex = getTextureData(u_finestIndexes, i, 256.0).r;\n vec4 otherPosition = getTextureData(u_physData, otherFinestIndex, 256.0);\n\n vec2 delta = myPosition.xy - otherPosition.xy;\n float dist = max(length(delta), 0.0000001);\n float maxDist = 25.0;\n float repulsionForceScale = 0.1;\n\n float F = (clusterArea * fScale) / (dist * dist);\n\n if (u_isTopLevel == 1.0) {\n repulsionForceScale = 0.2;\n }\n\n acceleration += ((delta / sqrt(dist)) * F) * repulsionForceScale * otherClusterWeight;\n\n if (dist < maxDist) {\n float collide = (maxDist - dist) / (dist * dist);\n acceleration += delta * collide * fScale * maxDist / (maxDist + 1.0);\n }\n }\n\n fragColor = vec4(acceleration, vec2(finestIndex, 0));\n}";
2
- export default _default;