@shapediver/viewer.shared.math 3.1.2 → 3.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { mat4, vec3 } from 'gl-matrix';
|
|
2
1
|
import { IPlane } from '../interfaces/IPlane';
|
|
2
|
+
import { mat4, vec3 } from 'gl-matrix';
|
|
3
3
|
export declare class Plane implements IPlane {
|
|
4
4
|
private _normal;
|
|
5
5
|
private _constant;
|
|
@@ -14,7 +14,7 @@ export declare class Plane implements IPlane {
|
|
|
14
14
|
containsPoint(point: vec3): boolean;
|
|
15
15
|
distanceToPoint(point: vec3): number;
|
|
16
16
|
intersect(origin: vec3, direction: vec3): number | null;
|
|
17
|
-
setFromNormalAndCoplanarPoint(normal: vec3, point: vec3): IPlane;
|
|
18
17
|
reset(): void;
|
|
18
|
+
setFromNormalAndCoplanarPoint(normal: vec3, point: vec3): IPlane;
|
|
19
19
|
}
|
|
20
20
|
//# sourceMappingURL=Plane.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Plane.d.ts","sourceRoot":"","sources":["../../src/implementation/Plane.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"Plane.d.ts","sourceRoot":"","sources":["../../src/implementation/Plane.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC9C,OAAO,EAAQ,IAAI,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAE7C,qBAAa,KAAM,YAAW,MAAM;IAGpB,OAAO,CAAC,OAAO;IAAmC,OAAO,CAAC,SAAS;gBAA3D,OAAO,GAAE,IAA+B,EAAU,SAAS,GAAE,MAAU;IAM3F,IAAW,QAAQ,IAAI,MAAM,CAE5B;IAED,IAAW,QAAQ,CAAC,KAAK,EAAE,MAAM,EAEhC;IAED,IAAW,MAAM,IAAI,IAAI,CAExB;IAED,IAAW,MAAM,CAAC,KAAK,EAAE,IAAI,EAE5B;IAMM,WAAW,CAAC,MAAM,EAAE,IAAI,GAAG,MAAM;IAUjC,UAAU,CAAC,KAAK,EAAE,IAAI,GAAG,IAAI;IAK7B,KAAK,IAAI,MAAM;IAIf,aAAa,CAAC,KAAK,EAAE,IAAI,GAAG,OAAO;IAInC,eAAe,CAAC,KAAK,EAAE,IAAI,GAAG,MAAM;IAIpC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,GAAG,MAAM,GAAG,IAAI;IAcvD,KAAK;IAKL,6BAA6B,CAAC,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,GAAG,MAAM;CAO1E"}
|
|
@@ -9,7 +9,7 @@ class Plane {
|
|
|
9
9
|
this._constant = _constant;
|
|
10
10
|
}
|
|
11
11
|
// #endregion Constructors (1)
|
|
12
|
-
// #region Public
|
|
12
|
+
// #region Public Getters And Setters (4)
|
|
13
13
|
get constant() {
|
|
14
14
|
return this._constant;
|
|
15
15
|
}
|
|
@@ -22,10 +22,13 @@ class Plane {
|
|
|
22
22
|
set normal(value) {
|
|
23
23
|
this._normal = value;
|
|
24
24
|
}
|
|
25
|
-
// #endregion Public
|
|
26
|
-
// #region Public Methods (
|
|
25
|
+
// #endregion Public Getters And Setters (4)
|
|
26
|
+
// #region Public Methods (8)
|
|
27
27
|
applyMatrix(matrix) {
|
|
28
|
-
|
|
28
|
+
let inverse = gl_matrix_1.mat3.invert(gl_matrix_1.mat3.create(), gl_matrix_1.mat3.fromMat4(gl_matrix_1.mat3.create(), matrix));
|
|
29
|
+
if (!inverse)
|
|
30
|
+
inverse = gl_matrix_1.mat3.create();
|
|
31
|
+
const normalMatrix = gl_matrix_1.mat3.transpose(gl_matrix_1.mat3.create(), inverse);
|
|
29
32
|
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);
|
|
30
33
|
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));
|
|
31
34
|
this.constant = -gl_matrix_1.vec3.dot(p, this._normal);
|
|
@@ -58,15 +61,15 @@ class Plane {
|
|
|
58
61
|
return null;
|
|
59
62
|
return t; //vec3.add(vec3.create(), vec3.multiply(vec3.create(), direction, vec3.fromValues(t,t,t)), origin);
|
|
60
63
|
}
|
|
64
|
+
reset() {
|
|
65
|
+
this._normal = gl_matrix_1.vec3.fromValues(1, 0, 0);
|
|
66
|
+
this._constant = 0;
|
|
67
|
+
}
|
|
61
68
|
setFromNormalAndCoplanarPoint(normal, point) {
|
|
62
69
|
gl_matrix_1.vec3.copy(this.normal, normal);
|
|
63
70
|
this.constant = -gl_matrix_1.vec3.dot(point, this.normal);
|
|
64
71
|
return this;
|
|
65
72
|
}
|
|
66
|
-
reset() {
|
|
67
|
-
this._normal = gl_matrix_1.vec3.fromValues(1, 0, 0);
|
|
68
|
-
this._constant = 0;
|
|
69
|
-
}
|
|
70
73
|
}
|
|
71
74
|
exports.Plane = Plane;
|
|
72
75
|
//# sourceMappingURL=Plane.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Plane.js","sourceRoot":"","sources":["../../src/implementation/Plane.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"Plane.js","sourceRoot":"","sources":["../../src/implementation/Plane.ts"],"names":[],"mappings":";;;AACA,yCAA6C;AAE7C,MAAa,KAAK;IACd,2BAA2B;IAE3B,YAAoB,UAAgB,gBAAI,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAU,YAAoB,CAAC;QAAvE,YAAO,GAAP,OAAO,CAAiC;QAAU,cAAS,GAAT,SAAS,CAAY;IAAI,CAAC;IAEhG,8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I,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,WAAW,CAAC;QAC1E,IAAI,CAAC,GAAG,CAAC;YAAE,OAAO,IAAI,CAAC;QAEvB,OAAO,CAAC,CAAC,CAAC,mGAAmG;IACjH,CAAC;IAEM,KAAK;QACR,IAAI,CAAC,OAAO,GAAG,gBAAI,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;QACxC,IAAI,CAAC,SAAS,GAAG,CAAC,CAAC;IACvB,CAAC;IAEM,6BAA6B,CAAC,MAAY,EAAE,KAAW;QAC1D,gBAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAC/B,IAAI,CAAC,QAAQ,GAAG,CAAC,gBAAI,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;QAC9C,OAAO,IAAI,CAAC;IAChB,CAAC;CAGJ;AAlFD,sBAkFC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shapediver/viewer.shared.math",
|
|
3
|
-
"version": "3.1
|
|
3
|
+
"version": "3.2.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"author": "Michael Oppitz <michael@shapediver.com>",
|
|
@@ -39,8 +39,8 @@
|
|
|
39
39
|
"testEnvironment": "node"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@shapediver/viewer.shared.services": "3.1
|
|
42
|
+
"@shapediver/viewer.shared.services": "3.2.1",
|
|
43
43
|
"gl-matrix": "3.3.0"
|
|
44
44
|
},
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "00f87aa21c3616bbabf0d06a93f94491324825c5"
|
|
46
46
|
}
|
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
import { mat3, mat4, vec3 } from 'gl-matrix'
|
|
2
1
|
import { IPlane } from '../interfaces/IPlane';
|
|
3
|
-
|
|
2
|
+
import { mat3, mat4, vec3 } from 'gl-matrix';
|
|
4
3
|
|
|
5
4
|
export class Plane implements IPlane {
|
|
6
|
-
|
|
7
5
|
// #region Constructors (1)
|
|
8
6
|
|
|
9
|
-
constructor(private _normal: vec3 = vec3.fromValues(1,0,0), private _constant: number = 0) {}
|
|
7
|
+
constructor(private _normal: vec3 = vec3.fromValues(1, 0, 0), private _constant: number = 0) { }
|
|
10
8
|
|
|
11
9
|
// #endregion Constructors (1)
|
|
12
10
|
|
|
13
|
-
// #region Public
|
|
11
|
+
// #region Public Getters And Setters (4)
|
|
14
12
|
|
|
15
13
|
public get constant(): number {
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
return this._constant;
|
|
15
|
+
}
|
|
18
16
|
|
|
19
17
|
public set constant(value: number) {
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
this._constant = value;
|
|
19
|
+
}
|
|
22
20
|
|
|
23
21
|
public get normal(): vec3 {
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
return this._normal;
|
|
23
|
+
}
|
|
26
24
|
|
|
27
25
|
public set normal(value: vec3) {
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
this._normal = value;
|
|
27
|
+
}
|
|
30
28
|
|
|
31
|
-
// #endregion Public
|
|
29
|
+
// #endregion Public Getters And Setters (4)
|
|
32
30
|
|
|
33
|
-
// #region Public Methods (
|
|
31
|
+
// #region Public Methods (8)
|
|
34
32
|
|
|
35
33
|
public applyMatrix(matrix: mat4): IPlane {
|
|
36
|
-
|
|
37
|
-
|
|
34
|
+
let inverse = mat3.invert(mat3.create(), mat3.fromMat4(mat3.create(), matrix));
|
|
35
|
+
if (!inverse) inverse = mat3.create();
|
|
36
|
+
const normalMatrix = mat3.transpose(mat3.create(), inverse);
|
|
37
|
+
const p = vec3.transformMat4(vec3.create(), vec3.multiply(vec3.create(), vec3.clone(this.normal), vec3.fromValues(this._constant, this._constant, this._constant)), matrix);
|
|
38
38
|
this._normal = vec3.normalize(vec3.create(), vec3.transformMat3(vec3.create(), this._normal, normalMatrix));
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
this.constant = -vec3.dot(p, this._normal);
|
|
40
|
+
return this;
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
public clampPoint(point: vec3): vec3 {
|
|
@@ -50,7 +50,7 @@ export class Plane implements IPlane {
|
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
public containsPoint(point: vec3): boolean {
|
|
53
|
-
|
|
53
|
+
return this.distanceToPoint(point) === 0;
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
public distanceToPoint(point: vec3): number {
|
|
@@ -58,29 +58,29 @@ export class Plane implements IPlane {
|
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
public intersect(origin: vec3, direction: vec3): number | null {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
61
|
+
const denominator = vec3.dot(this.normal, direction);
|
|
62
|
+
if (denominator === 0) {
|
|
63
|
+
// line is coplanar, return origin
|
|
64
|
+
if (this.distanceToPoint(origin) === 0) return 0;
|
|
65
|
+
// Null is preferable to undefined since undefined means.... it is undefined
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
const t = - (vec3.dot(origin, this.normal) + this.constant) / denominator;
|
|
69
|
+
if (t < 0) return null;
|
|
70
70
|
|
|
71
71
|
return t; //vec3.add(vec3.create(), vec3.multiply(vec3.create(), direction, vec3.fromValues(t,t,t)), origin);
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
public setFromNormalAndCoplanarPoint(normal: vec3, point: vec3): IPlane {
|
|
75
|
-
vec3.copy(this.normal, normal);
|
|
76
|
-
this.constant = -vec3.dot(point, this.normal);
|
|
77
|
-
return this;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
74
|
public reset() {
|
|
81
|
-
this._normal = vec3.fromValues(1,0,0);
|
|
75
|
+
this._normal = vec3.fromValues(1, 0, 0);
|
|
82
76
|
this._constant = 0;
|
|
83
77
|
}
|
|
84
78
|
|
|
85
|
-
|
|
79
|
+
public setFromNormalAndCoplanarPoint(normal: vec3, point: vec3): IPlane {
|
|
80
|
+
vec3.copy(this.normal, normal);
|
|
81
|
+
this.constant = -vec3.dot(point, this.normal);
|
|
82
|
+
return this;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// #endregion Public Methods (8)
|
|
86
86
|
}
|