Skip to content

Commit cdd25bc

Browse files
authored
Merge branch 'main' into performance/micro-optimisations
2 parents e6876fe + c684a64 commit cdd25bc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1153
-293
lines changed

docs/example-projects/custom-shader-effect-texture/src/MyCustomTexture.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export class MyCustomTexture extends Texture {
2929
this.props = MyCustomTexture.resolveDefaults(props);
3030
}
3131

32-
override async getTextureData(): Promise<TextureData> {
32+
override async getTextureSource(): Promise<TextureData> {
3333
const { percent, width, height } = this.props;
3434
const radius = Math.min(width, height) / 2;
3535
const angle = 2 * Math.PI * (percent / 100);
@@ -48,6 +48,12 @@ export class MyCustomTexture extends Texture {
4848
ctx.closePath();
4949
ctx.fillStyle = 'blue';
5050
ctx.fill();
51+
52+
this.setState('fetched', {
53+
width,
54+
height,
55+
});
56+
5157
return {
5258
data: ctx.getImageData(0, 0, canvas.width, canvas.height),
5359
};

docs/example-projects/custom-shader-effect-texture/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {
55
} from '@lightningjs/renderer/webgl';
66
import { CanvasTextRenderer } from '@lightningjs/renderer/canvas';
77
import { Inspector } from '@lightningjs/renderer/inspector';
8-
import { MyCustomEffect } from './MyCustomEffect.js';
98
import { MyCustomShader } from './MyCustomShader.js';
109
import { MyCustomTexture } from './MyCustomTexture.js';
1110
import robotImg from './assets/robot.png';

examples/tests/detect-touch.ts

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
import type { Point } from '@lightningjs/renderer';
2+
import type { ExampleSettings } from '../common/ExampleSettings.js';
3+
import type { CoreNode } from '../../dist/src/core/CoreNode.js';
4+
5+
const getRandomValue = (min: number, max: number) => {
6+
return Math.random() * (max - min) + min;
7+
};
8+
9+
const getRandomColor = () => {
10+
const randomInt = Math.floor(Math.random() * Math.pow(2, 24)); // Use 24 bits for RGB
11+
const hexString = randomInt.toString(16).padStart(6, '0'); // RGB hex without alpha
12+
return parseInt(hexString + 'FF', 16); // Append 'FF' for full alpha
13+
};
14+
15+
const getRandomBezierCurve = () => {
16+
// Generate random values for control points within specified ranges
17+
const x1 = Math.random(); // 0 to 1
18+
const y1 = Math.random() * 2; // Allow values above 1
19+
const x2 = Math.random(); // 0 to 1
20+
const y2 = Math.random() * 2 - 1; // Allow values between -1 and 1
21+
22+
// Return the Bezier curve in the required format
23+
return `cubic-bezier(${x1.toFixed(2)}, ${y1.toFixed(2)}, ${x2.toFixed(
24+
2,
25+
)}, ${y2.toFixed(2)})`;
26+
};
27+
28+
export default async function ({ renderer, testRoot }: ExampleSettings) {
29+
const holder = renderer.createNode({
30+
x: 0,
31+
y: 0,
32+
width: 1920,
33+
height: 1080,
34+
color: 0x000000ff,
35+
parent: testRoot,
36+
});
37+
38+
// Copy source texture from rootRenderToTextureNode
39+
for (let i = 0; i < 50; i++) {
40+
const dimension = getRandomValue(30, 150);
41+
const node = renderer.createNode({
42+
parent: holder,
43+
x: getRandomValue(0, 1820),
44+
y: getRandomValue(0, 980),
45+
width: dimension,
46+
height: dimension,
47+
color: getRandomColor(),
48+
interactive: true,
49+
zIndex: getRandomValue(0, 100),
50+
});
51+
52+
node
53+
.animate(
54+
{
55+
x: getRandomValue(0, 1820),
56+
y: getRandomValue(0, 980),
57+
},
58+
{
59+
duration: getRandomValue(8000, 12000),
60+
delay: getRandomValue(0, 5000),
61+
stopMethod: 'reverse',
62+
loop: true,
63+
easing: getRandomBezierCurve(),
64+
},
65+
)
66+
.start();
67+
}
68+
69+
document.addEventListener('touchstart', (e: TouchEvent) => {
70+
const { changedTouches } = e;
71+
if (changedTouches.length) {
72+
const touch = changedTouches.item(0);
73+
74+
const x = touch?.clientX ?? 0;
75+
const y = touch?.clientY ?? 0;
76+
77+
const eventData: Point = {
78+
x,
79+
y,
80+
};
81+
// const nodes: CoreNode[] = renderer.stage.findNodesAtPoint(eventData);
82+
const topNode: CoreNode | null =
83+
renderer.stage.getNodeFromPosition(eventData);
84+
85+
if (topNode) {
86+
topNode.scale = 1.5;
87+
setTimeout(() => {
88+
topNode.scale = 1;
89+
}, 150);
90+
}
91+
}
92+
});
93+
94+
document.addEventListener('mousemove', (e: MouseEvent) => {
95+
const x = e?.clientX ?? 0;
96+
const y = e?.clientY ?? 0;
97+
98+
const eventData: Point = {
99+
x,
100+
y,
101+
};
102+
103+
const topNode: CoreNode | null =
104+
renderer.stage.getNodeFromPosition(eventData);
105+
if (topNode) {
106+
topNode.scale = 1.5;
107+
setTimeout(() => {
108+
topNode.scale = 1;
109+
}, 150);
110+
}
111+
});
112+
}

0 commit comments

Comments
 (0)