circuit-json-to-gltf 0.0.153 → 0.0.154

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.
Files changed (2) hide show
  1. package/dist/index.js +44 -29
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -17285,36 +17285,51 @@ function getAccessorData(accessor, bufferViews, binaryBuffer) {
17285
17285
  const type = accessor.type;
17286
17286
  const componentsPerElement = type === "SCALAR" ? 1 : type === "VEC2" ? 2 : type === "VEC3" ? 3 : type === "VEC4" ? 4 : 1;
17287
17287
  const totalComponents = count * componentsPerElement;
17288
- if (componentType === 5126) {
17288
+ const componentSize = componentType === 5120 || componentType === 5121 ? 1 : componentType === 5122 || componentType === 5123 ? 2 : 4;
17289
+ const elementSize = componentSize * componentsPerElement;
17290
+ const stride = bufferView.byteStride ?? elementSize;
17291
+ if (componentType === 5126 && stride === elementSize) {
17289
17292
  return new Float32Array(binaryBuffer, byteOffset, totalComponents);
17290
- } else if (componentType === 5123) {
17291
- const uint16Array = new Uint16Array(
17292
- binaryBuffer,
17293
- byteOffset,
17294
- totalComponents
17295
- );
17296
- return new Float32Array(uint16Array);
17297
- } else if (componentType === 5125) {
17298
- const uint32Array = new Uint32Array(
17299
- binaryBuffer,
17300
- byteOffset,
17301
- totalComponents
17302
- );
17303
- return new Float32Array(uint32Array);
17304
- } else if (componentType === 5122) {
17305
- const int16Array = new Int16Array(binaryBuffer, byteOffset, totalComponents);
17306
- return new Float32Array(int16Array);
17307
- } else if (componentType === 5124) {
17308
- const int32Array = new Int32Array(binaryBuffer, byteOffset, totalComponents);
17309
- return new Float32Array(int32Array);
17310
- } else if (componentType === 5121) {
17311
- const uint8Array = new Uint8Array(binaryBuffer, byteOffset, totalComponents);
17312
- return new Float32Array(uint8Array);
17313
- } else if (componentType === 5120) {
17314
- const int8Array = new Int8Array(binaryBuffer, byteOffset, totalComponents);
17315
- return new Float32Array(int8Array);
17316
- }
17317
- throw new Error(`Unsupported component type: ${componentType}`);
17293
+ }
17294
+ const view = new DataView(binaryBuffer);
17295
+ const result = new Float32Array(totalComponents);
17296
+ for (let element = 0; element < count; element++) {
17297
+ for (let component = 0; component < componentsPerElement; component++) {
17298
+ const offset = byteOffset + element * stride + component * componentSize;
17299
+ let value;
17300
+ switch (componentType) {
17301
+ case 5120:
17302
+ value = view.getInt8(offset);
17303
+ if (accessor.normalized) value = Math.max(value / 127, -1);
17304
+ break;
17305
+ case 5121:
17306
+ value = view.getUint8(offset);
17307
+ if (accessor.normalized) value /= 255;
17308
+ break;
17309
+ case 5122:
17310
+ value = view.getInt16(offset, true);
17311
+ if (accessor.normalized) value = Math.max(value / 32767, -1);
17312
+ break;
17313
+ case 5123:
17314
+ value = view.getUint16(offset, true);
17315
+ if (accessor.normalized) value /= 65535;
17316
+ break;
17317
+ case 5124:
17318
+ value = view.getInt32(offset, true);
17319
+ break;
17320
+ case 5125:
17321
+ value = view.getUint32(offset, true);
17322
+ break;
17323
+ case 5126:
17324
+ value = view.getFloat32(offset, true);
17325
+ break;
17326
+ default:
17327
+ throw new Error(`Unsupported component type: ${componentType}`);
17328
+ }
17329
+ result[element * componentsPerElement + component] = value;
17330
+ }
17331
+ }
17332
+ return result;
17318
17333
  }
17319
17334
  function computeNormal(v0, v1, v2) {
17320
17335
  const edge1 = {
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "circuit-json-to-gltf",
3
3
  "main": "dist/index.js",
4
4
  "type": "module",
5
- "version": "0.0.153",
5
+ "version": "0.0.154",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "https://github.com/tscircuit/circuit-json-to-gltf.git"