@jscad/x3d-deserializer 2.1.5 → 2.2.2

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.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,33 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [2.2.2](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/x3d-deserializer@2.2.1...@jscad/x3d-deserializer@2.2.2) (2022-08-21)
7
+
8
+ **Note:** Version bump only for package @jscad/x3d-deserializer
9
+
10
+
11
+
12
+
13
+
14
+ ## [2.2.1](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/x3d-deserializer@2.2.0...@jscad/x3d-deserializer@2.2.1) (2022-07-17)
15
+
16
+ **Note:** Version bump only for package @jscad/x3d-deserializer
17
+
18
+
19
+
20
+
21
+
22
+ # [2.2.0](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/x3d-deserializer@2.1.5...@jscad/x3d-deserializer@2.2.0) (2022-06-12)
23
+
24
+
25
+ ### Features
26
+
27
+ * **x3d-serializer:** enhanced to convert 2D geometry and path to X3D Polyline2D ([#1091](https://github.com/jscad/OpenJSCAD.org/issues/1091)) ([4f763a8](https://github.com/jscad/OpenJSCAD.org/commit/4f763a8def39f3b0454f2079f3c1fd7da52dd880))
28
+
29
+
30
+
31
+
32
+
6
33
  ## [2.1.5](https://github.com/jscad/OpenJSCAD.org/compare/@jscad/x3d-deserializer@2.1.4...@jscad/x3d-deserializer@2.1.5) (2022-04-24)
7
34
 
8
35
  **Note:** Version bump only for package @jscad/x3d-deserializer
package/README.md CHANGED
@@ -9,7 +9,7 @@
9
9
  [![License](https://img.shields.io/github/license/jscad/OpenJSCAD.org)](https://github.com/jscad/OpenJSCAD.org/blob/master/LICENSE)
10
10
 
11
11
  [![User Group](https://img.shields.io/badge/maintained%20by-user%20group-blue)](https://openjscad.nodebb.com/)
12
- [![Lerna](https://img.shields.io/badge/maintained%20with-lerna-blue)](https://lernajs.io/)
12
+ [![Lerna](https://img.shields.io/badge/maintained%20with-lerna-blue)](https://lerna.js.org/)
13
13
  [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-blue)](https://standardjs.com)
14
14
 
15
15
  [![Backers](https://img.shields.io/opencollective/backers/openjscad)](https://opencollective.com/openjscad)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jscad/x3d-deserializer",
3
- "version": "2.1.5",
3
+ "version": "2.2.2",
4
4
  "description": "X3D Deserializer for JSCAD",
5
5
  "repository": "https://github.com/jscad/OpenJSCAD.org/",
6
6
  "main": "src/index.js",
@@ -27,12 +27,12 @@
27
27
  },
28
28
  "dependencies": {
29
29
  "@jscad/array-utils": "2.1.4",
30
- "@jscad/modeling": "2.4.0",
30
+ "@jscad/modeling": "2.10.0",
31
31
  "saxes": "5.0.1"
32
32
  },
33
33
  "devDependencies": {
34
34
  "ava": "3.15.0",
35
35
  "nyc": "15.1.0"
36
36
  },
37
- "gitHead": "85fa1fcdfb2d516a201ecf31da242e64b5b3274e"
37
+ "gitHead": "13572067545460affd53b64b3ab834a39af8c7e5"
38
38
  }
@@ -1,7 +1,6 @@
1
1
  const { maths } = require('@jscad/modeling')
2
2
 
3
3
  const createTransform = (center, rotation, scale, scaleOrientation, translation) => {
4
- // console.log('createTransform',center,rotation,scale,scaleOrientation,translation)
5
4
  const matrix = maths.mat4.create()
6
5
  const temp = maths.mat4.create()
7
6
  maths.mat4.multiply(matrix, matrix, maths.mat4.fromTranslation(temp, translation))
package/src/index.js CHANGED
@@ -15,6 +15,7 @@ All code released under MIT license
15
15
 
16
16
  /**
17
17
  * Deserializer of X3D source data (XML) to JSCAD geometries.
18
+ * @see {@link https://github.com/jscad/OpenJSCAD.org/blob/master/packages/io/x3d-deserializer/README.md|README} for supported conversion of X3D entities.
18
19
  * @module io/x3d-deserializer
19
20
  * @example
20
21
  * const { deserializer, extension } = require('@jscad/x3d-deserializer')
@@ -2,36 +2,7 @@ const test = require('ava')
2
2
 
3
3
  const createTransform = require('../src/createTransform')
4
4
 
5
- const Matrix4 = require('./helpers/Matrix4')
6
-
7
- const compareMat4ToMatrix4 = (mat4, matrix4) => {
8
- // console.log('compareMat4ToMatrix4',mat4,matrix4.toString())
9
- const EPS = 0.0000000000001
10
-
11
- if (Math.abs(mat4[0] - matrix4[0]) > EPS) return false
12
- if (Math.abs(mat4[1] - matrix4[1]) > EPS) return false
13
- if (Math.abs(mat4[2] - matrix4[2]) > EPS) return false
14
- if (Math.abs(mat4[3] - matrix4[3]) > EPS) return false
15
-
16
- if (Math.abs(mat4[4] - matrix4[4]) > EPS) return false
17
- if (Math.abs(mat4[5] - matrix4[5]) > EPS) return false
18
- if (Math.abs(mat4[6] - matrix4[6]) > EPS) return false
19
- if (Math.abs(mat4[7] - matrix4[7]) > EPS) return false
20
-
21
- if (Math.abs(mat4[8] - matrix4[8]) > EPS) return false
22
- if (Math.abs(mat4[9] - matrix4[9]) > EPS) return false
23
- if (Math.abs(mat4[10] - matrix4[10]) > EPS) return false
24
- if (Math.abs(mat4[11] - matrix4[11]) > EPS) return false
25
-
26
- if (Math.abs(mat4[12] - matrix4[12]) > EPS) return false
27
- if (Math.abs(mat4[13] - matrix4[13]) > EPS) return false
28
- if (Math.abs(mat4[14] - matrix4[14]) > EPS) return false
29
- if (Math.abs(mat4[15] - matrix4[15]) > EPS) return false
30
- return true
31
- }
32
-
33
5
  test('createTransform returns expected transform matrix', (t) => {
34
- const matrix4 = new Matrix4()
35
6
  // X3D defaults
36
7
  let center = [0, 0, 0]
37
8
  let rotation = [0, 0, 1, 0]
@@ -40,77 +11,107 @@ test('createTransform returns expected transform matrix', (t) => {
40
11
  let translation = [0, 0, 0]
41
12
 
42
13
  let obs = createTransform(center, rotation, scale, scaleOrientation, translation)
43
- let exp = matrix4.set(translation, rotation, scale, scaleOrientation, center)
44
- t.true(compareMat4ToMatrix4(obs, exp))
14
+ let exp = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]
15
+ t.deepEqual(obs, exp)
45
16
 
46
17
  center = [5, 5, 5]
47
18
  obs = createTransform(center, rotation, scale, scaleOrientation, translation)
48
- exp = matrix4.set(translation, rotation, scale, scaleOrientation, center)
49
- t.true(compareMat4ToMatrix4(obs, exp))
19
+ exp = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]
20
+ t.deepEqual(obs, exp)
50
21
  center = [0, 0, 0]
51
22
 
52
23
  scale = [5, 5, 5]
53
24
  obs = createTransform(center, rotation, scale, scaleOrientation, translation)
54
- exp = matrix4.set(translation, rotation, scale, scaleOrientation, center)
55
- t.true(compareMat4ToMatrix4(obs, exp))
25
+ exp = [5, 0, 0, 0, 0, 5, 0, 0, 0, 0, 5, 0, 0, 0, 0, 1]
26
+ t.deepEqual(obs, exp)
56
27
  scale = [1, 1, 1]
57
28
 
58
29
  translation = [5, 5, 5]
59
30
  obs = createTransform(center, rotation, scale, scaleOrientation, translation)
60
- exp = matrix4.set(translation, rotation, scale, scaleOrientation, center)
61
- t.true(compareMat4ToMatrix4(obs, exp))
31
+ exp = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 5, 5, 5, 1]
32
+ t.deepEqual(obs, exp)
62
33
  translation = [0, 0, 0]
63
34
 
64
35
  rotation = [1, 0, 0, -0.707]
65
36
  obs = createTransform(center, rotation, scale, scaleOrientation, translation)
66
- exp = matrix4.set(translation, rotation, scale, scaleOrientation, center)
67
- t.true(compareMat4ToMatrix4(obs, exp))
37
+ exp = [
38
+ 1, 0, 0, 0,
39
+ 0, 0.7603139617444397, -0.6495557555564224, 0,
40
+ 0, 0.6495557555564224, 0.7603139617444397, 0,
41
+ 0, 0, 0, 1
42
+ ]
43
+ t.deepEqual(obs, exp)
68
44
  rotation = [0, 0, 1, 0]
69
45
 
70
46
  rotation = [0.577, 0.577, 0.577, 1]
71
47
  obs = createTransform(center, rotation, scale, scaleOrientation, translation)
72
- exp = matrix4.set(translation, rotation, scale, scaleOrientation, center)
73
- t.true(compareMat4ToMatrix4(obs, exp))
48
+ exp = [
49
+ 0.6935348705787598, 0.6390560643047187, -0.33259093488347846, 0,
50
+ -0.33259093488347846, 0.6935348705787598, 0.6390560643047187, 0,
51
+ 0.6390560643047187, -0.33259093488347846, 0.6935348705787598, 0,
52
+ 0, 0, 0, 1
53
+ ]
54
+ t.deepEqual(obs, exp)
74
55
  rotation = [0, 0, 1, 0]
75
56
 
76
57
  rotation = [0, 0, -1, 0.523599]
77
58
  obs = createTransform(center, rotation, scale, scaleOrientation, translation)
78
- exp = matrix4.set(translation, rotation, scale, scaleOrientation, center)
79
- t.true(compareMat4ToMatrix4(obs, exp))
59
+ exp = [
60
+ 0.8660252915835662, -0.5000001943375613, 0, 0,
61
+ 0.5000001943375613, 0.8660252915835662, 0, 0,
62
+ 0, 0, 1, 0,
63
+ 0, 0, 0, 1
64
+ ]
65
+ t.deepEqual(obs, exp)
80
66
  rotation = [0, 0, 1, 0]
81
67
 
82
68
  rotation = [1, 0, 0, 5.27]
83
69
  obs = createTransform(center, rotation, scale, scaleOrientation, translation)
84
- exp = matrix4.set(translation, rotation, scale, scaleOrientation, center)
85
- t.true(compareMat4ToMatrix4(obs, exp))
70
+ exp = [
71
+ 1, 0, 0, 0,
72
+ 0, 0.5291606082056949, -0.8485216854762045, 0,
73
+ 0, 0.8485216854762045, 0.5291606082056949, 0,
74
+ 0, 0, 0, 1
75
+ ]
76
+ t.deepEqual(obs, exp)
86
77
  rotation = [0, 0, 1, 0]
87
78
 
88
79
  rotation = [0.0, 0.707, 0.707, 0.9]
89
80
  obs = createTransform(center, rotation, scale, scaleOrientation, translation)
90
- exp = matrix4.set(translation, rotation, scale, scaleOrientation, center)
91
- t.true(compareMat4ToMatrix4(obs, exp))
81
+ exp = [
82
+ 0.6216099682706644, 0.5538957696834953, -0.5538957696834953, 0,
83
+ -0.5538957696834953, 0.8108049841353322, 0.18919501586466775, 0,
84
+ 0.5538957696834953, 0.18919501586466775, 0.8108049841353322, 0,
85
+ 0, 0, 0, 1
86
+ ]
87
+ t.deepEqual(obs, exp)
92
88
  rotation = [0, 0, 1, 0]
93
89
 
94
90
  rotation = [0.0, 0.0, 0.0, 1.57]
95
91
  obs = createTransform(center, rotation, scale, scaleOrientation, translation)
96
- exp = matrix4.set(translation, rotation, scale, scaleOrientation, center)
97
- t.true(compareMat4ToMatrix4(obs, exp))
92
+ exp = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]
93
+ t.deepEqual(obs, exp)
98
94
  rotation = [0, 0, 1, 0]
99
95
 
100
96
  // COMBINATIONS
101
97
  scale = [0.91, 0.6, 0.3]
102
98
  translation = [0.8, -0.65, 0.5]
103
99
  obs = createTransform(center, rotation, scale, scaleOrientation, translation)
104
- exp = matrix4.set(translation, rotation, scale, scaleOrientation, center)
105
- t.true(compareMat4ToMatrix4(obs, exp))
100
+ exp = [0.91, 0, 0, 0, 0, 0.6, 0, 0, 0, 0, 0.3, 0, 0.8, -0.65, 0.5, 1]
101
+ t.deepEqual(obs, exp)
106
102
  scale = [1, 1, 1]
107
103
  translation = [0, 0, 0]
108
104
 
109
105
  rotation = [0.0, 0.0, -1.0, 0.523599]
110
106
  translation = [-0.25, 0.75, 0.0]
111
107
  obs = createTransform(center, rotation, scale, scaleOrientation, translation)
112
- exp = matrix4.set(translation, rotation, scale, scaleOrientation, center)
113
- t.true(compareMat4ToMatrix4(obs, exp))
108
+ exp = [
109
+ 0.8660252915835662, -0.5000001943375613, 0, 0,
110
+ 0.5000001943375613, 0.8660252915835662, 0, 0,
111
+ 0, 0, 1, 0,
112
+ -0.25, 0.75, 0, 1
113
+ ]
114
+ t.deepEqual(obs, exp)
114
115
  rotation = [0, 0, 1, 0]
115
116
  translation = [0, 0, 0]
116
117
 
@@ -118,8 +119,13 @@ test('createTransform returns expected transform matrix', (t) => {
118
119
  rotation = [0, 1, 0, 1.57079]
119
120
  translation = [0.00303999, -0.898843, 0.049247]
120
121
  obs = createTransform(center, rotation, scale, scaleOrientation, translation)
121
- exp = matrix4.set(translation, rotation, scale, scaleOrientation, center)
122
- t.true(compareMat4ToMatrix4(obs, exp))
122
+ exp = [
123
+ 0.000006326794896668469, 0, -0.9999999999799858, 0,
124
+ 0, 1, 0, 0,
125
+ 0.9999999999799858, 0, 0.000006326794896668469, 0,
126
+ 0.09181701923155557, -0.898843, -0.04560940909261213, 1
127
+ ]
128
+ t.deepEqual(obs, exp)
123
129
  center = [0, 0, 0]
124
130
  rotation = [0, 0, 1, 0]
125
131
  translation = [0, 0, 0]
@@ -1,371 +0,0 @@
1
- const Vector3 = require('./Vector3')
2
- const Rotation4 = require('./Rotation4')
3
-
4
- function Matrix4 () {
5
- if (arguments.length) {
6
- this[0] = arguments[0]
7
- this[1] = arguments[1]
8
- this[2] = arguments[2]
9
- this[3] = arguments[3]
10
- this[4] = arguments[4]
11
- this[5] = arguments[5]
12
- this[6] = arguments[6]
13
- this[7] = arguments[7]
14
- this[8] = arguments[8]
15
- this[9] = arguments[9]
16
- this[10] = arguments[10]
17
- this[11] = arguments[11]
18
- this[12] = arguments[12]
19
- this[13] = arguments[13]
20
- this[14] = arguments[14]
21
- this[15] = arguments[15]
22
- } else {
23
- this.identity()
24
- }
25
- }
26
-
27
- Matrix4.prototype = {
28
- constructor: Matrix4,
29
- order: 4,
30
- length: 16,
31
- equals: function (matrix) {
32
- return this[0] === matrix[0] &&
33
- this[1] === matrix[1] &&
34
- this[2] === matrix[2] &&
35
- this[3] === matrix[3] &&
36
- this[4] === matrix[4] &&
37
- this[5] === matrix[5] &&
38
- this[6] === matrix[6] &&
39
- this[7] === matrix[7] &&
40
- this[8] === matrix[8] &&
41
- this[9] === matrix[9] &&
42
- this[10] === matrix[10] &&
43
- this[11] === matrix[11] &&
44
- this[12] === matrix[12] &&
45
- this[13] === matrix[13] &&
46
- this[14] === matrix[14] &&
47
- this[15] === matrix[15]
48
- },
49
- set: function (translation, rotation, scale, scaleOrientation, center) {
50
- translation = new Vector3(translation[0], translation[1], translation[2])
51
- rotation = new Rotation4(rotation[0], rotation[1], rotation[2], rotation[3])
52
- scale = new Vector3(scale[0], scale[1], scale[2])
53
- scaleOrientation = new Rotation4(scaleOrientation[0], scaleOrientation[1], scaleOrientation[2], scaleOrientation[3])
54
- center = new Vector3(center[0], center[1], center[2])
55
-
56
- switch (arguments.length) {
57
- case 0: {
58
- this.identity()
59
- break
60
- }
61
- case 1: {
62
- if (translation === null) translation = Vector3.Zero
63
-
64
- this.identity()
65
- this.translate(translation)
66
- break
67
- }
68
- case 2: {
69
- if (translation === null) translation = Vector3.Zero
70
- if (rotation === null) rotation = Rotation4.Identity
71
-
72
- this.identity()
73
- this.translate(translation)
74
-
75
- if (!rotation.equals(Rotation4.Identity)) this.rotate(rotation)
76
-
77
- break
78
- }
79
- case 3: {
80
- if (translation === null) translation = Vector3.Zero
81
- if (rotation === null) rotation = Rotation4.Identity
82
- if (scale === null) scale = Vector3.One
83
-
84
- this.identity()
85
- this.translate(translation)
86
-
87
- if (!rotation.equals(Rotation4.Identity)) this.rotate(rotation)
88
-
89
- if (!scale.equals(Vector3.One)) this.scale(scale)
90
-
91
- break
92
- }
93
- case 4: {
94
- if (translation === null) translation = Vector3.Zero
95
- if (rotation === null) rotation = Rotation4.Identity
96
- if (scale === null) scale = Vector3.One
97
- if (scaleOrientation === null) scaleOrientation = Rotation4.Identity
98
-
99
- this.identity()
100
- this.translate(translation)
101
-
102
- if (!rotation.equals(Rotation4.Identity)) this.rotate(rotation)
103
-
104
- if (!scale.equals(Vector3.One)) {
105
- const hasScaleOrientation = !scaleOrientation.equals(Rotation4.Identity)
106
-
107
- if (hasScaleOrientation) {
108
- this.rotate(scaleOrientation)
109
- this.scale(scale)
110
- this.rotate(Rotation4.inverse(scaleOrientation))
111
- } else {
112
- this.scale(scale)
113
- }
114
- }
115
- break
116
- }
117
- case 5: {
118
- if (translation === null) translation = Vector3.Zero
119
- if (rotation === null) rotation = Rotation4.Identity
120
- if (scale === null) scale = Vector3.One
121
- if (scaleOrientation === null) scaleOrientation = Rotation4.Identity
122
- if (center === null) center = Vector3.Zero
123
-
124
- // P' = T * C * R * SR * S * -SR * -C * P
125
- this.identity()
126
- this.translate(translation)
127
-
128
- const hasCenter = !center.equals(Vector3.Zero)
129
-
130
- if (hasCenter) this.translate(center)
131
-
132
- if (!rotation.equals(Rotation4.Identity)) this.rotate(rotation)
133
-
134
- if (!scale.equals(Vector3.One)) {
135
- if (!scaleOrientation.equals(Rotation4.Identity)) {
136
- this.rotate(scaleOrientation)
137
- this.scale(scale)
138
- this.rotate(Rotation4.inverse(scaleOrientation))
139
- } else {
140
- this.scale(scale)
141
- }
142
- }
143
-
144
- if (hasCenter) this.translate(Vector3.negate(center))
145
-
146
- break
147
- }
148
- case 16: {
149
- this[0] = arguments[0]
150
- this[1] = arguments[1]
151
- this[2] = arguments[2]
152
- this[3] = arguments[3]
153
- this[4] = arguments[4]
154
- this[5] = arguments[5]
155
- this[6] = arguments[6]
156
- this[7] = arguments[7]
157
- this[8] = arguments[8]
158
- this[9] = arguments[9]
159
- this[10] = arguments[10]
160
- this[11] = arguments[11]
161
- this[12] = arguments[12]
162
- this[13] = arguments[13]
163
- this[14] = arguments[14]
164
- this[15] = arguments[15]
165
- break
166
- }
167
- }
168
-
169
- return this
170
- },
171
- setRotation: function (rotation) {
172
- return this.setQuaternion(rotation.value)
173
- },
174
- setQuaternion: function (quaternion) {
175
- const x = quaternion.x
176
- const y = quaternion.y
177
- const z = quaternion.z
178
- const w = quaternion.w
179
- const A = y * y
180
- const B = z * z
181
- const C = x * y
182
- const D = z * w
183
- const E = z * x
184
- const F = y * w
185
- const G = x * x
186
- const H = y * z
187
- const I = x * w
188
-
189
- this[0] = 1 - 2 * (A + B)
190
- this[1] = 2 * (C + D)
191
- this[2] = 2 * (E - F)
192
- this[3] = 0
193
- this[4] = 2 * (C - D)
194
- this[5] = 1 - 2 * (B + G)
195
- this[6] = 2 * (H + I)
196
- this[7] = 0
197
- this[8] = 2 * (E + F)
198
- this[9] = 2 * (H - I)
199
- this[10] = 1 - 2 * (A + G)
200
- this[11] = 0
201
- this[12] = 0
202
- this[13] = 0
203
- this[14] = 0
204
- this[15] = 1
205
-
206
- return this
207
- },
208
- multLeft: function (matrix) {
209
- const a00 = this[0]
210
- const a01 = this[1]
211
- const a02 = this[2]
212
- const a03 = this[3]
213
- const a04 = this[4]
214
- const a05 = this[5]
215
- const a06 = this[6]
216
- const a07 = this[7]
217
- const a08 = this[8]
218
- const a09 = this[9]
219
- const a10 = this[10]
220
- const a11 = this[11]
221
- const a12 = this[12]
222
- const a13 = this[13]
223
- const a14 = this[14]
224
- const a15 = this[15]
225
- const b00 = matrix[0]
226
- const b01 = matrix[1]
227
- const b02 = matrix[2]
228
- const b03 = matrix[3]
229
- const b04 = matrix[4]
230
- const b05 = matrix[5]
231
- const b06 = matrix[6]
232
- const b07 = matrix[7]
233
- const b08 = matrix[8]
234
- const b09 = matrix[9]
235
- const b10 = matrix[10]
236
- const b11 = matrix[11]
237
- const b12 = matrix[12]
238
- const b13 = matrix[13]
239
- const b14 = matrix[14]
240
- const b15 = matrix[15]
241
-
242
- this[0] = a00 * b00 + a04 * b01 + a08 * b02 + a12 * b03
243
- this[1] = a01 * b00 + a05 * b01 + a09 * b02 + a13 * b03
244
- this[2] = a02 * b00 + a06 * b01 + a10 * b02 + a14 * b03
245
- this[3] = a03 * b00 + a07 * b01 + a11 * b02 + a15 * b03
246
- this[4] = a00 * b04 + a04 * b05 + a08 * b06 + a12 * b07
247
- this[5] = a01 * b04 + a05 * b05 + a09 * b06 + a13 * b07
248
- this[6] = a02 * b04 + a06 * b05 + a10 * b06 + a14 * b07
249
- this[7] = a03 * b04 + a07 * b05 + a11 * b06 + a15 * b07
250
- this[8] = a00 * b08 + a04 * b09 + a08 * b10 + a12 * b11
251
- this[9] = a01 * b08 + a05 * b09 + a09 * b10 + a13 * b11
252
- this[10] = a02 * b08 + a06 * b09 + a10 * b10 + a14 * b11
253
- this[11] = a03 * b08 + a07 * b09 + a11 * b10 + a15 * b11
254
- this[12] = a00 * b12 + a04 * b13 + a08 * b14 + a12 * b15
255
- this[13] = a01 * b12 + a05 * b13 + a09 * b14 + a13 * b15
256
- this[14] = a02 * b12 + a06 * b13 + a10 * b14 + a14 * b15
257
- this[15] = a03 * b12 + a07 * b13 + a11 * b14 + a15 * b15
258
-
259
- return this
260
- },
261
- multRight: function (matrix) {
262
- const a00 = this[0]
263
- const a01 = this[1]
264
- const a02 = this[2]
265
- const a03 = this[3]
266
- const a04 = this[4]
267
- const a05 = this[5]
268
- const a06 = this[6]
269
- const a07 = this[7]
270
- const a08 = this[8]
271
- const a09 = this[9]
272
- const a10 = this[10]
273
- const a11 = this[11]
274
- const a12 = this[12]
275
- const a13 = this[13]
276
- const a14 = this[14]
277
- const a15 = this[15]
278
- const b00 = matrix[0]
279
- const b01 = matrix[1]
280
- const b02 = matrix[2]
281
- const b03 = matrix[3]
282
- const b04 = matrix[4]
283
- const b05 = matrix[5]
284
- const b06 = matrix[6]
285
- const b07 = matrix[7]
286
- const b08 = matrix[8]
287
- const b09 = matrix[9]
288
- const b10 = matrix[10]
289
- const b11 = matrix[11]
290
- const b12 = matrix[12]
291
- const b13 = matrix[13]
292
- const b14 = matrix[14]
293
- const b15 = matrix[15]
294
-
295
- this[0] = a00 * b00 + a01 * b04 + a02 * b08 + a03 * b12
296
- this[1] = a00 * b01 + a01 * b05 + a02 * b09 + a03 * b13
297
- this[2] = a00 * b02 + a01 * b06 + a02 * b10 + a03 * b14
298
- this[3] = a00 * b03 + a01 * b07 + a02 * b11 + a03 * b15
299
- this[4] = a04 * b00 + a05 * b04 + a06 * b08 + a07 * b12
300
- this[5] = a04 * b01 + a05 * b05 + a06 * b09 + a07 * b13
301
- this[6] = a04 * b02 + a05 * b06 + a06 * b10 + a07 * b14
302
- this[7] = a04 * b03 + a05 * b07 + a06 * b11 + a07 * b15
303
- this[8] = a08 * b00 + a09 * b04 + a10 * b08 + a11 * b12
304
- this[9] = a08 * b01 + a09 * b05 + a10 * b09 + a11 * b13
305
- this[10] = a08 * b02 + a09 * b06 + a10 * b10 + a11 * b14
306
- this[11] = a08 * b03 + a09 * b07 + a10 * b11 + a11 * b15
307
- this[12] = a12 * b00 + a13 * b04 + a14 * b08 + a15 * b12
308
- this[13] = a12 * b01 + a13 * b05 + a14 * b09 + a15 * b13
309
- this[14] = a12 * b02 + a13 * b06 + a14 * b10 + a15 * b14
310
- this[15] = a12 * b03 + a13 * b07 + a14 * b11 + a15 * b15
311
-
312
- return this
313
- },
314
- identity: function () {
315
- this[0] = 1
316
- this[1] = 0
317
- this[2] = 0
318
- this[3] = 0
319
- this[4] = 0
320
- this[5] = 1
321
- this[6] = 0
322
- this[7] = 0
323
- this[8] = 0
324
- this[9] = 0
325
- this[10] = 1
326
- this[11] = 0
327
- this[12] = 0
328
- this[13] = 0
329
- this[14] = 0
330
- this[15] = 1
331
- },
332
- translate: function (translation) {
333
- const x = translation.x
334
- const y = translation.y
335
- const z = translation.z
336
-
337
- this[12] += this[0] * x + this[4] * y + this[8] * z
338
- this[13] += this[1] * x + this[5] * y + this[9] * z
339
- this[14] += this[2] * x + this[6] * y + this[10] * z
340
-
341
- return this
342
- },
343
- rotate: function (rotation) {
344
- this.multLeft(rotateMatrix.setQuaternion(rotation.value))
345
-
346
- return this
347
- },
348
- scale: function (scale) {
349
- const x = scale.x
350
- const y = scale.y
351
- const z = scale.z
352
-
353
- this[0] *= x
354
- this[4] *= y
355
- this[8] *= z
356
-
357
- this[1] *= x
358
- this[5] *= y
359
- this[9] *= z
360
-
361
- this[2] *= x
362
- this[6] *= y
363
- this[10] *= z
364
-
365
- return this
366
- }
367
- }
368
-
369
- const rotateMatrix = new Matrix4()
370
-
371
- module.exports = Matrix4
@@ -1,23 +0,0 @@
1
- function Quaternion (x, y, z, w) {
2
- this.x = x
3
- this.y = y
4
- this.z = z
5
- this.w = w
6
- }
7
-
8
- Quaternion.prototype = {
9
- constructor: Quaternion,
10
- length: 4,
11
- set: function (x, y, z, w) {
12
- this.x = x
13
- this.y = y
14
- this.z = z
15
- this.w = w
16
- return this
17
- },
18
- equals: function (quat) {
19
- return this.x === quat.x && this.y === quat.y && this.z === quat.z && this.w === quat.w
20
- }
21
- }
22
-
23
- module.exports = Quaternion
@@ -1,93 +0,0 @@
1
- const Vector3 = require('./Vector3')
2
- const Quaternion = require('./Quaternion')
3
-
4
- const interval = (value, low, high) => {
5
- if (value >= high) return ((value - low) % (high - low)) + low
6
-
7
- if (value < low) return ((value - high) % (high - low)) + high
8
-
9
- return value
10
- }
11
-
12
- function Rotation4 (x, y, z, angle) {
13
- this.x_ = 0
14
- this.y_ = 0
15
- this.z_ = 1
16
- this.angle_ = 0
17
-
18
- switch (arguments.length) {
19
- case 0: {
20
- this.value = new Quaternion(0, 0, 0, 1)
21
- return
22
- }
23
- case 1: {
24
- this.value = arguments[0]
25
- this.update()
26
- return
27
- }
28
- case 2: {
29
- const arg0 = arguments[0]
30
- const arg1 = arguments[1]
31
-
32
- this.value = new Quaternion(0, 0, 0, 1)
33
-
34
- if (arg1 instanceof Vector3) return this.setFromToVec(arg0, arg1)
35
-
36
- this.set(arg0.x, arg0.y, arg0.z, arg1)
37
-
38
- return
39
- }
40
- case 4: {
41
- this.value = new Quaternion(0, 0, 0, 1)
42
- this.set(x, y, z, angle)
43
- break
44
- }
45
- }
46
- }
47
-
48
- Rotation4.prototype = {
49
- constructor: Rotation4,
50
- length: 4,
51
- update: function () {
52
- const rotation = this.get()
53
-
54
- this.x_ = rotation.x
55
- this.y_ = rotation.y
56
- this.z_ = rotation.z
57
- this.angle_ = rotation.w
58
-
59
- return this
60
- },
61
- set: function (x, y, z, angle) {
62
- this.x_ = x
63
- this.y_ = y
64
- this.z_ = z
65
- this.angle_ = angle
66
-
67
- let scale = Math.hypot(x, y, z)
68
-
69
- if (scale === 0) {
70
- this.value.set(0, 0, 0, 1)
71
- return this
72
- }
73
-
74
- // Calculate quaternion
75
-
76
- const halfTheta = interval(angle / 2, 0, Math.PI)
77
- scale = Math.sin(halfTheta) / scale
78
-
79
- this.value.set(x * scale, y * scale, z * scale, Math.cos(halfTheta))
80
- return this
81
- },
82
- equals: function (rot) {
83
- return this.value.equals(rot.value)
84
- }
85
- }
86
-
87
- Object.assign(Rotation4,
88
- {
89
- Identity: new Rotation4()
90
- }
91
- )
92
-
93
- module.exports = Rotation4
@@ -1,28 +0,0 @@
1
- function Vector3 (x, y, z) {
2
- this.x = x
3
- this.y = y
4
- this.z = z
5
- }
6
-
7
- Vector3.prototype = {
8
- constructor: Vector3,
9
- length: 3,
10
- equals: function (vector) {
11
- return this.x === vector.x && this.y === vector.y && this.z === vector.z
12
- }
13
- }
14
-
15
- Object.assign(Vector3, {
16
- Zero: new Vector3(0, 0, 0),
17
- One: new Vector3(1, 1, 1),
18
- negate: (vector) => {
19
- const copy = Object.create(Vector3.prototype)
20
- copy.x = -vector.x
21
- copy.y = -vector.y
22
- copy.z = -vector.z
23
- return copy
24
- }
25
- }
26
- )
27
-
28
- module.exports = Vector3
@@ -1,13 +0,0 @@
1
- function Vector4 (x, y, z, w) {
2
- this.x = x
3
- this.y = y
4
- this.z = z
5
- this.w = w
6
- }
7
-
8
- Vector4.prototype = {
9
- constructor: Vector4,
10
- length: 4
11
- }
12
-
13
- module.exports = Vector4