@woosh/meep-engine 2.36.28 → 2.37.0

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 (125) hide show
  1. package/core/bvh2/bvh3/{bvh_query_user_data_by_frustum.js → bvh_query_user_data_overlaps_frustum.js} +4 -5
  2. package/core/bvh2/traversal/ThreeClippingPlaneComputingBVHVisitor.js +1 -1
  3. package/core/color/Color.js +54 -3
  4. package/core/color/hsv2rgb.js +3 -3
  5. package/core/color/kelvin_to_rgb.js +51 -0
  6. package/core/color/kelvin_to_rgb.spec.js +61 -0
  7. package/core/color/linear_to_sRGB.js +17 -0
  8. package/core/color/prototype_kelvin_to_rgb.js +44 -0
  9. package/core/color/rgb_to_kelvin.js +34 -0
  10. package/core/color/rgb_to_kelvin.spec.js +15 -0
  11. package/core/color/sRGB_to_linear.js +16 -0
  12. package/core/geom/3d/frustum/read_frustum_planes_to_array.d.ts +3 -0
  13. package/{engine/graphics/render/forward_plus/cluster → core/geom/3d/frustum}/read_frustum_planes_to_array.js +1 -1
  14. package/core/geom/3d/line/line3_computeSegmentPointDistance_sqr.js +2 -2
  15. package/core/geom/LineSegment.js +2 -2
  16. package/core/geom/Vector3.js +14 -0
  17. package/core/math/DEG_TO_RAD.js +1 -0
  18. package/core/math/MathUtils.spec.js +0 -13
  19. package/core/math/RAD_TO_DEG.js +1 -0
  20. package/core/math/clamp01.js +15 -0
  21. package/core/math/fract.js +10 -0
  22. package/core/math/newton_solver_1d.js +21 -0
  23. package/core/math/smoothStep.js +3 -3
  24. package/core/math/solveQuadratic.js +32 -12
  25. package/core/math/solveQuadratic.spec.js +18 -0
  26. package/core/primitives/strings/StringUtils.js +10 -0
  27. package/core/process/task/TaskUtils.js +2 -2
  28. package/core/process/undo/Action.d.ts +2 -2
  29. package/core/process/undo/Action.js +4 -4
  30. package/core/process/undo/ActionGroup.js +4 -4
  31. package/core/process/undo/ActionProcessor.d.ts +6 -6
  32. package/core/process/undo/ActionProcessor.js +106 -16
  33. package/core/process/undo/ActionProcessor.spec.js +20 -15
  34. package/editor/actions/concrete/ComponentAddAction.js +2 -2
  35. package/editor/actions/concrete/ComponentRemoveAction.js +2 -2
  36. package/editor/actions/concrete/EntityCreateAction.js +2 -2
  37. package/editor/actions/concrete/EntityRemoveAction.js +2 -2
  38. package/editor/actions/concrete/PaintTerrainOverlayAction.js +2 -2
  39. package/editor/actions/concrete/PatchTerrainHeightAction.js +2 -2
  40. package/editor/actions/concrete/PatchTerrainTextureAction.js +2 -2
  41. package/editor/actions/concrete/SelectionAddAction.js +2 -2
  42. package/editor/actions/concrete/SelectionClearAction.js +2 -2
  43. package/editor/actions/concrete/SelectionRemoveAction.js +2 -2
  44. package/editor/actions/concrete/TransformModifyAction.js +2 -2
  45. package/editor/actions/concrete/WriteGridValueAction.js +2 -2
  46. package/editor/view/EditorView.js +11 -9
  47. package/editor/view/ecs/components/color/GaugeView.js +2 -2
  48. package/editor/view/ecs/components/particles/ColorParameterLUTController.js +5 -4
  49. package/editor/view/ecs/components/particles/ScalarParameterLUTController.js +5 -3
  50. package/engine/Clock.js +4 -0
  51. package/engine/UserController.js +2 -1
  52. package/engine/animation/behavior/animateProperty.js +6 -1
  53. package/engine/animation/keyed2/behavior/AnimationBehavior.js +0 -1
  54. package/engine/ecs/EntityBuilder.js +12 -1
  55. package/engine/ecs/animation/OneBoneSurfaceAlignmentSolver.js +2 -1
  56. package/engine/ecs/animation/TwoBoneInverseKinematicsSolver.js +2 -1
  57. package/engine/ecs/fow/shader/screenSpaceFogOfWarShader.js +14 -11
  58. package/engine/ecs/systems/AimControllerSystem.js +3 -2
  59. package/engine/ecs/systems/RangedAttackSystem.js +3 -2
  60. package/engine/ecs/systems/SteeringSystem.js +3 -3
  61. package/engine/ecs/terrain/ecs/ClingToTerrainSystem.js +2 -2
  62. package/engine/ecs/terrain/util/paintTerrainOverlayViaLookupTable.js +2 -2
  63. package/engine/graphics/GraphicsEngine.js +2 -1
  64. package/engine/graphics/camera/CameraShake.js +4 -4
  65. package/engine/graphics/ecs/animation/animator/graph/AnimationTransition.js +2 -2
  66. package/engine/graphics/ecs/camera/TiltCameraController.js +3 -2
  67. package/engine/graphics/ecs/compileAllMaterials.js +2 -2
  68. package/engine/graphics/ecs/highlight/renderer/OutlineRenderer.js +10 -11
  69. package/engine/graphics/ecs/mesh/createTaskWaitForMeshesToLoad.js +2 -2
  70. package/engine/graphics/ecs/mesh-v2/ShadedGeometrySystem.d.ts +6 -0
  71. package/engine/graphics/ecs/mesh-v2/ShadedGeometrySystem.js +19 -0
  72. package/engine/graphics/ecs/mesh-v2/render/ShadedGeometryRendererContext.js +4 -2
  73. package/engine/graphics/ecs/mesh-v2/render/optimization/RuntimeDrawMethodOptimizer.js +6 -0
  74. package/engine/graphics/geometry/instancing/InstancedMeshGroup.js +31 -0
  75. package/engine/graphics/micron/build/fill_patch_geometry_data.js +2 -2
  76. package/engine/graphics/particles/particular/engine/utils/volume/prototypeParticleVolume.js +5 -3
  77. package/engine/graphics/render/forward_plus/LightManager.js +1 -1
  78. package/engine/graphics/render/gizmo/Gizmo.js +3 -0
  79. package/engine/graphics/render/gizmo/GizmoRenderingPlugin.js +5 -0
  80. package/engine/graphics/render/gizmo/GizmoShapeRenderingInterface.js +91 -0
  81. package/engine/graphics/render/view/CameraView.js +1 -1
  82. package/engine/graphics/texture/sampler/Sampler2D.js +110 -18
  83. package/engine/graphics/three/OrbitControls.js +3 -2
  84. package/engine/graphics/trail/x/simulator/RibbonXFixedPhysicsSimulator.js +2 -2
  85. package/engine/graphics/util/makeMeshPreviewScene.js +11 -3
  86. package/engine/intelligence/behavior/Behavior.js +36 -17
  87. package/engine/intelligence/behavior/SelectorBehavior.js +6 -5
  88. package/engine/intelligence/behavior/composite/ParallelBehavior.js +0 -66
  89. package/engine/intelligence/behavior/composite/ParallelBehaviorSerializationAdapter.js +63 -0
  90. package/engine/intelligence/behavior/composite/SequenceBehavior.js +36 -11
  91. package/engine/intelligence/behavior/decorator/AbstractDecoratorBehavior.js +0 -2
  92. package/engine/intelligence/behavior/decorator/IgnoreFailureBehavior.js +2 -4
  93. package/engine/intelligence/behavior/decorator/InverterBehavior.js +3 -3
  94. package/engine/intelligence/behavior/decorator/RepeatBehavior.js +0 -35
  95. package/engine/intelligence/behavior/decorator/RepeatBehavior.spec.js +0 -10
  96. package/engine/intelligence/behavior/decorator/RepeatBehaviorSerializationAdapter.js +37 -0
  97. package/engine/intelligence/behavior/decorator/RepeatUntilFailureBehavior.js +0 -3
  98. package/engine/intelligence/behavior/decorator/RepeatUntilSuccessBehavior.js +5 -10
  99. package/engine/intelligence/behavior/ecs/BehaviorComponent.js +95 -7
  100. package/engine/intelligence/behavior/ecs/BehaviorComponentSerializationAdapter.js +15 -8
  101. package/engine/intelligence/behavior/ecs/BehaviorSystem.js +28 -37
  102. package/engine/intelligence/behavior/ecs/DieBehavior.js +2 -7
  103. package/engine/intelligence/behavior/ecs/WaitForEventBehavior.js +2 -29
  104. package/engine/intelligence/behavior/ecs/WaitForEventBehaviorSerializationAdapter.js +29 -0
  105. package/engine/intelligence/behavior/primitive/ActionBehavior.js +6 -13
  106. package/engine/intelligence/behavior/primitive/FailingBehavior.js +1 -29
  107. package/engine/intelligence/behavior/primitive/FailingBehaviorSerializationAdapter.js +29 -0
  108. package/engine/intelligence/behavior/primitive/PromiseBehavior.js +15 -3
  109. package/engine/intelligence/behavior/selector/WeightedRandomBehavior.js +1 -5
  110. package/engine/intelligence/behavior/util/ConditionBehavior.js +1 -3
  111. package/engine/intelligence/behavior/util/ConditionBehavior.spec.js +1 -7
  112. package/engine/intelligence/behavior/util/ConditionalBehavior.js +3 -6
  113. package/engine/intelligence/behavior/util/DelayBehavior.js +2 -4
  114. package/engine/intelligence/behavior/util/SelectorBehavior.js +13 -12
  115. package/engine/intelligence/blackboard/AbstractBlackboard.js +16 -2
  116. package/engine/plugin/EnginePluginManager.js +4 -14
  117. package/engine/sound/ecs/emitter/SoundEmitter.js +3 -0
  118. package/generation/filtering/numeric/math/CellFilterSaturate.js +2 -2
  119. package/generation/grid/generation/GridTaskDensityMarkerDistribution.js +3 -2
  120. package/generation/markers/transform/MarkerNodeTransformerYRotateByFilterGradient.spec.js +1 -1
  121. package/generation/rules/CellMatcherLayerBitMaskTest.js +3 -3
  122. package/package.json +1 -1
  123. package/view/elements/progress/SmoothProgressBar.js +2 -2
  124. package/view/elements/progress/segmented/SegmentedResourceBarView.js +3 -3
  125. package/view/elements/radial/RadialProgressView.js +2 -2
@@ -1,9 +1,9 @@
1
- import { clamp } from "../../../../../core/math/clamp.js";
2
1
  import GuiControl from "../../../../../view/controller/controls/GuiControl.js";
3
2
  import EmptyView from "../../../../../view/elements/EmptyView.js";
4
3
  import LabelView from "../../../../../view/common/LabelView.js";
5
4
  import { PointerDevice } from "../../../../../engine/input/devices/PointerDevice.js";
6
5
  import { AutoCanvasView } from "../common/AutoCanvasView.js";
6
+ import { clamp01 } from "../../../../../core/math/clamp01.js";
7
7
 
8
8
  export class GaugeView extends GuiControl {
9
9
  /**
@@ -80,7 +80,7 @@ export class GaugeView extends GuiControl {
80
80
  return;
81
81
  }
82
82
 
83
- model.set(clamp(v, 0, 1));
83
+ model.set(clamp01(v));
84
84
  }
85
85
 
86
86
  function setValueFromMouseEvent(event) {
@@ -1,4 +1,3 @@
1
- import { clamp } from "../../../../../core/math/clamp.js";
2
1
  import GuiControl from "../../../../../view/controller/controls/GuiControl.js";
3
2
  import View from "../../../../../view/View.js";
4
3
  import { PointerDevice } from "../../../../../engine/input/devices/PointerDevice.js";
@@ -7,10 +6,13 @@ import ObservedValue from "../../../../../core/model/ObservedValue.js";
7
6
  import { ColorPickerView } from "../../../../../view/elements/ColorPickerView.js";
8
7
  import Vector1 from "../../../../../core/geom/Vector1.js";
9
8
  import Vector4 from "../../../../../core/geom/Vector4.js";
10
- import { ParameterLookupTableFlags } from "../../../../../engine/graphics/particles/particular/engine/parameter/ParameterLookupTableFlags.js";
9
+ import {
10
+ ParameterLookupTableFlags
11
+ } from "../../../../../engine/graphics/particles/particular/engine/parameter/ParameterLookupTableFlags.js";
11
12
  import { DomSizeObserver } from "../../../../../view/util/DomSizeObserver.js";
12
13
  import { AutoCanvasView } from "../common/AutoCanvasView.js";
13
14
  import EmptyView from "../../../../../view/elements/EmptyView.js";
15
+ import { clamp01 } from "../../../../../core/math/clamp01.js";
14
16
 
15
17
 
16
18
  class MarkerView extends View {
@@ -31,7 +33,6 @@ class MarkerView extends View {
31
33
  }
32
34
 
33
35
 
34
-
35
36
  /**
36
37
  *
37
38
  * @param {Array.<MarkerView>} markers
@@ -74,7 +75,7 @@ function buildMarker(markers, model, update, canvas, selection) {
74
75
 
75
76
  const positionDelta = delta.x / canvas.width;
76
77
 
77
- const newPosition = clamp(oldPosition + positionDelta, 0, 1);
78
+ const newPosition = clamp01(oldPosition + positionDelta);
78
79
 
79
80
  lut.positions[markerIndex] = newPosition;
80
81
 
@@ -1,11 +1,13 @@
1
- import { clamp } from "../../../../../core/math/clamp.js";
2
1
  import GuiControl from "../../../../../view/controller/controls/GuiControl.js";
3
2
  import View from "../../../../../view/View.js";
4
3
  import { PointerDevice } from "../../../../../engine/input/devices/PointerDevice.js";
5
4
  import Vector2 from "../../../../../core/geom/Vector2.js";
6
- import { ParameterLookupTableFlags } from "../../../../../engine/graphics/particles/particular/engine/parameter/ParameterLookupTableFlags.js";
5
+ import {
6
+ ParameterLookupTableFlags
7
+ } from "../../../../../engine/graphics/particles/particular/engine/parameter/ParameterLookupTableFlags.js";
7
8
  import LabelView from "../../../../../view/common/LabelView.js";
8
9
  import Vector1 from "../../../../../core/geom/Vector1.js";
10
+ import { clamp01 } from "../../../../../core/math/clamp01.js";
9
11
 
10
12
 
11
13
  function computeVerticalValuePosition(v, min, max, height, lineWidth) {
@@ -151,7 +153,7 @@ function buildMarker(markers, model, update, canvas) {
151
153
 
152
154
  const valueDelta = valueDeltaNormalized * dragScale;
153
155
 
154
- const newPosition = clamp(oldPosition + positionDelta, 0, 1);
156
+ const newPosition = clamp01(oldPosition + positionDelta);
155
157
 
156
158
  lut.positions[markerIndex] = newPosition;
157
159
 
package/engine/Clock.js CHANGED
@@ -83,6 +83,10 @@ class Clock {
83
83
  this.__isRunning = true;
84
84
  }
85
85
 
86
+ stop() {
87
+ this.__isRunning = false;
88
+ }
89
+
86
90
  pause() {
87
91
  this.__isRunning = false;
88
92
  //update time
@@ -5,6 +5,7 @@ import Vector3 from "../core/geom/Vector3.js";
5
5
  import { Transform } from './ecs/transform/Transform.js';
6
6
  import Hammer from 'Hammer';
7
7
  import { Euler as ThreeEuler, Vector2 as ThreeVector2, Vector3 as ThreeVector3 } from 'three';
8
+ import { DEG_TO_RAD } from "../core/math/DEG_TO_RAD.js";
8
9
 
9
10
  const keyboardRotationSpeed = 1.2;
10
11
 
@@ -37,7 +38,7 @@ function panUp(distance, object, result) {
37
38
  // right and down are positive
38
39
  function pan(delta, object, element, targetDistance, fov, result) {
39
40
  // half of the fov is center to top of screen
40
- targetDistance *= Math.tan((fov / 2) * Math.PI / 180.0);
41
+ targetDistance *= Math.tan((fov / 2) * DEG_TO_RAD);
41
42
  // we actually don't use screenWidth, since perspective camera is fixed to screen height
42
43
  panLeft(2 * delta.x * targetDistance / element.clientHeight, object, result);
43
44
  panUp(2 * delta.y * targetDistance / element.clientHeight, object, result);
@@ -1,10 +1,13 @@
1
- import { TransitionPropertyVectorXBehavior } from "../../../../model/game/story/behaviors/generic/TransitionPropertyVectorXBehavior.js";
1
+ import {
2
+ TransitionPropertyVectorXBehavior
3
+ } from "../../../../model/game/story/behaviors/generic/TransitionPropertyVectorXBehavior.js";
2
4
  import EntityBuilder from "../../ecs/EntityBuilder.js";
3
5
  import { BehaviorComponent } from "../../intelligence/behavior/ecs/BehaviorComponent.js";
4
6
  import { SequenceBehavior } from "../../intelligence/behavior/composite/SequenceBehavior.js";
5
7
  import { DieBehavior } from "../../intelligence/behavior/ecs/DieBehavior.js";
6
8
  import { SendEventBehavior } from "../../../../model/game/util/behavior/SendEventBehavior.js";
7
9
  import { SerializationMetadata } from "../../ecs/components/SerializationMetadata.js";
10
+ import { assert } from "../../../core/assert.js";
8
11
 
9
12
  /**
10
13
  *
@@ -18,6 +21,8 @@ import { SerializationMetadata } from "../../ecs/components/SerializationMetadat
18
21
  */
19
22
  export async function animateProperty(ecd, entity, component, property, target, time) {
20
23
 
24
+ assert.ok(ecd.entityExists(entity), `entity ${entity} doesn't exist`);
25
+
21
26
  const builder = new EntityBuilder()
22
27
  .add(SerializationMetadata.Transient)
23
28
  .add(BehaviorComponent.fromOne(SequenceBehavior.from([
@@ -29,6 +29,5 @@ export class AnimationBehavior extends Behavior {
29
29
 
30
30
  initialize() {
31
31
  this.animation.setPosition(this.animation.track.timeStart);
32
- this.__status = BehaviorStatus.Running;
33
32
  }
34
33
  }
@@ -226,7 +226,18 @@ class EntityBuilder {
226
226
  */
227
227
  promiseEvent(eventName) {
228
228
  return new Promise((resolve, reject) => {
229
- this.addEventListener(eventName, resolve);
229
+
230
+ const handle_event = () => {
231
+
232
+ this.removeEventListener(eventName, handle_event);
233
+ this.removeEventListener(EventType.EntityRemoved, reject);
234
+
235
+ resolve();
236
+ }
237
+
238
+
239
+ this.addEventListener(eventName, handle_event);
240
+ this.removeEventListener(EventType.EntityRemoved, reject);
230
241
  });
231
242
  }
232
243
 
@@ -8,6 +8,7 @@ import { SurfacePoint3 } from "../../../core/geom/3d/SurfacePoint3.js";
8
8
  import { v3_computeOffsetVector } from "./IKMath.js";
9
9
  import { v3_dot } from "../../../core/geom/v3_dot.js";
10
10
  import { v3_length } from "../../../core/geom/v3_length.js";
11
+ import { clamp01 } from "../../../core/math/clamp01.js";
11
12
 
12
13
  const boneWorldPosition = new Vector3();
13
14
  const boneWorldRotation = new Quaternion();
@@ -141,7 +142,7 @@ export class OneBoneSurfaceAlignmentSolver extends IKSolver {
141
142
  //no penetration, hovering case, use hover distance for influence
142
143
  const normalized_effector_distance = inverseLerp(0, bone_scale, delta_contact_c_length);
143
144
 
144
- influence = 1 - clamp(constraint.distance.normalizeValue(normalized_effector_distance), 0, 1);
145
+ influence = 1 - clamp01(constraint.distance.normalizeValue(normalized_effector_distance));
145
146
  }
146
147
 
147
148
  if (influence <= 0) {
@@ -9,6 +9,7 @@ import { IKSolver } from "./IKSolver.js";
9
9
  import { v3_computeOffsetVector } from "./IKMath.js";
10
10
  import { v3_dot } from "../../../core/geom/v3_dot.js";
11
11
  import { v3_length } from "../../../core/geom/v3_length.js";
12
+ import { clamp01 } from "../../../core/math/clamp01.js";
12
13
 
13
14
  const boneWorldPositionC = new Vector3();
14
15
  const boneWorldPositionB = new Vector3();
@@ -280,7 +281,7 @@ export class TwoBoneInverseKinematicsSolver extends IKSolver {
280
281
  //no penetration, hovering case, use hover distance for influence
281
282
  const normalized_effector_distance = inverseLerp(0, limbLength, delta_contact_c_length);
282
283
 
283
- influence = 1 - clamp(constraint.distance.normalizeValue(normalized_effector_distance), 0, 1);
284
+ influence = 1 - clamp01(constraint.distance.normalizeValue(normalized_effector_distance));
284
285
  }
285
286
 
286
287
  if (influence <= 0) {
@@ -25,8 +25,8 @@ export function buildScreenSpaceFogOfWarShader() {
25
25
 
26
26
  varying vec2 vUv;
27
27
 
28
- const float c_samplesX = 7.0;
29
- const float c_samplesY = 7.0;
28
+ const float c_samplesX = 5.0;
29
+ const float c_samplesY = 5.0;
30
30
 
31
31
  const float c_halfSamplesX = c_samplesX / 2.0;
32
32
  const float c_halfSamplesY = c_samplesY / 2.0;
@@ -95,15 +95,15 @@ export function buildScreenSpaceFogOfWarShader() {
95
95
  }
96
96
 
97
97
  void main(){
98
- //get world fragment position
99
- vec3 worldPosition = computeWorldPosition();
100
-
101
- vec2 fogUv = worldPosition.xz * uFogUvTransform.zw + uFogUvTransform.xy;
102
-
103
- float fogValue = getFog( fogUv );
104
-
105
- gl_FragColor = uColor;
106
- gl_FragColor.a *= fogValue;
98
+ //get world fragment position
99
+ vec3 worldPosition = computeWorldPosition();
100
+
101
+ vec2 fogUv = worldPosition.xz * uFogUvTransform.zw + uFogUvTransform.xy;
102
+
103
+ float fogValue = getFog( fogUv );
104
+
105
+ gl_FragColor = uColor;
106
+ gl_FragColor.a *= fogValue;
107
107
  }
108
108
  `;
109
109
  }
@@ -127,6 +127,9 @@ export function buildScreenSpaceFogOfWarShader() {
127
127
  uProjectionInverse: { type: 'm4', value: new Matrix4() },
128
128
  uColor: { type: 'c', value: new Vector4(0, 0, 0, 1) },
129
129
  uFogUvTransform: { type: 'v4', value: new Vector4(0, 0, 1, 1) },
130
+ /**
131
+ * Fog texture resolution
132
+ */
130
133
  uResolution: { type: 'v2', value: new Vector2(0, 0) }
131
134
  };
132
135
 
@@ -7,6 +7,7 @@ import { System } from '../System.js';
7
7
  import AimController from '../components/AimController.js';
8
8
  import CharacterController from '../components/CharacterController.js';
9
9
  import { Transform } from '../transform/Transform.js';
10
+ import { DEG_TO_RAD } from "../../../core/math/DEG_TO_RAD.js";
10
11
 
11
12
 
12
13
  class AimControllerSystem extends System {
@@ -14,7 +15,7 @@ class AimControllerSystem extends System {
14
15
  super();
15
16
  this.dependencies = [AimController];
16
17
 
17
- this.sensitivity = 5 * Math.PI / 180;
18
+ this.sensitivity = 5 * DEG_TO_RAD;
18
19
  }
19
20
 
20
21
  add(component, entity) {
@@ -31,7 +32,7 @@ class AimControllerSystem extends System {
31
32
  updateController(aimController, sensitivity);
32
33
  //rotate player
33
34
  const quaternion = new THREE.Quaternion();
34
- quaternion.setFromAxisAngle(new THREE.Vector3(0, 1, 0), -aimController.lon * (Math.PI / 180));
35
+ quaternion.setFromAxisAngle(new THREE.Vector3(0, 1, 0), -aimController.lon * DEG_TO_RAD);
35
36
  transform.rotation.copy(quaternion);
36
37
  //rotate aim transform
37
38
  const aimTransform = character.aim;
@@ -34,11 +34,12 @@ const intercept = (function () {
34
34
  const c = toTarget.dot(toTarget);
35
35
 
36
36
  // Solve quadratic
37
- const ts = solveQuadratic(a, b, c); // See quad(), below
37
+ const ts = [];
38
+ const root_count = solveQuadratic(ts, 0, a, b, c); // See quad(), below
38
39
 
39
40
  // Find smallest positive solution
40
41
  let sol = null;
41
- if (ts) {
42
+ if (root_count > 0) {
42
43
  const t0 = ts[0], t1 = ts[1];
43
44
  let t = Math.min(t0, t1);
44
45
  if (t < 0) t = Math.max(t0, t1);
@@ -39,11 +39,11 @@ function computeInterceptPoint(result, source, target, targetVelocity, sourceSpe
39
39
  );
40
40
 
41
41
  // Solve quadratic
42
- const ts = solveQuadratic(a, b, c); // See quad(), below
42
+ const ts = [];
43
+ const root_count = solveQuadratic(ts, 0, a, b, c); // See quad(), below
43
44
 
44
45
  // Find smallest positive solution
45
- let sol = null;
46
- if (ts) {
46
+ if (root_count > 0) {
47
47
  const t0 = ts[0], t1 = ts[1];
48
48
  let t = Math.min(t0, t1);
49
49
  if (t < 0) t = Math.max(t0, t1);
@@ -1,7 +1,6 @@
1
1
  /**
2
2
  * Created by Alex on 13/05/2016.
3
3
  */
4
- import { clamp } from "../../../../core/math/clamp.js";
5
4
  import { min2 } from "../../../../core/math/min2.js";
6
5
  import { System } from '../../System.js';
7
6
  import { Transform } from '../../transform/Transform.js';
@@ -16,6 +15,7 @@ import { assert } from "../../../../core/assert.js";
16
15
  import { SurfacePoint3 } from "../../../../core/geom/3d/SurfacePoint3.js";
17
16
  import { Deque } from "../../../../core/collection/queue/Deque.js";
18
17
  import { obtainTerrain } from "../util/obtainTerrain.js";
18
+ import { clamp01 } from "../../../../core/math/clamp01.js";
19
19
 
20
20
 
21
21
  /**
@@ -235,7 +235,7 @@ export function alignToVector(rotation, direction, angularLimit, up = Vector3.up
235
235
  return;
236
236
  }
237
237
 
238
- const t = clamp(angularLimit / angle, 0, 1);
238
+ const t = clamp01(angularLimit / angle);
239
239
 
240
240
  // TODO Consider replacing this with slerp
241
241
  rotation.lerp(q_temp, t);
@@ -1,7 +1,7 @@
1
- import { clamp } from "../../../../core/math/clamp.js";
2
1
  import { Sampler2D } from "../../../graphics/texture/sampler/Sampler2D.js";
3
2
  import { ParameterLookupTable } from "../../../graphics/particles/particular/engine/parameter/ParameterLookupTable.js";
4
3
  import { passThrough } from "../../../../core/function/Functions.js";
4
+ import { clamp01 } from "../../../../core/math/clamp01.js";
5
5
 
6
6
 
7
7
  const heatmap_lut = new ParameterLookupTable(4);
@@ -48,7 +48,7 @@ export function paintTerrainOverlayViaLookupTable({ overlay, sampler, lut = heat
48
48
 
49
49
  const scaledPosition = lookupScaleFunction(p);
50
50
 
51
- const position = clamp(range.normalizeValue(scaledPosition), 0, 1);
51
+ const position = clamp01(range.normalizeValue(scaledPosition));
52
52
 
53
53
  lut.sample(position, colorSample);
54
54
 
@@ -39,6 +39,7 @@ import { CameraViewManager } from "./render/view/CameraViewManager.js";
39
39
  import { StandardFrameBuffers } from "./StandardFrameBuffers.js";
40
40
  import { load_environment_map } from "./texture/cubemap/load_environment_map.js";
41
41
  import { CompositingStages } from "./composit/CompositingStages.js";
42
+ import { DEG_TO_RAD } from "../../core/math/DEG_TO_RAD.js";
42
43
 
43
44
  /**
44
45
  *
@@ -493,7 +494,7 @@ GraphicsEngine.prototype.normalizeViewportPoint = function (input, result) {
493
494
  */
494
495
  GraphicsEngine.prototype.viewportWorldSize = function (camera, zDistance, result) {
495
496
  const size = this.viewport.size;
496
- const angleY = camera.fov * (Math.PI / 180);
497
+ const angleY = camera.fov * DEG_TO_RAD;
497
498
  const cameraZ = camera.position.z;
498
499
  const distFromCamToPlane = Math.abs(cameraZ) + zDistance;
499
500
 
@@ -1,12 +1,12 @@
1
1
  import Vector3 from "../../../core/geom/Vector3.js";
2
2
 
3
3
  import SimplexNoise from 'simplex-noise';
4
- import { clamp } from "../../../core/math/clamp.js";
5
- import { makeCubicCurve} from "../../../core/math/MathUtils.js";
4
+ import { makeCubicCurve } from "../../../core/math/MathUtils.js";
6
5
  import { seededRandom } from "../../../core/math/random/seededRandom.js";
7
6
  import { Behavior } from "../../intelligence/behavior/Behavior.js";
8
7
  import { BehaviorStatus } from "../../intelligence/behavior/BehaviorStatus.js";
9
8
  import Quaternion from "../../../core/geom/Quaternion.js";
9
+ import { clamp01 } from "../../../core/math/clamp01.js";
10
10
 
11
11
  export class CameraShakeTraumaBehavior extends Behavior {
12
12
 
@@ -31,9 +31,9 @@ export class CameraShakeTraumaBehavior extends Behavior {
31
31
  }
32
32
 
33
33
  tick(timeDelta) {
34
- const shake = this.formula(clamp(this.trauma, 0, 1));
34
+ const shake = this.formula(clamp01(this.trauma));
35
35
 
36
- this.trauma = clamp(this.trauma - timeDelta * this.decay, 0, 1);
36
+ this.trauma = clamp01(this.trauma - timeDelta * this.decay);
37
37
 
38
38
 
39
39
  this.shakeBehavior.strength = shake;
@@ -1,6 +1,6 @@
1
- import { clamp } from "../../../../../../core/math/clamp.js";
2
1
  import { lerp } from "../../../../../../core/math/lerp.js";
3
2
  import { BlendStateMatrix } from "../blending/BlendStateMatrix.js";
3
+ import { clamp01 } from "../../../../../../core/math/clamp01.js";
4
4
 
5
5
  export class AnimationTransition {
6
6
  constructor() {
@@ -90,7 +90,7 @@ export class AnimationTransition {
90
90
  }
91
91
 
92
92
  updateBlendsState() {
93
- const t = clamp(this.computeNormalizedTime(), 0, 1);
93
+ const t = clamp01(this.computeNormalizedTime());
94
94
 
95
95
  BlendStateMatrix.lerp(this.blendState, this.source.blendState, this.target.blendState, t);
96
96
  }
@@ -5,13 +5,14 @@ import { Object3D, Vector3 as ThreeVector3 } from 'three';
5
5
 
6
6
  import Vector3 from "../../../../core/geom/Vector3.js";
7
7
  import Vector2 from '../../../../core/geom/Vector2.js';
8
+ import { DEG_TO_RAD } from "../../../../core/math/DEG_TO_RAD.js";
8
9
 
9
10
  const CC = function () {
10
11
  this.target = new Vector3();
11
12
  this.rotationAxis = new Vector3(0, 1, 0);
12
- this.rotationAngle = (Math.PI / 180) * 0;
13
+ this.rotationAngle = DEG_TO_RAD * 0;
13
14
  //angle between rotation axis and vector from target to position
14
- this.tiltAngle = (Math.PI / 180) * 10;
15
+ this.tiltAngle = DEG_TO_RAD * 10;
15
16
 
16
17
  this.distance = 100;
17
18
  this.position = new Vector3();
@@ -1,8 +1,8 @@
1
1
  import { Mesh, PlaneBufferGeometry } from "three";
2
- import { clamp } from "../../../core/math/clamp.js";
3
2
  import Task from "../../../core/process/task/Task.js";
4
3
  import TaskSignal from "../../../core/process/task/TaskSignal.js";
5
4
  import { collectIteratorValueToArray } from "../../../core/collection/IteratorUtils.js";
5
+ import { clamp01 } from "../../../core/math/clamp01.js";
6
6
 
7
7
  /**
8
8
  * Compile all materials found in the dataset
@@ -100,7 +100,7 @@ export function compileAllMaterials({ graphics, timeout = 0, includeHiddenLayers
100
100
 
101
101
  const f = index / n;
102
102
 
103
- return clamp(f, 0, 1);
103
+ return clamp01(f);
104
104
 
105
105
  }
106
106
  },
@@ -93,26 +93,25 @@ const object_id_cache = new WeakMap();
93
93
  * @param {Mesh|SkinnedMesh} object
94
94
  */
95
95
  function obtain_id_mesh(object) {
96
- const existing = object_id_cache.get(object);
96
+ let mesh = object_id_cache.get(object);
97
97
 
98
- if (existing !== undefined) {
99
- return existing;
98
+ if (mesh === undefined) {
99
+
100
+ if (object.isSkinnedMesh) {
101
+ mesh = new SkinnedMesh(object.geometry, makeIdMaterialSkinned());
102
+ } else {
103
+ mesh = new Mesh(object.geometry, makeIdMaterialStatic());
104
+ }
105
+
106
+ object_id_cache.set(object, mesh);
100
107
  }
101
108
 
102
- let material, mesh;
103
109
  if (object.isSkinnedMesh) {
104
- material = makeIdMaterialSkinned();
105
- mesh = new SkinnedMesh(object.geometry, material);
106
110
  mesh.bindMatrix.copy(object.bindMatrix);
107
111
  mesh.bindMatrixInverse.copy(object.bindMatrixInverse);
108
112
  mesh.skeleton = object.skeleton;
109
- } else {
110
- material = makeIdMaterialStatic();
111
- mesh = new Mesh(object.geometry, material);
112
113
  }
113
114
 
114
- object_id_cache.set(object, mesh);
115
-
116
115
  return mesh;
117
116
  }
118
117
 
@@ -1,4 +1,3 @@
1
- import { clamp } from "../../../../core/math/clamp.js";
2
1
  import { max2 } from "../../../../core/math/max2.js";
3
2
  import Mesh from "./Mesh.js";
4
3
  import Task from "../../../../core/process/task/Task.js";
@@ -6,6 +5,7 @@ import TaskSignal from "../../../../core/process/task/TaskSignal.js";
6
5
  import { assert } from "../../../../core/assert.js";
7
6
  import { assetTypeByPath } from "./assetTypeByPath.js";
8
7
  import { collectIteratorValueToArray } from "../../../../core/collection/IteratorUtils.js";
8
+ import { clamp01 } from "../../../../core/math/clamp01.js";
9
9
 
10
10
  /**
11
11
  * Produces a task that will wait for all existing Meshes of a dataset to be loaded, will fail upon timeout being reached
@@ -96,7 +96,7 @@ export function createTaskWaitForMeshesToLoad(ecd, engine, timeout) {
96
96
 
97
97
  const p = max2(progress, relativeExpiredTime);
98
98
 
99
- return clamp(p, 0, 1);
99
+ return clamp01(p);
100
100
  },
101
101
  cycleFunction() {
102
102
  currentTime = performance.now();
@@ -20,4 +20,10 @@ export class ShadedGeometrySystem extends System<ShadedGeometry> {
20
20
  filter_function?: (entity: number, mesh: ShadedGeometry) => boolean,
21
21
  filter_function_context?: any
22
22
  ): { entity: number, mesh: ShadedGeometry, contact: SurfacePoint3 }[]
23
+
24
+ queryOverlapFrustum(
25
+ result: ArrayLike<number>,
26
+ result_offset: number,
27
+ planes: ArrayLike<number>
28
+ ): number
23
29
  }
@@ -19,6 +19,9 @@ import Task from "../../../../core/process/task/Task.js";
19
19
  import { RuntimeDrawMethodOptimizer } from "./render/optimization/RuntimeDrawMethodOptimizer.js";
20
20
  import TaskSignal from "../../../../core/process/task/TaskSignal.js";
21
21
  import TaskState from "../../../../core/process/task/TaskState.js";
22
+ import {
23
+ bvh_query_user_data_overlaps_frustum
24
+ } from "../../../../core/bvh2/bvh3/bvh_query_user_data_overlaps_frustum.js";
22
25
 
23
26
 
24
27
  /**
@@ -308,6 +311,21 @@ export class ShadedGeometrySystem extends System {
308
311
  }
309
312
  }
310
313
 
314
+ /**
315
+ *
316
+ * @param {number[]} result entity IDs
317
+ * @param {number} result_offset offset into result array where to write first result into
318
+ * @param {number[]|ArrayLike<number>} planes
319
+ * @returns {number} number of results
320
+ */
321
+ queryOverlapFrustum(
322
+ result,
323
+ result_offset,
324
+ planes
325
+ ) {
326
+ return bvh_query_user_data_overlaps_frustum(result, result_offset, this.__bvh_binary, planes);
327
+ }
328
+
311
329
  /**
312
330
  *
313
331
  * @param {number} origin_x
@@ -393,6 +411,7 @@ export class ShadedGeometrySystem extends System {
393
411
  return result;
394
412
  }
395
413
 
414
+
396
415
  /**
397
416
  *
398
417
  * @param {SurfacePoint3} contact
@@ -3,7 +3,9 @@ import { InstancedRendererAdapter } from "./adapters/InstancedRendererAdapter.js
3
3
  import { GenericRendererAdapter } from "./adapters/GenericRendererAdapter.js";
4
4
  import { assert } from "../../../../../core/assert.js";
5
5
  import { ShadedGeometry } from "../ShadedGeometry.js";
6
- import { bvh_query_user_data_by_frustum } from "../../../../../core/bvh2/bvh3/bvh_query_user_data_by_frustum.js";
6
+ import {
7
+ bvh_query_user_data_overlaps_frustum
8
+ } from "../../../../../core/bvh2/bvh3/bvh_query_user_data_overlaps_frustum.js";
7
9
 
8
10
  /**
9
11
  *
@@ -89,7 +91,7 @@ export class ShadedGeometryRendererContext {
89
91
 
90
92
 
91
93
  // get all meshes
92
- const intersection_count = bvh_query_user_data_by_frustum(collection_array, 0, bvh, view.frustum);
94
+ const intersection_count = bvh_query_user_data_overlaps_frustum(collection_array, 0, bvh, view.frustum);
93
95
 
94
96
  const sg_component_index = ecd.computeComponentTypeIndex(ShadedGeometry);
95
97
 
@@ -54,6 +54,12 @@ export class RuntimeDrawMethodOptimizer {
54
54
 
55
55
  const entity = next.value;
56
56
 
57
+ if (!ecd.entityExists(entity)) {
58
+ // seems that iterator is stale, reset iterator
59
+ this.__entity_iterator = null;
60
+ return false;
61
+ }
62
+
57
63
  /**
58
64
  *
59
65
  * @type {ShadedGeometry}
@@ -78,6 +78,22 @@ export class InstancedMeshGroup {
78
78
  */
79
79
  this.__attributeTransformArray = null;
80
80
 
81
+
82
+ /**
83
+ *
84
+ * TODO implement usage
85
+ * @type {InstancedBufferAttribute}
86
+ * @private
87
+ */
88
+ this.__attributeColor = null;
89
+
90
+ /**
91
+ * TODO implement usage
92
+ * @type {Uint8Array}
93
+ * @private
94
+ */
95
+ this.__attributeColorArray = null;
96
+
81
97
  /**
82
98
  *
83
99
  * @type {Usage}
@@ -409,4 +425,19 @@ export class InstancedMeshGroup {
409
425
 
410
426
  this.mesh.geometry = geometry;
411
427
  }
428
+
429
+ /**
430
+ *
431
+ * @param {THREE.BufferGeometry} geometry
432
+ * @param {Material} material
433
+ * @returns {InstancedMeshGroup}
434
+ */
435
+ static from(geometry, material) {
436
+ const r = new InstancedMeshGroup();
437
+
438
+ r.setGeometry(geometry);
439
+ r.setMaterial(material);
440
+
441
+ return r;
442
+ }
412
443
  }