Socket
Socket
Sign inDemoInstall

@shapediver/viewer.shared.math

Package Overview
Dependencies
Maintainers
5
Versions
203
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@shapediver/viewer.shared.math - npm Package Compare versions

Comparing version 2.10.1-rc.0 to 2.11.0

64

dist/implementation/Box.js

@@ -1,13 +0,16 @@

import { mat4, vec3, vec4 } from 'gl-matrix';
import { Sphere } from '..';
export class Box {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Box = void 0;
const gl_matrix_1 = require("gl-matrix");
const __1 = require("..");
class Box {
// #endregion Properties (2)
// #region Constructors (1)
constructor(_min = vec3.fromValues(Infinity, Infinity, Infinity), _max = vec3.fromValues(-Infinity, -Infinity, -Infinity)) {
constructor(_min = gl_matrix_1.vec3.fromValues(Infinity, Infinity, Infinity), _max = gl_matrix_1.vec3.fromValues(-Infinity, -Infinity, -Infinity)) {
this._min = _min;
this._max = _max;
// #region Properties (2)
this._boundingSphere = new Sphere();
this._boundingSphere = new __1.Sphere();
this._boundingSphereState = {
min: vec3.create(), max: vec3.create()
min: gl_matrix_1.vec3.create(), max: gl_matrix_1.vec3.create()
};

@@ -57,4 +60,4 @@ }

this._boundingSphereState = {
min: vec3.clone(this.min),
max: vec3.clone(this.max)
min: gl_matrix_1.vec3.clone(this.min),
max: gl_matrix_1.vec3.clone(this.max)
};

@@ -80,15 +83,15 @@ }

const points = [];
points.push(vec3.transformMat4(vec3.create(), vec3.fromValues(this.min[0], this.min[1], this.min[2]), matrix));
points.push(vec3.transformMat4(vec3.create(), vec3.fromValues(this.min[0], this.min[1], this.max[2]), matrix));
points.push(vec3.transformMat4(vec3.create(), vec3.fromValues(this.min[0], this.max[1], this.min[2]), matrix));
points.push(vec3.transformMat4(vec3.create(), vec3.fromValues(this.min[0], this.max[1], this.max[2]), matrix));
points.push(vec3.transformMat4(vec3.create(), vec3.fromValues(this.max[0], this.min[1], this.min[2]), matrix));
points.push(vec3.transformMat4(vec3.create(), vec3.fromValues(this.max[0], this.min[1], this.max[2]), matrix));
points.push(vec3.transformMat4(vec3.create(), vec3.fromValues(this.max[0], this.max[1], this.min[2]), matrix));
points.push(vec3.transformMat4(vec3.create(), vec3.fromValues(this.max[0], this.max[1], this.max[2]), matrix));
this.min = vec3.fromValues(Infinity, Infinity, Infinity);
this.max = vec3.fromValues(-Infinity, -Infinity, -Infinity);
points.push(gl_matrix_1.vec3.transformMat4(gl_matrix_1.vec3.create(), gl_matrix_1.vec3.fromValues(this.min[0], this.min[1], this.min[2]), matrix));
points.push(gl_matrix_1.vec3.transformMat4(gl_matrix_1.vec3.create(), gl_matrix_1.vec3.fromValues(this.min[0], this.min[1], this.max[2]), matrix));
points.push(gl_matrix_1.vec3.transformMat4(gl_matrix_1.vec3.create(), gl_matrix_1.vec3.fromValues(this.min[0], this.max[1], this.min[2]), matrix));
points.push(gl_matrix_1.vec3.transformMat4(gl_matrix_1.vec3.create(), gl_matrix_1.vec3.fromValues(this.min[0], this.max[1], this.max[2]), matrix));
points.push(gl_matrix_1.vec3.transformMat4(gl_matrix_1.vec3.create(), gl_matrix_1.vec3.fromValues(this.max[0], this.min[1], this.min[2]), matrix));
points.push(gl_matrix_1.vec3.transformMat4(gl_matrix_1.vec3.create(), gl_matrix_1.vec3.fromValues(this.max[0], this.min[1], this.max[2]), matrix));
points.push(gl_matrix_1.vec3.transformMat4(gl_matrix_1.vec3.create(), gl_matrix_1.vec3.fromValues(this.max[0], this.max[1], this.min[2]), matrix));
points.push(gl_matrix_1.vec3.transformMat4(gl_matrix_1.vec3.create(), gl_matrix_1.vec3.fromValues(this.max[0], this.max[1], this.max[2]), matrix));
this.min = gl_matrix_1.vec3.fromValues(Infinity, Infinity, Infinity);
this.max = gl_matrix_1.vec3.fromValues(-Infinity, -Infinity, -Infinity);
for (let i = 0, il = points.length; i < il; i++) {
this.min = vec3.fromValues(Math.min(this.min[0], points[i][0]), Math.min(this.min[1], points[i][1]), Math.min(this.min[2], points[i][2]));
this.max = vec3.fromValues(Math.max(this.max[0], points[i][0]), Math.max(this.max[1], points[i][1]), Math.max(this.max[2], points[i][2]));
this.min = gl_matrix_1.vec3.fromValues(Math.min(this.min[0], points[i][0]), Math.min(this.min[1], points[i][1]), Math.min(this.min[2], points[i][2]));
this.max = gl_matrix_1.vec3.fromValues(Math.max(this.max[0], points[i][0]), Math.max(this.max[1], points[i][1]), Math.max(this.max[2], points[i][2]));
}

@@ -98,3 +101,3 @@ return this;

clone() {
return new Box(vec3.clone(this.min), vec3.clone(this.max));
return new Box(gl_matrix_1.vec3.clone(this.min), gl_matrix_1.vec3.clone(this.max));
}

@@ -112,3 +115,3 @@ containsPoint(point) {

}
setFromAttributeArray(array, stride, bytes, matrix = mat4.create()) {
setFromAttributeArray(array, stride, bytes, matrix = gl_matrix_1.mat4.create()) {
let transformedArray = [];

@@ -118,3 +121,3 @@ const length = (Math.floor(array.length / 3) * 3);

for (let i = 0; i < length; i += byteStride) {
let point = vec4.transformMat4(vec4.create(), vec4.fromValues(array[i], array[i + 1], array[i + 2], 1), matrix);
let point = gl_matrix_1.vec4.transformMat4(gl_matrix_1.vec4.create(), gl_matrix_1.vec4.fromValues(array[i], array[i + 1], array[i + 2], 1), matrix);
transformedArray.push([point[0] / point[3], point[1] / point[3], point[2] / point[3]]);

@@ -125,4 +128,4 @@ }

let z_coords = transformedArray.map(p => p[2]);
this.min = vec3.fromValues(Math.min(...x_coords), Math.min(...y_coords), Math.min(...z_coords));
this.max = vec3.fromValues(Math.max(...x_coords), Math.max(...y_coords), Math.max(...z_coords));
this.min = gl_matrix_1.vec3.fromValues(Math.min(...x_coords), Math.min(...y_coords), Math.min(...z_coords));
this.max = gl_matrix_1.vec3.fromValues(Math.max(...x_coords), Math.max(...y_coords), Math.max(...z_coords));
return this;

@@ -150,10 +153,11 @@ }

reset() {
vec3.zero(this._boundingSphere.center);
gl_matrix_1.vec3.zero(this._boundingSphere.center);
this._boundingSphere.radius = 0;
vec3.zero(this._boundingSphereState.min);
vec3.zero(this._boundingSphereState.max);
vec3.set(this._min, Infinity, Infinity, Infinity);
vec3.set(this._max, -Infinity, -Infinity, -Infinity);
gl_matrix_1.vec3.zero(this._boundingSphereState.min);
gl_matrix_1.vec3.zero(this._boundingSphereState.max);
gl_matrix_1.vec3.set(this._min, Infinity, Infinity, Infinity);
gl_matrix_1.vec3.set(this._max, -Infinity, -Infinity, -Infinity);
}
}
exports.Box = Box;
//# sourceMappingURL=Box.js.map

@@ -1,5 +0,8 @@

import { mat3, vec3 } from 'gl-matrix';
export class Plane {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Plane = void 0;
const gl_matrix_1 = require("gl-matrix");
class Plane {
// #region Constructors (1)
constructor(_normal = vec3.fromValues(1, 0, 0), _constant = 0) {
constructor(_normal = gl_matrix_1.vec3.fromValues(1, 0, 0), _constant = 0) {
this._normal = _normal;

@@ -25,6 +28,6 @@ this._constant = _constant;

applyMatrix(matrix) {
const normalMatrix = mat3.transpose(mat3.create(), mat3.invert(mat3.create(), mat3.fromMat4(mat3.create(), matrix)));
const p = vec3.transformMat4(vec3.create(), vec3.multiply(vec3.create(), vec3.clone(this.normal), vec3.fromValues(this._constant, this._constant, this._constant)), matrix);
this._normal = vec3.normalize(vec3.create(), vec3.transformMat3(vec3.create(), this._normal, normalMatrix));
this.constant = -vec3.dot(p, this._normal);
const normalMatrix = gl_matrix_1.mat3.transpose(gl_matrix_1.mat3.create(), gl_matrix_1.mat3.invert(gl_matrix_1.mat3.create(), gl_matrix_1.mat3.fromMat4(gl_matrix_1.mat3.create(), matrix)));
const p = gl_matrix_1.vec3.transformMat4(gl_matrix_1.vec3.create(), gl_matrix_1.vec3.multiply(gl_matrix_1.vec3.create(), gl_matrix_1.vec3.clone(this.normal), gl_matrix_1.vec3.fromValues(this._constant, this._constant, this._constant)), matrix);
this._normal = gl_matrix_1.vec3.normalize(gl_matrix_1.vec3.create(), gl_matrix_1.vec3.transformMat3(gl_matrix_1.vec3.create(), this._normal, normalMatrix));
this.constant = -gl_matrix_1.vec3.dot(p, this._normal);
return this;

@@ -34,3 +37,3 @@ }

const d = -this.distanceToPoint(point);
return vec3.add(vec3.create(), vec3.multiply(vec3.create(), this.normal, vec3.fromValues(d, d, d)), point);
return gl_matrix_1.vec3.add(gl_matrix_1.vec3.create(), gl_matrix_1.vec3.multiply(gl_matrix_1.vec3.create(), this.normal, gl_matrix_1.vec3.fromValues(d, d, d)), point);
}

@@ -44,6 +47,6 @@ clone() {

distanceToPoint(point) {
return vec3.dot(this.normal, point) + this.constant;
return gl_matrix_1.vec3.dot(this.normal, point) + this.constant;
}
intersect(origin, direction) {
const denominator = vec3.dot(this.normal, direction);
const denominator = gl_matrix_1.vec3.dot(this.normal, direction);
if (denominator === 0) {

@@ -56,3 +59,3 @@ // line is coplanar, return origin

}
const t = -(vec3.dot(origin, this.normal) + this.constant) / denominator;
const t = -(gl_matrix_1.vec3.dot(origin, this.normal) + this.constant) / denominator;
if (t < 0)

@@ -63,11 +66,12 @@ return null;

setFromNormalAndCoplanarPoint(normal, point) {
vec3.copy(this.normal, normal);
this.constant = -vec3.dot(point, this.normal);
gl_matrix_1.vec3.copy(this.normal, normal);
this.constant = -gl_matrix_1.vec3.dot(point, this.normal);
return this;
}
reset() {
this._normal = vec3.fromValues(1, 0, 0);
this._normal = gl_matrix_1.vec3.fromValues(1, 0, 0);
this._constant = 0;
}
}
exports.Plane = Plane;
//# sourceMappingURL=Plane.js.map

@@ -1,5 +0,8 @@

import { vec3 } from 'gl-matrix';
export class Sphere {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Sphere = void 0;
const gl_matrix_1 = require("gl-matrix");
class Sphere {
// #region Constructors (1)
constructor(_center = vec3.create(), _radius = 0) {
constructor(_center = gl_matrix_1.vec3.create(), _radius = 0) {
this._center = _center;

@@ -25,3 +28,3 @@ this._radius = _radius;

applyMatrix(matrix) {
this._center = vec3.transformMat4(vec3.create(), this._center, matrix);
this._center = gl_matrix_1.vec3.transformMat4(gl_matrix_1.vec3.create(), this._center, matrix);
const scaleXSq = matrix[0] * matrix[0] + matrix[1] * matrix[1] + matrix[2] * matrix[2];

@@ -35,6 +38,6 @@ const scaleYSq = matrix[4] * matrix[4] + matrix[5] * matrix[5] + matrix[6] * matrix[6];

clone() {
return new Sphere(vec3.clone(this._center), this._radius);
return new Sphere(gl_matrix_1.vec3.clone(this._center), this._radius);
}
containsPoint(point) {
return (vec3.squaredDistance(point, this.center) <= (this.radius * this.radius));
return (gl_matrix_1.vec3.squaredDistance(point, this.center) <= (this.radius * this.radius));
}

@@ -46,7 +49,7 @@ clampPoint(point) {

// vector from ray origin to sphere center
const rayToSphere = vec3.sub(vec3.create(), this.center, origin);
const rayToSphere = gl_matrix_1.vec3.sub(gl_matrix_1.vec3.create(), this.center, origin);
// project rayToSphere onto direction
const projection = vec3.dot(rayToSphere, direction);
const projection = gl_matrix_1.vec3.dot(rayToSphere, direction);
// distance from sphere center to projection
const distanceToProjection = vec3.squaredDistance(rayToSphere, vec3.multiply(vec3.create(), direction, vec3.fromValues(projection, projection, projection)));
const distanceToProjection = gl_matrix_1.vec3.squaredDistance(rayToSphere, gl_matrix_1.vec3.multiply(gl_matrix_1.vec3.create(), direction, gl_matrix_1.vec3.fromValues(projection, projection, projection)));
// check if the distance to projection is less than the radius

@@ -63,20 +66,21 @@ if (distanceToProjection <= this.radius * this.radius) {

// vector from ray origin to sphere center
const rayToSphere = vec3.sub(vec3.create(), this.center, origin);
const rayToSphere = gl_matrix_1.vec3.sub(gl_matrix_1.vec3.create(), this.center, origin);
// project rayToSphere onto direction
const projection = vec3.dot(rayToSphere, direction);
const projection = gl_matrix_1.vec3.dot(rayToSphere, direction);
// distance from sphere center to projection
const distanceToProjection = vec3.squaredDistance(rayToSphere, vec3.multiply(vec3.create(), direction, vec3.fromValues(projection, projection, projection)));
const distanceToProjection = gl_matrix_1.vec3.squaredDistance(rayToSphere, gl_matrix_1.vec3.multiply(gl_matrix_1.vec3.create(), direction, gl_matrix_1.vec3.fromValues(projection, projection, projection)));
return distanceToProjection <= this.radius * this.radius;
}
setFromBox(box) {
vec3.add(this.center, box.min, box.max);
vec3.scale(this.center, this.center, 0.5);
this.radius = vec3.dist(box.min, box.max) * 0.5;
gl_matrix_1.vec3.add(this.center, box.min, box.max);
gl_matrix_1.vec3.scale(this.center, this.center, 0.5);
this.radius = gl_matrix_1.vec3.dist(box.min, box.max) * 0.5;
return this;
}
reset() {
this._center = vec3.create();
this._center = gl_matrix_1.vec3.create();
this._radius = 0;
}
}
exports.Sphere = Sphere;
//# sourceMappingURL=Sphere.js.map

@@ -1,3 +0,6 @@

import { vec3 } from 'gl-matrix';
export class Spherical {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Spherical = void 0;
const gl_matrix_1 = require("gl-matrix");
class Spherical {
constructor(_radius = 1, _phi = 0, _theta = 0) {

@@ -45,5 +48,6 @@ this._radius = _radius;

const sinPhiRadius = Math.sin(this.phi) * this.radius;
return vec3.fromValues(sinPhiRadius * Math.sin(this.theta), Math.cos(this.phi) * this.radius, sinPhiRadius * Math.cos(this.theta));
return gl_matrix_1.vec3.fromValues(sinPhiRadius * Math.sin(this.theta), Math.cos(this.phi) * this.radius, sinPhiRadius * Math.cos(this.theta));
}
}
exports.Spherical = Spherical;
//# sourceMappingURL=Spherical.js.map

@@ -1,4 +0,7 @@

import { vec3 } from 'gl-matrix';
export class Triangle {
constructor(_v0 = vec3.create(), _v1 = vec3.create(), _v2 = vec3.create()) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Triangle = void 0;
const gl_matrix_1 = require("gl-matrix");
class Triangle {
constructor(_v0 = gl_matrix_1.vec3.create(), _v1 = gl_matrix_1.vec3.create(), _v2 = gl_matrix_1.vec3.create()) {
this._v0 = _v0;

@@ -9,9 +12,9 @@ this._v1 = _v1;

applyMatrix(matrix) {
vec3.transformMat4(this._v0, this._v0, matrix);
vec3.transformMat4(this._v1, this._v1, matrix);
vec3.transformMat4(this._v2, this._v2, matrix);
gl_matrix_1.vec3.transformMat4(this._v0, this._v0, matrix);
gl_matrix_1.vec3.transformMat4(this._v1, this._v1, matrix);
gl_matrix_1.vec3.transformMat4(this._v2, this._v2, matrix);
return this;
}
clone() {
return new Triangle(vec3.clone(this._v0), vec3.clone(this._v1), vec3.clone(this._v2));
return new Triangle(gl_matrix_1.vec3.clone(this._v0), gl_matrix_1.vec3.clone(this._v1), gl_matrix_1.vec3.clone(this._v2));
}

@@ -21,27 +24,28 @@ // Möller–Trumbore intersection algorithm

const EPSILON = 0.0000001;
const edge1 = vec3.sub(vec3.create(), this._v1, this._v0);
const edge2 = vec3.sub(vec3.create(), this._v2, this._v0);
const h = vec3.cross(vec3.create(), direction, edge2);
const a = vec3.dot(edge1, h);
const edge1 = gl_matrix_1.vec3.sub(gl_matrix_1.vec3.create(), this._v1, this._v0);
const edge2 = gl_matrix_1.vec3.sub(gl_matrix_1.vec3.create(), this._v2, this._v0);
const h = gl_matrix_1.vec3.cross(gl_matrix_1.vec3.create(), direction, edge2);
const a = gl_matrix_1.vec3.dot(edge1, h);
if (a > -EPSILON && a < EPSILON)
return null; // This ray is parallel to this triangle.
const f = 1.0 / a;
const s = vec3.sub(vec3.create(), origin, this._v0);
const u = f * vec3.dot(s, h);
const s = gl_matrix_1.vec3.sub(gl_matrix_1.vec3.create(), origin, this._v0);
const u = f * gl_matrix_1.vec3.dot(s, h);
if (u < 0.0 || u > 1.0)
return null;
const q = vec3.cross(vec3.create(), s, edge1);
const v = f * vec3.dot(direction, q);
const q = gl_matrix_1.vec3.cross(gl_matrix_1.vec3.create(), s, edge1);
const v = f * gl_matrix_1.vec3.dot(direction, q);
if (v < 0.0 || u + v > 1.0)
return null;
// At this stage we can compute t to find out where the intersection point is on the line.
const t = f * vec3.dot(edge2, q);
return t > EPSILON ? vec3.add(vec3.create(), vec3.multiply(vec3.create(), direction, vec3.fromValues(t, t, t)), origin) : null;
const t = f * gl_matrix_1.vec3.dot(edge2, q);
return t > EPSILON ? gl_matrix_1.vec3.add(gl_matrix_1.vec3.create(), gl_matrix_1.vec3.multiply(gl_matrix_1.vec3.create(), direction, gl_matrix_1.vec3.fromValues(t, t, t)), origin) : null;
}
reset() {
this._v0 = vec3.create();
this._v1 = vec3.create();
this._v2 = vec3.create();
this._v0 = gl_matrix_1.vec3.create();
this._v1 = gl_matrix_1.vec3.create();
this._v2 = gl_matrix_1.vec3.create();
}
}
exports.Triangle = Triangle;
//# sourceMappingURL=Triangle.js.map

@@ -1,7 +0,14 @@

import { Box } from './implementation/Box';
import { Plane } from './implementation/Plane';
import { Sphere } from './implementation/Sphere';
import { Spherical } from './implementation/Spherical';
import { Triangle } from './implementation/Triangle';
export { Box, Sphere, Spherical, Plane, Triangle };
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Triangle = exports.Plane = exports.Spherical = exports.Sphere = exports.Box = void 0;
const Box_1 = require("./implementation/Box");
Object.defineProperty(exports, "Box", { enumerable: true, get: function () { return Box_1.Box; } });
const Plane_1 = require("./implementation/Plane");
Object.defineProperty(exports, "Plane", { enumerable: true, get: function () { return Plane_1.Plane; } });
const Sphere_1 = require("./implementation/Sphere");
Object.defineProperty(exports, "Sphere", { enumerable: true, get: function () { return Sphere_1.Sphere; } });
const Spherical_1 = require("./implementation/Spherical");
Object.defineProperty(exports, "Spherical", { enumerable: true, get: function () { return Spherical_1.Spherical; } });
const Triangle_1 = require("./implementation/Triangle");
Object.defineProperty(exports, "Triangle", { enumerable: true, get: function () { return Triangle_1.Triangle; } });
//# sourceMappingURL=index.js.map

@@ -1,2 +0,3 @@

export {};
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=IBox.js.map

@@ -1,2 +0,3 @@

export {};
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=IGeometry.js.map

@@ -1,2 +0,3 @@

export {};
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=IPlane.js.map

@@ -1,2 +0,3 @@

export {};
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=ISphere.js.map

@@ -1,2 +0,3 @@

export {};
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=ISpherical.js.map

@@ -1,2 +0,3 @@

export {};
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=ITriangle.js.map
{
"name": "@shapediver/viewer.shared.math",
"version": "2.10.1-rc.0",
"version": "2.11.0",
"description": "",

@@ -42,6 +42,6 @@ "keywords": [],

"dependencies": {
"@shapediver/viewer.shared.services": "2.10.1-rc.0",
"@shapediver/viewer.shared.services": "2.11.0",
"gl-matrix": "3.3.0"
},
"gitHead": "7d6e75b740536d82351b9f4d1c2b0722bbde5a87"
"gitHead": "abc828ee5f772bc79b737c994716b8ec372503ef"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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