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.2.2 to 0.3.0

src/precise.js

37

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

@@ -32,6 +32,6 @@ "main": "dist/index.js",

"devDependencies": {
"babel-core": "6.26.0",
"babel-loader": "7.1.2",
"babel-core": "6.26.3",
"babel-loader": "7.1.5",
"babel-plugin-add-module-exports": "^0.2.1",
"babel-preset-latest": "6.24.1",
"babel-preset-env": "^1.7.0",
"babel-register": "6.26.0",

@@ -42,19 +42,20 @@ "chai": "4.1.2",

"gulp": "3.9.1",
"gulp-eslint": "4.0.0",
"gulp-filter": "5.0.1",
"gulp-istanbul": "1.1.2",
"gulp-eslint": "5.0.0",
"gulp-filter": "5.1.0",
"gulp-istanbul": "1.1.3",
"gulp-livereload": "3.8.1",
"gulp-load-plugins": "1.5.0",
"gulp-mocha": "4.3.1",
"gulp-plumber": "1.1.0",
"gulp-rename": "1.2.2",
"gulp-sourcemaps": "2.6.1",
"gulp-uglify": "3.0.0",
"isparta": "4.0.0",
"gulp-mocha": "6.0.0",
"gulp-plumber": "1.2.0",
"gulp-rename": "1.4.0",
"gulp-sourcemaps": "2.6.4",
"gulp-uglify": "3.0.1",
"isparta": "4.1.0",
"json-loader": "0.5.7",
"mocha": "3.5.3",
"sinon": "3.3.0",
"sinon-chai": "2.13.0",
"webpack": "3.6.0",
"webpack-stream": "4.0.0"
"mocha": "5.2.0",
"natives": "1.1.6",
"sinon": "6.1.4",
"sinon-chai": "3.2.0",
"webpack": "4.16.5",
"webpack-stream": "5.1.1"
},

@@ -61,0 +62,0 @@ "babelBoilerplateOptions": {

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

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

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

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

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

@@ -5,5 +5,7 @@ import { Matrix } from 'matrixmath';

import precise from './precise';
const gltf1BoundingBox = {
computeBoundings(gltf) {
computeBoundings(gltf, { precision } = {}) {
// get all the points and retrieve min max

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

dimensions: {
width: Math.round(boundings.max[0] - boundings.min[0]),
depth: Math.round(boundings.max[2] - boundings.min[2]),
height: Math.round(boundings.max[1] - boundings.min[1]),
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),
},
center: {
x: Math.round((boundings.max[0] + boundings.min[0]) / 2),
y: Math.round((boundings.max[2] + boundings.min[2]) / 2),
z: Math.round((boundings.max[1] + boundings.min[1]) / 2),
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,
},

@@ -59,5 +61,3 @@ };

const transformedPoints = positions.map(point => Matrix.multiply(point, matrix));
acc.push(...transformedPoints);
return acc;
return acc.concat(transformedPoints);
}, []);

@@ -64,0 +64,0 @@ },

@@ -5,5 +5,7 @@ import { Matrix } from 'matrixmath';

import precise from './precise';
const gltf2BoundingBox = {
computeBoundings(gltf, buffers=[]) {
computeBoundings(gltf, buffers=[], { precision } = {}) {
const boundings = this.getMeshesTransformMatrices(gltf.nodes, gltf, buffers).reduce((acc, point) => {

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

dimensions: {
width: Math.round(boundings.max[0] - boundings.min[0]),
depth: Math.round(boundings.max[2] - boundings.min[2]),
height: Math.round(boundings.max[1] - boundings.min[1]),
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),
},
center: {
x: Math.round((boundings.max[0] + boundings.min[0]) / 2),
y: Math.round((boundings.max[2] + boundings.min[2]) / 2),
z: Math.round((boundings.max[1] + boundings.min[1]) / 2),
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,
},

@@ -51,5 +53,3 @@ };

const transformedPoints = positions.map(point => Matrix.multiply(point, matrix));
acc.push(...transformedPoints);
return acc;
return acc.concat(transformedPoints);
}, []);

@@ -56,0 +56,0 @@ },

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

* @param {Object|Buffer} gltf
* @param {Buffer} [buffers={}] External buffers list if any.
* @param {Buffer} buffers External buffers list if any.
* @param {Object} options
* @param {number} options.precision boundings precision, number of decimals.
*/
computeBoundings(gltf, buffers={}) {
computeBoundings(gltf, buffers = [], options) {
options = Object.assign({ precision: 0 }, options)
if (Boolean(gltf.readUInt32LE)) {
const version = gltf.readUInt32LE(4);
if (version === 2) {
return glb2BoundingBox.computeBoundings(gltf, buffers);
return glb2BoundingBox.computeBoundings(gltf, options);
} else {

@@ -22,5 +25,5 @@ throw new Error("gltf-bounding-box only currently handles glTF1 and glTF/glb2.");

if (+gltf.asset.version === 1) {
return gltf1BoundingBox.computeBoundings(gltf, buffers);
return gltf1BoundingBox.computeBoundings(gltf, options);
} else if (+gltf.asset.version === 2) {
return gltf2BoundingBox.computeBoundings(gltf, buffers);
return gltf2BoundingBox.computeBoundings(gltf, buffers, options);
} else {

@@ -27,0 +30,0 @@ throw new Error("gltf-bounding-box only currently handles glTF1 and glTF/glb2.");

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc