@woosh/meep-engine 2.75.7 → 2.75.9

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 (150) hide show
  1. package/build/bundle-worker-terrain.js +1 -1
  2. package/build/meep.cjs +1052 -1234
  3. package/build/meep.min.js +1 -1
  4. package/build/meep.module.js +1052 -1234
  5. package/editor/actions/concrete/ModifyPatchSampler2DAction.js +6 -3
  6. package/editor/actions/concrete/PatchTerrainTextureAction.js +6 -3
  7. package/editor/ecs/component/createObjectEditor.js +2 -2
  8. package/editor/process/EditorProcess.js +12 -16
  9. package/editor/process/ProcessEngine.js +9 -10
  10. package/package.json +1 -1
  11. package/src/core/binary/dec2hex.js +1 -1
  12. package/src/{engine/ecs/ik/IKMath.js → core/geom/vec3/v3_computeOffsetVector.js} +1 -1
  13. package/src/core/math/newton_solver_1d.js +13 -4
  14. package/src/core/math/solveQuadratic.js +5 -3
  15. package/src/core/math/spline/catmull_rom_compute_T.js +19 -0
  16. package/src/{engine/navigation/ecs/components → core/math/spline}/computeCatmullRomSpline.js +3 -3
  17. package/src/{engine/navigation/ecs/components → core/math/spline}/computeCatmullRomSplineUniformDistance.js +3 -3
  18. package/src/core/math/spline/computeNonuniformCatmullRomSplineSample.js +109 -0
  19. package/src/core/math/spline/interpolate_bicubic.js +12 -0
  20. package/src/core/math/spline/spline_catmullrom_1d.js +120 -0
  21. package/src/core/model/object/ImmutableObjectPool.js +14 -5
  22. package/src/engine/control/ControlContext.js +25 -27
  23. package/src/engine/ecs/EntityManager.js +12 -9
  24. package/src/engine/ecs/EntityObserver.js +26 -22
  25. package/src/engine/ecs/binding/ComponentPropertyPath.js +12 -12
  26. package/src/engine/ecs/components/Motion.js +5 -7
  27. package/src/engine/ecs/components/SerializationMetadata.js +5 -3
  28. package/src/engine/ecs/dynamic_actions/actions/definition/AbstractActionDescription.js +0 -2
  29. package/src/engine/ecs/dynamic_actions/actions/definition/ActionSequenceDescription.js +7 -9
  30. package/src/engine/ecs/dynamic_actions/actions/definition/DelayActionDescription.js +3 -5
  31. package/src/engine/ecs/dynamic_actions/actions/definition/SendRequestActionDescription.js +6 -8
  32. package/src/engine/ecs/dynamic_actions/actions/definition/SpeakLineActionDescription.js +14 -17
  33. package/src/engine/ecs/dynamic_actions/actions/definition/WeightedRandomActionDescription.js +8 -11
  34. package/src/engine/ecs/dynamic_actions/actions/definition/WriteToBlackboardActionDescription.js +15 -18
  35. package/src/engine/ecs/ik/OneBoneSurfaceAlignmentSolver.js +7 -7
  36. package/src/engine/ecs/ik/TwoBoneInverseKinematicsSolver.js +6 -6
  37. package/src/engine/ecs/parent/EntityNode.js +39 -37
  38. package/src/engine/ecs/speaker/VoiceSystem.js +36 -39
  39. package/src/engine/ecs/storage/BinaryBufferDeSerializer.js +7 -9
  40. package/src/engine/ecs/storage/BinaryBufferSerializer.js +15 -16
  41. package/src/engine/ecs/storage/binary/BinaryClassUpgrader.js +10 -59
  42. package/src/engine/ecs/storage/binary/BinarySerializationRegistry.js +14 -15
  43. package/src/engine/ecs/storage/binary/collection/BinaryCollectionDeSerializer.js +3 -3
  44. package/src/engine/ecs/storage/binary/collection/BinaryCollectionSerializer.js +60 -62
  45. package/src/engine/ecs/storage/binary/executeBinaryClassUpgraderChain.js +46 -0
  46. package/src/engine/ecs/storage/binary/object/BinaryObjectSerializationAdapter.js +2 -2
  47. package/src/engine/ecs/system/SystemEntityContext.js +25 -23
  48. package/src/engine/ecs/tag/find_entities_with_tag.js +18 -0
  49. package/src/engine/ecs/terrain/TerrainClouds.js +23 -24
  50. package/src/engine/ecs/terrain/ecs/layers/TerrainLayer.js +37 -31
  51. package/src/engine/ecs/terrain/ecs/layers/TerrainLayers.js +8 -7
  52. package/src/engine/ecs/terrain/ecs/splat/SplatMapMaterialPatch.js +5 -2
  53. package/src/engine/ecs/terrain/overlay/TerrainOverlay.js +15 -14
  54. package/src/engine/ecs/tooltip/TooltipComponent.js +6 -7
  55. package/src/engine/graphics/camera/testClippingPlaneComputation.js +0 -4
  56. package/src/engine/graphics/ecs/path/testPathDisplaySystem.js +1 -5
  57. package/src/engine/graphics/ecs/path/tube/prototypeAnimatedPathMask.js +2 -6
  58. package/src/engine/graphics/ecs/water2/shader/testWaterShader.js +12 -14
  59. package/src/engine/graphics/material/optimization/MaterialOptimizationContext.js +22 -20
  60. package/src/engine/graphics/particles/particular/engine/utils/volume/prototypeParticleVolume.js +3 -4
  61. package/src/engine/graphics/render/RendererPool.js +36 -40
  62. package/src/engine/graphics/render/buffer/FrameBuffer.js +25 -24
  63. package/src/engine/graphics/render/buffer/RenderGraph.js +21 -21
  64. package/src/engine/graphics/render/buffer/buffers/prototypeNormalFrameBuffer.js +0 -4
  65. package/src/engine/graphics/render/forward_plus/plugin/ptototypeFPPlugin.js +1 -5
  66. package/src/engine/graphics/render/frame_graph/IRenderContext.js +31 -1
  67. package/src/engine/graphics/render/frame_graph/RenderGraph.js +5 -5
  68. package/src/engine/graphics/render/frame_graph/RenderTarget.js +9 -0
  69. package/src/engine/graphics/render/frame_graph/RenderTextureManager.js +57 -0
  70. package/src/engine/graphics/render/frame_graph/ResourceEntry.js +7 -5
  71. package/src/engine/graphics/render/frame_graph/TextureDescriptor.js +48 -33
  72. package/src/engine/graphics/render/frame_graph/TextureInitialState.js +14 -0
  73. package/src/engine/graphics/render/frame_graph/sample/deferred/CopyPass.js +20 -0
  74. package/src/engine/graphics/render/frame_graph/sample/deferred/LightingPass.js +4 -0
  75. package/src/engine/graphics/render/frame_graph/sample/deferred/run.js +34 -6
  76. package/src/engine/graphics/render/frame_graph/webgl/WebGLRenderContext.js +34 -0
  77. package/src/engine/graphics/render/visibility/hiz/prototypeHiZ.js +3 -6
  78. package/src/engine/graphics/sh3/gi/prototypeSHGI.js +92 -0
  79. package/src/engine/graphics/shadows/testShadowMapRendering.js +0 -2
  80. package/src/engine/graphics/texture/atlas/TextureAtlas.js +13 -11
  81. package/src/engine/graphics/texture/sampler/Sampler2D.js +15 -366
  82. package/src/engine/graphics/texture/sampler/Sampler2D.spec.js +0 -31
  83. package/src/engine/graphics/texture/sampler/sampler2d_copy_with_margins.js +166 -0
  84. package/src/engine/graphics/texture/sampler/sampler2d_copy_with_margins.spec.js +31 -0
  85. package/src/engine/graphics/texture/sampler/sampler2d_paint.js +81 -0
  86. package/src/engine/graphics/texture/sampler/sampler2d_sub_copy_same_item_size.js +50 -0
  87. package/src/engine/graphics/texture/virtual/{v2/VirtualTextureMemoryMapping.js → VirtualTextureMemoryMapping.js} +2 -26
  88. package/src/engine/graphics/texture/virtual/{v2/VirtualTexturePage.js → VirtualTexturePage.js} +10 -10
  89. package/src/engine/graphics/texture/virtual/{v2/VirtualTextureTileLoader.js → VirtualTextureTileLoader.js} +7 -7
  90. package/src/engine/graphics/texture/virtual/{v2/VirtualTextureUsage.js → VirtualTextureUsage.js} +1 -1
  91. package/src/engine/graphics/texture/virtual/{v2/VirtualTextureUsageUpdater.js → VirtualTextureUsageUpdater.js} +7 -7
  92. package/src/engine/graphics/texture/virtual/{v2/debug → debug}/ResidencyDebugView.js +4 -4
  93. package/src/engine/graphics/texture/virtual/{v2/debug → debug}/UsageDebugView.js +2 -2
  94. package/src/engine/graphics/texture/virtual/{v2/debug → debug}/UsagePyramidDebugView.js +4 -4
  95. package/src/engine/graphics/texture/virtual/{v2/prototype.js → prototype.js} +7 -7
  96. package/src/engine/graphics/texture/virtual/{v2/tile → tile}/compose_finger_print.js +1 -1
  97. package/src/engine/graphics/texture/virtual/{v2/tile → tile}/compose_tile_address.js +2 -2
  98. package/src/engine/graphics/texture/virtual/{v2/tile → tile}/tile_address_to_finger_print.js +1 -1
  99. package/src/engine/navigation/ecs/components/Path.js +10 -9
  100. package/src/engine/physics/computeInterceptPoint.js +44 -0
  101. package/src/engine/plugin/EnginePlugin.js +1 -2
  102. package/src/engine/ecs/components/AlignToVelocity.js +0 -9
  103. package/src/engine/ecs/components/CharacterController.js +0 -31
  104. package/src/engine/ecs/components/PhysicalBody.js +0 -51
  105. package/src/engine/ecs/components/Steering.js +0 -111
  106. package/src/engine/ecs/components/SteeringSerializationAdapter.js +0 -34
  107. package/src/engine/ecs/storage/json/Blueprint.js +0 -129
  108. package/src/engine/ecs/storage/json/EntityFactory.js +0 -207
  109. package/src/engine/ecs/storage/json/JSONDeSerializer.js +0 -148
  110. package/src/engine/ecs/storage/json/JSONSerializer.js +0 -132
  111. package/src/engine/ecs/storage/json/README.md +0 -5
  112. package/src/engine/ecs/systems/AlignToVelocitySystem.js +0 -51
  113. package/src/engine/ecs/systems/CharacterControlSystem.js +0 -134
  114. package/src/engine/ecs/systems/PhysicsSystem.js +0 -89
  115. package/src/engine/ecs/systems/PropertySetSystem.js +0 -18
  116. package/src/engine/ecs/systems/SteeringSystem.js +0 -171
  117. package/src/engine/ecs/systems/TagSystem.d.ts +0 -5
  118. package/src/engine/ecs/systems/TagSystem.js +0 -31
  119. package/src/engine/graphics/render/webgpu/sample/MeshInstance.js +0 -108
  120. package/src/engine/graphics/render/webgpu/sample/fragmentDeferredRendering.wgsl +0 -71
  121. package/src/engine/graphics/render/webgpu/sample/fragmentGBuffersDebugView.wgsl +0 -39
  122. package/src/engine/graphics/render/webgpu/sample/fragmentWriteGBuffers.wgsl +0 -21
  123. package/src/engine/graphics/render/webgpu/sample/lightUpdate.wgsl +0 -41
  124. package/src/engine/graphics/render/webgpu/sample/main.js +0 -605
  125. package/src/engine/graphics/render/webgpu/sample/vertexTextureQuad.wgsl +0 -9
  126. package/src/engine/graphics/render/webgpu/sample/vertexWriteGBuffers.wgsl +0 -30
  127. package/src/engine/graphics/texture/sampler/bicubic.js +0 -59
  128. package/src/engine/graphics/texture/sampler/bicubic.spec.js +0 -13
  129. package/src/engine/graphics/texture/virtual/TileOperation.js +0 -13
  130. package/src/engine/graphics/texture/virtual/TileTree.js +0 -150
  131. package/src/engine/graphics/texture/virtual/TileTree.spec.js +0 -58
  132. package/src/engine/graphics/texture/virtual/TileUsage.js +0 -137
  133. package/src/engine/graphics/texture/virtual/VirtualTexture.js +0 -238
  134. package/src/engine/graphics/texture/virtual/VirtualTexture.spec.js +0 -39
  135. package/src/engine/graphics/texture/virtual/page/TilePage.js +0 -148
  136. package/src/engine/graphics/texture/virtual/page/TilePageSlot.js +0 -36
  137. package/src/engine/graphics/texture/virtual/tile/Tile.js +0 -44
  138. package/src/engine/graphics/texture/virtual/tile/Tile.spec.js +0 -11
  139. package/src/engine/graphics/texture/virtual/tile/TileAddress.js +0 -63
  140. package/src/engine/graphics/texture/virtual/tile/TileAddress.spec.js +0 -30
  141. package/src/engine/graphics/texture/virtual/tile/TileLoader.js +0 -178
  142. package/src/engine/graphics/texture/virtual/tile/TileRequest.js +0 -40
  143. package/src/engine/graphics/texture/virtual/tile/TileStatus.js +0 -10
  144. package/src/engine/navigation/ecs/components/computeNonuniformCatmullRomSplineSample.js +0 -242
  145. /package/src/engine/graphics/texture/virtual/{v2/NOTES.md → NOTES.md} +0 -0
  146. /package/src/engine/graphics/texture/virtual/{v2/VirtualTextureMaterial.js → VirtualTextureMaterial.js} +0 -0
  147. /package/src/engine/graphics/texture/virtual/{v2/VirtualTextureUsageShader.js → VirtualTextureUsageShader.js} +0 -0
  148. /package/src/engine/graphics/texture/virtual/{v2/tile → tile}/VirtualTextureTile.js +0 -0
  149. /package/src/engine/graphics/texture/virtual/{v2/tile → tile}/decompose_finger_print.js +0 -0
  150. /package/src/engine/graphics/texture/virtual/{v2/tile → tile}/finger_print_to_tile_address.js +0 -0
@@ -1,134 +0,0 @@
1
- /**
2
- * User: Alex Goldring
3
- * Date: 7/4/2014
4
- * Time: 09:17
5
- */
6
- import { System } from '../System.js';
7
- import CharacterController from '../components/CharacterController.js';
8
- import { Transform } from '../transform/Transform.js';
9
- import PhysicalBody from '../components/PhysicalBody.js';
10
- import Vector3 from "../../../core/geom/Vector3.js";
11
-
12
-
13
- class CharacterControlSystem extends System {
14
- constructor() {
15
- super();
16
- //
17
- this.entityManager = null;
18
-
19
- this.dependencies = [CharacterController];
20
- }
21
-
22
- remove(component) {
23
- }
24
-
25
- add(component) {
26
- }
27
-
28
- update(timeDelta) {
29
- const entityManager = this.entityManager;
30
- const PhysicsSystemType = entityManager.getSystemIdByComponentClass(PhysicalBody);
31
- const physicsSystem = entityManager.systems[PhysicsSystemType];
32
- entityManager.traverseEntities([CharacterController, PhysicalBody, Transform], function (controller, physicalBody, transform) {
33
- if (controller.lockedTimeout > 0) {
34
- //controlls are locked - can't do anything
35
- controller.lockedTimeout -= timeDelta;
36
- if (controller.lockedTieout < 0) {
37
- controller.lockedTimeout = 0;
38
- }
39
- } else {
40
- //controls aren't locked
41
- setOnSolidSurface(transform, controller, physicsSystem);
42
- updatePosition(controller, physicalBody.body, transform, physicsSystem);
43
- if (controller.attacking) {
44
- console.log("pow!");
45
- }
46
- }
47
- });
48
-
49
- }
50
- }
51
-
52
-
53
- function setOnSolidSurface(transform, controller, physicsSystem) {
54
- const from = transform.position.clone();
55
- const to = from.clone().add(new Vector3(0, -100, 0));
56
- physicsSystem.rayTest(from, to, function (success, point) {
57
- if (success) {
58
- const v = new Vector3();
59
- v.copy(point);
60
- const number = v.distanceTo(from);
61
- if (number <= controller.height / 2 + 0.06) {
62
- controller.onSolidSurface = true;
63
- } else {
64
- controller.onSolidSurface = false;
65
- }
66
- } else {
67
- controller.onSolidSurface = false;
68
- }
69
- });
70
- }
71
-
72
- function updatePosition(controls, body, transform) {
73
- let z = 0;
74
- let x = 0;
75
- if (controls.forward) {
76
- z -= 1;
77
- }
78
- if (controls.back) {
79
- z += 1;
80
- }
81
- if (controls.right) {
82
- x += 1;
83
- }
84
- if (controls.left) {
85
- x -= 1;
86
- }
87
- const moving = (x !== 0 || z !== 0);
88
- let vector;
89
- const notTakingOff = body.linearVelocity.y <= 0.00001;
90
- if (controls.onSolidSurface && notTakingOff) {
91
- if (moving) {
92
- const y = body.linearVelocity.y;
93
- //obtain facing direction
94
- const euler = new THREE.Euler();
95
- euler.setFromQuaternion(transform.rotation);
96
- //vector pointing in the direction of travel
97
- vector = new THREE.Vector3(x, 0, z);
98
- const rotationMatrix = new THREE.Matrix4().makeRotationFromQuaternion(transform.rotation);
99
- vector.applyMatrix4(rotationMatrix);
100
- vector.y = y;
101
- //enforce movement speed
102
- let scalar = controls.movementSpeed;
103
- if (controls.sprinting) {
104
- //apply sprinting multiplier
105
- scalar *= controls.sprintingMultiplier;
106
- }
107
- //scale facing direction vector by the movement speed
108
- vector.normalize().multiplyScalar(scalar);
109
- //write the property
110
- body.linearVelocity.copy(vector);
111
- } else {
112
- //when on ground and not moving - stand still
113
- const v = body.linearVelocity;
114
- if (v.x !== 0 || v.z !== 0) {
115
- v.set(0, 0, 0);
116
- }
117
- }
118
- if (controls.jump) {
119
- //perform jump
120
- const up = new Vector3(0, 1, 0);
121
- const magnitude = (8 * body.mass);
122
- const force = up.scale(magnitude);
123
- body.applyCentralImpulse(force);
124
-
125
- controls.onSolidSurface = false; //prevent further jumps
126
- controls.lockedTimeout = 0.1; //lock controls to prevent some race conditions
127
- }
128
- }
129
-
130
- //set jump to false
131
- controls.jump = false;
132
- }
133
-
134
- export default CharacterControlSystem;
@@ -1,89 +0,0 @@
1
- /**
2
- * Created by Alex on 01/04/2014.
3
- */
4
- import { System } from '../System.js';
5
- import PhysicalBody from '../components/PhysicalBody.js';
6
- import { Transform } from '../transform/Transform.js';
7
- import PhysicsWorld from '../../physics/ammo/World.js';
8
-
9
-
10
- class PhysicsSystem extends System {
11
- constructor() {
12
- super();
13
-
14
- this.dependencies = [PhysicalBody];
15
- }
16
-
17
- rayTest(from, to, callback) {
18
- this.physics.rayTest(from, to, callback);
19
- }
20
-
21
- startup(entityManager, readyCallback, errorCallback) {
22
- this.entityManager = entityManager;
23
- this.physics = new PhysicsWorld(readyCallback);
24
- }
25
-
26
- shutdown(entityManager, readyCallback, errorCallback) {
27
- try {
28
- this.physics = null;
29
- readyCallback();
30
- } catch (e) {
31
- errorCallback(e);
32
- }
33
- }
34
-
35
- add(component, entity) {
36
- const body = component.body;
37
- body.__entity = entity;
38
- this.physics.addBody(body);
39
- //collisions
40
- if (component.notifyCollision) {
41
- const entityManager = this.entityManager;
42
-
43
- body.onCollision(function (other) {
44
- entityManager.sendEvent(entity, "collision", other.__entity);
45
- });
46
- }
47
- }
48
-
49
- remove(component) {
50
- const body = component.body;
51
- this.physics.removeBody(body);
52
- }
53
-
54
- update(timeDelta) {
55
- const entityManager = this.entityManager;
56
- let signals = entityManager.eventManager.signals;
57
- //set position to physical body
58
- entityManager.traverseEntities([PhysicalBody, Transform], function (physicalBody, transform) {
59
- //copy position into body
60
- const body = physicalBody.body;
61
- body.position.copy(transform.position);
62
- body.rotation.copy(transform.rotation);
63
- });
64
-
65
-
66
- const stepFinishedCallback = function () {
67
- //set position from physical body
68
- entityManager.traverseEntities([PhysicalBody, Transform], function (physicalBody, transform, entity) {
69
- //copy position from body
70
- const body = physicalBody.body;
71
- const previousPosition = transform.previousPosition;
72
- const currentPosition = transform.position;
73
- if (previousPosition.x != currentPosition.x || previousPosition.y != currentPosition.y || previousPosition.z != currentPosition.z) {
74
- //write previous position is the current position is different from before
75
- previousPosition.copy(currentPosition);
76
- }
77
- currentPosition.copy(body.position);
78
- // transform.rotation.copy(body.rotation);
79
- });
80
- };
81
- this.physics.simulate(timeDelta, stepFinishedCallback);
82
- }
83
- }
84
-
85
-
86
- function collisionHandler() {
87
- }
88
-
89
- export default PhysicsSystem;
@@ -1,18 +0,0 @@
1
- /**
2
- * Created by Alex on 13/04/2017.
3
- */
4
-
5
-
6
- import { System } from '../System.js';
7
- import PropertySet from '../components/PropertySet.js';
8
-
9
- class PropertySetSystem extends System {
10
- constructor() {
11
- super();
12
-
13
- this.dependencies = [PropertySet];
14
- }
15
- }
16
-
17
-
18
- export default PropertySetSystem;
@@ -1,171 +0,0 @@
1
- /**
2
- * User: Alex Goldring
3
- * Date: 1/6/2014
4
- * Time: 08:37
5
- */
6
- import { max2 } from "../../../core/math/max2.js";
7
- import { min2 } from "../../../core/math/min2.js";
8
- import { System } from '../System.js';
9
- import PhysicalBody from '../components/PhysicalBody.js';
10
- import Motion from '../components/Motion.js';
11
- import { Transform } from '../transform/Transform.js';
12
- import Steering, { SteeringEvents, SteeringFlags } from '../components/Steering.js';
13
- import Vector3 from "../../../core/geom/Vector3.js";
14
- import { alignToVector } from "../terrain/ecs/cling/ClingToTerrainSystem.js";
15
- import { v3_dot } from "../../../core/geom/vec3/v3_dot.js";
16
- import { solveQuadratic } from "../../../core/math/solveQuadratic.js";
17
-
18
- /**
19
- *
20
- * @param {Vector3} result
21
- * @param {Vector3} source
22
- * @param {Vector3} target
23
- * @param {Vector3} targetVelocity
24
- * @param {number} sourceSpeed
25
- * @return {boolean}
26
- */
27
- function computeInterceptPoint(result, source, target, targetVelocity, sourceSpeed) {
28
- const d_ts_x = target.x - source.x;
29
- const d_ts_y = target.y - source.y;
30
- const d_ts_z = target.z - source.z;
31
-
32
- // Get quadratic equation components
33
- const a = targetVelocity.dot(targetVelocity) - sourceSpeed * sourceSpeed;
34
- const b = 2 * v3_dot(targetVelocity.x, targetVelocity.y, targetVelocity.z, d_ts_x, d_ts_y, d_ts_z);
35
-
36
- const c = v3_dot(
37
- d_ts_x, d_ts_y, d_ts_z,
38
- d_ts_x, d_ts_y, d_ts_z
39
- );
40
-
41
- // Solve quadratic
42
- const ts = [];
43
- const root_count = solveQuadratic(ts, 0, a, b, c); // See quad(), below
44
-
45
- // Find smallest positive solution
46
- if (root_count > 0) {
47
- const t0 = ts[0], t1 = ts[1];
48
- let t = Math.min(t0, t1);
49
- if (t < 0) t = Math.max(t0, t1);
50
-
51
- if (t > 0) {
52
- result.copy(targetVelocity).multiplyScalar(t).add(target);
53
- return true;
54
- }
55
-
56
- }
57
- return false;
58
- }
59
-
60
- class SteeringSystem extends System {
61
- constructor() {
62
- super();
63
-
64
- this.dependencies = [Steering];
65
- }
66
-
67
- update(timeDelta) {
68
- const entityManager = this.entityManager;
69
-
70
- const ecd = entityManager.dataset;
71
-
72
- if (ecd === null) {
73
- return;
74
- }
75
-
76
- /**
77
- *
78
- * @param {number} entity
79
- * @param {Steering} steering
80
- * @param {Transform} transform
81
- * @param {Vector3} velocity
82
- */
83
- function process(entity, steering, transform, velocity) {
84
- if (!steering.getFlag(SteeringFlags.Active)) {
85
- //steering is inactive
86
- return;
87
- }
88
-
89
- const destination = steering.destination;
90
-
91
- const delta = destination.clone().sub(transform.position);
92
- delta.normalize();
93
-
94
- const distanceWithError = computeDistanceWithError(transform.position, destination, steering.targetMargin);
95
-
96
- if (distanceWithError > 0) {
97
- //not at the target yet
98
- const d = steering.maxSpeed;
99
-
100
- const angularLimit = steering.rotationSpeed * timeDelta;
101
-
102
- alignToVector(transform.rotation, delta, angularLimit, Vector3.up, Vector3.forward);
103
-
104
- //compute forward vector
105
- const v = Vector3.forward.clone();
106
- v.applyQuaternion(transform.rotation);
107
- v.normalize();
108
-
109
-
110
- //check old velocity to avoid flying past target
111
- if (distanceWithError < d * timeDelta) {
112
- const distance = delta.length();
113
- const adjustedVelocity = min2(d, distance / timeDelta);
114
- v.multiplyScalar(adjustedVelocity);
115
- } else {
116
- v.multiplyScalar(d);
117
- }
118
-
119
- velocity.copy(v);
120
-
121
- } else {
122
- //goal is reached, de-activate
123
- steering.clearFlag(SteeringFlags.Active);
124
-
125
- //drop velocity
126
- velocity.set(0, 0, 0);
127
-
128
- //dispatch
129
- ecd.sendEvent(entity, SteeringEvents.DestinationReached, steering);
130
- }
131
- }
132
-
133
- //Make sure physical bodies exist
134
- if (ecd.isComponentTypeRegistered(PhysicalBody)) {
135
-
136
- ecd.traverseEntities([Steering, PhysicalBody, Transform], function (steering, physicalBody, transform, entity) {
137
-
138
- const body = physicalBody.body;
139
-
140
- process(entity, steering, transform, body.linearVelocity);
141
-
142
- });
143
-
144
- }
145
-
146
- ecd.traverseEntities([Steering, Motion, Transform], function (steering, motion, transform, entity) {
147
- process(entity, steering, transform, motion.velocity);
148
- });
149
- }
150
- }
151
-
152
- /**
153
- *
154
- * @param {Vector3} v0
155
- * @param {Vector3} v1
156
- * @param {Vector3} error
157
- * @return {number}
158
- */
159
- function computeDistanceWithError(v0, v1, error) {
160
- const absDelta = v0.clone().sub(v1).abs();
161
-
162
- absDelta.set(
163
- max2(absDelta.x - error.x, 0),
164
- max2(absDelta.y - error.y, 0),
165
- max2(absDelta.z - error.z, 0)
166
- );
167
-
168
- return absDelta.length();
169
- }
170
-
171
- export default SteeringSystem;
@@ -1,5 +0,0 @@
1
- import {System} from "../System";
2
-
3
- export class TagSystem extends System {
4
-
5
- }
@@ -1,31 +0,0 @@
1
- /**
2
- * Created by Alex on 23/04/2014.
3
- */
4
- import { System } from '../System.js';
5
- import Tag from '../components/Tag.js';
6
-
7
-
8
- class TagSystem extends System {
9
-
10
- dependencies = [Tag];
11
-
12
- /**
13
- *
14
- * @param {string} tag
15
- * @param {EntityComponentDataset} ecd
16
- * @returns {number[]}
17
- */
18
- static find_entities_with_tag(tag, ecd) {
19
- const r = [];
20
- ecd.traverseComponents(Tag, (t, e) => {
21
- if (t.contains(tag)) {
22
- r.push(e);
23
- }
24
- });
25
-
26
- return r;
27
- }
28
- }
29
-
30
-
31
- export default TagSystem;
@@ -1,108 +0,0 @@
1
- import { array_copy } from "../../../../../core/collection/array/array_copy.js";
2
-
3
- const BIND_GROUP_MATERIAL = 1;
4
-
5
- export class MeshInstance {
6
- constructor() {
7
-
8
- /**
9
- *
10
- * @type {THREE.BufferGeometry|null}
11
- */
12
- this.geometry = null;
13
-
14
- /**
15
- *
16
- * @type {null}
17
- */
18
- this.material = null;
19
-
20
- /**
21
- *
22
- * @type {GPUBuffer|null}
23
- */
24
- this.vertex_buffer = null;
25
-
26
- /**
27
- *
28
- * @type {GPUBuffer|null}
29
- */
30
- this.index_buffer = null;
31
- }
32
-
33
- /**
34
- *
35
- * @param {GPUDevice} device
36
- */
37
- init(device) {
38
- const mesh = this.geometry;
39
-
40
- const kVertexStride = 8;
41
- const attribute_position = mesh.getAttribute('position');
42
- const vertexBuffer = device.createBuffer({
43
- // position: vec3, normal: vec3, uv: vec2
44
- size: attribute_position.array.length * kVertexStride * Float32Array.BYTES_PER_ELEMENT,
45
- usage: GPUBufferUsage.VERTEX,
46
- mappedAtCreation: true,
47
- });
48
-
49
- {
50
- const mapping = new Float32Array(vertexBuffer.getMappedRange());
51
-
52
- const attribute_normal = mesh.getAttribute('normal');
53
- const attribute_uv = mesh.getAttribute('uv');
54
-
55
- const vertex_count = attribute_position.count;
56
-
57
- for (let i = 0; i < vertex_count; ++i) {
58
- const address = kVertexStride * i;
59
- array_copy(attribute_position.array, i * 3, mapping, address, 3);
60
- array_copy(attribute_normal.array, i * 3, mapping, address + 3, 3);
61
- array_copy(attribute_uv.array, i * 2, mapping, address + 6, 2);
62
- }
63
- vertexBuffer.unmap();
64
- }
65
-
66
- this.vertex_buffer = vertexBuffer;
67
-
68
- const indexCount = mesh.getIndex().array.length;
69
- const indexBuffer = device.createBuffer({
70
- size: indexCount * Uint32Array.BYTES_PER_ELEMENT,
71
- usage: GPUBufferUsage.INDEX,
72
- mappedAtCreation: true,
73
- });
74
- {
75
- const mapping = new Uint32Array(indexBuffer.getMappedRange());
76
-
77
- mapping.set(mesh.getIndex().array);
78
-
79
- indexBuffer.unmap();
80
- }
81
-
82
- this.index_buffer = indexBuffer;
83
-
84
- }
85
-
86
- /**
87
- *
88
- * @param {GPURenderPassEncoder} pass
89
- */
90
- preparePass(pass) {
91
-
92
- }
93
-
94
- /**
95
- *
96
- * @param {GPURenderPassEncoder} pass
97
- */
98
- draw(pass) {
99
- // set material bindings
100
-
101
- // pass.setBindGroup(BIND_GROUP_MATERIAL, {});
102
-
103
- pass.setVertexBuffer(0, this.vertex_buffer);
104
- pass.setIndexBuffer(this.index_buffer, 'uint32');
105
-
106
- pass.drawIndexed(this.geometry.getIndex().array.length);
107
- }
108
- }
@@ -1,71 +0,0 @@
1
- [[group(0), binding(0)]] var gBufferPosition: texture_2d<f32>;
2
- [[group(0), binding(1)]] var gBufferNormal: texture_2d<f32>;
3
- [[group(0), binding(2)]] var gBufferAlbedo: texture_2d<f32>;
4
-
5
- struct LightData {
6
- position : vec4<f32>;
7
- color : vec3<f32>;
8
- radius : f32;
9
- };
10
-
11
- struct LightsBuffer {
12
- lights: array<LightData>;
13
- };
14
-
15
- [[group(1), binding(0)]] var<storage, read> lightsBuffer: LightsBuffer;
16
-
17
- struct Config {
18
- numLights : u32;
19
- };
20
-
21
- [[group(1), binding(1)]] var<uniform> config: Config;
22
-
23
- struct CanvasConstants {
24
- size: vec2<f32>;
25
- };
26
-
27
- [[group(2), binding(0)]] var<uniform> canvas : CanvasConstants;
28
-
29
- [[stage(fragment)]]
30
- fn main([[builtin(position)]] coord : vec4<f32>)
31
- -> [[location(0)]] vec4<f32> {
32
- var result = vec3<f32>(0.0, 0.0, 0.0);
33
-
34
- let position = textureLoad(
35
- gBufferPosition,
36
- vec2<i32>(floor(coord.xy)),
37
- 0
38
- ).xyz;
39
-
40
- if (position.z > 10000.0) {
41
- discard;
42
- }
43
-
44
- let normal = textureLoad(
45
- gBufferNormal,
46
- vec2<i32>(floor(coord.xy)),
47
- 0
48
- ).xyz;
49
-
50
- let albedo = textureLoad(
51
- gBufferAlbedo,
52
- vec2<i32>(floor(coord.xy)),
53
- 0
54
- ).rgb;
55
-
56
- for (var i : u32 = 0u; i < config.numLights; i = i + 1u) {
57
- let L = lightsBuffer.lights[i].position.xyz - position;
58
- let distance = length(L);
59
- if (distance > lightsBuffer.lights[i].radius) {
60
- continue;
61
- }
62
- let lambert = max(dot(normal, normalize(L)), 0.0);
63
- result = result + vec3<f32>(
64
- lambert * pow(1.0 - distance / lightsBuffer.lights[i].radius, 2.0) * lightsBuffer.lights[i].color * albedo);
65
- }
66
-
67
- // some manual ambient
68
- result = result + vec3<f32>(0.2, 0.2, 0.2);
69
-
70
- return vec4<f32>(result, 1.0);
71
- }
@@ -1,39 +0,0 @@
1
- [[group(0), binding(0)]] var gBufferPosition: texture_2d<f32>;
2
- [[group(0), binding(1)]] var gBufferNormal: texture_2d<f32>;
3
- [[group(0), binding(2)]] var gBufferAlbedo: texture_2d<f32>;
4
-
5
- struct CanvasConstants {
6
- size: vec2<f32>;
7
- };
8
-
9
- [[group(1), binding(0)]] var<uniform> canvas : CanvasConstants;
10
-
11
- [[stage(fragment)]]
12
- fn main([[builtin(position)]] coord : vec4<f32>)
13
- -> [[location(0)]] vec4<f32> {
14
- var result : vec4<f32>;
15
- let c = coord.xy / canvas.size;
16
- if (c.x < 0.33333) {
17
- result = textureLoad(
18
- gBufferPosition,
19
- vec2<i32>(floor(coord.xy)),
20
- 0
21
- );
22
- } else if (c.x < 0.66667) {
23
- result = textureLoad(
24
- gBufferNormal,
25
- vec2<i32>(floor(coord.xy)),
26
- 0
27
- );
28
- result.x = (result.x + 1.0) * 0.5;
29
- result.y = (result.y + 1.0) * 0.5;
30
- result.z = (result.z + 1.0) * 0.5;
31
- } else {
32
- result = textureLoad(
33
- gBufferAlbedo,
34
- vec2<i32>(floor(coord.xy)),
35
- 0
36
- );
37
- }
38
- return result;
39
- }
@@ -1,21 +0,0 @@
1
- struct GBufferOutput {
2
- [[location(0)]] position : vec4<f32>;
3
- [[location(1)]] normal : vec4<f32>;
4
-
5
- // Textures: diffuse color, specular color, smoothness, emissive etc. could go here
6
- [[location(2)]] albedo : vec4<f32>;
7
- };
8
-
9
- [[stage(fragment)]]
10
- fn main([[location(0)]] fragPosition: vec3<f32>,
11
- [[location(1)]] fragNormal: vec3<f32>,
12
- [[location(2)]] fragUV : vec2<f32>) -> GBufferOutput {
13
- var output : GBufferOutput;
14
- output.position = vec4<f32>(fragPosition, 1.0);
15
- output.normal = vec4<f32>(fragNormal, 1.0);
16
- // faking some kind of checkerboard texture
17
- let uv = floor(30.0 * fragUV);
18
- let c = 0.2 + 0.5 * ((uv.x + uv.y) - 2.0 * floor((uv.x + uv.y) / 2.0));
19
- output.albedo = vec4<f32>(c, c, c, 1.0);
20
- return output;
21
- }