Socket
Socket
Sign inDemoInstall

gltf-bounding-box

Package Overview
Dependencies
Maintainers
6
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gltf-bounding-box - npm Package Compare versions

Comparing version 0.3.1 to 0.4.1

2

package.json
{
"name": "gltf-bounding-box",
"version": "0.3.1",
"version": "0.4.1",
"description": "Computes the global bounding box of a gltf model",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -5,3 +5,3 @@ import gltf2BoundingBox from './gltf2-bounding-box';

computeBoundings(glb, { precision } = {}) {
computeBoundings(glb, options) {
// Extract json chunk

@@ -17,3 +17,3 @@ const jsonChunkLength = glb.readUInt32LE(12);

return gltf2BoundingBox.computeBoundings(gltf, [binChunkData], { precision });
return gltf2BoundingBox.computeBoundings(gltf, [binChunkData], options);
},

@@ -20,0 +20,0 @@

@@ -9,3 +9,3 @@ import { Matrix } from 'matrixmath';

computeBoundings(gltf, { precision } = {}) {
computeBoundings(gltf, { precision, ceilDimensions } = {}) {
// get all the points and retrieve min max

@@ -19,12 +19,13 @@ const boundings = this.getMeshesTransformMatrices(gltf.nodes, gltf).reduce((acc, point) => {

// Return the dimensions of the bounding box
const dimensionsRound = ceilDimensions === true ? precise.ceil : precise.round;
const res = {
dimensions: {
width: precise.round(boundings.max[0] - boundings.min[0], precision),
depth: precise.round(boundings.max[2] - boundings.min[2], precision),
height: precise.round(boundings.max[1] - boundings.min[1], precision),
width: dimensionsRound(boundings.max[0] - boundings.min[0], precision),
depth: dimensionsRound(boundings.max[2] - boundings.min[2], precision),
height: dimensionsRound(boundings.max[1] - boundings.min[1], precision),
},
center: {
x: precise.round((boundings.max[0] + boundings.min[0]), precision) / 2,
y: precise.round((boundings.max[2] + boundings.min[2]), precision) / 2,
z: precise.round((boundings.max[1] + boundings.min[1]), precision) / 2,
x: precise.round((boundings.max[0] + boundings.min[0]) / 2, precision + 1),
y: precise.round((boundings.max[2] + boundings.min[2]) / 2, precision + 1),
z: precise.round((boundings.max[1] + boundings.min[1]) / 2, precision + 1),
},

@@ -31,0 +32,0 @@ };

@@ -9,3 +9,3 @@ import { Matrix } from 'matrixmath';

computeBoundings(gltf, buffers=[], { precision } = {}) {
computeBoundings(gltf, buffers=[], { precision, ceilDimensions } = {}) {
const boundings = this.getMeshesTransformMatrices(gltf.nodes, gltf, buffers).reduce((acc, point) => {

@@ -18,12 +18,13 @@ acc.min = acc.min.map((elt, i) => elt < point[i] ? elt : point[i]);

// Return the dimensions of the bounding box
const dimensionRound = ceilDimensions ? precise.ceil : precise.round;
const res = {
dimensions: {
width: precise.round(boundings.max[0] - boundings.min[0], precision),
depth: precise.round(boundings.max[2] - boundings.min[2], precision),
height: precise.round(boundings.max[1] - boundings.min[1], precision),
width: dimensionRound(boundings.max[0] - boundings.min[0], precision),
depth: dimensionRound(boundings.max[2] - boundings.min[2], precision),
height: dimensionRound(boundings.max[1] - boundings.min[1], precision),
},
center: {
x: precise.round((boundings.max[0] + boundings.min[0]), precision) / 2,
y: precise.round((boundings.max[2] + boundings.min[2]), precision) / 2,
z: precise.round((boundings.max[1] + boundings.min[1]), precision) / 2,
x: precise.round((boundings.max[0] + boundings.min[0]) / 2, precision + 1),
y: precise.round((boundings.max[2] + boundings.min[2]) / 2, precision + 1),
z: precise.round((boundings.max[1] + boundings.min[1]) / 2, precision + 1),
},

@@ -30,0 +31,0 @@ };

@@ -12,5 +12,9 @@ import gltf1BoundingBox from './gltf1-bounding-box';

* @param {number} options.precision boundings precision, number of decimals.
* @param {boolean} options.ceilDimensions ceil bounding box dimensions to prevent it of being smaller than the actual object.
*/
computeBoundings(gltf, buffers = [], options) {
options = Object.assign({ precision: 0 }, options)
options = Object.assign({
precision: 0,
ceilDimensions: false,
}, options)
if (Boolean(gltf.readUInt32LE)) {

@@ -17,0 +21,0 @@ const version = gltf.readUInt32LE(4);

@@ -8,12 +8,18 @@ const precise = {

* @return {Number} the rounded number
*
* If precision is not 0, the number is rounded using ceil to avoid having a bbox smaller than the actual object.
*/
round(number, precision = 0) {
round(number, precision) {
return precise._operation(Math.round, number, precision);
},
ceil(number, precision = 0) {
return precise._operation(Math.ceil, number, precision);
},
_operation(operation, number, precision = 0) {
if (precision === 0) {
return Math.round(number);
return operation(number);
}
const factor = Math.pow(10, precision);
const tempNumber = number * factor;
const roundedTempNumber = Math.ceil(tempNumber);
const roundedTempNumber = operation(tempNumber);
return roundedTempNumber / factor;

@@ -20,0 +26,0 @@ }

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc