gltf-bounding-box
Advanced tools
Comparing version 0.1.8 to 0.2.0
{ | ||
"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; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2608849
28
20085
2
1