Skip to content

Commit

Permalink
🔨 fix: merge
Browse files Browse the repository at this point in the history
  • Loading branch information
ccjr1120 committed Nov 2, 2024
2 parents 464221d + 8036b29 commit 2e7ffda
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 212 deletions.
6 changes: 5 additions & 1 deletion docs/.vitepress/config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,9 @@ export default defineConfig({
{ icon: 'github', link: 'https://github.com/ccjr1120/gpu-mesh' }
]
},
vite: {}
vite: {
ssr: {
noExternal: ['monaco-editor']
}
}
})
38 changes: 20 additions & 18 deletions docs/components/playground/composables/use-view.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { onMounted, Ref, ShallowRef, watch } from 'vue'
import { onMounted, ref, Ref, ShallowRef, watch } from 'vue'
import GPUMesh from '../../../../src/index'
import { DataMap } from '../index'
import { _throttle } from '../utils'

export default function useView({
el,
Expand All @@ -9,35 +10,36 @@ export default function useView({
el: Readonly<ShallowRef<HTMLElement | null>>
dataMap: Ref<DataMap>
}) {
const loading = ref(false)
onMounted(async () => {
await GPUMesh.Mesh.loadDevice()
const observer = new ResizeObserver(renderGPUMesh)
observer.observe(el.value!)
loading.value = true
})
watch(
dataMap,
[dataMap, el, loading],
() => {
console.log('dataMap changed')
if (!loading.value) return
renderGPUMesh()
},
{ deep: true }
{ deep: true, immediate: true, flush: 'pre' }
)
onMounted(async () => {

const WAIT_TIME = 600
const renderGPUMesh = _throttle(() => {
if (!el.value) return
await GPUMesh.Mesh.loadDevice()
el.value.innerHTML = ''
new GPUMesh.Mesh(el.value, {
vertices: new Float32Array([
-0.8, -0.8, 0.8, -0.8, 0.8, 0.8,
// Triangle 2
-0.8, -0.8, 0.8, 0.8, -0.8, 0.8
]),
shader: {
vertex: `
@vertex
fn vertexMain(@location(0) pos: vec2f) ->
@builtin(position) vec4f {
return vec4f(pos, 0, 1);
}`,
fragment: `
@fragment
fn fragmentMain() -> @location(0) vec4f {
return vec4f(1, 0, 0, 1); // (Red, Green, Blue, Alpha)
}`
vertex: `${dataMap.value.vertex}`,
fragment: `${dataMap.value.fragment}`
}
})
})
}, WAIT_TIME)
}
12 changes: 12 additions & 0 deletions docs/components/playground/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export const _throttle = (func: () => void, wait: number) => {
let timeout: null | NodeJS.Timeout = null
return function () {
if (timeout) {
clearTimeout(timeout)
}
timeout = setTimeout(() => {
func()
timeout = null
}, wait)
}
}
9 changes: 7 additions & 2 deletions docs/playground.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ pageClass: custom-page-class
---

<script setup>
import Playground from './components/playground/index.vue'
import { defineAsyncComponent } from 'vue';
import { inBrowser } from 'vitepress';

const Play = inBrowser
? defineAsyncComponent(() => import('./components/playground/index.vue'))
: () => null;
</script>
<Playground/>
<Play/>
Loading

0 comments on commit 2e7ffda

Please sign in to comment.