@antv/layout 0.3.12 → 1.0.0-alpha.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.
- package/README.md +45 -32
- package/dist/3a54d760230d1933f953.worker.js +2 -0
- package/dist/3a54d760230d1933f953.worker.js.map +1 -0
- package/dist/index.min.js +2 -0
- package/dist/index.min.js.map +1 -0
- package/lib/Circular.d.ts +40 -0
- package/lib/Supervisor.d.ts +65 -0
- package/lib/index.d.ts +4 -3
- package/lib/registry.d.ts +3 -0
- package/lib/types.d.ts +128 -0
- package/lib/util/gpu.d.ts +22 -22
- package/lib/util/index.d.ts +6 -6
- package/lib/util/math.d.ts +3 -3
- package/lib/worker.d.ts +3 -0
- package/package.json +21 -95
- package/dist/layout.min.js +0 -3
- package/dist/layout.min.js.LICENSE.txt +0 -1
- package/dist/layout.min.js.map +0 -1
- package/es/index.d.ts +0 -3
- package/es/index.js +0 -6
- package/es/index.js.map +0 -1
- package/es/layout/base.d.ts +0 -22
- package/es/layout/base.js +0 -51
- package/es/layout/base.js.map +0 -1
- package/es/layout/circular.d.ts +0 -80
- package/es/layout/circular.js +0 -314
- package/es/layout/circular.js.map +0 -1
- package/es/layout/comboCombined.d.ts +0 -54
- package/es/layout/comboCombined.js +0 -354
- package/es/layout/comboCombined.js.map +0 -1
- package/es/layout/comboForce.d.ts +0 -134
- package/es/layout/comboForce.js +0 -801
- package/es/layout/comboForce.js.map +0 -1
- package/es/layout/concentric.d.ts +0 -67
- package/es/layout/concentric.js +0 -219
- package/es/layout/concentric.js.map +0 -1
- package/es/layout/constants.d.ts +0 -12
- package/es/layout/constants.js +0 -22
- package/es/layout/constants.js.map +0 -1
- package/es/layout/dagre/graph.d.ts +0 -91
- package/es/layout/dagre/graph.js +0 -4
- package/es/layout/dagre/graph.js.map +0 -1
- package/es/layout/dagre/index.d.ts +0 -8
- package/es/layout/dagre/index.js +0 -31
- package/es/layout/dagre/index.js.map +0 -1
- package/es/layout/dagre/src/acyclic.d.ts +0 -6
- package/es/layout/dagre/src/acyclic.js +0 -52
- package/es/layout/dagre/src/acyclic.js.map +0 -1
- package/es/layout/dagre/src/add-border-segments.d.ts +0 -3
- package/es/layout/dagre/src/add-border-segments.js +0 -32
- package/es/layout/dagre/src/add-border-segments.js.map +0 -1
- package/es/layout/dagre/src/coordinate-system.d.ts +0 -6
- package/es/layout/dagre/src/coordinate-system.js +0 -69
- package/es/layout/dagre/src/coordinate-system.js.map +0 -1
- package/es/layout/dagre/src/data/list.d.ts +0 -12
- package/es/layout/dagre/src/data/list.js +0 -48
- package/es/layout/dagre/src/data/list.js.map +0 -1
- package/es/layout/dagre/src/debug.d.ts +0 -3
- package/es/layout/dagre/src/debug.js +0 -24
- package/es/layout/dagre/src/debug.js.map +0 -1
- package/es/layout/dagre/src/greedy-fas.d.ts +0 -3
- package/es/layout/dagre/src/greedy-fas.js +0 -114
- package/es/layout/dagre/src/greedy-fas.js.map +0 -1
- package/es/layout/dagre/src/layout.d.ts +0 -3
- package/es/layout/dagre/src/layout.js +0 -518
- package/es/layout/dagre/src/layout.js.map +0 -1
- package/es/layout/dagre/src/nesting-graph.d.ts +0 -6
- package/es/layout/dagre/src/nesting-graph.js +0 -117
- package/es/layout/dagre/src/nesting-graph.js.map +0 -1
- package/es/layout/dagre/src/normalize.d.ts +0 -6
- package/es/layout/dagre/src/normalize.js +0 -89
- package/es/layout/dagre/src/normalize.js.map +0 -1
- package/es/layout/dagre/src/order/add-subgraph-constraints.d.ts +0 -3
- package/es/layout/dagre/src/order/add-subgraph-constraints.js +0 -27
- package/es/layout/dagre/src/order/add-subgraph-constraints.js.map +0 -1
- package/es/layout/dagre/src/order/barycenter.d.ts +0 -11
- package/es/layout/dagre/src/order/barycenter.js +0 -24
- package/es/layout/dagre/src/order/barycenter.js.map +0 -1
- package/es/layout/dagre/src/order/build-layer-graph.d.ts +0 -3
- package/es/layout/dagre/src/order/build-layer-graph.js +0 -71
- package/es/layout/dagre/src/order/build-layer-graph.js.map +0 -1
- package/es/layout/dagre/src/order/cross-count.d.ts +0 -3
- package/es/layout/dagre/src/order/cross-count.js +0 -65
- package/es/layout/dagre/src/order/cross-count.js.map +0 -1
- package/es/layout/dagre/src/order/index.d.ts +0 -3
- package/es/layout/dagre/src/order/index.js +0 -91
- package/es/layout/dagre/src/order/index.js.map +0 -1
- package/es/layout/dagre/src/order/init-data-order.d.ts +0 -6
- package/es/layout/dagre/src/order/init-data-order.js +0 -25
- package/es/layout/dagre/src/order/init-data-order.js.map +0 -1
- package/es/layout/dagre/src/order/init-order.d.ts +0 -3
- package/es/layout/dagre/src/order/init-order.js +0 -52
- package/es/layout/dagre/src/order/init-order.js.map +0 -1
- package/es/layout/dagre/src/order/resolve-conflicts.d.ts +0 -19
- package/es/layout/dagre/src/order/resolve-conflicts.js +0 -93
- package/es/layout/dagre/src/order/resolve-conflicts.js.map +0 -1
- package/es/layout/dagre/src/order/sort-subgraph.d.ts +0 -7
- package/es/layout/dagre/src/order/sort-subgraph.js +0 -85
- package/es/layout/dagre/src/order/sort-subgraph.js.map +0 -1
- package/es/layout/dagre/src/order/sort.d.ts +0 -7
- package/es/layout/dagre/src/order/sort.js +0 -68
- package/es/layout/dagre/src/order/sort.js.map +0 -1
- package/es/layout/dagre/src/parent-dummy-chains.d.ts +0 -3
- package/es/layout/dagre/src/parent-dummy-chains.js +0 -81
- package/es/layout/dagre/src/parent-dummy-chains.js.map +0 -1
- package/es/layout/dagre/src/position/bk.d.ts +0 -23
- package/es/layout/dagre/src/position/bk.js +0 -370
- package/es/layout/dagre/src/position/bk.js.map +0 -1
- package/es/layout/dagre/src/position/index.d.ts +0 -3
- package/es/layout/dagre/src/position/index.js +0 -51
- package/es/layout/dagre/src/position/index.js.map +0 -1
- package/es/layout/dagre/src/rank/feasible-tree.d.ts +0 -9
- package/es/layout/dagre/src/rank/feasible-tree.js +0 -148
- package/es/layout/dagre/src/rank/feasible-tree.js.map +0 -1
- package/es/layout/dagre/src/rank/index.d.ts +0 -3
- package/es/layout/dagre/src/rank/index.js +0 -53
- package/es/layout/dagre/src/rank/index.js.map +0 -1
- package/es/layout/dagre/src/rank/network-simplex.d.ts +0 -9
- package/es/layout/dagre/src/rank/network-simplex.js +0 -195
- package/es/layout/dagre/src/rank/network-simplex.js.map +0 -1
- package/es/layout/dagre/src/rank/util.d.ts +0 -11
- package/es/layout/dagre/src/rank/util.js +0 -141
- package/es/layout/dagre/src/rank/util.js.map +0 -1
- package/es/layout/dagre/src/util.d.ts +0 -31
- package/es/layout/dagre/src/util.js +0 -261
- package/es/layout/dagre/src/util.js.map +0 -1
- package/es/layout/dagre.d.ts +0 -71
- package/es/layout/dagre.js +0 -433
- package/es/layout/dagre.js.map +0 -1
- package/es/layout/dagreCompound.d.ts +0 -121
- package/es/layout/dagreCompound.js +0 -391
- package/es/layout/dagreCompound.js.map +0 -1
- package/es/layout/er/core.d.ts +0 -1
- package/es/layout/er/core.js +0 -107
- package/es/layout/er/core.js.map +0 -1
- package/es/layout/er/forceGrid.d.ts +0 -8
- package/es/layout/er/forceGrid.js +0 -88
- package/es/layout/er/forceGrid.js.map +0 -1
- package/es/layout/er/grid.d.ts +0 -26
- package/es/layout/er/grid.js +0 -162
- package/es/layout/er/grid.js.map +0 -1
- package/es/layout/er/index.d.ts +0 -29
- package/es/layout/er/index.js +0 -54
- package/es/layout/er/index.js.map +0 -1
- package/es/layout/er/mysqlWorkbench.d.ts +0 -6
- package/es/layout/er/mysqlWorkbench.js +0 -324
- package/es/layout/er/mysqlWorkbench.js.map +0 -1
- package/es/layout/er/type.d.ts +0 -35
- package/es/layout/er/type.js +0 -2
- package/es/layout/er/type.js.map +0 -1
- package/es/layout/force/force-in-a-box.d.ts +0 -28
- package/es/layout/force/force-in-a-box.js +0 -330
- package/es/layout/force/force-in-a-box.js.map +0 -1
- package/es/layout/force/force.d.ts +0 -100
- package/es/layout/force/force.js +0 -340
- package/es/layout/force/force.js.map +0 -1
- package/es/layout/force/index.d.ts +0 -1
- package/es/layout/force/index.js +0 -2
- package/es/layout/force/index.js.map +0 -1
- package/es/layout/force2/ForceNBody.d.ts +0 -7
- package/es/layout/force2/ForceNBody.js +0 -94
- package/es/layout/force2/ForceNBody.js.map +0 -1
- package/es/layout/force2/index.d.ts +0 -119
- package/es/layout/force2/index.js +0 -608
- package/es/layout/force2/index.js.map +0 -1
- package/es/layout/forceAtlas2/body.d.ts +0 -33
- package/es/layout/forceAtlas2/body.js +0 -89
- package/es/layout/forceAtlas2/body.js.map +0 -1
- package/es/layout/forceAtlas2/index.d.ts +0 -115
- package/es/layout/forceAtlas2/index.js +0 -484
- package/es/layout/forceAtlas2/index.js.map +0 -1
- package/es/layout/forceAtlas2/quad.d.ts +0 -27
- package/es/layout/forceAtlas2/quad.js +0 -96
- package/es/layout/forceAtlas2/quad.js.map +0 -1
- package/es/layout/forceAtlas2/quadTree.d.ts +0 -20
- package/es/layout/forceAtlas2/quadTree.js +0 -103
- package/es/layout/forceAtlas2/quadTree.js.map +0 -1
- package/es/layout/fruchterman.d.ts +0 -73
- package/es/layout/fruchterman.js +0 -296
- package/es/layout/fruchterman.js.map +0 -1
- package/es/layout/gForce.d.ts +0 -96
- package/es/layout/gForce.js +0 -399
- package/es/layout/gForce.js.map +0 -1
- package/es/layout/gpu/fruchterman.d.ts +0 -57
- package/es/layout/gpu/fruchterman.js +0 -267
- package/es/layout/gpu/fruchterman.js.map +0 -1
- package/es/layout/gpu/fruchtermanShader.d.ts +0 -4
- package/es/layout/gpu/fruchtermanShader.js +0 -201
- package/es/layout/gpu/fruchtermanShader.js.map +0 -1
- package/es/layout/gpu/gForce.d.ts +0 -68
- package/es/layout/gpu/gForce.js +0 -330
- package/es/layout/gpu/gForce.js.map +0 -1
- package/es/layout/gpu/gForceShader.d.ts +0 -4
- package/es/layout/gpu/gForceShader.js +0 -218
- package/es/layout/gpu/gForceShader.js.map +0 -1
- package/es/layout/grid.d.ts +0 -83
- package/es/layout/grid.js +0 -317
- package/es/layout/grid.js.map +0 -1
- package/es/layout/index.d.ts +0 -22
- package/es/layout/index.js +0 -25
- package/es/layout/index.js.map +0 -1
- package/es/layout/layout.d.ts +0 -26
- package/es/layout/layout.js +0 -97
- package/es/layout/layout.js.map +0 -1
- package/es/layout/mds.d.ts +0 -39
- package/es/layout/mds.js +0 -122
- package/es/layout/mds.js.map +0 -1
- package/es/layout/radial/index.d.ts +0 -1
- package/es/layout/radial/index.js +0 -2
- package/es/layout/radial/index.js.map +0 -1
- package/es/layout/radial/mds.d.ts +0 -15
- package/es/layout/radial/mds.js +0 -38
- package/es/layout/radial/mds.js.map +0 -1
- package/es/layout/radial/radial.d.ts +0 -74
- package/es/layout/radial/radial.js +0 -420
- package/es/layout/radial/radial.js.map +0 -1
- package/es/layout/radial/radialNonoverlapForce.d.ts +0 -50
- package/es/layout/radial/radialNonoverlapForce.js +0 -123
- package/es/layout/radial/radialNonoverlapForce.js.map +0 -1
- package/es/layout/random.d.ts +0 -35
- package/es/layout/random.js +0 -62
- package/es/layout/random.js.map +0 -1
- package/es/layout/types.d.ts +0 -432
- package/es/layout/types.js +0 -2
- package/es/layout/types.js.map +0 -1
- package/es/registy/index.d.ts +0 -3
- package/es/registy/index.js +0 -41
- package/es/registy/index.js.map +0 -1
- package/es/util/array.d.ts +0 -1
- package/es/util/array.js +0 -2
- package/es/util/array.js.map +0 -1
- package/es/util/function.d.ts +0 -6
- package/es/util/function.js +0 -56
- package/es/util/function.js.map +0 -1
- package/es/util/gpu.d.ts +0 -52
- package/es/util/gpu.js +0 -239
- package/es/util/gpu.js.map +0 -1
- package/es/util/index.d.ts +0 -6
- package/es/util/index.js +0 -7
- package/es/util/index.js.map +0 -1
- package/es/util/math.d.ts +0 -48
- package/es/util/math.js +0 -276
- package/es/util/math.js.map +0 -1
- package/es/util/number.d.ts +0 -3
- package/es/util/number.js +0 -7
- package/es/util/number.js.map +0 -1
- package/es/util/object.d.ts +0 -2
- package/es/util/object.js +0 -25
- package/es/util/object.js.map +0 -1
- package/es/util/string.d.ts +0 -2
- package/es/util/string.js +0 -16
- package/es/util/string.js.map +0 -1
- package/lib/index.js +0 -24
- package/lib/index.js.map +0 -1
- package/lib/layout/base.d.ts +0 -22
- package/lib/layout/base.js +0 -56
- package/lib/layout/base.js.map +0 -1
- package/lib/layout/circular.d.ts +0 -80
- package/lib/layout/circular.js +0 -337
- package/lib/layout/circular.js.map +0 -1
- package/lib/layout/comboCombined.d.ts +0 -54
- package/lib/layout/comboCombined.js +0 -390
- package/lib/layout/comboCombined.js.map +0 -1
- package/lib/layout/comboForce.d.ts +0 -134
- package/lib/layout/comboForce.js +0 -826
- package/lib/layout/comboForce.js.map +0 -1
- package/lib/layout/concentric.d.ts +0 -67
- package/lib/layout/concentric.js +0 -243
- package/lib/layout/concentric.js.map +0 -1
- package/lib/layout/constants.d.ts +0 -12
- package/lib/layout/constants.js +0 -25
- package/lib/layout/constants.js.map +0 -1
- package/lib/layout/dagre/graph.d.ts +0 -91
- package/lib/layout/dagre/graph.js +0 -28
- package/lib/layout/dagre/graph.js.map +0 -1
- package/lib/layout/dagre/index.d.ts +0 -8
- package/lib/layout/dagre/index.js +0 -36
- package/lib/layout/dagre/index.js.map +0 -1
- package/lib/layout/dagre/src/acyclic.d.ts +0 -6
- package/lib/layout/dagre/src/acyclic.js +0 -57
- package/lib/layout/dagre/src/acyclic.js.map +0 -1
- package/lib/layout/dagre/src/add-border-segments.d.ts +0 -3
- package/lib/layout/dagre/src/add-border-segments.js +0 -34
- package/lib/layout/dagre/src/add-border-segments.js.map +0 -1
- package/lib/layout/dagre/src/coordinate-system.d.ts +0 -6
- package/lib/layout/dagre/src/coordinate-system.js +0 -71
- package/lib/layout/dagre/src/coordinate-system.js.map +0 -1
- package/lib/layout/dagre/src/data/list.d.ts +0 -12
- package/lib/layout/dagre/src/data/list.js +0 -52
- package/lib/layout/dagre/src/data/list.js.map +0 -1
- package/lib/layout/dagre/src/debug.d.ts +0 -3
- package/lib/layout/dagre/src/debug.js +0 -26
- package/lib/layout/dagre/src/debug.js.map +0 -1
- package/lib/layout/dagre/src/greedy-fas.d.ts +0 -3
- package/lib/layout/dagre/src/greedy-fas.js +0 -144
- package/lib/layout/dagre/src/greedy-fas.js.map +0 -1
- package/lib/layout/dagre/src/layout.d.ts +0 -3
- package/lib/layout/dagre/src/layout.js +0 -535
- package/lib/layout/dagre/src/layout.js.map +0 -1
- package/lib/layout/dagre/src/nesting-graph.d.ts +0 -6
- package/lib/layout/dagre/src/nesting-graph.js +0 -119
- package/lib/layout/dagre/src/nesting-graph.js.map +0 -1
- package/lib/layout/dagre/src/normalize.d.ts +0 -6
- package/lib/layout/dagre/src/normalize.js +0 -91
- package/lib/layout/dagre/src/normalize.js.map +0 -1
- package/lib/layout/dagre/src/order/add-subgraph-constraints.d.ts +0 -3
- package/lib/layout/dagre/src/order/add-subgraph-constraints.js +0 -29
- package/lib/layout/dagre/src/order/add-subgraph-constraints.js.map +0 -1
- package/lib/layout/dagre/src/order/barycenter.d.ts +0 -11
- package/lib/layout/dagre/src/order/barycenter.js +0 -26
- package/lib/layout/dagre/src/order/barycenter.js.map +0 -1
- package/lib/layout/dagre/src/order/build-layer-graph.d.ts +0 -3
- package/lib/layout/dagre/src/order/build-layer-graph.js +0 -73
- package/lib/layout/dagre/src/order/build-layer-graph.js.map +0 -1
- package/lib/layout/dagre/src/order/cross-count.d.ts +0 -3
- package/lib/layout/dagre/src/order/cross-count.js +0 -67
- package/lib/layout/dagre/src/order/cross-count.js.map +0 -1
- package/lib/layout/dagre/src/order/index.d.ts +0 -3
- package/lib/layout/dagre/src/order/index.js +0 -96
- package/lib/layout/dagre/src/order/index.js.map +0 -1
- package/lib/layout/dagre/src/order/init-data-order.d.ts +0 -6
- package/lib/layout/dagre/src/order/init-data-order.js +0 -27
- package/lib/layout/dagre/src/order/init-data-order.js.map +0 -1
- package/lib/layout/dagre/src/order/init-order.d.ts +0 -3
- package/lib/layout/dagre/src/order/init-order.js +0 -54
- package/lib/layout/dagre/src/order/init-order.js.map +0 -1
- package/lib/layout/dagre/src/order/resolve-conflicts.d.ts +0 -19
- package/lib/layout/dagre/src/order/resolve-conflicts.js +0 -98
- package/lib/layout/dagre/src/order/resolve-conflicts.js.map +0 -1
- package/lib/layout/dagre/src/order/sort-subgraph.d.ts +0 -7
- package/lib/layout/dagre/src/order/sort-subgraph.js +0 -90
- package/lib/layout/dagre/src/order/sort-subgraph.js.map +0 -1
- package/lib/layout/dagre/src/order/sort.d.ts +0 -7
- package/lib/layout/dagre/src/order/sort.js +0 -70
- package/lib/layout/dagre/src/order/sort.js.map +0 -1
- package/lib/layout/dagre/src/parent-dummy-chains.d.ts +0 -3
- package/lib/layout/dagre/src/parent-dummy-chains.js +0 -83
- package/lib/layout/dagre/src/parent-dummy-chains.js.map +0 -1
- package/lib/layout/dagre/src/position/bk.d.ts +0 -23
- package/lib/layout/dagre/src/position/bk.js +0 -409
- package/lib/layout/dagre/src/position/bk.js.map +0 -1
- package/lib/layout/dagre/src/position/index.d.ts +0 -3
- package/lib/layout/dagre/src/position/index.js +0 -64
- package/lib/layout/dagre/src/position/index.js.map +0 -1
- package/lib/layout/dagre/src/rank/feasible-tree.d.ts +0 -9
- package/lib/layout/dagre/src/rank/feasible-tree.js +0 -152
- package/lib/layout/dagre/src/rank/feasible-tree.js.map +0 -1
- package/lib/layout/dagre/src/rank/index.d.ts +0 -3
- package/lib/layout/dagre/src/rank/index.js +0 -58
- package/lib/layout/dagre/src/rank/index.js.map +0 -1
- package/lib/layout/dagre/src/rank/network-simplex.d.ts +0 -9
- package/lib/layout/dagre/src/rank/network-simplex.js +0 -205
- package/lib/layout/dagre/src/rank/network-simplex.js.map +0 -1
- package/lib/layout/dagre/src/rank/util.d.ts +0 -11
- package/lib/layout/dagre/src/rank/util.js +0 -146
- package/lib/layout/dagre/src/rank/util.js.map +0 -1
- package/lib/layout/dagre/src/util.d.ts +0 -31
- package/lib/layout/dagre/src/util.js +0 -280
- package/lib/layout/dagre/src/util.js.map +0 -1
- package/lib/layout/dagre.d.ts +0 -71
- package/lib/layout/dagre.js +0 -462
- package/lib/layout/dagre.js.map +0 -1
- package/lib/layout/dagreCompound.d.ts +0 -121
- package/lib/layout/dagreCompound.js +0 -429
- package/lib/layout/dagreCompound.js.map +0 -1
- package/lib/layout/er/core.d.ts +0 -1
- package/lib/layout/er/core.js +0 -147
- package/lib/layout/er/core.js.map +0 -1
- package/lib/layout/er/forceGrid.d.ts +0 -8
- package/lib/layout/er/forceGrid.js +0 -97
- package/lib/layout/er/forceGrid.js.map +0 -1
- package/lib/layout/er/grid.d.ts +0 -26
- package/lib/layout/er/grid.js +0 -177
- package/lib/layout/er/grid.js.map +0 -1
- package/lib/layout/er/index.d.ts +0 -29
- package/lib/layout/er/index.js +0 -80
- package/lib/layout/er/index.js.map +0 -1
- package/lib/layout/er/mysqlWorkbench.d.ts +0 -6
- package/lib/layout/er/mysqlWorkbench.js +0 -326
- package/lib/layout/er/mysqlWorkbench.js.map +0 -1
- package/lib/layout/er/type.d.ts +0 -35
- package/lib/layout/er/type.js +0 -3
- package/lib/layout/er/type.js.map +0 -1
- package/lib/layout/force/force-in-a-box.d.ts +0 -28
- package/lib/layout/force/force-in-a-box.js +0 -357
- package/lib/layout/force/force-in-a-box.js.map +0 -1
- package/lib/layout/force/force.d.ts +0 -100
- package/lib/layout/force/force.js +0 -388
- package/lib/layout/force/force.js.map +0 -1
- package/lib/layout/force/index.d.ts +0 -1
- package/lib/layout/force/index.js +0 -18
- package/lib/layout/force/index.js.map +0 -1
- package/lib/layout/force2/ForceNBody.d.ts +0 -7
- package/lib/layout/force2/ForceNBody.js +0 -98
- package/lib/layout/force2/ForceNBody.js.map +0 -1
- package/lib/layout/force2/index.d.ts +0 -119
- package/lib/layout/force2/index.js +0 -643
- package/lib/layout/force2/index.js.map +0 -1
- package/lib/layout/forceAtlas2/body.d.ts +0 -33
- package/lib/layout/forceAtlas2/body.js +0 -93
- package/lib/layout/forceAtlas2/body.js.map +0 -1
- package/lib/layout/forceAtlas2/index.d.ts +0 -115
- package/lib/layout/forceAtlas2/index.js +0 -509
- package/lib/layout/forceAtlas2/index.js.map +0 -1
- package/lib/layout/forceAtlas2/quad.d.ts +0 -27
- package/lib/layout/forceAtlas2/quad.js +0 -100
- package/lib/layout/forceAtlas2/quad.js.map +0 -1
- package/lib/layout/forceAtlas2/quadTree.d.ts +0 -20
- package/lib/layout/forceAtlas2/quadTree.js +0 -107
- package/lib/layout/forceAtlas2/quadTree.js.map +0 -1
- package/lib/layout/fruchterman.d.ts +0 -73
- package/lib/layout/fruchterman.js +0 -320
- package/lib/layout/fruchterman.js.map +0 -1
- package/lib/layout/gForce.d.ts +0 -96
- package/lib/layout/gForce.js +0 -421
- package/lib/layout/gForce.js.map +0 -1
- package/lib/layout/gpu/fruchterman.d.ts +0 -57
- package/lib/layout/gpu/fruchterman.js +0 -361
- package/lib/layout/gpu/fruchterman.js.map +0 -1
- package/lib/layout/gpu/fruchtermanShader.d.ts +0 -4
- package/lib/layout/gpu/fruchtermanShader.js +0 -8
- package/lib/layout/gpu/fruchtermanShader.js.map +0 -1
- package/lib/layout/gpu/gForce.d.ts +0 -68
- package/lib/layout/gpu/gForce.js +0 -415
- package/lib/layout/gpu/gForce.js.map +0 -1
- package/lib/layout/gpu/gForceShader.d.ts +0 -4
- package/lib/layout/gpu/gForceShader.js +0 -8
- package/lib/layout/gpu/gForceShader.js.map +0 -1
- package/lib/layout/grid.d.ts +0 -83
- package/lib/layout/grid.js +0 -339
- package/lib/layout/grid.js.map +0 -1
- package/lib/layout/index.d.ts +0 -22
- package/lib/layout/index.js +0 -59
- package/lib/layout/index.js.map +0 -1
- package/lib/layout/layout.d.ts +0 -26
- package/lib/layout/layout.js +0 -102
- package/lib/layout/layout.js.map +0 -1
- package/lib/layout/mds.d.ts +0 -39
- package/lib/layout/mds.js +0 -144
- package/lib/layout/mds.js.map +0 -1
- package/lib/layout/radial/index.d.ts +0 -1
- package/lib/layout/radial/index.js +0 -18
- package/lib/layout/radial/index.js.map +0 -1
- package/lib/layout/radial/mds.d.ts +0 -15
- package/lib/layout/radial/mds.js +0 -42
- package/lib/layout/radial/mds.js.map +0 -1
- package/lib/layout/radial/radial.d.ts +0 -74
- package/lib/layout/radial/radial.js +0 -445
- package/lib/layout/radial/radial.js.map +0 -1
- package/lib/layout/radial/radialNonoverlapForce.d.ts +0 -50
- package/lib/layout/radial/radialNonoverlapForce.js +0 -127
- package/lib/layout/radial/radialNonoverlapForce.js.map +0 -1
- package/lib/layout/random.d.ts +0 -35
- package/lib/layout/random.js +0 -84
- package/lib/layout/random.js.map +0 -1
- package/lib/layout/types.d.ts +0 -432
- package/lib/layout/types.js +0 -3
- package/lib/layout/types.js.map +0 -1
- package/lib/registy/index.d.ts +0 -3
- package/lib/registy/index.js +0 -65
- package/lib/registy/index.js.map +0 -1
- package/lib/util/array.js +0 -5
- package/lib/util/array.js.map +0 -1
- package/lib/util/function.js +0 -65
- package/lib/util/function.js.map +0 -1
- package/lib/util/gpu.js +0 -250
- package/lib/util/gpu.js.map +0 -1
- package/lib/util/index.js +0 -23
- package/lib/util/index.js.map +0 -1
- package/lib/util/math.js +0 -289
- package/lib/util/math.js.map +0 -1
- package/lib/util/number.js +0 -13
- package/lib/util/number.js.map +0 -1
- package/lib/util/object.js +0 -43
- package/lib/util/object.js.map +0 -1
- package/lib/util/string.js +0 -20
- package/lib/util/string.js.map +0 -1
- package/src/index.ts +0 -7
- package/src/layout/base.ts +0 -57
- package/src/layout/circular.ts +0 -370
- package/src/layout/comboCombined.ts +0 -397
- package/src/layout/comboForce.ts +0 -873
- package/src/layout/concentric.ts +0 -289
- package/src/layout/constants.ts +0 -22
- package/src/layout/dagre/graph.ts +0 -104
- package/src/layout/dagre/index.ts +0 -31
- package/src/layout/dagre/src/acyclic.ts +0 -58
- package/src/layout/dagre/src/add-border-segments.ts +0 -47
- package/src/layout/dagre/src/coordinate-system.ts +0 -77
- package/src/layout/dagre/src/data/list.ts +0 -60
- package/src/layout/dagre/src/debug.ts +0 -30
- package/src/layout/dagre/src/greedy-fas.ts +0 -144
- package/src/layout/dagre/src/layout.ts +0 -579
- package/src/layout/dagre/src/nesting-graph.ts +0 -143
- package/src/layout/dagre/src/normalize.ts +0 -96
- package/src/layout/dagre/src/order/add-subgraph-constraints.ts +0 -29
- package/src/layout/dagre/src/order/barycenter.ts +0 -26
- package/src/layout/dagre/src/order/build-layer-graph.ts +0 -82
- package/src/layout/dagre/src/order/cross-count.ts +0 -77
- package/src/layout/dagre/src/order/index.ts +0 -105
- package/src/layout/dagre/src/order/init-data-order.ts +0 -27
- package/src/layout/dagre/src/order/init-order.ts +0 -56
- package/src/layout/dagre/src/order/resolve-conflicts.ts +0 -152
- package/src/layout/dagre/src/order/sort-subgraph.ts +0 -105
- package/src/layout/dagre/src/order/sort.ts +0 -76
- package/src/layout/dagre/src/parent-dummy-chains.ts +0 -102
- package/src/layout/dagre/src/position/bk.ts +0 -493
- package/src/layout/dagre/src/position/index.ts +0 -82
- package/src/layout/dagre/src/rank/feasible-tree.ts +0 -165
- package/src/layout/dagre/src/rank/index.ts +0 -54
- package/src/layout/dagre/src/rank/network-simplex.ts +0 -225
- package/src/layout/dagre/src/rank/util.ts +0 -166
- package/src/layout/dagre/src/util.ts +0 -309
- package/src/layout/dagre.ts +0 -460
- package/src/layout/dagreCompound.ts +0 -518
- package/src/layout/er/core.ts +0 -117
- package/src/layout/er/forceGrid.ts +0 -95
- package/src/layout/er/grid.ts +0 -185
- package/src/layout/er/index.ts +0 -68
- package/src/layout/er/mysqlWorkbench.ts +0 -345
- package/src/layout/er/type.ts +0 -39
- package/src/layout/force/force-in-a-box.ts +0 -400
- package/src/layout/force/force.ts +0 -391
- package/src/layout/force/index.ts +0 -1
- package/src/layout/force2/ForceNBody.ts +0 -128
- package/src/layout/force2/index.ts +0 -741
- package/src/layout/forceAtlas2/body.ts +0 -115
- package/src/layout/forceAtlas2/index.ts +0 -556
- package/src/layout/forceAtlas2/quad.ts +0 -115
- package/src/layout/forceAtlas2/quadTree.ts +0 -107
- package/src/layout/fruchterman.ts +0 -361
- package/src/layout/gForce.ts +0 -488
- package/src/layout/gpu/fruchterman.ts +0 -314
- package/src/layout/gpu/fruchtermanShader.ts +0 -203
- package/src/layout/gpu/gForce.ts +0 -407
- package/src/layout/gpu/gForceShader.ts +0 -220
- package/src/layout/grid.ts +0 -404
- package/src/layout/index.ts +0 -47
- package/src/layout/layout.ts +0 -110
- package/src/layout/mds.ts +0 -140
- package/src/layout/radial/index.ts +0 -1
- package/src/layout/radial/mds.ts +0 -51
- package/src/layout/radial/radial.ts +0 -500
- package/src/layout/radial/radialNonoverlapForce.ts +0 -189
- package/src/layout/random.ts +0 -75
- package/src/layout/types.ts +0 -496
- package/src/registy/index.ts +0 -43
- package/src/util/array.ts +0 -1
- package/src/util/function.ts +0 -64
- package/src/util/gpu.ts +0 -256
- package/src/util/index.ts +0 -6
- package/src/util/math.ts +0 -294
- package/src/util/number.ts +0 -8
- package/src/util/object.ts +0 -28
- package/src/util/string.ts +0 -18
package/es/layout/gpu/gForce.js
DELETED
|
@@ -1,330 +0,0 @@
|
|
|
1
|
-
// @ts-nocheck
|
|
2
|
-
/**
|
|
3
|
-
* @fileOverview fruchterman layout
|
|
4
|
-
* @author shiwu.wyy@antfin.com
|
|
5
|
-
*/
|
|
6
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
7
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
8
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
9
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
10
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
11
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
12
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
13
|
-
});
|
|
14
|
-
};
|
|
15
|
-
import { Base } from "../base";
|
|
16
|
-
import { isNumber } from "../../util";
|
|
17
|
-
// @ts-ignore
|
|
18
|
-
import { World } from "@antv/g-webgpu";
|
|
19
|
-
import { proccessToFunc, buildTextureDataWithTwoEdgeAttr, arrayToTextureData } from "../../util/gpu";
|
|
20
|
-
import { getDegree } from "../../util/math";
|
|
21
|
-
import { gForceBundle, aveMovementBundle } from "./gForceShader";
|
|
22
|
-
import { LAYOUT_MESSAGE } from "../constants";
|
|
23
|
-
/**
|
|
24
|
-
* graphin 中的 force 布局
|
|
25
|
-
*/
|
|
26
|
-
export class GForceGPULayout extends Base {
|
|
27
|
-
constructor(options) {
|
|
28
|
-
super();
|
|
29
|
-
/** 停止迭代的最大迭代数 */
|
|
30
|
-
this.maxIteration = 1000;
|
|
31
|
-
/** 弹簧引力系数 */
|
|
32
|
-
this.edgeStrength = 200;
|
|
33
|
-
/** 斥力系数 */
|
|
34
|
-
this.nodeStrength = 1000;
|
|
35
|
-
/** 库伦系数 */
|
|
36
|
-
this.coulombDisScale = 0.005;
|
|
37
|
-
/** 阻尼系数 */
|
|
38
|
-
this.damping = 0.9;
|
|
39
|
-
/** 最大速度 */
|
|
40
|
-
this.maxSpeed = 1000;
|
|
41
|
-
/** 一次迭代的平均移动距离小于该值时停止迭代 */
|
|
42
|
-
this.minMovement = 0.5;
|
|
43
|
-
/** 迭代中衰减 */
|
|
44
|
-
this.interval = 0.02;
|
|
45
|
-
/** 斥力的一个系数 */
|
|
46
|
-
this.factor = 1;
|
|
47
|
-
/** 理想边长 */
|
|
48
|
-
this.linkDistance = 1;
|
|
49
|
-
/** 重力大小 */
|
|
50
|
-
this.gravity = 10;
|
|
51
|
-
/** 是否启用web worker。前提是在web worker里执行布局,否则无效 */
|
|
52
|
-
this.workerEnabled = false;
|
|
53
|
-
this.nodes = [];
|
|
54
|
-
this.edges = [];
|
|
55
|
-
this.width = 300;
|
|
56
|
-
this.height = 300;
|
|
57
|
-
this.nodeMap = {};
|
|
58
|
-
this.nodeIdxMap = {};
|
|
59
|
-
this.updateCfg(options);
|
|
60
|
-
}
|
|
61
|
-
getDefaultCfg() {
|
|
62
|
-
return {
|
|
63
|
-
maxIteration: 2000,
|
|
64
|
-
gravity: 10,
|
|
65
|
-
clustering: false,
|
|
66
|
-
clusterGravity: 10
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* 执行布局
|
|
71
|
-
*/
|
|
72
|
-
execute() {
|
|
73
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
74
|
-
const self = this;
|
|
75
|
-
const nodes = self.nodes;
|
|
76
|
-
if (!nodes || nodes.length === 0) {
|
|
77
|
-
if (self.onLayoutEnd)
|
|
78
|
-
self.onLayoutEnd();
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
if (!self.width && typeof window !== "undefined") {
|
|
82
|
-
self.width = window.innerWidth;
|
|
83
|
-
}
|
|
84
|
-
if (!self.height && typeof window !== "undefined") {
|
|
85
|
-
self.height = window.innerHeight;
|
|
86
|
-
}
|
|
87
|
-
if (!self.center) {
|
|
88
|
-
self.center = [self.width / 2, self.height / 2];
|
|
89
|
-
}
|
|
90
|
-
const center = self.center;
|
|
91
|
-
if (nodes.length === 1) {
|
|
92
|
-
nodes[0].x = center[0];
|
|
93
|
-
nodes[0].y = center[1];
|
|
94
|
-
if (self.onLayoutEnd)
|
|
95
|
-
self.onLayoutEnd();
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
const nodeMap = {};
|
|
99
|
-
const nodeIdxMap = {};
|
|
100
|
-
nodes.forEach((node, i) => {
|
|
101
|
-
if (!isNumber(node.x))
|
|
102
|
-
node.x = Math.random() * self.width;
|
|
103
|
-
if (!isNumber(node.y))
|
|
104
|
-
node.y = Math.random() * self.height;
|
|
105
|
-
nodeMap[node.id] = node;
|
|
106
|
-
nodeIdxMap[node.id] = i;
|
|
107
|
-
});
|
|
108
|
-
self.nodeMap = nodeMap;
|
|
109
|
-
self.nodeIdxMap = nodeIdxMap;
|
|
110
|
-
self.nodeStrength = proccessToFunc(self.nodeStrength, 1);
|
|
111
|
-
self.edgeStrength = proccessToFunc(self.edgeStrength, 1);
|
|
112
|
-
// layout
|
|
113
|
-
yield self.run();
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
executeWithWorker(canvas, ctx) {
|
|
117
|
-
const self = this;
|
|
118
|
-
const nodes = self.nodes;
|
|
119
|
-
const center = self.center;
|
|
120
|
-
if (!nodes || nodes.length === 0) {
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
123
|
-
if (nodes.length === 1) {
|
|
124
|
-
nodes[0].x = center[0];
|
|
125
|
-
nodes[0].y = center[1];
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
const nodeMap = {};
|
|
129
|
-
const nodeIdxMap = {};
|
|
130
|
-
nodes.forEach((node, i) => {
|
|
131
|
-
if (!isNumber(node.x))
|
|
132
|
-
node.x = Math.random() * self.width;
|
|
133
|
-
if (!isNumber(node.y))
|
|
134
|
-
node.y = Math.random() * self.height;
|
|
135
|
-
nodeMap[node.id] = node;
|
|
136
|
-
nodeIdxMap[node.id] = i;
|
|
137
|
-
});
|
|
138
|
-
self.nodeMap = nodeMap;
|
|
139
|
-
self.nodeIdxMap = nodeIdxMap;
|
|
140
|
-
self.nodeStrength = proccessToFunc(self.nodeStrength, 1);
|
|
141
|
-
self.edgeStrength = proccessToFunc(self.edgeStrength, 1);
|
|
142
|
-
// layout
|
|
143
|
-
self.run(canvas, ctx);
|
|
144
|
-
}
|
|
145
|
-
run(canvas, ctx) {
|
|
146
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
147
|
-
const self = this;
|
|
148
|
-
const nodes = self.nodes;
|
|
149
|
-
const edges = self.edges;
|
|
150
|
-
const maxIteration = self.maxIteration;
|
|
151
|
-
if (!self.width && typeof window !== "undefined") {
|
|
152
|
-
self.width = window.innerWidth;
|
|
153
|
-
}
|
|
154
|
-
if (!self.height && typeof window !== "undefined") {
|
|
155
|
-
self.height = window.innerHeight;
|
|
156
|
-
}
|
|
157
|
-
const numParticles = nodes.length;
|
|
158
|
-
self.linkDistance = proccessToFunc(self.linkDistance);
|
|
159
|
-
self.edgeStrength = proccessToFunc(self.edgeStrength);
|
|
160
|
-
const { maxEdgePerVetex, array: nodesEdgesArray } = buildTextureDataWithTwoEdgeAttr(nodes, edges, self.linkDistance, self.edgeStrength);
|
|
161
|
-
// init degree for mass
|
|
162
|
-
self.degrees = getDegree(nodes.length, self.nodeIdxMap, edges).map((degree) => degree.all);
|
|
163
|
-
const masses = [];
|
|
164
|
-
const nodeStrengths = [];
|
|
165
|
-
const centerXs = [];
|
|
166
|
-
const centerYs = [];
|
|
167
|
-
const centerGravities = [];
|
|
168
|
-
const fxs = [];
|
|
169
|
-
const fys = [];
|
|
170
|
-
if (!self.getMass) {
|
|
171
|
-
self.getMass = (d) => {
|
|
172
|
-
return self.degrees[self.nodeIdxMap[d.id]] || 1;
|
|
173
|
-
};
|
|
174
|
-
}
|
|
175
|
-
const gravity = self.gravity;
|
|
176
|
-
const center = self.center;
|
|
177
|
-
nodes.forEach((node, i) => {
|
|
178
|
-
masses.push(self.getMass(node));
|
|
179
|
-
nodeStrengths.push(self.nodeStrength(node));
|
|
180
|
-
if (!self.degrees[i])
|
|
181
|
-
self.degrees[i] = 0;
|
|
182
|
-
let nodeGravity = [center[0], center[1], gravity];
|
|
183
|
-
if (self.getCenter) {
|
|
184
|
-
const customCenter = self.getCenter(node, self.degrees[i]);
|
|
185
|
-
if (customCenter &&
|
|
186
|
-
isNumber(customCenter[0]) &&
|
|
187
|
-
isNumber(customCenter[1]) &&
|
|
188
|
-
isNumber(customCenter[2])) {
|
|
189
|
-
nodeGravity = customCenter;
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
centerXs.push(nodeGravity[0]);
|
|
193
|
-
centerYs.push(nodeGravity[1]);
|
|
194
|
-
centerGravities.push(nodeGravity[2]);
|
|
195
|
-
if (isNumber(node.fx) && isNumber(node.fy)) {
|
|
196
|
-
fxs.push(node.fx || 0.001);
|
|
197
|
-
fys.push(node.fy || 0.001);
|
|
198
|
-
}
|
|
199
|
-
else {
|
|
200
|
-
fxs.push(0);
|
|
201
|
-
fys.push(0);
|
|
202
|
-
}
|
|
203
|
-
});
|
|
204
|
-
// 每个节点的额外属性占两个数组各一格,nodeAttributeArray1 中是:mass, degree, nodeSterngth, 0
|
|
205
|
-
const nodeAttributeArray1 = arrayToTextureData([
|
|
206
|
-
masses,
|
|
207
|
-
self.degrees,
|
|
208
|
-
nodeStrengths,
|
|
209
|
-
fxs
|
|
210
|
-
]);
|
|
211
|
-
// nodeAttributeArray2 中是:centerX, centerY, gravity, 0,
|
|
212
|
-
const nodeAttributeArray2 = arrayToTextureData([
|
|
213
|
-
centerXs,
|
|
214
|
-
centerYs,
|
|
215
|
-
centerGravities,
|
|
216
|
-
fys
|
|
217
|
-
]);
|
|
218
|
-
const workerEnabled = self.workerEnabled;
|
|
219
|
-
let world;
|
|
220
|
-
if (workerEnabled) {
|
|
221
|
-
world = World.create({
|
|
222
|
-
canvas,
|
|
223
|
-
engineOptions: {
|
|
224
|
-
supportCompute: true
|
|
225
|
-
}
|
|
226
|
-
});
|
|
227
|
-
}
|
|
228
|
-
else {
|
|
229
|
-
world = World.create({
|
|
230
|
-
engineOptions: {
|
|
231
|
-
supportCompute: true
|
|
232
|
-
}
|
|
233
|
-
});
|
|
234
|
-
}
|
|
235
|
-
// TODO: 最终的预编译代码放入到 gForceShader.ts 中直接引入,不再需要下面三行
|
|
236
|
-
// const compiler = new Compiler();
|
|
237
|
-
// const gForceBundle = compiler.compileBundle(gForceCode);
|
|
238
|
-
// console.log(gForceBundle.toString());
|
|
239
|
-
const onLayoutEnd = self.onLayoutEnd;
|
|
240
|
-
const initPreviousData = [];
|
|
241
|
-
nodesEdgesArray.forEach((value) => {
|
|
242
|
-
initPreviousData.push(value);
|
|
243
|
-
});
|
|
244
|
-
for (let i = 0; i < 4; i++) {
|
|
245
|
-
initPreviousData.push(0);
|
|
246
|
-
}
|
|
247
|
-
const kernelGForce = world
|
|
248
|
-
.createKernel(gForceBundle)
|
|
249
|
-
.setDispatch([numParticles, 1, 1])
|
|
250
|
-
.setBinding({
|
|
251
|
-
u_Data: nodesEdgesArray,
|
|
252
|
-
u_damping: self.damping,
|
|
253
|
-
u_maxSpeed: self.maxSpeed,
|
|
254
|
-
u_minMovement: self.minMovement,
|
|
255
|
-
u_coulombDisScale: self.coulombDisScale,
|
|
256
|
-
u_factor: self.factor,
|
|
257
|
-
u_NodeAttributeArray1: nodeAttributeArray1,
|
|
258
|
-
u_NodeAttributeArray2: nodeAttributeArray2,
|
|
259
|
-
MAX_EDGE_PER_VERTEX: maxEdgePerVetex,
|
|
260
|
-
VERTEX_COUNT: numParticles,
|
|
261
|
-
u_AveMovement: initPreviousData,
|
|
262
|
-
u_interval: self.interval // 每次迭代更新,首次设置为 interval,在 onIterationCompleted 中更新
|
|
263
|
-
});
|
|
264
|
-
// const aveMovementBundle = compiler.compileBundle(aveMovementCode);
|
|
265
|
-
// console.log(aveMovementBundle.toString());
|
|
266
|
-
const kernelAveMovement = world
|
|
267
|
-
.createKernel(aveMovementBundle)
|
|
268
|
-
.setDispatch([1, 1, 1])
|
|
269
|
-
.setBinding({
|
|
270
|
-
u_Data: nodesEdgesArray,
|
|
271
|
-
VERTEX_COUNT: numParticles,
|
|
272
|
-
u_AveMovement: [0, 0, 0, 0]
|
|
273
|
-
});
|
|
274
|
-
// 执行迭代
|
|
275
|
-
// let midRes = nodesEdgesArray;
|
|
276
|
-
const execute = () => __awaiter(this, void 0, void 0, function* () {
|
|
277
|
-
for (let i = 0; i < maxIteration; i++) {
|
|
278
|
-
// TODO: 似乎都来自 kernelGForce 是一个引用
|
|
279
|
-
// 当前坐标作为下一次迭代的 PreviousData
|
|
280
|
-
// if (i > 0) {
|
|
281
|
-
// kernelAveMovement.setBinding({
|
|
282
|
-
// u_PreviousData: kernelGForce
|
|
283
|
-
// });
|
|
284
|
-
// }
|
|
285
|
-
// eslint-disable-next-line no-await-in-loop
|
|
286
|
-
yield kernelGForce.execute();
|
|
287
|
-
// midRes = await kernelGForce.getOutput();
|
|
288
|
-
// 每次迭代完成后
|
|
289
|
-
// 计算平均位移,用于提前终止迭代
|
|
290
|
-
kernelAveMovement.setBinding({
|
|
291
|
-
u_Data: kernelGForce
|
|
292
|
-
});
|
|
293
|
-
// eslint-disable-next-line no-await-in-loop
|
|
294
|
-
yield kernelAveMovement.execute();
|
|
295
|
-
// 更新衰减函数
|
|
296
|
-
const stepInterval = Math.max(0.02, self.interval - i * 0.002);
|
|
297
|
-
kernelGForce.setBinding({
|
|
298
|
-
u_interval: stepInterval,
|
|
299
|
-
u_AveMovement: kernelAveMovement
|
|
300
|
-
});
|
|
301
|
-
}
|
|
302
|
-
const finalParticleData = yield kernelGForce.getOutput();
|
|
303
|
-
// 所有迭代完成后
|
|
304
|
-
if (canvas) {
|
|
305
|
-
// 传递数据给主线程
|
|
306
|
-
ctx.postMessage({
|
|
307
|
-
type: LAYOUT_MESSAGE.GPUEND,
|
|
308
|
-
vertexEdgeData: finalParticleData
|
|
309
|
-
// edgeIndexBufferData,
|
|
310
|
-
});
|
|
311
|
-
}
|
|
312
|
-
else {
|
|
313
|
-
nodes.forEach((node, i) => {
|
|
314
|
-
const x = finalParticleData[4 * i];
|
|
315
|
-
const y = finalParticleData[4 * i + 1];
|
|
316
|
-
node.x = x;
|
|
317
|
-
node.y = y;
|
|
318
|
-
});
|
|
319
|
-
}
|
|
320
|
-
if (onLayoutEnd)
|
|
321
|
-
onLayoutEnd();
|
|
322
|
-
});
|
|
323
|
-
yield execute();
|
|
324
|
-
});
|
|
325
|
-
}
|
|
326
|
-
getType() {
|
|
327
|
-
return "gForce-gpu";
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
//# sourceMappingURL=gForce.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"gForce.js","sourceRoot":"","sources":["../../../src/layout/gpu/gForce.ts"],"names":[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BAED,IAAI,WAAW;oBAAE,WAAW,EAAE,CAAC;YACjC,CAAC,CAAA,CAAC;YAEF,MAAM,OAAO,EAAE,CAAC;QAClB,CAAC;KAAA;IAEM,OAAO;QACZ,OAAO,YAAY,CAAC;IACtB,CAAC;CACF"}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
export declare const gForceCode = "\nimport { globalInvocationID } from 'g-webgpu';\n\nconst MAX_EDGE_PER_VERTEX;\nconst VERTEX_COUNT;\nconst SHIFT_20 = 1048576;\n\n@numthreads(1, 1, 1)\nclass GGForce {\n @in @out\n u_Data: vec4[];\n\n @in\n u_damping: float;\n \n @in\n u_maxSpeed: float;\n\n @in\n u_minMovement: float;\n\n @in\n u_AveMovement: vec4[];\n\n @in\n u_coulombDisScale: float;\n\n @in\n u_factor: float;\n\n @in\n u_NodeAttributeArray1: vec4[];\n\n @in\n u_NodeAttributeArray2: vec4[];\n\n @in\n u_interval: float;\n\n unpack_float(packedValue: float): ivec2 {\n const packedIntValue = int(packedValue);\n const v0 = packedIntValue / SHIFT_20;\n return [v0, packedIntValue - v0 * SHIFT_20];\n }\n\n calcRepulsive(i: int, currentNode: vec4): vec2 {\n let ax = 0, ay = 0;\n for (let j: int = 0; j < VERTEX_COUNT; j++) {\n if (i != j) {\n const nextNode = this.u_Data[j];\n const vx = currentNode[0] - nextNode[0];\n const vy = currentNode[1] - nextNode[1];\n const dist = sqrt(vx * vx + vy * vy) + 0.01;\n const n_dist = (dist + 0.1) * this.u_coulombDisScale;\n const direx = vx / dist;\n const direy = vy / dist;\n const attributesi = this.u_NodeAttributeArray1[i];\n const attributesj = this.u_NodeAttributeArray1[j];\n const massi = attributesi[0];\n const nodeStrengthi = attributesi[2];\n const nodeStrengthj = attributesj[2];\n const nodeStrength = (nodeStrengthi + nodeStrengthj) / 2;\n // const param = nodeStrength * this.u_factor / (n_dist * n_dist * massi);\n const param = nodeStrength * this.u_factor / (n_dist * n_dist);\n ax += direx * param;\n ay += direy * param;\n }\n }\n return [ax, ay];\n }\n\n calcGravity(i: int, currentNode: vec4, attributes2: vec4): vec2 {\n // note: attributes2 = [centerX, centerY, gravity, 0]\n\n const vx = currentNode[0] - attributes2[0];\n const vy = currentNode[1] - attributes2[1];\n \n const ax = vx * attributes2[2];\n const ay = vy * attributes2[2];\n \n return [ax, ay];\n }\n\n calcAttractive(i: int, currentNode: vec4, attributes1: vec4): vec2 {\n // note: attributes1 = [mass, degree, nodeSterngth, 0]\n\n const mass = attributes1[0];\n let ax = 0, ay = 0;\n // const arr_offset = int(floor(currentNode[2] + 0.5));\n // const length = int(floor(currentNode[3] + 0.5));\n\n const compressed = this.unpack_float(currentNode[2]);\n const length = compressed[0];\n const arr_offset = compressed[1];\n\n const node_buffer: vec4;\n for (let p: int = 0; p < MAX_EDGE_PER_VERTEX; p++) {\n if (p >= length) break;\n const arr_idx = arr_offset + 4 * p; // i \u8282\u70B9\u7684\u7B2C p \u6761\u8FB9\u5F00\u59CB\u7684\u5C0F\u683C\u5B50\u4F4D\u7F6E\n const buf_offset = arr_idx - arr_idx / 4 * 4;\n if (p == 0 || buf_offset == 0) {\n node_buffer = this.u_Data[int(arr_idx / 4)]; // \u5927\u683C\u5B50\uFF0C\u5927\u683C\u5B50\u4F4D\u7F6E=\u5C0F\u4E2A\u5B50\u4F4D\u7F6E / 4\uFF0C\n }\n\n let float_j: float = node_buffer[0];\n\n const nextNode = this.u_Data[int(float_j)];\n const vx = nextNode[0] - currentNode[0];\n const vy = nextNode[1] - currentNode[1];\n const dist = sqrt(vx * vx + vy * vy) + 0.01;\n const direx = vx / dist;\n const direy = vy / dist;\n const edgeLength = node_buffer[1];\n const edgeStrength = node_buffer[2];\n const diff: float = edgeLength - dist;//edgeLength\n // const param = diff * this.u_stiffness / mass; //\n const param = diff * edgeStrength / mass; // \n ax -= direx * param;\n ay -= direy * param;\n }\n return [ax, ay];\n }\n\n @main\n compute() {\n const i = globalInvocationID.x;\n const currentNode = this.u_Data[i];\n const movement = u_AveMovement[0];\n let ax = 0, ay = 0;\n\n if (i >= VERTEX_COUNT || movement.x < u_minMovement) {\n this.u_Data[i] = currentNode;\n return;\n }\n\n // \u6BCF\u4E2A\u8282\u70B9\u5C5E\u6027\u5360\u4E24\u4E2A\u6570\u7EC4\u4E2D\u5404\u4E00\u683C\n // [mass, degree, nodeStrength, fx]\n const nodeAttributes1 = this.u_NodeAttributeArray1[i];\n // [centerX, centerY, centerGravity, fy]\n const nodeAttributes2 = this.u_NodeAttributeArray2[i];\n\n // repulsive\n const repulsive = this.calcRepulsive(i, currentNode);\n ax += repulsive[0];\n ay += repulsive[1];\n\n // attractive\n const attractive = this.calcAttractive(i, currentNode, nodeAttributes1);\n ax += attractive[0];\n ay += attractive[1];\n\n // gravity\n const gravity = this.calcGravity(i, currentNode, nodeAttributes2);\n ax -= gravity[0];\n ay -= gravity[1];\n\n // speed\n const param = this.u_interval * this.u_damping;\n let vx = ax * param;\n let vy = ay * param;\n const vlength = sqrt(vx * vx + vy * vy) + 0.0001;\n if (vlength > this.u_maxSpeed) {\n const param2 = this.u_maxSpeed / vlength;\n vx = param2 * vx;\n vy = param2 * vy;\n }\n\n // move\n if (nodeAttributes1[3] != 0 && nodeAttributes2[3] != 0) {\n this.u_Data[i] = [\n nodeAttributes1[3],\n nodeAttributes2[3],\n currentNode[2],\n 0\n ];\n } else {\n const distx = vx * this.u_interval;\n const disty = vy * this.u_interval;\n const distLength = sqrt(distx * distx + disty * disty);\n this.u_Data[i] = [\n currentNode[0] + distx,\n currentNode[1] + disty,\n currentNode[2],\n distLength\n ];\n }\n \n // the avarage move distance\n // need to share memory\n \n }\n}\n";
|
|
2
|
-
export declare const gForceBundle = "{\"shaders\":{\"WGSL\":\"\",\"GLSL450\":\"\",\"GLSL100\":\"\\n\\nfloat epsilon = 0.00001;\\nvec2 addrTranslation_1Dto2D(float address1D, vec2 texSize) {\\n vec2 conv_const = vec2(1.0 / texSize.x, 1.0 / (texSize.x * texSize.y));\\n vec2 normAddr2D = float(address1D) * conv_const;\\n return vec2(fract(normAddr2D.x + epsilon), normAddr2D.y);\\n}\\n\\nvoid barrier() {}\\n \\n\\nuniform vec2 u_OutputTextureSize;\\nuniform int u_OutputTexelCount;\\nvarying vec2 v_TexCoord;\\n\\nbool gWebGPUDebug = false;\\nvec4 gWebGPUDebugOutput = vec4(0.0);\\n\\n#define MAX_EDGE_PER_VERTEX __DefineValuePlaceholder__MAX_EDGE_PER_VERTEX\\n#define VERTEX_COUNT __DefineValuePlaceholder__VERTEX_COUNT\\n#define SHIFT_20 1048576.0\\n\\nuniform sampler2D u_Data;\\nuniform vec2 u_DataSize;\\nvec4 getDatau_Data(vec2 address2D) {\\n return vec4(texture2D(u_Data, address2D).rgba);\\n}\\nvec4 getDatau_Data(float address1D) {\\n return getDatau_Data(addrTranslation_1Dto2D(address1D, u_DataSize));\\n}\\nvec4 getDatau_Data(int address1D) {\\n return getDatau_Data(float(address1D));\\n}\\nuniform float u_damping;\\nuniform float u_maxSpeed;\\nuniform float u_minMovement;\\nuniform sampler2D u_AveMovement;\\nuniform vec2 u_AveMovementSize;\\nvec4 getDatau_AveMovement(vec2 address2D) {\\n return vec4(texture2D(u_AveMovement, address2D).rgba);\\n}\\nvec4 getDatau_AveMovement(float address1D) {\\n return getDatau_AveMovement(addrTranslation_1Dto2D(address1D, u_AveMovementSize));\\n}\\nvec4 getDatau_AveMovement(int address1D) {\\n return getDatau_AveMovement(float(address1D));\\n}\\nuniform float u_coulombDisScale;\\nuniform float u_factor;\\nuniform sampler2D u_NodeAttributeArray1;\\nuniform vec2 u_NodeAttributeArray1Size;\\nvec4 getDatau_NodeAttributeArray1(vec2 address2D) {\\n return vec4(texture2D(u_NodeAttributeArray1, address2D).rgba);\\n}\\nvec4 getDatau_NodeAttributeArray1(float address1D) {\\n return getDatau_NodeAttributeArray1(addrTranslation_1Dto2D(address1D, u_NodeAttributeArray1Size));\\n}\\nvec4 getDatau_NodeAttributeArray1(int address1D) {\\n return getDatau_NodeAttributeArray1(float(address1D));\\n}\\nuniform sampler2D u_NodeAttributeArray2;\\nuniform vec2 u_NodeAttributeArray2Size;\\nvec4 getDatau_NodeAttributeArray2(vec2 address2D) {\\n return vec4(texture2D(u_NodeAttributeArray2, address2D).rgba);\\n}\\nvec4 getDatau_NodeAttributeArray2(float address1D) {\\n return getDatau_NodeAttributeArray2(addrTranslation_1Dto2D(address1D, u_NodeAttributeArray2Size));\\n}\\nvec4 getDatau_NodeAttributeArray2(int address1D) {\\n return getDatau_NodeAttributeArray2(float(address1D));\\n}\\nuniform float u_interval;\\nivec2 unpack_float(float packedValue) {\\nivec3 workGroupSize = ivec3(1, 1, 1);\\nivec3 numWorkGroups = ivec3(1, 1, 1); \\nint globalInvocationIndex = int(floor(v_TexCoord.x * u_OutputTextureSize.x))\\n + int(floor(v_TexCoord.y * u_OutputTextureSize.y)) * int(u_OutputTextureSize.x);\\nint workGroupIDLength = globalInvocationIndex / (workGroupSize.x * workGroupSize.y * workGroupSize.z);\\nivec3 workGroupID = ivec3(workGroupIDLength / numWorkGroups.y / numWorkGroups.z, workGroupIDLength / numWorkGroups.x / numWorkGroups.z, workGroupIDLength / numWorkGroups.x / numWorkGroups.y);\\nint localInvocationIDZ = globalInvocationIndex / (workGroupSize.x * workGroupSize.y);\\nint localInvocationIDY = (globalInvocationIndex - localInvocationIDZ * workGroupSize.x * workGroupSize.y) / workGroupSize.x;\\nint localInvocationIDX = globalInvocationIndex - localInvocationIDZ * workGroupSize.x * workGroupSize.y - localInvocationIDY * workGroupSize.x;\\nivec3 localInvocationID = ivec3(localInvocationIDX, localInvocationIDY, localInvocationIDZ);\\nivec3 globalInvocationID = workGroupID * workGroupSize + localInvocationID;\\nint localInvocationIndex = localInvocationID.z * workGroupSize.x * workGroupSize.y\\n + localInvocationID.y * workGroupSize.x + localInvocationID.x;\\nint packedIntValue = int(packedValue);\\nint v0 = packedIntValue / int(SHIFT_20);\\nreturn ivec2(v0, packedIntValue - (v0 * int(SHIFT_20)));}\\nvec2 calcRepulsive(int i, vec4 currentNode) {\\nivec3 workGroupSize = ivec3(1, 1, 1);\\nivec3 numWorkGroups = ivec3(1, 1, 1); \\nint globalInvocationIndex = int(floor(v_TexCoord.x * u_OutputTextureSize.x))\\n + int(floor(v_TexCoord.y * u_OutputTextureSize.y)) * int(u_OutputTextureSize.x);\\nint workGroupIDLength = globalInvocationIndex / (workGroupSize.x * workGroupSize.y * workGroupSize.z);\\nivec3 workGroupID = ivec3(workGroupIDLength / numWorkGroups.y / numWorkGroups.z, workGroupIDLength / numWorkGroups.x / numWorkGroups.z, workGroupIDLength / numWorkGroups.x / numWorkGroups.y);\\nint localInvocationIDZ = globalInvocationIndex / (workGroupSize.x * workGroupSize.y);\\nint localInvocationIDY = (globalInvocationIndex - localInvocationIDZ * workGroupSize.x * workGroupSize.y) / workGroupSize.x;\\nint localInvocationIDX = globalInvocationIndex - localInvocationIDZ * workGroupSize.x * workGroupSize.y - localInvocationIDY * workGroupSize.x;\\nivec3 localInvocationID = ivec3(localInvocationIDX, localInvocationIDY, localInvocationIDZ);\\nivec3 globalInvocationID = workGroupID * workGroupSize + localInvocationID;\\nint localInvocationIndex = localInvocationID.z * workGroupSize.x * workGroupSize.y\\n + localInvocationID.y * workGroupSize.x + localInvocationID.x;\\nfloat ax = 0.0;\\nfloat ay = 0.0;\\nfor (int j = 0; j < VERTEX_COUNT; j++) {if (i != j) {vec4 nextNode = getDatau_Data(j);\\nfloat vx = currentNode.x - nextNode.x;\\nfloat vy = currentNode.y - nextNode.y;\\nfloat dist = sqrt((vx * vx) + (vy * vy)) + 0.01;\\nfloat n_dist = (dist + 0.1) * u_coulombDisScale;\\nfloat direx = vx / dist;\\nfloat direy = vy / dist;\\nvec4 attributesi = getDatau_NodeAttributeArray1(i);\\nvec4 attributesj = getDatau_NodeAttributeArray1(j);\\nfloat massi = attributesi.x;\\nfloat nodeStrengthi = attributesi.z;\\nfloat nodeStrengthj = attributesj.z;\\nfloat nodeStrength = (nodeStrengthi + nodeStrengthj) / 2.0;\\nfloat param = (nodeStrength * u_factor) / (n_dist * n_dist);\\nax += direx * param;\\nay += direy * param;}}\\nreturn vec2(ax, ay);}\\nvec2 calcGravity(int i, vec4 currentNode, vec4 attributes2) {\\nivec3 workGroupSize = ivec3(1, 1, 1);\\nivec3 numWorkGroups = ivec3(1, 1, 1); \\nint globalInvocationIndex = int(floor(v_TexCoord.x * u_OutputTextureSize.x))\\n + int(floor(v_TexCoord.y * u_OutputTextureSize.y)) * int(u_OutputTextureSize.x);\\nint workGroupIDLength = globalInvocationIndex / (workGroupSize.x * workGroupSize.y * workGroupSize.z);\\nivec3 workGroupID = ivec3(workGroupIDLength / numWorkGroups.y / numWorkGroups.z, workGroupIDLength / numWorkGroups.x / numWorkGroups.z, workGroupIDLength / numWorkGroups.x / numWorkGroups.y);\\nint localInvocationIDZ = globalInvocationIndex / (workGroupSize.x * workGroupSize.y);\\nint localInvocationIDY = (globalInvocationIndex - localInvocationIDZ * workGroupSize.x * workGroupSize.y) / workGroupSize.x;\\nint localInvocationIDX = globalInvocationIndex - localInvocationIDZ * workGroupSize.x * workGroupSize.y - localInvocationIDY * workGroupSize.x;\\nivec3 localInvocationID = ivec3(localInvocationIDX, localInvocationIDY, localInvocationIDZ);\\nivec3 globalInvocationID = workGroupID * workGroupSize + localInvocationID;\\nint localInvocationIndex = localInvocationID.z * workGroupSize.x * workGroupSize.y\\n + localInvocationID.y * workGroupSize.x + localInvocationID.x;\\nfloat vx = currentNode.x - attributes2.x;\\nfloat vy = currentNode.y - attributes2.y;\\nfloat ax = vx * attributes2.z;\\nfloat ay = vy * attributes2.z;\\nreturn vec2(ax, ay);}\\nvec2 calcAttractive(int i, vec4 currentNode, vec4 attributes1) {\\nivec3 workGroupSize = ivec3(1, 1, 1);\\nivec3 numWorkGroups = ivec3(1, 1, 1); \\nint globalInvocationIndex = int(floor(v_TexCoord.x * u_OutputTextureSize.x))\\n + int(floor(v_TexCoord.y * u_OutputTextureSize.y)) * int(u_OutputTextureSize.x);\\nint workGroupIDLength = globalInvocationIndex / (workGroupSize.x * workGroupSize.y * workGroupSize.z);\\nivec3 workGroupID = ivec3(workGroupIDLength / numWorkGroups.y / numWorkGroups.z, workGroupIDLength / numWorkGroups.x / numWorkGroups.z, workGroupIDLength / numWorkGroups.x / numWorkGroups.y);\\nint localInvocationIDZ = globalInvocationIndex / (workGroupSize.x * workGroupSize.y);\\nint localInvocationIDY = (globalInvocationIndex - localInvocationIDZ * workGroupSize.x * workGroupSize.y) / workGroupSize.x;\\nint localInvocationIDX = globalInvocationIndex - localInvocationIDZ * workGroupSize.x * workGroupSize.y - localInvocationIDY * workGroupSize.x;\\nivec3 localInvocationID = ivec3(localInvocationIDX, localInvocationIDY, localInvocationIDZ);\\nivec3 globalInvocationID = workGroupID * workGroupSize + localInvocationID;\\nint localInvocationIndex = localInvocationID.z * workGroupSize.x * workGroupSize.y\\n + localInvocationID.y * workGroupSize.x + localInvocationID.x;\\nfloat mass = attributes1.x;\\nfloat ax = 0.0;\\nfloat ay = 0.0;\\nivec2 compressed = unpack_float(currentNode.z);\\nint length = compressed.x;\\nint arr_offset = compressed.y;\\nvec4 node_buffer;\\nfor (int p = 0; p < MAX_EDGE_PER_VERTEX; p++) {if (p >= length) {break;}\\nint arr_idx = arr_offset + (4 * p);\\nint buf_offset = arr_idx - ((arr_idx / 4) * 4);\\nif ((p == 0) || (buf_offset == 0)) {node_buffer = getDatau_Data(int(arr_idx / 4));}\\nfloat float_j = node_buffer.x;\\nvec4 nextNode = getDatau_Data(int(float_j));\\nfloat vx = nextNode.x - currentNode.x;\\nfloat vy = nextNode.y - currentNode.y;\\nfloat dist = sqrt((vx * vx) + (vy * vy)) + 0.01;\\nfloat direx = vx / dist;\\nfloat direy = vy / dist;\\nfloat edgeLength = node_buffer.y;\\nfloat edgeStrength = node_buffer.z;\\nfloat diff = edgeLength - dist;\\nfloat param = (diff * edgeStrength) / mass;\\nax -= direx * param;\\nay -= direy * param;}\\nreturn vec2(ax, ay);}\\nvoid main() {\\nivec3 workGroupSize = ivec3(1, 1, 1);\\nivec3 numWorkGroups = ivec3(1, 1, 1); \\nint globalInvocationIndex = int(floor(v_TexCoord.x * u_OutputTextureSize.x))\\n + int(floor(v_TexCoord.y * u_OutputTextureSize.y)) * int(u_OutputTextureSize.x);\\nint workGroupIDLength = globalInvocationIndex / (workGroupSize.x * workGroupSize.y * workGroupSize.z);\\nivec3 workGroupID = ivec3(workGroupIDLength / numWorkGroups.y / numWorkGroups.z, workGroupIDLength / numWorkGroups.x / numWorkGroups.z, workGroupIDLength / numWorkGroups.x / numWorkGroups.y);\\nint localInvocationIDZ = globalInvocationIndex / (workGroupSize.x * workGroupSize.y);\\nint localInvocationIDY = (globalInvocationIndex - localInvocationIDZ * workGroupSize.x * workGroupSize.y) / workGroupSize.x;\\nint localInvocationIDX = globalInvocationIndex - localInvocationIDZ * workGroupSize.x * workGroupSize.y - localInvocationIDY * workGroupSize.x;\\nivec3 localInvocationID = ivec3(localInvocationIDX, localInvocationIDY, localInvocationIDZ);\\nivec3 globalInvocationID = workGroupID * workGroupSize + localInvocationID;\\nint localInvocationIndex = localInvocationID.z * workGroupSize.x * workGroupSize.y\\n + localInvocationID.y * workGroupSize.x + localInvocationID.x;\\nint i = globalInvocationID.x;\\nvec4 currentNode = getDatau_Data(i);\\nvec4 movement = getDatau_AveMovement(0.0);\\nfloat ax = 0.0;\\nfloat ay = 0.0;\\nif ((i >= VERTEX_COUNT) || (movement.x < u_minMovement)) {gl_FragColor = vec4(currentNode);\\nreturn ;}\\nvec4 nodeAttributes1 = getDatau_NodeAttributeArray1(i);\\nvec4 nodeAttributes2 = getDatau_NodeAttributeArray2(i);\\nvec2 repulsive = calcRepulsive(i, currentNode);\\nax += repulsive.x;\\nay += repulsive.y;\\nvec2 attractive = calcAttractive(i, currentNode, nodeAttributes1);\\nax += attractive.x;\\nay += attractive.y;\\nvec2 gravity = calcGravity(i, currentNode, nodeAttributes2);\\nax -= gravity.x;\\nay -= gravity.y;\\nfloat param = u_interval * u_damping;\\nfloat vx = ax * param;\\nfloat vy = ay * param;\\nfloat vlength = sqrt((vx * vx) + (vy * vy)) + 0.0001;\\nif (vlength > u_maxSpeed) {float param2 = u_maxSpeed / vlength;\\nvx = param2 * vx;\\nvy = param2 * vy;}\\nif ((nodeAttributes1.w != 0.0) && (nodeAttributes2.w != 0.0)) {gl_FragColor = vec4(vec4(nodeAttributes1.w, nodeAttributes2.w, currentNode.z, 0.0));}else {float distx = vx * u_interval;\\nfloat disty = vy * u_interval;\\nfloat distLength = sqrt((distx * distx) + (disty * disty));\\ngl_FragColor = vec4(vec4(currentNode.x + distx, currentNode.y + disty, currentNode.z, distLength));}if (gWebGPUDebug) {\\n gl_FragColor = gWebGPUDebugOutput;\\n}}\\n\"},\"context\":{\"name\":\"\",\"dispatch\":[1,1,1],\"threadGroupSize\":[1,1,1],\"maxIteration\":1,\"defines\":[{\"name\":\"MAX_EDGE_PER_VERTEX\",\"type\":\"Float\",\"runtime\":true},{\"name\":\"VERTEX_COUNT\",\"type\":\"Float\",\"runtime\":true},{\"name\":\"SHIFT_20\",\"type\":\"Float\",\"value\":1048576,\"runtime\":false}],\"uniforms\":[{\"name\":\"u_Data\",\"type\":\"vec4<f32>[]\",\"storageClass\":\"StorageBuffer\",\"readonly\":false,\"writeonly\":false,\"size\":[1,1]},{\"name\":\"u_damping\",\"type\":\"Float\",\"storageClass\":\"Uniform\",\"readonly\":true,\"writeonly\":false,\"size\":[1,1]},{\"name\":\"u_maxSpeed\",\"type\":\"Float\",\"storageClass\":\"Uniform\",\"readonly\":true,\"writeonly\":false,\"size\":[1,1]},{\"name\":\"u_minMovement\",\"type\":\"Float\",\"storageClass\":\"Uniform\",\"readonly\":true,\"writeonly\":false,\"size\":[1,1]},{\"name\":\"u_AveMovement\",\"type\":\"vec4<f32>[]\",\"storageClass\":\"StorageBuffer\",\"readonly\":true,\"writeonly\":false,\"size\":[1,1]},{\"name\":\"u_coulombDisScale\",\"type\":\"Float\",\"storageClass\":\"Uniform\",\"readonly\":true,\"writeonly\":false,\"size\":[1,1]},{\"name\":\"u_factor\",\"type\":\"Float\",\"storageClass\":\"Uniform\",\"readonly\":true,\"writeonly\":false,\"size\":[1,1]},{\"name\":\"u_NodeAttributeArray1\",\"type\":\"vec4<f32>[]\",\"storageClass\":\"StorageBuffer\",\"readonly\":true,\"writeonly\":false,\"size\":[1,1]},{\"name\":\"u_NodeAttributeArray2\",\"type\":\"vec4<f32>[]\",\"storageClass\":\"StorageBuffer\",\"readonly\":true,\"writeonly\":false,\"size\":[1,1]},{\"name\":\"u_interval\",\"type\":\"Float\",\"storageClass\":\"Uniform\",\"readonly\":true,\"writeonly\":false,\"size\":[1,1]}],\"globalDeclarations\":[],\"output\":{\"name\":\"u_Data\",\"size\":[1,1],\"length\":1},\"needPingpong\":true}}";
|
|
3
|
-
export declare const aveMovementCode = "\nconst VERTEX_COUNT;\n@numthreads(1, 1, 1)\nclass CalcAveMovement {\n @in\n u_Data: vec4[];\n @in\n u_iter: float;\n @in @out\n u_AveMovement: vec4[];\n @main\n compute() {\n let movement = 0;\n for (let j: int = 0; j < VERTEX_COUNT; j++) {\n const vertex = this.u_Data[j];\n movement += vertex[3];\n }\n movement = movement / float(VERTEX_COUNT);\n this.u_AveMovement[0] = [movement, 0, 0, 0];\n }\n}\n";
|
|
4
|
-
export declare const aveMovementBundle = "{\"shaders\":{\"WGSL\":\"\",\"GLSL450\":\"\",\"GLSL100\":\"\\n\\nfloat epsilon = 0.00001;\\nvec2 addrTranslation_1Dto2D(float address1D, vec2 texSize) {\\n vec2 conv_const = vec2(1.0 / texSize.x, 1.0 / (texSize.x * texSize.y));\\n vec2 normAddr2D = float(address1D) * conv_const;\\n return vec2(fract(normAddr2D.x + epsilon), normAddr2D.y);\\n}\\n\\nvoid barrier() {}\\n \\n\\nuniform vec2 u_OutputTextureSize;\\nuniform int u_OutputTexelCount;\\nvarying vec2 v_TexCoord;\\n\\nbool gWebGPUDebug = false;\\nvec4 gWebGPUDebugOutput = vec4(0.0);\\n\\n#define VERTEX_COUNT __DefineValuePlaceholder__VERTEX_COUNT\\n\\nuniform sampler2D u_Data;\\nuniform vec2 u_DataSize;\\nvec4 getDatau_Data(vec2 address2D) {\\n return vec4(texture2D(u_Data, address2D).rgba);\\n}\\nvec4 getDatau_Data(float address1D) {\\n return getDatau_Data(addrTranslation_1Dto2D(address1D, u_DataSize));\\n}\\nvec4 getDatau_Data(int address1D) {\\n return getDatau_Data(float(address1D));\\n}\\nuniform float u_iter;\\nuniform sampler2D u_AveMovement;\\nuniform vec2 u_AveMovementSize;\\nvec4 getDatau_AveMovement(vec2 address2D) {\\n return vec4(texture2D(u_AveMovement, address2D).rgba);\\n}\\nvec4 getDatau_AveMovement(float address1D) {\\n return getDatau_AveMovement(addrTranslation_1Dto2D(address1D, u_AveMovementSize));\\n}\\nvec4 getDatau_AveMovement(int address1D) {\\n return getDatau_AveMovement(float(address1D));\\n}\\nvoid main() {\\nivec3 workGroupSize = ivec3(1, 1, 1);\\nivec3 numWorkGroups = ivec3(1, 1, 1); \\nint globalInvocationIndex = int(floor(v_TexCoord.x * u_OutputTextureSize.x))\\n + int(floor(v_TexCoord.y * u_OutputTextureSize.y)) * int(u_OutputTextureSize.x);\\nint workGroupIDLength = globalInvocationIndex / (workGroupSize.x * workGroupSize.y * workGroupSize.z);\\nivec3 workGroupID = ivec3(workGroupIDLength / numWorkGroups.y / numWorkGroups.z, workGroupIDLength / numWorkGroups.x / numWorkGroups.z, workGroupIDLength / numWorkGroups.x / numWorkGroups.y);\\nint localInvocationIDZ = globalInvocationIndex / (workGroupSize.x * workGroupSize.y);\\nint localInvocationIDY = (globalInvocationIndex - localInvocationIDZ * workGroupSize.x * workGroupSize.y) / workGroupSize.x;\\nint localInvocationIDX = globalInvocationIndex - localInvocationIDZ * workGroupSize.x * workGroupSize.y - localInvocationIDY * workGroupSize.x;\\nivec3 localInvocationID = ivec3(localInvocationIDX, localInvocationIDY, localInvocationIDZ);\\nivec3 globalInvocationID = workGroupID * workGroupSize + localInvocationID;\\nint localInvocationIndex = localInvocationID.z * workGroupSize.x * workGroupSize.y\\n + localInvocationID.y * workGroupSize.x + localInvocationID.x;\\nfloat movement = 0.0;\\nfor (int j = 0; j < VERTEX_COUNT; j++) {vec4 vertex = getDatau_Data(j);\\nmovement += vertex.w;}\\nmovement = movement / float(VERTEX_COUNT);\\ngl_FragColor = vec4(vec4(movement, 0.0, 0.0, 0.0));if (gWebGPUDebug) {\\n gl_FragColor = gWebGPUDebugOutput;\\n}}\\n\"},\"context\":{\"name\":\"\",\"dispatch\":[1,1,1],\"threadGroupSize\":[1,1,1],\"maxIteration\":1,\"defines\":[{\"name\":\"VERTEX_COUNT\",\"type\":\"Float\",\"runtime\":true}],\"uniforms\":[{\"name\":\"u_Data\",\"type\":\"vec4<f32>[]\",\"storageClass\":\"StorageBuffer\",\"readonly\":true,\"writeonly\":false,\"size\":[1,1]},{\"name\":\"u_iter\",\"type\":\"Float\",\"storageClass\":\"Uniform\",\"readonly\":true,\"writeonly\":false,\"size\":[1,1]},{\"name\":\"u_AveMovement\",\"type\":\"vec4<f32>[]\",\"storageClass\":\"StorageBuffer\",\"readonly\":false,\"writeonly\":false,\"size\":[1,1]}],\"globalDeclarations\":[],\"output\":{\"name\":\"u_AveMovement\",\"size\":[1,1],\"length\":1},\"needPingpong\":true}}";
|
|
@@ -1,218 +0,0 @@
|
|
|
1
|
-
export const gForceCode = `
|
|
2
|
-
import { globalInvocationID } from 'g-webgpu';
|
|
3
|
-
|
|
4
|
-
const MAX_EDGE_PER_VERTEX;
|
|
5
|
-
const VERTEX_COUNT;
|
|
6
|
-
const SHIFT_20 = 1048576;
|
|
7
|
-
|
|
8
|
-
@numthreads(1, 1, 1)
|
|
9
|
-
class GGForce {
|
|
10
|
-
@in @out
|
|
11
|
-
u_Data: vec4[];
|
|
12
|
-
|
|
13
|
-
@in
|
|
14
|
-
u_damping: float;
|
|
15
|
-
|
|
16
|
-
@in
|
|
17
|
-
u_maxSpeed: float;
|
|
18
|
-
|
|
19
|
-
@in
|
|
20
|
-
u_minMovement: float;
|
|
21
|
-
|
|
22
|
-
@in
|
|
23
|
-
u_AveMovement: vec4[];
|
|
24
|
-
|
|
25
|
-
@in
|
|
26
|
-
u_coulombDisScale: float;
|
|
27
|
-
|
|
28
|
-
@in
|
|
29
|
-
u_factor: float;
|
|
30
|
-
|
|
31
|
-
@in
|
|
32
|
-
u_NodeAttributeArray1: vec4[];
|
|
33
|
-
|
|
34
|
-
@in
|
|
35
|
-
u_NodeAttributeArray2: vec4[];
|
|
36
|
-
|
|
37
|
-
@in
|
|
38
|
-
u_interval: float;
|
|
39
|
-
|
|
40
|
-
unpack_float(packedValue: float): ivec2 {
|
|
41
|
-
const packedIntValue = int(packedValue);
|
|
42
|
-
const v0 = packedIntValue / SHIFT_20;
|
|
43
|
-
return [v0, packedIntValue - v0 * SHIFT_20];
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
calcRepulsive(i: int, currentNode: vec4): vec2 {
|
|
47
|
-
let ax = 0, ay = 0;
|
|
48
|
-
for (let j: int = 0; j < VERTEX_COUNT; j++) {
|
|
49
|
-
if (i != j) {
|
|
50
|
-
const nextNode = this.u_Data[j];
|
|
51
|
-
const vx = currentNode[0] - nextNode[0];
|
|
52
|
-
const vy = currentNode[1] - nextNode[1];
|
|
53
|
-
const dist = sqrt(vx * vx + vy * vy) + 0.01;
|
|
54
|
-
const n_dist = (dist + 0.1) * this.u_coulombDisScale;
|
|
55
|
-
const direx = vx / dist;
|
|
56
|
-
const direy = vy / dist;
|
|
57
|
-
const attributesi = this.u_NodeAttributeArray1[i];
|
|
58
|
-
const attributesj = this.u_NodeAttributeArray1[j];
|
|
59
|
-
const massi = attributesi[0];
|
|
60
|
-
const nodeStrengthi = attributesi[2];
|
|
61
|
-
const nodeStrengthj = attributesj[2];
|
|
62
|
-
const nodeStrength = (nodeStrengthi + nodeStrengthj) / 2;
|
|
63
|
-
// const param = nodeStrength * this.u_factor / (n_dist * n_dist * massi);
|
|
64
|
-
const param = nodeStrength * this.u_factor / (n_dist * n_dist);
|
|
65
|
-
ax += direx * param;
|
|
66
|
-
ay += direy * param;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
return [ax, ay];
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
calcGravity(i: int, currentNode: vec4, attributes2: vec4): vec2 {
|
|
73
|
-
// note: attributes2 = [centerX, centerY, gravity, 0]
|
|
74
|
-
|
|
75
|
-
const vx = currentNode[0] - attributes2[0];
|
|
76
|
-
const vy = currentNode[1] - attributes2[1];
|
|
77
|
-
|
|
78
|
-
const ax = vx * attributes2[2];
|
|
79
|
-
const ay = vy * attributes2[2];
|
|
80
|
-
|
|
81
|
-
return [ax, ay];
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
calcAttractive(i: int, currentNode: vec4, attributes1: vec4): vec2 {
|
|
85
|
-
// note: attributes1 = [mass, degree, nodeSterngth, 0]
|
|
86
|
-
|
|
87
|
-
const mass = attributes1[0];
|
|
88
|
-
let ax = 0, ay = 0;
|
|
89
|
-
// const arr_offset = int(floor(currentNode[2] + 0.5));
|
|
90
|
-
// const length = int(floor(currentNode[3] + 0.5));
|
|
91
|
-
|
|
92
|
-
const compressed = this.unpack_float(currentNode[2]);
|
|
93
|
-
const length = compressed[0];
|
|
94
|
-
const arr_offset = compressed[1];
|
|
95
|
-
|
|
96
|
-
const node_buffer: vec4;
|
|
97
|
-
for (let p: int = 0; p < MAX_EDGE_PER_VERTEX; p++) {
|
|
98
|
-
if (p >= length) break;
|
|
99
|
-
const arr_idx = arr_offset + 4 * p; // i 节点的第 p 条边开始的小格子位置
|
|
100
|
-
const buf_offset = arr_idx - arr_idx / 4 * 4;
|
|
101
|
-
if (p == 0 || buf_offset == 0) {
|
|
102
|
-
node_buffer = this.u_Data[int(arr_idx / 4)]; // 大格子,大格子位置=小个子位置 / 4,
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
let float_j: float = node_buffer[0];
|
|
106
|
-
|
|
107
|
-
const nextNode = this.u_Data[int(float_j)];
|
|
108
|
-
const vx = nextNode[0] - currentNode[0];
|
|
109
|
-
const vy = nextNode[1] - currentNode[1];
|
|
110
|
-
const dist = sqrt(vx * vx + vy * vy) + 0.01;
|
|
111
|
-
const direx = vx / dist;
|
|
112
|
-
const direy = vy / dist;
|
|
113
|
-
const edgeLength = node_buffer[1];
|
|
114
|
-
const edgeStrength = node_buffer[2];
|
|
115
|
-
const diff: float = edgeLength - dist;//edgeLength
|
|
116
|
-
// const param = diff * this.u_stiffness / mass; //
|
|
117
|
-
const param = diff * edgeStrength / mass; //
|
|
118
|
-
ax -= direx * param;
|
|
119
|
-
ay -= direy * param;
|
|
120
|
-
}
|
|
121
|
-
return [ax, ay];
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
@main
|
|
125
|
-
compute() {
|
|
126
|
-
const i = globalInvocationID.x;
|
|
127
|
-
const currentNode = this.u_Data[i];
|
|
128
|
-
const movement = u_AveMovement[0];
|
|
129
|
-
let ax = 0, ay = 0;
|
|
130
|
-
|
|
131
|
-
if (i >= VERTEX_COUNT || movement.x < u_minMovement) {
|
|
132
|
-
this.u_Data[i] = currentNode;
|
|
133
|
-
return;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
// 每个节点属性占两个数组中各一格
|
|
137
|
-
// [mass, degree, nodeStrength, fx]
|
|
138
|
-
const nodeAttributes1 = this.u_NodeAttributeArray1[i];
|
|
139
|
-
// [centerX, centerY, centerGravity, fy]
|
|
140
|
-
const nodeAttributes2 = this.u_NodeAttributeArray2[i];
|
|
141
|
-
|
|
142
|
-
// repulsive
|
|
143
|
-
const repulsive = this.calcRepulsive(i, currentNode);
|
|
144
|
-
ax += repulsive[0];
|
|
145
|
-
ay += repulsive[1];
|
|
146
|
-
|
|
147
|
-
// attractive
|
|
148
|
-
const attractive = this.calcAttractive(i, currentNode, nodeAttributes1);
|
|
149
|
-
ax += attractive[0];
|
|
150
|
-
ay += attractive[1];
|
|
151
|
-
|
|
152
|
-
// gravity
|
|
153
|
-
const gravity = this.calcGravity(i, currentNode, nodeAttributes2);
|
|
154
|
-
ax -= gravity[0];
|
|
155
|
-
ay -= gravity[1];
|
|
156
|
-
|
|
157
|
-
// speed
|
|
158
|
-
const param = this.u_interval * this.u_damping;
|
|
159
|
-
let vx = ax * param;
|
|
160
|
-
let vy = ay * param;
|
|
161
|
-
const vlength = sqrt(vx * vx + vy * vy) + 0.0001;
|
|
162
|
-
if (vlength > this.u_maxSpeed) {
|
|
163
|
-
const param2 = this.u_maxSpeed / vlength;
|
|
164
|
-
vx = param2 * vx;
|
|
165
|
-
vy = param2 * vy;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
// move
|
|
169
|
-
if (nodeAttributes1[3] != 0 && nodeAttributes2[3] != 0) {
|
|
170
|
-
this.u_Data[i] = [
|
|
171
|
-
nodeAttributes1[3],
|
|
172
|
-
nodeAttributes2[3],
|
|
173
|
-
currentNode[2],
|
|
174
|
-
0
|
|
175
|
-
];
|
|
176
|
-
} else {
|
|
177
|
-
const distx = vx * this.u_interval;
|
|
178
|
-
const disty = vy * this.u_interval;
|
|
179
|
-
const distLength = sqrt(distx * distx + disty * disty);
|
|
180
|
-
this.u_Data[i] = [
|
|
181
|
-
currentNode[0] + distx,
|
|
182
|
-
currentNode[1] + disty,
|
|
183
|
-
currentNode[2],
|
|
184
|
-
distLength
|
|
185
|
-
];
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
// the avarage move distance
|
|
189
|
-
// need to share memory
|
|
190
|
-
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
`;
|
|
194
|
-
export const gForceBundle = `{"shaders":{"WGSL":"","GLSL450":"","GLSL100":"\\n\\nfloat epsilon = 0.00001;\\nvec2 addrTranslation_1Dto2D(float address1D, vec2 texSize) {\\n vec2 conv_const = vec2(1.0 / texSize.x, 1.0 / (texSize.x * texSize.y));\\n vec2 normAddr2D = float(address1D) * conv_const;\\n return vec2(fract(normAddr2D.x + epsilon), normAddr2D.y);\\n}\\n\\nvoid barrier() {}\\n \\n\\nuniform vec2 u_OutputTextureSize;\\nuniform int u_OutputTexelCount;\\nvarying vec2 v_TexCoord;\\n\\nbool gWebGPUDebug = false;\\nvec4 gWebGPUDebugOutput = vec4(0.0);\\n\\n#define MAX_EDGE_PER_VERTEX __DefineValuePlaceholder__MAX_EDGE_PER_VERTEX\\n#define VERTEX_COUNT __DefineValuePlaceholder__VERTEX_COUNT\\n#define SHIFT_20 1048576.0\\n\\nuniform sampler2D u_Data;\\nuniform vec2 u_DataSize;\\nvec4 getDatau_Data(vec2 address2D) {\\n return vec4(texture2D(u_Data, address2D).rgba);\\n}\\nvec4 getDatau_Data(float address1D) {\\n return getDatau_Data(addrTranslation_1Dto2D(address1D, u_DataSize));\\n}\\nvec4 getDatau_Data(int address1D) {\\n return getDatau_Data(float(address1D));\\n}\\nuniform float u_damping;\\nuniform float u_maxSpeed;\\nuniform float u_minMovement;\\nuniform sampler2D u_AveMovement;\\nuniform vec2 u_AveMovementSize;\\nvec4 getDatau_AveMovement(vec2 address2D) {\\n return vec4(texture2D(u_AveMovement, address2D).rgba);\\n}\\nvec4 getDatau_AveMovement(float address1D) {\\n return getDatau_AveMovement(addrTranslation_1Dto2D(address1D, u_AveMovementSize));\\n}\\nvec4 getDatau_AveMovement(int address1D) {\\n return getDatau_AveMovement(float(address1D));\\n}\\nuniform float u_coulombDisScale;\\nuniform float u_factor;\\nuniform sampler2D u_NodeAttributeArray1;\\nuniform vec2 u_NodeAttributeArray1Size;\\nvec4 getDatau_NodeAttributeArray1(vec2 address2D) {\\n return vec4(texture2D(u_NodeAttributeArray1, address2D).rgba);\\n}\\nvec4 getDatau_NodeAttributeArray1(float address1D) {\\n return getDatau_NodeAttributeArray1(addrTranslation_1Dto2D(address1D, u_NodeAttributeArray1Size));\\n}\\nvec4 getDatau_NodeAttributeArray1(int address1D) {\\n return getDatau_NodeAttributeArray1(float(address1D));\\n}\\nuniform sampler2D u_NodeAttributeArray2;\\nuniform vec2 u_NodeAttributeArray2Size;\\nvec4 getDatau_NodeAttributeArray2(vec2 address2D) {\\n return vec4(texture2D(u_NodeAttributeArray2, address2D).rgba);\\n}\\nvec4 getDatau_NodeAttributeArray2(float address1D) {\\n return getDatau_NodeAttributeArray2(addrTranslation_1Dto2D(address1D, u_NodeAttributeArray2Size));\\n}\\nvec4 getDatau_NodeAttributeArray2(int address1D) {\\n return getDatau_NodeAttributeArray2(float(address1D));\\n}\\nuniform float u_interval;\\nivec2 unpack_float(float packedValue) {\\nivec3 workGroupSize = ivec3(1, 1, 1);\\nivec3 numWorkGroups = ivec3(1, 1, 1); \\nint globalInvocationIndex = int(floor(v_TexCoord.x * u_OutputTextureSize.x))\\n + int(floor(v_TexCoord.y * u_OutputTextureSize.y)) * int(u_OutputTextureSize.x);\\nint workGroupIDLength = globalInvocationIndex / (workGroupSize.x * workGroupSize.y * workGroupSize.z);\\nivec3 workGroupID = ivec3(workGroupIDLength / numWorkGroups.y / numWorkGroups.z, workGroupIDLength / numWorkGroups.x / numWorkGroups.z, workGroupIDLength / numWorkGroups.x / numWorkGroups.y);\\nint localInvocationIDZ = globalInvocationIndex / (workGroupSize.x * workGroupSize.y);\\nint localInvocationIDY = (globalInvocationIndex - localInvocationIDZ * workGroupSize.x * workGroupSize.y) / workGroupSize.x;\\nint localInvocationIDX = globalInvocationIndex - localInvocationIDZ * workGroupSize.x * workGroupSize.y - localInvocationIDY * workGroupSize.x;\\nivec3 localInvocationID = ivec3(localInvocationIDX, localInvocationIDY, localInvocationIDZ);\\nivec3 globalInvocationID = workGroupID * workGroupSize + localInvocationID;\\nint localInvocationIndex = localInvocationID.z * workGroupSize.x * workGroupSize.y\\n + localInvocationID.y * workGroupSize.x + localInvocationID.x;\\nint packedIntValue = int(packedValue);\\nint v0 = packedIntValue / int(SHIFT_20);\\nreturn ivec2(v0, packedIntValue - (v0 * int(SHIFT_20)));}\\nvec2 calcRepulsive(int i, vec4 currentNode) {\\nivec3 workGroupSize = ivec3(1, 1, 1);\\nivec3 numWorkGroups = ivec3(1, 1, 1); \\nint globalInvocationIndex = int(floor(v_TexCoord.x * u_OutputTextureSize.x))\\n + int(floor(v_TexCoord.y * u_OutputTextureSize.y)) * int(u_OutputTextureSize.x);\\nint workGroupIDLength = globalInvocationIndex / (workGroupSize.x * workGroupSize.y * workGroupSize.z);\\nivec3 workGroupID = ivec3(workGroupIDLength / numWorkGroups.y / numWorkGroups.z, workGroupIDLength / numWorkGroups.x / numWorkGroups.z, workGroupIDLength / numWorkGroups.x / numWorkGroups.y);\\nint localInvocationIDZ = globalInvocationIndex / (workGroupSize.x * workGroupSize.y);\\nint localInvocationIDY = (globalInvocationIndex - localInvocationIDZ * workGroupSize.x * workGroupSize.y) / workGroupSize.x;\\nint localInvocationIDX = globalInvocationIndex - localInvocationIDZ * workGroupSize.x * workGroupSize.y - localInvocationIDY * workGroupSize.x;\\nivec3 localInvocationID = ivec3(localInvocationIDX, localInvocationIDY, localInvocationIDZ);\\nivec3 globalInvocationID = workGroupID * workGroupSize + localInvocationID;\\nint localInvocationIndex = localInvocationID.z * workGroupSize.x * workGroupSize.y\\n + localInvocationID.y * workGroupSize.x + localInvocationID.x;\\nfloat ax = 0.0;\\nfloat ay = 0.0;\\nfor (int j = 0; j < VERTEX_COUNT; j++) {if (i != j) {vec4 nextNode = getDatau_Data(j);\\nfloat vx = currentNode.x - nextNode.x;\\nfloat vy = currentNode.y - nextNode.y;\\nfloat dist = sqrt((vx * vx) + (vy * vy)) + 0.01;\\nfloat n_dist = (dist + 0.1) * u_coulombDisScale;\\nfloat direx = vx / dist;\\nfloat direy = vy / dist;\\nvec4 attributesi = getDatau_NodeAttributeArray1(i);\\nvec4 attributesj = getDatau_NodeAttributeArray1(j);\\nfloat massi = attributesi.x;\\nfloat nodeStrengthi = attributesi.z;\\nfloat nodeStrengthj = attributesj.z;\\nfloat nodeStrength = (nodeStrengthi + nodeStrengthj) / 2.0;\\nfloat param = (nodeStrength * u_factor) / (n_dist * n_dist);\\nax += direx * param;\\nay += direy * param;}}\\nreturn vec2(ax, ay);}\\nvec2 calcGravity(int i, vec4 currentNode, vec4 attributes2) {\\nivec3 workGroupSize = ivec3(1, 1, 1);\\nivec3 numWorkGroups = ivec3(1, 1, 1); \\nint globalInvocationIndex = int(floor(v_TexCoord.x * u_OutputTextureSize.x))\\n + int(floor(v_TexCoord.y * u_OutputTextureSize.y)) * int(u_OutputTextureSize.x);\\nint workGroupIDLength = globalInvocationIndex / (workGroupSize.x * workGroupSize.y * workGroupSize.z);\\nivec3 workGroupID = ivec3(workGroupIDLength / numWorkGroups.y / numWorkGroups.z, workGroupIDLength / numWorkGroups.x / numWorkGroups.z, workGroupIDLength / numWorkGroups.x / numWorkGroups.y);\\nint localInvocationIDZ = globalInvocationIndex / (workGroupSize.x * workGroupSize.y);\\nint localInvocationIDY = (globalInvocationIndex - localInvocationIDZ * workGroupSize.x * workGroupSize.y) / workGroupSize.x;\\nint localInvocationIDX = globalInvocationIndex - localInvocationIDZ * workGroupSize.x * workGroupSize.y - localInvocationIDY * workGroupSize.x;\\nivec3 localInvocationID = ivec3(localInvocationIDX, localInvocationIDY, localInvocationIDZ);\\nivec3 globalInvocationID = workGroupID * workGroupSize + localInvocationID;\\nint localInvocationIndex = localInvocationID.z * workGroupSize.x * workGroupSize.y\\n + localInvocationID.y * workGroupSize.x + localInvocationID.x;\\nfloat vx = currentNode.x - attributes2.x;\\nfloat vy = currentNode.y - attributes2.y;\\nfloat ax = vx * attributes2.z;\\nfloat ay = vy * attributes2.z;\\nreturn vec2(ax, ay);}\\nvec2 calcAttractive(int i, vec4 currentNode, vec4 attributes1) {\\nivec3 workGroupSize = ivec3(1, 1, 1);\\nivec3 numWorkGroups = ivec3(1, 1, 1); \\nint globalInvocationIndex = int(floor(v_TexCoord.x * u_OutputTextureSize.x))\\n + int(floor(v_TexCoord.y * u_OutputTextureSize.y)) * int(u_OutputTextureSize.x);\\nint workGroupIDLength = globalInvocationIndex / (workGroupSize.x * workGroupSize.y * workGroupSize.z);\\nivec3 workGroupID = ivec3(workGroupIDLength / numWorkGroups.y / numWorkGroups.z, workGroupIDLength / numWorkGroups.x / numWorkGroups.z, workGroupIDLength / numWorkGroups.x / numWorkGroups.y);\\nint localInvocationIDZ = globalInvocationIndex / (workGroupSize.x * workGroupSize.y);\\nint localInvocationIDY = (globalInvocationIndex - localInvocationIDZ * workGroupSize.x * workGroupSize.y) / workGroupSize.x;\\nint localInvocationIDX = globalInvocationIndex - localInvocationIDZ * workGroupSize.x * workGroupSize.y - localInvocationIDY * workGroupSize.x;\\nivec3 localInvocationID = ivec3(localInvocationIDX, localInvocationIDY, localInvocationIDZ);\\nivec3 globalInvocationID = workGroupID * workGroupSize + localInvocationID;\\nint localInvocationIndex = localInvocationID.z * workGroupSize.x * workGroupSize.y\\n + localInvocationID.y * workGroupSize.x + localInvocationID.x;\\nfloat mass = attributes1.x;\\nfloat ax = 0.0;\\nfloat ay = 0.0;\\nivec2 compressed = unpack_float(currentNode.z);\\nint length = compressed.x;\\nint arr_offset = compressed.y;\\nvec4 node_buffer;\\nfor (int p = 0; p < MAX_EDGE_PER_VERTEX; p++) {if (p >= length) {break;}\\nint arr_idx = arr_offset + (4 * p);\\nint buf_offset = arr_idx - ((arr_idx / 4) * 4);\\nif ((p == 0) || (buf_offset == 0)) {node_buffer = getDatau_Data(int(arr_idx / 4));}\\nfloat float_j = node_buffer.x;\\nvec4 nextNode = getDatau_Data(int(float_j));\\nfloat vx = nextNode.x - currentNode.x;\\nfloat vy = nextNode.y - currentNode.y;\\nfloat dist = sqrt((vx * vx) + (vy * vy)) + 0.01;\\nfloat direx = vx / dist;\\nfloat direy = vy / dist;\\nfloat edgeLength = node_buffer.y;\\nfloat edgeStrength = node_buffer.z;\\nfloat diff = edgeLength - dist;\\nfloat param = (diff * edgeStrength) / mass;\\nax -= direx * param;\\nay -= direy * param;}\\nreturn vec2(ax, ay);}\\nvoid main() {\\nivec3 workGroupSize = ivec3(1, 1, 1);\\nivec3 numWorkGroups = ivec3(1, 1, 1); \\nint globalInvocationIndex = int(floor(v_TexCoord.x * u_OutputTextureSize.x))\\n + int(floor(v_TexCoord.y * u_OutputTextureSize.y)) * int(u_OutputTextureSize.x);\\nint workGroupIDLength = globalInvocationIndex / (workGroupSize.x * workGroupSize.y * workGroupSize.z);\\nivec3 workGroupID = ivec3(workGroupIDLength / numWorkGroups.y / numWorkGroups.z, workGroupIDLength / numWorkGroups.x / numWorkGroups.z, workGroupIDLength / numWorkGroups.x / numWorkGroups.y);\\nint localInvocationIDZ = globalInvocationIndex / (workGroupSize.x * workGroupSize.y);\\nint localInvocationIDY = (globalInvocationIndex - localInvocationIDZ * workGroupSize.x * workGroupSize.y) / workGroupSize.x;\\nint localInvocationIDX = globalInvocationIndex - localInvocationIDZ * workGroupSize.x * workGroupSize.y - localInvocationIDY * workGroupSize.x;\\nivec3 localInvocationID = ivec3(localInvocationIDX, localInvocationIDY, localInvocationIDZ);\\nivec3 globalInvocationID = workGroupID * workGroupSize + localInvocationID;\\nint localInvocationIndex = localInvocationID.z * workGroupSize.x * workGroupSize.y\\n + localInvocationID.y * workGroupSize.x + localInvocationID.x;\\nint i = globalInvocationID.x;\\nvec4 currentNode = getDatau_Data(i);\\nvec4 movement = getDatau_AveMovement(0.0);\\nfloat ax = 0.0;\\nfloat ay = 0.0;\\nif ((i >= VERTEX_COUNT) || (movement.x < u_minMovement)) {gl_FragColor = vec4(currentNode);\\nreturn ;}\\nvec4 nodeAttributes1 = getDatau_NodeAttributeArray1(i);\\nvec4 nodeAttributes2 = getDatau_NodeAttributeArray2(i);\\nvec2 repulsive = calcRepulsive(i, currentNode);\\nax += repulsive.x;\\nay += repulsive.y;\\nvec2 attractive = calcAttractive(i, currentNode, nodeAttributes1);\\nax += attractive.x;\\nay += attractive.y;\\nvec2 gravity = calcGravity(i, currentNode, nodeAttributes2);\\nax -= gravity.x;\\nay -= gravity.y;\\nfloat param = u_interval * u_damping;\\nfloat vx = ax * param;\\nfloat vy = ay * param;\\nfloat vlength = sqrt((vx * vx) + (vy * vy)) + 0.0001;\\nif (vlength > u_maxSpeed) {float param2 = u_maxSpeed / vlength;\\nvx = param2 * vx;\\nvy = param2 * vy;}\\nif ((nodeAttributes1.w != 0.0) && (nodeAttributes2.w != 0.0)) {gl_FragColor = vec4(vec4(nodeAttributes1.w, nodeAttributes2.w, currentNode.z, 0.0));}else {float distx = vx * u_interval;\\nfloat disty = vy * u_interval;\\nfloat distLength = sqrt((distx * distx) + (disty * disty));\\ngl_FragColor = vec4(vec4(currentNode.x + distx, currentNode.y + disty, currentNode.z, distLength));}if (gWebGPUDebug) {\\n gl_FragColor = gWebGPUDebugOutput;\\n}}\\n"},"context":{"name":"","dispatch":[1,1,1],"threadGroupSize":[1,1,1],"maxIteration":1,"defines":[{"name":"MAX_EDGE_PER_VERTEX","type":"Float","runtime":true},{"name":"VERTEX_COUNT","type":"Float","runtime":true},{"name":"SHIFT_20","type":"Float","value":1048576,"runtime":false}],"uniforms":[{"name":"u_Data","type":"vec4<f32>[]","storageClass":"StorageBuffer","readonly":false,"writeonly":false,"size":[1,1]},{"name":"u_damping","type":"Float","storageClass":"Uniform","readonly":true,"writeonly":false,"size":[1,1]},{"name":"u_maxSpeed","type":"Float","storageClass":"Uniform","readonly":true,"writeonly":false,"size":[1,1]},{"name":"u_minMovement","type":"Float","storageClass":"Uniform","readonly":true,"writeonly":false,"size":[1,1]},{"name":"u_AveMovement","type":"vec4<f32>[]","storageClass":"StorageBuffer","readonly":true,"writeonly":false,"size":[1,1]},{"name":"u_coulombDisScale","type":"Float","storageClass":"Uniform","readonly":true,"writeonly":false,"size":[1,1]},{"name":"u_factor","type":"Float","storageClass":"Uniform","readonly":true,"writeonly":false,"size":[1,1]},{"name":"u_NodeAttributeArray1","type":"vec4<f32>[]","storageClass":"StorageBuffer","readonly":true,"writeonly":false,"size":[1,1]},{"name":"u_NodeAttributeArray2","type":"vec4<f32>[]","storageClass":"StorageBuffer","readonly":true,"writeonly":false,"size":[1,1]},{"name":"u_interval","type":"Float","storageClass":"Uniform","readonly":true,"writeonly":false,"size":[1,1]}],"globalDeclarations":[],"output":{"name":"u_Data","size":[1,1],"length":1},"needPingpong":true}}`;
|
|
195
|
-
export const aveMovementCode = `
|
|
196
|
-
const VERTEX_COUNT;
|
|
197
|
-
@numthreads(1, 1, 1)
|
|
198
|
-
class CalcAveMovement {
|
|
199
|
-
@in
|
|
200
|
-
u_Data: vec4[];
|
|
201
|
-
@in
|
|
202
|
-
u_iter: float;
|
|
203
|
-
@in @out
|
|
204
|
-
u_AveMovement: vec4[];
|
|
205
|
-
@main
|
|
206
|
-
compute() {
|
|
207
|
-
let movement = 0;
|
|
208
|
-
for (let j: int = 0; j < VERTEX_COUNT; j++) {
|
|
209
|
-
const vertex = this.u_Data[j];
|
|
210
|
-
movement += vertex[3];
|
|
211
|
-
}
|
|
212
|
-
movement = movement / float(VERTEX_COUNT);
|
|
213
|
-
this.u_AveMovement[0] = [movement, 0, 0, 0];
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
`;
|
|
217
|
-
export const aveMovementBundle = `{"shaders":{"WGSL":"","GLSL450":"","GLSL100":"\\n\\nfloat epsilon = 0.00001;\\nvec2 addrTranslation_1Dto2D(float address1D, vec2 texSize) {\\n vec2 conv_const = vec2(1.0 / texSize.x, 1.0 / (texSize.x * texSize.y));\\n vec2 normAddr2D = float(address1D) * conv_const;\\n return vec2(fract(normAddr2D.x + epsilon), normAddr2D.y);\\n}\\n\\nvoid barrier() {}\\n \\n\\nuniform vec2 u_OutputTextureSize;\\nuniform int u_OutputTexelCount;\\nvarying vec2 v_TexCoord;\\n\\nbool gWebGPUDebug = false;\\nvec4 gWebGPUDebugOutput = vec4(0.0);\\n\\n#define VERTEX_COUNT __DefineValuePlaceholder__VERTEX_COUNT\\n\\nuniform sampler2D u_Data;\\nuniform vec2 u_DataSize;\\nvec4 getDatau_Data(vec2 address2D) {\\n return vec4(texture2D(u_Data, address2D).rgba);\\n}\\nvec4 getDatau_Data(float address1D) {\\n return getDatau_Data(addrTranslation_1Dto2D(address1D, u_DataSize));\\n}\\nvec4 getDatau_Data(int address1D) {\\n return getDatau_Data(float(address1D));\\n}\\nuniform float u_iter;\\nuniform sampler2D u_AveMovement;\\nuniform vec2 u_AveMovementSize;\\nvec4 getDatau_AveMovement(vec2 address2D) {\\n return vec4(texture2D(u_AveMovement, address2D).rgba);\\n}\\nvec4 getDatau_AveMovement(float address1D) {\\n return getDatau_AveMovement(addrTranslation_1Dto2D(address1D, u_AveMovementSize));\\n}\\nvec4 getDatau_AveMovement(int address1D) {\\n return getDatau_AveMovement(float(address1D));\\n}\\nvoid main() {\\nivec3 workGroupSize = ivec3(1, 1, 1);\\nivec3 numWorkGroups = ivec3(1, 1, 1); \\nint globalInvocationIndex = int(floor(v_TexCoord.x * u_OutputTextureSize.x))\\n + int(floor(v_TexCoord.y * u_OutputTextureSize.y)) * int(u_OutputTextureSize.x);\\nint workGroupIDLength = globalInvocationIndex / (workGroupSize.x * workGroupSize.y * workGroupSize.z);\\nivec3 workGroupID = ivec3(workGroupIDLength / numWorkGroups.y / numWorkGroups.z, workGroupIDLength / numWorkGroups.x / numWorkGroups.z, workGroupIDLength / numWorkGroups.x / numWorkGroups.y);\\nint localInvocationIDZ = globalInvocationIndex / (workGroupSize.x * workGroupSize.y);\\nint localInvocationIDY = (globalInvocationIndex - localInvocationIDZ * workGroupSize.x * workGroupSize.y) / workGroupSize.x;\\nint localInvocationIDX = globalInvocationIndex - localInvocationIDZ * workGroupSize.x * workGroupSize.y - localInvocationIDY * workGroupSize.x;\\nivec3 localInvocationID = ivec3(localInvocationIDX, localInvocationIDY, localInvocationIDZ);\\nivec3 globalInvocationID = workGroupID * workGroupSize + localInvocationID;\\nint localInvocationIndex = localInvocationID.z * workGroupSize.x * workGroupSize.y\\n + localInvocationID.y * workGroupSize.x + localInvocationID.x;\\nfloat movement = 0.0;\\nfor (int j = 0; j < VERTEX_COUNT; j++) {vec4 vertex = getDatau_Data(j);\\nmovement += vertex.w;}\\nmovement = movement / float(VERTEX_COUNT);\\ngl_FragColor = vec4(vec4(movement, 0.0, 0.0, 0.0));if (gWebGPUDebug) {\\n gl_FragColor = gWebGPUDebugOutput;\\n}}\\n"},"context":{"name":"","dispatch":[1,1,1],"threadGroupSize":[1,1,1],"maxIteration":1,"defines":[{"name":"VERTEX_COUNT","type":"Float","runtime":true}],"uniforms":[{"name":"u_Data","type":"vec4<f32>[]","storageClass":"StorageBuffer","readonly":true,"writeonly":false,"size":[1,1]},{"name":"u_iter","type":"Float","storageClass":"Uniform","readonly":true,"writeonly":false,"size":[1,1]},{"name":"u_AveMovement","type":"vec4<f32>[]","storageClass":"StorageBuffer","readonly":false,"writeonly":false,"size":[1,1]}],"globalDeclarations":[],"output":{"name":"u_AveMovement","size":[1,1],"length":1},"needPingpong":true}}`;
|
|
218
|
-
//# sourceMappingURL=gForceShader.js.map
|