-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
796 additions
and
413 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<script setup> | ||
import { Circle } from '@infinite-canvas-tutorial/lesson8'; | ||
import { onMounted, ref } from 'vue'; | ||
import Stats from 'stats.js'; | ||
const total = ref(0); | ||
const culled = ref(0); | ||
const circles = []; | ||
let canvas; | ||
const stats = new Stats(); | ||
stats.showPanel(0); | ||
const $stats = stats.dom; | ||
$stats.style.position = 'absolute'; | ||
$stats.style.left = '0px'; | ||
$stats.style.top = '0px'; | ||
const add500Circles = () => { | ||
for (let i = 0; i < 500; i++) { | ||
const fill = `rgb(${Math.floor(Math.random() * 255)},${Math.floor( | ||
Math.random() * 255, | ||
)},${Math.floor(Math.random() * 255)})`; | ||
const circle = new Circle({ | ||
cx: Math.random() * 1000, | ||
cy: Math.random() * 1000, | ||
r: Math.random() * 20, | ||
fill, | ||
batchable: true, | ||
cullable: true, | ||
}); | ||
canvas.appendChild(circle); | ||
circles.push(circle); | ||
circle.addEventListener('pointerenter', () => { | ||
circle.fill = 'red'; | ||
}); | ||
circle.addEventListener('pointerleave', () => { | ||
circle.fill = fill; | ||
}); | ||
} | ||
}; | ||
onMounted(() => { | ||
const $canvas = document.querySelector('ic-canvas-lesson8'); | ||
$canvas.parentElement.appendChild($stats); | ||
$canvas.addEventListener('ic-ready', (e) => { | ||
canvas = e.detail; | ||
add500Circles(); | ||
}); | ||
$canvas.addEventListener('ic-frame', (e) => { | ||
stats.update(); | ||
total.value = circles.length; | ||
culled.value = circles.filter((circle) => circle.culled).length; | ||
}); | ||
}); | ||
</script> | ||
|
||
<template> | ||
<span>total: {{ total }}</span> | ||
| ||
<span>culled: {{ culled }}</span> | ||
| ||
<sl-button size="small" @click="add500Circles">Add 500 circles</sl-button> | ||
<div style="position: relative"> | ||
<ic-canvas-lesson8></ic-canvas-lesson8> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
--- | ||
|
||
We can enhance picking performance with RBush, see: | ||
<a href="/guide/lesson-008">Performace optimazation</a> | ||
|
||
<script setup> | ||
import Picking from '../components/Picking.vue' | ||
</script> | ||
|
||
<Picking /> |
Oops, something went wrong.