laymur 0.15.1 → 0.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (248) hide show
  1. package/.claude/settings.local.json +9 -0
  2. package/.editorconfig +14 -0
  3. package/CLAUDE.md +181 -0
  4. package/README.md +84 -208
  5. package/assets/logotype.png +0 -0
  6. package/eslint.config.js +111 -0
  7. package/package.json +20 -36
  8. package/rollup.config.js +52 -0
  9. package/{dist/constraints/UIAspectConstraint/UIAspectConstraint.Internal.d.ts → src/core/constraints/UIAspectConstraint/UIAspectConstraint.Internal.ts} +3 -2
  10. package/src/core/constraints/UIAspectConstraint/UIAspectConstraint.ts +60 -0
  11. package/src/core/constraints/UIConstraint.ts +20 -0
  12. package/src/core/constraints/UICustomConstraint.ts +62 -0
  13. package/{dist/constraints/UIHeightConstraint/UIHeightConstraint.Internal.d.ts → src/core/constraints/UIHeightConstraint/UIHeightConstraint.Internal.ts} +3 -2
  14. package/src/core/constraints/UIHeightConstraint/UIHeightConstraint.ts +52 -0
  15. package/src/core/constraints/UIHorizontalDistanceConstraint/UIHorizontalDistanceConstraint.Internal.ts +13 -0
  16. package/src/core/constraints/UIHorizontalDistanceConstraint/UIHorizontalDistanceConstraint.ts +139 -0
  17. package/src/core/constraints/UIHorizontalInterpolationConstraint/UIHorizontalInterpolationConstraint.Internal.ts +16 -0
  18. package/src/core/constraints/UIHorizontalInterpolationConstraint/UIHorizontalInterpolationConstraint.ts +189 -0
  19. package/{dist/constraints/UIHorizontalProportionConstraint/UIHorizontalProportionConstraint.Internal.d.ts → src/core/constraints/UIHorizontalProportionConstraint/UIHorizontalProportionConstraint.Internal.ts} +3 -2
  20. package/src/core/constraints/UIHorizontalProportionConstraint/UIHorizontalProportionConstraint.ts +68 -0
  21. package/{dist/constraints/UISingleParameterConstraint/UISingleParameterConstraint.Internal.d.ts → src/core/constraints/UISingleParameterConstraint/UISingleParameterConstraint.Internal.ts} +9 -8
  22. package/src/core/constraints/UISingleParameterConstraint/UISingleParameterConstraint.ts +94 -0
  23. package/src/core/constraints/UIVerticalDistanceConstraint/UIVerticalDistanceConstraint.Internal.ts +13 -0
  24. package/src/core/constraints/UIVerticalDistanceConstraint/UIVerticalDistanceConstraint.ts +135 -0
  25. package/src/core/constraints/UIVerticalInterpolationConstraint/UIVerticalInterpolationConstraint.Internal.ts +16 -0
  26. package/src/core/constraints/UIVerticalInterpolationConstraint/UIVerticalInterpolationConstraint.ts +189 -0
  27. package/{dist/constraints/UIVerticalProportionConstraint/UIVerticalProportionConstraint.Internal.d.ts → src/core/constraints/UIVerticalProportionConstraint/UIVerticalProportionConstraint.Internal.ts} +3 -2
  28. package/src/core/constraints/UIVerticalProportionConstraint/UIVerticalProportionConstraint.ts +68 -0
  29. package/{dist/constraints/UIWidthConstraint/UIWidthConstraint.Internal.d.ts → src/core/constraints/UIWidthConstraint/UIWidthConstraint.Internal.ts} +3 -2
  30. package/src/core/constraints/UIWidthConstraint/UIWidthConstraint.ts +52 -0
  31. package/src/core/constraints/builders/UIConstraint2DBuilder.Internal.ts +84 -0
  32. package/src/core/constraints/builders/UIConstraint2DBuilder.ts +168 -0
  33. package/src/core/constraints/builders/UICoverConstraintBuilder.Internal.ts +15 -0
  34. package/src/core/constraints/builders/UICoverConstraintBuilder.ts +84 -0
  35. package/src/core/constraints/builders/UIFitConstraintBuilder.Internal.ts +15 -0
  36. package/src/core/constraints/builders/UIFitConstraintBuilder.ts +84 -0
  37. package/src/core/elements/UIAnchor/UIAnchor.Internal.ts +13 -0
  38. package/src/core/elements/UIAnchor/UIAnchor.ts +70 -0
  39. package/src/core/elements/UIAnimatedImage/UIAnimatedImage.Internal.ts +30 -0
  40. package/src/core/elements/UIAnimatedImage/UIAnimatedImage.ts +355 -0
  41. package/src/core/elements/UIDummy/UIDummy.Internal.ts +33 -0
  42. package/src/core/elements/UIDummy/UIDummy.ts +244 -0
  43. package/src/core/elements/UIElement/UIElement.Internal.ts +13 -0
  44. package/src/core/elements/UIElement/UIElement.ts +127 -0
  45. package/{dist/elements/UIGraphics/UIGraphics.Internal.d.ts → src/core/elements/UIGraphics/UIGraphics.Internal.ts} +7 -5
  46. package/src/core/elements/UIGraphics/UIGraphics.ts +168 -0
  47. package/{dist/elements/UIImage/UIImage.Internal.d.ts → src/core/elements/UIImage/UIImage.Internal.ts} +3 -2
  48. package/src/core/elements/UIImage/UIImage.ts +138 -0
  49. package/src/core/elements/UINineSlice/UINineSlice.Internal.ts +26 -0
  50. package/src/core/elements/UINineSlice/UINineSlice.ts +296 -0
  51. package/src/core/elements/UIProgress/UIProgress.Internal.ts +24 -0
  52. package/src/core/elements/UIProgress/UIProgress.ts +259 -0
  53. package/src/core/elements/UIScene/UIScene.Internal.ts +46 -0
  54. package/src/core/elements/UIScene/UIScene.ts +259 -0
  55. package/{dist/elements/UIText/UIText.Interfaces.d.ts → src/core/elements/UIText/UIText.Interfaces.ts} +21 -16
  56. package/src/core/elements/UIText/UIText.Internal.ts +29 -0
  57. package/src/core/elements/UIText/UIText.Measuring.ts +183 -0
  58. package/src/core/elements/UIText/UIText.Rendering.ts +83 -0
  59. package/src/core/elements/UIText/UIText.ts +376 -0
  60. package/{dist/index.d.ts → src/core/index.ts} +2 -1
  61. package/{dist/layers/UIFullscreenLayer/UIFullscreenLayer.Internal.d.ts → src/core/layers/UIFullscreenLayer/UIFullscreenLayer.Internal.ts} +14 -11
  62. package/src/core/layers/UIFullscreenLayer/UIFullscreenLayer.ts +233 -0
  63. package/{dist/layers/UILayer/UILayer.Internal.d.ts → src/core/layers/UILayer/UILayer.Internal.ts} +15 -11
  64. package/src/core/layers/UILayer/UILayer.ts +156 -0
  65. package/src/core/miscellaneous/UIExpression.ts +142 -0
  66. package/src/core/miscellaneous/UIMode.ts +29 -0
  67. package/src/core/miscellaneous/UIOrientation.ts +18 -0
  68. package/src/core/miscellaneous/UIPriority.ts +63 -0
  69. package/src/core/miscellaneous/UIRelation.ts +39 -0
  70. package/src/core/miscellaneous/UITransparencyMode.ts +9 -0
  71. package/src/core/miscellaneous/area/UIArea.ts +5 -0
  72. package/src/core/miscellaneous/area/UIAreaCircle.ts +32 -0
  73. package/src/core/miscellaneous/area/UIAreaPolygon.ts +50 -0
  74. package/src/core/miscellaneous/area/UIAreaRectangle.ts +38 -0
  75. package/src/core/miscellaneous/area/UIAreaRoundedRectangle.ts +78 -0
  76. package/src/core/miscellaneous/asserts.ts +187 -0
  77. package/src/core/miscellaneous/canvas.ts +73 -0
  78. package/src/core/miscellaneous/color/UIColor.Internal.ts +89 -0
  79. package/src/core/miscellaneous/color/UIColor.ts +844 -0
  80. package/src/core/miscellaneous/computeTransform.ts +127 -0
  81. package/src/core/miscellaneous/generic-plane/UIGenericInstancedPlane/UIGenericInstancedPlane.Internal.ts +235 -0
  82. package/src/core/miscellaneous/generic-plane/UIGenericInstancedPlane/UIGenericInstancedPlane.ts +524 -0
  83. package/{dist/miscellaneous/generic-plane/UIGenericPlaneRegistry/UIGenericPlaneRegistry.Internal.d.ts → src/core/miscellaneous/generic-plane/UIGenericPlaneRegistry/UIGenericPlaneRegistry.Internal.ts} +10 -8
  84. package/src/core/miscellaneous/generic-plane/UIGenericPlaneRegistry/UIGenericPlaneRegistry.ts +448 -0
  85. package/src/core/miscellaneous/generic-plane/shared.ts +323 -0
  86. package/src/core/miscellaneous/insets/UIInsets.Internal.ts +9 -0
  87. package/src/core/miscellaneous/insets/UIInsets.ts +248 -0
  88. package/src/core/miscellaneous/mask-function/UIProgressMaskFunction.ts +24 -0
  89. package/src/core/miscellaneous/mask-function/UIProgressMaskFunctionCircular.ts +58 -0
  90. package/src/core/miscellaneous/mask-function/UIProgressMaskFunctionDirectional.ts +52 -0
  91. package/src/core/miscellaneous/math.ts +16 -0
  92. package/src/core/miscellaneous/micro/UIMicro.Internal.ts +33 -0
  93. package/src/core/miscellaneous/micro/UIMicro.ts +222 -0
  94. package/src/core/miscellaneous/resize-policy/UIResizePolicy.ts +8 -0
  95. package/src/core/miscellaneous/resize-policy/UIResizePolicyCover.ts +57 -0
  96. package/src/core/miscellaneous/resize-policy/UIResizePolicyCross.ts +65 -0
  97. package/src/core/miscellaneous/resize-policy/UIResizePolicyCrossInverted.ts +65 -0
  98. package/src/core/miscellaneous/resize-policy/UIResizePolicyFit.ts +57 -0
  99. package/src/core/miscellaneous/resize-policy/UIResizePolicyFixedHeight.ts +65 -0
  100. package/src/core/miscellaneous/resize-policy/UIResizePolicyFixedWidth.ts +65 -0
  101. package/src/core/miscellaneous/resize-policy/UIResizePolicyNone.ts +11 -0
  102. package/src/core/miscellaneous/shared.ts +73 -0
  103. package/{dist/miscellaneous/text-span/UITextSpan.Internal.d.ts → src/core/miscellaneous/text-span/UITextSpan.Internal.ts} +5 -4
  104. package/src/core/miscellaneous/text-span/UITextSpan.ts +43 -0
  105. package/src/core/miscellaneous/text-style/UITextStyle.Internal.ts +52 -0
  106. package/src/core/miscellaneous/text-style/UITextStyle.ts +479 -0
  107. package/src/core/miscellaneous/texture/UITextureView.Internal.ts +55 -0
  108. package/src/core/miscellaneous/texture/UITextureView.ts +308 -0
  109. package/src/core/miscellaneous/webglCapabilities.ts +129 -0
  110. package/src/core/shaders/UIImage.glsl +10 -0
  111. package/src/core/shaders/UINineSlice.glsl +53 -0
  112. package/src/core/shaders/UIProgress.glsl +15 -0
  113. package/src/core/shaders/UIProgressMaskFunctionCircular.glsl +13 -0
  114. package/src/core/shaders/UIProgressMaskFunctionDirectional.glsl +12 -0
  115. package/src/core/shaders/glsl.d.ts +27 -0
  116. package/src/core/wrappers/UIInputWrapper/UIInputWrapper.Internal.ts +23 -0
  117. package/src/core/wrappers/UIInputWrapper/UIInputWrapper.ts +124 -0
  118. package/src/core/wrappers/UISceneWrapper/UISceneWrapper.Internal.ts +22 -0
  119. package/src/core/wrappers/UISceneWrapper/UISceneWrapper.ts +101 -0
  120. package/src/core/wrappers/UISolverWrapper/UISolverWrapper.Internal.ts +58 -0
  121. package/src/core/wrappers/UISolverWrapper/UISolverWrapper.ts +605 -0
  122. package/src/particles/behaviorModules/UIBehaviorDirectionalGravity.ts +70 -0
  123. package/src/particles/behaviorModules/UIBehaviorModule.ts +20 -0
  124. package/src/particles/behaviorModules/UIBehaviorPointGravity.ts +173 -0
  125. package/src/particles/behaviorModules/UIBehaviorScaleOverLife.ts +104 -0
  126. package/src/particles/behaviorModules/UIBehaviorTorqueDamping.ts +75 -0
  127. package/src/particles/behaviorModules/UIBehaviorTorqueNoise.ts +115 -0
  128. package/src/particles/behaviorModules/UIBehaviorVelocityDamping.ts +77 -0
  129. package/src/particles/behaviorModules/UIBehaviorVelocityNoise.ts +118 -0
  130. package/src/particles/elements/UIEmitter.Internal.ts +22 -0
  131. package/src/particles/elements/UIEmitter.ts +313 -0
  132. package/src/particles/index.ts +18 -0
  133. package/src/particles/instancedParticle/UIInstancedParticle.Internal.ts +263 -0
  134. package/src/particles/instancedParticle/UIInstancedParticle.ts +138 -0
  135. package/src/particles/miscellaneous/miscellaneous.ts +115 -0
  136. package/src/particles/renderingModules/UIRenderingColorOverLife.ts +39 -0
  137. package/src/particles/renderingModules/UIRenderingColorOverVelocity.ts +49 -0
  138. package/src/particles/renderingModules/UIRenderingModule.ts +17 -0
  139. package/src/particles/renderingModules/UIRenderingTexture.ts +30 -0
  140. package/src/particles/shaders/UIRenderingColorOverLife.glsl +4 -0
  141. package/src/particles/shaders/UIRenderingColorOverVelocity.glsl +6 -0
  142. package/src/particles/shaders/UIRenderingTexture.glsl +4 -0
  143. package/src/particles/spawnModules/UISpawnModule.ts +22 -0
  144. package/src/particles/spawnModules/UISpawnOffset.ts +62 -0
  145. package/src/particles/spawnModules/UISpawnRandomLifetime.ts +68 -0
  146. package/src/particles/spawnModules/UISpawnRandomRotation.ts +60 -0
  147. package/src/particles/spawnModules/UISpawnRandomScale.ts +81 -0
  148. package/src/particles/spawnModules/UISpawnRandomTorque.ts +62 -0
  149. package/src/particles/spawnModules/UISpawnRandomVelocity.ts +92 -0
  150. package/src/particles/spawnModules/UISpawnRectangle.ts +81 -0
  151. package/tsconfig.json +29 -0
  152. package/dist/constraints/UIAspectConstraint/UIAspectConstraint.d.ts +0 -22
  153. package/dist/constraints/UIConstraint.d.ts +0 -12
  154. package/dist/constraints/UICustomConstraint.d.ts +0 -28
  155. package/dist/constraints/UIHeightConstraint/UIHeightConstraint.d.ts +0 -20
  156. package/dist/constraints/UIHorizontalDistanceConstraint/UIHorizontalDistanceConstraint.Internal.d.ts +0 -11
  157. package/dist/constraints/UIHorizontalDistanceConstraint/UIHorizontalDistanceConstraint.d.ts +0 -36
  158. package/dist/constraints/UIHorizontalInterpolationConstraint/UIHorizontalInterpolationConstraint.Internal.d.ts +0 -14
  159. package/dist/constraints/UIHorizontalInterpolationConstraint/UIHorizontalInterpolationConstraint.d.ts +0 -44
  160. package/dist/constraints/UIHorizontalProportionConstraint/UIHorizontalProportionConstraint.d.ts +0 -22
  161. package/dist/constraints/UISingleParameterConstraint/UISingleParameterConstraint.d.ts +0 -43
  162. package/dist/constraints/UIVerticalDistanceConstraint/UIVerticalDistanceConstraint.Internal.d.ts +0 -11
  163. package/dist/constraints/UIVerticalDistanceConstraint/UIVerticalDistanceConstraint.d.ts +0 -32
  164. package/dist/constraints/UIVerticalInterpolationConstraint/UIVerticalInterpolationConstraint.Internal.d.ts +0 -14
  165. package/dist/constraints/UIVerticalInterpolationConstraint/UIVerticalInterpolationConstraint.d.ts +0 -44
  166. package/dist/constraints/UIVerticalProportionConstraint/UIVerticalProportionConstraint.d.ts +0 -22
  167. package/dist/constraints/UIWidthConstraint/UIWidthConstraint.d.ts +0 -20
  168. package/dist/constraints/builders/UIConstraint2DBuilder.Internal.d.ts +0 -64
  169. package/dist/constraints/builders/UIConstraint2DBuilder.d.ts +0 -46
  170. package/dist/constraints/builders/UICoverConstraintBuilder.Internal.d.ts +0 -13
  171. package/dist/constraints/builders/UICoverConstraintBuilder.d.ts +0 -29
  172. package/dist/constraints/builders/UIFitConstraintBuilder.Internal.d.ts +0 -13
  173. package/dist/constraints/builders/UIFitConstraintBuilder.d.ts +0 -29
  174. package/dist/elements/UIAnchor/UIAnchor.Internal.d.ts +0 -9
  175. package/dist/elements/UIAnchor/UIAnchor.d.ts +0 -32
  176. package/dist/elements/UIAnimatedImage/UIAnimatedImage.Internal.d.ts +0 -27
  177. package/dist/elements/UIAnimatedImage/UIAnimatedImage.d.ts +0 -77
  178. package/dist/elements/UIElement/UIElement.Internal.d.ts +0 -11
  179. package/dist/elements/UIElement/UIElement.d.ts +0 -38
  180. package/dist/elements/UIGraphics/UIGraphics.d.ts +0 -51
  181. package/dist/elements/UIImage/UIImage.d.ts +0 -32
  182. package/dist/elements/UIInputDummy/UIInputDummy.Internal.d.ts +0 -30
  183. package/dist/elements/UIInputDummy/UIInputDummy.d.ts +0 -82
  184. package/dist/elements/UINineSlice/UINineSlice.Internal.d.ts +0 -23
  185. package/dist/elements/UINineSlice/UINineSlice.d.ts +0 -60
  186. package/dist/elements/UIProgress/UIProgress.Internal.d.ts +0 -14
  187. package/dist/elements/UIProgress/UIProgress.d.ts +0 -45
  188. package/dist/elements/UIScene/UIScene.Internal.d.ts +0 -43
  189. package/dist/elements/UIScene/UIScene.d.ts +0 -59
  190. package/dist/elements/UIText/UIText.Internal.d.ts +0 -26
  191. package/dist/elements/UIText/UIText.Measuring.d.ts +0 -50
  192. package/dist/elements/UIText/UIText.Rendering.d.ts +0 -20
  193. package/dist/elements/UIText/UIText.d.ts +0 -71
  194. package/dist/index.js +0 -9236
  195. package/dist/index.js.map +0 -1
  196. package/dist/index.min.js +0 -2
  197. package/dist/index.min.js.map +0 -1
  198. package/dist/layers/UIFullscreenLayer/UIFullscreenLayer.d.ts +0 -63
  199. package/dist/layers/UILayer/UILayer.d.ts +0 -49
  200. package/dist/miscellaneous/UIExpression.d.ts +0 -69
  201. package/dist/miscellaneous/UIMode.d.ts +0 -23
  202. package/dist/miscellaneous/UIOrientation.d.ts +0 -15
  203. package/dist/miscellaneous/UIPriority.d.ts +0 -32
  204. package/dist/miscellaneous/UIRelation.d.ts +0 -23
  205. package/dist/miscellaneous/UITransparencyMode.d.ts +0 -9
  206. package/dist/miscellaneous/area/UIArea.d.ts +0 -3
  207. package/dist/miscellaneous/area/UIAreaCircle.d.ts +0 -15
  208. package/dist/miscellaneous/area/UIAreaPolygon.d.ts +0 -12
  209. package/dist/miscellaneous/area/UIAreaRectangle.d.ts +0 -17
  210. package/dist/miscellaneous/area/UIAreaRoundedRectangle.d.ts +0 -21
  211. package/dist/miscellaneous/asserts.d.ts +0 -43
  212. package/dist/miscellaneous/canvas.d.ts +0 -31
  213. package/dist/miscellaneous/color/UIColor.Internal.d.ts +0 -7
  214. package/dist/miscellaneous/color/UIColor.d.ts +0 -234
  215. package/dist/miscellaneous/computeTransform.d.ts +0 -18
  216. package/dist/miscellaneous/generic-plane/UIGenericInstancedPlane/UIGenericInstancedPlane.Internal.d.ts +0 -19
  217. package/dist/miscellaneous/generic-plane/UIGenericInstancedPlane/UIGenericInstancedPlane.d.ts +0 -1
  218. package/dist/miscellaneous/generic-plane/UIGenericPlaneRegistry/UIGenericPlaneRegistry.d.ts +0 -1
  219. package/dist/miscellaneous/generic-plane/shared.d.ts +0 -38
  220. package/dist/miscellaneous/insets/UIInsets.Internal.d.ts +0 -11
  221. package/dist/miscellaneous/insets/UIInsets.d.ts +0 -48
  222. package/dist/miscellaneous/mask-function/UIProgressMaskFunction.d.ts +0 -9
  223. package/dist/miscellaneous/mask-function/UIProgressMaskFunctionCircular.d.ts +0 -21
  224. package/dist/miscellaneous/mask-function/UIProgressMaskFunctionDirectional.d.ts +0 -16
  225. package/dist/miscellaneous/math.d.ts +0 -5
  226. package/dist/miscellaneous/micro/UIMicro.Internal.d.ts +0 -31
  227. package/dist/miscellaneous/micro/UIMicro.d.ts +0 -59
  228. package/dist/miscellaneous/resize-policy/UIResizePolicy.d.ts +0 -3
  229. package/dist/miscellaneous/resize-policy/UIResizePolicyCover.d.ts +0 -22
  230. package/dist/miscellaneous/resize-policy/UIResizePolicyCross.d.ts +0 -22
  231. package/dist/miscellaneous/resize-policy/UIResizePolicyCrossInverted.d.ts +0 -22
  232. package/dist/miscellaneous/resize-policy/UIResizePolicyFit.d.ts +0 -22
  233. package/dist/miscellaneous/resize-policy/UIResizePolicyFixedHeight.d.ts +0 -22
  234. package/dist/miscellaneous/resize-policy/UIResizePolicyFixedWidth.d.ts +0 -22
  235. package/dist/miscellaneous/resize-policy/UIResizePolicyNone.d.ts +0 -5
  236. package/dist/miscellaneous/shared.d.ts +0 -46
  237. package/dist/miscellaneous/text-span/UITextSpan.d.ts +0 -14
  238. package/dist/miscellaneous/text-style/UITextStyle.Internal.d.ts +0 -48
  239. package/dist/miscellaneous/text-style/UITextStyle.d.ts +0 -85
  240. package/dist/miscellaneous/texture/UITextureView.Internal.d.ts +0 -49
  241. package/dist/miscellaneous/texture/UITextureView.d.ts +0 -67
  242. package/dist/miscellaneous/webglCapabilities.d.ts +0 -2
  243. package/dist/wrappers/UIInputWrapper/UIInputWrapper.Internal.d.ts +0 -17
  244. package/dist/wrappers/UIInputWrapper/UIInputWrapper.d.ts +0 -13
  245. package/dist/wrappers/UISceneWrapper/UISceneWrapper.Internal.d.ts +0 -13
  246. package/dist/wrappers/UISceneWrapper/UISceneWrapper.d.ts +0 -20
  247. package/dist/wrappers/UISolverWrapper/UISolverWrapper.Internal.d.ts +0 -49
  248. package/dist/wrappers/UISolverWrapper/UISolverWrapper.d.ts +0 -215
@@ -0,0 +1,138 @@
1
+ import type { InstancedBufferGeometry, ShaderMaterial, Vector2 } from "three";
2
+ import { InstancedBufferAttribute, Mesh, StreamDrawUsage } from "three";
3
+ import {
4
+ resolvePropertyUniform,
5
+ type GLProperty,
6
+ type GLTypeInfo,
7
+ } from "../../core/miscellaneous/generic-plane/shared";
8
+ import { BUILTIN_OFFSET_AGE, BUILTIN_OFFSET_LIFETIME } from "../miscellaneous/miscellaneous";
9
+ import { buildParticleMaterial, INSTANCED_PARTICLE_GEOMETRY } from "./UIInstancedParticle.Internal";
10
+
11
+ export class UIInstancedParticle extends Mesh {
12
+ public readonly propertyBuffers: Record<string, InstancedBufferAttribute> = {};
13
+
14
+ private readonly instancedGeometry: InstancedBufferGeometry;
15
+ private readonly shaderMaterial: ShaderMaterial;
16
+ private capacity: number;
17
+
18
+ constructor(
19
+ sources: string[],
20
+ uniforms: Record<string, GLProperty>,
21
+ varyings: Record<string, GLTypeInfo>,
22
+ expectedCapacity: number,
23
+ private readonly capacityStep: number,
24
+ ) {
25
+ const instancedGeometry = INSTANCED_PARTICLE_GEOMETRY.clone();
26
+ const shaderMaterial = buildParticleMaterial(sources, uniforms, varyings);
27
+
28
+ super(instancedGeometry, shaderMaterial);
29
+
30
+ this.frustumCulled = false;
31
+ this.matrixAutoUpdate = false;
32
+ this.matrixWorldAutoUpdate = false;
33
+
34
+ this.instancedGeometry = instancedGeometry;
35
+ this.instancedGeometry.instanceCount = 0;
36
+
37
+ this.shaderMaterial = shaderMaterial;
38
+ this.capacity = Math.max(
39
+ Math.ceil(expectedCapacity / this.capacityStep) * this.capacityStep,
40
+ this.capacityStep,
41
+ );
42
+
43
+ for (const name in varyings) {
44
+ const { bufferSize } = varyings[name];
45
+ const attribute = new InstancedBufferAttribute(
46
+ new Float32Array(this.capacity * bufferSize),
47
+ bufferSize,
48
+ );
49
+ attribute.setUsage(StreamDrawUsage);
50
+ this.instancedGeometry.setAttribute(`a_${name}`, attribute);
51
+ this.propertyBuffers[name] = attribute;
52
+ }
53
+ }
54
+
55
+ public get instanceCount(): number {
56
+ return this.instancedGeometry.instanceCount;
57
+ }
58
+
59
+ public createInstances(count: number): void {
60
+ const currentInstanceCount = this.instancedGeometry.instanceCount;
61
+ this.ensureCapacity(currentInstanceCount + count);
62
+ this.instancedGeometry.instanceCount += count;
63
+ }
64
+
65
+ public setOrigin(x: number, y: number): void {
66
+ const uniform = resolvePropertyUniform("origin", this.shaderMaterial);
67
+ (uniform.value as Vector2).set(x, y);
68
+ }
69
+
70
+ public removeDeadParticles(): void {
71
+ const builtinBuffer = this.propertyBuffers.builtin as InstancedBufferAttribute | undefined;
72
+ if (builtinBuffer === undefined) {
73
+ return;
74
+ }
75
+
76
+ const { array: builtinArray, itemSize: builtinItemSize } = builtinBuffer;
77
+ const { instanceCount } = this.instancedGeometry;
78
+
79
+ let writeIndex = 0;
80
+
81
+ for (let readIndex = 0; readIndex < instanceCount; readIndex++) {
82
+ const offset = readIndex * builtinItemSize;
83
+
84
+ if (
85
+ builtinArray[offset + BUILTIN_OFFSET_AGE] < builtinArray[offset + BUILTIN_OFFSET_LIFETIME]
86
+ ) {
87
+ if (writeIndex !== readIndex) {
88
+ for (const name in this.propertyBuffers) {
89
+ const attribute = this.propertyBuffers[name];
90
+ const { itemSize: dataItemSize, array: dataArray } = attribute;
91
+
92
+ const srcOffset = readIndex * dataItemSize;
93
+ const dstOffset = writeIndex * dataItemSize;
94
+
95
+ dataArray.copyWithin(dstOffset, srcOffset, srcOffset + dataItemSize);
96
+ attribute.needsUpdate = true;
97
+ }
98
+ }
99
+
100
+ writeIndex++;
101
+ }
102
+ }
103
+
104
+ this.instancedGeometry.instanceCount = writeIndex;
105
+ }
106
+
107
+ public drop(): void {
108
+ this.instancedGeometry.instanceCount = 0;
109
+ }
110
+
111
+ public destroy(): void {
112
+ this.instancedGeometry.dispose();
113
+ this.shaderMaterial.dispose();
114
+ }
115
+
116
+ private ensureCapacity(requiredCapacity: number): void {
117
+ if (requiredCapacity <= this.capacity) {
118
+ return;
119
+ }
120
+
121
+ const newCapacity = Math.ceil(requiredCapacity / this.capacityStep) * this.capacityStep;
122
+
123
+ for (const name in this.propertyBuffers) {
124
+ const { itemSize, array, usage } = this.propertyBuffers[name];
125
+ const newArray = new Float32Array(newCapacity * itemSize);
126
+ newArray.set(array);
127
+
128
+ const newAttribute = new InstancedBufferAttribute(newArray, itemSize);
129
+ newAttribute.setUsage(usage);
130
+ this.instancedGeometry.setAttribute(`a_${name}`, newAttribute);
131
+ this.propertyBuffers[name] = newAttribute;
132
+ }
133
+
134
+ this.capacity = newCapacity;
135
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- old three.js compatibility fix
136
+ (this.instancedGeometry as any)._maxInstanceCount = newCapacity;
137
+ }
138
+ }
@@ -0,0 +1,115 @@
1
+ import {
2
+ ClampToEdgeWrapping,
3
+ DataTexture,
4
+ LinearFilter,
5
+ RGBAFormat,
6
+ SRGBColorSpace,
7
+ Texture,
8
+ UnsignedByteType,
9
+ UVMapping,
10
+ type Vector2Tuple,
11
+ } from "three";
12
+ import type { UIColor } from "../../core";
13
+ import type { Vector2Like } from "../../core/miscellaneous/math";
14
+ import type { UITextureConfig } from "../../core/miscellaneous/texture/UITextureView.Internal";
15
+
16
+ export interface UIRange {
17
+ min: number;
18
+ max: number;
19
+ }
20
+
21
+ export type UIRangeConfig = UIRange | [number, number] | number;
22
+ export type UIVector2Config = Vector2Like | Vector2Tuple | number;
23
+ export type UIAspectConfig = number | UITextureConfig;
24
+
25
+ export function resolveUIRangeConfig(config: UIRangeConfig): UIRange {
26
+ if (typeof config === "number") {
27
+ return { min: config, max: config };
28
+ }
29
+
30
+ if (Array.isArray(config)) {
31
+ return { min: config[0], max: config[1] };
32
+ }
33
+
34
+ return config;
35
+ }
36
+
37
+ export function resolveUIVector2Config(config: UIVector2Config): Vector2Like {
38
+ if (typeof config === "number") {
39
+ return { x: config, y: config };
40
+ }
41
+
42
+ if (Array.isArray(config)) {
43
+ return { x: config[0], y: config[1] };
44
+ }
45
+
46
+ return config;
47
+ }
48
+
49
+ export function resolveAspect(config: number | UITextureConfig): number {
50
+ if (typeof config === "number") {
51
+ return config;
52
+ }
53
+
54
+ if (config instanceof Texture) {
55
+ return config.image.naturalWidth / config.image.naturalHeight;
56
+ }
57
+
58
+ return config.sourceSize.w / config.sourceSize.h;
59
+ }
60
+
61
+ export function generateNoise2D(x: number, y: number): number {
62
+ const noise = Math.sin(x * 12.9898 + y * 78.233) * 43758.5453123;
63
+ return (noise - Math.floor(noise)) * 2 - 1;
64
+ }
65
+
66
+ export function buildGradientTexture(colors: UIColor[]): DataTexture {
67
+ const width = colors.length;
68
+ const height = 1;
69
+ const data = new Uint8Array(width * height * 4);
70
+
71
+ for (let i = 0; i < width; i++) {
72
+ const color = colors[i];
73
+
74
+ const index = i * 4;
75
+ data[index] = Math.round(color.r * 255);
76
+ data[index + 1] = Math.round(color.g * 255);
77
+ data[index + 2] = Math.round(color.b * 255);
78
+ data[index + 3] = Math.round(color.a * 255);
79
+ }
80
+
81
+ const texture = new DataTexture(
82
+ data,
83
+ width,
84
+ height,
85
+ RGBAFormat,
86
+ UnsignedByteType,
87
+ UVMapping,
88
+ ClampToEdgeWrapping,
89
+ ClampToEdgeWrapping,
90
+ LinearFilter,
91
+ LinearFilter,
92
+ 1,
93
+ SRGBColorSpace,
94
+ );
95
+
96
+ texture.needsUpdate = true;
97
+ return texture;
98
+ }
99
+
100
+ export const BUILTIN_OFFSET_POSITION_X = 0;
101
+ export const BUILTIN_OFFSET_POSITION_Y = 1;
102
+ export const BUILTIN_OFFSET_VELOCITY_X = 2;
103
+ export const BUILTIN_OFFSET_VELOCITY_Y = 3;
104
+ export const BUILTIN_OFFSET_SCALE_X = 4;
105
+ export const BUILTIN_OFFSET_SCALE_Y = 5;
106
+ export const BUILTIN_OFFSET_ROTATION = 6;
107
+ export const BUILTIN_OFFSET_TORQUE = 7;
108
+ export const BUILTIN_OFFSET_LIFETIME = 8;
109
+ export const BUILTIN_OFFSET_AGE = 9;
110
+ export const BUILTIN_OFFSET_RANDOM_A = 10;
111
+ export const BUILTIN_OFFSET_RANDOM_B = 11;
112
+ export const BUILTIN_OFFSET_RANDOM_C = 12;
113
+ export const BUILTIN_OFFSET_RANDOM_D = 13;
114
+ export const BUILTIN_OFFSET_RANDOM_E = 14;
115
+ export const BUILTIN_OFFSET_RANDOM_F = 15;
@@ -0,0 +1,39 @@
1
+ import type { DataTexture } from "three";
2
+ import type { UIColor } from "../../core";
3
+ import type { UIProperty, UIPropertyName } from "../../core/miscellaneous/generic-plane/shared";
4
+ import { buildGradientTexture } from "../miscellaneous/miscellaneous";
5
+ import source from "../shaders/UIRenderingColorOverLife.glsl";
6
+ import { UIRenderingModule } from "./UIRenderingModule";
7
+
8
+ /**
9
+ * Colors particles based on lifetime progression.
10
+ *
11
+ * Interpolates through color gradient as particles age from birth to death.
12
+ */
13
+ export class UIRenderingColorOverLife extends UIRenderingModule {
14
+ /** @internal */
15
+ public override readonly requiredProperties: Record<string, UIPropertyName> = {
16
+ builtin: "Matrix4",
17
+ } as const;
18
+ /** @internal */
19
+ public readonly requiredUniforms: Record<string, UIProperty>;
20
+ /** @internal */
21
+ public readonly source = source;
22
+
23
+ /**
24
+ * @param colors - Color gradient stops from birth to death
25
+ */
26
+ constructor(colors: UIColor[]) {
27
+ super();
28
+
29
+ if (colors.length === 0) {
30
+ throw new Error("UIRenderingColorOverLife: colors array cannot be empty");
31
+ }
32
+
33
+ this.requiredUniforms = { colorOverLifeTexture: buildGradientTexture(colors) };
34
+ }
35
+
36
+ public override destroy(): void {
37
+ (this.requiredUniforms.colorOverLifeTexture as DataTexture).dispose();
38
+ }
39
+ }
@@ -0,0 +1,49 @@
1
+ import type { DataTexture } from "three";
2
+ import type { UIColor } from "../../core";
3
+ import type { UIProperty, UIPropertyName } from "../../core/miscellaneous/generic-plane/shared";
4
+ import { buildGradientTexture } from "../miscellaneous/miscellaneous";
5
+ import source from "../shaders/UIRenderingColorOverVelocity.glsl";
6
+ import { UIRenderingModule } from "./UIRenderingModule";
7
+
8
+ /**
9
+ * Colors particles based on velocity magnitude.
10
+ *
11
+ * Maps velocity from 0 to maxVelocity across the color gradient.
12
+ */
13
+ export class UIRenderingColorOverVelocity extends UIRenderingModule {
14
+ /** @internal */
15
+ public override readonly requiredProperties: Record<string, UIPropertyName> = {
16
+ builtin: "Matrix4",
17
+ } as const;
18
+ /** @internal */
19
+ public readonly requiredUniforms: Record<string, UIProperty>;
20
+ /** @internal */
21
+ public readonly source = source;
22
+
23
+ /**
24
+ * @param colors - Color gradient from slow to fast
25
+ * @param maxVelocity - Velocity mapped to final color
26
+ */
27
+ constructor(colors: UIColor[], maxVelocity: number) {
28
+ super();
29
+
30
+ if (colors.length === 0) {
31
+ throw new Error("UIRenderingColorOverVelocity: colors array cannot be empty");
32
+ }
33
+
34
+ if (maxVelocity <= 0) {
35
+ throw new Error("UIRenderingColorOverVelocity: maxVelocity must be greater than 0");
36
+ }
37
+
38
+ this.source = source.replace(
39
+ "COLOR_OVER_VELOCITY_MAX",
40
+ `COLOR_OVER_VELOCITY_MAX ${maxVelocity.toFixed(2)}`,
41
+ );
42
+
43
+ this.requiredUniforms = { colorOverVelocityTexture: buildGradientTexture(colors) } as const;
44
+ }
45
+
46
+ public override destroy(): void {
47
+ (this.requiredUniforms.colorOverVelocityTexture as DataTexture).dispose();
48
+ }
49
+ }
@@ -0,0 +1,17 @@
1
+ import type { UIProperty, UIPropertyName } from "../../core/miscellaneous/generic-plane/shared";
2
+
3
+ /**
4
+ * Base class for particle rendering modules.
5
+ *
6
+ * Rendering modules provide fragment shader code and uniforms for particle appearance.
7
+ */
8
+ export abstract class UIRenderingModule {
9
+ /** @internal */
10
+ public readonly requiredProperties?: Record<string, UIPropertyName>;
11
+ /** @internal */
12
+ public abstract readonly requiredUniforms: Record<string, UIProperty>;
13
+ /** @internal */
14
+ public abstract readonly source: string;
15
+
16
+ public destroy?(): void;
17
+ }
@@ -0,0 +1,30 @@
1
+ import type { UIProperty } from "../../core/miscellaneous/generic-plane/shared";
2
+ import { UITextureView } from "../../core/miscellaneous/texture/UITextureView";
3
+ import type { UITextureConfig } from "../../core/miscellaneous/texture/UITextureView.Internal";
4
+ import source from "../shaders/UIRenderingTexture.glsl";
5
+ import { UIRenderingModule } from "./UIRenderingModule";
6
+
7
+ /**
8
+ * Renders particles with a texture.
9
+ *
10
+ * Samples the texture using particle UV coordinates.
11
+ */
12
+ export class UITextureRenderingModule extends UIRenderingModule {
13
+ /** @internal */
14
+ public readonly requiredUniforms: Record<string, UIProperty>;
15
+ /** @internal */
16
+ public readonly source = source;
17
+ private readonly texture: UITextureView;
18
+
19
+ /**
20
+ * @param config - Texture configuration
21
+ */
22
+ constructor(config: UITextureConfig) {
23
+ super();
24
+ this.texture = new UITextureView(config);
25
+ this.requiredUniforms = {
26
+ texture: this.texture.texture,
27
+ textureTransform: this.texture.calculateUVTransform(),
28
+ };
29
+ }
30
+ }
@@ -0,0 +1,4 @@
1
+ vec4 draw() {
2
+ float t = clamp(PARTICLE_AGE / PARTICLE_LIFETIME, 0.0, 1.0);
3
+ return srgbTexture2D(p_colorOverLifeTexture, vec2(t, 0.5));
4
+ }
@@ -0,0 +1,6 @@
1
+ #define COLOR_OVER_VELOCITY_MAX // will be replaced with COLOR_OVER_VELOCITY_MAX <value>
2
+
3
+ vec4 draw() {
4
+ float t = clamp(length(vec2(PARTICLE_VELOCITY_X, PARTICLE_VELOCITY_Y)) / COLOR_OVER_VELOCITY_MAX, 0.0, 1.0);
5
+ return srgbTexture2D(p_colorOverVelocityTexture, vec2(t, 0.5));
6
+ }
@@ -0,0 +1,4 @@
1
+ vec4 draw() {
2
+ vec2 transformedUV = (p_textureTransform * vec3(p_uv, 1.0)).xy;
3
+ return srgbTexture2D(p_texture, transformedUV);
4
+ }
@@ -0,0 +1,22 @@
1
+ import type { InstancedBufferAttribute } from "three";
2
+ import type { UIPropertyName } from "../../core/miscellaneous/generic-plane/shared";
3
+
4
+ /**
5
+ * Base class for particle spawn modules.
6
+ *
7
+ * Spawn modules initialize particle properties when particles are created.
8
+ */
9
+ export abstract class UISpawnModule<
10
+ T extends Record<string, UIPropertyName> = Record<string, UIPropertyName>,
11
+ > {
12
+ /** @internal */
13
+ public abstract readonly requiredProperties: T;
14
+ /** @internal */
15
+ public abstract spawn(
16
+ properties: { [K in keyof T]: InstancedBufferAttribute },
17
+ instanceBegin: number,
18
+ instanceEnd: number,
19
+ ): void;
20
+
21
+ public destroy?(): void;
22
+ }
@@ -0,0 +1,62 @@
1
+ import type { InstancedBufferAttribute } from "three";
2
+ import { assertValidNumber } from "../../core/miscellaneous/asserts";
3
+ import type { Vector2Like } from "../../core/miscellaneous/math";
4
+ import {
5
+ BUILTIN_OFFSET_POSITION_X,
6
+ BUILTIN_OFFSET_POSITION_Y,
7
+ resolveUIVector2Config,
8
+ type UIVector2Config,
9
+ } from "../miscellaneous/miscellaneous";
10
+ import { UISpawnModule } from "./UISpawnModule";
11
+
12
+ /**
13
+ * Sets particle spawn position offset.
14
+ *
15
+ * All particles spawned with this module start at the specified position.
16
+ */
17
+ export class UISpawnOffset extends UISpawnModule<{ builtin: "Matrix4" }> {
18
+ /** @internal */
19
+ public readonly requiredProperties = { builtin: "Matrix4" } as const;
20
+ private offsetInternal: Vector2Like;
21
+
22
+ /**
23
+ * @param offset - Initial particle position offset
24
+ */
25
+ constructor(offset: UIVector2Config = { x: 0, y: 0 }) {
26
+ super();
27
+ this.offsetInternal = resolveUIVector2Config(offset);
28
+ assertValidNumber(this.offsetInternal.x, "UISpawnOffset.constructor.offset.x");
29
+ assertValidNumber(this.offsetInternal.y, "UISpawnOffset.constructor.offset.y");
30
+ }
31
+
32
+ /** Particle position offset */
33
+ public get offset(): Vector2Like {
34
+ return this.offsetInternal;
35
+ }
36
+
37
+ /** Particle position offset */
38
+ public set offset(value: UIVector2Config) {
39
+ this.offsetInternal = resolveUIVector2Config(value);
40
+ assertValidNumber(this.offsetInternal.x, "UISpawnOffset.offset.x");
41
+ assertValidNumber(this.offsetInternal.y, "UISpawnOffset.offset.y");
42
+ }
43
+
44
+ /** @internal */
45
+ public spawn(
46
+ properties: { builtin: InstancedBufferAttribute },
47
+ instanceBegin: number,
48
+ instanceEnd: number,
49
+ ): void {
50
+ const { builtin } = properties;
51
+ const { array, itemSize } = builtin;
52
+ const { x: offsetX, y: offsetY } = this.offsetInternal;
53
+
54
+ for (let i = instanceBegin; i < instanceEnd; i++) {
55
+ const itemOffset = i * itemSize;
56
+ array[itemOffset + BUILTIN_OFFSET_POSITION_X] = offsetX;
57
+ array[itemOffset + BUILTIN_OFFSET_POSITION_Y] = offsetY;
58
+ }
59
+
60
+ builtin.needsUpdate = true;
61
+ }
62
+ }
@@ -0,0 +1,68 @@
1
+ import type { InstancedBufferAttribute } from "three";
2
+ import { MathUtils } from "three";
3
+ import { assertValidPositiveNumber } from "../../core/miscellaneous/asserts";
4
+ import type { UIRange, UIRangeConfig } from "../miscellaneous/miscellaneous";
5
+ import {
6
+ BUILTIN_OFFSET_AGE,
7
+ BUILTIN_OFFSET_LIFETIME,
8
+ resolveUIRangeConfig,
9
+ } from "../miscellaneous/miscellaneous";
10
+ import { UISpawnModule } from "./UISpawnModule";
11
+
12
+ /**
13
+ * Assigns random lifetime to particles.
14
+ *
15
+ * Lifetime is chosen uniformly from the specified range. Age is set to 0.
16
+ */
17
+ export class UISpawnRandomLifetime extends UISpawnModule<{ builtin: "Matrix4" }> {
18
+ /** @internal */
19
+ public readonly requiredProperties = { builtin: "Matrix4" } as const;
20
+ private lifetimeInternal: UIRange;
21
+
22
+ /**
23
+ * @param lifetime - Lifetime range in seconds. Accepts number, tuple, or range object
24
+ */
25
+ constructor(lifetime: UIRangeConfig = { min: 4, max: 8 }) {
26
+ super();
27
+ this.lifetimeInternal = resolveUIRangeConfig(lifetime);
28
+ assertValidPositiveNumber(
29
+ this.lifetimeInternal.min,
30
+ "UISpawnRandomLifetime.constructor.lifetime.min",
31
+ );
32
+ assertValidPositiveNumber(
33
+ this.lifetimeInternal.max,
34
+ "UISpawnRandomLifetime.constructor.lifetime.max",
35
+ );
36
+ }
37
+
38
+ /** Lifetime range in seconds */
39
+ public get lifetime(): UIRange {
40
+ return this.lifetimeInternal;
41
+ }
42
+
43
+ /** Lifetime range in seconds */
44
+ public set lifetime(value: UIRangeConfig) {
45
+ this.lifetimeInternal = resolveUIRangeConfig(value);
46
+ assertValidPositiveNumber(this.lifetimeInternal.min, "UISpawnRandomLifetime.lifetime.min");
47
+ assertValidPositiveNumber(this.lifetimeInternal.max, "UISpawnRandomLifetime.lifetime.max");
48
+ }
49
+
50
+ /** @internal */
51
+ public spawn(
52
+ properties: { builtin: InstancedBufferAttribute },
53
+ instanceBegin: number,
54
+ instanceEnd: number,
55
+ ): void {
56
+ const { builtin } = properties;
57
+ const { array, itemSize } = builtin;
58
+ const { min: lifetimeMin, max: lifetimeMax } = this.lifetimeInternal;
59
+
60
+ for (let i = instanceBegin; i < instanceEnd; i++) {
61
+ const itemOffset = i * itemSize;
62
+ array[itemOffset + BUILTIN_OFFSET_LIFETIME] = MathUtils.randFloat(lifetimeMin, lifetimeMax);
63
+ array[itemOffset + BUILTIN_OFFSET_AGE] = 0;
64
+ }
65
+
66
+ builtin.needsUpdate = true;
67
+ }
68
+ }
@@ -0,0 +1,60 @@
1
+ import type { InstancedBufferAttribute } from "three";
2
+ import { MathUtils } from "three";
3
+ import { assertValidNumber } from "../../core/miscellaneous/asserts";
4
+ import {
5
+ BUILTIN_OFFSET_ROTATION,
6
+ resolveUIRangeConfig,
7
+ type UIRange,
8
+ type UIRangeConfig,
9
+ } from "../miscellaneous/miscellaneous";
10
+ import { UISpawnModule } from "./UISpawnModule";
11
+
12
+ /**
13
+ * Assigns random rotation to particles.
14
+ *
15
+ * Initial rotation is chosen uniformly from the specified range.
16
+ */
17
+ export class UISpawnRandomRotation extends UISpawnModule<{ builtin: "Matrix4" }> {
18
+ /** @internal */
19
+ public requiredProperties = { builtin: "Matrix4" } as const;
20
+ private rotationInternal: UIRange;
21
+
22
+ /**
23
+ * @param rotation - Rotation range in radians. Accepts number, tuple, or range object
24
+ */
25
+ constructor(rotation: UIRangeConfig = { min: -Math.PI, max: Math.PI }) {
26
+ super();
27
+ this.rotationInternal = resolveUIRangeConfig(rotation);
28
+ assertValidNumber(this.rotationInternal.min, "UISpawnRandomRotation.constructor.rotation.min");
29
+ assertValidNumber(this.rotationInternal.max, "UISpawnRandomRotation.constructor.rotation.max");
30
+ }
31
+
32
+ /** Rotation range in radians */
33
+ public get rotation(): UIRange {
34
+ return this.rotationInternal;
35
+ }
36
+
37
+ /** Rotation range in radians */
38
+ public set rotation(value: UIRangeConfig) {
39
+ this.rotationInternal = resolveUIRangeConfig(value);
40
+ assertValidNumber(this.rotationInternal.min, "UISpawnRandomRotation.rotation.min");
41
+ assertValidNumber(this.rotationInternal.max, "UISpawnRandomRotation.rotation.max");
42
+ }
43
+
44
+ /** @internal */
45
+ public spawn(
46
+ properties: { builtin: InstancedBufferAttribute },
47
+ instanceBegin: number,
48
+ instanceEnd: number,
49
+ ): void {
50
+ const { builtin } = properties;
51
+ const { array, itemSize } = builtin;
52
+ const { min: rotationMin, max: rotationMax } = this.rotationInternal;
53
+
54
+ for (let i = instanceBegin; i < instanceEnd; i++) {
55
+ array[i * itemSize + BUILTIN_OFFSET_ROTATION] = MathUtils.randFloat(rotationMin, rotationMax);
56
+ }
57
+
58
+ builtin.needsUpdate = true;
59
+ }
60
+ }