@woosh/meep-engine 2.33.61 → 2.33.62

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/editor/actions/concrete/PaintTerrainOverlayAction.js +1 -1
  2. package/editor/process/ObstacleGridDisplayProcess.js +1 -1
  3. package/editor/process/symbolic/makeGridPositionSymbolDisplay.js +1 -1
  4. package/editor/tools/FoliagePaintTool.js +1 -1
  5. package/editor/tools/GridPaintTool.js +1 -1
  6. package/editor/tools/paint/TerrainPaintTool.js +1 -1
  7. package/editor/tools/paint/TerrainTexturePaintTool.js +1 -1
  8. package/editor/view/EditorView.js +1 -1
  9. package/editor/view/GridPickCoordinateView.js +1 -1
  10. package/engine/ecs/animation/InverseKinematicsSystem.js +1 -1
  11. package/engine/ecs/evaluation/world/ReadTerrainLayerWeightPointFitness.js +1 -1
  12. package/engine/ecs/fow/FogOfWarRevealerSystem.js +1 -1
  13. package/engine/ecs/terrain/ecs/ClingToTerrainSystem.js +2 -2
  14. package/engine/ecs/terrain/util/loadVisibleTerrainTiles.js +112 -0
  15. package/engine/ecs/terrain/util/obtainTerrain.js +23 -0
  16. package/engine/graphics/ecs/camera/topdown/TopDownCameraLanderSystem.js +1 -1
  17. package/engine/graphics/ecs/water/WaterSystem.js +1 -1
  18. package/engine/graphics/ecs/water2/shader/testWaterShader.js +1 -1
  19. package/engine/graphics/particles/particular/engine/utils/volume/prototypeParticleVolume.js +1 -1
  20. package/engine/graphics/render/forward_plus/plugin/ptototypeFPPlugin.js +1 -1
  21. package/engine/graphics/render/webgpu/sample/MeshInstance.js +87 -0
  22. package/engine/graphics/render/webgpu/sample/fragmentDeferredRendering.wgsl +7 -3
  23. package/engine/graphics/render/webgpu/sample/fragmentGBuffersDebugView.wgsl +4 -3
  24. package/engine/graphics/render/webgpu/sample/lightUpdate.wgsl +13 -6
  25. package/engine/graphics/render/webgpu/sample/main.js +82 -44
  26. package/engine/graphics/render/webgpu/sample/vertexWriteGBuffers.wgsl +5 -3
  27. package/engine/grid/systems/GridPosition2TransformSystem.js +1 -1
  28. package/engine/grid/systems/ViewportGridProjectionSystem.js +1 -1
  29. package/engine/grid/transform2grid/Transform2GridPositionSystem.js +1 -1
  30. package/engine/scene/transitionToScene.js +1 -1
  31. package/generation/grid/actions/ContinuousGridCellActionSetTerrainHeight.js +1 -1
  32. package/generation/markers/actions/placement/MarkerNodeEntityProcessorClingToTerrain.js +1 -1
  33. package/generation/markers/debug/visualizeMarkers.js +1 -1
  34. package/generation/theme/ThemeEngine.js +1 -1
  35. package/package.json +1 -1
  36. package/samples/terrain/main.js +1 -1
  37. package/view/minimap/Minimap.js +1 -1
  38. package/engine/graphics/render/webgpu/sample/_main.ts +0 -650
@@ -1,6 +1,6 @@
1
- import { obtainTerrain } from "../../../../model/game/scenes/SceneUtils.js";
2
1
  import Vector4 from "../../../core/geom/Vector4.js";
3
2
  import { Action } from "../../../core/process/undo/Action.js";
3
+ import { obtainTerrain } from "../../../engine/ecs/terrain/util/obtainTerrain.js";
4
4
 
5
5
  class PaintTerrainOverlayAction extends Action {
6
6
  /**
@@ -1,8 +1,8 @@
1
1
  import { EditorProcess } from "./EditorProcess.js";
2
- import { obtainTerrain } from "../../../model/game/scenes/SceneUtils.js";
3
2
  import GridObstacle from "../../engine/grid/components/GridObstacle.js";
4
3
  import GridPosition from "../../engine/grid/components/GridPosition.js";
5
4
  import { Sampler2D } from "../../engine/graphics/texture/sampler/Sampler2D.js";
5
+ import { obtainTerrain } from "../../engine/ecs/terrain/util/obtainTerrain.js";
6
6
 
7
7
  class ObstacleGridDisplayProcess extends EditorProcess {
8
8
 
@@ -4,7 +4,6 @@ import Task from "../../../core/process/task/Task.js";
4
4
  import TaskSignal from "../../../core/process/task/TaskSignal.js";
5
5
  import EntityBuilder from "../../../engine/ecs/EntityBuilder.js";
6
6
  import { BufferGeometry, Float32BufferAttribute, Line, LineBasicMaterial } from "three";
7
- import { obtainTerrain } from "../../../../model/game/scenes/SceneUtils.js";
8
7
  import Renderable from "../../../engine/ecs/components/Renderable.js";
9
8
  import { SurfacePoint3 } from "../../../core/geom/3d/SurfacePoint3.js";
10
9
  import Vector3 from "../../../core/geom/Vector3.js";
@@ -14,6 +13,7 @@ import { EventType } from "../../../engine/ecs/EntityManager.js";
14
13
  import { make3DSymbolicDisplay } from "./make3DSymbolicDisplay.js";
15
14
  import GridPosition from "../../../engine/grid/components/GridPosition.js";
16
15
  import { ProcessState } from "../../../core/process/ProcessState.js";
16
+ import { obtainTerrain } from "../../../engine/ecs/terrain/util/obtainTerrain.js";
17
17
 
18
18
  /**
19
19
  *
@@ -1,12 +1,12 @@
1
1
  import Tool from "./engine/Tool.js";
2
2
  import Vector1 from "../../core/geom/Vector1.js";
3
- import { obtainTerrain } from "../../../model/game/scenes/SceneUtils.js";
4
3
  import ObservedValue from "../../core/model/ObservedValue.js";
5
4
  import Vector4 from "../../core/geom/Vector4.js";
6
5
  import loadSampler2D from "../../engine/graphics/texture/sampler/loadSampler2D.js";
7
6
  import convertSampler2D2Canvas from "../../engine/graphics/texture/sampler/Sampler2D2Canvas.js";
8
7
  import { InstancedMeshComponent } from "../../engine/ecs/foliage/ecs/InstancedMeshComponent.js";
9
8
  import { parseHex } from "../../core/color/parseHex.js";
9
+ import { obtainTerrain } from "../../engine/ecs/terrain/util/obtainTerrain.js";
10
10
 
11
11
  class FoliagePaintTool extends Tool {
12
12
  constructor() {
@@ -6,12 +6,12 @@ import Vector4 from "../../core/geom/Vector4.js";
6
6
  import ObservedValue from "../../core/model/ObservedValue.js";
7
7
  import Vector1 from "../../core/geom/Vector1.js";
8
8
  import WriteGridValueAction from "../actions/concrete/WriteGridValueAction.js";
9
- import { obtainTerrain } from "../../../model/game/scenes/SceneUtils.js";
10
9
  import PaintTerrainOverlayAction from "../actions/concrete/PaintTerrainOverlayAction.js";
11
10
  import { decodeMouseEventButtons, PointerDevice } from "../../engine/input/devices/PointerDevice.js";
12
11
  import Vector2 from "../../core/geom/Vector2.js";
13
12
  import TopDownCameraControllerSystem from "../../engine/graphics/ecs/camera/topdown/TopDownCameraControllerSystem.js";
14
13
  import { parseHex } from "../../core/color/parseHex.js";
14
+ import { obtainTerrain } from "../../engine/ecs/terrain/util/obtainTerrain.js";
15
15
 
16
16
  class GridPaintTool extends Tool {
17
17
  constructor() {
@@ -1,7 +1,6 @@
1
1
  import { max2 } from "../../../core/math/max2.js";
2
2
  import Tool from "../engine/Tool.js";
3
3
  import { Color } from "../../../core/color/Color.js";
4
- import { obtainTerrain } from "../../../../model/game/scenes/SceneUtils.js";
5
4
  import { Sampler2D } from "../../../engine/graphics/texture/sampler/Sampler2D.js";
6
5
  import Vector2 from "../../../core/geom/Vector2.js";
7
6
  import { pick } from "../../../../model/game/util/ScreenGridPicker.js";
@@ -9,6 +8,7 @@ import convertSampler2D2Canvas from "../../../engine/graphics/texture/sampler/Sa
9
8
  import ObservedString from "../../../core/model/ObservedString.js";
10
9
  import { GameAssetType } from "../../../engine/asset/GameAssetType.js";
11
10
  import Vector1 from "../../../core/geom/Vector1.js";
11
+ import { obtainTerrain } from "../../../engine/ecs/terrain/util/obtainTerrain.js";
12
12
 
13
13
  export class TerrainPaintTool extends Tool {
14
14
  constructor() {
@@ -4,7 +4,7 @@ import { TerrainPaintTool } from "./TerrainPaintTool.js";
4
4
  import { Sampler2D } from "../../../engine/graphics/texture/sampler/Sampler2D.js";
5
5
  import { PatchTerrainTextureAction } from "../../actions/concrete/PatchTerrainTextureAction.js";
6
6
  import { convertSampler2D2DataURL } from "../../../engine/graphics/texture/sampler/convertSampler2D2DataURL.js";
7
- import { obtainTerrain } from "../../../../model/game/scenes/SceneUtils.js";
7
+ import { obtainTerrain } from "../../../engine/ecs/terrain/util/obtainTerrain.js";
8
8
 
9
9
  export class TerrainTexturePaintTool extends TerrainPaintTool {
10
10
  constructor() {
@@ -22,7 +22,6 @@ import MeshLibraryView from "./library/MeshLibraryView.js";
22
22
  import BottomLeftResizeHandleView from "../../view/elements/BottomLeftResizeHandleView.js";
23
23
  import Vector2 from "../../core/geom/Vector2.js";
24
24
  import Vector3 from "../../core/geom/Vector3.js";
25
- import { obtainTerrain } from "../../../model/game/scenes/SceneUtils.js";
26
25
  import Mesh from "../../engine/graphics/ecs/mesh/Mesh.js";
27
26
  import { Transform } from "../../engine/ecs/transform/Transform.js";
28
27
  import SelectionClearAction from "../actions/concrete/SelectionClearAction.js";
@@ -32,6 +31,7 @@ import SelectionAddAction from "../actions/concrete/SelectionAddAction.js";
32
31
  import { noop, passThrough } from "../../core/function/Functions.js";
33
32
  import { ProcessState } from "../../core/process/ProcessState.js";
34
33
  import { MeshEvents } from "../../engine/graphics/ecs/mesh/MeshEvents.js";
34
+ import { obtainTerrain } from "../../engine/ecs/terrain/util/obtainTerrain.js";
35
35
 
36
36
  class ViewManager extends View {
37
37
  constructor() {
@@ -1,8 +1,8 @@
1
1
  import View from "../../view/View.js";
2
2
  import { pick } from "../../../model/game/util/ScreenGridPicker.js";
3
- import { obtainTerrain } from "../../../model/game/scenes/SceneUtils.js";
4
3
  import domify from "../../view/DOM.js";
5
4
  import { PointerDevice } from "../../engine/input/devices/PointerDevice.js";
5
+ import { obtainTerrain } from "../../engine/ecs/terrain/util/obtainTerrain.js";
6
6
 
7
7
  class GridPickCoordinateView extends View {
8
8
  /**
@@ -3,9 +3,9 @@ import { InverseKinematics } from "./InverseKinematics.js";
3
3
  import Mesh, { MeshFlags } from "../../graphics/ecs/mesh/Mesh.js";
4
4
  import { TwoBoneInverseKinematicsSolver } from "./TwoBoneInverseKinematicsSolver.js";
5
5
  import { extractSkeletonFromMeshComponent } from "../../graphics/ecs/mesh/SkeletonUtils.js";
6
- import { obtainTerrain } from "../../../../model/game/scenes/SceneUtils.js";
7
6
  import { OneBoneSurfaceAlignmentSolver } from "./OneBoneSurfaceAlignmentSolver.js";
8
7
  import { IKProblem } from "./IKProblem.js";
8
+ import { obtainTerrain } from "../terrain/util/obtainTerrain.js";
9
9
 
10
10
 
11
11
  export class InverseKinematicsSystem extends System {
@@ -1,8 +1,8 @@
1
1
  import { PointFitnessFunction } from "../PointFitnessFunction.js";
2
- import { obtainTerrain } from "../../../../../model/game/scenes/SceneUtils.js";
3
2
  import Vector3 from "../../../../core/geom/Vector3.js";
4
3
  import Vector2 from "../../../../core/geom/Vector2.js";
5
4
  import { assert } from "../../../../core/assert.js";
5
+ import { obtainTerrain } from "../../terrain/util/obtainTerrain.js";
6
6
 
7
7
 
8
8
  const v3 = new Vector3();
@@ -4,8 +4,8 @@ import { SignalBinding } from "../../../core/events/signal/SignalBinding.js";
4
4
  import { FogOfWar } from "./FogOfWar.js";
5
5
  import Team from "../../../../model/game/ecs/component/Team.js";
6
6
  import { Transform } from "../transform/Transform.js";
7
- import { obtainTerrain } from "../../../../model/game/scenes/SceneUtils.js";
8
7
  import Vector2 from "../../../core/geom/Vector2.js";
8
+ import { obtainTerrain } from "../terrain/util/obtainTerrain.js";
9
9
 
10
10
  const v2 = new Vector2();
11
11
 
@@ -9,13 +9,13 @@ import { Transform } from '../../transform/Transform.js';
9
9
  import ClingToTerrain from './ClingToTerrain.js';
10
10
 
11
11
  import Vector3 from '../../../../core/geom/Vector3.js';
12
- import { obtainTerrain } from "../../../../../model/game/scenes/SceneUtils.js";
13
12
  import Quaternion from "../../../../core/geom/Quaternion.js";
14
- import { EPSILON} from "../../../../core/math/MathUtils.js";
13
+ import { EPSILON } from "../../../../core/math/MathUtils.js";
15
14
  import { Matrix4 } from "three";
16
15
  import { assert } from "../../../../core/assert.js";
17
16
  import { SurfacePoint3 } from "../../../../core/geom/3d/SurfacePoint3.js";
18
17
  import { Deque } from "../../../../core/collection/queue/Deque.js";
18
+ import { obtainTerrain } from "../util/obtainTerrain.js";
19
19
 
20
20
 
21
21
  /**
@@ -0,0 +1,112 @@
1
+ import TopDownCameraControllerSystem from "../../../graphics/ecs/camera/topdown/TopDownCameraControllerSystem.js";
2
+ import { Camera } from "../../../graphics/ecs/camera/Camera.js";
3
+ import { obtainTerrain } from "./obtainTerrain.js";
4
+ import { assert } from "../../../../core/assert.js";
5
+ import TerrainSystem from "../ecs/TerrainSystem.js";
6
+ import Task from "../../../../core/process/task/Task.js";
7
+ import TaskSignal from "../../../../core/process/task/TaskSignal.js";
8
+
9
+ /**
10
+ *
11
+ * @param {EntityManager} em
12
+ * @param {EntityComponentDataset} ecd
13
+ * @returns {Task}
14
+ */
15
+ export function loadVisibleTerrainTiles(em, ecd) {
16
+
17
+ let totalTiles = 0;
18
+ let loadedTiles = 0;
19
+ let failedTiles = 0;
20
+
21
+ let attempt = 0;
22
+
23
+ let failureFlag = false;
24
+
25
+ function init() {
26
+ const attemptId = attempt;
27
+
28
+ //force update by camera controller, to ensure correct focus is set
29
+ em.getSystem(TopDownCameraControllerSystem).update(0);
30
+
31
+ ecd.traverseComponents(Camera, function (c) {
32
+ c.updateMatrices();
33
+ });
34
+
35
+ const tiles = [];
36
+
37
+ const terrain = obtainTerrain(ecd);
38
+
39
+ assert.notEqual(terrain, null, 'terrain not found');
40
+
41
+ TerrainSystem.traverseVisibleTiles(ecd, terrain, function (tile) {
42
+ tiles.push(tile);
43
+ });
44
+
45
+ totalTiles = tiles.length;
46
+ const tileManager = terrain.tiles;
47
+
48
+ function handleObtainedTile(t) {
49
+ if (attemptId !== attempt) {
50
+ return;
51
+ }
52
+
53
+ loadedTiles++;
54
+ }
55
+
56
+ function handleFailedTile(t) {
57
+ if (attemptId !== attempt) {
58
+ return;
59
+ }
60
+
61
+ attempt++;
62
+
63
+ failedTiles++;
64
+
65
+ if (attempt < 10) {
66
+ init();
67
+ } else {
68
+ failureFlag = true;
69
+ }
70
+ }
71
+
72
+ if (totalTiles !== 0) {
73
+ tiles.forEach(function (tile) {
74
+ tileManager.obtain(tile.gridPosition.x, tile.gridPosition.y).then(handleObtainedTile, handleFailedTile);
75
+ });
76
+ }
77
+ }
78
+
79
+ const task = new Task({
80
+ name: "Building visible terrain tiles",
81
+
82
+ initializer: init,
83
+
84
+ cycleFunction() {
85
+ if (failureFlag) {
86
+ return TaskSignal.EndFailure;
87
+ }
88
+
89
+ if (loadedTiles >= totalTiles) {
90
+ return TaskSignal.EndSuccess;
91
+ } else {
92
+ return TaskSignal.Yield;
93
+ }
94
+ },
95
+
96
+ computeProgress() {
97
+ if (totalTiles === 0) {
98
+ return 0;
99
+ }
100
+
101
+ const f = loadedTiles / totalTiles;
102
+
103
+ if (f >= 1) {
104
+ return 1;
105
+ }
106
+
107
+ return f;
108
+ }
109
+ });
110
+
111
+ return task;
112
+ }
@@ -0,0 +1,23 @@
1
+ import { assert } from "../../../../core/assert.js";
2
+ import Terrain from "../ecs/Terrain.js";
3
+
4
+ /**
5
+ *
6
+ * @param {EntityComponentDataset} ecd
7
+ * @param {function(terrain:Terrain,entity:number)} [callback]
8
+ * @returns {Terrain|null}
9
+ */
10
+ export function obtainTerrain(ecd, callback) {
11
+ assert.notEqual(ecd, null, 'ecd is null');
12
+ assert.notEqual(ecd, undefined, 'ecd is undefined');
13
+
14
+ const object = ecd.getAnyComponent(Terrain);
15
+
16
+ const terrain = object.component;
17
+
18
+ if (terrain !== null && typeof callback === "function") {
19
+ callback(terrain, object.entity);
20
+ }
21
+
22
+ return terrain;
23
+ }
@@ -2,11 +2,11 @@ import { clamp } from "../../../../../core/math/clamp.js";
2
2
  import { System } from "../../../../ecs/System.js";
3
3
  import { TopDownCameraLander } from "./TopDownCameraLander.js";
4
4
  import { Cache } from "../../../../../core/cache/Cache.js";
5
- import { obtainTerrain } from "../../../../../../model/game/scenes/SceneUtils.js";
6
5
  import { buildCameraTargetSampler } from "../../../../input/ecs/util/TerrainCameraTargetSampler.js";
7
6
  import TopDownCameraController from "./TopDownCameraController.js";
8
7
  import Vector2 from "../../../../../core/geom/Vector2.js";
9
8
  import { SignalBinding } from "../../../../../core/events/signal/SignalBinding.js";
9
+ import { obtainTerrain } from "../../../../ecs/terrain/util/obtainTerrain.js";
10
10
 
11
11
 
12
12
  /**
@@ -8,10 +8,10 @@ import { LeafNode } from '../../../../core/bvh2/LeafNode.js';
8
8
  import { buildPlanarRenderLayerClipPlaneComputationMethod } from "../../render/layers/RenderLayerUtils.js";
9
9
  import ThreeFactory from "../../three/ThreeFactory.js";
10
10
  import { RenderPassType } from "../../render/RenderPassType.js";
11
- import { obtainTerrain } from "../../../../../model/game/scenes/SceneUtils.js";
12
11
  import { makeAlexWaterMaterial } from "../water2/shader/AlexWaterShader.js";
13
12
  import { threeUpdateTransform } from "../../util/threeUpdateTransform.js";
14
13
  import { StandardFrameBuffers } from "../../StandardFrameBuffers.js";
14
+ import { obtainTerrain } from "../../../ecs/terrain/util/obtainTerrain.js";
15
15
 
16
16
  const WATER_SIZE = 800;
17
17
 
@@ -1,4 +1,3 @@
1
- import { obtainTerrain } from "../../../../../../model/game/scenes/SceneUtils.js";
2
1
  import { seededRandom } from "../../../../../core/math/random/seededRandom.js";
3
2
  import { EngineConfiguration } from "../../../../EngineConfiguration.js";
4
3
  import ScriptSystem from "../../../../ecs/systems/ScriptSystem.js";
@@ -28,6 +27,7 @@ import { EngineHarness } from "../../../../EngineHarness.js";
28
27
  import Vector2 from "../../../../../core/geom/Vector2.js";
29
28
  import Vector3 from "../../../../../core/geom/Vector3.js";
30
29
  import SimplexNoise from 'simplex-noise';
30
+ import { obtainTerrain } from "../../../../ecs/terrain/util/obtainTerrain.js";
31
31
 
32
32
  const engineHarness = new EngineHarness();
33
33
 
@@ -43,7 +43,6 @@ import { ActionBehavior } from "../../../../../../intelligence/behavior/primitiv
43
43
  import { pingpong } from "../../../../../../../core/math/pingpong.js";
44
44
  import { ParameterLookupTable } from "../../parameter/ParameterLookupTable.js";
45
45
  import { pick } from "../../../../../../../../model/game/util/ScreenGridPicker.js";
46
- import { obtainTerrain } from "../../../../../../../../model/game/scenes/SceneUtils.js";
47
46
  import GUIElement from "../../../../../../ecs/gui/GUIElement.js";
48
47
  import EmptyView from "../../../../../../../view/elements/EmptyView.js";
49
48
  import HeadsUpDisplay from "../../../../../../ecs/gui/hud/HeadsUpDisplay.js";
@@ -77,6 +76,7 @@ import { UnitSphereShape3D } from "../../../../../../../core/geom/3d/shape/UnitS
77
76
  import TopDownCameraController from "../../../../../ecs/camera/topdown/TopDownCameraController.js";
78
77
  import { randomFloatBetween } from "../../../../../../../core/math/random/randomFloatBetween.js";
79
78
  import { MicronRenderPlugin } from "../../../../../micron/plugin/MicronRenderPlugin.js";
79
+ import { obtainTerrain } from "../../../../../../ecs/terrain/util/obtainTerrain.js";
80
80
 
81
81
  const engineHarness = new EngineHarness();
82
82
 
@@ -69,7 +69,6 @@ import Renderable from "../../../../ecs/components/Renderable.js";
69
69
  import { makeHelperSphereGeometry } from "../../../../../editor/process/symbolic/makeHelperSphereGeometry.js";
70
70
  import TopDownCameraController from "../../../ecs/camera/topdown/TopDownCameraController.js";
71
71
  import ThreeFactory from "../../../three/ThreeFactory.js";
72
- import { obtainTerrain } from "../../../../../../model/game/scenes/SceneUtils.js";
73
72
  import { JsonAssetLoader } from "../../../../asset/loaders/JsonAssetLoader.js";
74
73
  import { TextureAssetLoader } from "../../../../asset/loaders/texture/TextureAssetLoader.js";
75
74
  import { GameAssetType } from "../../../../asset/GameAssetType.js";
@@ -83,6 +82,7 @@ import { FogOfWar } from "../../../../ecs/fow/FogOfWar.js";
83
82
  import { FogOfWarRevealer } from "../../../../ecs/fow/FogOfWarRevealer.js";
84
83
  import Team from "../../../../../../model/game/ecs/component/Team.js";
85
84
  import { AmbientOcclusionPostProcessEffect } from "../../buffer/simple-fx/ao/AmbientOcclusionPostProcessEffect.js";
85
+ import { obtainTerrain } from "../../../../ecs/terrain/util/obtainTerrain.js";
86
86
 
87
87
  const geo_light_center_octahedron = new BoxBufferGeometry(0.1, 0.1, 0.1);
88
88
  const engineHarness = new EngineHarness();
@@ -0,0 +1,87 @@
1
+ import { array_copy } from "../../../../../core/collection/array/copyArray.js";
2
+
3
+ export class MeshInstance {
4
+ constructor() {
5
+
6
+ /**
7
+ *
8
+ * @type {THREE.BufferGeometry|null}
9
+ */
10
+ this.geometry = null;
11
+
12
+ /**
13
+ *
14
+ * @type {GPUBuffer|null}
15
+ */
16
+ this.vertex_buffer = null;
17
+
18
+ /**
19
+ *
20
+ * @type {GPUBuffer|null}
21
+ */
22
+ this.index_buffer = null;
23
+ }
24
+
25
+ /**
26
+ *
27
+ * @param {GPUDevice} device
28
+ */
29
+ init(device) {
30
+ const mesh = this.geometry;
31
+
32
+ const kVertexStride = 8;
33
+ const attribute_position = mesh.getAttribute('position');
34
+ const vertexBuffer = device.createBuffer({
35
+ // position: vec3, normal: vec3, uv: vec2
36
+ size: attribute_position.array.length * kVertexStride * Float32Array.BYTES_PER_ELEMENT,
37
+ usage: GPUBufferUsage.VERTEX,
38
+ mappedAtCreation: true,
39
+ });
40
+
41
+ {
42
+ const mapping = new Float32Array(vertexBuffer.getMappedRange());
43
+
44
+ const attribute_normal = mesh.getAttribute('normal');
45
+ const attribute_uv = mesh.getAttribute('uv');
46
+
47
+ const vertex_count = attribute_position.count;
48
+
49
+ for (let i = 0; i < vertex_count; ++i) {
50
+ const address = kVertexStride * i;
51
+ array_copy(attribute_position.array, i * 3, mapping, address, 3);
52
+ array_copy(attribute_normal.array, i * 3, mapping, address + 3, 3);
53
+ array_copy(attribute_uv.array, i * 2, mapping, address + 6, 2);
54
+ }
55
+ vertexBuffer.unmap();
56
+ }
57
+
58
+ this.vertex_buffer = vertexBuffer;
59
+
60
+ const indexCount = mesh.getIndex().array.length;
61
+ const indexBuffer = device.createBuffer({
62
+ size: indexCount * Uint32Array.BYTES_PER_ELEMENT,
63
+ usage: GPUBufferUsage.INDEX,
64
+ mappedAtCreation: true,
65
+ });
66
+ {
67
+ const mapping = new Uint32Array(indexBuffer.getMappedRange());
68
+
69
+ mapping.set(mesh.getIndex().array);
70
+
71
+ indexBuffer.unmap();
72
+ }
73
+
74
+ this.index_buffer = indexBuffer;
75
+
76
+ }
77
+
78
+ /**
79
+ *
80
+ * @param {GPURenderPassEncoder} pass
81
+ */
82
+ draw(pass) {
83
+ pass.setVertexBuffer(0, this.vertex_buffer);
84
+ pass.setIndexBuffer(this.index_buffer, 'uint32');
85
+ pass.drawIndexed(this.geometry.getIndex().array.length);
86
+ }
87
+ }
@@ -7,19 +7,23 @@ struct LightData {
7
7
  color : vec3<f32>;
8
8
  radius : f32;
9
9
  };
10
- [[block]] struct LightsBuffer {
10
+
11
+ struct LightsBuffer {
11
12
  lights: array<LightData>;
12
13
  };
14
+
13
15
  [[group(1), binding(0)]] var<storage, read> lightsBuffer: LightsBuffer;
14
16
 
15
- [[block]] struct Config {
17
+ struct Config {
16
18
  numLights : u32;
17
19
  };
20
+
18
21
  [[group(1), binding(1)]] var<uniform> config: Config;
19
22
 
20
- [[block]] struct CanvasConstants {
23
+ struct CanvasConstants {
21
24
  size: vec2<f32>;
22
25
  };
26
+
23
27
  [[group(2), binding(0)]] var<uniform> canvas : CanvasConstants;
24
28
 
25
29
  [[stage(fragment)]]
@@ -2,9 +2,10 @@
2
2
  [[group(0), binding(1)]] var gBufferNormal: texture_2d<f32>;
3
3
  [[group(0), binding(2)]] var gBufferAlbedo: texture_2d<f32>;
4
4
 
5
- [[block]] struct CanvasConstants {
5
+ struct CanvasConstants {
6
6
  size: vec2<f32>;
7
7
  };
8
+
8
9
  [[group(1), binding(0)]] var<uniform> canvas : CanvasConstants;
9
10
 
10
11
  [[stage(fragment)]]
@@ -18,7 +19,7 @@ fn main([[builtin(position)]] coord : vec4<f32>)
18
19
  vec2<i32>(floor(coord.xy)),
19
20
  0
20
21
  );
21
- } elseif (c.x < 0.66667) {
22
+ } else if (c.x < 0.66667) {
22
23
  result = textureLoad(
23
24
  gBufferNormal,
24
25
  vec2<i32>(floor(coord.xy)),
@@ -35,4 +36,4 @@ fn main([[builtin(position)]] coord : vec4<f32>)
35
36
  );
36
37
  }
37
38
  return result;
38
- }
39
+ }
@@ -3,20 +3,22 @@ struct LightData {
3
3
  color : vec3<f32>;
4
4
  radius : f32;
5
5
  };
6
- [[block]] struct LightsBuffer {
6
+ struct LightsBuffer {
7
7
  lights: array<LightData>;
8
8
  };
9
9
  [[group(0), binding(0)]] var<storage, read_write> lightsBuffer: LightsBuffer;
10
10
 
11
- [[block]] struct Config {
11
+ struct Config {
12
12
  numLights : u32;
13
13
  };
14
+
14
15
  [[group(0), binding(1)]] var<uniform> config: Config;
15
16
 
16
- [[block]] struct LightExtent {
17
+ struct LightExtent {
17
18
  min : vec4<f32>;
18
19
  max : vec4<f32>;
19
20
  };
21
+
20
22
  [[group(0), binding(2)]] var<uniform> lightExtent: LightExtent;
21
23
 
22
24
  [[stage(compute), workgroup_size(64, 1, 1)]]
@@ -26,9 +28,14 @@ fn main([[builtin(global_invocation_id)]] GlobalInvocationID : vec3<u32>) {
26
28
  return;
27
29
  }
28
30
 
29
- lightsBuffer.lights[index].position.y = lightsBuffer.lights[index].position.y - 0.5 - 0.003 * (f32(index) - 64.0 * floor(f32(index) / 64.0));
31
+ let light = &lightsBuffer.lights[index];
30
32
 
31
- if (lightsBuffer.lights[index].position.y < lightExtent.min.y) {
32
- lightsBuffer.lights[index].position.y = lightExtent.max.y;
33
+ (*light).position.y = (*light).position.y - 0.001 - 0.003 * (f32(index) - 64.0 * floor(f32(index) / 64.0));
34
+
35
+ if ((*light).position.y < lightExtent.min.y) {
36
+ (*light).position.y = lightExtent.max.y;
33
37
  }
38
+
39
+ // write out
40
+ // lightBuffer.lighs[index] = light;
34
41
  }