@cosmos.gl/graph 2.7.0-beta.0 → 2.7.0-beta.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.
Files changed (176) hide show
  1. package/dist/config.d.ts +18 -5
  2. package/dist/{index-FUIgayhu.js → index-B1_1MjaX.js} +1909 -1819
  3. package/dist/index-B1_1MjaX.js.map +1 -0
  4. package/dist/index.d.ts +66 -6
  5. package/dist/index.js +1 -1
  6. package/dist/index.min.js +46 -34
  7. package/dist/index.min.js.map +1 -1
  8. package/dist/modules/Clusters/index.d.ts +0 -3
  9. package/dist/modules/GraphData/index.d.ts +1 -0
  10. package/dist/modules/Points/index.d.ts +2 -4
  11. package/dist/{webgl-device-B9ewDj5L.js → webgl-device-DzkMihDq.js} +2 -2
  12. package/dist/{webgl-device-B9ewDj5L.js.map → webgl-device-DzkMihDq.js.map} +1 -1
  13. package/package.json +5 -1
  14. package/.eslintrc +0 -147
  15. package/.github/SECURITY.md +0 -13
  16. package/.github/dco.yml +0 -4
  17. package/.github/workflows/github_pages.yml +0 -54
  18. package/.storybook/main.ts +0 -26
  19. package/.storybook/manager-head.html +0 -1
  20. package/.storybook/manager.ts +0 -14
  21. package/.storybook/preview.ts +0 -29
  22. package/.storybook/style.css +0 -3
  23. package/CHARTER.md +0 -69
  24. package/CODE_OF_CONDUCT.md +0 -178
  25. package/CONTRIBUTING.md +0 -22
  26. package/GOVERNANCE.md +0 -21
  27. package/cosmos-2-0-migration-notes.md +0 -98
  28. package/cosmos_awesome.md +0 -96
  29. package/dist/index-FUIgayhu.js.map +0 -1
  30. package/dist/stories/beginners/basic-set-up/data-gen.d.ts +0 -4
  31. package/dist/stories/beginners/basic-set-up/index.d.ts +0 -6
  32. package/dist/stories/beginners/link-hovering/data-generator.d.ts +0 -19
  33. package/dist/stories/beginners/link-hovering/index.d.ts +0 -6
  34. package/dist/stories/beginners/point-labels/data.d.ts +0 -13
  35. package/dist/stories/beginners/point-labels/index.d.ts +0 -10
  36. package/dist/stories/beginners/point-labels/labels.d.ts +0 -8
  37. package/dist/stories/beginners/quick-start.d.ts +0 -6
  38. package/dist/stories/beginners/remove-points/config.d.ts +0 -2
  39. package/dist/stories/beginners/remove-points/data-gen.d.ts +0 -4
  40. package/dist/stories/beginners/remove-points/index.d.ts +0 -6
  41. package/dist/stories/beginners.stories.d.ts +0 -10
  42. package/dist/stories/clusters/polygon-selection/index.d.ts +0 -6
  43. package/dist/stories/clusters/polygon-selection/polygon.d.ts +0 -20
  44. package/dist/stories/clusters/radial.d.ts +0 -6
  45. package/dist/stories/clusters/with-labels.d.ts +0 -6
  46. package/dist/stories/clusters/worm.d.ts +0 -6
  47. package/dist/stories/clusters.stories.d.ts +0 -9
  48. package/dist/stories/create-cluster-labels.d.ts +0 -4
  49. package/dist/stories/create-cosmos.d.ts +0 -17
  50. package/dist/stories/create-story.d.ts +0 -16
  51. package/dist/stories/experiments/full-mesh.d.ts +0 -6
  52. package/dist/stories/experiments/mesh-with-holes.d.ts +0 -6
  53. package/dist/stories/experiments.stories.d.ts +0 -7
  54. package/dist/stories/generate-mesh-data.d.ts +0 -12
  55. package/dist/stories/geospatial/moscow-metro-stations/index.d.ts +0 -16
  56. package/dist/stories/geospatial/moscow-metro-stations/moscow-metro-coords.d.ts +0 -1
  57. package/dist/stories/geospatial/moscow-metro-stations/point-colors.d.ts +0 -1
  58. package/dist/stories/geospatial.stories.d.ts +0 -6
  59. package/dist/stories/shapes/all-shapes/index.d.ts +0 -6
  60. package/dist/stories/shapes/image-example/index.d.ts +0 -6
  61. package/dist/stories/shapes.stories.d.ts +0 -7
  62. package/dist/stories/test-luma-migration.d.ts +0 -6
  63. package/dist/stories/test.stories.d.ts +0 -6
  64. package/logo.svg +0 -3
  65. package/rollup.config.js +0 -70
  66. package/src/config.ts +0 -728
  67. package/src/declaration.d.ts +0 -12
  68. package/src/graph/utils/error-message.ts +0 -23
  69. package/src/helper.ts +0 -113
  70. package/src/index.ts +0 -1769
  71. package/src/modules/Clusters/calculate-centermass.frag +0 -12
  72. package/src/modules/Clusters/calculate-centermass.vert +0 -38
  73. package/src/modules/Clusters/force-cluster.frag +0 -55
  74. package/src/modules/Clusters/index.ts +0 -578
  75. package/src/modules/Drag/index.ts +0 -33
  76. package/src/modules/FPSMonitor/css.ts +0 -53
  77. package/src/modules/FPSMonitor/index.ts +0 -28
  78. package/src/modules/ForceCenter/calculate-centermass.frag +0 -9
  79. package/src/modules/ForceCenter/calculate-centermass.vert +0 -26
  80. package/src/modules/ForceCenter/force-center.frag +0 -37
  81. package/src/modules/ForceCenter/index.ts +0 -284
  82. package/src/modules/ForceGravity/force-gravity.frag +0 -40
  83. package/src/modules/ForceGravity/index.ts +0 -107
  84. package/src/modules/ForceLink/force-spring.ts +0 -89
  85. package/src/modules/ForceLink/index.ts +0 -293
  86. package/src/modules/ForceManyBody/calculate-level.frag +0 -9
  87. package/src/modules/ForceManyBody/calculate-level.vert +0 -37
  88. package/src/modules/ForceManyBody/force-centermass.frag +0 -61
  89. package/src/modules/ForceManyBody/force-level.frag +0 -138
  90. package/src/modules/ForceManyBody/index.ts +0 -525
  91. package/src/modules/ForceManyBody/quadtree-frag-shader.ts +0 -89
  92. package/src/modules/ForceManyBodyQuadtree/calculate-level.frag +0 -9
  93. package/src/modules/ForceManyBodyQuadtree/calculate-level.vert +0 -25
  94. package/src/modules/ForceManyBodyQuadtree/index.ts +0 -157
  95. package/src/modules/ForceManyBodyQuadtree/quadtree-frag-shader.ts +0 -93
  96. package/src/modules/ForceMouse/force-mouse.frag +0 -35
  97. package/src/modules/ForceMouse/index.ts +0 -102
  98. package/src/modules/GraphData/index.ts +0 -383
  99. package/src/modules/Lines/draw-curve-line.frag +0 -59
  100. package/src/modules/Lines/draw-curve-line.vert +0 -248
  101. package/src/modules/Lines/geometry.ts +0 -18
  102. package/src/modules/Lines/hovered-line-index.frag +0 -43
  103. package/src/modules/Lines/hovered-line-index.vert +0 -13
  104. package/src/modules/Lines/index.ts +0 -661
  105. package/src/modules/Points/atlas-utils.ts +0 -137
  106. package/src/modules/Points/drag-point.frag +0 -34
  107. package/src/modules/Points/draw-highlighted.frag +0 -44
  108. package/src/modules/Points/draw-highlighted.vert +0 -145
  109. package/src/modules/Points/draw-points.frag +0 -259
  110. package/src/modules/Points/draw-points.vert +0 -203
  111. package/src/modules/Points/fill-sampled-points.frag +0 -12
  112. package/src/modules/Points/fill-sampled-points.vert +0 -51
  113. package/src/modules/Points/find-hovered-point.frag +0 -15
  114. package/src/modules/Points/find-hovered-point.vert +0 -90
  115. package/src/modules/Points/find-points-on-area-selection.frag +0 -88
  116. package/src/modules/Points/find-points-on-polygon-selection.frag +0 -89
  117. package/src/modules/Points/index.ts +0 -2292
  118. package/src/modules/Points/track-positions.frag +0 -30
  119. package/src/modules/Points/update-position.frag +0 -39
  120. package/src/modules/Shared/buffer.ts +0 -39
  121. package/src/modules/Shared/clear.frag +0 -10
  122. package/src/modules/Shared/quad.vert +0 -13
  123. package/src/modules/Store/index.ts +0 -283
  124. package/src/modules/Zoom/index.ts +0 -148
  125. package/src/modules/core-module.ts +0 -28
  126. package/src/stories/1. welcome.mdx +0 -75
  127. package/src/stories/2. configuration.mdx +0 -111
  128. package/src/stories/3. api-reference.mdx +0 -591
  129. package/src/stories/beginners/basic-set-up/data-gen.ts +0 -33
  130. package/src/stories/beginners/basic-set-up/index.ts +0 -167
  131. package/src/stories/beginners/basic-set-up/style.css +0 -35
  132. package/src/stories/beginners/link-hovering/data-generator.ts +0 -198
  133. package/src/stories/beginners/link-hovering/index.ts +0 -65
  134. package/src/stories/beginners/link-hovering/style.css +0 -73
  135. package/src/stories/beginners/point-labels/data.ts +0 -73
  136. package/src/stories/beginners/point-labels/index.ts +0 -69
  137. package/src/stories/beginners/point-labels/labels.ts +0 -46
  138. package/src/stories/beginners/point-labels/style.css +0 -16
  139. package/src/stories/beginners/quick-start.ts +0 -54
  140. package/src/stories/beginners/remove-points/config.ts +0 -25
  141. package/src/stories/beginners/remove-points/data-gen.ts +0 -30
  142. package/src/stories/beginners/remove-points/index.ts +0 -96
  143. package/src/stories/beginners/remove-points/style.css +0 -31
  144. package/src/stories/beginners.stories.ts +0 -130
  145. package/src/stories/clusters/polygon-selection/index.ts +0 -52
  146. package/src/stories/clusters/polygon-selection/polygon.ts +0 -143
  147. package/src/stories/clusters/polygon-selection/style.css +0 -8
  148. package/src/stories/clusters/radial.ts +0 -24
  149. package/src/stories/clusters/with-labels.ts +0 -54
  150. package/src/stories/clusters/worm.ts +0 -40
  151. package/src/stories/clusters.stories.ts +0 -77
  152. package/src/stories/create-cluster-labels.ts +0 -50
  153. package/src/stories/create-cosmos.ts +0 -72
  154. package/src/stories/create-story.ts +0 -51
  155. package/src/stories/experiments/full-mesh.ts +0 -13
  156. package/src/stories/experiments/mesh-with-holes.ts +0 -13
  157. package/src/stories/experiments.stories.ts +0 -43
  158. package/src/stories/generate-mesh-data.ts +0 -125
  159. package/src/stories/geospatial/moscow-metro-stations/index.ts +0 -66
  160. package/src/stories/geospatial/moscow-metro-stations/moscow-metro-coords.ts +0 -1
  161. package/src/stories/geospatial/moscow-metro-stations/point-colors.ts +0 -46
  162. package/src/stories/geospatial/moscow-metro-stations/style.css +0 -30
  163. package/src/stories/geospatial.stories.ts +0 -30
  164. package/src/stories/shapes/all-shapes/index.ts +0 -73
  165. package/src/stories/shapes/image-example/icons/box.png +0 -0
  166. package/src/stories/shapes/image-example/icons/lego.png +0 -0
  167. package/src/stories/shapes/image-example/icons/s.png +0 -0
  168. package/src/stories/shapes/image-example/icons/swift.png +0 -0
  169. package/src/stories/shapes/image-example/icons/toolbox.png +0 -0
  170. package/src/stories/shapes/image-example/index.ts +0 -246
  171. package/src/stories/shapes.stories.ts +0 -37
  172. package/src/stories/test-luma-migration.ts +0 -195
  173. package/src/stories/test.stories.ts +0 -25
  174. package/src/variables.ts +0 -68
  175. package/tsconfig.json +0 -41
  176. package/vite.config.ts +0 -52
@@ -1,33 +0,0 @@
1
- import { drag } from 'd3-drag'
2
- import { Store } from '@/graph/modules/Store'
3
- import { GraphConfigInterface } from '@/graph/config'
4
-
5
- export class Drag {
6
- public readonly store: Store
7
- public readonly config: GraphConfigInterface
8
- public isActive = false
9
- public behavior = drag<HTMLCanvasElement, undefined>()
10
- .subject((event) => {
11
- return this.store.hoveredPoint && !this.store.isSpaceKeyPressed ? { x: event.x, y: event.y } : undefined
12
- })
13
- .on('start', (e) => {
14
- if (this.store.hoveredPoint) {
15
- this.store.draggingPointIndex = this.store.hoveredPoint.index
16
- this.isActive = true
17
- this.config?.onDragStart?.(e)
18
- }
19
- })
20
- .on('drag', (e) => {
21
- this.config?.onDrag?.(e)
22
- })
23
- .on('end', (e) => {
24
- this.isActive = false
25
- this.store.draggingPointIndex = undefined
26
- this.config?.onDragEnd?.(e)
27
- })
28
-
29
- public constructor (store: Store, config: GraphConfigInterface) {
30
- this.store = store
31
- this.config = config
32
- }
33
- }
@@ -1,53 +0,0 @@
1
- export const benchCSS = `
2
- #gl-bench {
3
- position:absolute;
4
- right:0;
5
- top:0;
6
- z-index:1000;
7
- -webkit-user-select: none;
8
- -moz-user-select: none;
9
- user-select: none;
10
- }
11
- #gl-bench div {
12
- position: relative;
13
- display: block;
14
- margin: 4px;
15
- padding: 0 7px 0 10px;
16
- background: #5f69de;
17
- border-radius: 15px;
18
- cursor: pointer;
19
- opacity: 0.9;
20
- }
21
- #gl-bench svg {
22
- height: 60px;
23
- margin: 0 -1px;
24
- }
25
- #gl-bench text {
26
- font-size: 12px;
27
- font-family: Helvetica,Arial,sans-serif;
28
- font-weight: 700;
29
- dominant-baseline: middle;
30
- text-anchor: middle;
31
- }
32
- #gl-bench .gl-mem {
33
- font-size: 9px;
34
- }
35
- #gl-bench line {
36
- stroke-width: 5;
37
- stroke: #112211;
38
- stroke-linecap: round;
39
- }
40
- #gl-bench polyline {
41
- fill: none;
42
- stroke: #112211;
43
- stroke-linecap: round;
44
- stroke-linejoin: round;
45
- stroke-width: 3.5;
46
- }
47
- #gl-bench rect {
48
- fill: #8288e4;
49
- }
50
- #gl-bench .opacity {
51
- stroke: #8288e4;
52
- }
53
- `
@@ -1,28 +0,0 @@
1
-
2
- import { select } from 'd3-selection'
3
- import GLBench from 'gl-bench/dist/gl-bench'
4
- import { benchCSS } from './css'
5
-
6
- export class FPSMonitor {
7
- private bench: GLBench | undefined
8
-
9
- public constructor (canvas: HTMLCanvasElement) {
10
- this.destroy()
11
- const gl = (canvas.getContext('webgl') || canvas.getContext('experimental-webgl')) as WebGL2RenderingContext
12
- this.bench = new GLBench(gl, { css: benchCSS })
13
- }
14
-
15
- public begin (): void {
16
- this.bench?.begin('frame')
17
- }
18
-
19
- public end (now: number): void {
20
- this.bench?.end('frame')
21
- this.bench?.nextFrame(now)
22
- }
23
-
24
- public destroy (): void {
25
- this.bench = undefined
26
- select('#gl-bench').remove()
27
- }
28
- }
@@ -1,9 +0,0 @@
1
- #version 300 es
2
- precision highp float;
3
-
4
- in vec4 rgba;
5
- out vec4 fragColor;
6
-
7
- void main() {
8
- fragColor = rgba;
9
- }
@@ -1,26 +0,0 @@
1
- #version 300 es
2
- precision highp float;
3
-
4
- uniform sampler2D positionsTexture;
5
-
6
- #ifdef USE_UNIFORM_BUFFERS
7
- layout(std140) uniform calculateCentermassUniforms {
8
- float pointsTextureSize;
9
- } calculateCentermass;
10
-
11
- #define pointsTextureSize calculateCentermass.pointsTextureSize
12
- #else
13
- uniform float pointsTextureSize;
14
- #endif
15
-
16
- in vec2 pointIndices;
17
-
18
- out vec4 rgba;
19
-
20
- void main() {
21
- vec4 pointPosition = texture(positionsTexture, pointIndices / pointsTextureSize);
22
- rgba = vec4(pointPosition.xy, 1.0, 0.0);
23
-
24
- gl_Position = vec4(0.0, 0.0, 0.0, 1.0);
25
- gl_PointSize = 1.0;
26
- }
@@ -1,37 +0,0 @@
1
- #version 300 es
2
- precision highp float;
3
-
4
- uniform sampler2D positionsTexture;
5
- uniform sampler2D centermassTexture;
6
-
7
- #ifdef USE_UNIFORM_BUFFERS
8
- layout(std140) uniform forceCenterUniforms {
9
- float centerForce;
10
- float alpha;
11
- } forceCenter;
12
-
13
- #define centerForce forceCenter.centerForce
14
- #define alpha forceCenter.alpha
15
- #else
16
- uniform float centerForce;
17
- uniform float alpha;
18
- #endif
19
-
20
- in vec2 textureCoords;
21
- out vec4 fragColor;
22
-
23
- void main() {
24
- vec4 pointPosition = texture(positionsTexture, textureCoords);
25
- vec4 velocity = vec4(0.0);
26
- vec4 centermassValues = texture(centermassTexture, vec2(0.0));
27
- vec2 centermassPosition = centermassValues.xy / centermassValues.b;
28
- vec2 distVector = centermassPosition - pointPosition.xy;
29
- float dist = sqrt(dot(distVector, distVector));
30
- if (dist > 0.0) {
31
- float angle = atan(distVector.y, distVector.x);
32
- float addV = alpha * centerForce * dist * 0.01;
33
- velocity.rg += addV * vec2(cos(angle), sin(angle));
34
- }
35
-
36
- fragColor = velocity;
37
- }
@@ -1,284 +0,0 @@
1
- import { Buffer, Framebuffer, RenderPass, Texture, UniformStore } from '@luma.gl/core'
2
- import { Model } from '@luma.gl/engine'
3
- import { CoreModule } from '@/graph/modules/core-module'
4
- import calculateCentermassFrag from '@/graph/modules/ForceCenter/calculate-centermass.frag?raw'
5
- import calculateCentermassVert from '@/graph/modules/ForceCenter/calculate-centermass.vert?raw'
6
- import forceFrag from '@/graph/modules/ForceCenter/force-center.frag?raw'
7
- import { createIndexesForBuffer } from '@/graph/modules/Shared/buffer'
8
- import clearFrag from '@/graph/modules/Shared/clear.frag?raw'
9
- import updateVert from '@/graph/modules/Shared/quad.vert?raw'
10
-
11
- export class ForceCenter extends CoreModule {
12
- private centermassTexture: Texture | undefined
13
- private centermassFbo: Framebuffer | undefined
14
- private pointIndices: Buffer | undefined
15
-
16
- private clearCentermassCommand: Model | undefined
17
- private calculateCentermassCommand: Model | undefined
18
- private runCommand: Model | undefined
19
-
20
- private clearVertexCoordBuffer: Buffer | undefined
21
- private forceVertexCoordBuffer: Buffer | undefined
22
-
23
- private calculateUniformStore: UniformStore<{
24
- calculateCentermassUniforms: {
25
- pointsTextureSize: number;
26
- };
27
- }> | undefined
28
-
29
- private forceUniformStore: UniformStore<{
30
- forceCenterUniforms: {
31
- centerForce: number;
32
- alpha: number;
33
- };
34
- }> | undefined
35
-
36
- private previousPointsTextureSize: number | undefined
37
-
38
- public create (): void {
39
- const { device, store } = this
40
- const { pointsTextureSize } = store
41
- if (!pointsTextureSize) return
42
-
43
- if (!this.centermassTexture || this.centermassTexture.destroyed) {
44
- this.centermassTexture = device.createTexture({
45
- width: 1,
46
- height: 1,
47
- format: 'rgba32float',
48
- usage: Texture.SAMPLE | Texture.RENDER | Texture.COPY_DST,
49
- })
50
- }
51
- this.centermassTexture.copyImageData({
52
- data: new Float32Array(4).fill(0),
53
- bytesPerRow: 1,
54
- mipLevel: 0,
55
- x: 0,
56
- y: 0,
57
- })
58
-
59
- if (!this.centermassFbo || this.centermassFbo.destroyed) {
60
- this.centermassFbo = device.createFramebuffer({
61
- width: 1,
62
- height: 1,
63
- colorAttachments: [this.centermassTexture],
64
- })
65
- }
66
-
67
- const indexData = createIndexesForBuffer(pointsTextureSize)
68
- if (!this.pointIndices || this.pointIndices.byteLength !== indexData.byteLength) {
69
- this.pointIndices?.destroy()
70
- this.pointIndices = device.createBuffer({
71
- data: indexData,
72
- usage: Buffer.VERTEX | Buffer.COPY_DST,
73
- })
74
- } else {
75
- this.pointIndices.write(indexData)
76
- }
77
-
78
- this.previousPointsTextureSize = pointsTextureSize
79
- }
80
-
81
- public initPrograms (): void {
82
- const { device, store, points } = this
83
- if (!points || !store.pointsTextureSize) return
84
- if (!this.centermassFbo || this.centermassFbo.destroyed || !this.centermassTexture || this.centermassTexture.destroyed) return
85
- if (!this.pointIndices) return
86
-
87
- // Fullscreen quad buffer (shared by clear and force passes)
88
- if (!this.clearVertexCoordBuffer || this.clearVertexCoordBuffer.destroyed) {
89
- this.clearVertexCoordBuffer = device.createBuffer({
90
- data: new Float32Array([-1, -1, 1, -1, -1, 1, 1, 1]),
91
- })
92
- }
93
- if (!this.forceVertexCoordBuffer || this.forceVertexCoordBuffer.destroyed) {
94
- this.forceVertexCoordBuffer = device.createBuffer({
95
- data: new Float32Array([-1, -1, 1, -1, -1, 1, 1, 1]),
96
- })
97
- }
98
-
99
- if (!this.calculateUniformStore) {
100
- this.calculateUniformStore = new UniformStore({
101
- calculateCentermassUniforms: {
102
- uniformTypes: {
103
- pointsTextureSize: 'f32',
104
- },
105
- },
106
- })
107
- }
108
-
109
- if (!this.forceUniformStore) {
110
- this.forceUniformStore = new UniformStore({
111
- forceCenterUniforms: {
112
- uniformTypes: {
113
- centerForce: 'f32',
114
- alpha: 'f32',
115
- },
116
- },
117
- })
118
- }
119
-
120
- if (!this.clearCentermassCommand) {
121
- this.clearCentermassCommand = new Model(device, {
122
- fs: clearFrag,
123
- vs: updateVert,
124
- topology: 'triangle-strip',
125
- vertexCount: 4,
126
- attributes: {
127
- vertexCoord: this.clearVertexCoordBuffer,
128
- },
129
- bufferLayout: [
130
- { name: 'vertexCoord', format: 'float32x2' },
131
- ],
132
- parameters: {
133
- depthWriteEnabled: false,
134
- depthCompare: 'always',
135
- },
136
- })
137
- }
138
-
139
- if (!this.calculateCentermassCommand) {
140
- this.calculateCentermassCommand = new Model(device, {
141
- fs: calculateCentermassFrag,
142
- vs: calculateCentermassVert,
143
- topology: 'point-list',
144
- vertexCount: this.data.pointsNumber ?? 0,
145
- attributes: {
146
- pointIndices: this.pointIndices,
147
- },
148
- bufferLayout: [
149
- { name: 'pointIndices', format: 'float32x2' },
150
- ],
151
- defines: {
152
- USE_UNIFORM_BUFFERS: true,
153
- },
154
- bindings: {
155
- calculateCentermassUniforms: this.calculateUniformStore.getManagedUniformBuffer(device, 'calculateCentermassUniforms'),
156
- positionsTexture: points.previousPositionTexture!,
157
- },
158
- parameters: {
159
- blend: true,
160
- blendColorOperation: 'add',
161
- blendColorSrcFactor: 'one',
162
- blendColorDstFactor: 'one',
163
- blendAlphaOperation: 'add',
164
- blendAlphaSrcFactor: 'one',
165
- blendAlphaDstFactor: 'one',
166
- depthWriteEnabled: false,
167
- depthCompare: 'always',
168
- },
169
- })
170
- } else {
171
- this.calculateCentermassCommand.setVertexCount(this.data.pointsNumber ?? 0)
172
- }
173
-
174
- if (!this.runCommand) {
175
- this.runCommand = new Model(device, {
176
- fs: forceFrag,
177
- vs: updateVert,
178
- topology: 'triangle-strip',
179
- vertexCount: 4,
180
- attributes: {
181
- vertexCoord: this.forceVertexCoordBuffer,
182
- },
183
- bufferLayout: [
184
- { name: 'vertexCoord', format: 'float32x2' },
185
- ],
186
- defines: {
187
- USE_UNIFORM_BUFFERS: true,
188
- },
189
- bindings: {
190
- forceCenterUniforms: this.forceUniformStore.getManagedUniformBuffer(device, 'forceCenterUniforms'),
191
- positionsTexture: points.previousPositionTexture!,
192
- centermassTexture: this.centermassTexture,
193
- },
194
- parameters: {
195
- depthWriteEnabled: false,
196
- depthCompare: 'always',
197
- },
198
- })
199
- }
200
- }
201
-
202
- public run (renderPass?: RenderPass): void {
203
- const { device, store, points } = this
204
- if (!points || !this.centermassFbo || !this.centermassTexture) return
205
- if (!this.calculateCentermassCommand || !this.calculateUniformStore || !this.runCommand || !this.forceUniformStore) return
206
- if (!points.previousPositionTexture || points.previousPositionTexture.destroyed) return
207
- if (!renderPass && (!points.velocityFbo || points.velocityFbo.destroyed)) return
208
-
209
- // Skip if sizes changed and create() wasn't called yet
210
- if (store.pointsTextureSize !== this.previousPointsTextureSize) return
211
-
212
- // Clear centermass then accumulate
213
- const centermassPass = device.beginRenderPass({
214
- framebuffer: this.centermassFbo,
215
- clearColor: [0, 0, 0, 0],
216
- })
217
-
218
- this.calculateUniformStore.setUniforms({
219
- calculateCentermassUniforms: {
220
- pointsTextureSize: store.pointsTextureSize ?? 0,
221
- },
222
- })
223
- this.calculateCentermassCommand.setBindings({
224
- calculateCentermassUniforms: this.calculateUniformStore.getManagedUniformBuffer(device, 'calculateCentermassUniforms'),
225
- positionsTexture: points.previousPositionTexture!,
226
- })
227
-
228
- // No need to draw clear model separately; pass clearColor already zeroed
229
- this.calculateCentermassCommand.draw(centermassPass)
230
- centermassPass.end()
231
-
232
- // Apply center force into velocity
233
- this.forceUniformStore.setUniforms({
234
- forceCenterUniforms: {
235
- centerForce: this.config.simulationCenter ?? 0,
236
- alpha: store.alpha,
237
- },
238
- })
239
- this.runCommand.setBindings({
240
- forceCenterUniforms: this.forceUniformStore.getManagedUniformBuffer(device, 'forceCenterUniforms'),
241
- positionsTexture: points.previousPositionTexture!,
242
- centermassTexture: this.centermassTexture,
243
- })
244
-
245
- const pass = renderPass ?? device.beginRenderPass({
246
- framebuffer: points.velocityFbo,
247
- })
248
-
249
- this.runCommand.draw(pass)
250
-
251
- if (!renderPass) pass.end()
252
- }
253
-
254
- public destroy (): void {
255
- this.calculateUniformStore?.destroy()
256
- this.calculateUniformStore = undefined
257
- this.forceUniformStore?.destroy()
258
- this.forceUniformStore = undefined
259
-
260
- this.clearCentermassCommand?.destroy()
261
- this.clearCentermassCommand = undefined
262
- this.calculateCentermassCommand?.destroy()
263
- this.calculateCentermassCommand = undefined
264
- this.runCommand?.destroy()
265
- this.runCommand = undefined
266
-
267
- if (this.clearVertexCoordBuffer && !this.clearVertexCoordBuffer.destroyed) this.clearVertexCoordBuffer.destroy()
268
- this.clearVertexCoordBuffer = undefined
269
-
270
- if (this.forceVertexCoordBuffer && !this.forceVertexCoordBuffer.destroyed) this.forceVertexCoordBuffer.destroy()
271
- this.forceVertexCoordBuffer = undefined
272
-
273
- this.pointIndices?.destroy()
274
- this.pointIndices = undefined
275
-
276
- if (this.centermassTexture && !this.centermassTexture.destroyed) this.centermassTexture.destroy()
277
- this.centermassTexture = undefined
278
-
279
- if (this.centermassFbo && !this.centermassFbo.destroyed) this.centermassFbo.destroy()
280
- this.centermassFbo = undefined
281
-
282
- this.previousPointsTextureSize = undefined
283
- }
284
- }
@@ -1,40 +0,0 @@
1
- #version 300 es
2
- precision highp float;
3
-
4
- uniform sampler2D positionsTexture;
5
-
6
- #ifdef USE_UNIFORM_BUFFERS
7
- layout(std140) uniform forceGravityUniforms {
8
- float gravity;
9
- float spaceSize;
10
- float alpha;
11
- } forceGravity;
12
-
13
- #define gravity forceGravity.gravity
14
- #define spaceSize forceGravity.spaceSize
15
- #define alpha forceGravity.alpha
16
- #else
17
- uniform float gravity;
18
- uniform float spaceSize;
19
- uniform float alpha;
20
- #endif
21
-
22
- in vec2 textureCoords;
23
- out vec4 fragColor;
24
-
25
- void main() {
26
- vec4 pointPosition = texture(positionsTexture, textureCoords);
27
-
28
- vec4 velocity = vec4(0.0);
29
-
30
- vec2 centerPosition = vec2(spaceSize * 0.5);
31
- vec2 distVector = centerPosition - pointPosition.rg;
32
- float dist = sqrt(dot(distVector, distVector));
33
- if (dist > 0.0) {
34
- float angle = atan(distVector.y, distVector.x);
35
- float additionalVelocity = alpha * gravity * dist * 0.1;
36
- velocity.rg += additionalVelocity * vec2(cos(angle), sin(angle));
37
- }
38
-
39
- fragColor = velocity;
40
- }
@@ -1,107 +0,0 @@
1
- import { Buffer, RenderPass, UniformStore } from '@luma.gl/core'
2
- import { Model } from '@luma.gl/engine'
3
- import { CoreModule } from '@/graph/modules/core-module'
4
- import forceFrag from '@/graph/modules/ForceGravity/force-gravity.frag?raw'
5
- import updateVert from '@/graph/modules/Shared/quad.vert?raw'
6
-
7
- export class ForceGravity extends CoreModule {
8
- private runCommand: Model | undefined
9
- private vertexCoordBuffer: Buffer | undefined
10
- private uniformStore: UniformStore<{
11
- forceGravityUniforms: {
12
- gravity: number;
13
- spaceSize: number;
14
- alpha: number;
15
- };
16
- }> | undefined
17
-
18
- public initPrograms (): void {
19
- const { device, points, store } = this
20
- if (!points || !store.pointsTextureSize) return
21
-
22
- if (!this.vertexCoordBuffer || this.vertexCoordBuffer.destroyed) {
23
- this.vertexCoordBuffer = device.createBuffer({
24
- data: new Float32Array([-1, -1, 1, -1, -1, 1, 1, 1]),
25
- })
26
- }
27
-
28
- if (!this.uniformStore) {
29
- this.uniformStore = new UniformStore({
30
- forceGravityUniforms: {
31
- uniformTypes: {
32
- gravity: 'f32',
33
- spaceSize: 'f32',
34
- alpha: 'f32',
35
- },
36
- },
37
- })
38
- }
39
-
40
- if (!this.runCommand) {
41
- this.runCommand = new Model(device, {
42
- fs: forceFrag,
43
- vs: updateVert,
44
- topology: 'triangle-strip',
45
- vertexCount: 4,
46
- attributes: {
47
- vertexCoord: this.vertexCoordBuffer,
48
- },
49
- bufferLayout: [
50
- { name: 'vertexCoord', format: 'float32x2' },
51
- ],
52
- defines: {
53
- USE_UNIFORM_BUFFERS: true,
54
- },
55
- bindings: {
56
- forceGravityUniforms: this.uniformStore.getManagedUniformBuffer(device, 'forceGravityUniforms'),
57
- positionsTexture: points.previousPositionTexture!,
58
- },
59
- parameters: {
60
- depthWriteEnabled: false,
61
- depthCompare: 'always',
62
- },
63
- })
64
- }
65
- }
66
-
67
- public run (renderPass?: RenderPass): void {
68
- const { device, points, store } = this
69
- if (!points || !this.runCommand || !this.uniformStore) return
70
- if (!points.previousPositionTexture || points.previousPositionTexture.destroyed) return
71
- if (!renderPass && (!points.velocityFbo || points.velocityFbo.destroyed)) return
72
-
73
- this.uniformStore.setUniforms({
74
- forceGravityUniforms: {
75
- gravity: this.config.simulationGravity ?? 0,
76
- spaceSize: store.adjustedSpaceSize ?? 0,
77
- alpha: store.alpha,
78
- },
79
- })
80
-
81
- this.runCommand.setBindings({
82
- forceGravityUniforms: this.uniformStore.getManagedUniformBuffer(device, 'forceGravityUniforms'),
83
- positionsTexture: points.previousPositionTexture!,
84
- })
85
-
86
- const pass = renderPass ?? device.beginRenderPass({
87
- framebuffer: points.velocityFbo,
88
- })
89
-
90
- this.runCommand.draw(pass)
91
-
92
- if (!renderPass) pass.end()
93
- }
94
-
95
- public destroy (): void {
96
- this.uniformStore?.destroy()
97
- this.uniformStore = undefined
98
-
99
- if (this.runCommand && !this.runCommand.destroyed) this.runCommand.destroy()
100
- this.runCommand = undefined
101
-
102
- if (this.vertexCoordBuffer && !this.vertexCoordBuffer.destroyed) {
103
- this.vertexCoordBuffer.destroy()
104
- }
105
- this.vertexCoordBuffer = undefined
106
- }
107
- }