@woosh/meep-engine 2.33.22 → 2.33.26

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 (288) hide show
  1. package/core/bvh2/BinaryNode.js +1 -1
  2. package/core/bvh2/aabb3/AABB3.js +18 -0
  3. package/core/bvh2/aabb3/AABB3Math.js +1 -1
  4. package/core/bvh2/binary/2/BinaryUint32BVH.js +498 -0
  5. package/core/bvh2/binary/2/BinaryUint32BVH.spec.js +54 -0
  6. package/core/bvh2/binary/IndexedBinaryBVH.js +22 -26
  7. package/core/bvh2/traversal/ThreeClippingPlaneComputingBVHVisitor.js +5 -1
  8. package/core/bvh2/traversal/__detailed_box_volume_intersection.js +31 -11
  9. package/core/collection/ArrayUtils.js +1 -1
  10. package/core/collection/array/arrayQuickSort.js +9 -6
  11. package/core/collection/array/array_swap.js +22 -0
  12. package/core/collection/array/binarySearchHighIndex.js +1 -1
  13. package/core/collection/array/computeHashArray.js +22 -0
  14. package/core/collection/array/computeHashIntegerArray.js +15 -0
  15. package/core/collection/array/copyArray.js +2 -2
  16. package/core/collection/table/DataType2TypedArrayConstructorMapping.js +15 -0
  17. package/core/color/Color.js +2 -1
  18. package/core/function/FunctionCompiler.js +2 -1
  19. package/core/geom/3d/aabb/aabb3_computeDistanceAbovePlane.js +9 -33
  20. package/core/geom/3d/frustum/frustum3_computeNearestPointToPoint.js +10 -2
  21. package/core/geom/3d/line/line3_computeSegmentPointDistance_sqr.js +41 -0
  22. package/core/geom/3d/morton/mortonEncode_magicbits.js +2 -1
  23. package/core/geom/3d/morton/reinterpret_float32_as_int32.js +13 -0
  24. package/core/geom/3d/morton/v3_morton_encode_transformed.js +33 -0
  25. package/core/geom/3d/normal/hemioct/unit_hemioct.spec.js +1 -1
  26. package/core/geom/3d/plane/plane_computeConvex3PlaneIntersection.js +13 -14
  27. package/core/geom/3d/ray/ray_computeNearestPointToPoint.js +37 -0
  28. package/core/geom/3d/shape/AbstractShape3D.js +65 -0
  29. package/core/geom/3d/shape/TransformedShape3D.js +181 -0
  30. package/core/geom/3d/shape/TransformedShape3D.spec.js +33 -0
  31. package/core/geom/3d/shape/UnionShape3D.js +255 -0
  32. package/core/geom/3d/shape/UnitCubeShape3D.js +101 -0
  33. package/core/geom/3d/shape/UnitCubeShape3D.spec.js +42 -0
  34. package/core/geom/3d/shape/UnitSphereShape3D.js +55 -0
  35. package/core/geom/3d/shape/util/compute_signed_distance_gradient_by_sampling.js +48 -0
  36. package/core/geom/3d/shape/util/shape_to_visual_entity.js +159 -0
  37. package/core/geom/3d/voxel/DenseBitVolume3D.js +87 -0
  38. package/core/geom/3d/voxel/buildVolumeFromProjectedGeometry.js +23 -0
  39. package/core/geom/AABB2.js +1 -1
  40. package/core/geom/ConicRay.js +3 -1
  41. package/core/geom/LineSegment.js +0 -78
  42. package/core/geom/Matrix4.js +7 -8
  43. package/core/geom/Plane.js +14 -9
  44. package/core/geom/Rectangle.js +2 -1
  45. package/core/geom/Vector1.js +1 -1
  46. package/core/geom/Vector3.js +2 -1
  47. package/core/geom/Vector4.js +2 -1
  48. package/core/geom/random/randomPointInBox.js +7 -3
  49. package/core/geom/random/randomPointInPoint.js +6 -3
  50. package/core/geom/random/randomPointInSphere.js +9 -5
  51. package/core/geom/random/randomPointOnBox.js +7 -3
  52. package/core/geom/random/randomPointOnSphere.js +6 -3
  53. package/core/geom/v3_length.js +8 -3
  54. package/core/graph/graph_k_means_cluster.js +1 -1
  55. package/core/json/resolvePathByArray.js +2 -2
  56. package/core/math/MathUtils.js +0 -354
  57. package/core/math/MathUtils.spec.js +7 -1
  58. package/core/math/gaussian.js +9 -0
  59. package/core/math/hash/computeHashFloat.js +17 -0
  60. package/core/math/hash/computeHashFloatArray.js +34 -0
  61. package/core/math/hash/computeObjectHash.js +54 -0
  62. package/core/math/intersects1D.js +19 -0
  63. package/core/math/interval/NumericInterval.js +2 -2
  64. package/core/math/isValueBetween.js +10 -0
  65. package/core/math/isValueBetweenInclusive.js +10 -0
  66. package/core/math/noise/curl_noise_3dt.js +1 -1
  67. package/core/math/noise/sdnoise.js +10 -10
  68. package/core/math/overlap1D.js +19 -0
  69. package/core/math/pingpong.js +17 -0
  70. package/core/math/random/makeRangedRandom.js +19 -0
  71. package/core/math/random/randomFloatBetween.js +14 -0
  72. package/core/math/random/randomFromArray.js +19 -0
  73. package/core/math/random/randomGaussian.js +15 -0
  74. package/core/math/random/randomIntegerBetween.js +14 -0
  75. package/core/math/random/roundFair.js +15 -0
  76. package/core/math/separation1D.js +21 -0
  77. package/core/math/solveQuadratic.js +25 -0
  78. package/core/model/BoundedValue.js +1 -1
  79. package/core/model/node-graph/node/NodeInstancePortReference.js +1 -1
  80. package/core/model/node-graph/node/Port.js +1 -1
  81. package/core/model/reactive/evaluation/MultiPredicateEvaluator.spec.js +3 -1
  82. package/core/model/reactive/model/ReactiveBinaryExpression.js +1 -1
  83. package/core/model/reactive/model/terminal/ReactiveLiteralNumber.js +1 -1
  84. package/core/model/reactive/model/terminal/ReactiveReference.js +1 -1
  85. package/core/model/reactive/model/util/createRandomReactiveExpression.js +1 -1
  86. package/core/model/stat/LinearModifier.js +1 -1
  87. package/core/primitives/array/computeIntegerArrayHash.js +1 -1
  88. package/{engine/graphics/render/forward_plus/materials → core/primitives/strings}/insert_after.js +3 -0
  89. package/core/primitives/strings/insert_after_or_replace.js +27 -0
  90. package/editor/process/symbolic/makeHelperBoxGeometry.js +44 -0
  91. package/editor/view/ecs/EntityEditor.js +2 -2
  92. package/editor/view/ecs/components/particles/ParticleEmitterController.js +2 -2
  93. package/engine/EngineHarness.js +1 -0
  94. package/engine/animation/AnimationUtils.js +5 -5
  95. package/engine/animation/curve/AnimationCurve.js +72 -0
  96. package/engine/animation/curve/Keyframe.js +27 -0
  97. package/engine/animation/keyed2/AnimationTrack.js +27 -3
  98. package/engine/asset/Asset.js +1 -1
  99. package/engine/asset/loaders/GLTFAssetLoader.d.ts +1 -1
  100. package/engine/asset/loaders/GLTFAssetLoader.js +10 -0
  101. package/engine/asset/loaders/image/ImageRGBADataAsset.js +8 -1
  102. package/engine/asset/loaders/material/computeImageBitmapEquality.js +11 -0
  103. package/engine/asset/loaders/material/computeImageBitmapHash.js +22 -28
  104. package/engine/asset/loaders/material/computeMaterialHash.js +3 -1
  105. package/engine/asset/loaders/material/computeTextureHash.js +2 -1
  106. package/engine/ecs/EntityBuilder.js +25 -5
  107. package/engine/ecs/animation/Animation.js +2 -1
  108. package/engine/ecs/animation/InverseKinematics.js +2 -1
  109. package/engine/ecs/attachment/AttachmentBinding.js +8 -0
  110. package/engine/ecs/attachment/AttachmentSystem.js +4 -0
  111. package/engine/ecs/attachment/TransformAttachmentBinding.js +14 -44
  112. package/engine/ecs/components/Tag.js +27 -6
  113. package/engine/ecs/dynamic_actions/DynamicActorSystem.js +2 -1
  114. package/engine/ecs/dynamic_actions/DynamicRuleDescriptionTable.spec.js +3 -5
  115. package/engine/ecs/dynamic_actions/actions/definition/WeightedRandomActionDescription.js +1 -1
  116. package/engine/ecs/evaluation/complex/PointFitnessGaussianBlur.js +1 -1
  117. package/engine/ecs/foliage/ecs/Foliage2.js +1 -1
  118. package/engine/ecs/fow/FogOfWar.js +4 -0
  119. package/engine/ecs/fow/FogOfWarSystem.js +2 -0
  120. package/engine/ecs/fow/shader/FogOfWarRenderer.js +1 -1
  121. package/engine/ecs/gui/GUIElement.js +1 -1
  122. package/engine/ecs/gui/hud/HeadsUpDisplay.js +1 -1
  123. package/engine/ecs/gui/hud/HeadsUpDisplaySystem.js +2 -0
  124. package/engine/ecs/gui/position/ViewportPosition.js +2 -1
  125. package/engine/ecs/system/AbstractContextSystem.js +1 -1
  126. package/engine/ecs/systems/RangedAttackSystem.js +1 -1
  127. package/engine/ecs/systems/SteeringSystem.js +1 -1
  128. package/engine/ecs/systems/TagSystem.js +17 -0
  129. package/engine/ecs/terrain/tiles/TerrainTileManager.js +1 -1
  130. package/engine/ecs/tooltip/TooltipComponent.js +15 -0
  131. package/engine/ecs/transform/Transform.js +19 -6
  132. package/engine/ecs/util/hideEntityGracefully.js +18 -0
  133. package/engine/graphics/GraphicsEngine.js +11 -23
  134. package/engine/graphics/camera/testClippingPlaneComputation.js +2 -2
  135. package/engine/graphics/composit/CompositLayer.js +17 -4
  136. package/engine/graphics/composit/CompositingStages.js +8 -0
  137. package/engine/graphics/composit/LayerCompositer.js +35 -6
  138. package/engine/graphics/ecs/animation/animator/AnimationClip.js +2 -1
  139. package/engine/graphics/ecs/animation/animator/AnimationClipDefinition.js +2 -1
  140. package/engine/graphics/ecs/animation/animator/AnimationNotification.js +2 -1
  141. package/engine/graphics/ecs/animation/animator/AnimationNotificationDefinition.js +2 -1
  142. package/engine/graphics/ecs/animation/animator/graph/AnimationGraph.js +2 -1
  143. package/engine/graphics/ecs/animation/animator/graph/definition/AnimationGraphDefinition.js +2 -1
  144. package/engine/graphics/ecs/animation/animator/graph/definition/AnimationStateDefinition.js +1 -1
  145. package/engine/graphics/ecs/animation/animator/graph/definition/AnimationTransitionDefinition.js +2 -1
  146. package/engine/graphics/ecs/camera/CameraClippingPlaneComputer.js +1 -1
  147. package/engine/graphics/ecs/highlight/HighlightDefinition.js +2 -1
  148. package/engine/graphics/ecs/highlight/plugin/OutlineRenderPlugin.js +11 -7
  149. package/engine/graphics/ecs/light/Light.d.ts +1 -1
  150. package/engine/graphics/ecs/light/Light.js +5 -0
  151. package/engine/graphics/ecs/light/binding/three/ThreeLightBinding.js +5 -1
  152. package/engine/graphics/ecs/mesh/Mesh.js +2 -1
  153. package/engine/graphics/ecs/mesh-v2/DrawMode.js +5 -0
  154. package/engine/graphics/ecs/mesh-v2/ShadedGeometry.d.ts +13 -0
  155. package/engine/graphics/ecs/mesh-v2/ShadedGeometry.js +32 -18
  156. package/engine/graphics/ecs/mesh-v2/ShadedGeometrySystem.d.ts +6 -0
  157. package/engine/graphics/ecs/path/testPathDisplaySystem.js +98 -98
  158. package/engine/graphics/ecs/trail2d/Trail2D.js +17 -4
  159. package/engine/graphics/ecs/trail2d/Trail2DSystem.d.ts +2 -3
  160. package/engine/graphics/ecs/trail2d/Trail2DSystem.js +34 -118
  161. package/engine/graphics/geometry/AttributeSpec.js +105 -0
  162. package/engine/graphics/{micron/format/MicronVertexDataSpec.js → geometry/VertexDataSpec.js} +56 -25
  163. package/engine/graphics/micron/build/buildMicronGeometryFromBufferGeometry.js +7 -7
  164. package/engine/graphics/micron/build/fill_patch_geometry_data.js +1 -1
  165. package/engine/graphics/micron/buildPatchwork.js +1 -1
  166. package/engine/graphics/micron/format/MicronGeometry.js +3 -3
  167. package/engine/graphics/micron/format/serialization/MicronGeometryBinarySerializationAdapter.js +2 -2
  168. package/engine/graphics/micron/format/serialization/deserialize_attribute_spec.js +1 -1
  169. package/engine/graphics/micron/format/serialization/serialize_attribute_spec.js +1 -1
  170. package/engine/graphics/micron/render/PatchCacheKey.js +1 -1
  171. package/engine/graphics/micron/render/instanced/AttributeDataTexture.js +5 -5
  172. package/engine/graphics/micron/render/v1/ThreeVirtualGeometryAdapter.js +1 -1
  173. package/engine/graphics/particles/ParticleEmitterLibrary.js +3 -0
  174. package/engine/graphics/particles/ecs/{ParticleEmitterSystem2.js → ParticleEmitterSystem.js} +17 -9
  175. package/engine/graphics/particles/particular/engine/ParticularEngine.js +12 -4
  176. package/engine/graphics/particles/particular/engine/emitter/PARTICULAR_PARTICLE_SPECIFICATION.js +84 -0
  177. package/engine/graphics/particles/particular/engine/emitter/ParticleEmitter.js +106 -169
  178. package/engine/graphics/particles/particular/engine/emitter/ParticleEmitterFlag.js +5 -0
  179. package/engine/graphics/particles/particular/engine/emitter/ParticleLayer.js +14 -3
  180. package/engine/graphics/particles/particular/engine/emitter/ParticlePool.js +141 -14
  181. package/engine/graphics/particles/particular/engine/emitter/ParticlePool.spec.js +8 -7
  182. package/engine/graphics/particles/particular/engine/emitter/computeEmissionFunction.js +37 -0
  183. package/engine/graphics/particles/particular/engine/emitter/distance_to_camera.js +25 -0
  184. package/engine/graphics/particles/particular/engine/emitter/serde/ParameterLookupTableSerializationAdapter.js +8 -2
  185. package/engine/graphics/particles/particular/engine/parameter/ParameterLookupTable.js +2 -1
  186. package/engine/graphics/particles/particular/engine/parameter/ParameterTrack.js +1 -1
  187. package/engine/graphics/particles/particular/engine/parameter/ParticleParameter.js +1 -1
  188. package/engine/graphics/particles/particular/engine/renderers/billboard/BILLBOARD_PARTICLE_SPECIFICATION.js +24 -0
  189. package/engine/graphics/particles/particular/engine/renderers/billboard/ParticleBillboardMaterial.js +262 -71
  190. package/engine/graphics/particles/particular/engine/renderers/billboard/prototypeBillboardRenderer.js +9 -9
  191. package/engine/graphics/particles/particular/engine/shader/ShaderManager.js +80 -46
  192. package/engine/graphics/particles/particular/engine/shader/debugAtlas.js +14 -0
  193. package/engine/graphics/particles/particular/engine/simulator/SimulationStepApplyForce.js +2 -5
  194. package/engine/graphics/particles/particular/engine/simulator/SimulationStepCurlNoiseAcceleration.js +2 -6
  195. package/engine/graphics/particles/particular/engine/simulator/SimulationStepCurlNoiseVelocity.js +2 -7
  196. package/engine/graphics/particles/particular/engine/simulator/SimulationStepFixedPhysics.js +2 -5
  197. package/engine/graphics/particles/particular/engine/simulator/update_parameters.js +1 -1
  198. package/engine/graphics/particles/particular/engine/utils/distributeParticlesOnObject3D.js +1 -1
  199. package/engine/graphics/particles/particular/engine/utils/distrubuteParticlesOnMesh.js +1 -1
  200. package/engine/graphics/particles/particular/engine/utils/volume/AttributeValue.js +141 -0
  201. package/engine/graphics/particles/particular/engine/utils/volume/ParticleVolume.js +478 -0
  202. package/engine/graphics/particles/particular/engine/utils/volume/lut_to_sampler.js +27 -0
  203. package/engine/graphics/particles/particular/engine/utils/volume/prototypeParticleVolume.js +935 -0
  204. package/engine/graphics/particles/particular/group/Operation.js +18 -0
  205. package/engine/graphics/particles/particular/group/OperationType.js +9 -0
  206. package/engine/graphics/particles/particular/group/ParticleAttribute.js +2 -1
  207. package/engine/graphics/particles/particular/group/ParticleAttributeType.js +11 -0
  208. package/engine/graphics/particles/particular/group/ParticleDataType.js +10 -0
  209. package/engine/graphics/particles/particular/group/ParticleGroup.js +7 -245
  210. package/engine/graphics/particles/particular/group/ParticleGroup.spec.js +3 -1
  211. package/engine/graphics/particles/particular/group/ParticleSpecification.js +21 -14
  212. package/engine/graphics/particles/particular/group/itemSizeFromAttributeType.js +20 -0
  213. package/engine/graphics/particles/particular/group/optimizeCommandQueue.js +162 -0
  214. package/engine/graphics/particles/particular/group/typedArrayConstructorFromDataType.js +19 -0
  215. package/engine/graphics/render/buffer/buffers/prototypeNormalFrameBuffer.js +2 -2
  216. package/engine/graphics/render/buffer/simple-fx/ao/AmbientOcclusionPostProcessEffect.js +13 -7
  217. package/engine/graphics/render/buffer/slot/parameter/ProgramValueSlotParameter.js +2 -1
  218. package/engine/graphics/render/buffer/slot/parameter/ProgramValueSlotParameterSet.js +1 -1
  219. package/engine/graphics/render/forward_plus/LightManager.js +126 -95
  220. package/engine/graphics/render/forward_plus/PointLight.js +9 -0
  221. package/engine/graphics/render/forward_plus/PointLightData.js +1 -1
  222. package/engine/graphics/render/forward_plus/SpotLight.js +9 -0
  223. package/engine/graphics/render/forward_plus/cluster/compute_light_data_hash_0.js +2 -2
  224. package/engine/graphics/render/forward_plus/computeFrustumCorners.js +14 -32
  225. package/engine/graphics/render/forward_plus/materials/FP_INJECTION_POINT_ACCUMULATION.js +1 -0
  226. package/engine/graphics/render/forward_plus/materials/FP_SHADER_CHUNK_ACCUMULATION.js +32 -0
  227. package/engine/graphics/render/forward_plus/materials/FP_SHADER_CHUNK_DECODE_PARS.js +51 -0
  228. package/engine/graphics/render/forward_plus/materials/FP_SHADER_CHUNK_PREAMBLE.js +25 -0
  229. package/engine/graphics/render/forward_plus/materials/fp_build_fragment_shader.js +31 -120
  230. package/engine/graphics/render/forward_plus/materials/fp_build_vertex_lighting_shared.js +35 -0
  231. package/engine/graphics/render/forward_plus/materials/fp_build_vertex_shader.js +4 -5
  232. package/engine/graphics/render/forward_plus/plugin/ForwardPlusRenderingPlugin.js +1 -1
  233. package/engine/graphics/render/forward_plus/plugin/MaterialTransformer.js +10 -3
  234. package/engine/graphics/render/forward_plus/plugin/ptototypeFPPlugin.js +595 -60
  235. package/engine/graphics/render/forward_plus/prototypeLightManager.js +256 -136
  236. package/engine/graphics/render/forward_plus/query/analytical_triplanar_corner_mapping.js +8 -0
  237. package/engine/graphics/render/forward_plus/query/cube_mapping.js +38 -0
  238. package/engine/graphics/render/forward_plus/query/detailed_sphere_frustum_intersection_test.js +86 -0
  239. package/engine/graphics/render/forward_plus/query/point_light_inside_volume.js +73 -0
  240. package/engine/graphics/render/forward_plus/query/query_bvh_frustum_from_objects.js +131 -0
  241. package/engine/graphics/render/forward_plus/query/query_bvh_frustum_from_texture.js +129 -0
  242. package/engine/graphics/render/forward_plus/query/spot_light_inside_volume.js +33 -0
  243. package/engine/graphics/render/forward_plus/read_frustum_corner.js +14 -0
  244. package/engine/graphics/render/forward_plus/testClusterEquality.js +22 -0
  245. package/engine/graphics/render/layers/RenderLayerUtils.js +7 -4
  246. package/engine/graphics/render/visibility/IncrementalDeltaSet.js +11 -0
  247. package/engine/graphics/render/visibility/hiz/prototypeHiZ.js +2 -2
  248. package/engine/graphics/shaders/TerrainShader.js +4 -5
  249. package/engine/graphics/shadows/ShadowMapRenderer.js +8 -2
  250. package/engine/graphics/texture/atlas/AtlasPatch.js +7 -2
  251. package/engine/graphics/texture/atlas/TextureAtlas.js +2 -2
  252. package/engine/graphics/texture/sampler/HarmonicDiffusionGrid.spec.js +1 -1
  253. package/engine/graphics/texture/sampler/SampleTraverser.js +1 -1
  254. package/engine/graphics/texture/sampler/Sampler2D.js +8 -7
  255. package/engine/graphics/texture/sampler/distanceField.spec.js +1 -1
  256. package/engine/graphics/texture/sampler/scaleSampler2D.js +7 -10
  257. package/engine/graphics/trail/x/RibbonMaterialX.js +3 -3
  258. package/engine/graphics/trail/x/RibbonX.js +17 -2
  259. package/engine/graphics/trail/x/RibbonXPlugin.js +51 -1
  260. package/engine/graphics/util/composeMatrix4.js +33 -23
  261. package/engine/graphics/util/decompose_matrix_4_array.js +61 -0
  262. package/engine/grid/components/GridObstacle.js +3 -10
  263. package/engine/intelligence/behavior/ecs/BehaviorComponent.js +30 -14
  264. package/engine/intelligence/behavior/selector/WeightedElement.js +2 -1
  265. package/engine/intelligence/optimization/RandomOptimizer.js +1 -1
  266. package/engine/knowledge/database/StaticKnowledgeDataTable.js +6 -1
  267. package/engine/navigation/ecs/components/Path.js +1 -6
  268. package/engine/navigation/grid/FastBinaryHeap.spec.js +1 -1
  269. package/engine/reference/v2/Reference.js +6 -0
  270. package/engine/sound/ecs/emitter/SoundEmitter.js +2 -1
  271. package/engine/sound/ecs/emitter/SoundTrack.js +2 -1
  272. package/engine/sound/material/concrete/RandomSoundMaterial.js +1 -1
  273. package/engine/ui/notification/notificationGenerator.js +1 -1
  274. package/generation/filtering/numeric/complex/CellFilterGaussianBlur.js +1 -1
  275. package/generation/grid/generation/GridTaskExecuteRuleTimes.js +2 -1
  276. package/generation/markers/actions/MarkerNodeActionSelectRandom.js +1 -1
  277. package/generation/markers/transform/MarkerNodeTransformerRecordUniqueRandomEnum.js +1 -1
  278. package/generation/placement/action/random/CellActionSelectRandom.js +1 -1
  279. package/generation/theme/ThemeEngine.js +2 -2
  280. package/misc/makeMaterialIconCached.js +2 -2
  281. package/package.json +3 -3
  282. package/view/View.js +4 -2
  283. package/view/elements/image/HTMLElementCacheKey.js +2 -1
  284. package/view/elements/radial/RadialText.js +2 -1
  285. package/view/minimap/gl/MinimapMarkersGL.js +6 -100
  286. package/view/minimap/gl/buildMaterial.js +94 -0
  287. package/engine/graphics/micron/format/MicronGeometryBufferAttributeSpec.js +0 -71
  288. package/engine/graphics/render/forward_plus/queryBVH_Frustum.js +0 -345
@@ -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
  *
@@ -63,10 +69,12 @@ ParticularEngine.prototype.add = function (emitter) {
63
69
  * @param {ParticleEmitter} emitter
64
70
  */
65
71
  ParticularEngine.prototype.remove = function (emitter) {
66
- const i = this.emitters.indexOf(emitter);
72
+ const emitters = this.emitters;
73
+
74
+ const i = emitters.indexOf(emitter);
67
75
 
68
76
  if (i !== -1) {
69
- this.emitters.remove(i);
77
+ emitters.remove(i);
70
78
  }
71
79
 
72
80
  this.shaderManager.deregister(emitter);
@@ -0,0 +1,84 @@
1
+ import { VertexDataSpec } from "../../../../geometry/VertexDataSpec.js";
2
+ import { AttributeSpec } from "../../../../geometry/AttributeSpec.js";
3
+ import { DataType } from "../../../../../../core/collection/table/DataType.js";
4
+
5
+ //build particle spec
6
+ export const PARTICULAR_PARTICLE_SPECIFICATION = new VertexDataSpec();
7
+
8
+ PARTICULAR_PARTICLE_SPECIFICATION.add(AttributeSpec.fromJSON({
9
+ name: 'position',
10
+ itemSize: 3,
11
+ type: DataType.Float32,
12
+ normalized: false
13
+ }));
14
+ PARTICULAR_PARTICLE_SPECIFICATION.add(AttributeSpec.fromJSON({
15
+ name: 'age',
16
+ itemSize: 1,
17
+ type: DataType.Float32,
18
+ normalized: false
19
+ }));
20
+ PARTICULAR_PARTICLE_SPECIFICATION.add(AttributeSpec.fromJSON({
21
+ name: 'deathAge',
22
+ itemSize: 1,
23
+ type: DataType.Float32,
24
+ normalized: false
25
+ }));
26
+
27
+ PARTICULAR_PARTICLE_SPECIFICATION.add(AttributeSpec.fromJSON({
28
+ name: 'atlasPatch',
29
+ itemSize: 4,
30
+ type: DataType.Uint16,
31
+ normalized: true
32
+ }));
33
+
34
+ // TODO convert "size" to scale instead
35
+ PARTICULAR_PARTICLE_SPECIFICATION.add(AttributeSpec.fromJSON({
36
+ name: 'size',
37
+ itemSize: 1,
38
+ type: DataType.Float32,
39
+ normalized: false
40
+ }));
41
+
42
+ PARTICULAR_PARTICLE_SPECIFICATION.add(AttributeSpec.fromJSON({
43
+ name: 'layerPosition',
44
+ itemSize: 1,
45
+ type: DataType.Uint8,
46
+ normalized: false
47
+ }));
48
+
49
+ PARTICULAR_PARTICLE_SPECIFICATION.add(AttributeSpec.fromJSON({
50
+ name: 'velocity',
51
+ itemSize: 3,
52
+ type: DataType.Float32,
53
+ normalized: false
54
+ }));
55
+ PARTICULAR_PARTICLE_SPECIFICATION.add(AttributeSpec.fromJSON({
56
+ name: 'rotation',
57
+ itemSize: 1,
58
+ type: DataType.Float32,
59
+ normalized: false
60
+ }));
61
+ PARTICULAR_PARTICLE_SPECIFICATION.add(AttributeSpec.fromJSON({
62
+ name: 'rotationSpeed',
63
+ itemSize: 1,
64
+ type: DataType.Float32,
65
+ normalized: false
66
+ }));
67
+ PARTICULAR_PARTICLE_SPECIFICATION.add(AttributeSpec.fromJSON({
68
+ name: 'color',
69
+ itemSize: 4,
70
+ type: DataType.Uint8,
71
+ normalized: true
72
+ }));
73
+ PARTICULAR_PARTICLE_SPECIFICATION.add(AttributeSpec.fromJSON({
74
+ name: 'blending',
75
+ itemSize: 1,
76
+ type: DataType.Float32,
77
+ normalized: false
78
+ }));
79
+ PARTICULAR_PARTICLE_SPECIFICATION.add(AttributeSpec.fromJSON({
80
+ name: 'size_initial',
81
+ itemSize: 1,
82
+ type: DataType.Float32,
83
+ normalized: false
84
+ }));
@@ -3,7 +3,6 @@ import List from "../../../../../../core/collection/list/List.js";
3
3
  import { lerp } from "../../../../../../core/math/lerp.js";
4
4
  import { max2 } from "../../../../../../core/math/max2.js";
5
5
  import { min2 } from "../../../../../../core/math/min2.js";
6
- import { ParticleAttributeType, ParticleDataType } from "../../group/ParticleGroup.js";
7
6
  import { Box3, BufferGeometry, Frustum, Matrix4, Points, PointsMaterial } from 'three';
8
7
  import { frustumFromCamera } from "../../../../ecs/camera/CameraSystem.js";
9
8
  import { ParticlePool } from "./ParticlePool.js";
@@ -15,9 +14,6 @@ import { ParticleLayer } from "./ParticleLayer.js";
15
14
  import { ParticleParameters } from "./ParticleParameters.js";
16
15
  import { BlendingType } from "../../../../texture/sampler/BlendingType.js";
17
16
  import Quaternion from "../../../../../../core/geom/Quaternion.js";
18
- import { computeHashIntegerArray } from "../../../../../../core/math/MathUtils.js";
19
- import { ParticleSpecification } from "../../group/ParticleSpecification.js";
20
- import { ParticleAttribute } from "../../group/ParticleAttribute.js";
21
17
  import { ParticleEmitterFlag } from "./ParticleEmitterFlag.js";
22
18
  import { AABB3 } from "../../../../../../core/bvh2/aabb3/AABB3.js";
23
19
  import {
@@ -34,14 +30,11 @@ import {
34
30
  PARTICLE_ATTRIBUTE_VELOCITY
35
31
  } from "./PARTICLE_ATTRIBUTES.js";
36
32
  import { composeMatrix4 } from "../../../../util/composeMatrix4.js";
37
- import { randomPointInPoint } from "../../../../../../core/geom/random/randomPointInPoint.js";
38
- import { randomPointInSphere } from "../../../../../../core/geom/random/randomPointInSphere.js";
39
- import { randomPointOnSphere } from "../../../../../../core/geom/random/randomPointOnSphere.js";
40
- import { randomPointInBox } from "../../../../../../core/geom/random/randomPointInBox.js";
41
- import { randomPointOnBox } from "../../../../../../core/geom/random/randomPointOnBox.js";
42
- import { EmissionFromType } from "./EmissionFromType.js";
43
- import { EmissionShapeType } from "./EmissionShapeType.js";
44
33
  import { update_parameters } from "../simulator/update_parameters.js";
34
+ import { distance_to_camera } from "./distance_to_camera.js";
35
+ import { computeEmissionFunction } from "./computeEmissionFunction.js";
36
+ import { PARTICULAR_PARTICLE_SPECIFICATION } from "./PARTICULAR_PARTICLE_SPECIFICATION.js";
37
+ import { computeHashIntegerArray } from "../../../../../../core/collection/array/computeHashIntegerArray.js";
45
38
 
46
39
  const EMPTY_GEOMETRY = new BufferGeometry();
47
40
 
@@ -68,57 +61,9 @@ const scratch_array = [];
68
61
 
69
62
  /**
70
63
  *
71
- * @param {EmissionFromType} emissionType
72
- * @param {EmissionShapeType} emissionShape
73
- * @returns {function(random: function, result:Vector3):void}
74
- */
75
- function computeEmissionFunction(emissionType, emissionShape) {
76
- if (emissionShape === EmissionShapeType.Point) {
77
- return randomPointInPoint;
78
- } else if (emissionShape === EmissionShapeType.Sphere) {
79
- if (emissionType === EmissionFromType.Volume) {
80
- return randomPointInSphere;
81
- } else if (emissionType === EmissionFromType.Shell) {
82
- return randomPointOnSphere;
83
- } else {
84
- throw new TypeError(`Unsupported EmissionFrom Type`);
85
- }
86
- } else if (emissionShape === EmissionShapeType.Box) {
87
- if (emissionType === EmissionFromType.Volume) {
88
- return randomPointInBox;
89
- } else if (emissionType === EmissionFromType.Shell) {
90
- return randomPointOnBox;
91
- } else {
92
- throw new TypeError(`Unsupported EmissionFrom Type`);
93
- }
94
- }
95
- }
96
-
97
- /**
98
- *
99
- * @param {number} index
100
- * @param {number[]|Float32Array} positionArray
101
- * @param {Vector3} planeNormal
102
- * @return {number}
64
+ * @type {number[]}
103
65
  */
104
- function distanceToCamera(index, positionArray, planeNormal) {
105
- const address = index * 3;
106
-
107
- // extract position components of the particle
108
- const x = positionArray[address];
109
- const y = positionArray[address + 1];
110
- const z = positionArray[address + 2];
111
-
112
- const planeNormalX = planeNormal.x;
113
- const planeNormalY = planeNormal.y;
114
- const planeNormalZ = planeNormal.z;
115
-
116
- // compute dot product
117
- const dot = x * planeNormalX + y * planeNormalY + z * planeNormalZ;
118
-
119
- // use dot product instead of the actual distance to save computation. Difference is going to be constant
120
- return dot;
121
- }
66
+ const scratch_v3_array = [];
122
67
 
123
68
  /**
124
69
  *
@@ -135,6 +80,35 @@ function generateStandardParameterSet(parameters) {
135
80
  parameters.add(pColor);
136
81
  }
137
82
 
83
+
84
+ const uint16_mul = 65536;
85
+
86
+ /**
87
+ *
88
+ * @param {AtlasPatch} atlasPatch
89
+ * @param {ParticlePool} particles
90
+ * @param {number} ref
91
+ */
92
+ function write_particle_patch_uv(atlasPatch, particles, ref) {
93
+ const uv = atlasPatch.uv;
94
+
95
+ const uv_position = uv.position;
96
+
97
+ const u0 = uv_position.x;
98
+ const v0 = uv_position.y;
99
+
100
+ const uv_size = uv.size;
101
+
102
+ const u1 = uv_size.x;
103
+ const v1 = uv_size.y;
104
+
105
+ particles.writeAttributeVector4(
106
+ ref,
107
+ PARTICLE_ATTRIBUTE_UV,
108
+ u0 * uint16_mul, v0 * uint16_mul, u1 * uint16_mul, v1 * uint16_mul
109
+ );
110
+ }
111
+
138
112
  export class ParticleEmitter {
139
113
  constructor() {
140
114
  /**
@@ -297,6 +271,8 @@ export class ParticleEmitter {
297
271
  readDepth: !this.getFlag(ParticleEmitterFlag.DepthReadDisabled),
298
272
  softDepth: !this.getFlag(ParticleEmitterFlag.DepthSoftDisabled),
299
273
  velocityAlign: this.getFlag(ParticleEmitterFlag.AlignOnVelocity),
274
+ depthSort: this.getFlag(ParticleEmitterFlag.DepthSorting),
275
+ receiveLight: this.getFlag(ParticleEmitterFlag.Lit),
300
276
  blendingMode: this.blendingMode,
301
277
  layers: this.layers.toJSON()
302
278
  };
@@ -349,6 +325,18 @@ export class ParticleEmitter {
349
325
  this.writeFlag(ParticleEmitterFlag.AlignOnVelocity, false);
350
326
  }
351
327
 
328
+ if (typeof json.depthSort === "boolean") {
329
+ this.writeFlag(ParticleEmitterFlag.DepthSorting, json.depthSort);
330
+ } else {
331
+ this.writeFlag(ParticleEmitterFlag.DepthSorting, true);
332
+ }
333
+
334
+ if (typeof json.receiveLight === "boolean") {
335
+ this.writeFlag(ParticleEmitterFlag.Lit, json.receiveLight);
336
+ } else {
337
+ this.clearFlag(ParticleEmitterFlag.Lit);
338
+ }
339
+
352
340
  this.layers.fromJSON(json.layers, ParticleLayer);
353
341
 
354
342
  this.writeFlag(ParticleEmitterFlag.Built, false);
@@ -404,19 +392,20 @@ export class ParticleEmitter {
404
392
  throw new Error('Layer not found');
405
393
  }
406
394
 
407
- const numLayers = layers.length;
408
-
409
395
  const particles = this.particles;
410
396
  const occupancy = particles.occupancy;
411
397
 
412
398
  let removeCount = 0;
413
399
 
414
- for (let i = occupancy.nextSetBit(0); i !== -1; i = occupancy.nextSetBit(i + 1)) {
415
- const layerPosition = particles.readAttributeScalar(i, PARTICLE_ATTRIBUTE_LAYER_POSITION);
400
+ for (
401
+ let i = occupancy.nextSetBit(0);
402
+ i !== -1;
403
+ i = occupancy.nextSetBit(i + 1)
404
+ ) {
416
405
 
417
- const layerIndex = Math.round(layerPosition * numLayers);
406
+ const layerPosition = particles.readAttributeScalar(i, PARTICLE_ATTRIBUTE_LAYER_POSITION);
418
407
 
419
- if (layerIndex !== targetLayerIndex) {
408
+ if (layerPosition !== targetLayerIndex) {
420
409
  // not the layer we want
421
410
  continue;
422
411
  }
@@ -425,6 +414,7 @@ export class ParticleEmitter {
425
414
  occupancy.set(i, false);
426
415
 
427
416
  removeCount++;
417
+
428
418
  }
429
419
 
430
420
  if (removeCount > 0) {
@@ -489,7 +479,10 @@ export class ParticleEmitter {
489
479
  }
490
480
  }
491
481
 
492
- this.emisionBounds.setBounds(bounds_x0, bounds_y0, bounds_z0, bounds_x1, bounds_y1, bounds_z1);
482
+ this.emisionBounds.setBounds(
483
+ bounds_x0, bounds_y0, bounds_z0,
484
+ bounds_x1, bounds_y1, bounds_z1
485
+ );
493
486
 
494
487
  this.clearFlag(ParticleEmitterFlag.BaseBoundsNeedUpdate);
495
488
  }
@@ -498,33 +491,15 @@ export class ParticleEmitter {
498
491
  //retire dead particles
499
492
  const particles = this.particles;
500
493
 
501
- const liveParticleCount = particles.size();
494
+ particles.computeAttributeVector3AxisAlignedBoundingBox(PARTICLE_ATTRIBUTE_POSITION, scratch_array);
502
495
 
503
- let bounds_x0 = Infinity;
504
- let bounds_y0 = Infinity;
505
- 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];
506
499
 
507
- let bounds_x1 = -Infinity;
508
- let bounds_y1 = -Infinity;
509
- let bounds_z1 = -Infinity;
510
-
511
- for (let i = 0; i < liveParticleCount; i++) {
512
-
513
- particles.readAttributeVector3(i, PARTICLE_ATTRIBUTE_POSITION, position);
514
-
515
- const p_x = position[0];
516
- const p_y = position[1];
517
- const p_z = position[2];
518
-
519
- //update bounds
520
- bounds_x0 = min2(bounds_x0, p_x);
521
- bounds_y0 = min2(bounds_y0, p_y);
522
- bounds_z0 = min2(bounds_z0, p_z);
523
-
524
- bounds_x1 = max2(bounds_x1, p_x);
525
- bounds_y1 = max2(bounds_y1, p_y);
526
- bounds_z1 = max2(bounds_z1, p_z);
527
- }
500
+ let bounds_x1 = scratch_array[3];
501
+ let bounds_y1 = scratch_array[4];
502
+ let bounds_z1 = scratch_array[5];
528
503
 
529
504
  //expand bounds by maximum sprite size
530
505
  const extents = this.computeSpriteMaxHalfSize();
@@ -708,8 +683,8 @@ export class ParticleEmitter {
708
683
  }
709
684
 
710
685
  computeHash() {
711
- const parametersHash = this.parameters.hash();
712
- const layersHash = this.layers.hash();
686
+ const parameters_hash = this.parameters.hash();
687
+ const layers_hash = this.layers.hash();
713
688
 
714
689
  /**
715
690
  * Extract relevant flags
@@ -717,7 +692,12 @@ export class ParticleEmitter {
717
692
  */
718
693
  const flags = this.flags & (SERIALIZABLE_FLAGS);
719
694
 
720
- return computeHashIntegerArray(parametersHash, layersHash, this.blendingMode, flags);
695
+ return computeHashIntegerArray(
696
+ parameters_hash,
697
+ layers_hash,
698
+ this.blendingMode,
699
+ flags
700
+ );
721
701
  }
722
702
 
723
703
  hash() {
@@ -799,14 +779,19 @@ export class ParticleEmitter {
799
779
 
800
780
  const pivotIndex = (left + right) >> 1;
801
781
 
802
- const pivot = distanceToCamera(pivotIndex, positionArray, nearPlaneNormal);
782
+ const pivot = distance_to_camera(pivotIndex, positionArray, nearPlaneNormal);
803
783
 
804
784
  /* partition */
805
785
  while (i <= j) {
806
- while (distanceToCamera(i, positionArray, nearPlaneNormal) > pivot)
786
+
787
+ while (distance_to_camera(i, positionArray, nearPlaneNormal) > pivot) {
807
788
  i++;
808
- while (distanceToCamera(j, positionArray, nearPlaneNormal) < pivot)
789
+ }
790
+
791
+ while (distance_to_camera(j, positionArray, nearPlaneNormal) < pivot) {
809
792
  j--;
793
+ }
794
+
810
795
  if (i <= j) {
811
796
 
812
797
  if (i !== j) {
@@ -879,29 +864,19 @@ export class ParticleEmitter {
879
864
 
880
865
  const layers = this.layers;
881
866
 
882
- const numLayers = layers.length;
883
-
884
867
  let missingFlag = false;
885
868
 
886
869
  //cycle through each particle
887
870
  for (let i = occupancy.nextSetBit(0); i !== -1; i = occupancy.nextSetBit(i + 1)) {
888
- const layerPosition = particles.readAttributeScalar(i, PARTICLE_ATTRIBUTE_LAYER_POSITION);
889
-
890
- const layerIndex = Math.round(layerPosition * numLayers);
871
+ const layerIndex = particles.readAttributeScalar(i, PARTICLE_ATTRIBUTE_LAYER_POSITION);
891
872
 
892
873
  const layer = layers.get(layerIndex);
893
874
 
894
875
  const atlasPatch = layer.__atlasPatch;
895
876
 
896
877
  if (atlasPatch !== null) {
897
- const uv = atlasPatch.uv;
898
-
899
- const u0 = uv.position.x;
900
- const v0 = uv.position.y;
901
- const u1 = uv.size.x;
902
- const v1 = uv.size.y;
903
878
 
904
- particles.writeAttributeVector4(i, PARTICLE_ATTRIBUTE_UV, u0, v0, u1, v1);
879
+ write_particle_patch_uv(atlasPatch, particles, i);
905
880
  } else {
906
881
  missingFlag = true;
907
882
  }
@@ -933,8 +908,6 @@ export class ParticleEmitter {
933
908
 
934
909
  const emissionPeriod = 1 / layer.emissionRate;
935
910
 
936
- const layerPosition = layerIndex / this.layers.length;
937
-
938
911
  //compute transform matrix of the emitter
939
912
  const emitter_position = this.position;
940
913
  const last_spawn_position = this.__lastSpawnPosition;
@@ -952,7 +925,9 @@ export class ParticleEmitter {
952
925
  const f = time / timeDelta;
953
926
 
954
927
  //compute position for particle
955
- emissionFunction(random, v3position);
928
+ emissionFunction(random, scratch_v3_array, 0);
929
+
930
+ v3position.readFromArray(scratch_v3_array, 0);
956
931
 
957
932
  //apply layer transform
958
933
  v3position.multiply(layer.scale);
@@ -1011,28 +986,17 @@ export class ParticleEmitter {
1011
986
  //write UV
1012
987
  const atlasPatch = layer.__atlasPatch;
1013
988
  if (atlasPatch !== null) {
1014
- const uv = atlasPatch.uv;
1015
-
1016
- const uv_position = uv.position;
1017
-
1018
- const u0 = uv_position.x;
1019
- const v0 = uv_position.y;
1020
-
1021
- const uv_size = uv.size;
1022
-
1023
- const u1 = uv_size.x;
1024
- const v1 = uv_size.y;
1025
-
1026
- particles.writeAttributeVector4(ref, PARTICLE_ATTRIBUTE_UV, u0, v0, u1, v1);
989
+ //patch exists, write it
990
+ write_particle_patch_uv(atlasPatch, particles, ref);
1027
991
  } else {
1028
992
  this.setFlag(ParticleEmitterFlag.SpritesNeedUpdate);
1029
993
  }
1030
994
 
1031
- particles.writeAttributeScalar(ref, PARTICLE_ATTRIBUTE_LAYER_POSITION, layerPosition);
995
+ particles.writeAttributeScalar(ref, PARTICLE_ATTRIBUTE_LAYER_POSITION, layerIndex);
1032
996
 
1033
997
  update_parameters(ref, particles, layer, initialAge / deathAge);
1034
998
 
1035
- particles.writeAttributeScalar(ref,PARTICLE_ATTRIBUTE_BLEND,this.blendingMode);
999
+ particles.writeAttributeScalar(ref, PARTICLE_ATTRIBUTE_BLEND, this.blendingMode);
1036
1000
  }
1037
1001
 
1038
1002
  //update time buffer
@@ -1051,9 +1015,11 @@ export class ParticleEmitter {
1051
1015
  return;
1052
1016
  }
1053
1017
 
1054
- assert.ok(layerIndex < this.layers.length && layerIndex >= 0, `layerIndex[=${layerIndex}] is out of bounds`);
1018
+ const layers = this.layers;
1055
1019
 
1056
- const layer = this.layers.get(layerIndex);
1020
+ assert.ok(layerIndex < layers.length && layerIndex >= 0, `layerIndex[=${layerIndex}] is out of bounds`);
1021
+
1022
+ const layer = layers.get(layerIndex);
1057
1023
 
1058
1024
  const random = Math.random;
1059
1025
 
@@ -1065,8 +1031,6 @@ export class ParticleEmitter {
1065
1031
 
1066
1032
  const emissionFunction = computeEmissionFunction(layer.emissionFrom, layer.emissionShape);
1067
1033
 
1068
- const layerPosition = layerIndex / this.layers.length;
1069
-
1070
1034
  //compute transform matrix of the emitter
1071
1035
  composeMatrix4(matrix4, this.position, this.rotation, this.scale);
1072
1036
 
@@ -1079,7 +1043,9 @@ export class ParticleEmitter {
1079
1043
  const ref = particles.create();
1080
1044
 
1081
1045
  //compute position for particle
1082
- emissionFunction(random, v3position);
1046
+ emissionFunction(random, scratch_v3_array, 0);
1047
+
1048
+ v3position.readFromArray(scratch_v3_array, 0);
1083
1049
 
1084
1050
  //apply layer transform
1085
1051
  v3position.multiply(layer.scale);
@@ -1137,29 +1103,17 @@ export class ParticleEmitter {
1137
1103
 
1138
1104
  if (atlasPatch !== null) {
1139
1105
  //patch exists, write it
1140
- const uv = atlasPatch.uv;
1141
-
1142
- const uv_position = uv.position;
1143
-
1144
- const u0 = uv_position.x;
1145
- const v0 = uv_position.y;
1146
-
1147
- const uv_size = uv.size;
1148
-
1149
- const u1 = uv_size.x;
1150
- const v1 = uv_size.y;
1151
-
1152
- particles.writeAttributeVector4(ref, PARTICLE_ATTRIBUTE_UV, u0, v0, u1, v1);
1106
+ write_particle_patch_uv(atlasPatch, particles, ref);
1153
1107
  } else {
1154
1108
  //patch is not loaded yet, request update
1155
1109
  spritesNeedUpdate = true;
1156
1110
  }
1157
1111
 
1158
- particles.writeAttributeScalar(ref, PARTICLE_ATTRIBUTE_LAYER_POSITION, layerPosition);
1112
+ particles.writeAttributeScalar(ref, PARTICLE_ATTRIBUTE_LAYER_POSITION, layerIndex);
1159
1113
 
1160
1114
  update_parameters(ref, particles, layer, initialAge / deathAge);
1161
1115
 
1162
- particles.writeAttributeScalar(ref,PARTICLE_ATTRIBUTE_BLEND,this.blendingMode);
1116
+ particles.writeAttributeScalar(ref, PARTICLE_ATTRIBUTE_BLEND, this.blendingMode);
1163
1117
  }
1164
1118
 
1165
1119
  if (spritesNeedUpdate) {
@@ -1197,7 +1151,9 @@ export class ParticleEmitter {
1197
1151
  continue;
1198
1152
  }
1199
1153
 
1200
- const averageLifetime = (layer.particleLife.max + layer.particleLife.min) / 2;
1154
+ const particleLife = layer.particleLife;
1155
+
1156
+ const averageLifetime = (particleLife.max + particleLife.min) / 2;
1201
1157
 
1202
1158
  //emitting more than averageLifetime lifetime is unproductive, so we'll crop the emission
1203
1159
  let emissionDelta;
@@ -1260,27 +1216,8 @@ const matrix4 = new Matrix4();
1260
1216
 
1261
1217
  const defaultPointsMaterial = new PointsMaterial({ color: 0xFFFFFF });
1262
1218
 
1263
-
1264
- //build particle spec
1265
- export const PARTICULAR_PARTICLE_SPECIFICATION = new ParticleSpecification();
1266
-
1267
- PARTICULAR_PARTICLE_SPECIFICATION.add(new ParticleAttribute('position', ParticleAttributeType.Vector3, ParticleDataType.Float32));
1268
- PARTICULAR_PARTICLE_SPECIFICATION.add(new ParticleAttribute('age', ParticleAttributeType.Scalar, ParticleDataType.Float32));
1269
- PARTICULAR_PARTICLE_SPECIFICATION.add(new ParticleAttribute('deathAge', ParticleAttributeType.Scalar, ParticleDataType.Float32));
1270
- PARTICULAR_PARTICLE_SPECIFICATION.add(new ParticleAttribute('atlasPatch', ParticleAttributeType.Vector4, ParticleDataType.Float32));
1271
- PARTICULAR_PARTICLE_SPECIFICATION.add(new ParticleAttribute('size', ParticleAttributeType.Scalar, ParticleDataType.Float32));
1272
- PARTICULAR_PARTICLE_SPECIFICATION.add(new ParticleAttribute('layerPosition', ParticleAttributeType.Scalar, ParticleDataType.Float32));
1273
- PARTICULAR_PARTICLE_SPECIFICATION.add(new ParticleAttribute('velocity', ParticleAttributeType.Vector3, ParticleDataType.Float32));
1274
- PARTICULAR_PARTICLE_SPECIFICATION.add(new ParticleAttribute('rotation', ParticleAttributeType.Scalar, ParticleDataType.Float32));
1275
- PARTICULAR_PARTICLE_SPECIFICATION.add(new ParticleAttribute('rotationSpeed', ParticleAttributeType.Scalar, ParticleDataType.Float32));
1276
- PARTICULAR_PARTICLE_SPECIFICATION.add(new ParticleAttribute('color', ParticleAttributeType.Vector4, ParticleDataType.Float32));
1277
- PARTICULAR_PARTICLE_SPECIFICATION.add(new ParticleAttribute('blending', ParticleAttributeType.Scalar, ParticleDataType.Uint8));
1278
- PARTICULAR_PARTICLE_SPECIFICATION.add(new ParticleAttribute('size_initial', ParticleAttributeType.Scalar, ParticleDataType.Float32));
1279
-
1280
-
1281
1219
  const frustum = new Frustum();
1282
1220
 
1283
- const velocity = [];
1284
1221
  const position = [];
1285
1222
 
1286
1223
  const v3position = new Vector3();
@@ -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
  };