|
3 | 3 | import { Uniform, MeshBasicMaterial, Vector2 } from 'three'; |
4 | 4 | import noise from './threlte/shaders/noise.glsl?raw'; |
5 | 5 | import { onMount } from 'svelte'; |
6 | | - import { useViewport } from '@threlte/extras'; |
7 | | -
|
8 | | - const { invalidate } = useThrelte(); |
9 | | - const viewport = useViewport(); |
| 6 | + const { invalidate, size } = useThrelte(); |
10 | 7 |
|
11 | 8 | let uAspect: Uniform; |
12 | 9 | let uOpacity: Uniform; |
13 | 10 | let uTime: Uniform; |
14 | 11 | let uViewportSize: Uniform; |
15 | 12 |
|
16 | 13 | $effect(() => { |
17 | | - const width = $viewport.width; |
18 | | - const height = $viewport.height; |
| 14 | + const width = $size.width || 1; |
| 15 | + const height = $size.height || 1; |
19 | 16 | if (uAspect) { |
20 | 17 | uAspect.value = width / height; |
21 | 18 | invalidate(); |
|
30 | 27 | let material = $state<MeshBasicMaterial>(new MeshBasicMaterial()); |
31 | 28 |
|
32 | 29 | onMount(() => { |
33 | | - uAspect = new Uniform($viewport.width / $viewport.height); |
| 30 | + const width = $size.width || 1; |
| 31 | + const height = $size.height || 1; |
| 32 | +
|
| 33 | + uAspect = new Uniform(width / height); |
34 | 34 | uOpacity = new Uniform(0); |
35 | 35 | uTime = new Uniform(0); |
36 | | - uViewportSize = new Uniform(new Vector2($viewport.width, $viewport.height)); |
| 36 | + uViewportSize = new Uniform(new Vector2(width, height)); |
37 | 37 |
|
38 | 38 | material.onBeforeCompile = (shader) => { |
39 | 39 | shader.uniforms.uTime = uTime; |
|
104 | 104 | </script> |
105 | 105 |
|
106 | 106 | <T.OrthographicCamera position={[0, 0, 10]} fov={10} near={0.1} far={1000} makeDefault /> |
107 | | -<T.Mesh scale={[$viewport.width, $viewport.height, 1]} {material}> |
| 107 | +<T.Mesh scale={[$size.width || 1, $size.height || 1, 1]} {material}> |
108 | 108 | <T.PlaneGeometry args={[1, 1]} /> |
109 | 109 | </T.Mesh> |
0 commit comments