@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
@@ -109,6 +109,8 @@ export class Light {
109
109
 
110
110
  if (json.castShadow !== undefined) {
111
111
  this.castShadow.fromJSON(json.castShadow);
112
+ } else {
113
+ this.castShadow.set(false);
112
114
  }
113
115
 
114
116
  const actual_type = this.type.getValue();
@@ -99,7 +99,8 @@ export class ThreeLightBinding extends LightBinding {
99
99
  */
100
100
  const cache = this.__system.__three_light_cache;
101
101
 
102
- threeEnsureLightObject(this.__c_light, cache);
102
+ const c_light = this.__c_light;
103
+ threeEnsureLightObject(c_light, cache);
103
104
 
104
105
  super.link(ctx);
105
106
  }
@@ -112,6 +113,9 @@ export class ThreeLightBinding extends LightBinding {
112
113
 
113
114
  cache.release(this.__three_getLight());
114
115
 
116
+ // clear bound light
117
+ this.__c_light.__threeObject = null;
118
+
115
119
  this.__shadowmap_unlink();
116
120
 
117
121
  super.unlink(ctx);
@@ -0,0 +1,5 @@
1
+ export const DrawMode = {
2
+ Triangles: 0,
3
+ Lines: 2,
4
+ LineSegments: 3
5
+ };
@@ -1,9 +1,10 @@
1
- import { Mesh, Quaternion } from "three";
1
+ import { Line, LineSegments, Mesh } from "three";
2
2
  import { updateNodeByMatrix4AndBBB } from "../mesh/updateNodeByTransformAndBBB.js";
3
3
  import { LeafNode } from "../../../../core/bvh2/LeafNode.js";
4
4
  import { AABB3 } from "../../../../core/bvh2/aabb3/AABB3.js";
5
+ import { DrawMode } from "./DrawMode.js";
6
+ import { applyTransformToThreeObject } from "../mesh/applyTransformToThreeObject.js";
5
7
 
6
- const _q = new Quaternion();
7
8
  const _aabb3 = new AABB3();
8
9
 
9
10
  export class ShadedGeometry {
@@ -19,6 +20,12 @@ export class ShadedGeometry {
19
20
  */
20
21
  this.material = null;
21
22
 
23
+ /**
24
+ *
25
+ * @type {DrawMode|number}
26
+ */
27
+ this.mode = DrawMode.Triangles;
28
+
22
29
  /**
23
30
  *
24
31
  * @type {THREE.Object3D|null}
@@ -34,6 +41,19 @@ export class ShadedGeometry {
34
41
  this.__bvh_leaf = new LeafNode(this, 0, 0, 0, 0, 0, 0);
35
42
  }
36
43
 
44
+ __build_object() {
45
+ const mode = this.mode;
46
+ if (mode === DrawMode.Triangles) {
47
+ this.__cached_object = new Mesh(this.geometry, this.material);
48
+ } else if (mode === DrawMode.Lines) {
49
+ this.__cached_object = new Line(this.geometry, this.material);
50
+ } else if (mode === DrawMode.LineSegments) {
51
+ this.__cached_object = new LineSegments(this.geometry, this.material);
52
+ } else {
53
+ throw new Error(`Unsupported draw mode '${mode}'`);
54
+ }
55
+ }
56
+
37
57
  get bvh() {
38
58
  return this.__bvh_leaf;
39
59
  }
@@ -42,10 +62,12 @@ export class ShadedGeometry {
42
62
  *
43
63
  * @param {THREE.BufferGeometry} geometry
44
64
  * @param {THREE.Material} material
65
+ * @param draw_mode
45
66
  */
46
- from(geometry, material) {
67
+ from(geometry, material, draw_mode = DrawMode.Triangles) {
47
68
  this.geometry = geometry;
48
69
  this.material = material;
70
+ this.mode = draw_mode;
49
71
 
50
72
  // ensure that geometry has a bounding box
51
73
  if (geometry.boundingBox === null) {
@@ -53,7 +75,7 @@ export class ShadedGeometry {
53
75
  }
54
76
 
55
77
  if (this.__cached_object === null) {
56
- this.__cached_object = new Mesh(geometry, material);
78
+ this.__build_object();
57
79
  } else {
58
80
  this.__cached_object.material = material;
59
81
  this.__cached_object.geometry = geometry;
@@ -64,12 +86,13 @@ export class ShadedGeometry {
64
86
  *
65
87
  * @param geometry
66
88
  * @param material
89
+ * @param mode
67
90
  * @return {ShadedGeometry}
68
91
  */
69
- static from(geometry, material) {
92
+ static from(geometry, material, mode) {
70
93
  const r = new ShadedGeometry();
71
94
 
72
- r.from(geometry, material);
95
+ r.from(geometry, material, mode);
73
96
 
74
97
  return r;
75
98
  }
@@ -77,6 +100,7 @@ export class ShadedGeometry {
77
100
  updateTransform() {
78
101
  // update matrix
79
102
  this.__cached_object.updateMatrix();
103
+ this.__cached_object.updateMatrixWorld();
80
104
 
81
105
  // update bounds
82
106
 
@@ -116,9 +140,7 @@ export class ShadedGeometry {
116
140
  */
117
141
  setRotationByComponents(x, y, z, w) {
118
142
 
119
- _q.set(x, y, z, w);
120
-
121
- this.__cached_object.rotation.setFromQuaternion(_q);
143
+ this.__cached_object.quaternion.set(x, y, z, w);
122
144
 
123
145
  this.updateTransform();
124
146
  }
@@ -140,15 +162,7 @@ export class ShadedGeometry {
140
162
  * @param {Transform} t
141
163
  */
142
164
  applyTransform(t) {
143
- // TODO this can be optimized quite a lot
144
- const position = t.position;
145
- this.setPositionByComponents(position.x, position.y, position.z);
146
-
147
- const rotation = t.rotation;
148
- this.setRotationByComponents(rotation.x, rotation.y, rotation.z, rotation.w);
149
-
150
- const scale = t.scale;
151
- this.setScaleByComponents(scale.x, scale.y, scale.z);
165
+ applyTransformToThreeObject(this.__cached_object, t);
152
166
 
153
167
  this.updateTransform();
154
168
  }
@@ -9,6 +9,7 @@ import ThreeFactory from "../../three/ThreeFactory.js";
9
9
  import { StaticMaterialCache } from "../../../asset/loaders/material/StaticMaterialCache.js";
10
10
  import { composeCompile } from "../../material/composeCompile.js";
11
11
  import { typed_array_copy } from "../../../../core/collection/array/typed/typed_array_copy.js";
12
+ import { rewriteMaterial } from "./rewriteMaterial.js";
12
13
 
13
14
  /**
14
15
  *
@@ -94,77 +95,6 @@ InstancedMeshGroup.prototype.setGeometry = function (geometry) {
94
95
  };
95
96
 
96
97
 
97
- const SHADER_PREAMBLE = `
98
- attribute vec3 instancePosition;
99
- attribute vec4 instanceRotation;
100
- attribute vec3 instanceScale;
101
-
102
- vec3 instanceTransform( in vec3 position, vec3 T, vec4 R, vec3 S ){
103
- vec3 result = position;
104
-
105
- //applies the scale
106
- result *= S;
107
- //computes the rotation where R is a (vec4) quaternion
108
- result += 2.0 * cross( R.xyz, cross( R.xyz, result ) + R.w * result );
109
- //translates the transformed 'blueprint'
110
- result += T;
111
-
112
- return result;
113
- }
114
-
115
- mat4 getInstanceMatrix(){
116
- vec4 q = instanceRotation;
117
- vec3 s = instanceScale;
118
- vec3 v = instancePosition;
119
-
120
- vec3 q2 = q.xyz + q.xyz;
121
- vec3 a = q.xxx * q2.xyz;
122
- vec3 b = q.yyz * q2.yzz;
123
- vec3 c = q.www * q2.xyz;
124
-
125
- vec3 r0 = vec3( 1.0 - (b.x + b.z) , a.y + c.z , a.z - c.y ) * s.xxx;
126
- vec3 r1 = vec3( a.y - c.z , 1.0 - (a.x + b.z) , b.y + c.x ) * s.yyy;
127
- vec3 r2 = vec3( a.z + c.y , b.y - c.x , 1.0 - (a.x + b.x) ) * s.zzz;
128
-
129
- return mat4(
130
- r0 , 0.0,
131
- r1 , 0.0,
132
- r2 , 0.0,
133
- v , 1.0
134
- );
135
- }\n`;
136
-
137
- function rewriteMaterial(shader) {
138
- const originalVertexShader = shader.vertexShader;
139
-
140
- const newVertexShader = SHADER_PREAMBLE
141
- + originalVertexShader
142
- .replace(
143
- '#include <uv_vertex>',
144
- `
145
- mat4 instanceMatrix = getInstanceMatrix();
146
- #include <uv_vertex>
147
- `
148
- )
149
- .replace(
150
- '#include <begin_vertex>',
151
- `
152
- vec3 transformed = ( instanceMatrix * vec4(position,1.0) ).xyz;
153
- `
154
- )
155
- .replace(
156
- '#include <beginnormal_vertex>',
157
- `
158
- vec3 objectNormal = mat3( instanceMatrix ) * vec3( normal );
159
- #ifdef USE_TANGENT
160
- vec3 objectTangent = vec3( tangent.xyz );
161
- #endif
162
- `
163
- );
164
-
165
- shader.vertexShader = newVertexShader;
166
- }
167
-
168
98
  /**
169
99
  *
170
100
  * @param {THREE.Material} sourceMaterial
@@ -332,7 +262,19 @@ InstancedMeshGroup.prototype.add = function (reference) {
332
262
  * @param {*} [thisArg]
333
263
  */
334
264
  InstancedMeshGroup.prototype.traverseReferences = function (visitor, thisArg) {
335
- this.indices.forEach(visitor, thisArg);
265
+ const indices = this.indices;
266
+ const index_count = indices.length;
267
+
268
+ for (let i = 0; i < index_count; i++) {
269
+ const index = indices[i];
270
+
271
+ if (index === undefined) {
272
+ // unoccupied
273
+ continue;
274
+ }
275
+
276
+ visitor.call(thisArg, index, i);
277
+ }
336
278
  };
337
279
 
338
280
  /**
@@ -0,0 +1,70 @@
1
+ const SHADER_PREAMBLE = `
2
+ attribute vec3 instancePosition;
3
+ attribute vec4 instanceRotation;
4
+ attribute vec3 instanceScale;
5
+
6
+ vec3 instanceTransform( in vec3 position, vec3 T, vec4 R, vec3 S ){
7
+ vec3 result = position;
8
+
9
+ //applies the scale
10
+ result *= S;
11
+ //computes the rotation where R is a (vec4) quaternion
12
+ result += 2.0 * cross( R.xyz, cross( R.xyz, result ) + R.w * result );
13
+ //translates the transformed 'blueprint'
14
+ result += T;
15
+
16
+ return result;
17
+ }
18
+
19
+ mat4 getInstanceMatrix(){
20
+ vec4 q = instanceRotation;
21
+ vec3 s = instanceScale;
22
+ vec3 v = instancePosition;
23
+
24
+ vec3 q2 = q.xyz + q.xyz;
25
+ vec3 a = q.xxx * q2.xyz;
26
+ vec3 b = q.yyz * q2.yzz;
27
+ vec3 c = q.www * q2.xyz;
28
+
29
+ vec3 r0 = vec3( 1.0 - (b.x + b.z) , a.y + c.z , a.z - c.y ) * s.xxx;
30
+ vec3 r1 = vec3( a.y - c.z , 1.0 - (a.x + b.z) , b.y + c.x ) * s.yyy;
31
+ vec3 r2 = vec3( a.z + c.y , b.y - c.x , 1.0 - (a.x + b.x) ) * s.zzz;
32
+
33
+ return mat4(
34
+ r0 , 0.0,
35
+ r1 , 0.0,
36
+ r2 , 0.0,
37
+ v , 1.0
38
+ );
39
+ }\n`;
40
+
41
+ export function rewriteMaterial(shader) {
42
+ const originalVertexShader = shader.vertexShader;
43
+
44
+ const newVertexShader = SHADER_PREAMBLE
45
+ + originalVertexShader
46
+ .replace(
47
+ '#include <uv_vertex>',
48
+ `
49
+ mat4 instanceMatrix = getInstanceMatrix();
50
+ #include <uv_vertex>
51
+ `
52
+ )
53
+ .replace(
54
+ '#include <begin_vertex>',
55
+ `
56
+ vec3 transformed = ( instanceMatrix * vec4(position,1.0) ).xyz;
57
+ `
58
+ )
59
+ .replace(
60
+ '#include <beginnormal_vertex>',
61
+ `
62
+ vec3 objectNormal = mat3( instanceMatrix ) * vec3( normal );
63
+ #ifdef USE_TANGENT
64
+ vec3 objectTangent = vec3( tangent.xyz );
65
+ #endif
66
+ `
67
+ );
68
+
69
+ shader.vertexShader = newVertexShader;
70
+ }
@@ -14,7 +14,8 @@ export class MaterialManager {
14
14
  */
15
15
  this.__library = new HashMap({
16
16
  keyHashFunction: computeMaterialHash,
17
- keyEqualityFunction: computeMaterialEquality
17
+ keyEqualityFunction: computeMaterialEquality,
18
+ capacity: 1024
18
19
  });
19
20
 
20
21
  /**
@@ -237,8 +237,8 @@ export class AttributeDataTexture {
237
237
  /**
238
238
  *
239
239
  * @param {number} slot
240
- * @param {number[]} indices
241
- * @param {number[]} source
240
+ * @param {number[]} indices triangle indices (index buffer)
241
+ * @param {number[]} source vertex data
242
242
  */
243
243
  write_slot_from_indexed(slot, indices, source) {
244
244
  assert.isNonNegativeInteger(slot, 'index');
@@ -289,8 +289,10 @@ export class AttributeDataTexture {
289
289
  const start_index = slot_size * index;
290
290
  const end_index = slot_size * (index + 1);
291
291
 
292
- this.__texture.image.data.fill(0, start_index, end_index);
293
- this.__texture.needsUpdate = true;
292
+ const texture = this.__texture;
293
+
294
+ texture.image.data.fill(0, start_index, end_index);
295
+ texture.needsUpdate = true;
294
296
  }
295
297
 
296
298
  /**
@@ -11,7 +11,6 @@ import Signal from "../../../../../core/events/signal/Signal.js";
11
11
  import { ATTRIBUTE_NAME_ADDRESS, ATTRIBUTE_NAME_TRANSFORM } from "./shader/constants.js";
12
12
  import { shader_rewrite_standard } from "./shader/shader_rewrite_standard.js";
13
13
 
14
-
15
14
  export class ThreeInstancedAdapter {
16
15
  /**
17
16
  *
@@ -79,7 +78,6 @@ export class ThreeInstancedAdapter {
79
78
  const position_buffer = new BufferAttribute(new Uint8Array(MICRON_PATCH_SIZE_MAX * 3 * 3), 3, false);
80
79
 
81
80
 
82
-
83
81
  position_buffer.setUsage(StaticReadUsage);
84
82
 
85
83
  geo.setAttribute('position', position_buffer);
@@ -2,6 +2,9 @@ import { ParticleEmitter } from "./particular/engine/emitter/ParticleEmitter.js"
2
2
  import { GameAssetType } from "../../asset/GameAssetType.js";
3
3
  import { assert } from "../../../core/assert.js";
4
4
 
5
+ /**
6
+ * @deprecated Use "Effect" API to achieve the same results
7
+ */
5
8
  export class ParticleEmitterLibrary {
6
9
  /**
7
10
  *
@@ -8,6 +8,7 @@ import { ParticleEmitterLibrary } from "../ParticleEmitterLibrary.js";
8
8
  import { GameAssetType } from "../../../asset/GameAssetType.js";
9
9
  import { ImageRGBADataLoader } from "../../../asset/loaders/image/ImageRGBADataLoader.js";
10
10
  import { StandardFrameBuffers } from "../../StandardFrameBuffers.js";
11
+ import { assert } from "../../../../core/assert.js";
11
12
 
12
13
  /**
13
14
  *
@@ -28,36 +29,38 @@ function putEmitterToSleep(emitter) {
28
29
  emitter.setFlag(ParticleEmitterFlag.Sleeping);
29
30
  }
30
31
 
31
- export class ParticleEmitterSystem2 extends System {
32
+ export class ParticleEmitterSystem extends System {
32
33
  /**
33
34
  *
34
35
  * @extends {System.<ParticleEmitter>}
35
36
  * @constructor
36
- * @param {AssetManager} assetManager
37
- * @param {GraphicsEngine} graphicsEngine
37
+ * @param {Engine} engine
38
38
  */
39
- constructor(assetManager, graphicsEngine) {
39
+ constructor(engine) {
40
40
  super();
41
41
 
42
+ assert.defined(engine, 'engine');
43
+ assert.equal(engine.isEngine, true, 'engine.isEngine !== true');
44
+
42
45
  this.dependencies = [ParticleEmitter, Transform];
43
46
 
44
47
  /**
45
48
  *
46
49
  * @type {GraphicsEngine}
47
50
  */
48
- this.graphicsEngine = graphicsEngine;
51
+ this.graphicsEngine = engine.graphics;
49
52
 
50
53
  /**
51
54
  *
52
55
  * @type {AssetManager}
53
56
  */
54
- this.assetManager = assetManager;
57
+ this.assetManager = engine.assetManager;
55
58
 
56
59
  /**
57
60
  *
58
61
  * @type {ParticularEngine}
59
62
  */
60
- this.particleEngine = new ParticularEngine(assetManager);
63
+ this.particleEngine = new ParticularEngine(engine.assetManager, engine.graphics.getMaterialManager());
61
64
 
62
65
  /**
63
66
  *
@@ -72,14 +75,19 @@ export class ParticleEmitterSystem2 extends System {
72
75
  this.bvh = null;
73
76
 
74
77
  /**
75
- *
78
+ * @deprecated Use "Effect" API to achieve the same results
76
79
  * @type {ParticleEmitterLibrary}
77
80
  */
78
- this.library = new ParticleEmitterLibrary(assetManager);
81
+ this.__library = new ParticleEmitterLibrary(engine.assetManager);
79
82
 
80
83
  this.__handlers = [];
81
84
  }
82
85
 
86
+ get library() {
87
+ console.warn('Deprecated, use "Effect" API to achieve the same results');
88
+ return this.__library;
89
+ }
90
+
83
91
  get componentClass() {
84
92
  return ParticleEmitter;
85
93
  }
@@ -8,8 +8,14 @@ import { SimulationStepApplyForce } from "./simulator/SimulationStepApplyForce.j
8
8
  import { SimulationStepCurlNoiseVelocity } from "./simulator/SimulationStepCurlNoiseVelocity.js";
9
9
 
10
10
 
11
- function ParticularEngine(assetManager) {
12
- this.shaderManager = new ShaderManager(assetManager);
11
+ /**
12
+ *
13
+ * @param {AssetManager} assetManager
14
+ * @param {MaterialManager} material_manager
15
+ * @constructor
16
+ */
17
+ function ParticularEngine(assetManager, material_manager) {
18
+ this.shaderManager = new ShaderManager(assetManager, material_manager);
13
19
 
14
20
  /**
15
21
  *
@@ -272,6 +272,7 @@ export class ParticleEmitter {
272
272
  softDepth: !this.getFlag(ParticleEmitterFlag.DepthSoftDisabled),
273
273
  velocityAlign: this.getFlag(ParticleEmitterFlag.AlignOnVelocity),
274
274
  depthSort: this.getFlag(ParticleEmitterFlag.DepthSorting),
275
+ receiveLight: this.getFlag(ParticleEmitterFlag.Lit),
275
276
  blendingMode: this.blendingMode,
276
277
  layers: this.layers.toJSON()
277
278
  };
@@ -330,6 +331,12 @@ export class ParticleEmitter {
330
331
  this.writeFlag(ParticleEmitterFlag.DepthSorting, true);
331
332
  }
332
333
 
334
+ if (typeof json.receiveLight === "boolean") {
335
+ this.writeFlag(ParticleEmitterFlag.Lit, json.receiveLight);
336
+ } else {
337
+ this.clearFlag(ParticleEmitterFlag.Lit);
338
+ }
339
+
333
340
  this.layers.fromJSON(json.layers, ParticleLayer);
334
341
 
335
342
  this.writeFlag(ParticleEmitterFlag.Built, false);
@@ -484,33 +491,15 @@ export class ParticleEmitter {
484
491
  //retire dead particles
485
492
  const particles = this.particles;
486
493
 
487
- const liveParticleCount = particles.size();
494
+ particles.computeAttributeVector3AxisAlignedBoundingBox(PARTICLE_ATTRIBUTE_POSITION, scratch_array);
488
495
 
489
- let bounds_x0 = Infinity;
490
- let bounds_y0 = Infinity;
491
- let bounds_z0 = Infinity;
496
+ let bounds_x0 = scratch_array[0];
497
+ let bounds_y0 = scratch_array[1];
498
+ let bounds_z0 = scratch_array[2];
492
499
 
493
- let bounds_x1 = -Infinity;
494
- let bounds_y1 = -Infinity;
495
- let bounds_z1 = -Infinity;
496
-
497
- for (let i = 0; i < liveParticleCount; i++) {
498
-
499
- particles.readAttributeVector3(i, PARTICLE_ATTRIBUTE_POSITION, position);
500
-
501
- const p_x = position[0];
502
- const p_y = position[1];
503
- const p_z = position[2];
504
-
505
- //update bounds
506
- bounds_x0 = min2(bounds_x0, p_x);
507
- bounds_y0 = min2(bounds_y0, p_y);
508
- bounds_z0 = min2(bounds_z0, p_z);
509
-
510
- bounds_x1 = max2(bounds_x1, p_x);
511
- bounds_y1 = max2(bounds_y1, p_y);
512
- bounds_z1 = max2(bounds_z1, p_z);
513
- }
500
+ let bounds_x1 = scratch_array[3];
501
+ let bounds_y1 = scratch_array[4];
502
+ let bounds_z1 = scratch_array[5];
514
503
 
515
504
  //expand bounds by maximum sprite size
516
505
  const extents = this.computeSpriteMaxHalfSize();
@@ -59,4 +59,9 @@ export const ParticleEmitterFlag = {
59
59
  * Rotation of each particle will adjusted to world velocity vector
60
60
  */
61
61
  AlignOnVelocity: 8192,
62
+
63
+ /**
64
+ * Whether or not the particle should respond to lights
65
+ */
66
+ Lit: 16384
62
67
  };
@@ -5,6 +5,8 @@ import ObservedValue from "../../../../../../core/model/ObservedValue.js";
5
5
  import { typed_array_copy } from "../../../../../../core/collection/array/typed/typed_array_copy.js";
6
6
  import { assert } from "../../../../../../core/assert.js";
7
7
  import { compute_typed_array_constructor_from_data_type } from "../../../../../../core/collection/table/DataType2TypedArrayConstructorMapping.js";
8
+ import { min2 } from "../../../../../../core/math/min2.js";
9
+ import { max2 } from "../../../../../../core/math/max2.js";
8
10
 
9
11
  const SHRINK_THRESHOLD = 64;
10
12
  const GROW_MIN_STEP = 32;
@@ -218,11 +220,11 @@ export class ParticlePool {
218
220
  const addressA = offsetA + j;
219
221
  const addressB = offsetB + j;
220
222
 
221
- const elementA = array[addressA];
223
+ const temp = array[addressA];
222
224
 
223
225
  array[addressA] = array[addressB];
224
226
 
225
- array[addressB] = elementA;
227
+ array[addressB] = temp;
226
228
  }
227
229
  }
228
230
  }
@@ -505,6 +507,92 @@ export class ParticlePool {
505
507
  array[address + 3] = w;
506
508
  }
507
509
 
510
+ /**
511
+ * Write the same attribute value for every particle.
512
+ * Assumes particles are packed (no holes).
513
+ * @param {number} attribute_index
514
+ * @param {number[]|Float32Array|Uint8Array|Uint16Array|Int8Array|Int32Array} value
515
+ */
516
+ writeAttributeForAllArray(attribute_index, value) {
517
+ const attribute = this.attributes[attribute_index];
518
+
519
+ const itemSize = attribute.itemSize;
520
+
521
+ if (value.length < itemSize) {
522
+ throw new Error(`Argument underflow, attribute.itemSize is '${itemSize}', but supplier argument's length is '${value.length}'`);
523
+ }
524
+
525
+ const n = this.size();
526
+
527
+ const destination = attribute.array;
528
+
529
+ let k;
530
+ for (let i = 0; i < n; i++) {
531
+ const offset = i * itemSize;
532
+
533
+ for (k = 0; k < itemSize; k++) {
534
+ destination[offset + k] = value[k];
535
+ }
536
+ }
537
+
538
+ // mark for update
539
+ attribute.needsUpdate = true;
540
+ attribute.updateRange.count = n;
541
+ attribute.updateRange.offset = 0;
542
+ }
543
+
544
+ /**
545
+ *
546
+ * @param {number} attribute_index
547
+ * @param {number[]} result
548
+ */
549
+ computeAttributeVector3AxisAlignedBoundingBox(attribute_index, result) {
550
+ const attribute = this.attributes[attribute_index];
551
+ const item_size = attribute.itemSize;
552
+
553
+ if (item_size !== 3) {
554
+ throw new Error(`Attribute item_size is expected to be 3, instead was '${item_size}'`);
555
+ }
556
+
557
+ let bounds_x0 = Infinity;
558
+ let bounds_y0 = Infinity;
559
+ let bounds_z0 = Infinity;
560
+
561
+ let bounds_x1 = -Infinity;
562
+ let bounds_y1 = -Infinity;
563
+ let bounds_z1 = -Infinity;
564
+
565
+ const particle_count = this.size();
566
+
567
+ const data = attribute.array;
568
+
569
+ for (let i = 0; i < particle_count; i++) {
570
+ const particle_address = i * 3;
571
+
572
+ const x = data[particle_address];
573
+ const y = data[particle_address + 1];
574
+ const z = data[particle_address + 2];
575
+
576
+ bounds_x0 = min2(bounds_x0, x);
577
+ bounds_y0 = min2(bounds_y0, y);
578
+ bounds_z0 = min2(bounds_z0, z);
579
+
580
+ bounds_x1 = max2(bounds_x1, x);
581
+ bounds_y1 = max2(bounds_y1, y);
582
+ bounds_z1 = max2(bounds_z1, z);
583
+ }
584
+
585
+ // read out
586
+ result[0] = bounds_x0;
587
+ result[1] = bounds_y0;
588
+ result[2] = bounds_z0;
589
+
590
+ result[3] = bounds_x1;
591
+ result[4] = bounds_y1;
592
+ result[5] = bounds_z1;
593
+
594
+ }
595
+
508
596
  dispose() {
509
597
  const bufferGeometry = this.geometry.getValue();
510
598