diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a547bf3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,24 @@ +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +pnpm-debug.log* +lerna-debug.log* + +node_modules +dist +dist-ssr +*.local + +# Editor directories and files +.vscode/* +!.vscode/extensions.json +.idea +.DS_Store +*.suo +*.ntvs* +*.njsproj +*.sln +*.sw? diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 1e7150d..0000000 --- a/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "three.js"] - path = three.js - url = https://github.com/mrdoob/three.js.git diff --git a/bun.lockb b/bun.lockb new file mode 100644 index 0000000..7829147 Binary files /dev/null and b/bun.lockb differ diff --git a/index.html b/index.html new file mode 100644 index 0000000..e58236d --- /dev/null +++ b/index.html @@ -0,0 +1,15 @@ + + + + + + Tests + + + + +
+ +
+ + diff --git a/package.json b/package.json new file mode 100644 index 0000000..3ba1189 --- /dev/null +++ b/package.json @@ -0,0 +1,19 @@ +{ + "name": "vtt-mapper", + "private": true, + "version": "0.0.0", + "type": "module", + "scripts": { + "dev": "bunx --bun vite", + "build": "tsc && vite build", + "preview": "vite preview" + }, + "devDependencies": { + "typescript": "^5.2.2", + "vite": "^5.2.0" + }, + "dependencies": { + "@types/three": "^0.165.0", + "three": "^0.165.0" + } +} diff --git a/src/assets/asset.class.ts b/src/assets/asset.class.ts new file mode 100644 index 0000000..34a02a6 --- /dev/null +++ b/src/assets/asset.class.ts @@ -0,0 +1,18 @@ +import * as Three from 'three'; + +export default class Asset +{ + #mat: Three.Matrix4; + #layer: number; + + ready: boolean = false; + + _obj: Three.Object3D | undefined; + + constructor(mat?: Three.Matrix4, layer?: number) + { + this.#mat = mat ?? new Three.Matrix4(); + this.#layer = layer ?? 0; + } + static init(): void {} +} \ No newline at end of file diff --git a/src/assets/sprite.class.ts b/src/assets/sprite.class.ts new file mode 100644 index 0000000..b1ea974 --- /dev/null +++ b/src/assets/sprite.class.ts @@ -0,0 +1,13 @@ +import Asset from './asset.class'; +import * as CONST from '../consts'; +import * as Three from 'three'; + +export default class Sprite extends Asset +{ + static #material = new Three.RawShaderMaterial({ + fragmentShader: "", + vertexShader: "", + }); + static #mesh = CONST.QUAD; + static #instance = new Three.InstancedMesh(CONST.QUAD, Sprite.#material, 2**14); +} \ No newline at end of file diff --git a/src/consts.ts b/src/consts.ts new file mode 100644 index 0000000..774d80a --- /dev/null +++ b/src/consts.ts @@ -0,0 +1,11 @@ +import * as Three from 'three'; + +const QUAD = new Three.BufferGeometry(); +QUAD.setIndex( new Three.Float32BufferAttribute( [ 0, 2, 1, 2, 3, 1 ], 1 ) ) +QUAD.setAttribute( 'position', new Three.Float32BufferAttribute( [ -0.5, 0.5, 0, 0.5, 0.5, 0, -0.5, -0.5, 0, 0.5, -0.5, 0 ], 3 ) ); +QUAD.setAttribute( 'normal', new Three.Float32BufferAttribute( [ 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1 ], 3 ) ); +QUAD.setAttribute( 'uv', new Three.Float32BufferAttribute( [ 0, 1, 1, 1, 0, 0, 1, 0 ], 2 ) ); + +export { + QUAD +}; \ No newline at end of file diff --git a/src/main.ts b/src/main.ts new file mode 100644 index 0000000..8cc6107 --- /dev/null +++ b/src/main.ts @@ -0,0 +1,3 @@ +import Renderer from './renderer/renderer.class'; + +Renderer.init(); \ No newline at end of file diff --git a/src/renderer/renderer.class.ts b/src/renderer/renderer.class.ts new file mode 100644 index 0000000..57fc33f --- /dev/null +++ b/src/renderer/renderer.class.ts @@ -0,0 +1,47 @@ +import * as Three from 'three'; +import Asset from '../assets/asset.class'; + +export default class Renderer +{ + static #scene: Three.Scene; + static #camera: Three.OrthographicCamera; + static init(): Boolean + { + try { + const canvas = document.createElement("canvas"); + canvas.addEventListener("webglcontextcreationerror", console.error); + const context = canvas.getContext("webgl2"); + + this.#renderer.setPixelRatio( window.devicePixelRatio ); + document.body.appendChild(this.#renderer.domElement); + + this.#scene = new Three.Scene(); + this.#camera = new Three.OrthographicCamera( window.innerWidth / - 2, window.innerWidth / 2, window.innerHeight / 2, window.innerHeight / - 2, 1, 1000 ); + + this.#resize(); + window.addEventListener("resize", this.#resize.bind(this)); + + return true; + } + catch(e) + { + console.error(e); + return false; + } + } + static #resize(): void + { + this.#renderer.setSize( window.innerWidth, window.innerHeight ); + this.#camera.left = window.innerWidth / - 2; + this.#camera.right = window.innerWidth / 2; + this.#camera.top = window.innerHeight / 2; + this.#camera.bottom = window.innerHeight / - 2; + + this.render(); + } + static render(): void + { + console.log(new Three.PlaneGeometry()); + this.#renderer.render(this.#scene, this.#camera); + } +} \ No newline at end of file diff --git a/src/style.css b/src/style.css new file mode 100644 index 0000000..a5ac434 --- /dev/null +++ b/src/style.css @@ -0,0 +1,5 @@ +html, body, div +{ + padding: 0; + margin: 0; +} \ No newline at end of file diff --git a/src/vite-env.d.ts b/src/vite-env.d.ts new file mode 100644 index 0000000..11f02fe --- /dev/null +++ b/src/vite-env.d.ts @@ -0,0 +1 @@ +/// diff --git a/three.js b/three.js deleted file mode 160000 index 3556fc5..0000000 --- a/three.js +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 3556fc5d6986e03bcd4776ee2e89b862ec493c10 diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..75abdef --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "target": "ES2020", + "useDefineForClassFields": true, + "module": "ESNext", + "lib": ["ES2020", "DOM", "DOM.Iterable"], + "skipLibCheck": true, + + /* Bundler mode */ + "moduleResolution": "bundler", + "allowImportingTsExtensions": true, + "resolveJsonModule": true, + "isolatedModules": true, + "noEmit": true, + + /* Linting */ + "strict": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noFallthroughCasesInSwitch": true + }, + "include": ["src"] +}