backup-05-06-2024

This commit is contained in:
Peaceultime 2024-06-05 17:57:07 +02:00
parent f8122076eb
commit 98e78ca33e
14 changed files with 179 additions and 4 deletions

24
.gitignore vendored Normal file
View File

@ -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?

3
.gitmodules vendored
View File

@ -1,3 +0,0 @@
[submodule "three.js"]
path = three.js
url = https://github.com/mrdoob/three.js.git

BIN
bun.lockb Normal file

Binary file not shown.

15
index.html Normal file
View File

@ -0,0 +1,15 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Tests</title>
<link rel="stylesheet" href="src/style.css">
<script type="module" src="/src/main.ts"></script>
</head>
<body>
<div id="app">
</div>
</body>
</html>

19
package.json Normal file
View File

@ -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"
}
}

18
src/assets/asset.class.ts Normal file
View File

@ -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 {}
}

View File

@ -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);
}

11
src/consts.ts Normal file
View File

@ -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
};

3
src/main.ts Normal file
View File

@ -0,0 +1,3 @@
import Renderer from './renderer/renderer.class';
Renderer.init();

View File

@ -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);
}
}

5
src/style.css Normal file
View File

@ -0,0 +1,5 @@
html, body, div
{
padding: 0;
margin: 0;
}

1
src/vite-env.d.ts vendored Normal file
View File

@ -0,0 +1 @@
/// <reference types="vite/client" />

@ -1 +0,0 @@
Subproject commit 3556fc5d6986e03bcd4776ee2e89b862ec493c10

23
tsconfig.json Normal file
View File

@ -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"]
}