From d28d7896deee44662f5af9f98d406fc17ecc2c36 Mon Sep 17 00:00:00 2001 From: Szymon Nowakowski Date: Sun, 17 Mar 2024 20:20:56 +0100 Subject: [PATCH] Update deps, texture demo, fix textures and normals in shader --- .gitattributes | 1 + bun.lockb | Bin 10710 -> 11076 bytes example/script.ts | 86 ++++++++++++++++++++++++++++++------------- example/uvmap.png | 3 ++ package.json | 8 ++-- src/gltf.ts | 9 ++++- src/oktaeder.ts | 4 +- src/shader.ts | 22 +++++------ tsconfig.tsbuildinfo | 1 - 9 files changed, 88 insertions(+), 46 deletions(-) create mode 100644 example/uvmap.png delete mode 100644 tsconfig.tsbuildinfo diff --git a/.gitattributes b/.gitattributes index fdc560a..ab3e086 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1 +1,2 @@ *.webm filter=lfs diff=lfs merge=lfs -text +*.png filter=lfs diff=lfs merge=lfs -text diff --git a/bun.lockb b/bun.lockb index 28d9c1388ebfe186e3c93f1a1392ae3469322f43..db6a8868ad2a70ef43440b60f104b91ca3b30f4f 100644 GIT binary patch literal 11076 zcmeHNdt8iL_n*l`rMs?*CP}(YS5pzip+fFSIg+WSn$%2Yri)9A;}(i8$~BHki8weV z<#Ld&Dp7JPI(2eM2Ztksde@$rJu{s5^`rUc_r4$N^O@GO_uA{b*Is+?XRrONj0~-! zIBcr`2Gfepj3x&}F%{rv8O{n^8q5f%TL!b(5j3u4w6%f^fk4=1ox7-xTFPZ7MLZ3{Ked$Nn=b~x#W)VOICm_Z{TeE}oLea3mhvITBHU@hg+=s|QgmlMti0I3rE z6bJ+!of8nn2oEA`g>KcM91DC1@F3tCz~>6-PdjxSNFXDB!3+ny@?_IMR0nj@lUk*95L2l)nRek-P&q!fybM^nszV@UqQh z>lQ?8`O)n_%aKg&vu_U=^DN9a&;wMB#{UpA=v5Kbv*z@{l!6ss6cJmBY zWzSE&)RBC6h_?Hi)Nx%#VTpU<<4O6U{%T`mAEk3&9(3tG8=&<;Ud2G8JA6rIUsH1N zL^Ji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Q3a z0G2O3(dC$PQrUg2%N7nYG0twSRez8EJoytrXDXUANU%nE=q`i*kJ|yiVGkF8`kMDY z)CXuhKUZMdf0eI2@U;iN_Q3yJ55$OxtF2cZoOSTor?K8?k)#;lpOAD6+HXlzF@ z<}qU#k)dOZ9gJx#W*9p%RQ6rf`(7ld6VZ8JAOXEXXw z0G-$9t&PrW^oB)uO7u2F^`SQxdLN;;40?B^#e?EP@gWR^g)k8|ssq)9>O^&;7*H%ICKMZr5ygsPMzNzdpthhk zp|+tmqPDh*;hEHn2oF?V~r54P3VwO;9!MrHu5v3N)oMNU? zYQfwp<|3sQ%)Vl_Qfk5cEao$%7R=yc##3s+953cXr54NrW7bq^!8|eMRizfpBxB}P zYH@|h40Bb0xml?Nv(cEnm0B=gjrm=v1vA>10hU_o#dBHT7^VuyhnowJ5fRPcT7MJ6 zXK>jx)*L>U$qt)nY%87aPBPP-&kGS^TzIQ{h`VdME+Y6*p2qzjT-t{%FXHof3@+dW z))}w$4fT3G9ZJKx6C^r~y+(>r@115WbSEZSh&1d)u(oXfYH1O!D;V@JPLvIQC5OQi zeuZ$E9R5;1pTiq(W5Z>HF?oFMN^3SJBAjO($qj>OfbqAn5@{>6eC(|GVX>k>MZx`@ zH>yWi1%i+ytb{8R(?IhuevRILk?66M? zMld-%ssn@dQDF`z`=Au` zp1s{i{U^%%pmCxsfd8A}mV_rM3?nc3Ei?9?kAY&4fS^R5P=vEX0wYX)A&#Wq07dfq z3o&HI15jjAUx*_eYJia@z7Rz;TVX%}MDn{&7{aM3K@q0JtiH86udztPF{#q*Z|Og|WzN!+;`_>LU(r z6-MeyyTk{JXn{x*Ul@_>@dQniO@1K~J|;y0$)x&-gZl_0^`(zwe4%kNsn3i__ErM` U!ixrSg@*&WB8cur|9Rj426EA@!vFvP diff --git a/example/script.ts b/example/script.ts index 3a9652b..5a26ca0 100644 --- a/example/script.ts +++ b/example/script.ts @@ -1,4 +1,6 @@ -import { Color, DirectionalLight, Mesh, Node, PerspectiveCamera, PointLight, Quaternion, Scene, Submesh, Vector3 } from "../src/data/index"; +/// + +import { Color, Mesh, Node, PerspectiveCamera, PointLight, Quaternion, Scene, Submesh, Vector3 } from "../src/data/index"; import { Renderer, degToRad } from "../src/oktaeder"; import "./style.css"; @@ -16,38 +18,74 @@ const camera = new PerspectiveCamera({ farPlane: Infinity, }); -const vertexBuffer = renderer.createVertexBuffer({ vertexCount: 6 }); +const vertexBuffer = renderer.createVertexBuffer({ vertexCount: 12, texCoord: true }); vertexBuffer.writeTypedArray(0, { position: new Float32Array([ + 0, 0, 1, + 1, 0, 0, + 0, 1, 0, -1, 0, 0, + 0, 0, -1, + 0, 0, -1, + 0, 0, -1, 1, 0, 0, 0, -1, 0, - 0, 1, 0, + -1, 0, 0, 0, 0, -1, 0, 0, 1, ]), + texCoord: new Float32Array([ + 0.5, 0.7113, + 0.333333, 1, + 0.166666, 0.7113, + 0.333333, 0.4226, + 0, 0.4226, + 0, 1, + 1, 1, + 0.666666, 1, + 0.833333, 0.7113, + 0.666666, 0.4226, + 1, 0.4226, + 0.5, 0.7113, + ]), }); const indexBuffer = renderer.createIndexBuffer({ indexCount: 24, indexFormat: "uint16" }); indexBuffer.writeArray(0, [ - 0, 4, 3, - 4, 1, 3, - 1, 5, 3, - 5, 0, 3, - 4, 0, 2, - 1, 4, 2, + 0, 2, 1, + 3, 4, 2, 5, 1, 2, - 0, 5, 2, + 2, 0, 3, + 6, 8, 7, + 9, 8, 10, + 7, 8, 11, + 11, 8, 9, ]); const submesh: Submesh = { start: 0, length: 24 }; const mesh = new Mesh({ vertexBuffer, indexBuffer, submeshes: [submesh] }); +const imageBitmap = await loadImageBitmap("/uvmap.png"); + +const texture = renderer.createTexture({ + format: "srgb", + width: imageBitmap.width, + height: imageBitmap.height, + usage: GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.COPY_DST | GPUTextureUsage.RENDER_ATTACHMENT, +}); + +renderer._device.queue.copyExternalImageToTexture( + { source: imageBitmap, flipY: false }, + { texture: texture._texture }, + { width: imageBitmap.width, height: imageBitmap.height }, +); + const material = renderer.createMaterial({ baseColor: Color.white(), + baseColorPartialCoverageTexture: texture, roughness: 0.5, - metallic: 1, + metallic: 0, }); const node = new Node({ mesh, materials: [material] }); @@ -55,25 +93,13 @@ const node = new Node({ mesh, materials: [material] }); const scene = new Scene({ nodes: [ node, - new Node({ - translation: new Vector3(-1, 1, 0), - light: new PointLight({ color: new Color(1, 0, 0) }), - }), new Node({ translation: new Vector3(0, 1, -1), - light: new PointLight({ color: new Color(0, 1, 0) }), + light: new PointLight({ color: new Color(1, 1, 1) }), }), new Node({ - translation: new Vector3(1, 1, 0), - light: new PointLight({ color: new Color(0, 0, 1) }), - }), - new Node({ - translation: new Vector3(0, 1, 1), - light: new PointLight({ color: new Color(1, 1, 0) }), - }), - new Node({ - rotation: Quaternion.fromRotationYZ(degToRad(-90)), - light: new DirectionalLight({ color: new Color(0.5, 0.5, 0.5) }), + translation: new Vector3(0, -1, -1), + light: new PointLight({ color: new Color(1, 1, 1) }), }), new Node({ translation: new Vector3(0, 0.8, -3), @@ -91,6 +117,14 @@ function onResize(this: Window) { const _quaternion = Quaternion.identity(); +async function loadImageBitmap(url: string) { + const res = await fetch(url); + const blob = await res.blob(); + const imageBitmap = await createImageBitmap(blob, { colorSpaceConversion: "none" }); + + return imageBitmap; +} + function draw(timeMs: number) { const time = 0.001 * timeMs; node.setRotation(_quaternion.setRotationZX(-0.5 * time)); diff --git a/example/uvmap.png b/example/uvmap.png new file mode 100644 index 0000000..64689f8 --- /dev/null +++ b/example/uvmap.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b9ad63b29f85aed2ef2a6d630028d50a63f3a9050a3f9f0b291dcb5878adf820 +size 1079056 diff --git a/package.json b/package.json index 92a24ce..9555b64 100644 --- a/package.json +++ b/package.json @@ -22,12 +22,12 @@ "build": "tsc --build" }, "dependencies": { - "tslib": "^2.6.1" + "tslib": "^2.6.2" }, "devDependencies": { - "@webgpu/types": "^0.1.34", - "esbuild": "^0.19.2", - "typescript": "5.1.6" + "@webgpu/types": "^0.1.40", + "esbuild": "^0.20.2", + "typescript": "^5.4.2" }, "exports": { ".": { diff --git a/src/gltf.ts b/src/gltf.ts index 1bc9c58..39cd0a1 100644 --- a/src/gltf.ts +++ b/src/gltf.ts @@ -5,6 +5,7 @@ */ import * as data from "./data"; +import * as resources from "./resources"; /* INITIAL SUPPORT PLAN * @@ -94,7 +95,7 @@ import * as data from "./data"; export interface ParseResult { readonly cameras: readonly data.Camera[]; - readonly materials: readonly data.Material[]; + readonly materials: readonly resources.Material[]; readonly lights: readonly data.Light[]; readonly scenes: readonly data.Scene[]; readonly scene: data.Scene | null; @@ -181,7 +182,7 @@ export async function parse(gltf: ArrayBufferView, { }: ParseOptions = {}): Promise { const cameras: data.Camera[] = []; - const materials: data.Material[] = []; + const materials: resources.Material[] = []; const lights: data.Light[] = []; const scenes: data.Scene[] = []; const scene: data.Scene | null = null; @@ -267,6 +268,10 @@ export async function parse(gltf: ArrayBufferView, { // --- JSON CHUNK ---------------------------------------------------------- + void(stopOnFirstError); + void(treatWarningsAsErrors); + void(rest); + throw new Error("TODO"); // --- BIN CHUNK ----------------------------------------------------------- diff --git a/src/oktaeder.ts b/src/oktaeder.ts index 3878bdd..8e56a4a 100644 --- a/src/oktaeder.ts +++ b/src/oktaeder.ts @@ -49,7 +49,7 @@ export class Renderer { _textureWhite: Texture2D; /** 1×1 rgba8unorm texture of [0, 0, 0, 255] */ _textureBlack: Texture2D; - /** 1×1 rgba8unorm texture of [128, 128, 128, 255] */ + /** 1×1 rgba8unorm texture of [128, 128, 255, 255] */ _textureNormal: Texture2D; _depthBuffer: Texture2D; @@ -110,7 +110,7 @@ export class Renderer { height: 1, format: "linear", }); - this._textureNormal.writeFull(new Uint8Array([128, 128, 128, 255])); + this._textureNormal.writeFull(new Uint8Array([128, 128, 255, 255])); const framebufferTexture = this._context.getCurrentTexture(); this._depthBuffer = new Texture2D(this, { diff --git a/src/shader.ts b/src/shader.ts index 99cd009..cb4b6a1 100644 --- a/src/shader.ts +++ b/src/shader.ts @@ -46,10 +46,10 @@ export function _createPipeline(renderer: Renderer, { const shaderModule = renderer._device.createShaderModule({ code: shaderCode, - hints: { - "vert": { layout: renderer._pipelineLayout }, - "frag": { layout: renderer._pipelineLayout }, - }, + compilationHints: [ + { entryPoint: "vert", layout: renderer._pipelineLayout }, + { entryPoint: "frag", layout: renderer._pipelineLayout }, + ], }); let vertexLocation = 0; @@ -318,17 +318,17 @@ fn frag(fragment: Varyings) -> @location(0) vec4 { var emissive = _Material.emissive; var ior = _Material.ior; ${texCoord ? ` - let baseColorPartialCoverageTexel = texture(_BaseColorPartialCoverageTexture, _Sampler, fragment.texCoord); + let baseColorPartialCoverageTexel = textureSample(_BaseColorPartialCoverageTexture, _Sampler, fragment.texCoord); baseColor *= baseColorPartialCoverageTexel.rgb; partialCoverage *= baseColorPartialCoverageTexel.a; - let roughnessMetallicTexel = texture(_RoughnessMetallicTexture, _Sampler, fragment.texCoord); + let roughnessMetallicTexel = textureSample(_RoughnessMetallicTexture, _Sampler, fragment.texCoord); roughness *= roughnessMetallicTexel.g; metallic *= roughnessMetallicTexel.b; - let emissiveTexel = texture(_EmissiveTexture, _Sampler, fragment.texCoord); + let emissiveTexel = textureSample(_EmissiveTexture, _Sampler, fragment.texCoord); emissive *= emissiveTexel.rgb; ` : ""} ${lightTexCoord ? ` - let occlusionTexel = texture(_OcclusionTexture, _Sampler, fragment.lightTexCoord); + let occlusionTexel = textureSample(_OcclusionTexture, _Sampler, fragment.lightTexCoord); occlusion += _Material.occlusionTextureStrength * (occlusionTexel.r - 1.0); ` : ""} @@ -348,10 +348,10 @@ fn frag(fragment: Varyings) -> @location(0) vec4 { ` : ` let matrixTStoVS = screenSpaceMatrixTStoVS(positionVS, geometricNormalVS, fragment.texCoord); `} - let normalTextureTexel = texture(_NormalTexture, _Sampler, fragment.texCoord); + let normalTextureTexel = textureSample(_NormalTexture, _Sampler, fragment.texCoord); var normalTS = normalTextureTexel.xyz * 2.0 - 1.0; - normalTS.xy *= _Material.normalScale; - let actualNormalVS = normalize(matrixTStoVS * geometricNormalVS); + normalTS = vec3(normalTS.xy * _Material.normalScale, normalTS.z); + let actualNormalVS = normalize(matrixTStoVS * normalTS); ` : ` let actualNormalVS = geometricNormalVS; `} diff --git a/tsconfig.tsbuildinfo b/tsconfig.tsbuildinfo deleted file mode 100644 index 5be1229..0000000 --- a/tsconfig.tsbuildinfo +++ /dev/null @@ -1 +0,0 @@ -{"program":{"fileNames":["./node_modules/.pnpm/typescript@5.1.6/node_modules/typescript/lib/lib.es5.d.ts","./node_modules/.pnpm/typescript@5.1.6/node_modules/typescript/lib/lib.es2015.d.ts","./node_modules/.pnpm/typescript@5.1.6/node_modules/typescript/lib/lib.es2016.d.ts","./node_modules/.pnpm/typescript@5.1.6/node_modules/typescript/lib/lib.es2017.d.ts","./node_modules/.pnpm/typescript@5.1.6/node_modules/typescript/lib/lib.es2018.d.ts","./node_modules/.pnpm/typescript@5.1.6/node_modules/typescript/lib/lib.es2019.d.ts","./node_modules/.pnpm/typescript@5.1.6/node_modules/typescript/lib/lib.es2020.d.ts","./node_modules/.pnpm/typescript@5.1.6/node_modules/typescript/lib/lib.es2021.d.ts","./node_modules/.pnpm/typescript@5.1.6/node_modules/typescript/lib/lib.es2022.d.ts","./node_modules/.pnpm/typescript@5.1.6/node_modules/typescript/lib/lib.dom.d.ts","./node_modules/.pnpm/typescript@5.1.6/node_modules/typescript/lib/lib.es2015.core.d.ts","./node_modules/.pnpm/typescript@5.1.6/node_modules/typescript/lib/lib.es2015.collection.d.ts","./node_modules/.pnpm/typescript@5.1.6/node_modules/typescript/lib/lib.es2015.generator.d.ts","./node_modules/.pnpm/typescript@5.1.6/node_modules/typescript/lib/lib.es2015.iterable.d.ts","./node_modules/.pnpm/typescript@5.1.6/node_modules/typescript/lib/lib.es2015.promise.d.ts","./node_modules/.pnpm/typescript@5.1.6/node_modules/typescript/lib/lib.es2015.proxy.d.ts","./node_modules/.pnpm/typescript@5.1.6/node_modules/typescript/lib/lib.es2015.reflect.d.ts","./node_modules/.pnpm/typescript@5.1.6/node_modules/typescript/lib/lib.es2015.symbol.d.ts","./node_modules/.pnpm/typescript@5.1.6/node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts","./node_modules/.pnpm/typescript@5.1.6/node_modules/typescript/lib/lib.es2016.array.include.d.ts","./node_modules/.pnpm/typescript@5.1.6/node_modules/typescript/lib/lib.es2017.object.d.ts","./node_modules/.pnpm/typescript@5.1.6/node_modules/typescript/lib/lib.es2017.sharedmemory.d.ts","./node_modules/.pnpm/typescript@5.1.6/node_modules/typescript/lib/lib.es2017.string.d.ts","./node_modules/.pnpm/typescript@5.1.6/node_modules/typescript/lib/lib.es2017.intl.d.ts","./node_modules/.pnpm/typescript@5.1.6/node_modules/typescript/lib/lib.es2017.typedarrays.d.ts","./node_modules/.pnpm/typescript@5.1.6/node_modules/typescript/lib/lib.es2018.asyncgenerator.d.ts","./node_modules/.pnpm/typescript@5.1.6/node_modules/typescript/lib/lib.es2018.asynciterable.d.ts","./node_modules/.pnpm/typescript@5.1.6/node_modules/typescript/lib/lib.es2018.intl.d.ts","./node_modules/.pnpm/typescript@5.1.6/node_modules/typescript/lib/lib.es2018.promise.d.ts","./node_modules/.pnpm/typescript@5.1.6/node_modules/typescript/lib/lib.es2018.regexp.d.ts","./node_modules/.pnpm/typescript@5.1.6/node_modules/typescript/lib/lib.es2019.array.d.ts","./node_modules/.pnpm/typescript@5.1.6/node_modules/typescript/lib/lib.es2019.object.d.ts","./node_modules/.pnpm/typescript@5.1.6/node_modules/typescript/lib/lib.es2019.string.d.ts","./node_modules/.pnpm/typescript@5.1.6/node_modules/typescript/lib/lib.es2019.symbol.d.ts","./node_modules/.pnpm/typescript@5.1.6/node_modules/typescript/lib/lib.es2019.intl.d.ts","./node_modules/.pnpm/typescript@5.1.6/node_modules/typescript/lib/lib.es2020.bigint.d.ts","./node_modules/.pnpm/typescript@5.1.6/node_modules/typescript/lib/lib.es2020.date.d.ts","./node_modules/.pnpm/typescript@5.1.6/node_modules/typescript/lib/lib.es2020.promise.d.ts","./node_modules/.pnpm/typescript@5.1.6/node_modules/typescript/lib/lib.es2020.sharedmemory.d.ts","./node_modules/.pnpm/typescript@5.1.6/node_modules/typescript/lib/lib.es2020.string.d.ts","./node_modules/.pnpm/typescript@5.1.6/node_modules/typescript/lib/lib.es2020.symbol.wellknown.d.ts","./node_modules/.pnpm/typescript@5.1.6/node_modules/typescript/lib/lib.es2020.intl.d.ts","./node_modules/.pnpm/typescript@5.1.6/node_modules/typescript/lib/lib.es2020.number.d.ts","./node_modules/.pnpm/typescript@5.1.6/node_modules/typescript/lib/lib.es2021.promise.d.ts","./node_modules/.pnpm/typescript@5.1.6/node_modules/typescript/lib/lib.es2021.string.d.ts","./node_modules/.pnpm/typescript@5.1.6/node_modules/typescript/lib/lib.es2021.weakref.d.ts","./node_modules/.pnpm/typescript@5.1.6/node_modules/typescript/lib/lib.es2021.intl.d.ts","./node_modules/.pnpm/typescript@5.1.6/node_modules/typescript/lib/lib.es2022.array.d.ts","./node_modules/.pnpm/typescript@5.1.6/node_modules/typescript/lib/lib.es2022.error.d.ts","./node_modules/.pnpm/typescript@5.1.6/node_modules/typescript/lib/lib.es2022.intl.d.ts","./node_modules/.pnpm/typescript@5.1.6/node_modules/typescript/lib/lib.es2022.object.d.ts","./node_modules/.pnpm/typescript@5.1.6/node_modules/typescript/lib/lib.es2022.sharedmemory.d.ts","./node_modules/.pnpm/typescript@5.1.6/node_modules/typescript/lib/lib.es2022.string.d.ts","./node_modules/.pnpm/typescript@5.1.6/node_modules/typescript/lib/lib.es2022.regexp.d.ts","./node_modules/.pnpm/typescript@5.1.6/node_modules/typescript/lib/lib.decorators.d.ts","./node_modules/.pnpm/typescript@5.1.6/node_modules/typescript/lib/lib.decorators.legacy.d.ts","./node_modules/.pnpm/tslib@2.6.1/node_modules/tslib/tslib.d.ts","./node_modules/.pnpm/tslib@2.6.1/node_modules/tslib/modules/index.d.ts","./src/oktaeder.ts"],"fileInfos":[{"version":"f59215c5f1d886b05395ee7aca73e0ac69ddfad2843aa88530e797879d511bad","affectsGlobalScope":true},"45b7ab580deca34ae9729e97c13cfd999df04416a79116c3bfb483804f85ded4","dc48272d7c333ccf58034c0026162576b7d50ea0e69c3b9292f803fc20720fd5","27147504487dc1159369da4f4da8a26406364624fa9bc3db632f7d94a5bae2c3","5e1c4c362065a6b95ff952c0eab010f04dcd2c3494e813b493ecfd4fcb9fc0d8","68d73b4a11549f9c0b7d352d10e91e5dca8faa3322bfb77b661839c42b1ddec7","5efce4fc3c29ea84e8928f97adec086e3dc876365e0982cc8479a07954a3efd4","feecb1be483ed332fad555aff858affd90a48ab19ba7272ee084704eb7167569","5514e54f17d6d74ecefedc73c504eadffdeda79c7ea205cf9febead32d45c4bc",{"version":"3dda5344576193a4ae48b8d03f105c86f20b2f2aff0a1d1fd7935f5d68649654","affectsGlobalScope":true},{"version":"9d9885c728913c1d16e0d2831b40341d6ad9a0ceecaabc55209b306ad9c736a5","affectsGlobalScope":true},{"version":"17bea081b9c0541f39dd1ae9bc8c78bdd561879a682e60e2f25f688c0ecab248","affectsGlobalScope":true},{"version":"4443e68b35f3332f753eacc66a04ac1d2053b8b035a0e0ac1d455392b5e243b3","affectsGlobalScope":true},{"version":"ab22100fdd0d24cfc2cc59d0a00fc8cf449830d9c4030dc54390a46bd562e929","affectsGlobalScope":true},{"version":"f7bd636ae3a4623c503359ada74510c4005df5b36de7f23e1db8a5c543fd176b","affectsGlobalScope":true},{"version":"ce691fb9e5c64efb9547083e4a34091bcbe5bdb41027e310ebba8f7d96a98671","affectsGlobalScope":true},{"version":"8d697a2a929a5fcb38b7a65594020fcef05ec1630804a33748829c5ff53640d0","affectsGlobalScope":true},{"version":"0c20f4d2358eb679e4ae8a4432bdd96c857a2960fd6800b21ec4008ec59d60ea","affectsGlobalScope":true},{"version":"36ae84ccc0633f7c0787bc6108386c8b773e95d3b052d9464a99cd9b8795fbec","affectsGlobalScope":true},{"version":"82d0d8e269b9eeac02c3bd1c9e884e85d483fcb2cd168bccd6bc54df663da031","affectsGlobalScope":true},{"version":"b8deab98702588840be73d67f02412a2d45a417a3c097b2e96f7f3a42ac483d1","affectsGlobalScope":true},{"version":"4738f2420687fd85629c9efb470793bb753709c2379e5f85bc1815d875ceadcd","affectsGlobalScope":true},{"version":"2f11ff796926e0832f9ae148008138ad583bd181899ab7dd768a2666700b1893","affectsGlobalScope":true},{"version":"376d554d042fb409cb55b5cbaf0b2b4b7e669619493c5d18d5fa8bd67273f82a","affectsGlobalScope":true},{"version":"9fc46429fbe091ac5ad2608c657201eb68b6f1b8341bd6d670047d32ed0a88fa","affectsGlobalScope":true},{"version":"61c37c1de663cf4171e1192466e52c7a382afa58da01b1dc75058f032ddf0839","affectsGlobalScope":true},{"version":"c4138a3dd7cd6cf1f363ca0f905554e8d81b45844feea17786cdf1626cb8ea06","affectsGlobalScope":true},{"version":"6ff3e2452b055d8f0ec026511c6582b55d935675af67cdb67dd1dc671e8065df","affectsGlobalScope":true},{"version":"03de17b810f426a2f47396b0b99b53a82c1b60e9cba7a7edda47f9bb077882f4","affectsGlobalScope":true},{"version":"8184c6ddf48f0c98429326b428478ecc6143c27f79b79e85740f17e6feb090f1","affectsGlobalScope":true},{"version":"261c4d2cf86ac5a89ad3fb3fafed74cbb6f2f7c1d139b0540933df567d64a6ca","affectsGlobalScope":true},{"version":"6af1425e9973f4924fca986636ac19a0cf9909a7e0d9d3009c349e6244e957b6","affectsGlobalScope":true},{"version":"576711e016cf4f1804676043e6a0a5414252560eb57de9faceee34d79798c850","affectsGlobalScope":true},{"version":"89c1b1281ba7b8a96efc676b11b264de7a8374c5ea1e6617f11880a13fc56dc6","affectsGlobalScope":true},{"version":"15a630d6817718a2ddd7088c4f83e4673fde19fa992d2eae2cf51132a302a5d3","affectsGlobalScope":true},{"version":"f06948deb2a51aae25184561c9640fb66afeddb34531a9212d011792b1d19e0a","affectsGlobalScope":true},{"version":"01e0ee7e1f661acedb08b51f8a9b7d7f959e9cdb6441360f06522cc3aea1bf2e","affectsGlobalScope":true},{"version":"ac17a97f816d53d9dd79b0d235e1c0ed54a8cc6a0677e9a3d61efb480b2a3e4e","affectsGlobalScope":true},{"version":"bf14a426dbbf1022d11bd08d6b8e709a2e9d246f0c6c1032f3b2edb9a902adbe","affectsGlobalScope":true},{"version":"ec0104fee478075cb5171e5f4e3f23add8e02d845ae0165bfa3f1099241fa2aa","affectsGlobalScope":true},{"version":"2b72d528b2e2fe3c57889ca7baef5e13a56c957b946906d03767c642f386bbc3","affectsGlobalScope":true},{"version":"9cc66b0513ad41cb5f5372cca86ef83a0d37d1c1017580b7dace3ea5661836df","affectsGlobalScope":true},{"version":"368af93f74c9c932edd84c58883e736c9e3d53cec1fe24c0b0ff451f529ceab1","affectsGlobalScope":true},{"version":"709efdae0cb5df5f49376cde61daacc95cdd44ae4671da13a540da5088bf3f30","affectsGlobalScope":true},{"version":"995c005ab91a498455ea8dfb63aa9f83fa2ea793c3d8aa344be4a1678d06d399","affectsGlobalScope":true},{"version":"61ed9b6d07af959e745fb11f9593ecd743b279418cc8a99448ea3cd5f3b3eb22","affectsGlobalScope":true},{"version":"038a2f66a34ee7a9c2fbc3584c8ab43dff2995f8c68e3f566f4c300d2175e31e","affectsGlobalScope":true},{"version":"4fa6ed14e98aa80b91f61b9805c653ee82af3502dc21c9da5268d3857772ca05","affectsGlobalScope":true},{"version":"f5c92f2c27b06c1a41b88f6db8299205aee52c2a2943f7ed29bd585977f254e8","affectsGlobalScope":true},{"version":"930b0e15811f84e203d3c23508674d5ded88266df4b10abee7b31b2ac77632d2","affectsGlobalScope":true},{"version":"8444af78980e3b20b49324f4a16ba35024fef3ee069a0eb67616ea6ca821c47a","affectsGlobalScope":true},{"version":"b9ea5778ff8b50d7c04c9890170db34c26a5358cccba36844fe319f50a43a61a","affectsGlobalScope":true},{"version":"3287d9d085fbd618c3971944b65b4be57859f5415f495b33a6adc994edd2f004","affectsGlobalScope":true},{"version":"50d53ccd31f6667aff66e3d62adf948879a3a16f05d89882d1188084ee415bbc","affectsGlobalScope":true},{"version":"189c0703923150aa30673fa3de411346d727cc44a11c75d05d7cf9ef095daa22","affectsGlobalScope":true},{"version":"782dec38049b92d4e85c1585fbea5474a219c6984a35b004963b00beb1aab538","affectsGlobalScope":true},"7a1971efcba559ea9002ada4c4e3c925004fb67a755300d53b5edf9399354900","31973b272be35eab5ecf20a38ea54bec84cdc0317117590cb813c72fe0ef75b3","8e609bb71c20b858c77f0e9f90bb1319db8477b13f9f965f1a1e18524bf50881"],"root":[59],"options":{"allowSyntheticDefaultImports":true,"allowUnreachableCode":false,"allowUnusedLabels":false,"alwaysStrict":true,"composite":true,"declaration":true,"declarationMap":true,"esModuleInterop":true,"exactOptionalPropertyTypes":true,"importHelpers":true,"module":7,"newLine":1,"noErrorTruncation":true,"noFallthroughCasesInSwitch":true,"noImplicitAny":true,"noImplicitOverride":true,"noImplicitReturns":true,"noImplicitThis":true,"noPropertyAccessFromIndexSignature":true,"noUncheckedIndexedAccess":true,"noUnusedLocals":true,"noUnusedParameters":true,"removeComments":false,"skipLibCheck":false,"sourceMap":true,"strict":true,"strictBindCallApply":true,"strictFunctionTypes":true,"strictNullChecks":true,"strictPropertyInitialization":true,"target":9,"useUnknownInCatchVariables":true},"fileIdsList":[[57],[58]],"referencedMap":[[58,1],[59,2]],"exportedModulesMap":[[58,1],[59,2]],"semanticDiagnosticsPerFile":[58,57,55,56,10,12,11,2,13,14,15,16,17,18,19,20,3,4,24,21,22,23,25,26,27,5,28,29,30,31,6,35,32,33,34,36,7,37,42,43,38,39,40,41,8,47,44,45,46,48,9,49,50,51,54,52,53,1,59],"latestChangedDtsFile":"./src/oktaeder.d.ts"},"version":"5.1.6"} \ No newline at end of file