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,524 @@
1
+ import type { InstancedBufferGeometry, ShaderMaterial } from "three";
2
+ import { InstancedBufferAttribute, Matrix4, Mesh } from "three";
3
+ import type { UITransparencyMode } from "../../UITransparencyMode";
4
+ import type { GLProperty, PlaneData } from "../shared";
5
+ import {
6
+ arePropertiesPartiallyCompatible,
7
+ cloneGLProperties,
8
+ cloneProperty,
9
+ extractZIndexFromBuffer,
10
+ resolveGLSLTypeInfo,
11
+ resolvePropertyUniform,
12
+ } from "../shared";
13
+ import {
14
+ buildEmptyInstancedBufferAttribute,
15
+ buildMaterial,
16
+ CAPACITY_STEP,
17
+ copyBetweenBuffers,
18
+ INITIAL_CAPACITY,
19
+ INSTANCED_PLANE_GEOMETRY,
20
+ reconstructValue,
21
+ shiftBufferRegion,
22
+ writePropertyToArray,
23
+ } from "./UIGenericInstancedPlane.Internal";
24
+
25
+ /**
26
+ * Instanced shader plane mesh for batched rendering.
27
+ *
28
+ * Operates on indices, not handlers. Registry manages handler→index mapping.
29
+ * Elements are ordered by zIndex (ascending) within the buffer.
30
+ *
31
+ * @internal
32
+ */
33
+ export class UIGenericInstancedPlane extends Mesh {
34
+ public readonly source: string;
35
+ public readonly transparency: UITransparencyMode;
36
+
37
+ private readonly instancedGeometry: InstancedBufferGeometry;
38
+ private readonly shaderMaterial: ShaderMaterial;
39
+ private readonly uniformProperties: Record<string, GLProperty>;
40
+ private readonly varyingProperties: Record<string, GLProperty>;
41
+ private readonly propertyBuffers: Map<string, InstancedBufferAttribute>;
42
+
43
+ private capacity: number;
44
+ private instancesCountInternal: number;
45
+
46
+ constructor(
47
+ source: string,
48
+ properties: Record<string, GLProperty>,
49
+ transparency: UITransparencyMode,
50
+ initialCapacity: number = INITIAL_CAPACITY,
51
+ ) {
52
+ const uniformProperties: Record<string, GLProperty> = {};
53
+ const varyingProperties: Record<string, GLProperty> = {
54
+ instanceVisibility: {
55
+ value: 1,
56
+ glslTypeInfo: resolveGLSLTypeInfo("number"),
57
+ },
58
+ instanceTransform: {
59
+ value: new Matrix4().identity(),
60
+ glslTypeInfo: resolveGLSLTypeInfo("Matrix4"),
61
+ },
62
+ };
63
+
64
+ for (const name in properties) {
65
+ const descriptor = properties[name];
66
+ if (descriptor.glslTypeInfo.instantiable) {
67
+ varyingProperties[name] = descriptor;
68
+ } else {
69
+ uniformProperties[name] = descriptor;
70
+ }
71
+ }
72
+
73
+ const instancedGeometry = INSTANCED_PLANE_GEOMETRY.clone();
74
+ const shaderMaterial = buildMaterial(
75
+ source,
76
+ uniformProperties,
77
+ varyingProperties,
78
+ transparency,
79
+ );
80
+
81
+ super(instancedGeometry, shaderMaterial);
82
+
83
+ this.frustumCulled = false;
84
+ this.matrixAutoUpdate = false;
85
+ this.matrixWorldAutoUpdate = false;
86
+
87
+ this.source = source;
88
+ this.transparency = transparency;
89
+ this.instancedGeometry = instancedGeometry;
90
+ this.shaderMaterial = shaderMaterial;
91
+ this.uniformProperties = uniformProperties;
92
+ this.varyingProperties = varyingProperties;
93
+ this.propertyBuffers = new Map();
94
+
95
+ this.capacity = Math.max(
96
+ Math.ceil(initialCapacity / CAPACITY_STEP) * CAPACITY_STEP,
97
+ CAPACITY_STEP,
98
+ );
99
+ this.instancesCountInternal = 0;
100
+ this.instancedGeometry.instanceCount = 0;
101
+
102
+ for (const name in this.varyingProperties) {
103
+ const { value } = this.varyingProperties[name];
104
+ const attribute = buildEmptyInstancedBufferAttribute(value, this.capacity);
105
+ this.instancedGeometry.setAttribute(`a_${name}`, attribute);
106
+ this.propertyBuffers.set(name, attribute);
107
+ }
108
+
109
+ for (const name in this.uniformProperties) {
110
+ const { value } = this.uniformProperties[name];
111
+ const uniform = resolvePropertyUniform(name, this.shaderMaterial);
112
+ uniform.value = value;
113
+ }
114
+ this.shaderMaterial.uniformsNeedUpdate = true;
115
+ }
116
+
117
+ /** Current number of active instances */
118
+ public get instancesCount(): number {
119
+ return this.instancesCountInternal;
120
+ }
121
+
122
+ /**
123
+ * Insert instance at given index. Elements at [index..end) are shifted right.
124
+ */
125
+ public insertAt(
126
+ index: number,
127
+ properties: Record<string, GLProperty>,
128
+ transform: Matrix4,
129
+ visibility: boolean,
130
+ ): void {
131
+ if (index < 0 || index > this.instancesCountInternal) {
132
+ throw new Error(
133
+ `UIGenericInstancedPlane.insertAt.index: out of bounds (index=${index}, count=${this.instancesCountInternal})`,
134
+ );
135
+ }
136
+
137
+ this.ensureCapacity(this.instancesCountInternal + 1);
138
+
139
+ if (index < this.instancesCountInternal) {
140
+ this.shiftBuffersRight(index, 1);
141
+ }
142
+
143
+ this.writeToBuffers(index, properties, transform, visibility);
144
+
145
+ this.instancesCountInternal++;
146
+ this.instancedGeometry.instanceCount = this.instancesCountInternal;
147
+ }
148
+
149
+ /**
150
+ * Remove instance at given index. Elements at [index+1..end) are shifted left.
151
+ */
152
+ public removeAt(index: number): void {
153
+ if (index < 0 || index >= this.instancesCountInternal) {
154
+ throw new Error(
155
+ `UIGenericInstancedPlane.removeAt.index: out of bounds (index=${index}, count=${this.instancesCountInternal})`,
156
+ );
157
+ }
158
+
159
+ if (index < this.instancesCountInternal - 1) {
160
+ this.shiftBuffersLeft(index + 1, 1);
161
+ }
162
+
163
+ this.instancesCountInternal--;
164
+ this.instancedGeometry.instanceCount = this.instancesCountInternal;
165
+ }
166
+
167
+ /** Update properties at given index */
168
+ public setPropertiesAt(index: number, properties: Record<string, GLProperty>): void {
169
+ if (index < 0 || index >= this.instancesCountInternal) {
170
+ throw new Error(
171
+ `UIGenericInstancedPlane.setPropertiesAt.index: out of bounds (index=${index}, count=${this.instancesCountInternal})`,
172
+ );
173
+ }
174
+
175
+ for (const name in properties) {
176
+ const { value, glslTypeInfo } = properties[name];
177
+
178
+ if (glslTypeInfo.instantiable) {
179
+ const attribute = this.resolveAttribute(name);
180
+ const offset = index * attribute.itemSize;
181
+ writePropertyToArray(value, attribute.array as Float32Array, offset);
182
+ attribute.needsUpdate = true;
183
+ } else {
184
+ const uniform = resolvePropertyUniform(name, this.shaderMaterial);
185
+ uniform.value = value;
186
+ this.shaderMaterial.uniformsNeedUpdate = true;
187
+ }
188
+ }
189
+ }
190
+
191
+ /** Update transform at given index */
192
+ public setTransformAt(index: number, transform: Matrix4): void {
193
+ if (index < 0 || index >= this.instancesCountInternal) {
194
+ throw new Error(
195
+ `UIGenericInstancedPlane.setTransformAt.index: out of bounds (index=${index}, count=${this.instancesCountInternal})`,
196
+ );
197
+ }
198
+
199
+ const attribute = this.resolveAttribute("instanceTransform");
200
+ const array = attribute.array as Float32Array;
201
+ const offset = index * 16;
202
+
203
+ const elements = transform.elements;
204
+ for (let j = 0; j < 16; j++) {
205
+ array[offset + j] = elements[j];
206
+ }
207
+ attribute.needsUpdate = true;
208
+ }
209
+
210
+ /** Update visibility at given index */
211
+ public setVisibilityAt(index: number, visible: boolean): void {
212
+ if (index < 0 || index >= this.instancesCountInternal) {
213
+ throw new Error(
214
+ `UIGenericInstancedPlane.setVisibilityAt.index: out of bounds (index=${index}, count=${this.instancesCountInternal})`,
215
+ );
216
+ }
217
+
218
+ const attribute = this.resolveAttribute("instanceVisibility");
219
+ const array = attribute.array as Float32Array;
220
+ array[index] = visible ? 1 : 0;
221
+ attribute.needsUpdate = true;
222
+ }
223
+
224
+ /**
225
+ * Extract complete instance data at given index.
226
+ * Returns cloned data safe for external use.
227
+ */
228
+ public extractDataAt(index: number): PlaneData {
229
+ if (index < 0 || index >= this.instancesCountInternal) {
230
+ throw new Error(
231
+ `UIGenericInstancedPlane.extractDataAt.index: out of bounds (index=${index}, count=${this.instancesCountInternal})`,
232
+ );
233
+ }
234
+
235
+ const properties: Record<string, GLProperty> = {};
236
+
237
+ for (const name in this.uniformProperties) {
238
+ const prop = this.uniformProperties[name];
239
+ properties[name] = {
240
+ value: cloneProperty(prop.value),
241
+ glslTypeInfo: prop.glslTypeInfo,
242
+ };
243
+ }
244
+
245
+ for (const name in this.varyingProperties) {
246
+ if (name === "instanceVisibility" || name === "instanceTransform") {
247
+ continue;
248
+ }
249
+
250
+ const { value, glslTypeInfo } = this.varyingProperties[name];
251
+ const attribute = this.propertyBuffers.get(name) as InstancedBufferAttribute;
252
+ const array = attribute.array as Float32Array;
253
+ const offset = index * attribute.itemSize;
254
+
255
+ properties[name] = {
256
+ value: reconstructValue(value, array, offset),
257
+ glslTypeInfo,
258
+ };
259
+ }
260
+
261
+ const transformAttribute = this.propertyBuffers.get(
262
+ "instanceTransform",
263
+ ) as InstancedBufferAttribute;
264
+ const transformArray = transformAttribute.array as Float32Array;
265
+ const transform = new Matrix4();
266
+ transform.fromArray(transformArray, index * 16);
267
+
268
+ const visibilityAttribute = this.propertyBuffers.get(
269
+ "instanceVisibility",
270
+ ) as InstancedBufferAttribute;
271
+ const visibilityArray = visibilityAttribute.array as Float32Array;
272
+ const visibility = visibilityArray[index] >= 0.5;
273
+
274
+ return {
275
+ source: this.source,
276
+ properties,
277
+ transform,
278
+ visibility,
279
+ transparency: this.transparency,
280
+ };
281
+ }
282
+
283
+ /** Get zIndex at given index (from transform buffer) */
284
+ public getZIndexAt(index: number): number {
285
+ if (index < 0 || index >= this.instancesCountInternal) {
286
+ throw new Error(
287
+ `UIGenericInstancedPlane.getZIndexAt.index: out of bounds (index=${index}, count=${this.instancesCountInternal})`,
288
+ );
289
+ }
290
+
291
+ const attribute = this.propertyBuffers.get("instanceTransform") as InstancedBufferAttribute;
292
+ return extractZIndexFromBuffer(attribute.array as Float32Array, index);
293
+ }
294
+
295
+ /**
296
+ * Merge another instanced plane into this one (append).
297
+ * Other plane becomes empty after merge.
298
+ */
299
+ public merge(other: UIGenericInstancedPlane): void {
300
+ if (other.instancesCountInternal === 0) {
301
+ return;
302
+ }
303
+
304
+ this.ensureCapacity(this.instancesCountInternal + other.instancesCountInternal);
305
+
306
+ for (const [name, thisAttribute] of this.propertyBuffers) {
307
+ const otherAttribute = other.propertyBuffers.get(name);
308
+ if (!otherAttribute) {
309
+ throw new Error(`UIGenericInstancedPlane.merge: missing attribute ${name} in source`);
310
+ }
311
+
312
+ const itemSize = thisAttribute.itemSize;
313
+ const srcArray = otherAttribute.array as Float32Array;
314
+ const dstArray = thisAttribute.array as Float32Array;
315
+
316
+ copyBetweenBuffers(
317
+ srcArray,
318
+ 0,
319
+ dstArray,
320
+ this.instancesCountInternal * itemSize,
321
+ other.instancesCountInternal * itemSize,
322
+ );
323
+
324
+ thisAttribute.needsUpdate = true;
325
+ }
326
+
327
+ this.instancesCountInternal += other.instancesCountInternal;
328
+ this.instancedGeometry.instanceCount = this.instancesCountInternal;
329
+
330
+ other.instancesCountInternal = 0;
331
+ other.instancedGeometry.instanceCount = 0;
332
+ }
333
+
334
+ /**
335
+ * Split this plane at given index.
336
+ * Returns new plane with elements [atIndex..end).
337
+ * This plane keeps elements [0..atIndex).
338
+ */
339
+ public split(atIndex: number): UIGenericInstancedPlane {
340
+ if (atIndex <= 0 || atIndex >= this.instancesCountInternal) {
341
+ throw new Error(
342
+ `UIGenericInstancedPlane.split.atIndex: must be in range (0, count) (atIndex=${atIndex}, count=${this.instancesCountInternal})`,
343
+ );
344
+ }
345
+
346
+ const tailCount = this.instancesCountInternal - atIndex;
347
+
348
+ const newPlane = new UIGenericInstancedPlane(
349
+ this.source,
350
+ cloneGLProperties({
351
+ ...this.uniformProperties,
352
+ ...this.varyingProperties,
353
+ }),
354
+ this.transparency,
355
+ tailCount,
356
+ );
357
+
358
+ for (const [name, thisAttribute] of this.propertyBuffers) {
359
+ const newAttribute = newPlane.propertyBuffers.get(name);
360
+ if (!newAttribute) {
361
+ throw new Error(`UIGenericInstancedPlane.split: missing attribute ${name} in new plane`);
362
+ }
363
+
364
+ const itemSize = thisAttribute.itemSize;
365
+ const srcArray = thisAttribute.array as Float32Array;
366
+ const dstArray = newAttribute.array as Float32Array;
367
+
368
+ copyBetweenBuffers(srcArray, atIndex * itemSize, dstArray, 0, tailCount * itemSize);
369
+
370
+ newAttribute.needsUpdate = true;
371
+ }
372
+
373
+ newPlane.instancesCountInternal = tailCount;
374
+ newPlane.instancedGeometry.instanceCount = tailCount;
375
+
376
+ this.instancesCountInternal = atIndex;
377
+ this.instancedGeometry.instanceCount = atIndex;
378
+
379
+ return newPlane;
380
+ }
381
+
382
+ /**
383
+ * Check if this plane can accept elements with given parameters.
384
+ */
385
+ public isCompatibleWith(
386
+ source: string,
387
+ properties: Record<string, GLProperty>,
388
+ transparency: UITransparencyMode,
389
+ ): boolean {
390
+ if (this.source !== source) {
391
+ return false;
392
+ }
393
+
394
+ if (this.transparency !== transparency) {
395
+ return false;
396
+ }
397
+
398
+ const result = arePropertiesPartiallyCompatible(
399
+ { ...this.uniformProperties, ...this.varyingProperties },
400
+ properties,
401
+ );
402
+
403
+ return result;
404
+ }
405
+
406
+ /** Get all properties configuration (for compatibility checks) */
407
+ public getProperties(): Record<string, GLProperty> {
408
+ return { ...this.uniformProperties, ...this.varyingProperties };
409
+ }
410
+
411
+ /** Remove all instances, reset to empty state */
412
+ public clearInstances(): void {
413
+ this.instancesCountInternal = 0;
414
+ this.instancedGeometry.instanceCount = 0;
415
+ }
416
+
417
+ /** Dispose geometry, material, and clear buffers */
418
+ public destroy(): void {
419
+ this.instancedGeometry.dispose();
420
+ this.shaderMaterial.dispose();
421
+ this.propertyBuffers.clear();
422
+ }
423
+
424
+ private ensureCapacity(requiredCapacity: number): void {
425
+ if (requiredCapacity <= this.capacity) {
426
+ return;
427
+ }
428
+
429
+ const newCapacity = Math.ceil(requiredCapacity / CAPACITY_STEP) * CAPACITY_STEP;
430
+
431
+ for (const [name, oldAttribute] of this.propertyBuffers) {
432
+ const itemSize = oldAttribute.itemSize;
433
+ const newArray = new Float32Array(newCapacity * itemSize);
434
+ newArray.set(oldAttribute.array as Float32Array);
435
+
436
+ const newAttribute = new InstancedBufferAttribute(newArray, itemSize);
437
+ this.instancedGeometry.setAttribute(`a_${name}`, newAttribute);
438
+ this.propertyBuffers.set(name, newAttribute);
439
+ }
440
+
441
+ this.capacity = newCapacity;
442
+ }
443
+
444
+ private shiftBuffersRight(fromIndex: number, delta: number): void {
445
+ const elementsToMove = this.instancesCountInternal - fromIndex;
446
+ if (elementsToMove <= 0) {
447
+ return;
448
+ }
449
+
450
+ for (const attribute of this.propertyBuffers.values()) {
451
+ shiftBufferRegion(
452
+ attribute.array as Float32Array,
453
+ attribute.itemSize,
454
+ fromIndex,
455
+ elementsToMove,
456
+ delta,
457
+ );
458
+ attribute.needsUpdate = true;
459
+ }
460
+ }
461
+
462
+ private shiftBuffersLeft(fromIndex: number, delta: number): void {
463
+ const elementsToMove = this.instancesCountInternal - fromIndex;
464
+ if (elementsToMove <= 0) {
465
+ return;
466
+ }
467
+
468
+ for (const attribute of this.propertyBuffers.values()) {
469
+ shiftBufferRegion(
470
+ attribute.array as Float32Array,
471
+ attribute.itemSize,
472
+ fromIndex,
473
+ elementsToMove,
474
+ -delta,
475
+ );
476
+ attribute.needsUpdate = true;
477
+ }
478
+ }
479
+
480
+ private writeToBuffers(
481
+ index: number,
482
+ properties: Record<string, GLProperty>,
483
+ transform: Matrix4,
484
+ visibility: boolean,
485
+ ): void {
486
+ const visibilityAttribute = this.resolveAttribute("instanceVisibility");
487
+ (visibilityAttribute.array as Float32Array)[index] = visibility ? 1 : 0;
488
+ visibilityAttribute.needsUpdate = true;
489
+
490
+ const transformAttribute = this.resolveAttribute("instanceTransform");
491
+ const transformArray = transformAttribute.array as Float32Array;
492
+ const transformOffset = index * 16;
493
+ const elements = transform.elements;
494
+ for (let j = 0; j < 16; j++) {
495
+ transformArray[transformOffset + j] = elements[j];
496
+ }
497
+ transformAttribute.needsUpdate = true;
498
+
499
+ for (const name in properties) {
500
+ const { value, glslTypeInfo } = properties[name];
501
+
502
+ if (glslTypeInfo.instantiable) {
503
+ const attribute = this.propertyBuffers.get(name);
504
+ if (attribute) {
505
+ const offset = index * attribute.itemSize;
506
+ writePropertyToArray(value, attribute.array as Float32Array, offset);
507
+ attribute.needsUpdate = true;
508
+ }
509
+ } else {
510
+ const uniform = resolvePropertyUniform(name, this.shaderMaterial);
511
+ uniform.value = value;
512
+ this.shaderMaterial.uniformsNeedUpdate = true;
513
+ }
514
+ }
515
+ }
516
+
517
+ private resolveAttribute(name: string): InstancedBufferAttribute {
518
+ const attribute = this.propertyBuffers.get(name);
519
+ if (attribute === undefined) {
520
+ throw new Error(`UIGenericInstancedPlane.resolveAttribute.name: unknown attribute "${name}"`);
521
+ }
522
+ return attribute;
523
+ }
524
+ }
@@ -2,15 +2,17 @@ import type { Matrix4 } from "three";
2
2
  import type { UITransparencyMode } from "../../UITransparencyMode";
3
3
  import type { GLProperty } from "../shared";
4
4
  import type { UIGenericInstancedPlane } from "../UIGenericInstancedPlane/UIGenericInstancedPlane";
5
+
5
6
  export interface PlaneDescriptor {
6
- mesh: UIGenericInstancedPlane;
7
- instanceIndex: number;
7
+ mesh: UIGenericInstancedPlane;
8
+ instanceIndex: number;
8
9
  }
10
+
9
11
  export interface PlaneState {
10
- source: string;
11
- properties: Record<string, GLProperty>;
12
- transform: Matrix4;
13
- visibility: boolean;
14
- transparency: UITransparencyMode;
15
- zIndex: number;
12
+ source: string;
13
+ properties: Record<string, GLProperty>;
14
+ transform: Matrix4;
15
+ visibility: boolean;
16
+ transparency: UITransparencyMode;
17
+ zIndex: number;
16
18
  }