From 0a67ccb0409904e5fa8168cccba2ac413997bce3 Mon Sep 17 00:00:00 2001 From: Noelle Calliope <1581674+mekanoe@users.noreply.github.com> Date: Fri, 13 Oct 2023 16:59:46 -0400 Subject: [PATCH] update some build/telemetry stuff --- hack/build.ts | 2 ++ hack/convert-meshes.ts | 50 ++++++++++++++-------------------- hack/templates/work.html.txt | 8 +++--- html/003-scene/index.html | 8 +++--- html/003-scene/main.js | 6 ++--- html/work.css | 48 +++++++++++++++++++++++++++++++++ index.d.ts | 10 +++++++ package.json | 2 +- src/003-scene/main.ts | 28 ++++++++++--------- src/common-shaders/basic.frag | 36 ++++++++----------------- src/common-shaders/basic.ts | 3 +++ src/common-shaders/basic.vert | 5 ++-- src/meshes/plane.ts | 26 ++++-------------- src/meshes/teapot.ts | 26 ++++-------------- src/meshes/torus.ts | 26 ++++-------------- src/meshes/trianglething.ts | 26 ++++-------------- src/meshes/uvsphere.ts | 26 ++++-------------- src/public/work.css | 48 +++++++++++++++++++++++++++++++++ src/renderer/material.ts | 5 +++- src/renderer/mesh-renderer.ts | 31 ++++++++++++++++++--- src/renderer/mesh.ts | 4 +-- src/renderer/shader.ts | 19 ++++++++----- src/renderer/telemetry.ts | 51 ++++++++++++++++++++++++++--------- src/renderer/texture.ts | 17 ++++++++++++ src/renderer/webgl.ts | 42 +++++++++++++++++++++++++---- 25 files changed, 336 insertions(+), 217 deletions(-) create mode 100644 src/renderer/texture.ts diff --git a/hack/build.ts b/hack/build.ts index 4f0b982..c230b66 100644 --- a/hack/build.ts +++ b/hack/build.ts @@ -27,6 +27,8 @@ const results = await Bun.build({ ".wgsl": "text", ".vert": "text", ".frag": "text", + ".html": "text", + ".md": "text", }, minify: process.env.MINIFY === "false" ? false : true, plugins: [glslPlugin], diff --git a/hack/convert-meshes.ts b/hack/convert-meshes.ts index a760bc5..2fbb286 100644 --- a/hack/convert-meshes.ts +++ b/hack/convert-meshes.ts @@ -214,42 +214,32 @@ export const convertMeshes = async () => { : []; const facesArray: number[] = faces.flatMap((f) => [f.a, f.b, f.c]); + const facesMaxValue = facesArray.reduce( + (acc, face) => (face > acc ? face : acc), + 0 + ); + const facesBitDepth = + facesMaxValue <= 0xff ? 8 : facesMaxValue <= 0xffff ? 16 : 32; const outFile = file.replace(".ply", ".ts"); - const outString = ` -import { Mesh } from "../renderer/mesh"; + const outString = `import { Mesh } from "../renderer/mesh"; // prettier-ignore -const positions = new Float32Array(${JSON.stringify(positions)}); - -// prettier-ignore -const colors = ${ - vertexConfig.colors ? `new Uint8Array(${JSON.stringify(colors)})` : "null" - }; - -// prettier-ignore -const uvs = ${ - vertexConfig.uvs ? `new Float32Array(${JSON.stringify(uvs)})` : "null" - }; - - -// prettier-ignore -const normals = ${ - vertexConfig.normals - ? `new Float32Array(${JSON.stringify(normals)})` - : "null" - }; - -// prettier-ignore -const faces = new Uint32Array(${JSON.stringify(facesArray)}); - export default new Mesh({ - colors, - faces, + colors: ${ + vertexConfig.colors ? `new Uint8Array(${JSON.stringify(colors)})` : "null" + }, + faces: new Uint${facesBitDepth}Array(${JSON.stringify(facesArray)}), name: ${JSON.stringify(file)}, - normals, - positions, - uvs, + normals: ${ + vertexConfig.normals + ? `new Float32Array(${JSON.stringify(normals)})` + : "null" + }, + positions: new Float32Array(${JSON.stringify(positions)}), + uvs: ${ + vertexConfig.uvs ? `new Float32Array(${JSON.stringify(uvs)})` : "null" + }, vertexCount: ${vertexCount} }); `; diff --git a/hack/templates/work.html.txt b/hack/templates/work.html.txt index 55a9dda..0f879b4 100644 --- a/hack/templates/work.html.txt +++ b/hack/templates/work.html.txt @@ -1,4 +1,4 @@ - +