Select the types of activity you want to include in your feed.
[READ-ONLY] Mirror of https://github.com/flo-bit/svelte-depth-3d-component. svelte component to show a fake 3d image with depth map
flo-bit.dev/svelte-depth-3d-component/
···11# svelte depth 3d component
2233+Display an image with a fake 3D effect, using a depth map. Made for svelte, using threlte, threejs and tailwindcss. Still a work in progress, but usable.
44+55+[Try the demo here.](https://flo-bit.github.io/svelte-depth-3d-component/)
66+77+88+https://github.com/flo-bit/svelte-depth-3d-component/assets/45694132/bea0d04f-487b-4119-ba1a-a5743728195a
99+1010+1111+## How to use
1212+1313+1. Copy and paste the [`src/lib/Depth3D/`](https://download-directory.github.io/?url=https%3A%2F%2Fgithub.com%2Fflo-bit%2Fsvelte-depth-3d-component%2Ftree%2Fmain%2Fsrc%2Flib%2FDepth3D) folder of this repository into your svelte projects `src/lib/` folder.
1414+2. Install [tailwindcss](https://tailwindcss.com/docs/guides/sveltekit) and [threlte (core and extras)](https://threlte.xyz/docs/learn/getting-started/installation) (work through their setup or see below for commands)
1515+3. Get an image and generate a accompanying depth map, for example using [zoedepth](https://replicate.com/cjwbw/zoedepth)
1616+4. Use the `Depth3D` component in your pages directly like so:
1717+1818+```svelte
1919+<script>
2020+ // Depth3D example
2121+ import Depth3D from '$lib/Depth3D';
2222+</script>
2323+2424+<!-- will adjust to the parents size/position -->
2525+<Depth3D
2626+ image={{
2727+ image: 'your-image.png',
2828+ depth: 'your-depth.png'
2929+ }}
3030+/>
3131+```
3232+3333+## Which images work well
3434+3535+This effect only simulates 3D, so some images will show weird artifacts. Portraits with a single person in the middle tend to work well. The effect will also depend on the quality of the depth map. Some trial and error might be necessary to get the desired effect.
3636+3737+## Installing the dependencies
3838+3939+### TailwindCSS (assuming you created your svelte app with the svelte create command)
4040+4141+1. Install
4242+```bash
4343+npm install -D tailwindcss postcss autoprefixer
4444+npx tailwindcss init -p
4545+```
4646+2. Update your tailwind.config.js file to find files with tailwind classes:
4747+```js
4848+content: ['./src/**/*.{html,js,svelte,ts}'],
4949+```
5050+3. Create a app.css file in your src folder.
5151+```css
5252+@tailwind base;
5353+@tailwind components;
5454+@tailwind utilities;
5555+```
5656+4. Import the css file in your +layout.svelte file
5757+```svelte
5858+<script>
5959+ import "../app.css";
6060+</script>
6161+6262+<slot />
6363+```
6464+6565+### Threlte (core and extras)
6666+6767+1. Install
6868+```bash
6969+npm install three @threlte/core \
7070+ @threlte/extras \
7171+ @types/three
7272+```