@plasius/gpu-shared 0.1.4 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/gltf-loader.js"],"sourcesContent":["function decodeDataUri(uri) {\n const match = /^data:.*?;base64,(.+)$/i.exec(uri);\n if (!match) {\n throw new Error(`Unsupported glTF buffer URI: ${uri.slice(0, 48)}`);\n }\n\n const binary = atob(match[1]);\n const bytes = new Uint8Array(binary.length);\n for (let index = 0; index < binary.length; index += 1) {\n bytes[index] = binary.charCodeAt(index);\n }\n return bytes.buffer;\n}\n\nfunction getComponentArray(componentType, buffer, byteOffset, count) {\n switch (componentType) {\n case 5123:\n return new Uint16Array(buffer, byteOffset, count);\n case 5125:\n return new Uint32Array(buffer, byteOffset, count);\n case 5126:\n return new Float32Array(buffer, byteOffset, count);\n default:\n throw new Error(`Unsupported glTF componentType: ${componentType}`);\n }\n}\n\nfunction getTypeSize(type) {\n switch (type) {\n case \"SCALAR\":\n return 1;\n case \"VEC2\":\n return 2;\n case \"VEC3\":\n return 3;\n case \"VEC4\":\n return 4;\n default:\n throw new Error(`Unsupported glTF accessor type: ${type}`);\n }\n}\n\nfunction readAccessor(document, accessorIndex, buffers) {\n const accessor = document.accessors[accessorIndex];\n const bufferView = document.bufferViews[accessor.bufferView];\n const buffer = buffers[bufferView.buffer];\n const componentCount = getTypeSize(accessor.type);\n const byteOffset = (bufferView.byteOffset ?? 0) + (accessor.byteOffset ?? 0);\n const valueCount = accessor.count * componentCount;\n return getComponentArray(accessor.componentType, buffer, byteOffset, valueCount);\n}\n\nfunction getMaterialColor(document, primitive) {\n const material = document.materials?.[primitive.material] ?? null;\n const factor =\n material?.pbrMetallicRoughness?.baseColorFactor ?? [0.56, 0.33, 0.22, 1];\n return {\n r: factor[0],\n g: factor[1],\n b: factor[2],\n a: factor[3] ?? 1,\n };\n}\n\nfunction computeBounds(positions) {\n const min = [Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY];\n const max = [Number.NEGATIVE_INFINITY, Number.NEGATIVE_INFINITY, Number.NEGATIVE_INFINITY];\n for (let index = 0; index < positions.length; index += 3) {\n min[0] = Math.min(min[0], positions[index]);\n min[1] = Math.min(min[1], positions[index + 1]);\n min[2] = Math.min(min[2], positions[index + 2]);\n max[0] = Math.max(max[0], positions[index]);\n max[1] = Math.max(max[1], positions[index + 1]);\n max[2] = Math.max(max[2], positions[index + 2]);\n }\n return { min, max };\n}\n\nexport async function loadGltfModel(url) {\n const response = await fetch(url);\n if (!response.ok) {\n throw new Error(`Failed to load glTF asset: ${response.status} ${response.statusText}`);\n }\n\n const document = await response.json();\n const buffers = await Promise.all(\n (document.buffers ?? []).map(async (buffer) => {\n if (typeof buffer.uri !== \"string\") {\n throw new Error(\"glTF buffer URI is required for demo asset loading.\");\n }\n if (buffer.uri.startsWith(\"data:\")) {\n return decodeDataUri(buffer.uri);\n }\n const nested = await fetch(new URL(buffer.uri, url));\n if (!nested.ok) {\n throw new Error(`Failed to load glTF buffer: ${nested.status} ${nested.statusText}`);\n }\n return nested.arrayBuffer();\n })\n );\n\n const scene = document.scenes?.[document.scene ?? 0];\n if (!scene || !Array.isArray(scene.nodes) || scene.nodes.length === 0) {\n throw new Error(\"glTF demo asset must expose a default scene with at least one node.\");\n }\n\n const node = document.nodes[scene.nodes[0]];\n const mesh = document.meshes[node.mesh];\n const primitive = mesh.primitives[0];\n const positions = Array.from(readAccessor(document, primitive.attributes.POSITION, buffers));\n const indices = Array.from(readAccessor(document, primitive.indices, buffers));\n\n return Object.freeze({\n name: node.name ?? mesh.name ?? \"gltf-model\",\n positions,\n indices,\n bounds: computeBounds(positions),\n color: getMaterialColor(document, primitive),\n physics: Object.freeze({ ...(node.extras?.physics ?? {}) }),\n });\n}\n"],"mappings":";AAAA,SAAS,cAAc,KAAK;AAC1B,QAAM,QAAQ,0BAA0B,KAAK,GAAG;AAChD,MAAI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