laymur 0.19.3 → 0.20.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.
@@ -8,7 +8,7 @@ export { UIBehaviorVelocityNoise } from "./behaviorModules/UIBehaviorVelocityNoi
8
8
  export { UIEmitter } from "./elements/UIEmitter";
9
9
  export { UIRenderingColorOverLife } from "./renderingModules/UIRenderingColorOverLife";
10
10
  export { UIRenderingColorOverVelocity } from "./renderingModules/UIRenderingColorOverVelocity";
11
- export { UITextureRenderingModule } from "./renderingModules/UIRenderingTexture";
11
+ export { UIRenderingTexture } from "./renderingModules/UIRenderingTexture";
12
12
  export { UISpawnOffset } from "./spawnModules/UISpawnOffset";
13
13
  export { UISpawnRandomLifetime } from "./spawnModules/UISpawnRandomLifetime";
14
14
  export { UISpawnRandomRotation } from "./spawnModules/UISpawnRandomRotation";
@@ -8,7 +8,7 @@ export { UIBehaviorVelocityNoise } from './behaviorModules/UIBehaviorVelocityNoi
8
8
  export { UIEmitter } from './elements/UIEmitter.js';
9
9
  export { UIRenderingColorOverLife } from './renderingModules/UIRenderingColorOverLife.js';
10
10
  export { UIRenderingColorOverVelocity } from './renderingModules/UIRenderingColorOverVelocity.js';
11
- export { UITextureRenderingModule } from './renderingModules/UIRenderingTexture.js';
11
+ export { UIRenderingTexture } from './renderingModules/UIRenderingTexture.js';
12
12
  export { UISpawnOffset } from './spawnModules/UISpawnOffset.js';
13
13
  export { UISpawnRandomLifetime } from './spawnModules/UISpawnRandomLifetime.js';
14
14
  export { UISpawnRandomRotation } from './spawnModules/UISpawnRandomRotation.js';
@@ -3,12 +3,13 @@ import { UIRenderingModule } from "./UIRenderingModule";
3
3
  /**
4
4
  * Renders particles with a texture.
5
5
  *
6
- * Samples the texture using particle UV coordinates.
6
+ * Accepts a single texture config or an array of configs from the same atlas.
7
+ * When an array is provided, each particle picks one texture randomly using PARTICLE_RANDOM_A.
8
+ * All configs in the array must share the same underlying Three.js Texture object.
7
9
  */
8
- export declare class UITextureRenderingModule extends UIRenderingModule {
9
- private readonly texture;
10
+ export declare class UIRenderingTexture extends UIRenderingModule {
10
11
  /**
11
- * @param config - Texture configuration
12
+ * @param config - Single texture config or array of configs (same atlas required for arrays)
12
13
  */
13
- constructor(config: UITextureConfig);
14
+ constructor(config: UITextureConfig | UITextureConfig[]);
14
15
  }
@@ -2,25 +2,69 @@ import { UITextureView } from '../../core/miscellaneous/texture/UITextureView.js
2
2
  import source from '../shaders/UIRenderingTexture.glsl.js';
3
3
  import { UIRenderingModule } from './UIRenderingModule.js';
4
4
 
5
+ function buildMultiTextureShader(count) {
6
+ const branches = [];
7
+ for (let i = 0; i < count; i++) {
8
+ if (i === 0) {
9
+ branches.push(` if (idx == 0) t = p_textureTransform0;`);
10
+ }
11
+ else if (i === count - 1) {
12
+ branches.push(` else t = p_textureTransform${i};`);
13
+ }
14
+ else {
15
+ branches.push(` else if (idx == ${i}) t = p_textureTransform${i};`);
16
+ }
17
+ }
18
+ return [
19
+ "vec4 draw() {",
20
+ ` int idx = int(PARTICLE_RANDOM_A * ${count}.0);`,
21
+ " mat3 t;",
22
+ ...branches,
23
+ " vec2 transformedUV = (t * vec3(p_uv, 1.0)).xy;",
24
+ " return srgbTexture2D(p_texture, transformedUV);",
25
+ "}",
26
+ ].join("\n");
27
+ }
5
28
  /**
6
29
  * Renders particles with a texture.
7
30
  *
8
- * Samples the texture using particle UV coordinates.
31
+ * Accepts a single texture config or an array of configs from the same atlas.
32
+ * When an array is provided, each particle picks one texture randomly using PARTICLE_RANDOM_A.
33
+ * All configs in the array must share the same underlying Three.js Texture object.
9
34
  */
10
- class UITextureRenderingModule extends UIRenderingModule {
35
+ class UIRenderingTexture extends UIRenderingModule {
11
36
  /**
12
- * @param config - Texture configuration
37
+ * @param config - Single texture config or array of configs (same atlas required for arrays)
13
38
  */
14
39
  constructor(config) {
15
40
  super();
16
- /** @internal */
17
- this.source = source;
18
- this._private_texture = new UITextureView(config);
19
- this.requiredUniforms = {
20
- texture: this._private_texture.texture,
21
- textureTransform: this._private_texture.calculateUVTransform(),
22
- };
41
+ if (!Array.isArray(config) || config.length === 1) {
42
+ const view = new UITextureView(Array.isArray(config) ? config[0] : config);
43
+ this.source = source;
44
+ this.requiredUniforms = {
45
+ texture: view.texture,
46
+ textureTransform: view.calculateUVTransform(),
47
+ };
48
+ return;
49
+ }
50
+ if (config.length === 0) {
51
+ throw new Error("UIRenderingTexture.constructor: config array cannot be empty");
52
+ }
53
+ const views = config.map((c) => new UITextureView(c));
54
+ const baseTexture = views[0].texture;
55
+ for (let i = 1; i < views.length; i++) {
56
+ if (views[i].texture !== baseTexture) {
57
+ throw new Error(`UIRenderingTexture.constructor: all configs must share the same Three.js Texture (index ${i} differs)`);
58
+ }
59
+ }
60
+ const uniforms = { texture: baseTexture };
61
+ for (let i = 0; i < views.length; i++) {
62
+ uniforms[`textureTransform${i}`] = views[i].calculateUVTransform();
63
+ }
64
+ this.requiredProperties = { builtin: "Matrix4" };
65
+ this.requiredUniforms = uniforms;
66
+ this.source = buildMultiTextureShader(views.length);
23
67
  }
24
68
  }
25
69
 
26
- export { UITextureRenderingModule };
70
+ export { UIRenderingTexture };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "laymur",
3
- "version": "0.19.3",
3
+ "version": "0.20.0",
4
4
  "description": "Constraint-based UI library for Three.js mobile advertisements",
5
5
  "keywords": [
6
6
  "ui",