Skip to content

Commit fe674fa

Browse files
authored
Merge branch 'main' into feat/std-math-trigo
2 parents 88ca842 + 8acb7fe commit fe674fa

File tree

5 files changed

+88
-19
lines changed

5 files changed

+88
-19
lines changed

apps/typegpu-docs/src/components/ExampleView.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export function ExampleView({ example }: Props) {
9898
<div className='flex h-full flex-col gap-4 md:grid md:grid-cols-[1fr_18.75rem]'>
9999
<div
100100
className={cs(
101-
'grid flex-1 gap-4',
101+
'grid flex-1 gap-4 overflow-auto',
102102
codeEditorShowing ? 'md:grid-rows-[2fr_3fr]' : '',
103103
)}
104104
>
@@ -109,13 +109,13 @@ export function ExampleView({ example }: Props) {
109109
scrollbarGutter: 'stable both-edges',
110110
}}
111111
className={cs(
112-
'relative box-border flex h-full flex-col flex-wrap items-center justify-evenly md:flex-row md:gap-4',
112+
'relative box-border flex h-full flex-col flex-wrap items-center justify-evenly gap-4 overflow-auto md:flex-row',
113113
codeEditorShowing
114114
? 'md:max-h-[calc(40vh-1.25rem)] md:overflow-auto'
115115
: '',
116116
)}
117117
>
118-
<div ref={exampleHtmlRef} className='contents h-full w-full' />
118+
<div ref={exampleHtmlRef} className='contents' />
119119
</div>
120120
)
121121
: <GPUUnsupportedPanel />}

apps/typegpu-docs/src/content/examples/image-processing/blur/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ function render() {
295295
device.queue.submit([encoder.finish()]);
296296
}
297297

298-
render();
298+
setTimeout(() => render(), 100);
299299

300300
// #region Example controls & Cleanup
301301

apps/typegpu-docs/src/content/examples/rendering/3d-fish/index.ts

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ export const controls = {
326326
},
327327
};
328328

329-
// Variables for mouse interaction.
329+
// Variables for interaction
330330

331331
let isLeftPressed = false;
332332
let previousMouseX = 0;
@@ -406,6 +406,8 @@ canvas.addEventListener('contextmenu', (event) => {
406406
event.preventDefault();
407407
});
408408

409+
// Mouse controls
410+
409411
canvas.addEventListener('mousedown', async (event) => {
410412
previousMouseX = event.clientX;
411413
previousMouseY = event.clientY;
@@ -454,6 +456,37 @@ window.addEventListener('mousemove', (event) => {
454456
}
455457
});
456458

459+
// Touch controls
460+
461+
canvas.addEventListener('touchstart', async (event) => {
462+
if (event.touches.length === 1) {
463+
previousMouseX = event.touches[0].clientX;
464+
previousMouseY = event.touches[0].clientY;
465+
updateMouseRay(event.touches[0].clientX, event.touches[0].clientY);
466+
controlsPopup.style.opacity = '0';
467+
}
468+
});
469+
470+
window.addEventListener('touchmove', (event) => {
471+
if (event.touches.length === 1) {
472+
const dx = event.touches[0].clientX - previousMouseX;
473+
const dy = event.touches[0].clientY - previousMouseY;
474+
previousMouseX = event.touches[0].clientX;
475+
previousMouseY = event.touches[0].clientY;
476+
477+
updateCameraTarget(dx, dy);
478+
updateMouseRay(event.touches[0].clientX, event.touches[0].clientY);
479+
}
480+
});
481+
482+
window.addEventListener('touchend', () => {
483+
mouseRayBuffer.writePartial({
484+
activated: 0,
485+
});
486+
});
487+
488+
// observer and cleanup
489+
457490
const resizeObserver = new ResizeObserver(() => {
458491
camera.projection = m.mat4.perspective(
459492
Math.PI / 4,

apps/typegpu-docs/src/content/examples/rendering/function-visualizer/index.ts

Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -438,22 +438,19 @@ function queuePropertiesBufferUpdate() {
438438
}
439439

440440
// Canvas controls
441-
442441
let lastPos: number[] | null = null;
443442

444-
canvas.onmousedown = (event) => {
445-
lastPos = [event.offsetX, event.offsetY];
446-
};
443+
// Mouse interaction
447444

448-
canvas.onmouseup = (_) => {
449-
lastPos = null;
450-
};
445+
canvas.addEventListener('mousedown', (event) => {
446+
lastPos = [event.clientX, event.clientY];
447+
});
451448

452-
canvas.onmousemove = (event) => {
449+
window.addEventListener('mousemove', (event) => {
453450
if (lastPos === null) {
454451
return;
455452
}
456-
const currentPos = [event.offsetX, event.offsetY];
453+
const currentPos = [event.clientX, event.clientY];
457454
const translation = [
458455
(-(currentPos[0] - lastPos[0]) / canvas.width) *
459456
2.0 *
@@ -470,9 +467,13 @@ canvas.onmousemove = (event) => {
470467
);
471468

472469
lastPos = currentPos;
473-
};
470+
});
474471

475-
canvas.onwheel = (event) => {
472+
window.addEventListener('mouseup', (_) => {
473+
lastPos = null;
474+
});
475+
476+
canvas.addEventListener('wheel', (event) => {
476477
event.preventDefault();
477478

478479
const delta = Math.abs(event.deltaY) / 1000.0 + 1;
@@ -483,9 +484,42 @@ canvas.onwheel = (event) => {
483484
[scale, scale, 1],
484485
properties.transformation,
485486
);
486-
};
487+
});
488+
489+
// Mouse interaction
490+
491+
canvas.addEventListener('touchstart', (event) => {
492+
if (event.touches.length === 1) {
493+
lastPos = [event.touches[0].clientX, event.touches[0].clientY];
494+
}
495+
});
496+
497+
window.addEventListener('touchmove', (event) => {
498+
if (lastPos === null || event.touches.length !== 1) {
499+
return;
500+
}
501+
const currentPos = [event.touches[0].clientX, event.touches[0].clientY];
502+
const s = 2.0 * window.devicePixelRatio;
503+
const translation = [
504+
((currentPos[0] - lastPos[0]) / canvas.width) * -s,
505+
((currentPos[1] - lastPos[1]) / canvas.height) * s,
506+
0.0,
507+
];
508+
mat4.translate(
509+
properties.transformation,
510+
translation,
511+
properties.transformation,
512+
);
513+
514+
lastPos = currentPos;
515+
});
516+
517+
window.addEventListener('touchend', () => {
518+
lastPos = null;
519+
});
520+
521+
// Resize observer and cleanup
487522

488-
// recreate the multisampled texture on canvas resize
489523
const resizeObserver = new ResizeObserver(() => {
490524
msTexture.destroy();
491525
msTexture = device.createTexture({

apps/typegpu-docs/src/content/examples/simple/triangle/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ setTimeout(() => {
6363
storeOp: 'store',
6464
})
6565
.draw(3);
66+
}, 100);
6667

68+
export function onCleanup() {
6769
root.destroy();
68-
}, 100);
70+
}

0 commit comments

Comments
 (0)