@cosmos.gl/graph 2.7.0-beta.0 → 2.7.0-beta.2
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-FUIgayhu.js → index-CSMQs8iI.js} +4920 -4871
- package/dist/index-CSMQs8iI.js.map +1 -0
- package/dist/index.js +1 -1
- package/dist/index.min.js +71 -74
- package/dist/index.min.js.map +1 -1
- package/dist/{config.d.ts → src/config.d.ts} +18 -21
- package/dist/{index.d.ts → src/index.d.ts} +77 -7
- package/dist/{modules → src/modules}/Clusters/index.d.ts +6 -7
- package/dist/{modules → src/modules}/ForceCenter/index.d.ts +5 -4
- package/dist/{modules → src/modules}/ForceGravity/index.d.ts +5 -2
- package/dist/{modules → src/modules}/ForceLink/index.d.ts +5 -2
- package/dist/{modules → src/modules}/ForceManyBody/index.d.ts +5 -4
- package/dist/{modules → src/modules}/ForceMouse/index.d.ts +5 -2
- package/dist/{modules → src/modules}/GraphData/index.d.ts +1 -0
- package/dist/{modules → src/modules}/Lines/index.d.ts +5 -0
- package/dist/{modules → src/modules}/Points/index.d.ts +6 -8
- package/dist/src/modules/Shared/buffer.d.ts +1 -0
- package/dist/src/modules/Shared/texture-utils.d.ts +8 -0
- package/dist/src/modules/Shared/uniform-utils.d.ts +11 -0
- package/dist/{modules → src/modules}/Store/index.d.ts +1 -0
- package/dist/{variables.d.ts → src/variables.d.ts} +0 -2
- package/dist/vite.config.d.ts +2 -0
- package/dist/{webgl-device-B9ewDj5L.js → webgl-device-QoBMYpnS.js} +204 -194
- package/dist/webgl-device-QoBMYpnS.js.map +1 -0
- package/package.json +9 -6
- package/.eslintrc +0 -147
- package/.github/SECURITY.md +0 -13
- package/.github/dco.yml +0 -4
- package/.github/workflows/github_pages.yml +0 -54
- package/.storybook/main.ts +0 -26
- package/.storybook/manager-head.html +0 -1
- package/.storybook/manager.ts +0 -14
- package/.storybook/preview.ts +0 -29
- package/.storybook/style.css +0 -3
- package/CHARTER.md +0 -69
- package/CODE_OF_CONDUCT.md +0 -178
- package/CONTRIBUTING.md +0 -22
- package/GOVERNANCE.md +0 -21
- package/cosmos-2-0-migration-notes.md +0 -98
- package/cosmos_awesome.md +0 -96
- package/dist/index-FUIgayhu.js.map +0 -1
- package/dist/modules/ForceManyBody/quadtree-frag-shader.d.ts +0 -1
- package/dist/modules/ForceManyBodyQuadtree/index.d.ts +0 -15
- package/dist/modules/ForceManyBodyQuadtree/quadtree-frag-shader.d.ts +0 -1
- package/dist/modules/Shared/buffer.d.ts +0 -8
- package/dist/stories/beginners/basic-set-up/data-gen.d.ts +0 -4
- package/dist/stories/beginners/basic-set-up/index.d.ts +0 -6
- package/dist/stories/beginners/link-hovering/data-generator.d.ts +0 -19
- package/dist/stories/beginners/link-hovering/index.d.ts +0 -6
- package/dist/stories/beginners/point-labels/data.d.ts +0 -13
- package/dist/stories/beginners/point-labels/index.d.ts +0 -10
- package/dist/stories/beginners/point-labels/labels.d.ts +0 -8
- package/dist/stories/beginners/quick-start.d.ts +0 -6
- package/dist/stories/beginners/remove-points/config.d.ts +0 -2
- package/dist/stories/beginners/remove-points/data-gen.d.ts +0 -4
- package/dist/stories/beginners/remove-points/index.d.ts +0 -6
- package/dist/stories/beginners.stories.d.ts +0 -10
- package/dist/stories/clusters/polygon-selection/index.d.ts +0 -6
- package/dist/stories/clusters/polygon-selection/polygon.d.ts +0 -20
- package/dist/stories/clusters/radial.d.ts +0 -6
- package/dist/stories/clusters/with-labels.d.ts +0 -6
- package/dist/stories/clusters/worm.d.ts +0 -6
- package/dist/stories/clusters.stories.d.ts +0 -9
- package/dist/stories/create-cluster-labels.d.ts +0 -4
- package/dist/stories/create-cosmos.d.ts +0 -17
- package/dist/stories/create-story.d.ts +0 -16
- package/dist/stories/experiments/full-mesh.d.ts +0 -6
- package/dist/stories/experiments/mesh-with-holes.d.ts +0 -6
- package/dist/stories/experiments.stories.d.ts +0 -7
- package/dist/stories/generate-mesh-data.d.ts +0 -12
- package/dist/stories/geospatial/moscow-metro-stations/index.d.ts +0 -16
- package/dist/stories/geospatial/moscow-metro-stations/moscow-metro-coords.d.ts +0 -1
- package/dist/stories/geospatial/moscow-metro-stations/point-colors.d.ts +0 -1
- package/dist/stories/geospatial.stories.d.ts +0 -6
- package/dist/stories/shapes/all-shapes/index.d.ts +0 -6
- package/dist/stories/shapes/image-example/index.d.ts +0 -6
- package/dist/stories/shapes.stories.d.ts +0 -7
- package/dist/stories/test-luma-migration.d.ts +0 -6
- package/dist/stories/test.stories.d.ts +0 -6
- package/dist/webgl-device-B9ewDj5L.js.map +0 -1
- package/logo.svg +0 -3
- package/rollup.config.js +0 -70
- package/src/config.ts +0 -728
- package/src/declaration.d.ts +0 -12
- package/src/graph/utils/error-message.ts +0 -23
- package/src/helper.ts +0 -113
- package/src/index.ts +0 -1769
- package/src/modules/Clusters/calculate-centermass.frag +0 -12
- package/src/modules/Clusters/calculate-centermass.vert +0 -38
- package/src/modules/Clusters/force-cluster.frag +0 -55
- package/src/modules/Clusters/index.ts +0 -578
- package/src/modules/Drag/index.ts +0 -33
- package/src/modules/FPSMonitor/css.ts +0 -53
- package/src/modules/FPSMonitor/index.ts +0 -28
- package/src/modules/ForceCenter/calculate-centermass.frag +0 -9
- package/src/modules/ForceCenter/calculate-centermass.vert +0 -26
- package/src/modules/ForceCenter/force-center.frag +0 -37
- package/src/modules/ForceCenter/index.ts +0 -284
- package/src/modules/ForceGravity/force-gravity.frag +0 -40
- package/src/modules/ForceGravity/index.ts +0 -107
- package/src/modules/ForceLink/force-spring.ts +0 -89
- package/src/modules/ForceLink/index.ts +0 -293
- package/src/modules/ForceManyBody/calculate-level.frag +0 -9
- package/src/modules/ForceManyBody/calculate-level.vert +0 -37
- package/src/modules/ForceManyBody/force-centermass.frag +0 -61
- package/src/modules/ForceManyBody/force-level.frag +0 -138
- package/src/modules/ForceManyBody/index.ts +0 -525
- package/src/modules/ForceManyBody/quadtree-frag-shader.ts +0 -89
- package/src/modules/ForceManyBodyQuadtree/calculate-level.frag +0 -9
- package/src/modules/ForceManyBodyQuadtree/calculate-level.vert +0 -25
- package/src/modules/ForceManyBodyQuadtree/index.ts +0 -157
- package/src/modules/ForceManyBodyQuadtree/quadtree-frag-shader.ts +0 -93
- package/src/modules/ForceMouse/force-mouse.frag +0 -35
- package/src/modules/ForceMouse/index.ts +0 -102
- package/src/modules/GraphData/index.ts +0 -383
- package/src/modules/Lines/draw-curve-line.frag +0 -59
- package/src/modules/Lines/draw-curve-line.vert +0 -248
- package/src/modules/Lines/geometry.ts +0 -18
- package/src/modules/Lines/hovered-line-index.frag +0 -43
- package/src/modules/Lines/hovered-line-index.vert +0 -13
- package/src/modules/Lines/index.ts +0 -661
- package/src/modules/Points/atlas-utils.ts +0 -137
- package/src/modules/Points/drag-point.frag +0 -34
- package/src/modules/Points/draw-highlighted.frag +0 -44
- package/src/modules/Points/draw-highlighted.vert +0 -145
- package/src/modules/Points/draw-points.frag +0 -259
- package/src/modules/Points/draw-points.vert +0 -203
- package/src/modules/Points/fill-sampled-points.frag +0 -12
- package/src/modules/Points/fill-sampled-points.vert +0 -51
- package/src/modules/Points/find-hovered-point.frag +0 -15
- package/src/modules/Points/find-hovered-point.vert +0 -90
- package/src/modules/Points/find-points-on-area-selection.frag +0 -88
- package/src/modules/Points/find-points-on-polygon-selection.frag +0 -89
- package/src/modules/Points/index.ts +0 -2292
- package/src/modules/Points/track-positions.frag +0 -30
- package/src/modules/Points/update-position.frag +0 -39
- package/src/modules/Shared/buffer.ts +0 -39
- package/src/modules/Shared/clear.frag +0 -10
- package/src/modules/Shared/quad.vert +0 -13
- package/src/modules/Store/index.ts +0 -283
- package/src/modules/Zoom/index.ts +0 -148
- package/src/modules/core-module.ts +0 -28
- package/src/stories/1. welcome.mdx +0 -75
- package/src/stories/2. configuration.mdx +0 -111
- package/src/stories/3. api-reference.mdx +0 -591
- package/src/stories/beginners/basic-set-up/data-gen.ts +0 -33
- package/src/stories/beginners/basic-set-up/index.ts +0 -167
- package/src/stories/beginners/basic-set-up/style.css +0 -35
- package/src/stories/beginners/link-hovering/data-generator.ts +0 -198
- package/src/stories/beginners/link-hovering/index.ts +0 -65
- package/src/stories/beginners/link-hovering/style.css +0 -73
- package/src/stories/beginners/point-labels/data.ts +0 -73
- package/src/stories/beginners/point-labels/index.ts +0 -69
- package/src/stories/beginners/point-labels/labels.ts +0 -46
- package/src/stories/beginners/point-labels/style.css +0 -16
- package/src/stories/beginners/quick-start.ts +0 -54
- package/src/stories/beginners/remove-points/config.ts +0 -25
- package/src/stories/beginners/remove-points/data-gen.ts +0 -30
- package/src/stories/beginners/remove-points/index.ts +0 -96
- package/src/stories/beginners/remove-points/style.css +0 -31
- package/src/stories/beginners.stories.ts +0 -130
- package/src/stories/clusters/polygon-selection/index.ts +0 -52
- package/src/stories/clusters/polygon-selection/polygon.ts +0 -143
- package/src/stories/clusters/polygon-selection/style.css +0 -8
- package/src/stories/clusters/radial.ts +0 -24
- package/src/stories/clusters/with-labels.ts +0 -54
- package/src/stories/clusters/worm.ts +0 -40
- package/src/stories/clusters.stories.ts +0 -77
- package/src/stories/create-cluster-labels.ts +0 -50
- package/src/stories/create-cosmos.ts +0 -72
- package/src/stories/create-story.ts +0 -51
- package/src/stories/experiments/full-mesh.ts +0 -13
- package/src/stories/experiments/mesh-with-holes.ts +0 -13
- package/src/stories/experiments.stories.ts +0 -43
- package/src/stories/generate-mesh-data.ts +0 -125
- package/src/stories/geospatial/moscow-metro-stations/index.ts +0 -66
- package/src/stories/geospatial/moscow-metro-stations/moscow-metro-coords.ts +0 -1
- package/src/stories/geospatial/moscow-metro-stations/point-colors.ts +0 -46
- package/src/stories/geospatial/moscow-metro-stations/style.css +0 -30
- package/src/stories/geospatial.stories.ts +0 -30
- package/src/stories/shapes/all-shapes/index.ts +0 -73
- package/src/stories/shapes/image-example/icons/box.png +0 -0
- package/src/stories/shapes/image-example/icons/lego.png +0 -0
- package/src/stories/shapes/image-example/icons/s.png +0 -0
- package/src/stories/shapes/image-example/icons/swift.png +0 -0
- package/src/stories/shapes/image-example/icons/toolbox.png +0 -0
- package/src/stories/shapes/image-example/index.ts +0 -246
- package/src/stories/shapes.stories.ts +0 -37
- package/src/stories/test-luma-migration.ts +0 -195
- package/src/stories/test.stories.ts +0 -25
- package/src/variables.ts +0 -68
- package/tsconfig.json +0 -41
- package/vite.config.ts +0 -52
- /package/dist/{graph → src/graph}/utils/error-message.d.ts +0 -0
- /package/dist/{helper.d.ts → src/helper.d.ts} +0 -0
- /package/dist/{modules → src/modules}/Drag/index.d.ts +0 -0
- /package/dist/{modules → src/modules}/FPSMonitor/css.d.ts +0 -0
- /package/dist/{modules → src/modules}/FPSMonitor/index.d.ts +0 -0
- /package/dist/{modules → src/modules}/ForceLink/force-spring.d.ts +0 -0
- /package/dist/{modules → src/modules}/Lines/geometry.d.ts +0 -0
- /package/dist/{modules → src/modules}/Points/atlas-utils.d.ts +0 -0
- /package/dist/{modules → src/modules}/Zoom/index.d.ts +0 -0
- /package/dist/{modules → src/modules}/core-module.d.ts +0 -0
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
import regl from 'regl'
|
|
2
|
-
import { CoreModule } from '@/graph/modules/core-module'
|
|
3
|
-
import calculateLevelFrag from '@/graph/modules/ForceManyBody/calculate-level.frag?raw'
|
|
4
|
-
import calculateLevelVert from '@/graph/modules/ForceManyBody/calculate-level.vert?raw'
|
|
5
|
-
import { forceFrag } from '@/graph/modules/ForceManyBody/quadtree-frag-shader'
|
|
6
|
-
import { createIndexesForBuffer, createQuadBuffer } from '@/graph/modules/Shared/buffer'
|
|
7
|
-
import clearFrag from '@/graph/modules/Shared/clear.frag?raw'
|
|
8
|
-
import updateVert from '@/graph/modules/Shared/quad.vert?raw'
|
|
9
|
-
|
|
10
|
-
export class ForceManyBodyQuadtree extends CoreModule {
|
|
11
|
-
private randomValuesFbo: regl.Framebuffer2D | undefined
|
|
12
|
-
private levelsTextures = new Map<string, regl.Texture2D>()
|
|
13
|
-
private levelsFbos = new Map<string, regl.Framebuffer2D>()
|
|
14
|
-
private clearLevelsCommand: regl.DrawCommand | undefined
|
|
15
|
-
private calculateLevelsCommand: regl.DrawCommand | undefined
|
|
16
|
-
private quadtreeCommand: regl.DrawCommand | undefined
|
|
17
|
-
private quadtreeLevels = 0
|
|
18
|
-
private randomValuesTexture: regl.Texture2D | undefined
|
|
19
|
-
private pointIndices: regl.Buffer | undefined
|
|
20
|
-
|
|
21
|
-
public create (): void {
|
|
22
|
-
const { reglInstance, store } = this
|
|
23
|
-
if (!store.pointsTextureSize) return
|
|
24
|
-
this.quadtreeLevels = Math.log2(store.adjustedSpaceSize)
|
|
25
|
-
for (let i = 0; i < this.quadtreeLevels; i += 1) {
|
|
26
|
-
const levelTextureSize = Math.pow(2, i + 1)
|
|
27
|
-
const levelKey = `level[${i}]`
|
|
28
|
-
if (!this.levelsTextures.has(levelKey)) {
|
|
29
|
-
this.levelsTextures.set(levelKey, reglInstance.texture())
|
|
30
|
-
}
|
|
31
|
-
const texture = this.levelsTextures.get(levelKey)
|
|
32
|
-
if (texture) {
|
|
33
|
-
texture({
|
|
34
|
-
data: new Float32Array(levelTextureSize * levelTextureSize * 4),
|
|
35
|
-
shape: [levelTextureSize, levelTextureSize, 4],
|
|
36
|
-
type: 'float',
|
|
37
|
-
})
|
|
38
|
-
}
|
|
39
|
-
if (!this.levelsFbos.has(levelKey)) {
|
|
40
|
-
this.levelsFbos.set(levelKey, reglInstance.framebuffer())
|
|
41
|
-
}
|
|
42
|
-
const fbo = this.levelsFbos.get(levelKey)
|
|
43
|
-
if (fbo) {
|
|
44
|
-
fbo({
|
|
45
|
-
color: this.levelsTextures.get(levelKey),
|
|
46
|
-
depth: false,
|
|
47
|
-
stencil: false,
|
|
48
|
-
})
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// Create random number to prevent point to stick together in one coordinate
|
|
53
|
-
const randomValuesState = new Float32Array(store.pointsTextureSize * store.pointsTextureSize * 4)
|
|
54
|
-
for (let i = 0; i < store.pointsTextureSize * store.pointsTextureSize; ++i) {
|
|
55
|
-
randomValuesState[i * 4] = store.getRandomFloat(-1, 1) * 0.00001
|
|
56
|
-
randomValuesState[i * 4 + 1] = store.getRandomFloat(-1, 1) * 0.00001
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if (!this.randomValuesTexture) this.randomValuesTexture = reglInstance.texture()
|
|
60
|
-
this.randomValuesTexture({
|
|
61
|
-
data: randomValuesState,
|
|
62
|
-
shape: [store.pointsTextureSize, store.pointsTextureSize, 4],
|
|
63
|
-
type: 'float',
|
|
64
|
-
})
|
|
65
|
-
if (!this.randomValuesFbo) this.randomValuesFbo = reglInstance.framebuffer()
|
|
66
|
-
this.randomValuesFbo({
|
|
67
|
-
color: this.randomValuesTexture,
|
|
68
|
-
depth: false,
|
|
69
|
-
stencil: false,
|
|
70
|
-
})
|
|
71
|
-
|
|
72
|
-
if (!this.pointIndices) this.pointIndices = reglInstance.buffer(0)
|
|
73
|
-
this.pointIndices(createIndexesForBuffer(store.pointsTextureSize))
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
public initPrograms (): void {
|
|
77
|
-
const { reglInstance, config, store, data, points } = this
|
|
78
|
-
if (!this.clearLevelsCommand) {
|
|
79
|
-
this.clearLevelsCommand = reglInstance({
|
|
80
|
-
frag: clearFrag,
|
|
81
|
-
vert: updateVert,
|
|
82
|
-
framebuffer: (_: regl.DefaultContext, props: { levelFbo: regl.Framebuffer2D }) => props.levelFbo,
|
|
83
|
-
primitive: 'triangle strip',
|
|
84
|
-
count: 4,
|
|
85
|
-
attributes: { vertexCoord: createQuadBuffer(reglInstance) },
|
|
86
|
-
})
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
if (!this.calculateLevelsCommand) {
|
|
90
|
-
this.calculateLevelsCommand = reglInstance({
|
|
91
|
-
frag: calculateLevelFrag,
|
|
92
|
-
vert: calculateLevelVert,
|
|
93
|
-
framebuffer: (_: regl.DefaultContext, props: { levelFbo: regl.Framebuffer2D; levelTextureSize: number; cellSize: number }) => props.levelFbo,
|
|
94
|
-
primitive: 'points',
|
|
95
|
-
count: () => data.pointsNumber ?? 0,
|
|
96
|
-
attributes: {
|
|
97
|
-
pointIndices: {
|
|
98
|
-
buffer: this.pointIndices,
|
|
99
|
-
size: 2,
|
|
100
|
-
},
|
|
101
|
-
},
|
|
102
|
-
uniforms: {
|
|
103
|
-
positionsTexture: () => points?.previousPositionFbo,
|
|
104
|
-
pointsTextureSize: () => store.pointsTextureSize,
|
|
105
|
-
levelTextureSize: (_: regl.DefaultContext, props: { levelTextureSize: number }) => props.levelTextureSize,
|
|
106
|
-
cellSize: (_: regl.DefaultContext, props: { cellSize: number }) => props.cellSize,
|
|
107
|
-
},
|
|
108
|
-
blend: {
|
|
109
|
-
enable: true,
|
|
110
|
-
func: {
|
|
111
|
-
src: 'one',
|
|
112
|
-
dst: 'one',
|
|
113
|
-
},
|
|
114
|
-
equation: {
|
|
115
|
-
rgb: 'add',
|
|
116
|
-
alpha: 'add',
|
|
117
|
-
},
|
|
118
|
-
},
|
|
119
|
-
depth: { enable: false, mask: false },
|
|
120
|
-
stencil: { enable: false },
|
|
121
|
-
})
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
this.quadtreeCommand = reglInstance({
|
|
125
|
-
frag: forceFrag(config.simulationRepulsionQuadtreeLevels ?? this.quadtreeLevels, this.quadtreeLevels),
|
|
126
|
-
vert: updateVert,
|
|
127
|
-
framebuffer: () => points?.velocityFbo as regl.Framebuffer2D,
|
|
128
|
-
primitive: 'triangle strip',
|
|
129
|
-
count: 4,
|
|
130
|
-
attributes: { vertexCoord: createQuadBuffer(reglInstance) },
|
|
131
|
-
uniforms: {
|
|
132
|
-
positionsTexture: () => points?.previousPositionFbo,
|
|
133
|
-
randomValues: () => this.randomValuesFbo,
|
|
134
|
-
spaceSize: () => store.adjustedSpaceSize,
|
|
135
|
-
repulsion: () => config.simulationRepulsion,
|
|
136
|
-
theta: () => config.simulationRepulsionTheta,
|
|
137
|
-
alpha: () => store.alpha,
|
|
138
|
-
...Object.fromEntries(this.levelsFbos),
|
|
139
|
-
},
|
|
140
|
-
})
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
public run (): void {
|
|
144
|
-
const { store } = this
|
|
145
|
-
for (let i = 0; i < this.quadtreeLevels; i += 1) {
|
|
146
|
-
this.clearLevelsCommand?.({ levelFbo: this.levelsFbos.get(`level[${i}]`) })
|
|
147
|
-
const levelTextureSize = Math.pow(2, i + 1)
|
|
148
|
-
const cellSize = store.adjustedSpaceSize / levelTextureSize
|
|
149
|
-
this.calculateLevelsCommand?.({
|
|
150
|
-
levelFbo: this.levelsFbos.get(`level[${i}]`),
|
|
151
|
-
levelTextureSize,
|
|
152
|
-
cellSize,
|
|
153
|
-
})
|
|
154
|
-
}
|
|
155
|
-
this.quadtreeCommand?.()
|
|
156
|
-
}
|
|
157
|
-
}
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
/* The fragment shader calculates the velocity of a point based on its position,
|
|
2
|
-
* the positions of other points in a spatial hierarchy, and random factors.
|
|
3
|
-
**/
|
|
4
|
-
export function forceFrag (startLevel: number, maxLevels: number): string {
|
|
5
|
-
startLevel = Math.min(startLevel, maxLevels)
|
|
6
|
-
const delta = maxLevels - startLevel
|
|
7
|
-
const calculateVelocityAdjustment = `
|
|
8
|
-
float dist = sqrt(l);
|
|
9
|
-
if (dist > 0.0) {
|
|
10
|
-
float c = alpha * repulsion * centermass.b;
|
|
11
|
-
addVelocity += calculateAdditionalVelocity(vec2(x, y), l, c);
|
|
12
|
-
addVelocity += addVelocity * random.rg;
|
|
13
|
-
}
|
|
14
|
-
`
|
|
15
|
-
function quad (level: number): string {
|
|
16
|
-
if (level >= maxLevels) {
|
|
17
|
-
return calculateVelocityAdjustment
|
|
18
|
-
} else {
|
|
19
|
-
const groupSize = Math.pow(2, level + 1)
|
|
20
|
-
|
|
21
|
-
const iEnding = new Array(level + 1 - delta).fill(0).map((_, l) => `pow(2.0, ${level - (l + delta)}.0) * i${l + delta}`).join('+')
|
|
22
|
-
const jEnding = new Array(level + 1 - delta).fill(0).map((_, l) => `pow(2.0, ${level - (l + delta)}.0) * j${l + delta}`).join('+')
|
|
23
|
-
|
|
24
|
-
return `
|
|
25
|
-
for (float ij${level} = 0.0; ij${level} < 4.0; ij${level} += 1.0) {
|
|
26
|
-
float i${level} = 0.0;
|
|
27
|
-
float j${level} = 0.0;
|
|
28
|
-
if (ij${level} == 1.0 || ij${level} == 3.0) i${level} = 1.0;
|
|
29
|
-
if (ij${level} == 2.0 || ij${level} == 3.0) j${level} = 1.0;
|
|
30
|
-
float i = pow(2.0, ${startLevel}.0) * n / width${level + 1} + ${iEnding};
|
|
31
|
-
float j = pow(2.0, ${startLevel}.0) * m / width${level + 1} + ${jEnding};
|
|
32
|
-
float groupPosX = (i + 0.5) / ${groupSize}.0;
|
|
33
|
-
float groupPosY = (j + 0.5) / ${groupSize}.0;
|
|
34
|
-
|
|
35
|
-
vec4 centermass = texture2D(level[${level}], vec2(groupPosX, groupPosY));
|
|
36
|
-
if (centermass.r > 0.0 && centermass.g > 0.0 && centermass.b > 0.0) {
|
|
37
|
-
float x = centermass.r / centermass.b - pointPosition.r;
|
|
38
|
-
float y = centermass.g / centermass.b - pointPosition.g;
|
|
39
|
-
float l = x * x + y * y;
|
|
40
|
-
if ((width${level + 1} * width${level + 1}) / theta < l) {
|
|
41
|
-
${calculateVelocityAdjustment}
|
|
42
|
-
} else {
|
|
43
|
-
${quad(level + 1)}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
`
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
return `
|
|
51
|
-
#ifdef GL_ES
|
|
52
|
-
precision highp float;
|
|
53
|
-
#endif
|
|
54
|
-
|
|
55
|
-
uniform sampler2D positionsTexture;
|
|
56
|
-
uniform sampler2D randomValues;
|
|
57
|
-
uniform float spaceSize;
|
|
58
|
-
uniform float repulsion;
|
|
59
|
-
uniform float theta;
|
|
60
|
-
uniform float alpha;
|
|
61
|
-
uniform sampler2D level[${maxLevels}];
|
|
62
|
-
varying vec2 textureCoords;
|
|
63
|
-
|
|
64
|
-
vec2 calculateAdditionalVelocity(vec2 xy, float l, float c) {
|
|
65
|
-
float distanceMin2 = 1.0;
|
|
66
|
-
if (l < distanceMin2) l = sqrt(distanceMin2 * l);
|
|
67
|
-
float add = c / l;
|
|
68
|
-
return add * xy;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
void main() {
|
|
72
|
-
vec4 pointPosition = texture2D(positionsTexture, textureCoords);
|
|
73
|
-
vec4 random = texture2D(randomValues, textureCoords);
|
|
74
|
-
|
|
75
|
-
float width0 = spaceSize;
|
|
76
|
-
|
|
77
|
-
vec2 velocity = vec2(0.0);
|
|
78
|
-
vec2 addVelocity = vec2(0.0);
|
|
79
|
-
|
|
80
|
-
${new Array(maxLevels).fill(0).map((_, i) => `float width${i + 1} = width${i} / 2.0;`).join('\n')}
|
|
81
|
-
|
|
82
|
-
for (float n = 0.0; n < pow(2.0, ${delta}.0); n += 1.0) {
|
|
83
|
-
for (float m = 0.0; m < pow(2.0, ${delta}.0); m += 1.0) {
|
|
84
|
-
${quad(delta)}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
velocity -= addVelocity;
|
|
89
|
-
|
|
90
|
-
gl_FragColor = vec4(velocity, 0.0, 0.0);
|
|
91
|
-
}
|
|
92
|
-
`
|
|
93
|
-
}
|
|
@@ -1,35 +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 forceMouseUniforms {
|
|
8
|
-
float repulsion;
|
|
9
|
-
vec2 mousePos;
|
|
10
|
-
} forceMouse;
|
|
11
|
-
|
|
12
|
-
#define repulsion forceMouse.repulsion
|
|
13
|
-
#define mousePos forceMouse.mousePos
|
|
14
|
-
#else
|
|
15
|
-
uniform float repulsion;
|
|
16
|
-
uniform vec2 mousePos;
|
|
17
|
-
#endif
|
|
18
|
-
|
|
19
|
-
in vec2 textureCoords;
|
|
20
|
-
out vec4 fragColor;
|
|
21
|
-
|
|
22
|
-
void main() {
|
|
23
|
-
vec4 pointPosition = texture(positionsTexture, textureCoords);
|
|
24
|
-
vec4 velocity = vec4(0.0);
|
|
25
|
-
vec2 mouse = mousePos;
|
|
26
|
-
// Move particles away from the mouse position using a repulsive force
|
|
27
|
-
vec2 distVector = mouse - pointPosition.rg;
|
|
28
|
-
float dist = sqrt(dot(distVector, distVector));
|
|
29
|
-
dist = max(dist, 10.0);
|
|
30
|
-
float angle = atan(distVector.y, distVector.x);
|
|
31
|
-
float addV = 100.0 * repulsion / (dist * dist);
|
|
32
|
-
velocity.rg -= addV * vec2(cos(angle), sin(angle));
|
|
33
|
-
|
|
34
|
-
fragColor = velocity;
|
|
35
|
-
}
|
|
@@ -1,102 +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/ForceMouse/force-mouse.frag?raw'
|
|
5
|
-
import updateVert from '@/graph/modules/Shared/quad.vert?raw'
|
|
6
|
-
|
|
7
|
-
export class ForceMouse extends CoreModule {
|
|
8
|
-
private runCommand: Model | undefined
|
|
9
|
-
private vertexCoordBuffer: Buffer | undefined
|
|
10
|
-
private uniformStore: UniformStore<{
|
|
11
|
-
forceMouseUniforms: {
|
|
12
|
-
repulsion: number;
|
|
13
|
-
mousePos: [number, number];
|
|
14
|
-
};
|
|
15
|
-
}> | undefined
|
|
16
|
-
|
|
17
|
-
public initPrograms (): void {
|
|
18
|
-
const { device, points } = this
|
|
19
|
-
if (!points) return
|
|
20
|
-
|
|
21
|
-
if (!this.vertexCoordBuffer || this.vertexCoordBuffer.destroyed) {
|
|
22
|
-
this.vertexCoordBuffer = device.createBuffer({
|
|
23
|
-
data: new Float32Array([-1, -1, 1, -1, -1, 1, 1, 1]),
|
|
24
|
-
})
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
if (!this.uniformStore) {
|
|
28
|
-
this.uniformStore = new UniformStore({
|
|
29
|
-
forceMouseUniforms: {
|
|
30
|
-
uniformTypes: {
|
|
31
|
-
repulsion: 'f32',
|
|
32
|
-
mousePos: 'vec2<f32>',
|
|
33
|
-
},
|
|
34
|
-
},
|
|
35
|
-
})
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
if (!this.runCommand) {
|
|
39
|
-
this.runCommand = new Model(device, {
|
|
40
|
-
fs: forceFrag,
|
|
41
|
-
vs: updateVert,
|
|
42
|
-
topology: 'triangle-strip',
|
|
43
|
-
vertexCount: 4,
|
|
44
|
-
attributes: {
|
|
45
|
-
vertexCoord: this.vertexCoordBuffer,
|
|
46
|
-
},
|
|
47
|
-
bufferLayout: [
|
|
48
|
-
{ name: 'vertexCoord', format: 'float32x2' },
|
|
49
|
-
],
|
|
50
|
-
defines: {
|
|
51
|
-
USE_UNIFORM_BUFFERS: true,
|
|
52
|
-
},
|
|
53
|
-
bindings: {
|
|
54
|
-
forceMouseUniforms: this.uniformStore.getManagedUniformBuffer(device, 'forceMouseUniforms'),
|
|
55
|
-
positionsTexture: points.previousPositionTexture!,
|
|
56
|
-
},
|
|
57
|
-
parameters: {
|
|
58
|
-
depthWriteEnabled: false,
|
|
59
|
-
depthCompare: 'always',
|
|
60
|
-
},
|
|
61
|
-
})
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
public run (renderPass?: RenderPass): void {
|
|
66
|
-
const { device, points, store } = this
|
|
67
|
-
if (!points || !this.runCommand || !this.uniformStore) return
|
|
68
|
-
if (!points.previousPositionTexture || points.previousPositionTexture.destroyed) return
|
|
69
|
-
if (!renderPass && (!points.velocityFbo || points.velocityFbo.destroyed)) return
|
|
70
|
-
|
|
71
|
-
this.uniformStore.setUniforms({
|
|
72
|
-
forceMouseUniforms: {
|
|
73
|
-
repulsion: this.config.simulationRepulsionFromMouse ?? 0,
|
|
74
|
-
mousePos: [store.mousePosition[0] ?? 0, store.mousePosition[1] ?? 0],
|
|
75
|
-
},
|
|
76
|
-
})
|
|
77
|
-
|
|
78
|
-
this.runCommand.setBindings({
|
|
79
|
-
forceMouseUniforms: this.uniformStore.getManagedUniformBuffer(device, 'forceMouseUniforms'),
|
|
80
|
-
positionsTexture: points.previousPositionTexture!,
|
|
81
|
-
})
|
|
82
|
-
|
|
83
|
-
const pass = renderPass ?? device.beginRenderPass({
|
|
84
|
-
framebuffer: points.velocityFbo,
|
|
85
|
-
})
|
|
86
|
-
|
|
87
|
-
this.runCommand.draw(pass)
|
|
88
|
-
|
|
89
|
-
if (!renderPass) pass.end()
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
public destroy (): void {
|
|
93
|
-
this.uniformStore?.destroy()
|
|
94
|
-
this.uniformStore = undefined
|
|
95
|
-
|
|
96
|
-
this.runCommand?.destroy()
|
|
97
|
-
this.runCommand = undefined
|
|
98
|
-
|
|
99
|
-
if (this.vertexCoordBuffer && !this.vertexCoordBuffer.destroyed) this.vertexCoordBuffer.destroy()
|
|
100
|
-
this.vertexCoordBuffer = undefined
|
|
101
|
-
}
|
|
102
|
-
}
|