mirror of
https://github.com/BradNut/svelte-3d
synced 2025-09-08 17:40:17 +00:00
3D Svelte Tutorial Tolinski checkin. Github style contributions.
This commit is contained in:
commit
c484607caa
13 changed files with 5216 additions and 0 deletions
20
.eslintrc.cjs
Normal file
20
.eslintrc.cjs
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
module.exports = {
|
||||
root: true,
|
||||
parser: '@typescript-eslint/parser',
|
||||
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended', 'prettier'],
|
||||
plugins: ['svelte3', '@typescript-eslint'],
|
||||
ignorePatterns: ['*.cjs'],
|
||||
overrides: [{ files: ['*.svelte'], processor: 'svelte3/svelte3' }],
|
||||
settings: {
|
||||
'svelte3/typescript': () => require('typescript')
|
||||
},
|
||||
parserOptions: {
|
||||
sourceType: 'module',
|
||||
ecmaVersion: 2020
|
||||
},
|
||||
env: {
|
||||
browser: true,
|
||||
es2017: true,
|
||||
node: true
|
||||
}
|
||||
};
|
||||
8
.gitignore
vendored
Normal file
8
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
.DS_Store
|
||||
node_modules
|
||||
/build
|
||||
/.svelte-kit
|
||||
/package
|
||||
.env
|
||||
.env.*
|
||||
!.env.example
|
||||
1
.npmrc
Normal file
1
.npmrc
Normal file
|
|
@ -0,0 +1 @@
|
|||
engine-strict=true
|
||||
6
.prettierrc
Normal file
6
.prettierrc
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"useTabs": true,
|
||||
"singleQuote": true,
|
||||
"trailingComma": "none",
|
||||
"printWidth": 100
|
||||
}
|
||||
40
README.md
Normal file
40
README.md
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
# create-svelte
|
||||
|
||||
Everything you need to build a Svelte project, powered by [`create-svelte`](https://github.com/sveltejs/kit/tree/master/packages/create-svelte).
|
||||
|
||||
## Creating a project
|
||||
|
||||
If you're seeing this, you've probably already done this step. Congrats!
|
||||
|
||||
```bash
|
||||
# create a new project in the current directory
|
||||
npm init svelte@next
|
||||
|
||||
# create a new project in my-app
|
||||
npm init svelte@next my-app
|
||||
```
|
||||
|
||||
> Note: the `@next` is temporary
|
||||
|
||||
## Developing
|
||||
|
||||
Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server:
|
||||
|
||||
```bash
|
||||
npm run dev
|
||||
|
||||
# or start the server and open the app in a new browser tab
|
||||
npm run dev -- --open
|
||||
```
|
||||
|
||||
## Building
|
||||
|
||||
To create a production version of your app:
|
||||
|
||||
```bash
|
||||
npm run build
|
||||
```
|
||||
|
||||
You can preview the production build with `npm run preview`.
|
||||
|
||||
> To deploy your app, you may need to install an [adapter](https://kit.svelte.dev/docs/adapters) for your target environment.
|
||||
4961
package-lock.json
generated
Normal file
4961
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
36
package.json
Normal file
36
package.json
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
{
|
||||
"name": "cubed",
|
||||
"version": "0.0.1",
|
||||
"scripts": {
|
||||
"dev": "svelte-kit dev --host",
|
||||
"build": "svelte-kit build",
|
||||
"package": "svelte-kit package",
|
||||
"preview": "svelte-kit preview",
|
||||
"prepare": "svelte-kit sync",
|
||||
"check": "svelte-check --tsconfig ./tsconfig.json",
|
||||
"check:watch": "svelte-check --tsconfig ./tsconfig.json --watch",
|
||||
"lint": "prettier --ignore-path .gitignore --check --plugin-search-dir=. . && eslint --ignore-path .gitignore .",
|
||||
"format": "prettier --ignore-path .gitignore --write --plugin-search-dir=. ."
|
||||
},
|
||||
"devDependencies": {
|
||||
"@sveltejs/adapter-auto": "next",
|
||||
"@sveltejs/kit": "next",
|
||||
"@typescript-eslint/eslint-plugin": "^5.10.1",
|
||||
"@typescript-eslint/parser": "^5.10.1",
|
||||
"eslint": "^7.32.0",
|
||||
"eslint-config-prettier": "^8.3.0",
|
||||
"eslint-plugin-svelte3": "^3.2.1",
|
||||
"prettier": "^2.5.1",
|
||||
"prettier-plugin-svelte": "^2.5.0",
|
||||
"svelte": "^3.44.0",
|
||||
"svelte-check": "^2.2.6",
|
||||
"svelte-preprocess": "^4.10.1",
|
||||
"tslib": "^2.3.1",
|
||||
"typescript": "~4.6.2"
|
||||
},
|
||||
"type": "module",
|
||||
"dependencies": {
|
||||
"svelte-cubed": "^0.2.1",
|
||||
"three": "^0.138.3"
|
||||
}
|
||||
}
|
||||
10
src/app.d.ts
vendored
Normal file
10
src/app.d.ts
vendored
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
/// <reference types="@sveltejs/kit" />
|
||||
|
||||
// See https://kit.svelte.dev/docs/types#the-app-namespace
|
||||
// for information about these interfaces
|
||||
declare namespace App {
|
||||
// interface Locals {}
|
||||
// interface Platform {}
|
||||
// interface Session {}
|
||||
// interface Stuff {}
|
||||
}
|
||||
13
src/app.html
Normal file
13
src/app.html
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="description" content="" />
|
||||
<link rel="icon" href="%svelte.assets%/favicon.png" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
%svelte.head%
|
||||
</head>
|
||||
<body>
|
||||
<div>%svelte.body%</div>
|
||||
</body>
|
||||
</html>
|
||||
50
src/routes/index.svelte
Normal file
50
src/routes/index.svelte
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
<script>
|
||||
import * as THREE from 'three';
|
||||
import * as SC from 'svelte-cubed';
|
||||
import { spring } from 'svelte/motion';
|
||||
|
||||
let rows = 5;
|
||||
let depth = 10;
|
||||
let hue = Math.round(Math.random() * 360);
|
||||
|
||||
let contributions = spring(getContributions());
|
||||
|
||||
function refresh() {
|
||||
$contributions = getContributions();
|
||||
hue = Math.round(Math.random() * 360);
|
||||
}
|
||||
|
||||
function getContributions() {
|
||||
return new Array(rows * depth).fill(0).map((value) => {
|
||||
return Math.round(Math.random() * 10);
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="controls">
|
||||
<button on:click={refresh}>Refresh</button>
|
||||
</div>
|
||||
|
||||
<SC.Canvas antialias alpha>
|
||||
{#each $contributions as contribution, index}
|
||||
<SC.Mesh
|
||||
scale={[1, contribution, 1]}
|
||||
geometry={new THREE.BoxGeometry()}
|
||||
material={new THREE.MeshStandardMaterial({
|
||||
color: `hsl(${hue}, 50%, ${contribution * 10}%)`,
|
||||
})}
|
||||
position={[Math.floor(index / rows), contribution / 2, index % rows]}
|
||||
/>
|
||||
{/each}
|
||||
<SC.PerspectiveCamera position={[15, 15, 15]} />
|
||||
<SC.OrbitControls />
|
||||
<SC.AmbientLight intensity={0.5} />
|
||||
<SC.DirectionalLight intensity={1} position={[3, 5, -4]} />
|
||||
</SC.Canvas>
|
||||
|
||||
<style>
|
||||
.controls {
|
||||
position: absolute;
|
||||
z-index: 10;
|
||||
}
|
||||
</style>
|
||||
53
src/routes/playcube.svelte
Normal file
53
src/routes/playcube.svelte
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
<script>
|
||||
import * as THREE from 'three';
|
||||
import * as SC from 'svelte-cubed';
|
||||
import { spring } from 'svelte/motion';
|
||||
|
||||
let width = 1;
|
||||
let height = 1;
|
||||
let depth = 1;
|
||||
|
||||
let spin = 0;
|
||||
let isActive = false;
|
||||
|
||||
let xPos = spring(0);
|
||||
$: $xPos = isActive ? 10 : 0;
|
||||
</script>
|
||||
|
||||
<svelte:window on:click={() => { isActive = !isActive }} />
|
||||
|
||||
<div class="controls">
|
||||
<label>Width:
|
||||
<input type="range" min={0.1} max={3} step={0.1} bind:value={width} />
|
||||
</label>
|
||||
<label>Height:
|
||||
<input type="range" min={0.1} max={3} step={0.1} bind:value={height} />
|
||||
</label>
|
||||
<label>Depth:
|
||||
<input type="range" min={0.1} max={3} step={0.1} bind:value={depth} />
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<SC.Canvas antialias background={new THREE.Color('grey')}>
|
||||
<SC.Mesh
|
||||
position={[$xPos, 0, 0]}
|
||||
rotation={[0, spin, 0]}
|
||||
scale={[width, height, depth]}
|
||||
material={new THREE.MeshStandardMaterial({ color: 'purple' })}
|
||||
geometry={new THREE.BoxGeometry()}
|
||||
/>
|
||||
<SC.PerspectiveCamera position={[2, 2, 2]} />
|
||||
<SC.OrbitControls />
|
||||
<SC.AmbientLight intensity={0.5} />
|
||||
<SC.DirectionalLight intensity={1} position={[3, 5, -4]} />
|
||||
</SC.Canvas>
|
||||
|
||||
<style>
|
||||
.controls {
|
||||
position: absolute;
|
||||
z-index: 10;
|
||||
}
|
||||
label {
|
||||
display: block;
|
||||
}
|
||||
</style>
|
||||
15
svelte.config.js
Normal file
15
svelte.config.js
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
import adapter from '@sveltejs/adapter-auto';
|
||||
import preprocess from 'svelte-preprocess';
|
||||
|
||||
/** @type {import('@sveltejs/kit').Config} */
|
||||
const config = {
|
||||
// Consult https://github.com/sveltejs/svelte-preprocess
|
||||
// for more information about preprocessors
|
||||
preprocess: preprocess(),
|
||||
|
||||
kit: {
|
||||
adapter: adapter()
|
||||
}
|
||||
};
|
||||
|
||||
export default config;
|
||||
3
tsconfig.json
Normal file
3
tsconfig.json
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"extends": "./.svelte-kit/tsconfig.json"
|
||||
}
|
||||
Loading…
Reference in a new issue