@shapediver/viewer.shared.math
Advanced tools
Comparing version 2.7.10 to 2.8.0
@@ -11,2 +11,3 @@ import { mat4, vec3 } from 'gl-matrix'; | ||
intersect(origin: vec3, direction: vec3): number | null; | ||
intersects(origin: vec3, direction: vec3): boolean; | ||
get boundingSphere(): ISphere; | ||
@@ -13,0 +14,0 @@ get max(): vec3; |
@@ -51,2 +51,6 @@ "use strict"; | ||
; | ||
intersects(origin, direction) { | ||
return this.intersect(origin, direction) === null ? false : true; | ||
} | ||
; | ||
get boundingSphere() { | ||
@@ -144,8 +148,8 @@ if (!(this._boundingSphereState.min[0] === this.min[0] && this._boundingSphereState.min[1] === this.min[1] && this._boundingSphereState.min[2] === this.min[2] && | ||
reset() { | ||
this._boundingSphere = new __1.Sphere(); | ||
this._boundingSphereState = { | ||
min: gl_matrix_1.vec3.create(), max: gl_matrix_1.vec3.create() | ||
}; | ||
this._min = gl_matrix_1.vec3.fromValues(Infinity, Infinity, Infinity); | ||
this._max = gl_matrix_1.vec3.fromValues(-Infinity, -Infinity, -Infinity); | ||
gl_matrix_1.vec3.zero(this._boundingSphere.center); | ||
this._boundingSphere.radius = 0; | ||
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); | ||
} | ||
@@ -152,0 +156,0 @@ } |
@@ -16,2 +16,4 @@ import { mat4, vec3 } from 'gl-matrix'; | ||
clampPoint(point: vec3): vec3; | ||
intersect(origin: vec3, direction: vec3): number | null; | ||
intersects(origin: vec3, direction: vec3): boolean; | ||
setFromBox(box: IBox): ISphere; | ||
@@ -18,0 +20,0 @@ reset(): void; |
@@ -45,2 +45,27 @@ "use strict"; | ||
} | ||
intersect(origin, direction) { | ||
// vector from ray origin to sphere center | ||
const rayToSphere = gl_matrix_1.vec3.sub(gl_matrix_1.vec3.create(), this.center, origin); | ||
// project rayToSphere onto direction | ||
const projection = gl_matrix_1.vec3.dot(rayToSphere, direction); | ||
// distance from sphere center to 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 | ||
if (distanceToProjection <= this.radius * this.radius) { | ||
// calculate the distance from the origin to the intersection point | ||
const distanceToIntersection = Math.sqrt(this.radius * this.radius - distanceToProjection); | ||
return projection - distanceToIntersection; | ||
} | ||
// if there is no intersection, return null | ||
return null; | ||
} | ||
intersects(origin, direction) { | ||
// vector from ray origin to sphere center | ||
const rayToSphere = gl_matrix_1.vec3.sub(gl_matrix_1.vec3.create(), this.center, origin); | ||
// project rayToSphere onto direction | ||
const projection = gl_matrix_1.vec3.dot(rayToSphere, direction); | ||
// distance from sphere center to 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) { | ||
@@ -47,0 +72,0 @@ gl_matrix_1.vec3.add(this.center, box.min, box.max); |
@@ -13,2 +13,3 @@ import { mat4, vec3 } from "gl-matrix"; | ||
intersect(origin: vec3, direction: vec3): number | null; | ||
intersects(origin: vec3, direction: vec3): boolean; | ||
isEmpty(): boolean; | ||
@@ -15,0 +16,0 @@ setFromAttributeArray(array: Int8Array | Uint8Array | Int16Array | Uint16Array | Uint32Array | Float32Array, stride?: number, bytes?: number, matrix?: mat4): IBox; |
@@ -10,2 +10,4 @@ import { mat4, vec3 } from "gl-matrix"; | ||
clone(): ISphere; | ||
intersect(origin: vec3, direction: vec3): number | null; | ||
intersects(origin: vec3, direction: vec3): boolean; | ||
containsPoint(point: vec3): boolean; | ||
@@ -12,0 +14,0 @@ setFromBox(box: IBox): ISphere; |
{ | ||
"name": "@shapediver/viewer.shared.math", | ||
"version": "2.7.10", | ||
"version": "2.8.0", | ||
"description": "", | ||
@@ -42,7 +42,6 @@ "keywords": [], | ||
"dependencies": { | ||
"@shapediver/viewer.shared.services": "2.7.10", | ||
"gl-matrix": "3.3.0", | ||
"tsyringe": "^4.5.0" | ||
"@shapediver/viewer.shared.services": "2.8.0", | ||
"gl-matrix": "3.3.0" | ||
}, | ||
"gitHead": "08d9680d3b199406d1c6bedc8fbeed3d1ad6a385" | ||
"gitHead": "9caee20107c5d71e43de33edc14ee19d62ec268b" | ||
} |
@@ -62,2 +62,5 @@ import { mat4, vec3, vec4 } from 'gl-matrix' | ||
public intersects(origin: vec3, direction: vec3): boolean { | ||
return this.intersect(origin, direction) === null ? false : true; | ||
}; | ||
@@ -170,9 +173,10 @@ public get boundingSphere(): ISphere { | ||
public reset(): void { | ||
this._boundingSphere = new Sphere(); | ||
this._boundingSphereState = { | ||
min: vec3.create(), max: vec3.create() | ||
} | ||
vec3.zero(this._boundingSphere.center) | ||
this._boundingSphere.radius = 0; | ||
this._min = vec3.fromValues(Infinity, Infinity, Infinity); | ||
this._max = vec3.fromValues(-Infinity, -Infinity, -Infinity); | ||
vec3.zero(this._boundingSphereState.min); | ||
vec3.zero(this._boundingSphereState.max); | ||
vec3.set(this._min, Infinity, Infinity, Infinity); | ||
vec3.set(this._max, -Infinity, -Infinity, -Infinity); | ||
} | ||
@@ -179,0 +183,0 @@ |
@@ -59,2 +59,35 @@ import { mat4, vec3 } from 'gl-matrix' | ||
public intersect(origin: vec3, direction: vec3): number | null { | ||
// vector from ray origin to sphere center | ||
const rayToSphere = vec3.sub(vec3.create(), this.center, origin); | ||
// project rayToSphere onto direction | ||
const projection = 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))); | ||
// check if the distance to projection is less than the radius | ||
if (distanceToProjection <= this.radius * this.radius) { | ||
// calculate the distance from the origin to the intersection point | ||
const distanceToIntersection = Math.sqrt(this.radius * this.radius - distanceToProjection); | ||
return projection - distanceToIntersection; | ||
} | ||
// if there is no intersection, return null | ||
return null; | ||
} | ||
public intersects(origin: vec3, direction: vec3): boolean { | ||
// vector from ray origin to sphere center | ||
const rayToSphere = vec3.sub(vec3.create(), this.center, origin); | ||
// project rayToSphere onto direction | ||
const projection = 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))); | ||
return distanceToProjection <= this.radius * this.radius; | ||
} | ||
public setFromBox(box: IBox): ISphere { | ||
@@ -61,0 +94,0 @@ vec3.add(this.center, box.min, box.max); |
@@ -21,2 +21,3 @@ import { mat4, vec3 } from "gl-matrix"; | ||
intersect(origin: vec3, direction: vec3): number | null; | ||
intersects(origin: vec3, direction: vec3): boolean; | ||
isEmpty(): boolean; | ||
@@ -23,0 +24,0 @@ setFromAttributeArray(array: Int8Array | Uint8Array | Int16Array | Uint16Array | Uint32Array | Float32Array, stride?: number, bytes?: number, matrix?: mat4): IBox; |
@@ -18,2 +18,4 @@ import { mat4, vec3 } from "gl-matrix"; | ||
clone(): ISphere; | ||
intersect(origin: vec3, direction: vec3): number | null; | ||
intersects(origin: vec3, direction: vec3): boolean; | ||
containsPoint(point: vec3): boolean; | ||
@@ -20,0 +22,0 @@ setFromBox(box: IBox): ISphere; |
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
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
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
85841
2
1083
+ Added@shapediver/viewer.shared.build-data@2.8.0(transitive)
+ Added@shapediver/viewer.shared.services@2.8.0(transitive)
+ Added@types/uuid@9.0.8(transitive)
+ Addeduuid@9.0.1(transitive)
- Removedtsyringe@^4.5.0
- Removed@sentry/browser@6.19.7(transitive)
- Removed@sentry/core@6.19.7(transitive)
- Removed@sentry/hub@6.19.7(transitive)
- Removed@sentry/minimal@6.19.7(transitive)
- Removed@sentry/tracing@6.19.7(transitive)
- Removed@sentry/types@6.19.7(transitive)
- Removed@sentry/utils@6.19.7(transitive)
- Removed@shapediver/viewer.shared.build-data@2.7.10(transitive)
- Removed@shapediver/viewer.shared.services@2.7.10(transitive)
- Removed@types/uuid@8.3.4(transitive)
- Removedtslib@1.14.1(transitive)
- Removedtsyringe@4.8.0(transitive)