@woosh/meep-engine 2.36.26 → 2.36.29

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 (106) 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/color/Color.js +54 -3
  3. package/core/color/hsv2rgb.js +3 -3
  4. package/core/color/kelvin_to_rgb.js +51 -0
  5. package/core/color/kelvin_to_rgb.spec.js +61 -0
  6. package/core/color/linear_to_sRGB.js +17 -0
  7. package/core/color/prototype_kelvin_to_rgb.js +44 -0
  8. package/core/color/rgb_to_kelvin.js +34 -0
  9. package/core/color/rgb_to_kelvin.spec.js +15 -0
  10. package/core/color/sRGB_to_linear.js +16 -0
  11. package/core/geom/3d/line/line3_computeSegmentPointDistance_sqr.js +2 -2
  12. package/core/geom/LineSegment.js +2 -2
  13. package/core/geom/Vector3.js +14 -0
  14. package/core/math/DEG_TO_RAD.js +1 -0
  15. package/core/math/MathUtils.spec.js +0 -13
  16. package/core/math/RAD_TO_DEG.js +1 -0
  17. package/core/math/clamp01.js +15 -0
  18. package/core/math/fract.js +10 -0
  19. package/core/math/newton_solver_1d.js +21 -0
  20. package/core/math/smoothStep.js +3 -3
  21. package/core/math/solveQuadratic.js +32 -12
  22. package/core/math/solveQuadratic.spec.js +18 -0
  23. package/core/primitives/strings/StringUtils.js +10 -0
  24. package/core/process/task/TaskUtils.js +2 -2
  25. package/editor/view/ecs/components/color/GaugeView.js +2 -2
  26. package/editor/view/ecs/components/particles/ColorParameterLUTController.js +5 -4
  27. package/editor/view/ecs/components/particles/ScalarParameterLUTController.js +5 -3
  28. package/engine/Clock.js +4 -0
  29. package/engine/UserController.js +2 -1
  30. package/engine/animation/behavior/animateProperty.js +6 -1
  31. package/engine/animation/keyed2/behavior/AnimationBehavior.js +0 -1
  32. package/engine/ecs/EntityBuilder.js +12 -1
  33. package/engine/ecs/animation/OneBoneSurfaceAlignmentSolver.js +2 -1
  34. package/engine/ecs/animation/TwoBoneInverseKinematicsSolver.js +2 -1
  35. package/engine/ecs/fow/shader/screenSpaceFogOfWarShader.js +14 -11
  36. package/engine/ecs/systems/AimControllerSystem.js +3 -2
  37. package/engine/ecs/systems/RangedAttackSystem.js +3 -2
  38. package/engine/ecs/systems/SteeringSystem.js +3 -3
  39. package/engine/ecs/terrain/ecs/ClingToTerrainSystem.js +2 -2
  40. package/engine/ecs/terrain/util/paintTerrainOverlayViaLookupTable.js +2 -2
  41. package/engine/graphics/GraphicsEngine.js +2 -1
  42. package/engine/graphics/camera/CameraShake.js +4 -4
  43. package/engine/graphics/ecs/animation/animator/graph/AnimationTransition.js +2 -2
  44. package/engine/graphics/ecs/camera/TiltCameraController.js +3 -2
  45. package/engine/graphics/ecs/compileAllMaterials.js +2 -2
  46. package/engine/graphics/ecs/highlight/renderer/OutlineRenderer.js +14 -24
  47. package/engine/graphics/ecs/light/LightSystem.js +2 -3
  48. package/engine/graphics/ecs/mesh/createTaskWaitForMeshesToLoad.js +2 -2
  49. package/engine/graphics/ecs/mesh-v2/ShadedGeometrySystem.d.ts +6 -0
  50. package/engine/graphics/ecs/mesh-v2/ShadedGeometrySystem.js +19 -0
  51. package/engine/graphics/ecs/mesh-v2/render/ShadedGeometryRendererContext.js +4 -2
  52. package/engine/graphics/ecs/mesh-v2/render/adapters/AbstractRenderAdapter.js +9 -0
  53. package/engine/graphics/ecs/mesh-v2/render/optimization/RuntimeDrawMethodOptimizer.js +11 -0
  54. package/engine/graphics/ecs/mesh-v2/sample/load_gltf.js +3 -0
  55. package/engine/graphics/geometry/instancing/InstancedMeshGroup.js +31 -0
  56. package/engine/graphics/micron/build/fill_patch_geometry_data.js +2 -2
  57. package/engine/graphics/micron/plugin/MicronRenderPlugin.js +0 -82
  58. package/engine/graphics/micron/plugin/shaded_geometry/MicronShadedGeometryRenderAdapter.js +28 -3
  59. package/engine/graphics/particles/particular/engine/utils/volume/prototypeParticleVolume.js +5 -3
  60. package/engine/graphics/render/gizmo/Gizmo.js +3 -0
  61. package/engine/graphics/render/gizmo/GizmoRenderingPlugin.js +5 -0
  62. package/engine/graphics/render/gizmo/GizmoShapeRenderingInterface.js +91 -0
  63. package/engine/graphics/texture/sampler/Sampler2D.js +110 -18
  64. package/engine/graphics/three/OrbitControls.js +3 -2
  65. package/engine/graphics/trail/x/simulator/RibbonXFixedPhysicsSimulator.js +2 -2
  66. package/engine/graphics/util/makeMeshPreviewScene.js +11 -3
  67. package/engine/intelligence/behavior/Behavior.js +36 -17
  68. package/engine/intelligence/behavior/SelectorBehavior.js +6 -5
  69. package/engine/intelligence/behavior/composite/ParallelBehavior.js +0 -66
  70. package/engine/intelligence/behavior/composite/ParallelBehaviorSerializationAdapter.js +63 -0
  71. package/engine/intelligence/behavior/composite/SequenceBehavior.js +36 -11
  72. package/engine/intelligence/behavior/decorator/AbstractDecoratorBehavior.js +0 -2
  73. package/engine/intelligence/behavior/decorator/IgnoreFailureBehavior.js +2 -4
  74. package/engine/intelligence/behavior/decorator/InverterBehavior.js +3 -3
  75. package/engine/intelligence/behavior/decorator/RepeatBehavior.js +0 -35
  76. package/engine/intelligence/behavior/decorator/RepeatBehavior.spec.js +0 -10
  77. package/engine/intelligence/behavior/decorator/RepeatBehaviorSerializationAdapter.js +37 -0
  78. package/engine/intelligence/behavior/decorator/RepeatUntilFailureBehavior.js +0 -3
  79. package/engine/intelligence/behavior/decorator/RepeatUntilSuccessBehavior.js +5 -10
  80. package/engine/intelligence/behavior/ecs/BehaviorComponent.js +95 -7
  81. package/engine/intelligence/behavior/ecs/BehaviorComponentSerializationAdapter.js +15 -8
  82. package/engine/intelligence/behavior/ecs/BehaviorSystem.js +28 -37
  83. package/engine/intelligence/behavior/ecs/DieBehavior.js +2 -7
  84. package/engine/intelligence/behavior/ecs/WaitForEventBehavior.js +2 -29
  85. package/engine/intelligence/behavior/ecs/WaitForEventBehaviorSerializationAdapter.js +29 -0
  86. package/engine/intelligence/behavior/primitive/ActionBehavior.js +6 -13
  87. package/engine/intelligence/behavior/primitive/FailingBehavior.js +1 -29
  88. package/engine/intelligence/behavior/primitive/FailingBehaviorSerializationAdapter.js +29 -0
  89. package/engine/intelligence/behavior/primitive/PromiseBehavior.js +15 -3
  90. package/engine/intelligence/behavior/selector/WeightedRandomBehavior.js +1 -5
  91. package/engine/intelligence/behavior/util/ConditionBehavior.js +1 -3
  92. package/engine/intelligence/behavior/util/ConditionBehavior.spec.js +1 -7
  93. package/engine/intelligence/behavior/util/ConditionalBehavior.js +3 -6
  94. package/engine/intelligence/behavior/util/DelayBehavior.js +2 -4
  95. package/engine/intelligence/behavior/util/SelectorBehavior.js +13 -12
  96. package/engine/intelligence/blackboard/AbstractBlackboard.js +16 -2
  97. package/engine/plugin/EnginePluginManager.js +4 -14
  98. package/engine/sound/ecs/emitter/SoundEmitter.js +3 -0
  99. package/generation/filtering/numeric/math/CellFilterSaturate.js +2 -2
  100. package/generation/grid/generation/GridTaskDensityMarkerDistribution.js +3 -2
  101. package/generation/markers/transform/MarkerNodeTransformerYRotateByFilterGradient.spec.js +1 -1
  102. package/generation/rules/CellMatcherLayerBitMaskTest.js +3 -3
  103. package/package.json +1 -1
  104. package/view/elements/progress/SmoothProgressBar.js +2 -2
  105. package/view/elements/progress/segmented/SegmentedResourceBarView.js +3 -3
  106. package/view/elements/radial/RadialProgressView.js +2 -2
@@ -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}
@@ -102,6 +108,11 @@ export class RuntimeDrawMethodOptimizer {
102
108
  return false;
103
109
  }
104
110
 
111
+ if (!adapters[best_adapter].intend_draw(sg)) {
112
+ // unable to draw, don't do anything
113
+ return false;
114
+ }
115
+
105
116
  sg.draw_method = best_adapter;
106
117
 
107
118
  return true;
@@ -7,6 +7,7 @@ import { three_object_to_entity_composition } from "../three_object_to_entity_co
7
7
  import { AttachmentSystem } from "../../../../ecs/attachment/AttachmentSystem.js";
8
8
  import { TransformAttachmentSystem } from "../../../../ecs/transform-attachment/TransformAttachmentSystem.js";
9
9
  import { Camera } from "../../camera/Camera.js";
10
+ import { MicronRenderPlugin } from "../../../micron/plugin/MicronRenderPlugin.js";
10
11
 
11
12
  const eh = new EngineHarness();
12
13
 
@@ -25,6 +26,8 @@ async function init(harness) {
25
26
  config.addSystem(new TransformAttachmentSystem());
26
27
  config.addLoader(GameAssetType.ModelGLTF_JSON, new GLTFAssetLoader());
27
28
 
29
+ config.addPlugin( MicronRenderPlugin);
30
+
28
31
  await config.apply(engine);
29
32
 
30
33
  eh.initialize().then(main);
@@ -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
  }
@@ -4,8 +4,8 @@ import { to_half_float_uint16 } from "../../../../core/binary/to_half_float_uint
4
4
  import { compute_micron_buffer_array_constructor } from "./compute_micron_buffer_array_constructor.js";
5
5
  import { typedArrayToDataType } from "../../../../core/collection/array/typedArrayToDataType.js";
6
6
  import { dataTypeByteSize } from "../../../../core/collection/table/DataTypeByteSizes.js";
7
- import { clamp } from "../../../../core/math/clamp.js";
8
7
  import { UintArrayForCount } from "../../../../core/collection/array/typed/uint_array_for_count.js";
8
+ import { clamp01 } from "../../../../core/math/clamp01.js";
9
9
 
10
10
  /**
11
11
  * @param {number} vertex_count
@@ -82,7 +82,7 @@ function copy_attribute_data(vertex_count, index_map_backward, itemSize, attribu
82
82
  * @returns {number}
83
83
  */
84
84
  function resample_normalized_uint16_to_uint8(value) {
85
- const normalized = clamp(value / 65535, 0, 1);
85
+ const normalized = clamp01(value / 65535);
86
86
 
87
87
  return Math.round(normalized * 255);
88
88
  }
@@ -37,13 +37,6 @@ export class MicronRenderPlugin extends EnginePlugin {
37
37
  layer.managed = true;
38
38
  layer.renderPass = RenderPassType.Opaque;
39
39
 
40
- /**
41
- *
42
- * @type {RenderLayer|null}
43
- * @private
44
- */
45
- this.__micron_render_layer = layer;
46
-
47
40
  this.__vgtr.on.contextAdded.add(ctx => {
48
41
  const visibleSet = layer.visibleSet;
49
42
 
@@ -54,8 +47,6 @@ export class MicronRenderPlugin extends EnginePlugin {
54
47
 
55
48
  });
56
49
 
57
- this.__view_observers = new Map();
58
-
59
50
  /**
60
51
  *
61
52
  * @type {AsyncRemoteHashMap}
@@ -97,55 +88,6 @@ export class MicronRenderPlugin extends EnginePlugin {
97
88
  this.__sg_system = null;
98
89
  }
99
90
 
100
- /**
101
- *
102
- * @param {THREE.WebGLRenderer} renderer
103
- * @param {THREE.Camera} camera
104
- * @param {THREE.Object3D[]} elements
105
- * @param element_count
106
- */
107
- render(renderer, camera, elements, element_count = elements.length) {
108
- const vgtr = this.__vgtr;
109
-
110
- vgtr.clear();
111
-
112
- vgtr.attachMany(elements, element_count);
113
-
114
- vgtr.update(renderer, camera);
115
- vgtr.render();
116
- }
117
-
118
- /**
119
- *
120
- * @param {CameraView} view
121
- * @private
122
- */
123
- __handle_view_added(view) {
124
- const observer = () => {
125
- const ge = this.engine.graphics;
126
-
127
- this.render(ge.renderer, view.camera, view.visible_objects.elements, view.visible_objects.size);
128
- };
129
-
130
- this.__view_observers.set(view, observer);
131
-
132
-
133
- view.on.preRender.add(observer);
134
- }
135
-
136
- /**
137
- *
138
- * @param {CameraView} view
139
- * @private
140
- */
141
- __handle_view_removed(view) {
142
- const observer = this.__view_observers.get(view);
143
-
144
- this.__view_observers.delete(view);
145
-
146
- view.on.preRender.remove(observer);
147
- }
148
-
149
91
  /**
150
92
  *
151
93
  * @param {System} system
@@ -214,20 +156,6 @@ export class MicronRenderPlugin extends EnginePlugin {
214
156
  am.registerTransformer("model/gltf", this.__asset_transformer);
215
157
  am.registerTransformer("model/gltf+json", this.__asset_transformer);
216
158
 
217
- /**
218
- *
219
- * @type {GraphicsEngine}
220
- */
221
- const ge = engine.graphics;
222
-
223
- ge.layers.add(this.__micron_render_layer);
224
-
225
- ge.views.elements.on.added.add(this.__handle_view_added, this);
226
- ge.views.elements.on.removed.add(this.__handle_view_removed, this);
227
-
228
- // link all views
229
- ge.views.elements.forEach(this.__handle_view_added, this);
230
-
231
159
  this.__persisted_geometry.attach_storage(engine.storage);
232
160
 
233
161
  engine.entityManager.on.systemAdded.add(this.__handle_system_added, this);
@@ -250,16 +178,6 @@ export class MicronRenderPlugin extends EnginePlugin {
250
178
 
251
179
  this.__asset_transformer.assetManager = null;
252
180
 
253
- const ge = engine.graphics;
254
-
255
- ge.layers.remove(this.__micron_render_layer);
256
-
257
- ge.views.elements.on.added.remove(this.__handle_view_added, this);
258
- ge.views.elements.on.removed.remove(this.__handle_view_removed, this);
259
-
260
- // clear all observer
261
- ge.views.elements.forEach(this.__handle_view_removed, this);
262
-
263
181
  engine.entityManager.on.systemAdded.remove(this.__handle_system_added, this);
264
182
  engine.entityManager.on.systemRemoved.remove(this.__handle_system_removed, this);
265
183
 
@@ -56,13 +56,22 @@ export class MicronShadedGeometryRenderAdapter extends AbstractRenderAdapter {
56
56
  return inverseLerp(MICRON_POLYCOUNT_THRESHOLD_MIN, MICRON_POLYCOUNT_THRESHOLD_MAX, polycount);
57
57
  }
58
58
 
59
- add(sg) {
60
-
59
+ /**
60
+ *
61
+ * @param {ShadedGeometry} sg
62
+ * @returns {MicronGeometry}
63
+ * @private
64
+ */
65
+ __obtain_micron_geometry(sg) {
61
66
  const geometry_id = sg.geometry.id;
62
67
 
63
68
  const micron_geometry = this.__geometry_map.get(geometry_id);
64
69
 
65
- if (micron_geometry === undefined) {
70
+ if (micron_geometry !== undefined) {
71
+
72
+ return micron_geometry;
73
+
74
+ } else {
66
75
  // no micron geometry
67
76
  if (!this.__geometry_building_promises.has(geometry_id)) {
68
77
  const p = buildMicronGeometryFromBufferGeometry(sg.geometry);
@@ -71,6 +80,20 @@ export class MicronShadedGeometryRenderAdapter extends AbstractRenderAdapter {
71
80
 
72
81
  p.then(mg => this.__geometry_map.set(geometry_id, mg));
73
82
  }
83
+ return undefined;
84
+ }
85
+
86
+ }
87
+
88
+ intend_draw(sg) {
89
+ return this.__obtain_micron_geometry(sg) !== undefined;
90
+ }
91
+
92
+ add(sg) {
93
+ const micron_geometry = this.__obtain_micron_geometry(sg);
94
+
95
+ if (micron_geometry === undefined) {
96
+ // no micron geometry
74
97
  return;
75
98
  }
76
99
 
@@ -94,6 +117,8 @@ export class MicronShadedGeometryRenderAdapter extends AbstractRenderAdapter {
94
117
  * @param {CameraView} view
95
118
  */
96
119
  build_start(renderer, view) {
120
+ this.__object_count = 0;
121
+
97
122
  const resolution = new Vector2();
98
123
  let pixelRatio = 1;
99
124
 
@@ -28,7 +28,9 @@ import RenderSystem from "../../../../../../ecs/systems/RenderSystem.js";
28
28
  import { makeEngineOptionsModel } from "../../../../../../../../model/game/options/makeEngineOptionsModel.js";
29
29
  import { enableEditor } from "../../../../../../../editor/enableEditor.js";
30
30
  import { buildCubeURLs } from "../../../../../texture/cubemap/buildCubeURLs.js";
31
- import { AmbientOcclusionPostProcessEffect } from "../../../../../render/buffer/simple-fx/ao/AmbientOcclusionPostProcessEffect.js";
31
+ import {
32
+ AmbientOcclusionPostProcessEffect
33
+ } from "../../../../../render/buffer/simple-fx/ao/AmbientOcclusionPostProcessEffect.js";
32
34
  import Vector2 from "../../../../../../../core/geom/Vector2.js";
33
35
  import Vector3 from "../../../../../../../core/geom/Vector3.js";
34
36
  import EntityBuilder from "../../../../../../ecs/EntityBuilder.js";
@@ -49,7 +51,6 @@ import ViewportPosition from "../../../../../../ecs/gui/position/ViewportPositio
49
51
  import { CanvasView } from "../../../../../../../view/elements/CanvasView.js";
50
52
  import convertSampler2D2Canvas from "../../../../../texture/sampler/Sampler2D2Canvas.js";
51
53
  import Vector1 from "../../../../../../../core/geom/Vector1.js";
52
- import { clamp } from "../../../../../../../core/math/clamp.js";
53
54
  import { UnitCubeShape3D } from "../../../../../../../core/geom/3d/shape/UnitCubeShape3D.js";
54
55
  import { ShadedGeometrySystem } from "../../../../../ecs/mesh-v2/ShadedGeometrySystem.js";
55
56
  import { lut_to_sampler } from "./lut_to_sampler.js";
@@ -77,6 +78,7 @@ import { randomFloatBetween } from "../../../../../../../core/math/random/random
77
78
  import { MicronRenderPlugin } from "../../../../../micron/plugin/MicronRenderPlugin.js";
78
79
  import { obtainTerrain } from "../../../../../../ecs/terrain/util/obtainTerrain.js";
79
80
  import { pick } from "../../../../../../../ecs/grid/pick.js";
81
+ import { clamp01 } from "../../../../../../../core/math/clamp01.js";
80
82
 
81
83
  const engineHarness = new EngineHarness();
82
84
 
@@ -1225,7 +1227,7 @@ async function make_demo_volume({
1225
1227
 
1226
1228
  const _t = pingpong(time_total + period_offset, period);
1227
1229
 
1228
- const f = clamp(_t / period, 0, 1);
1230
+ const f = clamp01(_t / period);
1229
1231
 
1230
1232
  symbol.position.set(f);
1231
1233
 
@@ -0,0 +1,3 @@
1
+ import { GizmoShapeRenderingInterface } from "./GizmoShapeRenderingInterface.js";
2
+
3
+ export const Gizmo = GizmoShapeRenderingInterface.INSTANCE;
@@ -0,0 +1,5 @@
1
+ import { EnginePlugin } from "../../../plugin/EnginePlugin.js";
2
+
3
+ export class GizmoRenderingPlugin extends EnginePlugin {
4
+
5
+ }
@@ -0,0 +1,91 @@
1
+ import { array_copy } from "../../../../core/collection/array/copyArray.js";
2
+ import { assert } from "../../../../core/assert.js";
3
+ import { InstancedMeshGroup } from "../../geometry/instancing/InstancedMeshGroup.js";
4
+ import { BoxBufferGeometry, MeshBasicMaterial } from "three";
5
+ import { compose_matrix4_array } from "../../../../core/geom/3d/compose_matrix4_array.js";
6
+ import Vector3 from "../../../../core/geom/Vector3.js";
7
+ import Quaternion from "../../../../core/geom/Quaternion.js";
8
+
9
+ /**
10
+ *
11
+ * @type {number[]}
12
+ */
13
+ const scratch_m4 = [];
14
+
15
+ export class GizmoShapeRenderingInterface {
16
+ constructor() {
17
+
18
+ /**
19
+ *
20
+ * @type {number[]}
21
+ * @private
22
+ */
23
+ this.__color = [1, 1, 1, 1];
24
+
25
+ this.__boxes_solid = InstancedMeshGroup.from(new BoxBufferGeometry(), new MeshBasicMaterial());
26
+ }
27
+
28
+ /**
29
+ * RGBA
30
+ * @param {number[]} color
31
+ */
32
+ set color(color) {
33
+ assert.defined(color, 'color');
34
+ assert.isArray(color, 'color');
35
+ assert.greaterThanOrEqual(color.length, 4);
36
+
37
+ array_copy(color, 0, this.__color, 0, 4);
38
+ }
39
+
40
+ /**
41
+ *
42
+ * @param {number[]} center
43
+ * @param {number[]} size
44
+ */
45
+ draw_solid_cube(center, size) {
46
+ compose_matrix4_array(scratch_m4, Vector3.fromArray(center), Quaternion.identity, Vector3.fromArray(size));
47
+ const i = this.__boxes_solid.count;
48
+
49
+ this.__boxes_solid.setCount(i + 1);
50
+ this.__boxes_solid.setTransformAt(i, scratch_m4);
51
+ }
52
+
53
+ /**
54
+ *
55
+ * @param {number[]} center
56
+ * @param {number[]} size
57
+ */
58
+ draw_wire_cube(center, size) {
59
+
60
+ }
61
+
62
+ /**
63
+ *
64
+ * @param {number[]} from
65
+ * @param {number[]} to
66
+ */
67
+ draw_line(from, to) {
68
+
69
+ }
70
+
71
+
72
+ /**
73
+ *
74
+ * @param {number[]} center
75
+ * @param {number} radius
76
+ */
77
+ draw_solid_sphere(center, radius) {
78
+
79
+ }
80
+
81
+ /**
82
+ *
83
+ * @param {number[]} center
84
+ * @param {number} radius
85
+ */
86
+ draw_wire_sphere() {
87
+
88
+ }
89
+ }
90
+
91
+ GizmoShapeRenderingInterface.INSTANCE = new GizmoShapeRenderingInterface();
@@ -10,6 +10,7 @@ import { mix } from "../../../../core/math/mix.js";
10
10
  import { BlendingType } from "./BlendingType.js";
11
11
  import { assert } from "../../../../core/assert.js";
12
12
  import { typedArrayConstructorByInstance } from "./typedArrayConstructorByInstance.js";
13
+ import { fract } from "../../../../core/math/fract.js";
13
14
 
14
15
  function v2CrossMag(ax, ay, bx, by) {
15
16
  return ax * by - ay * bx;
@@ -530,17 +531,18 @@ Sampler2D.prototype.get = function (x, y, result) {
530
531
  };
531
532
 
532
533
  /**
533
- * Based on code from From reddit https://www.reddit.com/r/javascript/comments/jxa8x/bicubic_interpolation/
534
- * @param {number} t
535
- * @param {number} a
536
- * @param {number} b
537
- * @param {number} c
538
- * @param {number} d
539
- * @returns {number}
534
+ *
535
+ * @param {number} u
536
+ * @param {number} v
537
+ * @param {number[]} result
540
538
  */
541
- function bicubic_terp(t, a, b, c, d) {
542
- return 0.5 * (c - a + (2.0 * a - 5.0 * b + 4.0 * c - d + (3.0 * (b - c) + d - a) * t) * t) * t + b;
543
- }
539
+ Sampler2D.prototype.sampleCatmullRomUV = function (u, v, result) {
540
+ const itemSize = this.itemSize;
541
+
542
+ for (let i = 0; i < itemSize; i++) {
543
+ result[i] = this.sampleChannelCatmullRomUV(u, v, i);
544
+ }
545
+ };
544
546
 
545
547
  /**
546
548
  *
@@ -549,13 +551,87 @@ function bicubic_terp(t, a, b, c, d) {
549
551
  * @param {number} channel
550
552
  * @returns {number}
551
553
  */
552
- Sampler2D.prototype.sampleChannelBicubicUV = function (u, v, channel) {
554
+ Sampler2D.prototype.sampleChannelCatmullRomUV = function (u, v, channel) {
553
555
  const x = u * (this.width - 1);
554
556
  const y = v * (this.height - 1);
555
557
 
556
- return this.sampleChannelBicubic(x, y, channel);
558
+ return this.sampleChannelCatmullRom(x, y, channel);
557
559
  };
558
560
 
561
+ /**
562
+ *
563
+ * @see https://www.shadertoy.com/view/NsBfRG
564
+ * @see https://www.decarpentier.nl/2d-catmull-rom-in-4-samples
565
+ * @param {number} x
566
+ * @param {number} y
567
+ * @param {number} channel
568
+ * @returns {number}
569
+ */
570
+ Sampler2D.prototype.sampleChannelCatmullRom = function (x, y, channel) {
571
+ // Based on the standard Catmull-Rom spline: w1*C1+w2*C2+w3*C3+w4*C4, where
572
+ // w1 = ((-0.5*f + 1.0)*f - 0.5)*f, w2 = (1.5*f - 2.5)*f*f + 1.0,
573
+ // w3 = ((-1.5*f + 2.0)*f + 0.5)*f and w4 = (0.5*f - 0.5)*f*f with f as the
574
+ // normalized interpolation position between C2 (at f=0) and C3 (at f=1).
575
+
576
+ // half_f is a sort of sub-pixelquad fraction, -1 <= half_f < 1.
577
+ const half_f_x = 2.0 * fract(0.5 * x - 0.25) - 1.0;
578
+ const half_f_y = 2.0 * fract(0.5 * y - 0.25) - 1.0;
579
+
580
+ // f is the regular sub-pixel fraction, 0 <= f < 1. This is equivalent to
581
+ // fract(uv * texSize - 0.5), but based on half_f to prevent rounding issues.
582
+ const f_x = fract(half_f_x);
583
+ const f_y = fract(half_f_y);
584
+
585
+ const s1_x = (0.5 * f_x - 0.5) * f_x; // = w1 / (1 - f)
586
+ const s1_y = (0.5 * f_y - 0.5) * f_y; // = w1 / (1 - f)
587
+
588
+ const s12_x = (-2.0 * f_x + 1.5) * f_x + 1.0; // = (w2 - w1) / (1 - f)
589
+ const s12_y = (-2.0 * f_y + 1.5) * f_y + 1.0; // = (w2 - w1) / (1 - f)
590
+
591
+ const s34_x = (2.0 * f_x - 2.5) * f_x - 0.5; // = (w4 - w3) / f
592
+ const s34_y = (2.0 * f_y - 2.5) * f_y - 0.5; // = (w4 - w3) / f
593
+
594
+ // positions is equivalent to: (floor(uv * texSize - 0.5).xyxy + 0.5 +
595
+ // vec4(-1.0 + w2 / (w2 - w1), 1.0 + w4 / (w4 - w3))) / texSize.xyxy.
596
+ const positions_x = (-f_x * s12_x + s1_x) / (s12_x) + x;
597
+ const positions_y = (-f_y * s12_y + s1_y) / (s12_y) + y;
598
+ const positions_z = (-f_x * s34_x + s1_x + s34_x) / (s34_x) + x;
599
+ const positions_w = (-f_y * s34_y + s1_y + s34_y) / (s34_y) + y;
600
+
601
+ // Determine if the output needs to be sign-flipped. Equivalent to .x*.y of
602
+ // (1.0 - 2.0 * floor(t - 2.0 * floor(0.5 * t))), where t is uv * texSize - 0.5.
603
+ const sign_flip = half_f_x * half_f_y > 0.0 ? 1.0 : -1.0;
604
+
605
+ // = (w2 - w1, w4 - w3)
606
+ const w_x = -f_x * s12_x + s12_x;
607
+ const w_y = -f_y * s12_y + s12_y;
608
+ const w_z = s34_x * f_x
609
+ const w_w = s34_y * f_y
610
+
611
+ const weights_x = w_x * w_y * sign_flip;
612
+ const weights_y = w_z * w_y * sign_flip;
613
+ const weights_z = w_x * w_w * sign_flip;
614
+ const weights_w = w_z * w_w * sign_flip;
615
+
616
+ return this.sampleChannelBilinear(positions_x, positions_y, channel) * weights_x +
617
+ this.sampleChannelBilinear(positions_z, positions_y, channel) * weights_y +
618
+ this.sampleChannelBilinear(positions_x, positions_w, channel) * weights_z +
619
+ this.sampleChannelBilinear(positions_z, positions_w, channel) * weights_w;
620
+ }
621
+
622
+ /**
623
+ * Based on code from From reddit https://www.reddit.com/r/javascript/comments/jxa8x/bicubic_interpolation/
624
+ * @param {number} t
625
+ * @param {number} a
626
+ * @param {number} b
627
+ * @param {number} c
628
+ * @param {number} d
629
+ * @returns {number}
630
+ */
631
+ function bicubic_terp(t, a, b, c, d) {
632
+ return 0.5 * (c - a + (2.0 * a - 5.0 * b + 4.0 * c - d + (3.0 * (b - c) + d - a) * t) * t) * t + b;
633
+ }
634
+
559
635
  /**
560
636
  *
561
637
  * @param {number} u
@@ -570,6 +646,20 @@ Sampler2D.prototype.sampleBicubicUV = function (u, v, result) {
570
646
  }
571
647
  };
572
648
 
649
+ /**
650
+ *
651
+ * @param {number} u
652
+ * @param {number} v
653
+ * @param {number} channel
654
+ * @returns {number}
655
+ */
656
+ Sampler2D.prototype.sampleChannelBicubicUV = function (u, v, channel) {
657
+ const x = u * (this.width - 1);
658
+ const y = v * (this.height - 1);
659
+
660
+ return this.sampleChannelBicubic(x, y, channel);
661
+ };
662
+
573
663
  /**
574
664
  * Bicubic-filtered sampling
575
665
  * @param {number} x
@@ -687,7 +777,6 @@ Sampler2D.prototype.sampleChannelBilinearUV = function (u, v, channel) {
687
777
  return this.sampleChannelBilinear(x, y, channel);
688
778
  };
689
779
 
690
-
691
780
  /**
692
781
  *
693
782
  * @param {number} x
@@ -1287,15 +1376,18 @@ Sampler2D.prototype.zeroFill = function (x, y, width, height) {
1287
1376
  */
1288
1377
  Sampler2D.prototype.fill = function (x, y, width, height, value) {
1289
1378
 
1290
- const x0 = clamp(x, 0, this.width);
1291
- const y0 = clamp(y, 0, this.height);
1292
- const x1 = clamp(x + width, 0, this.width);
1293
- const y1 = clamp(y + height, 0, this.height);
1379
+ const _w = this.width;
1380
+ const _h = this.height;
1381
+
1382
+ const x0 = clamp(x, 0, _w);
1383
+ const y0 = clamp(y, 0, _h);
1384
+ const x1 = clamp(x + width, 0, _w);
1385
+ const y1 = clamp(y + height, 0, _h);
1294
1386
 
1295
1387
  const data = this.data;
1296
1388
  const itemSize = this.itemSize;
1297
1389
 
1298
- const rowSize = itemSize * this.width;
1390
+ const rowSize = itemSize * _w;
1299
1391
 
1300
1392
  let _y, _x, i;
1301
1393
 
@@ -8,6 +8,7 @@
8
8
 
9
9
 
10
10
  import * as THREE from 'three';
11
+ import { DEG_TO_RAD } from "../../../core/math/DEG_TO_RAD.js";
11
12
 
12
13
  // This set of controls performs orbiting, dollying (zooming), and panning.
13
14
  // Unlike TrackballControls, it maintains the "up" direction object.up (+Y by default).
@@ -360,7 +361,7 @@ function OrbitControls(object, domElement) {
360
361
  var targetDistance = offset.length();
361
362
 
362
363
  // half of the fov is center to top of screen
363
- targetDistance *= Math.tan((scope.object.fov / 2) * Math.PI / 180.0);
364
+ targetDistance *= Math.tan((scope.object.fov / 2) * DEG_TO_RAD);
364
365
 
365
366
  // we use only clientHeight here so aspect ratio does not distort speed
366
367
  panLeft(2 * deltaX * targetDistance / element.clientHeight, scope.object.matrix);
@@ -1041,4 +1042,4 @@ Object.defineProperties(OrbitControls.prototype, {
1041
1042
 
1042
1043
  });
1043
1044
 
1044
- export { OrbitControls };
1045
+ export { OrbitControls };
@@ -1,5 +1,5 @@
1
- import { clamp } from "../../../../../core/math/clamp.js";
2
1
  import { RIBBON_ATTRIBUTE_ADDRESS_AGE, RIBBON_ATTRIBUTE_ADDRESS_UV_OFFSET } from "../ribbon_attributes_spec.js";
2
+ import { clamp01 } from "../../../../../core/math/clamp01.js";
3
3
 
4
4
  /**
5
5
  * Fixed function simulation engine for ribbons
@@ -22,7 +22,7 @@ export class RibbonXFixedPhysicsSimulator {
22
22
  // age the ribbon
23
23
  const age = ribbon.incrementPointAttribute_Scalar(i, RIBBON_ATTRIBUTE_ADDRESS_AGE, timeDelta);
24
24
 
25
- const relative_age = clamp(age / max_age, 0, 1);
25
+ const relative_age = clamp01(age / max_age);
26
26
 
27
27
  // apply alpha over-time
28
28
  ribbon.setPointAlpha(i, 1.0 - relative_age);
@@ -1,8 +1,16 @@
1
- import { AmbientLight as ThreeAmbientLight, Box3, DirectionalLight as ThreeDirectionalLight, PerspectiveCamera as ThreePerspectiveCamera, Scene as ThreeScene, Vector3 as ThreeVector3 } from "three";
1
+ import {
2
+ AmbientLight as ThreeAmbientLight,
3
+ Box3,
4
+ DirectionalLight as ThreeDirectionalLight,
5
+ PerspectiveCamera as ThreePerspectiveCamera,
6
+ Scene as ThreeScene,
7
+ Vector3 as ThreeVector3
8
+ } from "three";
2
9
  import Vector3 from "../../../core/geom/Vector3.js";
3
10
  import { rootObject3DFastMatrixUpdate } from "../ecs/mesh/rootObject3DFastMatrixUpdate.js";
4
11
  import { computeMeshPreviewCameraDistance } from "./computeMeshPreviewCameraDistance.js";
5
12
  import { scaleObject3ToBox } from "./ScaleObject3ToBox.js";
13
+ import { DEG_TO_RAD } from "../../../core/math/DEG_TO_RAD.js";
6
14
 
7
15
  /**
8
16
  *
@@ -62,7 +70,7 @@ export function makeMeshPreviewScene(mesh, size, focus) {
62
70
  const focusHeight = (focus.y1 - focus.y0);
63
71
 
64
72
 
65
- const fov = camera.fov * (Math.PI / 180);
73
+ const fov = camera.fov * DEG_TO_RAD;
66
74
  const distance = computeMeshPreviewCameraDistance(focusHeight, fov, bBox.max.z);
67
75
 
68
76
  const cameraPositionX = focus.x0 + (focus.x1 - focus.x0) / 2 - 0.5;
@@ -76,4 +84,4 @@ export function makeMeshPreviewScene(mesh, size, focus) {
76
84
  // camera.far = bBox.size.z * mesh.scale.z+distance;
77
85
 
78
86
  return { scene: scene, camera: camera };
79
- }
87
+ }