-
-
Notifications
You must be signed in to change notification settings - Fork 10
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
8 changed files
with
174 additions
and
64 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<script setup lang="tsx"> | ||
import { App } from 'ant-design-vue'; | ||
import { ref, onMounted } from 'vue'; | ||
import { Group, deserializeNode, fromSVGElement, TesselationMethod } from '@infinite-canvas-tutorial/core'; | ||
defineOptions({ name: 'WebGPU' }); | ||
const wrapper = ref(null); | ||
let canvas = null; | ||
const renderSVG = async (svg: string, x: number, y: number) => { | ||
const $container = document.createElement('div'); | ||
$container.innerHTML = svg; | ||
const $svg = $container.children[0]; | ||
const root = new Group(); | ||
for (const child of $svg.children) { | ||
const group = await deserializeNode(fromSVGElement(child)); | ||
group.children.forEach((path) => { | ||
path.tessellationMethod = TesselationMethod.LIBTESS; | ||
path.cullable = false; | ||
}); | ||
root.appendChild(group); | ||
} | ||
canvas.appendChild(root); | ||
root.position.x = x; | ||
root.position.y = y; | ||
}; | ||
onMounted(() => { | ||
const $canvas = wrapper.value; | ||
if (!$canvas) { | ||
return; | ||
} | ||
$canvas.addEventListener('ic-ready', (e) => { | ||
canvas = e.detail; | ||
window.fetch( | ||
'/Ghostscript_Tiger.svg', | ||
).then(async (res) => { | ||
const svg = await res.text(); | ||
renderSVG(svg, 80, 80); | ||
}); | ||
}); | ||
}); | ||
const Demo = () => { | ||
return (<div> | ||
<div style="position: relative"> | ||
<ic-canvas renderer="webgpu" ref={wrapper} style="height: 400px"></ic-canvas> | ||
</div> | ||
</div>); | ||
}; | ||
defineRender(() => { | ||
return ( | ||
<App> | ||
<Demo /> | ||
</App> | ||
); | ||
}); | ||
</script> |
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,24 @@ | ||
--- | ||
publish: false | ||
--- | ||
|
||
<script setup> | ||
import WebGPU from '../components/WebGPU.vue' | ||
</script> | ||
|
||
<WebGPU /> | ||
|
||
Just use `renderer="webgpu"` to enable WebGPU. | ||
|
||
```html | ||
<ic-canvas renderer="webgpu"></ic-canvas> | ||
``` | ||
|
||
If you don't set `shaderCompilerPath`, it will use the default shader compiler `'https://unpkg.com/@antv/[email protected]/dist/pkg/glsl_wgsl_compiler_bg.wasm'`. | ||
|
||
```html | ||
<ic-canvas | ||
renderer="webgpu" | ||
shaderCompilerPath="/your/path/to/glsl_wgsl_compiler_bg.wasm" | ||
></ic-canvas> | ||
``` |
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,28 @@ | ||
--- | ||
publish: false | ||
--- | ||
|
||
<script setup> | ||
import WebGPU from '../../components/WebGPU.vue' | ||
</script> | ||
|
||
<WebGPU /> | ||
|
||
```html | ||
<ic-canvas renderer="webgpu" shaderCompilerPath="/xxx/xx"></ic-canvas> | ||
``` | ||
|
||
通过 `renderer="webgpu"` 启用 WebGPU。 | ||
|
||
```html | ||
<ic-canvas renderer="webgpu"></ic-canvas> | ||
``` | ||
|
||
如果未设置 `shaderCompilerPath`,则使用默认的着色器编译器路径 `'https://unpkg.com/@antv/[email protected]/dist/pkg/glsl_wgsl_compiler_bg.wasm'`。 | ||
|
||
```html | ||
<ic-canvas | ||
renderer="webgpu" | ||
shaderCompilerPath="/your/path/to/glsl_wgsl_compiler_bg.wasm" | ||
></ic-canvas> | ||
``` |