Socket
Socket
Sign inDemoInstall

gltf-bounding-box

Package Overview
Dependencies
2
Maintainers
8
Versions
15
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.8 to 0.2.0

dist/index.js

6

package.json
{
"name": "gltf-bounding-box",
"version": "0.1.8",
"version": "0.2.0",
"description": "Computes the global bounding box of a gltf model",
"main": "dist/gltf-bounding-box.js",
"main": "dist/index.js",
"scripts": {

@@ -60,3 +60,3 @@ "test": "gulp",

"babelBoilerplateOptions": {
"entryFileName": "gltf-bounding-box.js",
"entryFileName": "index.js",
"mainVarName": "gltfBoundingBox"

@@ -63,0 +63,0 @@ },

"use strict";
const gltfReader = {
/**
/**
* @private
* @param {Object} gltf
* @param {String} meshName
* @param {String|Number} meshName A number in glTF2
* @param {Object} [buffers={}] External buffers associations uri -> buffer
* @return {Object} Mesh geometry data
*/
loadPositions(gltf, meshName) {
const mesh = gltf.meshes[meshName];
const primitivesCount = mesh.primitives ? mesh.primitives.length : 0;
loadPositions(gltf, meshName, buffers = {}) {
const mesh = gltf.meshes[meshName];
const primitivesCount = mesh.primitives ? mesh.primitives.length : 0;
// @todo If more than one primitive, merge geometry and use MultiMaterial
if (primitivesCount > 1) {
console.error("gltfLoader: Currently unable to load meshes with more than 1 primitive.");
return null;
} else if (primitivesCount === 0) {
console.error("gltfLoader: Mesh has no primitive.");
return null;
}
if (primitivesCount > 1) {
console.error(
"gltfReader: Currently unable to load meshes with more than 1 primitive."
);
return null;
} else if (primitivesCount === 0) {
console.error("gltfReader: Mesh has no primitive.");
return null;
}
const primitive = mesh.primitives[0];
const primitive = mesh.primitives[0];
// Attributes
const attributes = {};
if (!primitive.attributes) return [];
return gltfReader._loadAccessor(gltf, primitive.attributes.POSITION);
},
// Attributes
const attributes = {};
if (!primitive.attributes) return [];
return gltfReader._loadAccessor(
gltf,
primitive.attributes.POSITION,
buffers
);
},
/**
/**
* @private
* @param {Object} gltf
* @param {String} accessorName
* @param {String|Number} accessorName A number in glTF2
* @param {Object} buffers
* @return {Number[]|null}
*/
_loadAccessor(gltf, accessorName) {
if (!accessorName) return null;
_loadAccessor(gltf, accessorName, buffers) {
if (accessorName === undefined) return null;
const accessor = gltf.accessors[accessorName];
const offset = accessor.byteOffset || 0;
const buffer = gltfReader._loadBufferView(gltf, accessor.bufferView, offset);
const accessor = gltf.accessors[accessorName];
const offset = accessor.byteOffset || 0;
const array = [];
switch (accessor.componentType) {
case 5123: // UNSIGNED_SHORT
for (let i = 0; i < buffer.length; i += 2) {
array.push(buffer.readUInt16LE(i));
}
break;
case 5126: // FLOAT
for (let i = 0; i < buffer.length; i += 4) {
array.push(buffer.readFloatLE(i));
}
break;
default:
console.error("gltfLoader: Unsupported component type: " + accessor.componentType);
const buffer = gltfReader._loadBufferView(
gltf,
accessor.bufferView,
offset,
buffers
);
const array = [];
switch (accessor.componentType) {
case 5123: // UNSIGNED_SHORT
for (let i = 0; i < buffer.length; i += 2) {
array.push(buffer.readUInt16LE(i));
}
break;
case 5126: // FLOAT
for (let i = 0; i < buffer.length; i += 4) {
array.push(buffer.readFloatLE(i));
}
break;
default:
console.error(
"gltfLoader: Unsupported component type: " + accessor.componentType
);
}
return array;
},
return array;
},
/**
/**
* @private
* @param {Object} gltf
* @param {String} bufferViewName
* @param {String|Number} bufferViewName A number in glTF2
* @param {Number} offset
* @param {Object} buffers
* @return {Buffer}
*/
_loadBufferView(gltf, bufferViewName, offset) {
const bufferView = gltf.bufferViews[bufferViewName];
const length = bufferView.byteLength || 0;
_loadBufferView(gltf, bufferViewName, offset, buffers) {
offset += bufferView.byteOffset ? bufferView.byteOffset : 0;
const bufferView = gltf.bufferViews[bufferViewName];
const length = bufferView.byteLength || 0;
const buffer = gltfReader._loadBuffer(gltf, bufferView.buffer);
return buffer.slice(offset, offset + length);
},
offset += bufferView.byteOffset ? bufferView.byteOffset : 0;
/**
const buffer = gltfReader._loadBuffer(gltf, bufferView.buffer, buffers);
return buffer.slice(offset, offset + length);
},
/**
* @private
* @param {Object} gltf
* @param {String} bufferName
* @param {String|Number} bufferName A number in glTF2
* @param {Object} buffers
* @return {Buffer}
*/
_loadBuffer(gltf, bufferName) {
if (gltf.loadedBuffers[bufferName]) {
return gltf.loadedBuffers[bufferName];
}
_loadBuffer(gltf, bufferName, buffers) {
if (buffers[bufferName]) {
return buffers[bufferName];
}
const buffer = gltf.buffers[bufferName];
const buffer = gltf.buffers[bufferName];
if (!buffer.uri.startsWith("data:")) {
console.error("gltfLoader: Currently unable to load buffers that are not data-URI based.");
return null;
}
if (!buffer.uri.startsWith("data:")) {
console.error(
"gltfReader: Currently unable to load buffers that are not data-URI based."
);
return null;
}
gltf.loadedBuffers[bufferName] = Buffer.from(buffer.uri.split(",")[1], "base64");
return gltf.loadedBuffers[bufferName];
},
buffers[bufferName] = Buffer.from(
buffer.uri.split(",")[1],
"base64"
);
return buffers[bufferName];
}
};
export default gltfReader;
// module.exports = gltfReader;
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc