@woosh/meep-engine 2.75.8 → 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 (77) hide show
  1. package/build/bundle-worker-terrain.js +1 -1
  2. package/build/meep.cjs +784 -982
  3. package/build/meep.min.js +1 -1
  4. package/build/meep.module.js +784 -982
  5. package/editor/actions/concrete/ModifyPatchSampler2DAction.js +6 -3
  6. package/editor/actions/concrete/PatchTerrainTextureAction.js +6 -3
  7. package/editor/process/EditorProcess.js +12 -16
  8. package/editor/process/ProcessEngine.js +9 -10
  9. package/package.json +1 -1
  10. package/src/core/binary/dec2hex.js +1 -1
  11. package/src/{engine/ecs/ik/IKMath.js → core/geom/vec3/v3_computeOffsetVector.js} +1 -1
  12. package/src/core/math/newton_solver_1d.js +13 -4
  13. package/src/core/math/solveQuadratic.js +5 -3
  14. package/src/core/math/spline/catmull_rom_compute_T.js +19 -0
  15. package/src/{engine/navigation/ecs/components → core/math/spline}/computeCatmullRomSpline.js +3 -3
  16. package/src/{engine/navigation/ecs/components → core/math/spline}/computeCatmullRomSplineUniformDistance.js +3 -3
  17. package/src/core/math/spline/computeNonuniformCatmullRomSplineSample.js +109 -0
  18. package/src/core/math/spline/interpolate_bicubic.js +12 -0
  19. package/src/core/math/spline/spline_catmullrom_1d.js +120 -0
  20. package/src/engine/control/ControlContext.js +25 -27
  21. package/src/engine/ecs/EntityManager.js +12 -9
  22. package/src/engine/ecs/EntityObserver.js +26 -22
  23. package/src/engine/ecs/binding/ComponentPropertyPath.js +12 -12
  24. package/src/engine/ecs/components/Motion.js +5 -7
  25. package/src/engine/ecs/components/SerializationMetadata.js +5 -3
  26. package/src/engine/ecs/dynamic_actions/actions/definition/AbstractActionDescription.js +0 -2
  27. package/src/engine/ecs/dynamic_actions/actions/definition/ActionSequenceDescription.js +7 -9
  28. package/src/engine/ecs/dynamic_actions/actions/definition/DelayActionDescription.js +3 -5
  29. package/src/engine/ecs/dynamic_actions/actions/definition/SendRequestActionDescription.js +6 -8
  30. package/src/engine/ecs/dynamic_actions/actions/definition/SpeakLineActionDescription.js +14 -17
  31. package/src/engine/ecs/dynamic_actions/actions/definition/WeightedRandomActionDescription.js +8 -11
  32. package/src/engine/ecs/dynamic_actions/actions/definition/WriteToBlackboardActionDescription.js +15 -18
  33. package/src/engine/ecs/ik/OneBoneSurfaceAlignmentSolver.js +7 -7
  34. package/src/engine/ecs/ik/TwoBoneInverseKinematicsSolver.js +6 -6
  35. package/src/engine/ecs/parent/EntityNode.js +39 -37
  36. package/src/engine/ecs/speaker/VoiceSystem.js +36 -39
  37. package/src/engine/ecs/system/SystemEntityContext.js +25 -23
  38. package/src/engine/ecs/tag/find_entities_with_tag.js +18 -0
  39. package/src/engine/ecs/terrain/TerrainClouds.js +23 -24
  40. package/src/engine/ecs/terrain/ecs/splat/SplatMapMaterialPatch.js +5 -2
  41. package/src/engine/ecs/terrain/overlay/TerrainOverlay.js +15 -14
  42. package/src/engine/ecs/tooltip/TooltipComponent.js +6 -7
  43. package/src/engine/graphics/camera/testClippingPlaneComputation.js +0 -4
  44. package/src/engine/graphics/ecs/path/testPathDisplaySystem.js +1 -5
  45. package/src/engine/graphics/ecs/path/tube/prototypeAnimatedPathMask.js +2 -6
  46. package/src/engine/graphics/ecs/water2/shader/testWaterShader.js +12 -14
  47. package/src/engine/graphics/material/optimization/MaterialOptimizationContext.js +22 -20
  48. package/src/engine/graphics/particles/particular/engine/utils/volume/prototypeParticleVolume.js +3 -4
  49. package/src/engine/graphics/render/buffer/buffers/prototypeNormalFrameBuffer.js +0 -4
  50. package/src/engine/graphics/render/forward_plus/plugin/ptototypeFPPlugin.js +0 -4
  51. package/src/engine/graphics/render/visibility/hiz/prototypeHiZ.js +0 -4
  52. package/src/engine/graphics/shadows/testShadowMapRendering.js +0 -2
  53. package/src/engine/graphics/texture/atlas/TextureAtlas.js +13 -11
  54. package/src/engine/graphics/texture/sampler/Sampler2D.js +15 -366
  55. package/src/engine/graphics/texture/sampler/Sampler2D.spec.js +0 -31
  56. package/src/engine/graphics/texture/sampler/sampler2d_copy_with_margins.js +166 -0
  57. package/src/engine/graphics/texture/sampler/sampler2d_copy_with_margins.spec.js +31 -0
  58. package/src/engine/graphics/texture/sampler/sampler2d_paint.js +81 -0
  59. package/src/engine/graphics/texture/sampler/sampler2d_sub_copy_same_item_size.js +50 -0
  60. package/src/engine/navigation/ecs/components/Path.js +10 -9
  61. package/src/engine/physics/computeInterceptPoint.js +44 -0
  62. package/src/engine/plugin/EnginePlugin.js +1 -2
  63. package/src/engine/ecs/components/AlignToVelocity.js +0 -9
  64. package/src/engine/ecs/components/CharacterController.js +0 -31
  65. package/src/engine/ecs/components/PhysicalBody.js +0 -51
  66. package/src/engine/ecs/components/Steering.js +0 -111
  67. package/src/engine/ecs/components/SteeringSerializationAdapter.js +0 -34
  68. package/src/engine/ecs/systems/AlignToVelocitySystem.js +0 -51
  69. package/src/engine/ecs/systems/CharacterControlSystem.js +0 -134
  70. package/src/engine/ecs/systems/PhysicsSystem.js +0 -89
  71. package/src/engine/ecs/systems/PropertySetSystem.js +0 -18
  72. package/src/engine/ecs/systems/SteeringSystem.js +0 -171
  73. package/src/engine/ecs/systems/TagSystem.d.ts +0 -5
  74. package/src/engine/ecs/systems/TagSystem.js +0 -31
  75. package/src/engine/graphics/texture/sampler/bicubic.js +0 -59
  76. package/src/engine/graphics/texture/sampler/bicubic.spec.js +0 -13
  77. package/src/engine/navigation/ecs/components/computeNonuniformCatmullRomSplineSample.js +0 -242
@@ -0,0 +1,81 @@
1
+ import { BlendingType } from "./BlendingType.js";
2
+
3
+ /**
4
+ *
5
+ * @param {number[]} source
6
+ * @param {number[]} destination
7
+ * @param {Array} result
8
+ */
9
+ function blendFunctionNormal(source, destination, result) {
10
+
11
+ const a1 = source[3] / 255;
12
+ const a0 = destination[3] / 255;
13
+
14
+ result[0] = source[0] * a1 + destination[0] * (1 - a1);
15
+ result[1] = source[1] * a1 + destination[1] * (1 - a1);
16
+ result[2] = source[2] * a1 + destination[2] * (1 - a1);
17
+ result[3] = (a1 + a0 * (1 - a1)) * 255;
18
+ }
19
+
20
+ /**
21
+ * Assumes both samplers are RGBA uint8 with values 0-255
22
+ * @param {Sampler2D} destination
23
+ * @param {Sampler2D} source
24
+ * @param {number} sourceX
25
+ * @param {number} sourceY
26
+ * @param {number} destinationX
27
+ * @param {number} destinationY
28
+ * @param {number} width
29
+ * @param {number} height
30
+ * @param {BlendingType} [blendMode]
31
+ */
32
+ export function sampler2d_paint(
33
+ destination,
34
+ source,
35
+ sourceX, sourceY,
36
+ destinationX, destinationY,
37
+ width, height,
38
+ blendMode = BlendingType.Normal
39
+ ) {
40
+
41
+ let blendFunction;
42
+ if (blendMode === BlendingType.Normal) {
43
+ blendFunction = blendFunctionNormal;
44
+ } else {
45
+ throw new Error(`Unsupported blendType(=${blendMode})`);
46
+ }
47
+
48
+ const _w = Math.min(width, source.width - sourceX, destination.width - destinationX);
49
+ const _h = Math.min(height, source.height - sourceY, destination.height - destinationY);
50
+
51
+ const _x0 = Math.max(0, -destinationX);
52
+ const _y0 = Math.max(0, -destinationY);
53
+
54
+ const c0 = [0, 0, 0, 255];
55
+ const c1 = [0, 0, 0, 255];
56
+
57
+ const c3 = [];
58
+
59
+ let x, y;
60
+
61
+ for (y = _y0; y < _h; y++) {
62
+ for (x = _x0; x < _w; x++) {
63
+ const d_x = Math.round(x + destinationX);
64
+ const d_y = Math.round(y + destinationY);
65
+
66
+ destination.read(d_x, d_y, c0);
67
+
68
+ const s_x = Math.round(x + sourceY);
69
+ const s_y = Math.round(y + sourceY);
70
+
71
+ source.read(s_x, s_y, c1);
72
+
73
+ blendFunction(c1, c0, c3);
74
+
75
+ destination.set(d_x, d_y, c3);
76
+
77
+ }
78
+ }
79
+
80
+
81
+ }
@@ -0,0 +1,50 @@
1
+ import { assert } from "../../../../core/assert.js";
2
+
3
+ /**
4
+ * Copy a patch from another sampler with the same itemSize
5
+ * @param {Sampler2D} destination
6
+ * @param {Sampler2D} source where to copy from
7
+ * @param {Number} sourceX where to start reading from, X coordinate
8
+ * @param {Number} sourceY where to start reading from, X coordinate
9
+ * @param {Number} destinationX where to start writing to, X coordinate
10
+ * @param {Number} destinationY where to start writing to, X coordinate
11
+ * @param {Number} width size of the patch that is to be copied
12
+ * @param {Number} height size of the patch that is to be copied
13
+ */
14
+ export function sampler2d_sub_copy_same_item_size(destination, source, sourceX, sourceY, destinationX, destinationY, width, height) {
15
+ const itemSize = destination.itemSize;
16
+ const sItemSize = source.itemSize;
17
+
18
+ assert.equal(sItemSize, sItemSize, `source.itemSize(=${sItemSize}) != destination.itemSize(=${itemSize})`);
19
+
20
+ const _w = Math.min(width, source.width - sourceX, destination.width - destinationX);
21
+ const _h = Math.min(height, source.height - sourceY, destination.height - destinationY);
22
+
23
+
24
+ const dRowSize = itemSize * destination.width;
25
+ const sRowSize = itemSize * source.width;
26
+
27
+ const sData = source.data;
28
+ const dData = destination.data;
29
+
30
+ const patchRowSize = _w * itemSize;
31
+
32
+ let y, i;
33
+
34
+ for (y = 0; y < _h; y++) {
35
+ const dA = (y + destinationY) * dRowSize;
36
+ const sA = (y + sourceY) * sRowSize;
37
+
38
+ const dOffset = dA + destinationX * itemSize;
39
+ const sOffset = sA + sourceX * itemSize;
40
+
41
+ for (i = 0; i < patchRowSize; i++) {
42
+
43
+ dData[dOffset + i] = sData[sOffset + i];
44
+
45
+ }
46
+ }
47
+
48
+ // update destination version
49
+ destination.version++;
50
+ }
@@ -3,23 +3,24 @@
3
3
  */
4
4
 
5
5
 
6
- import Vector3 from "../../../../core/geom/Vector3.js";
7
-
8
6
  import { CatmullRomCurve3 } from "three";
9
- import { clamp } from "../../../../core/math/clamp.js";
10
7
  import { assert } from "../../../../core/assert.js";
11
- import { RowFirstTableSpec } from "../../../../core/collection/table/RowFirstTableSpec.js";
12
8
  import { BinaryDataType } from "../../../../core/binary/type/BinaryDataType.js";
13
9
  import { RowFirstTable } from "../../../../core/collection/table/RowFirstTable.js";
14
- import { min2 } from "../../../../core/math/min2.js";
15
- import { computeNonuniformCatmullRomSplineSample } from "./computeNonuniformCatmullRomSplineSample.js";
16
- import { InterpolationType } from "./InterpolationType.js";
17
- import { v3_distance } from "../../../../core/geom/vec3/v3_distance.js";
10
+ import { RowFirstTableSpec } from "../../../../core/collection/table/RowFirstTableSpec.js";
18
11
  import {
19
12
  line3_computeSegmentPointDistance_sqr
20
13
  } from "../../../../core/geom/3d/line/line3_computeSegmentPointDistance_sqr.js";
21
- import { VertexDataSpec } from "../../../graphics/geometry/VertexDataSpec.js";
14
+ import { v3_distance } from "../../../../core/geom/vec3/v3_distance.js";
15
+ import Vector3 from "../../../../core/geom/Vector3.js";
16
+ import { clamp } from "../../../../core/math/clamp.js";
17
+ import { min2 } from "../../../../core/math/min2.js";
18
+ import {
19
+ computeNonuniformCatmullRomSplineSample
20
+ } from "../../../../core/math/spline/computeNonuniformCatmullRomSplineSample.js";
22
21
  import { AttributeSpec } from "../../../graphics/geometry/AttributeSpec.js";
22
+ import { VertexDataSpec } from "../../../graphics/geometry/VertexDataSpec.js";
23
+ import { InterpolationType } from "./InterpolationType.js";
23
24
 
24
25
  const v3_a = new Vector3();
25
26
  const v3_b = new Vector3();
@@ -0,0 +1,44 @@
1
+ import { v3_dot } from "../../core/geom/vec3/v3_dot.js";
2
+ import { solveQuadratic } from "../../core/math/solveQuadratic.js";
3
+
4
+ /**
5
+ *
6
+ * @param {Vector3} result
7
+ * @param {Vector3} source
8
+ * @param {Vector3} target
9
+ * @param {Vector3} targetVelocity
10
+ * @param {number} sourceSpeed
11
+ * @return {boolean}
12
+ */
13
+ function computeInterceptPoint(result, source, target, targetVelocity, sourceSpeed) {
14
+ const d_ts_x = target.x - source.x;
15
+ const d_ts_y = target.y - source.y;
16
+ const d_ts_z = target.z - source.z;
17
+
18
+ // Get quadratic equation components
19
+ const a = targetVelocity.dot(targetVelocity) - sourceSpeed * sourceSpeed;
20
+ const b = 2 * v3_dot(targetVelocity.x, targetVelocity.y, targetVelocity.z, d_ts_x, d_ts_y, d_ts_z);
21
+
22
+ const c = v3_dot(
23
+ d_ts_x, d_ts_y, d_ts_z,
24
+ d_ts_x, d_ts_y, d_ts_z
25
+ );
26
+
27
+ // Solve quadratic
28
+ const ts = [];
29
+ const root_count = solveQuadratic(ts, 0, a, b, c); // See quad(), below
30
+
31
+ // Find smallest positive solution
32
+ if (root_count > 0) {
33
+ const t0 = ts[0], t1 = ts[1];
34
+ let t = Math.min(t0, t1);
35
+ if (t < 0) t = Math.max(t0, t1);
36
+
37
+ if (t > 0) {
38
+ result.copy(targetVelocity).multiplyScalar(t).add(target);
39
+ return true;
40
+ }
41
+
42
+ }
43
+ return false;
44
+ }
@@ -1,5 +1,5 @@
1
- import { BaseProcess } from "../../core/process/BaseProcess.js";
2
1
  import { assert } from "../../core/assert.js";
2
+ import { BaseProcess } from "../../core/process/BaseProcess.js";
3
3
 
4
4
  export class EnginePlugin extends BaseProcess {
5
5
 
@@ -16,7 +16,6 @@ export class EnginePlugin extends BaseProcess {
16
16
  */
17
17
  engine = null;
18
18
 
19
-
20
19
  attach() {
21
20
  /**
22
21
  * Must be unique for each plugin
@@ -1,9 +0,0 @@
1
- /**
2
- * Created by Alex on 19/03/2015.
3
- */
4
-
5
- function AlignToVelocity(options) {
6
- this.angularSpeed = options !== void 0 ? options : Number.POSITIVE_INFINITY;
7
- }
8
-
9
- export default AlignToVelocity;
@@ -1,31 +0,0 @@
1
- /**
2
- * FPS-style character controller
3
- * @author Alex Goldring
4
- * @copyright Alex Goldring 7/4/2014
5
- */
6
- class CharacterController {
7
- height = 4;
8
- onSolidSurface = false;
9
- lockedTimeout = 0;
10
- //
11
- forward = false;
12
- back = false;
13
- left = false;
14
- right = false;
15
- sprinting = false;
16
- attacking = false;
17
- aim = null;
18
- //
19
- movementSpeed = 1;
20
- sprintingMultiplier = 1;
21
-
22
- constructor({
23
- movementSpeed = 1,
24
- sprintingMultiplier = 1.2
25
- } = {}) {
26
- this.movementSpeed = movementSpeed;
27
- this.sprintingMultiplier = sprintingMultiplier;
28
- }
29
- }
30
-
31
- export default CharacterController;
@@ -1,51 +0,0 @@
1
- /**
2
- * Created by Alex on 01/04/2014.
3
- */
4
- import Vector3 from "../../../core/geom/Vector3.js";
5
-
6
- let Shape = function () {
7
- this.type = void 0;
8
- };
9
- const BoxShape = function (options) {
10
- this.type = "box";
11
- const s = options.size;
12
- this.size = new Vector3(s.x, s.y, s.z);
13
- };
14
- const SphereShape = function (options) {
15
- this.type = "sphere";
16
- this.radius = options.radius;
17
- };
18
-
19
- function makeShape(desc) {
20
- switch (desc.type) {
21
- case "box":
22
- return new BoxShape(desc);
23
- case "sphere":
24
- return new SphereShape(desc);
25
- default:
26
- return desc;
27
- }
28
- }
29
-
30
- function PhysicalBody(options) {
31
- this.shape = makeShape(options.shape);
32
- this.velocity = new Vector3();
33
- this.linearDamping = options.linearDamping !== void 0 ? options.linearDamping : 0;
34
- this.angularVelocity = new Vector3();
35
- this.rotationAxis = new Vector3();
36
- //this.friction = options.friction !== void 0 ? options.friction : 0;
37
- if (options.rotationAxis !== void 0) {
38
- this.rotationAxis.copy(options.rotationAxis);
39
- }
40
- this.mass = options.mass !== void 0 ? options.mass : 0;
41
- this.collisionResponse = options.collisionResponse !== void 0 ? options.collisionResponse : true;
42
- //
43
- if (options.velocity !== void 0) {
44
- this.velocity.copy(options.velocity);
45
- }
46
- if (options.angularVelocity !== void 0) {
47
- this.angularVelocity.copy(options.angularVelocity);
48
- }
49
- }
50
-
51
- export default PhysicalBody;
@@ -1,111 +0,0 @@
1
- /**
2
- * User: Alex Goldring
3
- * Date: 1/6/2014
4
- * Time: 08:37
5
- */
6
-
7
-
8
- import Vector3 from '../../../core/geom/Vector3.js';
9
-
10
- /**
11
- * @readonly
12
- * @enum {String}
13
- */
14
- export const SteeringEvents = {
15
- DestinationReached: "steeringDestinationReached"
16
- };
17
-
18
- /**
19
- * @readonly
20
- * @enum {number}
21
- */
22
- export const SteeringFlags = {
23
- Active: 1
24
- };
25
-
26
- class Steering {
27
- constructor() {
28
- this.maxSpeed = 1;
29
-
30
- /**
31
- * @readonly
32
- * @type {Vector3}
33
- */
34
- this.destination = new Vector3();
35
-
36
- this.targetMargin = new Vector3(0.001, 0.001, 0.001);
37
-
38
- this.rotationSpeed = Math.PI / 2;
39
-
40
- /**
41
- *
42
- * @type {number}
43
- */
44
- this.flags = 0;
45
- }
46
-
47
- /**
48
- *
49
- * @param {number|SteeringFlags} flag
50
- * @returns {void}
51
- */
52
- setFlag(flag) {
53
- this.flags |= flag;
54
- }
55
-
56
- /**
57
- *
58
- * @param {number|SteeringFlags} flag
59
- * @returns {void}
60
- */
61
- clearFlag(flag) {
62
- this.flags &= ~flag;
63
- }
64
-
65
- /**
66
- *
67
- * @param {number|SteeringFlags} flag
68
- * @param {boolean} value
69
- */
70
- writeFlag(flag, value) {
71
- if (value) {
72
- this.setFlag(flag);
73
- } else {
74
- this.clearFlag(flag);
75
- }
76
- }
77
-
78
- /**
79
- *
80
- * @param {number|SteeringFlags} flag
81
- * @returns {boolean}
82
- */
83
- getFlag(flag) {
84
- return (this.flags & flag) === flag;
85
- }
86
-
87
- fromJSON(json) {
88
- if (json.maxSpeed !== undefined) {
89
- this.maxSpeed = json.maxSpeed;
90
- }
91
- if (json.rotationSpeed !== undefined) {
92
- this.rotationSpeed = json.rotationSpeed;
93
- }
94
- if (json.targetMargin !== undefined) {
95
- this.targetMargin.fromJSON(json.targetMargin);
96
- }
97
- }
98
-
99
- toJSON() {
100
- return {
101
- maxSpeed: this.maxSpeed,
102
- rotationSpeed: this.rotationSpeed,
103
- targetMargin: this.targetMargin.toJSON()
104
- };
105
- }
106
- }
107
-
108
- Steering.typeName = "Steering";
109
-
110
- export default Steering;
111
-
@@ -1,34 +0,0 @@
1
- import { BinaryClassSerializationAdapter } from "../storage/binary/BinaryClassSerializationAdapter.js";
2
- import Steering from "./Steering.js";
3
-
4
- export class SteeringSerializationAdapter extends BinaryClassSerializationAdapter {
5
-
6
- klass = Steering;
7
- version = 0;
8
-
9
- /**
10
- *
11
- * @param {BinaryBuffer} buffer
12
- * @param {Steering} value
13
- */
14
- serialize(buffer, value) {
15
- buffer.writeFloat32(value.maxSpeed);
16
- buffer.writeFloat32(value.rotationSpeed);
17
-
18
- value.destination.toBinaryBufferFloat32(buffer);
19
- value.targetMargin.toBinaryBufferFloat32_EqualityEncoded(buffer);
20
- }
21
-
22
- /**
23
- *
24
- * @param {BinaryBuffer} buffer
25
- * @param {Steering} value
26
- */
27
- deserialize(buffer, value) {
28
- value.maxSpeed = buffer.readFloat32();
29
- value.rotationSpeed = buffer.readFloat32();
30
-
31
- value.destination.fromBinaryBufferFloat32(buffer);
32
- value.targetMargin.fromBinaryBufferFloat32_EqualityEncoded(buffer);
33
- }
34
- }
@@ -1,51 +0,0 @@
1
- /**
2
- * Created by Alex on 19/03/2015.
3
- */
4
- import { System } from '../System.js';
5
- import AlignToVelocity from '../components/AlignToVelocity.js';
6
- import { Transform } from '../transform/Transform.js';
7
- import Motion from '../components/Motion.js';
8
- import Vector3 from "../../../core/geom/Vector3.js";
9
-
10
-
11
- class AlignToVelocitySystem extends System {
12
- constructor() {
13
- super();
14
-
15
- this.dependencies = [AlignToVelocity];
16
- }
17
-
18
- add(aabb, entity) {
19
-
20
- }
21
-
22
- remove(component) {
23
- }
24
-
25
- update(timeDelta) {
26
- const em = this.entityManager;
27
- const MotionType = em.getOwnerSystemIdByComponentClass(Motion);
28
- const PhysicsBodyType = em.getOwnerSystemIdByComponentClass(PhysicsBody);
29
- const velocity = new Vector3();
30
- em.traverseEntities([AlignToVelocity, Transform], function (align, transform, entity) {
31
- //find velocity
32
- const motion = em.getComponentByType(entity, MotionType);
33
- if (motion !== null) {
34
- velocity.copy(motion.velocity);
35
- } else {
36
- const body = em.getComponentByType(entity, PhysicsBodyType);
37
- if (body !== null) {
38
- velocity.copy(body.velocity);
39
- } else {
40
- return;
41
- }
42
- }
43
- const delta = velocity.sub(transform.position);
44
- //set transform rotation based on velocity
45
- Transform.adjustRotation(transform.rotation, delta, align.angularSpeed * timeDelta);
46
- });
47
- }
48
- }
49
-
50
-
51
- export default AlignToVelocitySystem;
@@ -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;