@woosh/meep-engine 2.33.24 → 2.33.28

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 (126) hide show
  1. package/core/binary/BitSet.js +151 -167
  2. package/core/binary/BitSet.spec.js +99 -1
  3. package/core/binary/ValidatingBitSetWrapper.js +81 -0
  4. package/core/bvh2/aabb3/AABB3.js +3 -10
  5. package/core/bvh2/binary/IndexedBinaryBVH.js +1 -1
  6. package/core/bvh2/traversal/ThreeClippingPlaneComputingBVHVisitor.js +5 -1
  7. package/core/bvh2/traversal/__detailed_box_volume_intersection.js +22 -5
  8. package/core/cache/Cache.d.ts +4 -2
  9. package/core/cache/Cache.js +5 -2
  10. package/core/collection/HashMap.d.ts +9 -2
  11. package/core/collection/HashSet.d.ts +7 -2
  12. package/core/collection/HashSet.js +7 -2
  13. package/core/collection/array/binarySearchHighIndex.js +1 -1
  14. package/core/collection/array/copyArray.js +2 -2
  15. package/core/collection/array/typed/typed_array_copy.js +1 -1
  16. package/core/geom/3d/frustum/array_setFromProjectionMatrix.js +3 -3
  17. package/core/geom/3d/normal/hemioct/unit_hemioct.spec.js +1 -1
  18. package/core/geom/3d/shape/AbstractShape3D.js +37 -1
  19. package/core/geom/3d/shape/TransformedShape3D.js +121 -10
  20. package/core/geom/3d/shape/TransformedShape3D.spec.js +33 -0
  21. package/core/geom/3d/shape/UnionShape3D.js +255 -0
  22. package/core/geom/3d/shape/UnitCubeShape3D.js +88 -0
  23. package/core/geom/3d/shape/UnitCubeShape3D.spec.js +42 -0
  24. package/core/geom/3d/shape/UnitSphereShape3D.js +39 -0
  25. package/core/geom/3d/shape/util/compute_signed_distance_gradient_by_sampling.js +48 -0
  26. package/core/geom/3d/shape/util/shape_to_visual_entity.js +159 -0
  27. package/core/geom/random/randomPointInSphere.js +3 -2
  28. package/core/json/resolvePathByArray.js +2 -2
  29. package/core/model/ObservedBoolean.d.ts +2 -0
  30. package/core/parser/simple/Token.d.ts +13 -0
  31. package/core/parser/simple/Token.js +61 -27
  32. package/{engine/graphics/render/forward_plus/materials → core/primitives/strings}/insert_after.js +3 -0
  33. package/core/primitives/strings/insert_after_or_replace.js +27 -0
  34. package/editor/process/symbolic/makeHelperBoxGeometry.js +44 -0
  35. package/editor/tools/FoliagePaintTool.js +4 -4
  36. package/editor/view/ecs/EntityEditor.js +2 -2
  37. package/editor/view/ecs/components/particles/ParticleEmitterController.js +2 -2
  38. package/engine/EngineHarness.js +1 -0
  39. package/engine/animation/AnimationUtils.js +5 -5
  40. package/engine/asset/loaders/GLTFAssetLoader.js +52 -1
  41. package/engine/asset/loaders/image/ImageDecoderWorker.js +4 -3
  42. package/engine/asset/loaders/image/ImageRGBADataAsset.js +3 -2
  43. package/engine/asset/loaders/image/ImageRGBADataLoader.js +3 -3
  44. package/engine/asset/loaders/image/codec/NativeImageDecoder.js +2 -1
  45. package/engine/asset/loaders/image/png/PNG.js +113 -6
  46. package/engine/asset/loaders/image/png/PNGReader.js +5 -0
  47. package/engine/asset/loaders/material/bitmap2sampler_gl.js +1 -1
  48. package/engine/asset/loaders/material/computeImageBitmapEquality.js +6 -1
  49. package/engine/asset/loaders/material/computeTextureEquality.js +40 -49
  50. package/engine/ecs/EntityBuilder.js +25 -5
  51. package/engine/ecs/EntityComponentDataset.js +1 -1
  52. package/engine/ecs/attachment/AttachmentBinding.js +8 -0
  53. package/engine/ecs/attachment/AttachmentSystem.js +4 -0
  54. package/engine/ecs/attachment/TransformAttachmentBinding.js +14 -44
  55. package/engine/ecs/components/Tag.js +27 -6
  56. package/engine/ecs/foliage/InstancedFoliage.js +277 -266
  57. package/engine/ecs/foliage/ecs/Foliage2System.js +7 -7
  58. package/engine/ecs/foliage/ecs/InstancedMeshComponent.js +37 -0
  59. package/engine/ecs/foliage/ecs/{Foliage2.js → InstancedMeshLayer.js} +3 -45
  60. package/engine/ecs/foliage/ecs/InstancedMeshSerializationAdapter.js +6 -5
  61. package/engine/ecs/foliage/ecs/InstancedMeshUtils.js +7 -6
  62. package/engine/ecs/fow/FogOfWar.js +4 -0
  63. package/engine/ecs/fow/FogOfWarSystem.js +2 -0
  64. package/engine/ecs/gui/hud/HeadsUpDisplaySystem.js +2 -0
  65. package/engine/ecs/storage/binary/BinarySerializationRegistry.js +1 -1
  66. package/engine/ecs/system/AbstractContextSystem.js +1 -1
  67. package/engine/ecs/systems/TagSystem.js +17 -0
  68. package/engine/ecs/terrain/ecs/layers/TerrainLayer.js +12 -16
  69. package/engine/ecs/transform/Transform.js +19 -6
  70. package/engine/graphics/GraphicsEngine.js +11 -6
  71. package/engine/graphics/composit/CompositLayer.js +17 -4
  72. package/engine/graphics/composit/CompositingStages.js +8 -0
  73. package/engine/graphics/composit/LayerCompositer.js +35 -6
  74. package/engine/graphics/ecs/highlight/plugin/OutlineRenderPlugin.js +11 -7
  75. package/engine/graphics/ecs/light/Light.js +2 -0
  76. package/engine/graphics/ecs/light/binding/three/ThreeLightBinding.js +5 -1
  77. package/engine/graphics/ecs/mesh-v2/DrawMode.js +5 -0
  78. package/engine/graphics/ecs/mesh-v2/ShadedGeometry.js +32 -18
  79. package/engine/graphics/geometry/instancing/InstancedMeshGroup.js +14 -72
  80. package/engine/graphics/geometry/instancing/rewriteMaterial.js +70 -0
  81. package/engine/graphics/material/manager/MaterialManager.js +2 -1
  82. package/engine/graphics/micron/render/instanced/AttributeDataTexture.js +6 -4
  83. package/engine/graphics/micron/render/instanced/ThreeInstancedAdapter.js +0 -2
  84. package/engine/graphics/particles/ParticleEmitterLibrary.js +3 -0
  85. package/engine/graphics/particles/ecs/{ParticleEmitterSystem2.js → ParticleEmitterSystem.js} +17 -9
  86. package/engine/graphics/particles/particular/engine/ParticularEngine.js +8 -2
  87. package/engine/graphics/particles/particular/engine/emitter/ParticleEmitter.js +14 -25
  88. package/engine/graphics/particles/particular/engine/emitter/ParticleEmitterFlag.js +5 -0
  89. package/engine/graphics/particles/particular/engine/emitter/ParticlePool.js +90 -2
  90. package/engine/graphics/particles/particular/engine/emitter/ParticlePool.spec.js +7 -7
  91. package/engine/graphics/particles/particular/engine/renderers/billboard/BILLBOARD_PARTICLE_SPECIFICATION.js +15 -12
  92. package/engine/graphics/particles/particular/engine/renderers/billboard/ParticleBillboardMaterial.js +262 -51
  93. package/engine/graphics/particles/particular/engine/shader/ShaderManager.js +81 -48
  94. package/engine/graphics/particles/particular/engine/shader/debugAtlas.js +14 -0
  95. package/engine/graphics/particles/particular/engine/utils/volume/AttributeValue.js +141 -0
  96. package/engine/graphics/particles/particular/engine/utils/volume/ParticleVolume.js +148 -54
  97. package/engine/graphics/particles/particular/engine/utils/volume/lut_to_sampler.js +27 -0
  98. package/engine/graphics/particles/particular/engine/utils/volume/prototypeParticleVolume.js +544 -164
  99. package/engine/graphics/render/buffer/simple-fx/ao/AmbientOcclusionPostProcessEffect.js +15 -10
  100. package/engine/graphics/render/forward_plus/materials/FP_INJECTION_POINT_ACCUMULATION.js +1 -0
  101. package/engine/graphics/render/forward_plus/materials/FP_SHADER_CHUNK_ACCUMULATION.js +32 -0
  102. package/engine/graphics/render/forward_plus/materials/FP_SHADER_CHUNK_DECODE_PARS.js +51 -0
  103. package/engine/graphics/render/forward_plus/materials/FP_SHADER_CHUNK_PREAMBLE.js +25 -0
  104. package/engine/graphics/render/forward_plus/materials/FPlusDebugMaterial.js +3 -3
  105. package/engine/graphics/render/forward_plus/materials/ForwardPlusThreeMaterial.js +1 -1
  106. package/engine/graphics/render/forward_plus/materials/fp_build_fragment_shader.js +31 -120
  107. package/engine/graphics/render/forward_plus/materials/fp_build_vertex_lighting_shared.js +35 -0
  108. package/engine/graphics/render/forward_plus/materials/fp_build_vertex_shader.js +4 -5
  109. package/engine/graphics/render/forward_plus/plugin/MaterialTransformer.js +10 -3
  110. package/engine/graphics/render/forward_plus/plugin/ptototypeFPPlugin.js +588 -53
  111. package/engine/graphics/render/forward_plus/prototypeLightManager.js +31 -6
  112. package/engine/graphics/render/forward_plus/query/point_light_inside_volume.js +10 -9
  113. package/engine/graphics/shaders/TerrainShader.js +4 -5
  114. package/engine/graphics/shadows/ShadowMapRenderer.js +8 -2
  115. package/engine/graphics/texture/atlas/ManagedTextureAtlas.js +12 -1
  116. package/engine/graphics/texture/sampler/Sampler2D.js +3 -1
  117. package/engine/graphics/texture/sampler/convertTexture2Sampler2D.js +1 -1
  118. package/engine/graphics/texture/sampler/copy_Sampler2D_channel_data.js +66 -0
  119. package/engine/graphics/util/composeMatrix4.js +33 -23
  120. package/engine/graphics/util/decompose_matrix_4_array.js +61 -0
  121. package/engine/intelligence/behavior/ecs/BehaviorComponent.js +30 -14
  122. package/engine/knowledge/database/StaticKnowledgeDataTable.js +6 -1
  123. package/engine/navigation/ecs/components/Path.js +0 -5
  124. package/package.json +1 -1
  125. package/view/minimap/gl/MinimapWorldGL.js +12 -5
  126. package/core/geom/3d/shape/CompositeShape.js +0 -60
@@ -2,47 +2,29 @@ import { EngineHarness } from "../../../../../../EngineHarness.js";
2
2
  import { EngineConfiguration } from "../../../../../../EngineConfiguration.js";
3
3
  import GUIElementSystem from "../../../../../../ecs/gui/GUIElementSystem.js";
4
4
  import HeadsUpDisplaySystem from "../../../../../../ecs/gui/hud/HeadsUpDisplaySystem.js";
5
- import ScriptSystem from "../../../../../../ecs/systems/ScriptSystem.js";
6
- import FacingDirectionSystem from "../../../../../../../../model/game/ecs/system/FacingDirectionSystem.js";
7
- import PathFollowingSystem from "../../../../../../navigation/ecs/path_following/PathFollowingSystem.js";
8
- import SteeringSystem from "../../../../../../ecs/systems/SteeringSystem.js";
9
- import MotionSystem from "../../../../../../ecs/systems/MotionSystem.js";
10
5
  import TagSystem from "../../../../../../ecs/systems/TagSystem.js";
11
6
  import { AttachmentSocketsSystem } from "../../../../../../ecs/sockets/AttachmentSocketsSystem.js";
12
7
  import { AttachmentSystem } from "../../../../../../ecs/attachment/AttachmentSystem.js";
13
8
  import { SoundEmitterSystem } from "../../../../../../sound/ecs/emitter/SoundEmitterSystem.js";
14
9
  import SoundControllerSystem from "../../../../../../sound/ecs/SoundControllerSystem.js";
15
10
  import SoundListenerSystem from "../../../../../../sound/ecs/SoundListenerSystem.js";
16
- import TimerSystem from "../../../../../../ecs/systems/TimerSystem.js";
17
11
  import AnimationSystem from "../../../../../../ecs/systems/AnimationSystem.js";
18
12
  import TopDownCameraControllerSystem from "../../../../../ecs/camera/topdown/TopDownCameraControllerSystem.js";
19
- import { TopDownCameraLanderSystem } from "../../../../../ecs/camera/topdown/TopDownCameraLanderSystem.js";
20
13
  import { CameraSystem } from "../../../../../ecs/camera/CameraSystem.js";
21
14
  import { MeshSystem } from "../../../../../ecs/mesh/MeshSystem.js";
22
15
  import ClingToTerrainSystem from "../../../../../../ecs/terrain/ecs/ClingToTerrainSystem.js";
23
16
  import TerrainSystem from "../../../../../../ecs/terrain/ecs/TerrainSystem.js";
24
- import WaterSystem from "../../../../../ecs/water/WaterSystem.js";
25
17
  import Trail2DSystem from "../../../../../ecs/trail2d/Trail2DSystem.js";
26
18
  import { Foliage2System } from "../../../../../../ecs/foliage/ecs/Foliage2System.js";
27
19
  import ViewportPositionSystem from "../../../../../../ecs/gui/position/ViewportPositionSystem.js";
28
- import { GridPosition2TransformSystem } from "../../../../../../grid/systems/GridPosition2TransformSystem.js";
29
- import { Transform2GridPositionSystem } from "../../../../../../grid/transform2grid/Transform2GridPositionSystem.js";
30
20
  import SynchronizePositionSystem from "../../../../../../ecs/systems/SynchronizePositionSystem.js";
31
- import GridObstacleSystem from "../../../../../../grid/systems/GridObstacleSystem.js";
32
- import GridPositionSystem from "../../../../../../grid/systems/GridPositionSystem.js";
33
21
  import InputControllerSystem from "../../../../../../input/ecs/systems/InputControllerSystem.js";
34
22
  import { InputSystem } from "../../../../../../input/ecs/systems/InputSystem.js";
35
23
  import MeshHighlightSystem from "../../../../../ecs/highlight/system/MeshHighlightSystem.js";
36
24
  import LightSystem from "../../../../../ecs/light/LightSystem.js";
37
- import AnimationControllerSystem from "../../../../../ecs/animation/AnimationControllerSystem.js";
38
- import { AnimationGraphSystem } from "../../../../../ecs/animation/animator/AnimationGraphSystem.js";
39
- import { FogOfWarSystem } from "../../../../../../ecs/fow/FogOfWarSystem.js";
40
- import { FogOfWarRevealerSystem } from "../../../../../../ecs/fow/FogOfWarRevealerSystem.js";
41
25
  import { BehaviorSystem } from "../../../../../../intelligence/behavior/ecs/BehaviorSystem.js";
42
26
  import { SerializationMetadataSystem } from "../../../../../../ecs/systems/SerializationMetadataSystem.js";
43
- import { InverseKinematicsSystem } from "../../../../../../ecs/animation/InverseKinematicsSystem.js";
44
27
  import { PathDisplaySystem } from "../../../../../ecs/path/PathDisplaySystem.js";
45
- import { MicronRenderPlugin } from "../../../../../micron/plugin/MicronRenderPlugin.js";
46
28
  import RenderSystem from "../../../../../../ecs/systems/RenderSystem.js";
47
29
  import { makeEngineOptionsModel } from "../../../../../../../../model/game/options/makeEngineOptionsModel.js";
48
30
  import { enableEditor } from "../../../../../../../editor/enableEditor.js";
@@ -55,7 +37,7 @@ import { Transform } from "../../../../../../ecs/transform/Transform.js";
55
37
  import Mesh from "../../../../../ecs/mesh/Mesh.js";
56
38
  import { AABB3 } from "../../../../../../../core/bvh2/aabb3/AABB3.js";
57
39
  import { ParticleVolume } from "./ParticleVolume.js";
58
- import { ParticleEmitterSystem2 } from "../../../../ecs/ParticleEmitterSystem2.js";
40
+ import { ParticleEmitterSystem } from "../../../../ecs/ParticleEmitterSystem.js";
59
41
  import { BehaviorComponent } from "../../../../../../intelligence/behavior/ecs/BehaviorComponent.js";
60
42
  import { RepeatBehavior } from "../../../../../../intelligence/behavior/decorator/RepeatBehavior.js";
61
43
  import { ActionBehavior } from "../../../../../../intelligence/behavior/primitive/ActionBehavior.js";
@@ -67,11 +49,35 @@ import GUIElement from "../../../../../../ecs/gui/GUIElement.js";
67
49
  import EmptyView from "../../../../../../../view/elements/EmptyView.js";
68
50
  import HeadsUpDisplay from "../../../../../../ecs/gui/hud/HeadsUpDisplay.js";
69
51
  import ViewportPosition from "../../../../../../ecs/gui/position/ViewportPosition.js";
70
- import { Sampler2D } from "../../../../../texture/sampler/Sampler2D.js";
71
52
  import { CanvasView } from "../../../../../../../view/elements/CanvasView.js";
72
53
  import convertSampler2D2Canvas from "../../../../../texture/sampler/Sampler2D2Canvas.js";
73
54
  import Vector1 from "../../../../../../../core/geom/Vector1.js";
74
55
  import { clamp } from "../../../../../../../core/math/clamp.js";
56
+ import { UnitCubeShape3D } from "../../../../../../../core/geom/3d/shape/UnitCubeShape3D.js";
57
+ import { ShadedGeometrySystem } from "../../../../../ecs/mesh-v2/ShadedGeometrySystem.js";
58
+ import { lut_to_sampler } from "./lut_to_sampler.js";
59
+ import {
60
+ shape_to_visual_entity,
61
+ SHAPE_VISUAL_ENTITY_TAG
62
+ } from "../../../../../../../core/geom/3d/shape/util/shape_to_visual_entity.js";
63
+ import { seededRandom } from "../../../../../../../core/math/random/seededRandom.js";
64
+ import { TransformedShape3D } from "../../../../../../../core/geom/3d/shape/TransformedShape3D.js";
65
+ import { mat4 } from "gl-matrix";
66
+ import { UnionShape3D } from "../../../../../../../core/geom/3d/shape/UnionShape3D.js";
67
+ import { ShadedGeometry } from "../../../../../ecs/mesh-v2/ShadedGeometry.js";
68
+ import { DrawMode } from "../../../../../ecs/mesh-v2/DrawMode.js";
69
+ import { makeHelperBoxGeometry } from "../../../../../../../editor/process/symbolic/makeHelperBoxGeometry.js";
70
+ import { LineBasicMaterial } from "three";
71
+ import Renderable from "../../../../../../ecs/components/Renderable.js";
72
+ import { TransformControls } from "three/examples/jsm/controls/TransformControls.js";
73
+ import { threeUpdateTransform } from "../../../../../util/threeUpdateTransform.js";
74
+ import InputController from "../../../../../../input/ecs/components/InputController.js";
75
+ import { computeStatisticalMean } from "../../../../../../../core/math/statistics/computeStatisticalMean.js";
76
+ import ButtonView from "../../../../../../../view/elements/button/ButtonView.js";
77
+ import { UnitSphereShape3D } from "../../../../../../../core/geom/3d/shape/UnitSphereShape3D.js";
78
+ import TopDownCameraController from "../../../../../ecs/camera/topdown/TopDownCameraController.js";
79
+ import { randomFloatBetween } from "../../../../../../../core/math/random/randomFloatBetween.js";
80
+ import { MicronRenderPlugin } from "../../../../../micron/plugin/MicronRenderPlugin.js";
75
81
 
76
82
  const engineHarness = new EngineHarness();
77
83
 
@@ -92,50 +98,35 @@ function makeConfig(engine) {
92
98
  const headsUpDisplaySystem = new HeadsUpDisplaySystem(graphics);
93
99
 
94
100
  config.systems.push(
95
- new ScriptSystem(),
96
- new FacingDirectionSystem(),
97
- new PathFollowingSystem(),
98
- new SteeringSystem(),
99
- new MotionSystem(),
100
101
  new TagSystem(),
101
102
  new AttachmentSocketsSystem(),
102
103
  new AttachmentSystem(),
103
104
  new SoundEmitterSystem(assetManager, sound.destination, sound.context),
104
105
  new SoundControllerSystem(),
105
106
  new SoundListenerSystem(sound.context),
106
- new TimerSystem(),
107
107
  guiSystem,
108
108
  new AnimationSystem(graphics.viewport.size),
109
109
  new TopDownCameraControllerSystem(graphics),
110
- new TopDownCameraLanderSystem(),
111
110
  new CameraSystem(graphics.scene, graphics),
112
111
  new MeshSystem(engine),
113
112
  new ClingToTerrainSystem(),
114
113
  new TerrainSystem(graphics, assetManager),
115
- new WaterSystem(graphics),
116
114
  new Trail2DSystem(engine),
117
115
  new Foliage2System(assetManager, graphics),
118
116
  new ViewportPositionSystem(graphics.viewport.size),
119
- new GridPosition2TransformSystem(),
120
- new Transform2GridPositionSystem(),
121
117
  new SynchronizePositionSystem(),
122
- new GridObstacleSystem(),
123
- new GridPositionSystem(),
124
118
  new InputControllerSystem(devices),
125
119
  new InputSystem(devices),
126
120
  new MeshHighlightSystem(engine),
127
121
  new LightSystem(engine, {
128
122
  shadowResolution: 2048
129
123
  }),
130
- new AnimationControllerSystem(),
131
- new AnimationGraphSystem(graphics.viewport.size),
132
124
  headsUpDisplaySystem,
133
- new FogOfWarSystem(graphics),
134
- new FogOfWarRevealerSystem(0),
135
125
  new BehaviorSystem(engine),
136
126
  new SerializationMetadataSystem(),
137
- new InverseKinematicsSystem(),
138
127
  new PathDisplaySystem(engine),
128
+ new ParticleEmitterSystem(engine),
129
+ new ShadedGeometrySystem(engine)
139
130
  );
140
131
 
141
132
 
@@ -186,19 +177,19 @@ heatmap_lut_0.write([
186
177
  ]);
187
178
  heatmap_lut_0.computeUniformPositions();
188
179
 
189
- const heatmap_lut_1 = new ParameterLookupTable(4);
190
- heatmap_lut_1.write([
180
+ const heatmap_lut_orange_to_red = new ParameterLookupTable(4);
181
+ heatmap_lut_orange_to_red.write([
191
182
  255, 127, 0, 100,
192
183
  206, 2, 86, 100
193
184
  ]);
194
- heatmap_lut_1.computeUniformPositions();
185
+ heatmap_lut_orange_to_red.computeUniformPositions();
195
186
 
196
- const heatmap_lut_2 = new ParameterLookupTable(4);
197
- heatmap_lut_2.write([
187
+ const heatmap_lut_pink_to_blue = new ParameterLookupTable(4);
188
+ heatmap_lut_pink_to_blue.write([
198
189
  255, 151, 213, 50,
199
190
  2, 243, 255, 50
200
191
  ]);
201
- heatmap_lut_2.computeUniformPositions();
192
+ heatmap_lut_pink_to_blue.computeUniformPositions();
202
193
 
203
194
  const heatmap_lut_3 = new ParameterLookupTable(4);
204
195
  heatmap_lut_3.write(
@@ -220,75 +211,114 @@ heatmap_lut_3.write(
220
211
  ]
221
212
  );
222
213
 
214
+
223
215
  /**
224
216
  *
225
217
  * @param {Engine} engine
226
218
  */
227
- async function main(engine) {
228
- EngineHarness.buildBasics({
229
- engine,
230
- enableWater: false,
231
- // enableTerrain: false,
232
- enableTerrain: true,
233
- terrainSize: new Vector2(100, 100),
234
- focus: new Vector3(102, 0, 61),
235
- // pitch: -0.5,
236
- // yaw: 2.2,
237
- // distance: 3
238
- pitch: 0.9,
239
- yaw: 3.1,
240
- distance: 20
241
- });
219
+ function make_shape_vis_toggle(engine) {
220
+ const ecd = engine.entityManager.dataset;
221
+ const entities = TagSystem.find_entities_with_tag(SHAPE_VISUAL_ENTITY_TAG, ecd);
242
222
 
243
223
 
244
- engine.graphics.renderer.setClearColor('rgba(99,99,99,1)');
224
+ const builders = entities.map(e => EntityBuilder.readFromDataset(e, ecd));
245
225
 
226
+ function toggle() {
227
+ if (builders.length <= 1) {
228
+ return;
229
+ }
246
230
 
247
- const ecd = engine.entityManager.dataset;
231
+ if (builders[0].isBuilt) {
232
+ builders.forEach(b => b.destroy());
233
+ } else {
234
+ builders.forEach(b => b.build(ecd));
235
+ }
236
+ }
237
+
238
+ const buttonView = new ButtonView({
239
+ action: toggle,
240
+ name: 'Toggle Shapes',
241
+ css: {
242
+ position: 'absolute',
243
+ bottom: '10px',
244
+ right: '10px',
245
+ background: 'rgba(255,255,255,0.8)',
246
+ border: '1px solid rgba(0,0,0,1)',
247
+ padding: '2px'
248
+ }
249
+ });
248
250
 
249
251
  new EntityBuilder()
250
- .add(Transform.fromJSON({
251
- position: {
252
- x: 20,
253
- y: -5.8,
254
- z: 100
255
- },
256
- scale: {
257
- x: 1,
258
- y: 1,
259
- z: 1
260
- }
261
- }))
262
- .add(Mesh.fromJSON({
263
- url: 'data/models/moicon/05-ground-floor/model.gltf',
264
- castShadow: true,
265
- receiveShadow: true
266
- }))
267
- // .build(ecd);
268
- new EntityBuilder()
269
- .add(Transform.fromJSON({
270
- position: {
271
- x: 20,
272
- y: -5.8,
273
- z: 100
274
- },
275
- scale: {
276
- x: 1,
277
- y: 1,
278
- z: 1
279
- }
280
- }))
252
+ .add(GUIElement.fromView(buttonView))
253
+ .build(ecd);
254
+
255
+ return {
256
+ toggle
257
+ };
258
+ }
259
+
260
+ function mat_from_aabb3(aabb3) {
261
+ const m4 = mat4.create();
262
+
263
+ mat4.fromRotationTranslationScale(m4, [0, 0, 0, 1], [(aabb3.x0 + aabb3.x1) / 2, (aabb3.y0 + aabb3.y1) / 2, (aabb3.z0 + aabb3.z1) / 2], [aabb3.getExtentsX(), aabb3.getExtentsY(), aabb3.getExtentsZ()]);
264
+
265
+ return m4;
266
+ }
267
+
268
+ /**
269
+ *
270
+ * @param {string} url
271
+ * @param {EntityComponentDataset} ecd
272
+ * @returns {EntityBuilder}
273
+ */
274
+ function load_model(url, ecd) {
275
+
276
+ const b = new EntityBuilder();
277
+ b
278
+ .add(new Transform())
281
279
  .add(Mesh.fromJSON({
282
- url: 'data/models/moicon/08-clickable-assets/model.gltf',
280
+ url: url,
283
281
  castShadow: true,
284
282
  receiveShadow: true
285
283
  }))
286
- // .build(ecd);
284
+ .build(ecd);
285
+
286
+ return b;
287
+ }
288
+
289
+ /**
290
+ *
291
+ * @param {Engine} engine
292
+ * @returns {Promise<void>}
293
+ */
294
+ async function sample_scene_0(engine) {
295
+ const ecd = engine.entityManager.dataset;
296
+
297
+ function load_model_s(url, y_offset = 0) {
298
+ const b = load_model(url, ecd);
299
+ b.getComponent(Transform).position.set(
300
+ 20,
301
+ -5.8 + y_offset,
302
+ 100
303
+ );
304
+
305
+ return b;
306
+ }
307
+
308
+ // load_model('moicon/06_04_hapro/00-environment/model.gltf', -0.1);
309
+ load_model_s('moicon/06_04_hapro/05-ground-floor/model.gltf');
310
+ load_model_s('C:/git/moh/app/moicon/06_04_hapro/08-clickable-assets-new/model.gltf');
311
+ // load_model('moicon/06_04_hapro/02-bearers/model.gltf');
312
+ // load_model('moicon/06_04_hapro/04-1st-floor/model.gltf');
313
+
287
314
 
288
315
  await make_demo_volume({
289
316
  ecd: ecd,
290
317
  lut: heatmap_lut_0,
291
- bounds: new AABB3(67.73, 0, 89, 115.84, 3, 118.34),
318
+ shape: UnionShape3D.from([
319
+ TransformedShape3D.from_m4(new UnitCubeShape3D(), mat_from_aabb3(new AABB3(67.73, 0, 89, 115.84, 3, 118.34))),
320
+ TransformedShape3D.from_m4(new UnitCubeShape3D(), mat_from_aabb3(new AABB3(98, 0, 76.5, 109.5, 3, 89)))
321
+ ]),
292
322
  particle_size: 4,
293
323
  density: 4,
294
324
  period: 10
@@ -297,7 +327,11 @@ async function main(engine) {
297
327
  await make_demo_volume({
298
328
  ecd: ecd,
299
329
  lut: heatmap_lut_0,
300
- bounds: new AABB3(43.8, 0, 89, 67.40, 3, 131),
330
+ shape: UnionShape3D.from([
331
+ TransformedShape3D.from_m4(new UnitCubeShape3D(), [14.980091485108495, 0, 0, 0, 0, 2.812495250139616, 0, 0, 0, 0, 7.469446746375293, 0, 54.83080514238756, 1.568241402881399, 92.51937192481576, 1]),
332
+ TransformedShape3D.from_m4(new UnitCubeShape3D(), [6.644515553810907, 0, 0, 0, 0, 2.812495250139616, 0, 0, 0, 0, 5.507507223409315, 0, 46.95032009188344, 1.568241402881399, 95.54148649329517, 1]),
333
+ TransformedShape3D.from_m4(new UnitCubeShape3D(), [23.762890107594952, 0, 0, 0, 0, 2.812495250139616, 0, 0, 0, 0, 34.57956316503163, 0, 55.436098243647756, 1.568241402881399, 113.46988143189215, 1])
334
+ ]),
301
335
  particle_size: 2,
302
336
  density: 1,
303
337
  period: 10,
@@ -306,8 +340,8 @@ async function main(engine) {
306
340
 
307
341
  await make_demo_volume({
308
342
  ecd: ecd,
309
- lut: heatmap_lut_1,
310
- bounds: new AABB3(97.68, 0, 67.71, 115.76, 3, 76.14),
343
+ lut: heatmap_lut_orange_to_red,
344
+ shape: TransformedShape3D.from_m4(new UnitCubeShape3D(), mat_from_aabb3(new AABB3(97.68, 0, 67.71, 115.76, 3, 76.14))),
311
345
  particle_size: 1,
312
346
  density: 1.2,
313
347
  period: 7,
@@ -316,121 +350,437 @@ async function main(engine) {
316
350
 
317
351
  await make_demo_volume({
318
352
  ecd: ecd,
319
- lut: heatmap_lut_2,
320
- bounds: new AABB3(79.0, 0, 67.71, 97.35, 3, 76.14),
353
+ lut: heatmap_lut_pink_to_blue,
354
+ shape: UnionShape3D.from([
355
+ TransformedShape3D.from_m4(new UnitCubeShape3D(), [15.218520811592711, 0, 0, 0, 0, 3.058639690434693, 0, 0, 0, 0, 5.828701399328644, 0, 89.53848861962253, 2.0721850959505907, 73.05504876489894, 1]),
356
+ TransformedShape3D.from_m4(new UnitCubeShape3D(), [18.10977091153633, 0, 0, 0, 0, 3.058639690434693, 0, 0, 0, 0, 2.5862076050328002, 0, 88.03260126722904, 2.0721850959505907, 69.0797462656922, 1])
357
+ ]),
321
358
  particle_size: 4,
322
359
  density: 4,
323
360
  period: 7,
324
361
  period_offset: 2,
325
362
  });
326
363
 
364
+ // large open room, dense particles
327
365
  await make_demo_volume({
328
366
  ecd: ecd,
329
367
  lut: heatmap_lut_3,
330
- bounds: new AABB3(67.85, 0, 31.1, 109.8, 3, 67.02),
331
- particle_size: 0.1,
368
+ shape: UnionShape3D.from([
369
+ TransformedShape3D.from_m4(new UnitCubeShape3D(), [20.977896627021547, 0, 0, 0, 0, 2.956899734575006, 0, 0, 0, 0, 36.201589869571954, 0, 99.2120028317975, 1.5919924971428276, 49.21655402009093, 1]),
370
+ TransformedShape3D.from_m4(new UnitCubeShape3D(), [24.455615450514458, 0, 0, 0, 0, 2.956899734575006, 0, 0, 0, 0, 28.081536987027807, 0, 80.11618755300161, 1.5919924971428276, 45.13808745329574, 1]),
371
+ TransformedShape3D.from_m4(new UnitCubeShape3D(), [5.562874425497998, 0, 0, 0, 0, 2.956899734575006, 0, 0, 0, 0, 2.654155224548708, 0, 70.80986716000054, 1.5919924971428276, 59.679876796143446, 1])
372
+ ]),
373
+ particle_size: 0.15,
332
374
  density: 5,
333
375
  period: 7,
334
376
  period_offset: 2,
335
377
  });
336
378
 
379
+ // popsicle
380
+ await make_demo_volume({
381
+ ecd: ecd,
382
+ lut: heatmap_lut_orange_to_red,
383
+ shape: UnionShape3D.from([
384
+ TransformedShape3D.from_m4(new UnitCubeShape3D(), [-3.8971594611231577, -1.9562533614625899, -0.5725042419276598, 0, -8.346390838999248, 16.986127440019352, -1.226109479938015, 0, 0.12112312197093604, 0, -0.8245111322851176, 0, 55.83305788880312, 9.579537179233043, 83.59013920067233, 1]),
385
+ TransformedShape3D.from_m4(new UnitSphereShape3D(), [10.237283879346698, 0, 0, 0, 0, 10.237283879346698, 0, 0, 0, 0, 10.237283879346698, 0, 51.783732965076716, 18.028888481196716, 82.91084586075068, 1])
386
+ ]),
387
+ particle_size: 0.7,
388
+ density: 5,
389
+ period: 3,
390
+ period_offset: 2,
391
+ sort: true
392
+ });
393
+
337
394
  engine.devices.pointer.on.down.add((p) => {
338
395
  pick(p.x, p.y, engine.graphics, obtainTerrain(ecd), (grid_position, position, normal) => {
339
396
  console.log(position.toJSON());
340
397
  });
341
398
  });
399
+
400
+ make_shape_vis_toggle(engine).toggle(); // turn off shape vis initially
401
+
402
+ // editing box
403
+ make_box_editor(engine, Transform.fromJSON({
404
+ position: {
405
+ x: 20,
406
+ y: 5,
407
+ z: 100
408
+ },
409
+ scale: {
410
+ x: 1,
411
+ y: 1,
412
+ z: 1
413
+ }
414
+ }));
342
415
  }
343
416
 
417
+
344
418
  /**
345
419
  *
346
- * @param {ParameterLookupTable} lut
347
- * @param {number} width
348
- * @param {number} height
349
- * @returns {Sampler2D}
420
+ * @param {Engine} engine
421
+ * @returns {Promise<void>}
350
422
  */
351
- function lut_to_sampler(lut, width, height) {
352
- const sampler = Sampler2D.uint8(4, width, height);
423
+ async function sample_scene_nam(engine) {
424
+ const ecd = engine.entityManager.dataset;
353
425
 
354
- const s = [];
426
+ ecd.getAnyComponent(TopDownCameraController).component.fromJSON({
427
+ "target": {
428
+ "x": 21.09522080045099,
429
+ "y": -0.6327784109623013,
430
+ "z": 6.138907038731565
431
+ },
432
+ "pitch": 1.1099999999999923,
433
+ "yaw": -3.143185307179591,
434
+ "roll": 0,
435
+ "distance": 29,
436
+ "distanceMin": 0,
437
+ "distanceMax": 1000
438
+ });
355
439
 
356
- for (let i = 0; i < width; i++) {
440
+ load_model('moicon/20_Dec_2021_Nammo/with_assets(for_alex)/model.gltf', ecd)
357
441
 
358
- lut.sample(i / (width - 1), s);
359
- s[3] = 255;
442
+ const P_SIZE_SMALL = 0.15;
443
+ const P_SIZE_MEDIUM = 0.6;
444
+ const P_SIZE_LARGE = 2;
360
445
 
361
- for (let j = 0; j < height; j++) {
362
- sampler.set(i, j, s);
363
- }
446
+ const random = seededRandom(42);
364
447
 
365
- }
448
+ const PERIOD_LONG = 13;
449
+
450
+ await make_demo_volume({
451
+ ecd: ecd,
452
+ lut: heatmap_lut_pink_to_blue,
453
+ shape: TransformedShape3D.from_m4(new UnitCubeShape3D(), [5.267098043281134, 0, 0, 0, 0, 2.3166487265965343, 0, 0, 0, 0, 6.606365126660234, 0, 2.8037239954452864, 1.4169994923726943, 11.460158766988037, 1]),
454
+ particle_size: P_SIZE_MEDIUM,
455
+ density: 3,
456
+ period: PERIOD_LONG,
457
+ period_offset: randomFloatBetween(random, 0, PERIOD_LONG),
458
+ sprite: 'data/textures/particle/UETools/Hexagon_01.png'
459
+ });
460
+ await make_demo_volume({
461
+ ecd: ecd,
462
+ lut: heatmap_lut_orange_to_red,
463
+ shape: TransformedShape3D.from_m4(new UnitCubeShape3D(), [4.7577406314060395, 0, 0, 0, 0, 2.3166487265965343, 0, 0, 0, 0, 6.606365126660234, 0, 8.075207307031247, 1.4169994923726943, 11.460158766988037, 1]),
464
+ particle_size: P_SIZE_MEDIUM,
465
+ density: 3,
466
+ period: PERIOD_LONG,
467
+ period_offset: randomFloatBetween(random, 0, PERIOD_LONG),
468
+ sprite: 'data/textures/particle/UETools/Circle_04.png'
469
+ });
470
+
471
+ await make_demo_volume({
472
+ ecd: ecd,
473
+ lut: heatmap_lut_pink_to_blue,
474
+ shape: TransformedShape3D.from_m4(new UnitCubeShape3D(), [6.956797095914032, 0, 0, 0, 0, 2.3166487265965343, 0, 0, 0, 0, 6.606365126660234, 0, 14.17733466985805, 1.4169994923726943, 11.460158766988037, 1]),
475
+ particle_size: P_SIZE_MEDIUM,
476
+ density: 3,
477
+ period: PERIOD_LONG,
478
+ period_offset: randomFloatBetween(random, 0, PERIOD_LONG),
479
+ sprite: 'data/textures/particle/travnik/plus_2.png'
480
+ });
481
+
482
+ await make_demo_volume({
483
+ ecd: ecd,
484
+ lut: heatmap_lut_pink_to_blue,
485
+ shape: TransformedShape3D.from_m4(new UnitCubeShape3D(), [4.733772190018377, 0, 0, 0, 0, 2.3166487265965343, 0, 0, 0, 0, 6.606365126660234, 0, 20.284613387782148, 1.4169994923726943, 11.460158766988037, 1]),
486
+ particle_size: P_SIZE_MEDIUM,
487
+ density: 3,
488
+ period: PERIOD_LONG,
489
+ period_offset: randomFloatBetween(random, 0, PERIOD_LONG),
490
+ sprite: 'data/textures/particle/UETools/Circle_04.png'
491
+ });
492
+
493
+ await make_demo_volume({
494
+ ecd: ecd,
495
+ lut: heatmap_lut_pink_to_blue,
496
+ shape: TransformedShape3D.from_m4(new UnitCubeShape3D(), [5.924905976332568, 0, 0, 0, 0, 2.3166487265965343, 0, 0, 0, 0, 6.606365126660234, 0, 31.662442543335885, 1.4169994923726943, 11.460158766988037, 1]),
497
+ particle_size: P_SIZE_MEDIUM,
498
+ density: 3,
499
+ period: PERIOD_LONG,
500
+ period_offset: randomFloatBetween(random, 0, PERIOD_LONG),
501
+ sprite: 'data/textures/particle/UETools/Circle_04.png'
502
+ });
366
503
 
367
- return sampler;
504
+ await make_demo_volume({
505
+ ecd: ecd,
506
+ lut: heatmap_lut_0,
507
+ shape: TransformedShape3D.from_m4(new UnitCubeShape3D(), [5.7305058801925, 0, 0, 0, 0, 2.3166487265965343, 0, 0, 0, 0, 6.606365126660234, 0, 37.70942297505848, 1.4169994923726943, 11.460158766988037, 1]),
508
+ particle_size: P_SIZE_MEDIUM,
509
+ density: 8,
510
+ period: PERIOD_LONG,
511
+ period_offset: randomFloatBetween(random, 0, PERIOD_LONG),
512
+ sprite: 'data/textures/particle/UETools/Circle_04.png'
513
+ });
514
+ await make_demo_volume({
515
+ ecd: ecd,
516
+ lut: heatmap_lut_0,
517
+ shape: TransformedShape3D.from_m4(new UnitCubeShape3D(), [6.575632395877399, 0, 0, 0, 0, 2.3166487265965343, 0, 0, 0, 0, 4.51714948412602, 0, 37.272800538855826, 1.4169994923726943, 2.4066558057134095, 1]),
518
+ particle_size: P_SIZE_MEDIUM,
519
+ density: 8,
520
+ period: PERIOD_LONG,
521
+ period_offset: randomFloatBetween(random, 0, PERIOD_LONG),
522
+ sprite: 'data/textures/particle/UETools/Circle_04.png'
523
+ });
524
+
525
+ await make_demo_volume({
526
+ ecd: ecd,
527
+ lut: heatmap_lut_0,
528
+ shape: TransformedShape3D.from_m4(new UnitCubeShape3D(), [6.410614101275306, 0, 0, 0, 0, 2.3166487265965343, 0, 0, 0, 0, 4.51714948412602, 0, 30.458756650580582, 1.4169994923726943, 2.4066558057134095, 1]),
529
+ particle_size: P_SIZE_MEDIUM,
530
+ density: 8,
531
+ period: PERIOD_LONG,
532
+ period_offset: randomFloatBetween(random, 0, PERIOD_LONG),
533
+ sprite: 'data/textures/particle/UETools/Circle_04.png'
534
+ });
535
+
536
+ await make_demo_volume({
537
+ ecd: ecd,
538
+ lut: heatmap_lut_3,
539
+ shape: TransformedShape3D.from_m4(new UnitCubeShape3D(), [4.260857135913424, 0, 0, 0, 0, 2.3166487265965343, 0, 0, 0, 0, 4.51714948412602, 0, 24.82865688356064, 1.4169994923726943, 2.4066558057134095, 1]),
540
+ particle_size: P_SIZE_SMALL,
541
+ density: 3,
542
+ period: PERIOD_LONG,
543
+ period_offset: randomFloatBetween(random, 0, PERIOD_LONG),
544
+ sprite: 'data/textures/particle/UETools/Circle_01.png'
545
+ });
546
+
547
+ await make_demo_volume({
548
+ ecd: ecd,
549
+ lut: heatmap_lut_3,
550
+ shape: TransformedShape3D.from_m4(new UnitCubeShape3D(), [4.870266350649175, 0, 0, 0, 0, 2.3166487265965343, 0, 0, 0, 0, 4.51714948412602, 0, 20.022408905267525, 1.4169994923726943, 2.4066558057134095, 1]),
551
+ particle_size: P_SIZE_SMALL,
552
+ density: 3,
553
+ period: PERIOD_LONG,
554
+ period_offset: randomFloatBetween(random, 0, PERIOD_LONG),
555
+ sprite: 'data/textures/particle/UETools/Cross_04.png'
556
+ });
557
+ await make_demo_volume({
558
+ ecd: ecd,
559
+ lut: heatmap_lut_pink_to_blue,
560
+ shape: UnionShape3D.from([
561
+ TransformedShape3D.from_m4(new UnitCubeShape3D(), [5.985827128973811, 0, 0, 0, 0, 2.435269776236539, 0, 0, 0, 0, 4.669621139110231, 0, 11.08356834576874, 1.2643565739307023, 2.4360416869081885, 1]),
562
+ TransformedShape3D.from_m4(new UnitCubeShape3D(), [8.413758403821523, 0, 0, 0, 0, 2.3166487265965343, 0, 0, 0, 0, 7.775469675813772, 0, 4.313201108449287, 1.4169994923726943, 4.011630095541064, 1]),
563
+ TransformedShape3D.from_m4(new UnitCubeShape3D(), [8.413758403821523, 0, 0, 0, 0, 2.3166487265965343, 0, 0, 0, 0, 2.925065210015915, 0, 12.417224289491141, 1.4169994923726943, 6.432483110925785, 1])
564
+ ]),
565
+ particle_size: P_SIZE_LARGE,
566
+ density: 4,
567
+ period: PERIOD_LONG,
568
+ period_offset: randomFloatBetween(random, 0, PERIOD_LONG),
569
+ sprite: 'data/textures/particle/UETools/Circle_04.png'
570
+ });
571
+
572
+ make_shape_vis_toggle(engine).toggle(); // turn off shape vis initially
573
+
574
+ // editing box
575
+ // make_box_editor(engine, Transform.fromJSON({
576
+ // position: {
577
+ // x: -2,
578
+ // y: 5,
579
+ // z: 0
580
+ // },
581
+ // scale: {
582
+ // x: 1,
583
+ // y: 1,
584
+ // z: 1
585
+ // }
586
+ // }));
368
587
  }
369
588
 
370
- async function create_volume({
371
- bounds = new AABB3(0, 0, 0, 1, 1, 1),
372
- density = 10,
373
- particle_size = 1
374
- }) {
589
+ /**
590
+ *
591
+ * @param {Engine} engine
592
+ */
593
+ async function main(engine) {
594
+ EngineHarness.buildBasics({
595
+ engine,
596
+ enableWater: false,
597
+ enableTerrain: false,
598
+ // enableTerrain: true,
599
+ terrainSize: new Vector2(100, 100),
600
+ focus: new Vector3(102, 0, 61),
601
+ // pitch: -0.5,
602
+ // yaw: 2.2,
603
+ // distance: 3
604
+ pitch: 0.9,
605
+ yaw: 3.1,
606
+ distance: 20
607
+ });
375
608
 
376
- const aabb_bounds = new AABB3();
377
- aabb_bounds.fromJSON(bounds);
378
609
 
379
- const hs = particle_size / 4;
610
+ engine.graphics.renderer.setClearColor('rgba(99,99,99,1)');
380
611
 
381
- aabb_bounds.x0 += hs;
382
- aabb_bounds.z0 += hs;
612
+ // await sample_scene_nam(engine);
613
+ await sample_scene_0(engine);
614
+ }
383
615
 
384
- aabb_bounds.x1 -= hs;
385
- aabb_bounds.z1 -= hs;
616
+ /**
617
+ *
618
+ * @param {Engine} engine
619
+ * @param {Transform} [transform]
620
+ */
621
+ function make_box_editor(engine, transform = new Transform()) {
622
+ const controls = new TransformControls(engine.graphics.camera, engine.graphics.domElement);
386
623
 
387
- const adjusted_density = density / particle_size;
624
+ const eb = new EntityBuilder();
625
+ const g_unit_cube = makeHelperBoxGeometry(1, 1, 1);
388
626
 
389
- const v = new ParticleVolume();
627
+ const ecd = engine.entityManager.dataset;
390
628
 
391
- const dx = aabb_bounds.x1 - aabb_bounds.x0;
392
- const dy = aabb_bounds.y1 - aabb_bounds.y0;
393
- const dz = aabb_bounds.z1 - aabb_bounds.z0;
629
+ const lineMaterial = new LineBasicMaterial({
630
+ depthTest: true,
631
+ depthWrite: false,
632
+ transparent: true,
633
+ linewidth: 1,
634
+ fog: false,
635
+ color: '#4aff51',
636
+ opacity: 1
637
+ });
394
638
 
395
- v.transform.scale.set(
396
- dx,
397
- dy,
398
- dz
399
- );
639
+ const box_transform = transform.clone();
640
+ eb.add(box_transform);
641
+ const sg = ShadedGeometry.from(g_unit_cube, lineMaterial, DrawMode.LineSegments);
642
+ eb.add(sg);
400
643
 
401
- v.transform.position.set(
402
- aabb_bounds.x0 + dx / 2,
403
- aabb_bounds.y0 + dy / 2,
404
- aabb_bounds.z0 + dz / 2
405
- );
644
+ eb.build(ecd);
406
645
 
646
+ const cachedObject = sg.__cached_object;
647
+ cachedObject.frustumCulled = false;
648
+ controls.attach(cachedObject);
407
649
 
408
- const em = engine.entityManager;
409
650
 
410
- if (em.getSystem(ParticleEmitterSystem2) === null) {
411
- await em.addSystem(new ParticleEmitterSystem2(engine.assetManager, engine.graphics));
412
- }
651
+ controls.setSize(1);
652
+ const r_controls = new Renderable(controls);
653
+ r_controls.matrixAutoUpdate = true;
654
+ r_controls.boundingBoxNeedsUpdate = false;
655
+ r_controls.boundingBox.setBounds(0, 0, 0, 1, 1, 1);
656
+
657
+ // make camera controller holder
658
+ const entity = TagSystem.find_entities_with_tag('CameraController', ecd)[0];
659
+
660
+ const camera_controls = EntityBuilder.readFromDataset(entity, ecd);
661
+
662
+
663
+ new EntityBuilder()
664
+ .add(r_controls)
665
+ .add(new Transform())
666
+ .add(new InputController([
667
+ {
668
+ path: 'keyboard/keys/w/down',
669
+ listener() {
670
+ controls.setMode('translate');
671
+ }
672
+ },
673
+ {
674
+ path: 'keyboard/keys/e/down',
675
+ listener() {
676
+ controls.setMode('scale');
677
+ }
678
+ },
679
+ {
680
+ path: 'keyboard/keys/r/down',
681
+ listener() {
682
+ controls.setMode('rotate');
683
+ }
684
+ },
685
+ {
686
+ path: 'keyboard/keys/s/down',
687
+ listener() {
688
+ // output current box
689
+
690
+ const code_snippet = `TransformedShape3D.from_m4(new UnitCubeShape3D(), ${JSON.stringify(cachedObject.matrix.elements)})`;
691
+ console.warn(code_snippet);
692
+
693
+ navigator.clipboard.writeText(code_snippet);
694
+ }
695
+ },
696
+ {
697
+ path: 'keyboard/keys/space/down',
698
+ listener() {
699
+ // reset scale and rotation
700
+ box_transform.scale.setScalar(1);
701
+ box_transform.rotation.set(0, 0, 0, 1);
702
+ }
703
+ }
704
+ ]))
705
+ .add(BehaviorComponent.looping_function(() => {
706
+
707
+ threeUpdateTransform(controls);
708
+
709
+ if (controls.dragging) {
710
+ if (camera_controls.isBuilt) {
711
+ camera_controls.destroy();
712
+ }
713
+ } else {
714
+ if (!camera_controls.isBuilt) {
715
+ camera_controls.build(ecd);
716
+ }
717
+ }
718
+
719
+ cachedObject.updateMatrix();
720
+ const matrix = cachedObject.matrix;
721
+ const t = eb.getComponent(Transform);
722
+
723
+ t.position.onChanged.mute();
724
+ t.rotation.onChanged.mute();
725
+ t.scale.onChanged.mute();
726
+
727
+ t.fromMatrix4(matrix.elements);
728
+
729
+ t.position.onChanged.unmute();
730
+ t.rotation.onChanged.unmute();
731
+ t.scale.onChanged.unmute();
732
+
733
+ sg.updateTransform();
734
+
735
+ }))
736
+ .build(ecd);
737
+ }
738
+
739
+ /**
740
+ *
741
+ * @param {EntityComponentDataset} ecd
742
+ * @param {AbstractShape3D} shape
743
+ * @param {number} density
744
+ * @param {number} particle_size
745
+ * @param {boolean} sort
746
+ * @returns {ParticleVolume}
747
+ */
748
+ function create_volume({
749
+ ecd,
750
+ shape = new UnitCubeShape3D(),
751
+ density = 10,
752
+ particle_size = 1,
753
+ sort = false,
754
+ sprite
755
+ }) {
756
+
757
+ const adjusted_density = density / particle_size;
758
+
759
+ const v = new ParticleVolume();
413
760
 
414
761
  v.from({
415
762
  density: adjusted_density,
416
- particle_size
763
+ particle_size,
764
+ shape: shape,
765
+ sort,
766
+ sprite
417
767
  });
418
768
 
419
769
  v.build();
420
770
 
421
- v.entity.build(em.dataset);
771
+ v.entity.build(ecd);
422
772
 
423
773
  return v;
424
774
  }
425
775
 
426
776
  /**
427
777
  *
428
- * @param {AABB3} bounds
778
+ * @param {Vector3} position
429
779
  * @param {ParameterLookupTable} lut
430
780
  * @return {{position: Vector1}}
431
781
  */
432
782
  function make_symbol_view({
433
- bounds,
783
+ position,
434
784
  lut
435
785
  }) {
436
786
 
@@ -494,7 +844,7 @@ function make_symbol_view({
494
844
  symbol_view.addChild(view_cursor);
495
845
 
496
846
  const symbol_transform = new Transform();
497
- bounds.getCenter(symbol_transform.position);
847
+ symbol_transform.position.copy(position);
498
848
 
499
849
  const vp = new ViewportPosition();
500
850
  vp.anchor.set(0.5, 1);
@@ -512,29 +862,59 @@ function make_symbol_view({
512
862
 
513
863
  async function make_demo_volume({
514
864
  ecd,
515
- bounds = new AABB3(0, 0, 0, 20, 10, 20),
865
+ shape,
516
866
  lut,
517
867
  period = 5,
518
868
  period_offset = 0,
519
869
  density,
520
- particle_size
870
+ particle_size,
871
+ sort = false,
872
+ sprite
521
873
  }) {
522
874
 
523
- const v = await create_volume({
524
- bounds,
875
+ // estimate bounds
876
+ const bounds = new AABB3();
877
+ bounds.setNegativelyInfiniteBounds();
878
+
879
+ const sample = [];
880
+ const samples_x = [];
881
+ const samples_y = [];
882
+ const samples_z = [];
883
+
884
+ const random = seededRandom(0xBEEF);
885
+
886
+ for (let i = 0; i < 1024; i++) {
887
+ shape.sample_random_point_in_volume(sample, 0, random);
888
+
889
+ samples_x.push(sample[0]);
890
+ samples_y.push(sample[1]);
891
+ samples_z.push(sample[2]);
892
+ }
893
+
894
+ const v = create_volume({
895
+ ecd,
896
+ shape,
525
897
  density,
526
- particle_size
898
+ particle_size,
899
+ sort,
900
+ sprite
527
901
  });
528
902
 
529
903
  let time_total = 0;
530
904
 
531
905
  const symbol = make_symbol_view({
532
- bounds,
906
+ position: new Vector3(
907
+ computeStatisticalMean(samples_x),
908
+ computeStatisticalMean(samples_y),
909
+ computeStatisticalMean(samples_z),
910
+ ),
533
911
  lut
534
912
  });
535
913
 
536
914
  symbol.entity.build(ecd);
537
915
 
916
+ v.attributes.color.lookup = lut;
917
+
538
918
  new EntityBuilder()
539
919
  .add(BehaviorComponent.fromOne(RepeatBehavior.from(new ActionBehavior((time) => {
540
920
  time_total += time;
@@ -545,14 +925,14 @@ async function make_demo_volume({
545
925
 
546
926
  symbol.position.set(f);
547
927
 
548
- const s = [];
549
- lut.sample(f, s);
550
-
551
- // console.log(JSON.stringify(s));
552
-
553
- v.setColor(s[0] , s[1] , s[2] , s[3] );
928
+ v.attributes.color.write_lookup_value(f);
554
929
  }))))
555
930
  .build(ecd);
931
+
932
+ const shape_entity = shape_to_visual_entity(v.shape, ecd);
933
+ shape_entity
934
+ .getComponent(Transform)
935
+ .copy(v.transform);
556
936
  }
557
937
 
558
938
  init(engineHarness);