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