Skip to content

Commit 586b141

Browse files
yashrajbhartiyashrajbharticybtekk
andauthored
Add Cursor control to Stencil mask (#534)
Add Cursor control directly to Stencil mask example Related to #527 ![ScreenRecording2025-07-20at1 17 05PM-ezgif com-video-to-gif-converter](https://github.com/user-attachments/assets/7ce36937-4f21-4b15-b916-0fe4517700e8) Added: <img width="306" height="102" alt="Screenshot 2025-07-20 at 2 06 24 PM" src="https://github.com/user-attachments/assets/6bc573fb-c059-4758-ae6b-2091c60880a7" /> https://github.com/user-attachments/assets/e8bb1138-57c5-4675-a422-9b266ea1c994 --------- Co-authored-by: yashrajbharticybtekk <[email protected]>
1 parent 230a16f commit 586b141

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

sample/stencilMask/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
height: 600px;
3030
max-width: 100%;
3131
display: block;
32+
touch-action: none;
3233
}
3334
</style>
3435
<script defer src="main.js" type="module"></script>

sample/stencilMask/main.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ context.configure({
3131
format: presentationFormat,
3232
});
3333

34+
let mousePos = { x: 0, y: 0 };
35+
canvas.addEventListener('pointermove', (e) => {
36+
const rect = canvas.getBoundingClientRect();
37+
const x = ((e.clientX - rect.left) / rect.width) * 2 - 1;
38+
const y = -(((e.clientY - rect.top) / rect.height) * 2 - 1);
39+
mousePos = { x, y };
40+
});
41+
3442
// Creates a buffer and puts data in it.
3543
function createBufferWithData(
3644
device: GPUDevice,
@@ -334,6 +342,9 @@ function updateMask(
334342

335343
objectInfos.forEach(({ uniformBuffer, uniformValues, worldMatrix }) => {
336344
mat4.identity(worldMatrix);
345+
const worldX = mousePos.x * 10;
346+
const worldY = mousePos.y * 10;
347+
mat4.translate(worldMatrix, [worldX, worldY, 0], worldMatrix);
337348
mat4.rotateX(worldMatrix, time * 0.25, worldMatrix);
338349
mat4.rotateY(worldMatrix, time * 0.15, worldMatrix);
339350
mat4.rotateX(worldMatrix, rotation[0] * Math.PI, worldMatrix);

0 commit comments

Comments
 (0)