@babylonjs/core 5.28.0 → 5.29.0
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/Actions/actionManager.js +2 -0
- package/Actions/actionManager.js.map +1 -1
- package/Cameras/camera.js +4 -4
- package/Cameras/camera.js.map +1 -1
- package/Collisions/pickingInfo.d.ts +0 -2
- package/Collisions/pickingInfo.js +0 -2
- package/Collisions/pickingInfo.js.map +1 -1
- package/Culling/ray.js +5 -0
- package/Culling/ray.js.map +1 -1
- package/Engines/Extensions/engine.videoTexture.js +6 -3
- package/Engines/Extensions/engine.videoTexture.js.map +1 -1
- package/Engines/renderTargetWrapper.d.ts +2 -1
- package/Engines/renderTargetWrapper.js +1 -0
- package/Engines/renderTargetWrapper.js.map +1 -1
- package/Engines/thinEngine.js +2 -2
- package/Engines/thinEngine.js.map +1 -1
- package/Events/pointerEvents.d.ts +11 -6
- package/Events/pointerEvents.js +24 -6
- package/Events/pointerEvents.js.map +1 -1
- package/Inputs/scene.inputManager.d.ts +9 -1
- package/Inputs/scene.inputManager.js +76 -37
- package/Inputs/scene.inputManager.js.map +1 -1
- package/Layers/effectLayer.js +2 -6
- package/Layers/effectLayer.js.map +1 -1
- package/Materials/PBR/pbrMetallicRoughnessMaterial.d.ts +1 -1
- package/Materials/PBR/pbrMetallicRoughnessMaterial.js +1 -1
- package/Materials/PBR/pbrMetallicRoughnessMaterial.js.map +1 -1
- package/Materials/Textures/htmlElementTexture.d.ts +5 -0
- package/Materials/Textures/htmlElementTexture.js +4 -1
- package/Materials/Textures/htmlElementTexture.js.map +1 -1
- package/Materials/Textures/renderTargetTexture.d.ts +1 -1
- package/Materials/Textures/renderTargetTexture.js +2 -2
- package/Materials/Textures/renderTargetTexture.js.map +1 -1
- package/Materials/Textures/videoTexture.d.ts +6 -1
- package/Materials/Textures/videoTexture.js +7 -2
- package/Materials/Textures/videoTexture.js.map +1 -1
- package/Maths/math.vector.d.ts +390 -319
- package/Maths/math.vector.js +298 -153
- package/Maths/math.vector.js.map +1 -1
- package/Meshes/Builders/decalBuilder.d.ts +8 -0
- package/Meshes/Builders/decalBuilder.js +270 -51
- package/Meshes/Builders/decalBuilder.js.map +1 -1
- package/Meshes/mesh.js +40 -0
- package/Meshes/mesh.js.map +1 -1
- package/PostProcesses/RenderPipeline/Pipelines/defaultRenderingPipeline.d.ts +14 -8
- package/PostProcesses/RenderPipeline/Pipelines/defaultRenderingPipeline.js +16 -6
- package/PostProcesses/RenderPipeline/Pipelines/defaultRenderingPipeline.js.map +1 -1
- package/PostProcesses/blurPostProcess.d.ts +2 -1
- package/PostProcesses/blurPostProcess.js +3 -2
- package/PostProcesses/blurPostProcess.js.map +1 -1
- package/PostProcesses/circleOfConfusionPostProcess.js +2 -1
- package/PostProcesses/circleOfConfusionPostProcess.js.map +1 -1
- package/PostProcesses/depthOfFieldBlurPostProcess.d.ts +2 -1
- package/PostProcesses/depthOfFieldBlurPostProcess.js +3 -5
- package/PostProcesses/depthOfFieldBlurPostProcess.js.map +1 -1
- package/PostProcesses/depthOfFieldEffect.js +9 -4
- package/PostProcesses/depthOfFieldEffect.js.map +1 -1
- package/PostProcesses/depthOfFieldMergePostProcess.js.map +1 -1
- package/PostProcesses/volumetricLightScatteringPostProcess.js +2 -6
- package/PostProcesses/volumetricLightScatteringPostProcess.js.map +1 -1
- package/Rendering/depthRenderer.js +2 -6
- package/Rendering/depthRenderer.js.map +1 -1
- package/Rendering/geometryBufferRenderer.js +2 -6
- package/Rendering/geometryBufferRenderer.js.map +1 -1
- package/Rendering/renderingGroup.d.ts +4 -0
- package/Rendering/renderingGroup.js +7 -1
- package/Rendering/renderingGroup.js.map +1 -1
- package/Rendering/renderingManager.d.ts +5 -0
- package/Rendering/renderingManager.js +15 -0
- package/Rendering/renderingManager.js.map +1 -1
- package/Shaders/circleOfConfusion.fragment.js +1 -1
- package/Shaders/circleOfConfusion.fragment.js.map +1 -1
- package/Shaders/depthOfFieldMerge.fragment.js +1 -1
- package/Shaders/depthOfFieldMerge.fragment.js.map +1 -1
- package/Shaders/kernelBlur.fragment.js +2 -2
- package/Shaders/kernelBlur.fragment.js.map +1 -1
- package/XR/webXRRenderTargetTextureProvider.js +1 -0
- package/XR/webXRRenderTargetTextureProvider.js.map +1 -1
- package/package.json +1 -1
- package/scene.d.ts +5 -0
- package/scene.js +10 -6
- package/scene.js.map +1 -1
package/Maths/math.vector.js
CHANGED
|
@@ -70,7 +70,7 @@ export class Vector2 {
|
|
|
70
70
|
* Example Playground https://playground.babylonjs.com/#QYBWV4#39
|
|
71
71
|
* @param array defines the destination array
|
|
72
72
|
* @param index defines the offset in the destination array
|
|
73
|
-
* @returns the current
|
|
73
|
+
* @returns the current Vector2
|
|
74
74
|
*/
|
|
75
75
|
fromArray(array, index = 0) {
|
|
76
76
|
Vector2.FromArrayToRef(array, index, this);
|
|
@@ -126,19 +126,19 @@ export class Vector2 {
|
|
|
126
126
|
* @returns a new Vector2 set with the addition of the current Vector2 and the given one coordinates
|
|
127
127
|
*/
|
|
128
128
|
add(otherVector) {
|
|
129
|
-
return new
|
|
129
|
+
return new this.constructor(this.x + otherVector.x, this.y + otherVector.y);
|
|
130
130
|
}
|
|
131
131
|
/**
|
|
132
132
|
* Sets the "result" coordinates with the addition of the current Vector2 and the given one coordinates
|
|
133
133
|
* Example Playground https://playground.babylonjs.com/#QYBWV4#12
|
|
134
134
|
* @param otherVector defines the other vector
|
|
135
135
|
* @param result defines the target vector
|
|
136
|
-
* @returns
|
|
136
|
+
* @returns result input
|
|
137
137
|
*/
|
|
138
138
|
addToRef(otherVector, result) {
|
|
139
139
|
result.x = this.x + otherVector.x;
|
|
140
140
|
result.y = this.y + otherVector.y;
|
|
141
|
-
return
|
|
141
|
+
return result;
|
|
142
142
|
}
|
|
143
143
|
/**
|
|
144
144
|
* Set the Vector2 coordinates by adding the given Vector2 coordinates
|
|
@@ -158,7 +158,7 @@ export class Vector2 {
|
|
|
158
158
|
* @returns a new Vector2
|
|
159
159
|
*/
|
|
160
160
|
addVector3(otherVector) {
|
|
161
|
-
return new
|
|
161
|
+
return new this.constructor(this.x + otherVector.x, this.y + otherVector.y);
|
|
162
162
|
}
|
|
163
163
|
/**
|
|
164
164
|
* Gets a new Vector2 set with the subtracted coordinates of the given one from the current Vector2
|
|
@@ -167,19 +167,19 @@ export class Vector2 {
|
|
|
167
167
|
* @returns a new Vector2
|
|
168
168
|
*/
|
|
169
169
|
subtract(otherVector) {
|
|
170
|
-
return new
|
|
170
|
+
return new this.constructor(this.x - otherVector.x, this.y - otherVector.y);
|
|
171
171
|
}
|
|
172
172
|
/**
|
|
173
173
|
* Sets the "result" coordinates with the subtraction of the given one from the current Vector2 coordinates.
|
|
174
174
|
* Example Playground https://playground.babylonjs.com/#QYBWV4#63
|
|
175
175
|
* @param otherVector defines the other vector
|
|
176
176
|
* @param result defines the target vector
|
|
177
|
-
* @returns
|
|
177
|
+
* @returns result input
|
|
178
178
|
*/
|
|
179
179
|
subtractToRef(otherVector, result) {
|
|
180
180
|
result.x = this.x - otherVector.x;
|
|
181
181
|
result.y = this.y - otherVector.y;
|
|
182
|
-
return
|
|
182
|
+
return result;
|
|
183
183
|
}
|
|
184
184
|
/**
|
|
185
185
|
* Sets the current Vector2 coordinates by subtracting from it the given one coordinates
|
|
@@ -210,19 +210,19 @@ export class Vector2 {
|
|
|
210
210
|
* @returns a new Vector2
|
|
211
211
|
*/
|
|
212
212
|
multiply(otherVector) {
|
|
213
|
-
return new
|
|
213
|
+
return new this.constructor(this.x * otherVector.x, this.y * otherVector.y);
|
|
214
214
|
}
|
|
215
215
|
/**
|
|
216
216
|
* Sets "result" coordinates with the multiplication of the current Vector2 and the given one coordinates
|
|
217
217
|
* Example Playground https://playground.babylonjs.com/#QYBWV4#44
|
|
218
218
|
* @param otherVector defines the other vector
|
|
219
219
|
* @param result defines the target vector
|
|
220
|
-
* @returns
|
|
220
|
+
* @returns result input
|
|
221
221
|
*/
|
|
222
222
|
multiplyToRef(otherVector, result) {
|
|
223
223
|
result.x = this.x * otherVector.x;
|
|
224
224
|
result.y = this.y * otherVector.y;
|
|
225
|
-
return
|
|
225
|
+
return result;
|
|
226
226
|
}
|
|
227
227
|
/**
|
|
228
228
|
* Gets a new Vector2 set with the Vector2 coordinates multiplied by the given floats
|
|
@@ -232,7 +232,7 @@ export class Vector2 {
|
|
|
232
232
|
* @returns a new Vector2
|
|
233
233
|
*/
|
|
234
234
|
multiplyByFloats(x, y) {
|
|
235
|
-
return new
|
|
235
|
+
return new this.constructor(this.x * x, this.y * y);
|
|
236
236
|
}
|
|
237
237
|
/**
|
|
238
238
|
* Returns a new Vector2 set with the Vector2 coordinates divided by the given one coordinates
|
|
@@ -241,19 +241,19 @@ export class Vector2 {
|
|
|
241
241
|
* @returns a new Vector2
|
|
242
242
|
*/
|
|
243
243
|
divide(otherVector) {
|
|
244
|
-
return new
|
|
244
|
+
return new this.constructor(this.x / otherVector.x, this.y / otherVector.y);
|
|
245
245
|
}
|
|
246
246
|
/**
|
|
247
247
|
* Sets the "result" coordinates with the Vector2 divided by the given one coordinates
|
|
248
248
|
* Example Playground https://playground.babylonjs.com/#QYBWV4#30
|
|
249
249
|
* @param otherVector defines the other vector
|
|
250
250
|
* @param result defines the target vector
|
|
251
|
-
* @returns
|
|
251
|
+
* @returns result input
|
|
252
252
|
*/
|
|
253
253
|
divideToRef(otherVector, result) {
|
|
254
254
|
result.x = this.x / otherVector.x;
|
|
255
255
|
result.y = this.y / otherVector.y;
|
|
256
|
-
return
|
|
256
|
+
return result;
|
|
257
257
|
}
|
|
258
258
|
/**
|
|
259
259
|
* Divides the current Vector2 coordinates by the given ones
|
|
@@ -270,7 +270,7 @@ export class Vector2 {
|
|
|
270
270
|
* @returns a new Vector2
|
|
271
271
|
*/
|
|
272
272
|
negate() {
|
|
273
|
-
return new
|
|
273
|
+
return new this.constructor(-this.x, -this.y);
|
|
274
274
|
}
|
|
275
275
|
/**
|
|
276
276
|
* Negate this vector in place
|
|
@@ -309,7 +309,7 @@ export class Vector2 {
|
|
|
309
309
|
* @returns a new Vector2
|
|
310
310
|
*/
|
|
311
311
|
scale(scale) {
|
|
312
|
-
const result = new
|
|
312
|
+
const result = new this.constructor(0, 0);
|
|
313
313
|
this.scaleToRef(scale, result);
|
|
314
314
|
return result;
|
|
315
315
|
}
|
|
@@ -318,24 +318,24 @@ export class Vector2 {
|
|
|
318
318
|
* Example Playground https://playground.babylonjs.com/#QYBWV4#57
|
|
319
319
|
* @param scale defines the scale factor
|
|
320
320
|
* @param result defines the Vector2 object where to store the result
|
|
321
|
-
* @returns
|
|
321
|
+
* @returns result input
|
|
322
322
|
*/
|
|
323
323
|
scaleToRef(scale, result) {
|
|
324
324
|
result.x = this.x * scale;
|
|
325
325
|
result.y = this.y * scale;
|
|
326
|
-
return
|
|
326
|
+
return result;
|
|
327
327
|
}
|
|
328
328
|
/**
|
|
329
329
|
* Scale the current Vector2 values by a factor and add the result to a given Vector2
|
|
330
330
|
* Example Playground https://playground.babylonjs.com/#QYBWV4#58
|
|
331
331
|
* @param scale defines the scale factor
|
|
332
332
|
* @param result defines the Vector2 object where to store the result
|
|
333
|
-
* @returns
|
|
333
|
+
* @returns result input
|
|
334
334
|
*/
|
|
335
335
|
scaleAndAddToRef(scale, result) {
|
|
336
336
|
result.x += this.x * scale;
|
|
337
337
|
result.y += this.y * scale;
|
|
338
|
-
return
|
|
338
|
+
return result;
|
|
339
339
|
}
|
|
340
340
|
/**
|
|
341
341
|
* Gets a boolean if two vectors are equals
|
|
@@ -363,7 +363,7 @@ export class Vector2 {
|
|
|
363
363
|
* @returns a new Vector2
|
|
364
364
|
*/
|
|
365
365
|
floor() {
|
|
366
|
-
return new
|
|
366
|
+
return new this.constructor(Math.floor(this.x), Math.floor(this.y));
|
|
367
367
|
}
|
|
368
368
|
/**
|
|
369
369
|
* Gets a new Vector2 from current Vector2 fractional values
|
|
@@ -372,21 +372,21 @@ export class Vector2 {
|
|
|
372
372
|
* @returns a new Vector2
|
|
373
373
|
*/
|
|
374
374
|
fract() {
|
|
375
|
-
return new
|
|
375
|
+
return new this.constructor(this.x - Math.floor(this.x), this.y - Math.floor(this.y));
|
|
376
376
|
}
|
|
377
377
|
/**
|
|
378
378
|
* Rotate the current vector into a given result vector
|
|
379
379
|
* Example Playground https://playground.babylonjs.com/#QYBWV4#49
|
|
380
380
|
* @param angle defines the rotation angle
|
|
381
381
|
* @param result defines the result vector where to store the rotated vector
|
|
382
|
-
* @returns
|
|
382
|
+
* @returns result input
|
|
383
383
|
*/
|
|
384
384
|
rotateToRef(angle, result) {
|
|
385
385
|
const cos = Math.cos(angle);
|
|
386
386
|
const sin = Math.sin(angle);
|
|
387
387
|
result.x = cos * this.x - sin * this.y;
|
|
388
388
|
result.y = sin * this.x + cos * this.y;
|
|
389
|
-
return
|
|
389
|
+
return result;
|
|
390
390
|
}
|
|
391
391
|
// Properties
|
|
392
392
|
/**
|
|
@@ -419,7 +419,7 @@ export class Vector2 {
|
|
|
419
419
|
* @returns a new Vector2
|
|
420
420
|
*/
|
|
421
421
|
clone() {
|
|
422
|
-
return new
|
|
422
|
+
return new this.constructor(this.x, this.y);
|
|
423
423
|
}
|
|
424
424
|
// Statics
|
|
425
425
|
/**
|
|
@@ -458,10 +458,12 @@ export class Vector2 {
|
|
|
458
458
|
* @param array defines the data source
|
|
459
459
|
* @param offset defines the offset in the data source
|
|
460
460
|
* @param result defines the target vector
|
|
461
|
+
* @returns result input
|
|
461
462
|
*/
|
|
462
463
|
static FromArrayToRef(array, offset, result) {
|
|
463
464
|
result.x = array[offset];
|
|
464
465
|
result.y = array[offset + 1];
|
|
466
|
+
return result;
|
|
465
467
|
}
|
|
466
468
|
/**
|
|
467
469
|
* Gets a new Vector2 located for "amount" (float) on the CatmullRom spline defined by the given four Vector2
|
|
@@ -486,7 +488,7 @@ export class Vector2 {
|
|
|
486
488
|
(-value1.y + value3.y) * amount +
|
|
487
489
|
(2.0 * value1.y - 5.0 * value2.y + 4.0 * value3.y - value4.y) * squared +
|
|
488
490
|
(-value1.y + 3.0 * value2.y - 3.0 * value3.y + value4.y) * cubed);
|
|
489
|
-
return new
|
|
491
|
+
return new value1.constructor(x, y);
|
|
490
492
|
}
|
|
491
493
|
/**
|
|
492
494
|
* Returns a new Vector2 set with same the coordinates than "value" ones if the vector "value" is in the square defined by "min" and "max".
|
|
@@ -505,7 +507,7 @@ export class Vector2 {
|
|
|
505
507
|
let y = value.y;
|
|
506
508
|
y = y > max.y ? max.y : y;
|
|
507
509
|
y = y < min.y ? min.y : y;
|
|
508
|
-
return new
|
|
510
|
+
return new value.constructor(x, y);
|
|
509
511
|
}
|
|
510
512
|
/**
|
|
511
513
|
* Returns a new Vector2 located for "amount" (float) on the Hermite spline defined by the vectors "value1", "value2", "tangent1", "tangent2"
|
|
@@ -526,7 +528,7 @@ export class Vector2 {
|
|
|
526
528
|
const part4 = cubed - squared;
|
|
527
529
|
const x = value1.x * part1 + value2.x * part2 + tangent1.x * part3 + tangent2.x * part4;
|
|
528
530
|
const y = value1.y * part1 + value2.y * part2 + tangent1.y * part3 + tangent2.y * part4;
|
|
529
|
-
return new
|
|
531
|
+
return new value1.constructor(x, y);
|
|
530
532
|
}
|
|
531
533
|
/**
|
|
532
534
|
* Returns a new Vector2 which is the 1st derivative of the Hermite spline defined by the vectors "value1", "value2", "tangent1", "tangent2".
|
|
@@ -539,7 +541,7 @@ export class Vector2 {
|
|
|
539
541
|
* @returns 1st derivative
|
|
540
542
|
*/
|
|
541
543
|
static Hermite1stDerivative(value1, tangent1, value2, tangent2, time) {
|
|
542
|
-
const result =
|
|
544
|
+
const result = new value1.constructor();
|
|
543
545
|
this.Hermite1stDerivativeToRef(value1, tangent1, value2, tangent2, time, result);
|
|
544
546
|
return result;
|
|
545
547
|
}
|
|
@@ -552,11 +554,13 @@ export class Vector2 {
|
|
|
552
554
|
* @param tangent2 defines the second tangent
|
|
553
555
|
* @param time define where the derivative must be done
|
|
554
556
|
* @param result define where the derivative will be stored
|
|
557
|
+
* @returns result input
|
|
555
558
|
*/
|
|
556
559
|
static Hermite1stDerivativeToRef(value1, tangent1, value2, tangent2, time, result) {
|
|
557
560
|
const t2 = time * time;
|
|
558
561
|
result.x = (t2 - time) * 6 * value1.x + (3 * t2 - 4 * time + 1) * tangent1.x + (-t2 + time) * 6 * value2.x + (3 * t2 - 2 * time) * tangent2.x;
|
|
559
562
|
result.y = (t2 - time) * 6 * value1.y + (3 * t2 - 4 * time + 1) * tangent1.y + (-t2 + time) * 6 * value2.y + (3 * t2 - 2 * time) * tangent2.y;
|
|
563
|
+
return result;
|
|
560
564
|
}
|
|
561
565
|
/**
|
|
562
566
|
* Returns a new Vector2 located for "amount" (float) on the linear interpolation between the vector "start" adn the vector "end".
|
|
@@ -569,7 +573,7 @@ export class Vector2 {
|
|
|
569
573
|
static Lerp(start, end, amount) {
|
|
570
574
|
const x = start.x + (end.x - start.x) * amount;
|
|
571
575
|
const y = start.y + (end.y - start.y) * amount;
|
|
572
|
-
return new
|
|
576
|
+
return new start.constructor(x, y);
|
|
573
577
|
}
|
|
574
578
|
/**
|
|
575
579
|
* Gets the dot product of the vector "left" and the vector "right"
|
|
@@ -588,7 +592,7 @@ export class Vector2 {
|
|
|
588
592
|
* @returns a new Vector2
|
|
589
593
|
*/
|
|
590
594
|
static Normalize(vector) {
|
|
591
|
-
const newVector =
|
|
595
|
+
const newVector = new vector.constructor();
|
|
592
596
|
this.NormalizeToRef(vector, newVector);
|
|
593
597
|
return newVector;
|
|
594
598
|
}
|
|
@@ -597,14 +601,16 @@ export class Vector2 {
|
|
|
597
601
|
* Example Playground https://playground.babylonjs.com/#QYBWV4#50
|
|
598
602
|
* @param vector defines the vector to normalize
|
|
599
603
|
* @param result defines the vector where to store the result
|
|
604
|
+
* @returns result input
|
|
600
605
|
*/
|
|
601
606
|
static NormalizeToRef(vector, result) {
|
|
602
607
|
const len = vector.length();
|
|
603
608
|
if (len === 0) {
|
|
604
|
-
return;
|
|
609
|
+
return result;
|
|
605
610
|
}
|
|
606
611
|
result.x = vector.x / len;
|
|
607
612
|
result.y = vector.y / len;
|
|
613
|
+
return result;
|
|
608
614
|
}
|
|
609
615
|
/**
|
|
610
616
|
* Gets a new Vector2 set with the minimal coordinate values from the "left" and "right" vectors
|
|
@@ -616,7 +622,7 @@ export class Vector2 {
|
|
|
616
622
|
static Minimize(left, right) {
|
|
617
623
|
const x = left.x < right.x ? left.x : right.x;
|
|
618
624
|
const y = left.y < right.y ? left.y : right.y;
|
|
619
|
-
return new
|
|
625
|
+
return new left.constructor(x, y);
|
|
620
626
|
}
|
|
621
627
|
/**
|
|
622
628
|
* Gets a new Vector2 set with the maximal coordinate values from the "left" and "right" vectors
|
|
@@ -628,7 +634,7 @@ export class Vector2 {
|
|
|
628
634
|
static Maximize(left, right) {
|
|
629
635
|
const x = left.x > right.x ? left.x : right.x;
|
|
630
636
|
const y = left.y > right.y ? left.y : right.y;
|
|
631
|
-
return new
|
|
637
|
+
return new left.constructor(x, y);
|
|
632
638
|
}
|
|
633
639
|
/**
|
|
634
640
|
* Gets a new Vector2 set with the transformed coordinates of the given vector by the given transformation matrix
|
|
@@ -638,9 +644,9 @@ export class Vector2 {
|
|
|
638
644
|
* @returns a new Vector2
|
|
639
645
|
*/
|
|
640
646
|
static Transform(vector, transformation) {
|
|
641
|
-
const
|
|
642
|
-
Vector2.TransformToRef(vector, transformation,
|
|
643
|
-
return
|
|
647
|
+
const result = new vector.constructor();
|
|
648
|
+
Vector2.TransformToRef(vector, transformation, result);
|
|
649
|
+
return result;
|
|
644
650
|
}
|
|
645
651
|
/**
|
|
646
652
|
* Transforms the given vector coordinates by the given transformation matrix and stores the result in the vector "result" coordinates
|
|
@@ -648,6 +654,7 @@ export class Vector2 {
|
|
|
648
654
|
* @param vector defines the vector to transform
|
|
649
655
|
* @param transformation defines the matrix to apply
|
|
650
656
|
* @param result defines the target vector
|
|
657
|
+
* @returns result input
|
|
651
658
|
*/
|
|
652
659
|
static TransformToRef(vector, transformation, result) {
|
|
653
660
|
const m = transformation.m;
|
|
@@ -655,6 +662,7 @@ export class Vector2 {
|
|
|
655
662
|
const y = vector.x * m[1] + vector.y * m[5] + m[13];
|
|
656
663
|
result.x = x;
|
|
657
664
|
result.y = y;
|
|
665
|
+
return result;
|
|
658
666
|
}
|
|
659
667
|
/**
|
|
660
668
|
* Determines if a given vector is included in a triangle
|
|
@@ -703,7 +711,8 @@ export class Vector2 {
|
|
|
703
711
|
* @returns a new Vector2
|
|
704
712
|
*/
|
|
705
713
|
static Center(value1, value2) {
|
|
706
|
-
|
|
714
|
+
const result = new value1.constructor();
|
|
715
|
+
return Vector2.CenterToRef(value1, value2, result);
|
|
707
716
|
}
|
|
708
717
|
/**
|
|
709
718
|
* Gets the center of the vectors "value1" and "value2" and stores the result in the vector "ref"
|
|
@@ -882,7 +891,7 @@ export class Vector3 {
|
|
|
882
891
|
* @returns the resulting Vector3
|
|
883
892
|
*/
|
|
884
893
|
add(otherVector) {
|
|
885
|
-
return new
|
|
894
|
+
return new this.constructor(this._x + otherVector._x, this._y + otherVector._y, this._z + otherVector._z);
|
|
886
895
|
}
|
|
887
896
|
/**
|
|
888
897
|
* Adds the current Vector3 to the given one and stores the result in the vector "result"
|
|
@@ -913,7 +922,7 @@ export class Vector3 {
|
|
|
913
922
|
* @returns the resulting Vector3
|
|
914
923
|
*/
|
|
915
924
|
subtract(otherVector) {
|
|
916
|
-
return new
|
|
925
|
+
return new this.constructor(this._x - otherVector._x, this._y - otherVector._y, this._z - otherVector._z);
|
|
917
926
|
}
|
|
918
927
|
/**
|
|
919
928
|
* Subtracts the given vector from the current Vector3 and stores the result in the vector "result".
|
|
@@ -934,7 +943,7 @@ export class Vector3 {
|
|
|
934
943
|
* @returns the resulting Vector3
|
|
935
944
|
*/
|
|
936
945
|
subtractFromFloats(x, y, z) {
|
|
937
|
-
return new
|
|
946
|
+
return new this.constructor(this._x - x, this._y - y, this._z - z);
|
|
938
947
|
}
|
|
939
948
|
/**
|
|
940
949
|
* Subtracts the given floats from the current Vector3 coordinates and set the given vector "result" with this result
|
|
@@ -954,7 +963,7 @@ export class Vector3 {
|
|
|
954
963
|
* @returns a new Vector3
|
|
955
964
|
*/
|
|
956
965
|
negate() {
|
|
957
|
-
return new
|
|
966
|
+
return new this.constructor(-this._x, -this._y, -this._z);
|
|
958
967
|
}
|
|
959
968
|
/**
|
|
960
969
|
* Negate this vector in place
|
|
@@ -995,7 +1004,7 @@ export class Vector3 {
|
|
|
995
1004
|
* @returns a new Vector3
|
|
996
1005
|
*/
|
|
997
1006
|
scale(scale) {
|
|
998
|
-
return new
|
|
1007
|
+
return new this.constructor(this._x * scale, this._y * scale, this._z * scale);
|
|
999
1008
|
}
|
|
1000
1009
|
/**
|
|
1001
1010
|
* Multiplies the current Vector3 coordinates by the float "scale" and stores the result in the given vector "result" coordinates
|
|
@@ -1068,14 +1077,14 @@ export class Vector3 {
|
|
|
1068
1077
|
* @returns a new Vector3
|
|
1069
1078
|
*/
|
|
1070
1079
|
applyRotationQuaternion(q) {
|
|
1071
|
-
return this.applyRotationQuaternionToRef(q,
|
|
1080
|
+
return this.applyRotationQuaternionToRef(q, new this.constructor());
|
|
1072
1081
|
}
|
|
1073
1082
|
/**
|
|
1074
1083
|
* Scale the current Vector3 values by a factor and add the result to a given Vector3
|
|
1075
1084
|
* Example Playground https://playground.babylonjs.com/#R1F8YU#55
|
|
1076
1085
|
* @param scale defines the scale factor
|
|
1077
1086
|
* @param result defines the Vector3 object where to store the result
|
|
1078
|
-
* @returns
|
|
1087
|
+
* @returns result input
|
|
1079
1088
|
*/
|
|
1080
1089
|
scaleAndAddToRef(scale, result) {
|
|
1081
1090
|
return result.addInPlaceFromFloats(this._x * scale, this._y * scale, this._z * scale);
|
|
@@ -1088,7 +1097,7 @@ export class Vector3 {
|
|
|
1088
1097
|
* @returns the projected vector3
|
|
1089
1098
|
*/
|
|
1090
1099
|
projectOnPlane(plane, origin) {
|
|
1091
|
-
const result =
|
|
1100
|
+
const result = new this.constructor();
|
|
1092
1101
|
this.projectOnPlaneToRef(plane, origin, result);
|
|
1093
1102
|
return result;
|
|
1094
1103
|
}
|
|
@@ -1098,6 +1107,7 @@ export class Vector3 {
|
|
|
1098
1107
|
* @param plane defines the plane to project to
|
|
1099
1108
|
* @param origin defines the origin of the projection ray
|
|
1100
1109
|
* @param result defines the Vector3 where to store the result
|
|
1110
|
+
* @returns result input
|
|
1101
1111
|
*/
|
|
1102
1112
|
projectOnPlaneToRef(plane, origin, result) {
|
|
1103
1113
|
const n = plane.normal;
|
|
@@ -1117,6 +1127,7 @@ export class Vector3 {
|
|
|
1117
1127
|
const scaledV = V.scaleInPlace(t);
|
|
1118
1128
|
origin.addToRef(scaledV, result);
|
|
1119
1129
|
}
|
|
1130
|
+
return result;
|
|
1120
1131
|
}
|
|
1121
1132
|
/**
|
|
1122
1133
|
* Returns true if the current Vector3 and the given vector coordinates are strictly equal
|
|
@@ -1191,7 +1202,7 @@ export class Vector3 {
|
|
|
1191
1202
|
* @returns the new Vector3
|
|
1192
1203
|
*/
|
|
1193
1204
|
multiplyByFloats(x, y, z) {
|
|
1194
|
-
return new
|
|
1205
|
+
return new this.constructor(this._x * x, this._y * y, this._z * z);
|
|
1195
1206
|
}
|
|
1196
1207
|
/**
|
|
1197
1208
|
* Returns a new Vector3 set with the result of the division of the current Vector3 coordinates by the given ones
|
|
@@ -1200,7 +1211,7 @@ export class Vector3 {
|
|
|
1200
1211
|
* @returns the new Vector3
|
|
1201
1212
|
*/
|
|
1202
1213
|
divide(otherVector) {
|
|
1203
|
-
return new
|
|
1214
|
+
return new this.constructor(this._x / otherVector._x, this._y / otherVector._y, this._z / otherVector._z);
|
|
1204
1215
|
}
|
|
1205
1216
|
/**
|
|
1206
1217
|
* Divides the current Vector3 coordinates by the given ones and stores the result in the given vector "result"
|
|
@@ -1321,7 +1332,7 @@ export class Vector3 {
|
|
|
1321
1332
|
* @returns a new Vector3
|
|
1322
1333
|
*/
|
|
1323
1334
|
floor() {
|
|
1324
|
-
return new
|
|
1335
|
+
return new this.constructor(Math.floor(this._x), Math.floor(this._y), Math.floor(this._z));
|
|
1325
1336
|
}
|
|
1326
1337
|
/**
|
|
1327
1338
|
* Gets a new Vector3 from current Vector3 fractional values
|
|
@@ -1329,7 +1340,7 @@ export class Vector3 {
|
|
|
1329
1340
|
* @returns a new Vector3
|
|
1330
1341
|
*/
|
|
1331
1342
|
fract() {
|
|
1332
|
-
return new
|
|
1343
|
+
return new this.constructor(this._x - Math.floor(this._x), this._y - Math.floor(this._y), this._z - Math.floor(this._z));
|
|
1333
1344
|
}
|
|
1334
1345
|
// Properties
|
|
1335
1346
|
/**
|
|
@@ -1415,7 +1426,8 @@ export class Vector3 {
|
|
|
1415
1426
|
* @returns the cross product
|
|
1416
1427
|
*/
|
|
1417
1428
|
cross(other) {
|
|
1418
|
-
|
|
1429
|
+
const result = new this.constructor();
|
|
1430
|
+
return Vector3.CrossToRef(this, other, result);
|
|
1419
1431
|
}
|
|
1420
1432
|
/**
|
|
1421
1433
|
* Normalize the current Vector3 with the given input length.
|
|
@@ -1436,7 +1448,7 @@ export class Vector3 {
|
|
|
1436
1448
|
* @returns the new Vector3
|
|
1437
1449
|
*/
|
|
1438
1450
|
normalizeToNew() {
|
|
1439
|
-
const normalized = new
|
|
1451
|
+
const normalized = new this.constructor(0, 0, 0);
|
|
1440
1452
|
this.normalizeToRef(normalized);
|
|
1441
1453
|
return normalized;
|
|
1442
1454
|
}
|
|
@@ -1459,7 +1471,7 @@ export class Vector3 {
|
|
|
1459
1471
|
* @returns the new Vector3
|
|
1460
1472
|
*/
|
|
1461
1473
|
clone() {
|
|
1462
|
-
return new
|
|
1474
|
+
return new this.constructor(this._x, this._y, this._z);
|
|
1463
1475
|
}
|
|
1464
1476
|
/**
|
|
1465
1477
|
* Copies the given vector coordinates to the current Vector3 ones
|
|
@@ -1635,6 +1647,7 @@ export class Vector3 {
|
|
|
1635
1647
|
vector1Dir.scaleInPlace(scale1);
|
|
1636
1648
|
result.copyFrom(vector0Dir).addInPlace(vector1Dir);
|
|
1637
1649
|
result.scaleInPlace(Scalar.Lerp(vector0Length, vector1Length, slerp));
|
|
1650
|
+
return result;
|
|
1638
1651
|
}
|
|
1639
1652
|
/**
|
|
1640
1653
|
* Smooth interpolation between two vectors using Slerp
|
|
@@ -1647,6 +1660,7 @@ export class Vector3 {
|
|
|
1647
1660
|
*/
|
|
1648
1661
|
static SmoothToRef(source, goal, deltaTime, lerpTime, result) {
|
|
1649
1662
|
Vector3.SlerpToRef(source, goal, lerpTime === 0 ? 1 : deltaTime / lerpTime, result);
|
|
1663
|
+
return result;
|
|
1650
1664
|
}
|
|
1651
1665
|
/**
|
|
1652
1666
|
* Returns a new Vector3 set from the index "offset" of the given array
|
|
@@ -1674,11 +1688,13 @@ export class Vector3 {
|
|
|
1674
1688
|
* @param array defines the source array
|
|
1675
1689
|
* @param offset defines the offset in the source array
|
|
1676
1690
|
* @param result defines the Vector3 where to store the result
|
|
1691
|
+
* @returns result input
|
|
1677
1692
|
*/
|
|
1678
1693
|
static FromArrayToRef(array, offset, result) {
|
|
1679
1694
|
result.x = array[offset];
|
|
1680
1695
|
result.y = array[offset + 1];
|
|
1681
1696
|
result.z = array[offset + 2];
|
|
1697
|
+
return result;
|
|
1682
1698
|
}
|
|
1683
1699
|
/**
|
|
1684
1700
|
* Sets the given vector "result" with the element values from the index "offset" of the given Float32Array
|
|
@@ -1700,6 +1716,7 @@ export class Vector3 {
|
|
|
1700
1716
|
*/
|
|
1701
1717
|
static FromFloatsToRef(x, y, z, result) {
|
|
1702
1718
|
result.copyFromFloats(x, y, z);
|
|
1719
|
+
return result;
|
|
1703
1720
|
}
|
|
1704
1721
|
/**
|
|
1705
1722
|
* Returns a new Vector3 set to (0.0, 0.0, 0.0)
|
|
@@ -1827,9 +1844,11 @@ export class Vector3 {
|
|
|
1827
1844
|
* @param vector defines the Vector3 to transform
|
|
1828
1845
|
* @param transformation defines the transformation matrix
|
|
1829
1846
|
* @param result defines the Vector3 where to store the result
|
|
1847
|
+
* @returns result input
|
|
1830
1848
|
*/
|
|
1831
1849
|
static TransformCoordinatesToRef(vector, transformation, result) {
|
|
1832
1850
|
Vector3.TransformCoordinatesFromFloatsToRef(vector._x, vector._y, vector._z, transformation, result);
|
|
1851
|
+
return result;
|
|
1833
1852
|
}
|
|
1834
1853
|
/**
|
|
1835
1854
|
* Sets the given vector "result" coordinates with the result of the transformation by the given matrix of the given floats (x, y, z)
|
|
@@ -1840,6 +1859,7 @@ export class Vector3 {
|
|
|
1840
1859
|
* @param z define the z coordinate of the source vector
|
|
1841
1860
|
* @param transformation defines the transformation matrix
|
|
1842
1861
|
* @param result defines the Vector3 where to store the result
|
|
1862
|
+
* @returns result input
|
|
1843
1863
|
*/
|
|
1844
1864
|
static TransformCoordinatesFromFloatsToRef(x, y, z, transformation, result) {
|
|
1845
1865
|
const m = transformation.m;
|
|
@@ -1850,6 +1870,7 @@ export class Vector3 {
|
|
|
1850
1870
|
result.x = rx * rw;
|
|
1851
1871
|
result.y = ry * rw;
|
|
1852
1872
|
result.z = rz * rw;
|
|
1873
|
+
return result;
|
|
1853
1874
|
}
|
|
1854
1875
|
/**
|
|
1855
1876
|
* Returns a new Vector3 set with the result of the normal transformation by the given matrix of the given vector
|
|
@@ -1871,9 +1892,11 @@ export class Vector3 {
|
|
|
1871
1892
|
* @param vector defines the Vector3 to transform
|
|
1872
1893
|
* @param transformation defines the transformation matrix
|
|
1873
1894
|
* @param result defines the Vector3 where to store the result
|
|
1895
|
+
* @returns result input
|
|
1874
1896
|
*/
|
|
1875
1897
|
static TransformNormalToRef(vector, transformation, result) {
|
|
1876
1898
|
this.TransformNormalFromFloatsToRef(vector._x, vector._y, vector._z, transformation, result);
|
|
1899
|
+
return result;
|
|
1877
1900
|
}
|
|
1878
1901
|
/**
|
|
1879
1902
|
* Sets the given vector "result" with the result of the normal transformation by the given matrix of the given floats (x, y, z)
|
|
@@ -1884,12 +1907,14 @@ export class Vector3 {
|
|
|
1884
1907
|
* @param z define the z coordinate of the source vector
|
|
1885
1908
|
* @param transformation defines the transformation matrix
|
|
1886
1909
|
* @param result defines the Vector3 where to store the result
|
|
1910
|
+
* @returns result input
|
|
1887
1911
|
*/
|
|
1888
1912
|
static TransformNormalFromFloatsToRef(x, y, z, transformation, result) {
|
|
1889
1913
|
const m = transformation.m;
|
|
1890
1914
|
result.x = x * m[0] + y * m[4] + z * m[8];
|
|
1891
1915
|
result.y = x * m[1] + y * m[5] + z * m[9];
|
|
1892
1916
|
result.z = x * m[2] + y * m[6] + z * m[10];
|
|
1917
|
+
return result;
|
|
1893
1918
|
}
|
|
1894
1919
|
/**
|
|
1895
1920
|
* Returns a new Vector3 located for "amount" on the CatmullRom interpolation spline defined by the vectors "value1", "value2", "value3", "value4"
|
|
@@ -1919,7 +1944,7 @@ export class Vector3 {
|
|
|
1919
1944
|
(-value1._z + value3._z) * amount +
|
|
1920
1945
|
(2.0 * value1._z - 5.0 * value2._z + 4.0 * value3._z - value4._z) * squared +
|
|
1921
1946
|
(-value1._z + 3.0 * value2._z - 3.0 * value3._z + value4._z) * cubed);
|
|
1922
|
-
return new
|
|
1947
|
+
return new value1.constructor(x, y, z);
|
|
1923
1948
|
}
|
|
1924
1949
|
/**
|
|
1925
1950
|
* Returns a new Vector3 set with the coordinates of "value", if the vector "value" is in the cube defined by the vectors "min" and "max"
|
|
@@ -1932,9 +1957,9 @@ export class Vector3 {
|
|
|
1932
1957
|
* @returns the new Vector3
|
|
1933
1958
|
*/
|
|
1934
1959
|
static Clamp(value, min, max) {
|
|
1935
|
-
const
|
|
1936
|
-
Vector3.ClampToRef(value, min, max,
|
|
1937
|
-
return
|
|
1960
|
+
const result = new value.constructor();
|
|
1961
|
+
Vector3.ClampToRef(value, min, max, result);
|
|
1962
|
+
return result;
|
|
1938
1963
|
}
|
|
1939
1964
|
/**
|
|
1940
1965
|
* Sets the given vector "result" with the coordinates of "value", if the vector "value" is in the cube defined by the vectors "min" and "max"
|
|
@@ -1945,6 +1970,7 @@ export class Vector3 {
|
|
|
1945
1970
|
* @param min defines the lower range value
|
|
1946
1971
|
* @param max defines the upper range value
|
|
1947
1972
|
* @param result defines the Vector3 where to store the result
|
|
1973
|
+
* @returns result input
|
|
1948
1974
|
*/
|
|
1949
1975
|
static ClampToRef(value, min, max, result) {
|
|
1950
1976
|
let x = value._x;
|
|
@@ -1957,6 +1983,7 @@ export class Vector3 {
|
|
|
1957
1983
|
z = z > max._z ? max._z : z;
|
|
1958
1984
|
z = z < min._z ? min._z : z;
|
|
1959
1985
|
result.copyFromFloats(x, y, z);
|
|
1986
|
+
return result;
|
|
1960
1987
|
}
|
|
1961
1988
|
/**
|
|
1962
1989
|
* Checks if a given vector is inside a specific range
|
|
@@ -1989,7 +2016,7 @@ export class Vector3 {
|
|
|
1989
2016
|
const x = value1._x * part1 + value2._x * part2 + tangent1._x * part3 + tangent2._x * part4;
|
|
1990
2017
|
const y = value1._y * part1 + value2._y * part2 + tangent1._y * part3 + tangent2._y * part4;
|
|
1991
2018
|
const z = value1._z * part1 + value2._z * part2 + tangent1._z * part3 + tangent2._z * part4;
|
|
1992
|
-
return new
|
|
2019
|
+
return new value1.constructor(x, y, z);
|
|
1993
2020
|
}
|
|
1994
2021
|
/**
|
|
1995
2022
|
* Returns a new Vector3 which is the 1st derivative of the Hermite spline defined by the vectors "value1", "value2", "tangent1", "tangent2".
|
|
@@ -2002,7 +2029,7 @@ export class Vector3 {
|
|
|
2002
2029
|
* @returns 1st derivative
|
|
2003
2030
|
*/
|
|
2004
2031
|
static Hermite1stDerivative(value1, tangent1, value2, tangent2, time) {
|
|
2005
|
-
const result =
|
|
2032
|
+
const result = new value1.constructor();
|
|
2006
2033
|
this.Hermite1stDerivativeToRef(value1, tangent1, value2, tangent2, time, result);
|
|
2007
2034
|
return result;
|
|
2008
2035
|
}
|
|
@@ -2015,12 +2042,14 @@ export class Vector3 {
|
|
|
2015
2042
|
* @param tangent2 defines the second tangent
|
|
2016
2043
|
* @param time define where the derivative must be done
|
|
2017
2044
|
* @param result define where to store the derivative
|
|
2045
|
+
* @returns result input
|
|
2018
2046
|
*/
|
|
2019
2047
|
static Hermite1stDerivativeToRef(value1, tangent1, value2, tangent2, time, result) {
|
|
2020
2048
|
const t2 = time * time;
|
|
2021
2049
|
result.x = (t2 - time) * 6 * value1.x + (3 * t2 - 4 * time + 1) * tangent1.x + (-t2 + time) * 6 * value2.x + (3 * t2 - 2 * time) * tangent2.x;
|
|
2022
2050
|
result.y = (t2 - time) * 6 * value1.y + (3 * t2 - 4 * time + 1) * tangent1.y + (-t2 + time) * 6 * value2.y + (3 * t2 - 2 * time) * tangent2.y;
|
|
2023
2051
|
result.z = (t2 - time) * 6 * value1.z + (3 * t2 - 4 * time + 1) * tangent1.z + (-t2 + time) * 6 * value2.z + (3 * t2 - 2 * time) * tangent2.z;
|
|
2052
|
+
return result;
|
|
2024
2053
|
}
|
|
2025
2054
|
/**
|
|
2026
2055
|
* Returns a new Vector3 located for "amount" (float) on the linear interpolation between the vectors "start" and "end"
|
|
@@ -2031,7 +2060,7 @@ export class Vector3 {
|
|
|
2031
2060
|
* @returns the new Vector3
|
|
2032
2061
|
*/
|
|
2033
2062
|
static Lerp(start, end, amount) {
|
|
2034
|
-
const result = new
|
|
2063
|
+
const result = new start.constructor(0, 0, 0);
|
|
2035
2064
|
Vector3.LerpToRef(start, end, amount, result);
|
|
2036
2065
|
return result;
|
|
2037
2066
|
}
|
|
@@ -2042,11 +2071,13 @@ export class Vector3 {
|
|
|
2042
2071
|
* @param end defines the end value
|
|
2043
2072
|
* @param amount max defines amount between both (between 0 and 1)
|
|
2044
2073
|
* @param result defines the Vector3 where to store the result
|
|
2074
|
+
* @returns result input
|
|
2045
2075
|
*/
|
|
2046
2076
|
static LerpToRef(start, end, amount, result) {
|
|
2047
2077
|
result.x = start._x + (end._x - start._x) * amount;
|
|
2048
2078
|
result.y = start._y + (end._y - start._y) * amount;
|
|
2049
2079
|
result.z = start._z + (end._z - start._z) * amount;
|
|
2080
|
+
return result;
|
|
2050
2081
|
}
|
|
2051
2082
|
/**
|
|
2052
2083
|
* Returns the dot product (float) between the vectors "left" and "right"
|
|
@@ -2067,7 +2098,7 @@ export class Vector3 {
|
|
|
2067
2098
|
* @returns the cross product
|
|
2068
2099
|
*/
|
|
2069
2100
|
static Cross(left, right) {
|
|
2070
|
-
const result =
|
|
2101
|
+
const result = new left.constructor();
|
|
2071
2102
|
Vector3.CrossToRef(left, right, result);
|
|
2072
2103
|
return result;
|
|
2073
2104
|
}
|
|
@@ -2078,12 +2109,14 @@ export class Vector3 {
|
|
|
2078
2109
|
* @param left defines the left operand
|
|
2079
2110
|
* @param right defines the right operand
|
|
2080
2111
|
* @param result defines the Vector3 where to store the result
|
|
2112
|
+
* @returns result input
|
|
2081
2113
|
*/
|
|
2082
2114
|
static CrossToRef(left, right, result) {
|
|
2083
2115
|
const x = left._y * right._z - left._z * right._y;
|
|
2084
2116
|
const y = left._z * right._x - left._x * right._z;
|
|
2085
2117
|
const z = left._x * right._y - left._y * right._x;
|
|
2086
2118
|
result.copyFromFloats(x, y, z);
|
|
2119
|
+
return result;
|
|
2087
2120
|
}
|
|
2088
2121
|
/**
|
|
2089
2122
|
* Returns a new Vector3 as the normalization of the given vector
|
|
@@ -2101,9 +2134,11 @@ export class Vector3 {
|
|
|
2101
2134
|
* Example Playground https://playground.babylonjs.com/#R1F8YU#98
|
|
2102
2135
|
* @param vector defines the Vector3 to normalize
|
|
2103
2136
|
* @param result defines the Vector3 where to store the result
|
|
2137
|
+
* @returns result input
|
|
2104
2138
|
*/
|
|
2105
2139
|
static NormalizeToRef(vector, result) {
|
|
2106
2140
|
vector.normalizeToRef(result);
|
|
2141
|
+
return result;
|
|
2107
2142
|
}
|
|
2108
2143
|
/**
|
|
2109
2144
|
* Project a Vector3 onto screen space
|
|
@@ -2115,7 +2150,7 @@ export class Vector3 {
|
|
|
2115
2150
|
* @returns the new Vector3
|
|
2116
2151
|
*/
|
|
2117
2152
|
static Project(vector, world, transform, viewport) {
|
|
2118
|
-
const result = new
|
|
2153
|
+
const result = new vector.constructor();
|
|
2119
2154
|
Vector3.ProjectToRef(vector, world, transform, viewport, result);
|
|
2120
2155
|
return result;
|
|
2121
2156
|
}
|
|
@@ -2127,7 +2162,7 @@ export class Vector3 {
|
|
|
2127
2162
|
* @param transform defines the transform (view x projection) matrix to use
|
|
2128
2163
|
* @param viewport defines the screen viewport to use
|
|
2129
2164
|
* @param result the vector in which the screen space will be stored
|
|
2130
|
-
* @returns
|
|
2165
|
+
* @returns result input
|
|
2131
2166
|
*/
|
|
2132
2167
|
static ProjectToRef(vector, world, transform, viewport, result) {
|
|
2133
2168
|
const cw = viewport.width;
|
|
@@ -2152,6 +2187,7 @@ export class Vector3 {
|
|
|
2152
2187
|
if (Scalar.WithinEpsilon(num, 1.0)) {
|
|
2153
2188
|
result.scaleInPlace(1.0 / num);
|
|
2154
2189
|
}
|
|
2190
|
+
return result;
|
|
2155
2191
|
}
|
|
2156
2192
|
/**
|
|
2157
2193
|
* Unproject from screen space to object space
|
|
@@ -2178,7 +2214,7 @@ export class Vector3 {
|
|
|
2178
2214
|
* @returns the new Vector3
|
|
2179
2215
|
*/
|
|
2180
2216
|
static Unproject(source, viewportWidth, viewportHeight, world, view, projection) {
|
|
2181
|
-
const result =
|
|
2217
|
+
const result = new source.constructor();
|
|
2182
2218
|
Vector3.UnprojectToRef(source, viewportWidth, viewportHeight, world, view, projection, result);
|
|
2183
2219
|
return result;
|
|
2184
2220
|
}
|
|
@@ -2192,9 +2228,11 @@ export class Vector3 {
|
|
|
2192
2228
|
* @param view defines the view matrix to use
|
|
2193
2229
|
* @param projection defines the projection matrix to use
|
|
2194
2230
|
* @param result defines the Vector3 where to store the result
|
|
2231
|
+
* @returns result input
|
|
2195
2232
|
*/
|
|
2196
2233
|
static UnprojectToRef(source, viewportWidth, viewportHeight, world, view, projection, result) {
|
|
2197
2234
|
Vector3.UnprojectFloatsToRef(source._x, source._y, source._z, viewportWidth, viewportHeight, world, view, projection, result);
|
|
2235
|
+
return result;
|
|
2198
2236
|
}
|
|
2199
2237
|
/**
|
|
2200
2238
|
* Unproject from screen space to object space
|
|
@@ -2208,6 +2246,7 @@ export class Vector3 {
|
|
|
2208
2246
|
* @param view defines the view matrix to use
|
|
2209
2247
|
* @param projection defines the projection matrix to use
|
|
2210
2248
|
* @param result defines the Vector3 where to store the result
|
|
2249
|
+
* @returns result input
|
|
2211
2250
|
*/
|
|
2212
2251
|
static UnprojectFloatsToRef(sourceX, sourceY, sourceZ, viewportWidth, viewportHeight, world, view, projection, result) {
|
|
2213
2252
|
var _a;
|
|
@@ -2225,6 +2264,7 @@ export class Vector3 {
|
|
|
2225
2264
|
screenSource.z = 2 * sourceZ - 1.0;
|
|
2226
2265
|
}
|
|
2227
2266
|
Vector3._UnprojectFromInvertedMatrixToRef(screenSource, matrix, result);
|
|
2267
|
+
return result;
|
|
2228
2268
|
}
|
|
2229
2269
|
/**
|
|
2230
2270
|
* Gets the minimal coordinate values between two Vector3
|
|
@@ -2234,7 +2274,8 @@ export class Vector3 {
|
|
|
2234
2274
|
* @returns the new Vector3
|
|
2235
2275
|
*/
|
|
2236
2276
|
static Minimize(left, right) {
|
|
2237
|
-
const min = left.
|
|
2277
|
+
const min = new left.constructor();
|
|
2278
|
+
min.copyFrom(left);
|
|
2238
2279
|
min.minimizeInPlace(right);
|
|
2239
2280
|
return min;
|
|
2240
2281
|
}
|
|
@@ -2246,7 +2287,8 @@ export class Vector3 {
|
|
|
2246
2287
|
* @returns the new Vector3
|
|
2247
2288
|
*/
|
|
2248
2289
|
static Maximize(left, right) {
|
|
2249
|
-
const max = left.
|
|
2290
|
+
const max = new left.constructor();
|
|
2291
|
+
max.copyFrom(left);
|
|
2250
2292
|
max.maximizeInPlace(right);
|
|
2251
2293
|
return max;
|
|
2252
2294
|
}
|
|
@@ -2447,7 +2489,7 @@ export class Vector3 {
|
|
|
2447
2489
|
* @see https://doc.babylonjs.com/divingDeeper/mesh/transforms/center_origin/target_align
|
|
2448
2490
|
*/
|
|
2449
2491
|
static RotationFromAxis(axis1, axis2, axis3) {
|
|
2450
|
-
const rotation =
|
|
2492
|
+
const rotation = new axis1.constructor();
|
|
2451
2493
|
Vector3.RotationFromAxisToRef(axis1, axis2, axis3, rotation);
|
|
2452
2494
|
return rotation;
|
|
2453
2495
|
}
|
|
@@ -2458,11 +2500,13 @@ export class Vector3 {
|
|
|
2458
2500
|
* @param axis2 defines the second axis
|
|
2459
2501
|
* @param axis3 defines the third axis
|
|
2460
2502
|
* @param ref defines the Vector3 where to store the result
|
|
2503
|
+
* @returns result input
|
|
2461
2504
|
*/
|
|
2462
2505
|
static RotationFromAxisToRef(axis1, axis2, axis3, ref) {
|
|
2463
2506
|
const quat = MathTmp.Quaternion[0];
|
|
2464
2507
|
Quaternion.RotationQuaternionFromAxisToRef(axis1, axis2, axis3, quat);
|
|
2465
2508
|
quat.toEulerAnglesToRef(ref);
|
|
2509
|
+
return ref;
|
|
2466
2510
|
}
|
|
2467
2511
|
}
|
|
2468
2512
|
Vector3._UpReadOnly = Vector3.Up();
|
|
@@ -2485,13 +2529,13 @@ export class Vector4 {
|
|
|
2485
2529
|
*/
|
|
2486
2530
|
constructor(
|
|
2487
2531
|
/** x value of the vector */
|
|
2488
|
-
x,
|
|
2532
|
+
x = 0,
|
|
2489
2533
|
/** y value of the vector */
|
|
2490
|
-
y,
|
|
2534
|
+
y = 0,
|
|
2491
2535
|
/** z value of the vector */
|
|
2492
|
-
z,
|
|
2536
|
+
z = 0,
|
|
2493
2537
|
/** w value of the vector */
|
|
2494
|
-
w) {
|
|
2538
|
+
w = 0) {
|
|
2495
2539
|
this.x = x;
|
|
2496
2540
|
this.y = y;
|
|
2497
2541
|
this.z = z;
|
|
@@ -2580,20 +2624,20 @@ export class Vector4 {
|
|
|
2580
2624
|
* @returns the resulting vector
|
|
2581
2625
|
*/
|
|
2582
2626
|
add(otherVector) {
|
|
2583
|
-
return new
|
|
2627
|
+
return new this.constructor(this.x + otherVector.x, this.y + otherVector.y, this.z + otherVector.z, this.w + otherVector.w);
|
|
2584
2628
|
}
|
|
2585
2629
|
/**
|
|
2586
2630
|
* Updates the given vector "result" with the result of the addition of the current Vector4 and the given one.
|
|
2587
2631
|
* @param otherVector the vector to add
|
|
2588
2632
|
* @param result the vector to store the result
|
|
2589
|
-
* @returns
|
|
2633
|
+
* @returns result input
|
|
2590
2634
|
*/
|
|
2591
2635
|
addToRef(otherVector, result) {
|
|
2592
2636
|
result.x = this.x + otherVector.x;
|
|
2593
2637
|
result.y = this.y + otherVector.y;
|
|
2594
2638
|
result.z = this.z + otherVector.z;
|
|
2595
2639
|
result.w = this.w + otherVector.w;
|
|
2596
|
-
return
|
|
2640
|
+
return result;
|
|
2597
2641
|
}
|
|
2598
2642
|
/**
|
|
2599
2643
|
* Subtract in place the given vector from the current Vector4.
|
|
@@ -2613,20 +2657,20 @@ export class Vector4 {
|
|
|
2613
2657
|
* @returns the new vector with the result
|
|
2614
2658
|
*/
|
|
2615
2659
|
subtract(otherVector) {
|
|
2616
|
-
return new
|
|
2660
|
+
return new this.constructor(this.x - otherVector.x, this.y - otherVector.y, this.z - otherVector.z, this.w - otherVector.w);
|
|
2617
2661
|
}
|
|
2618
2662
|
/**
|
|
2619
2663
|
* Sets the given vector "result" with the result of the subtraction of the given vector from the current Vector4.
|
|
2620
2664
|
* @param otherVector the vector to subtract
|
|
2621
2665
|
* @param result the vector to store the result
|
|
2622
|
-
* @returns
|
|
2666
|
+
* @returns result input
|
|
2623
2667
|
*/
|
|
2624
2668
|
subtractToRef(otherVector, result) {
|
|
2625
2669
|
result.x = this.x - otherVector.x;
|
|
2626
2670
|
result.y = this.y - otherVector.y;
|
|
2627
2671
|
result.z = this.z - otherVector.z;
|
|
2628
2672
|
result.w = this.w - otherVector.w;
|
|
2629
|
-
return
|
|
2673
|
+
return result;
|
|
2630
2674
|
}
|
|
2631
2675
|
/**
|
|
2632
2676
|
* Returns a new Vector4 set with the result of the subtraction of the given floats from the current Vector4 coordinates.
|
|
@@ -2640,7 +2684,7 @@ export class Vector4 {
|
|
|
2640
2684
|
* @returns new vector containing the result
|
|
2641
2685
|
*/
|
|
2642
2686
|
subtractFromFloats(x, y, z, w) {
|
|
2643
|
-
return new
|
|
2687
|
+
return new this.constructor(this.x - x, this.y - y, this.z - z, this.w - w);
|
|
2644
2688
|
}
|
|
2645
2689
|
/**
|
|
2646
2690
|
* Sets the given vector "result" set with the result of the subtraction of the given floats from the current Vector4 coordinates.
|
|
@@ -2649,21 +2693,21 @@ export class Vector4 {
|
|
|
2649
2693
|
* @param z value to subtract
|
|
2650
2694
|
* @param w value to subtract
|
|
2651
2695
|
* @param result the vector to store the result in
|
|
2652
|
-
* @returns
|
|
2696
|
+
* @returns result input
|
|
2653
2697
|
*/
|
|
2654
2698
|
subtractFromFloatsToRef(x, y, z, w, result) {
|
|
2655
2699
|
result.x = this.x - x;
|
|
2656
2700
|
result.y = this.y - y;
|
|
2657
2701
|
result.z = this.z - z;
|
|
2658
2702
|
result.w = this.w - w;
|
|
2659
|
-
return
|
|
2703
|
+
return result;
|
|
2660
2704
|
}
|
|
2661
2705
|
/**
|
|
2662
2706
|
* Returns a new Vector4 set with the current Vector4 negated coordinates.
|
|
2663
2707
|
* @returns a new vector with the negated values
|
|
2664
2708
|
*/
|
|
2665
2709
|
negate() {
|
|
2666
|
-
return new
|
|
2710
|
+
return new this.constructor(-this.x, -this.y, -this.z, -this.w);
|
|
2667
2711
|
}
|
|
2668
2712
|
/**
|
|
2669
2713
|
* Negate this vector in place
|
|
@@ -2702,33 +2746,33 @@ export class Vector4 {
|
|
|
2702
2746
|
* @returns a new vector with the result
|
|
2703
2747
|
*/
|
|
2704
2748
|
scale(scale) {
|
|
2705
|
-
return new
|
|
2749
|
+
return new this.constructor(this.x * scale, this.y * scale, this.z * scale, this.w * scale);
|
|
2706
2750
|
}
|
|
2707
2751
|
/**
|
|
2708
2752
|
* Sets the given vector "result" with the current Vector4 coordinates multiplied by scale (float).
|
|
2709
2753
|
* @param scale the number to scale with
|
|
2710
2754
|
* @param result a vector to store the result in
|
|
2711
|
-
* @returns
|
|
2755
|
+
* @returns result input
|
|
2712
2756
|
*/
|
|
2713
2757
|
scaleToRef(scale, result) {
|
|
2714
2758
|
result.x = this.x * scale;
|
|
2715
2759
|
result.y = this.y * scale;
|
|
2716
2760
|
result.z = this.z * scale;
|
|
2717
2761
|
result.w = this.w * scale;
|
|
2718
|
-
return
|
|
2762
|
+
return result;
|
|
2719
2763
|
}
|
|
2720
2764
|
/**
|
|
2721
2765
|
* Scale the current Vector4 values by a factor and add the result to a given Vector4
|
|
2722
2766
|
* @param scale defines the scale factor
|
|
2723
2767
|
* @param result defines the Vector4 object where to store the result
|
|
2724
|
-
* @returns
|
|
2768
|
+
* @returns result input
|
|
2725
2769
|
*/
|
|
2726
2770
|
scaleAndAddToRef(scale, result) {
|
|
2727
2771
|
result.x += this.x * scale;
|
|
2728
2772
|
result.y += this.y * scale;
|
|
2729
2773
|
result.z += this.z * scale;
|
|
2730
2774
|
result.w += this.w * scale;
|
|
2731
|
-
return
|
|
2775
|
+
return result;
|
|
2732
2776
|
}
|
|
2733
2777
|
/**
|
|
2734
2778
|
* Boolean : True if the current Vector4 coordinates are stricly equal to the given ones.
|
|
@@ -2780,20 +2824,20 @@ export class Vector4 {
|
|
|
2780
2824
|
* @returns resulting new vector
|
|
2781
2825
|
*/
|
|
2782
2826
|
multiply(otherVector) {
|
|
2783
|
-
return new
|
|
2827
|
+
return new this.constructor(this.x * otherVector.x, this.y * otherVector.y, this.z * otherVector.z, this.w * otherVector.w);
|
|
2784
2828
|
}
|
|
2785
2829
|
/**
|
|
2786
2830
|
* Updates the given vector "result" with the multiplication result of the current Vector4 and the given one.
|
|
2787
2831
|
* @param otherVector vector to multiple with
|
|
2788
2832
|
* @param result vector to store the result
|
|
2789
|
-
* @returns
|
|
2833
|
+
* @returns result input
|
|
2790
2834
|
*/
|
|
2791
2835
|
multiplyToRef(otherVector, result) {
|
|
2792
2836
|
result.x = this.x * otherVector.x;
|
|
2793
2837
|
result.y = this.y * otherVector.y;
|
|
2794
2838
|
result.z = this.z * otherVector.z;
|
|
2795
2839
|
result.w = this.w * otherVector.w;
|
|
2796
|
-
return
|
|
2840
|
+
return result;
|
|
2797
2841
|
}
|
|
2798
2842
|
/**
|
|
2799
2843
|
* Returns a new Vector4 set with the multiplication result of the given floats and the current Vector4 coordinates.
|
|
@@ -2804,7 +2848,7 @@ export class Vector4 {
|
|
|
2804
2848
|
* @returns resulting new vector
|
|
2805
2849
|
*/
|
|
2806
2850
|
multiplyByFloats(x, y, z, w) {
|
|
2807
|
-
return new
|
|
2851
|
+
return new this.constructor(this.x * x, this.y * y, this.z * z, this.w * w);
|
|
2808
2852
|
}
|
|
2809
2853
|
/**
|
|
2810
2854
|
* Returns a new Vector4 set with the division result of the current Vector4 by the given one.
|
|
@@ -2812,20 +2856,20 @@ export class Vector4 {
|
|
|
2812
2856
|
* @returns resulting new vector
|
|
2813
2857
|
*/
|
|
2814
2858
|
divide(otherVector) {
|
|
2815
|
-
return new
|
|
2859
|
+
return new this.constructor(this.x / otherVector.x, this.y / otherVector.y, this.z / otherVector.z, this.w / otherVector.w);
|
|
2816
2860
|
}
|
|
2817
2861
|
/**
|
|
2818
2862
|
* Updates the given vector "result" with the division result of the current Vector4 by the given one.
|
|
2819
2863
|
* @param otherVector vector to devide with
|
|
2820
2864
|
* @param result vector to store the result
|
|
2821
|
-
* @returns
|
|
2865
|
+
* @returns result input
|
|
2822
2866
|
*/
|
|
2823
2867
|
divideToRef(otherVector, result) {
|
|
2824
2868
|
result.x = this.x / otherVector.x;
|
|
2825
2869
|
result.y = this.y / otherVector.y;
|
|
2826
2870
|
result.z = this.z / otherVector.z;
|
|
2827
2871
|
result.w = this.w / otherVector.w;
|
|
2828
|
-
return
|
|
2872
|
+
return result;
|
|
2829
2873
|
}
|
|
2830
2874
|
/**
|
|
2831
2875
|
* Divides the current Vector3 coordinates by the given ones.
|
|
@@ -2880,14 +2924,14 @@ export class Vector4 {
|
|
|
2880
2924
|
* @returns a new Vector4
|
|
2881
2925
|
*/
|
|
2882
2926
|
floor() {
|
|
2883
|
-
return new
|
|
2927
|
+
return new this.constructor(Math.floor(this.x), Math.floor(this.y), Math.floor(this.z), Math.floor(this.w));
|
|
2884
2928
|
}
|
|
2885
2929
|
/**
|
|
2886
2930
|
* Gets a new Vector4 from current Vector4 fractional values
|
|
2887
2931
|
* @returns a new Vector4
|
|
2888
2932
|
*/
|
|
2889
2933
|
fract() {
|
|
2890
|
-
return new
|
|
2934
|
+
return new this.constructor(this.x - Math.floor(this.x), this.y - Math.floor(this.y), this.z - Math.floor(this.z), this.w - Math.floor(this.w));
|
|
2891
2935
|
}
|
|
2892
2936
|
// Properties
|
|
2893
2937
|
/**
|
|
@@ -2928,7 +2972,7 @@ export class Vector4 {
|
|
|
2928
2972
|
* @returns the new cloned vector
|
|
2929
2973
|
*/
|
|
2930
2974
|
clone() {
|
|
2931
|
-
return new
|
|
2975
|
+
return new this.constructor(this.x, this.y, this.z, this.w);
|
|
2932
2976
|
}
|
|
2933
2977
|
/**
|
|
2934
2978
|
* Updates the current Vector4 with the given one coordinates.
|
|
@@ -2995,21 +3039,25 @@ export class Vector4 {
|
|
|
2995
3039
|
* @param array the array to pull values from
|
|
2996
3040
|
* @param offset the offset into the array to start at
|
|
2997
3041
|
* @param result the vector to store the result in
|
|
3042
|
+
* @returns result input
|
|
2998
3043
|
*/
|
|
2999
3044
|
static FromArrayToRef(array, offset, result) {
|
|
3000
3045
|
result.x = array[offset];
|
|
3001
3046
|
result.y = array[offset + 1];
|
|
3002
3047
|
result.z = array[offset + 2];
|
|
3003
3048
|
result.w = array[offset + 3];
|
|
3049
|
+
return result;
|
|
3004
3050
|
}
|
|
3005
3051
|
/**
|
|
3006
3052
|
* Updates the given vector "result" from the starting index of the given Float32Array.
|
|
3007
3053
|
* @param array the array to pull values from
|
|
3008
3054
|
* @param offset the offset into the array to start at
|
|
3009
3055
|
* @param result the vector to store the result in
|
|
3056
|
+
* @returns result input
|
|
3010
3057
|
*/
|
|
3011
3058
|
static FromFloatArrayToRef(array, offset, result) {
|
|
3012
3059
|
Vector4.FromArrayToRef(array, offset, result);
|
|
3060
|
+
return result;
|
|
3013
3061
|
}
|
|
3014
3062
|
/**
|
|
3015
3063
|
* Updates the given vector "result" coordinates from the given floats.
|
|
@@ -3018,12 +3066,14 @@ export class Vector4 {
|
|
|
3018
3066
|
* @param z float to set from
|
|
3019
3067
|
* @param w float to set from
|
|
3020
3068
|
* @param result the vector to the floats in
|
|
3069
|
+
* @returns result input
|
|
3021
3070
|
*/
|
|
3022
3071
|
static FromFloatsToRef(x, y, z, w, result) {
|
|
3023
3072
|
result.x = x;
|
|
3024
3073
|
result.y = y;
|
|
3025
3074
|
result.z = z;
|
|
3026
3075
|
result.w = w;
|
|
3076
|
+
return result;
|
|
3027
3077
|
}
|
|
3028
3078
|
/**
|
|
3029
3079
|
* Returns a new Vector4 set to (0.0, 0.0, 0.0, 0.0)
|
|
@@ -3059,10 +3109,12 @@ export class Vector4 {
|
|
|
3059
3109
|
* Updates the given vector "result" from the normalization of the given one.
|
|
3060
3110
|
* @param vector the vector to normalize
|
|
3061
3111
|
* @param result the vector to store the result in
|
|
3112
|
+
* @returns result input
|
|
3062
3113
|
*/
|
|
3063
3114
|
static NormalizeToRef(vector, result) {
|
|
3064
3115
|
result.copyFrom(vector);
|
|
3065
3116
|
result.normalize();
|
|
3117
|
+
return result;
|
|
3066
3118
|
}
|
|
3067
3119
|
/**
|
|
3068
3120
|
* Returns a vector with the minimum values from the left and right vectors
|
|
@@ -3071,7 +3123,8 @@ export class Vector4 {
|
|
|
3071
3123
|
* @returns a new vector with the minimum of the left and right vector values
|
|
3072
3124
|
*/
|
|
3073
3125
|
static Minimize(left, right) {
|
|
3074
|
-
const min = left.
|
|
3126
|
+
const min = new left.constructor();
|
|
3127
|
+
min.copyFrom(left);
|
|
3075
3128
|
min.minimizeInPlace(right);
|
|
3076
3129
|
return min;
|
|
3077
3130
|
}
|
|
@@ -3082,7 +3135,8 @@ export class Vector4 {
|
|
|
3082
3135
|
* @returns a new vector with the maximum of the left and right vector values
|
|
3083
3136
|
*/
|
|
3084
3137
|
static Maximize(left, right) {
|
|
3085
|
-
const max = left.
|
|
3138
|
+
const max = new left.constructor();
|
|
3139
|
+
max.copyFrom(left);
|
|
3086
3140
|
max.maximizeInPlace(right);
|
|
3087
3141
|
return max;
|
|
3088
3142
|
}
|
|
@@ -3147,9 +3201,11 @@ export class Vector4 {
|
|
|
3147
3201
|
* @param vector defines the Vector3 to transform
|
|
3148
3202
|
* @param transformation defines the transformation matrix
|
|
3149
3203
|
* @param result defines the Vector4 where to store the result
|
|
3204
|
+
* @returns result input
|
|
3150
3205
|
*/
|
|
3151
3206
|
static TransformCoordinatesToRef(vector, transformation, result) {
|
|
3152
3207
|
Vector4.TransformCoordinatesFromFloatsToRef(vector._x, vector._y, vector._z, transformation, result);
|
|
3208
|
+
return result;
|
|
3153
3209
|
}
|
|
3154
3210
|
/**
|
|
3155
3211
|
* Sets the given vector "result" coordinates with the result of the transformation by the given matrix of the given floats (x, y, z)
|
|
@@ -3160,6 +3216,7 @@ export class Vector4 {
|
|
|
3160
3216
|
* @param z define the z coordinate of the source vector
|
|
3161
3217
|
* @param transformation defines the transformation matrix
|
|
3162
3218
|
* @param result defines the Vector4 where to store the result
|
|
3219
|
+
* @returns result input
|
|
3163
3220
|
*/
|
|
3164
3221
|
static TransformCoordinatesFromFloatsToRef(x, y, z, transformation, result) {
|
|
3165
3222
|
const m = transformation.m;
|
|
@@ -3171,6 +3228,7 @@ export class Vector4 {
|
|
|
3171
3228
|
result.y = ry;
|
|
3172
3229
|
result.z = rz;
|
|
3173
3230
|
result.w = rw;
|
|
3231
|
+
return result;
|
|
3174
3232
|
}
|
|
3175
3233
|
/**
|
|
3176
3234
|
* Returns a new Vector4 set with the result of the normal transformation by the given matrix of the given vector.
|
|
@@ -3180,7 +3238,7 @@ export class Vector4 {
|
|
|
3180
3238
|
* @returns the new vector
|
|
3181
3239
|
*/
|
|
3182
3240
|
static TransformNormal(vector, transformation) {
|
|
3183
|
-
const result =
|
|
3241
|
+
const result = new vector.constructor();
|
|
3184
3242
|
Vector4.TransformNormalToRef(vector, transformation, result);
|
|
3185
3243
|
return result;
|
|
3186
3244
|
}
|
|
@@ -3190,6 +3248,7 @@ export class Vector4 {
|
|
|
3190
3248
|
* @param vector the vector to transform
|
|
3191
3249
|
* @param transformation the transformation matrix to apply
|
|
3192
3250
|
* @param result the vector to store the result in
|
|
3251
|
+
* @returns result input
|
|
3193
3252
|
*/
|
|
3194
3253
|
static TransformNormalToRef(vector, transformation, result) {
|
|
3195
3254
|
const m = transformation.m;
|
|
@@ -3200,6 +3259,7 @@ export class Vector4 {
|
|
|
3200
3259
|
result.y = y;
|
|
3201
3260
|
result.z = z;
|
|
3202
3261
|
result.w = vector.w;
|
|
3262
|
+
return result;
|
|
3203
3263
|
}
|
|
3204
3264
|
/**
|
|
3205
3265
|
* Sets the given vector "result" with the result of the normal transformation by the given matrix of the given floats (x, y, z, w).
|
|
@@ -3210,6 +3270,7 @@ export class Vector4 {
|
|
|
3210
3270
|
* @param w value to transform
|
|
3211
3271
|
* @param transformation the transformation matrix to apply
|
|
3212
3272
|
* @param result the vector to store the results in
|
|
3273
|
+
* @returns result input
|
|
3213
3274
|
*/
|
|
3214
3275
|
static TransformNormalFromFloatsToRef(x, y, z, w, transformation, result) {
|
|
3215
3276
|
const m = transformation.m;
|
|
@@ -3217,6 +3278,7 @@ export class Vector4 {
|
|
|
3217
3278
|
result.y = x * m[1] + y * m[5] + z * m[9];
|
|
3218
3279
|
result.z = x * m[2] + y * m[6] + z * m[10];
|
|
3219
3280
|
result.w = w;
|
|
3281
|
+
return result;
|
|
3220
3282
|
}
|
|
3221
3283
|
/**
|
|
3222
3284
|
* Creates a new Vector4 from a Vector3
|
|
@@ -3357,7 +3419,7 @@ export class Quaternion {
|
|
|
3357
3419
|
* @returns a new quaternion copied from the current one
|
|
3358
3420
|
*/
|
|
3359
3421
|
clone() {
|
|
3360
|
-
return new
|
|
3422
|
+
return new this.constructor(this._x, this._y, this._z, this._w);
|
|
3361
3423
|
}
|
|
3362
3424
|
/**
|
|
3363
3425
|
* Copy a quaternion to the current one
|
|
@@ -3403,7 +3465,7 @@ export class Quaternion {
|
|
|
3403
3465
|
* @returns a new quaternion as the addition result of the given one and the current quaternion
|
|
3404
3466
|
*/
|
|
3405
3467
|
add(other) {
|
|
3406
|
-
return new
|
|
3468
|
+
return new this.constructor(this._x + other._x, this._y + other._y, this._z + other._z, this._w + other._w);
|
|
3407
3469
|
}
|
|
3408
3470
|
/**
|
|
3409
3471
|
* Add a quaternion to the current one
|
|
@@ -3423,7 +3485,7 @@ export class Quaternion {
|
|
|
3423
3485
|
* @returns a new quaternion as the subtraction result of the given one from the current one
|
|
3424
3486
|
*/
|
|
3425
3487
|
subtract(other) {
|
|
3426
|
-
return new
|
|
3488
|
+
return new this.constructor(this._x - other._x, this._y - other._y, this._z - other._z, this._w - other._w);
|
|
3427
3489
|
}
|
|
3428
3490
|
/**
|
|
3429
3491
|
* Subtract a quaternion to the current one
|
|
@@ -3443,20 +3505,20 @@ export class Quaternion {
|
|
|
3443
3505
|
* @returns a new quaternion set by multiplying the current quaternion coordinates by the float "scale"
|
|
3444
3506
|
*/
|
|
3445
3507
|
scale(value) {
|
|
3446
|
-
return new
|
|
3508
|
+
return new this.constructor(this._x * value, this._y * value, this._z * value, this._w * value);
|
|
3447
3509
|
}
|
|
3448
3510
|
/**
|
|
3449
3511
|
* Scale the current quaternion values by a factor and stores the result to a given quaternion
|
|
3450
3512
|
* @param scale defines the scale factor
|
|
3451
3513
|
* @param result defines the Quaternion object where to store the result
|
|
3452
|
-
* @returns
|
|
3514
|
+
* @returns result input
|
|
3453
3515
|
*/
|
|
3454
3516
|
scaleToRef(scale, result) {
|
|
3455
3517
|
result.x = this._x * scale;
|
|
3456
3518
|
result.y = this._y * scale;
|
|
3457
3519
|
result.z = this._z * scale;
|
|
3458
3520
|
result.w = this._w * scale;
|
|
3459
|
-
return
|
|
3521
|
+
return result;
|
|
3460
3522
|
}
|
|
3461
3523
|
/**
|
|
3462
3524
|
* Multiplies in place the current quaternion by a scale factor
|
|
@@ -3474,14 +3536,14 @@ export class Quaternion {
|
|
|
3474
3536
|
* Scale the current quaternion values by a factor and add the result to a given quaternion
|
|
3475
3537
|
* @param scale defines the scale factor
|
|
3476
3538
|
* @param result defines the Quaternion object where to store the result
|
|
3477
|
-
* @returns
|
|
3539
|
+
* @returns result input
|
|
3478
3540
|
*/
|
|
3479
3541
|
scaleAndAddToRef(scale, result) {
|
|
3480
3542
|
result.x += this._x * scale;
|
|
3481
3543
|
result.y += this._y * scale;
|
|
3482
3544
|
result.z += this._z * scale;
|
|
3483
3545
|
result.w += this._w * scale;
|
|
3484
|
-
return
|
|
3546
|
+
return result;
|
|
3485
3547
|
}
|
|
3486
3548
|
/**
|
|
3487
3549
|
* Multiplies two quaternions
|
|
@@ -3489,7 +3551,7 @@ export class Quaternion {
|
|
|
3489
3551
|
* @returns a new quaternion set as the multiplication result of the current one with the given one "q1"
|
|
3490
3552
|
*/
|
|
3491
3553
|
multiply(q1) {
|
|
3492
|
-
const result = new
|
|
3554
|
+
const result = new this.constructor(0, 0, 0, 1.0);
|
|
3493
3555
|
this.multiplyToRef(q1, result);
|
|
3494
3556
|
return result;
|
|
3495
3557
|
}
|
|
@@ -3505,7 +3567,7 @@ export class Quaternion {
|
|
|
3505
3567
|
const z = this._x * q1._y - this._y * q1._x + this._z * q1._w + this._w * q1._z;
|
|
3506
3568
|
const w = -this._x * q1._x - this._y * q1._y - this._z * q1._z + this._w * q1._w;
|
|
3507
3569
|
result.copyFromFloats(x, y, z, w);
|
|
3508
|
-
return
|
|
3570
|
+
return result;
|
|
3509
3571
|
}
|
|
3510
3572
|
/**
|
|
3511
3573
|
* Updates the current quaternion with the multiplication of itself with the given one "q1"
|
|
@@ -3519,11 +3581,11 @@ export class Quaternion {
|
|
|
3519
3581
|
/**
|
|
3520
3582
|
* Conjugates the current quaternion and stores the result in the given quaternion
|
|
3521
3583
|
* @param ref defines the target quaternion
|
|
3522
|
-
* @returns
|
|
3584
|
+
* @returns result input
|
|
3523
3585
|
*/
|
|
3524
3586
|
conjugateToRef(ref) {
|
|
3525
3587
|
ref.copyFromFloats(-this._x, -this._y, -this._z, this._w);
|
|
3526
|
-
return
|
|
3588
|
+
return ref;
|
|
3527
3589
|
}
|
|
3528
3590
|
/**
|
|
3529
3591
|
* Conjugates in place the current quaternion
|
|
@@ -3540,7 +3602,7 @@ export class Quaternion {
|
|
|
3540
3602
|
* @returns a new quaternion
|
|
3541
3603
|
*/
|
|
3542
3604
|
conjugate() {
|
|
3543
|
-
return new
|
|
3605
|
+
return new this.constructor(-this._x, -this._y, -this._z, this._w);
|
|
3544
3606
|
}
|
|
3545
3607
|
/**
|
|
3546
3608
|
* Returns the inverse of the current quaternion
|
|
@@ -3620,7 +3682,7 @@ export class Quaternion {
|
|
|
3620
3682
|
/**
|
|
3621
3683
|
* Sets the given vector3 "result" with the Euler angles translated from the current quaternion
|
|
3622
3684
|
* @param result defines the vector which will be filled with the Euler angles
|
|
3623
|
-
* @returns
|
|
3685
|
+
* @returns result input
|
|
3624
3686
|
* @see https://doc.babylonjs.com/divingDeeper/mesh/transforms/center_origin/rotation_conventions
|
|
3625
3687
|
*/
|
|
3626
3688
|
toEulerAnglesToRef(result) {
|
|
@@ -3649,7 +3711,7 @@ export class Quaternion {
|
|
|
3649
3711
|
result.x = Math.asin(-2.0 * zAxisY);
|
|
3650
3712
|
result.y = Math.atan2(2.0 * (qz * qx + qy * qw), sqz - sqx - sqy + sqw);
|
|
3651
3713
|
}
|
|
3652
|
-
return
|
|
3714
|
+
return result;
|
|
3653
3715
|
}
|
|
3654
3716
|
/**
|
|
3655
3717
|
* Updates the given rotation matrix with the current quaternion values
|
|
@@ -3658,7 +3720,7 @@ export class Quaternion {
|
|
|
3658
3720
|
*/
|
|
3659
3721
|
toRotationMatrix(result) {
|
|
3660
3722
|
Matrix.FromQuaternionToRef(this, result);
|
|
3661
|
-
return
|
|
3723
|
+
return result;
|
|
3662
3724
|
}
|
|
3663
3725
|
/**
|
|
3664
3726
|
* Updates the current quaternion from the given rotation matrix values
|
|
@@ -3684,6 +3746,7 @@ export class Quaternion {
|
|
|
3684
3746
|
* Updates the given quaternion with the given rotation matrix values
|
|
3685
3747
|
* @param matrix defines the source matrix
|
|
3686
3748
|
* @param result defines the target quaternion
|
|
3749
|
+
* @returns result input
|
|
3687
3750
|
*/
|
|
3688
3751
|
static FromRotationMatrixToRef(matrix, result) {
|
|
3689
3752
|
const data = matrix.m;
|
|
@@ -3720,6 +3783,7 @@ export class Quaternion {
|
|
|
3720
3783
|
result.y = (m23 + m32) / s;
|
|
3721
3784
|
result.z = 0.25 * s;
|
|
3722
3785
|
}
|
|
3786
|
+
return result;
|
|
3723
3787
|
}
|
|
3724
3788
|
/**
|
|
3725
3789
|
* Creates the rotation quaternion needed to rotate from one Vector3 onto another Vector3
|
|
@@ -3782,6 +3846,7 @@ export class Quaternion {
|
|
|
3782
3846
|
let slerp = lerpTime === 0 ? 1 : deltaTime / lerpTime;
|
|
3783
3847
|
slerp = Scalar.Clamp(slerp, 0, 1);
|
|
3784
3848
|
Quaternion.SlerpToRef(source, goal, slerp, result);
|
|
3849
|
+
return result;
|
|
3785
3850
|
}
|
|
3786
3851
|
/**
|
|
3787
3852
|
* Creates an empty quaternion
|
|
@@ -3796,7 +3861,7 @@ export class Quaternion {
|
|
|
3796
3861
|
* @returns a new quaternion as the inverted current quaternion
|
|
3797
3862
|
*/
|
|
3798
3863
|
static Inverse(q) {
|
|
3799
|
-
return new
|
|
3864
|
+
return new q.constructor(-q._x, -q._y, -q._z, q._w);
|
|
3800
3865
|
}
|
|
3801
3866
|
/**
|
|
3802
3867
|
* Inverse a given quaternion
|
|
@@ -3865,12 +3930,14 @@ export class Quaternion {
|
|
|
3865
3930
|
* @param array the array to pull values from
|
|
3866
3931
|
* @param offset the offset into the array to start at
|
|
3867
3932
|
* @param result the quaternion to store the result in
|
|
3933
|
+
* @returns result input
|
|
3868
3934
|
*/
|
|
3869
3935
|
static FromArrayToRef(array, offset, result) {
|
|
3870
3936
|
result.x = array[offset];
|
|
3871
3937
|
result.y = array[offset + 1];
|
|
3872
3938
|
result.z = array[offset + 2];
|
|
3873
3939
|
result.w = array[offset + 3];
|
|
3940
|
+
return result;
|
|
3874
3941
|
}
|
|
3875
3942
|
/**
|
|
3876
3943
|
* Create a quaternion from Euler rotation angles
|
|
@@ -3957,6 +4024,7 @@ export class Quaternion {
|
|
|
3957
4024
|
* @param pitch defines the rotation around X axis
|
|
3958
4025
|
* @param roll defines the rotation around Z axis
|
|
3959
4026
|
* @param result defines the target quaternion
|
|
4027
|
+
* @returns result input
|
|
3960
4028
|
*/
|
|
3961
4029
|
static RotationYawPitchRollToRef(yaw, pitch, roll, result) {
|
|
3962
4030
|
// Produces a quaternion from Euler angles in the z-y-x orientation (Tait-Bryan angles)
|
|
@@ -3973,6 +4041,7 @@ export class Quaternion {
|
|
|
3973
4041
|
result.y = sinYaw * cosPitch * cosRoll - cosYaw * sinPitch * sinRoll;
|
|
3974
4042
|
result.z = cosYaw * cosPitch * sinRoll - sinYaw * sinPitch * cosRoll;
|
|
3975
4043
|
result.w = cosYaw * cosPitch * cosRoll + sinYaw * sinPitch * sinRoll;
|
|
4044
|
+
return result;
|
|
3976
4045
|
}
|
|
3977
4046
|
/**
|
|
3978
4047
|
* Creates a new quaternion from the given Euler float angles expressed in z-x-z orientation
|
|
@@ -3992,6 +4061,7 @@ export class Quaternion {
|
|
|
3992
4061
|
* @param beta defines the rotation around second axis
|
|
3993
4062
|
* @param gamma defines the rotation around third axis
|
|
3994
4063
|
* @param result defines the target quaternion
|
|
4064
|
+
* @returns result input
|
|
3995
4065
|
*/
|
|
3996
4066
|
static RotationAlphaBetaGammaToRef(alpha, beta, gamma, result) {
|
|
3997
4067
|
// Produces a quaternion from Euler angles in the z-x-z orientation
|
|
@@ -4002,6 +4072,7 @@ export class Quaternion {
|
|
|
4002
4072
|
result.y = Math.sin(halfGammaMinusAlpha) * Math.sin(halfBeta);
|
|
4003
4073
|
result.z = Math.sin(halfGammaPlusAlpha) * Math.cos(halfBeta);
|
|
4004
4074
|
result.w = Math.cos(halfGammaPlusAlpha) * Math.cos(halfBeta);
|
|
4075
|
+
return result;
|
|
4005
4076
|
}
|
|
4006
4077
|
/**
|
|
4007
4078
|
* Creates a new quaternion containing the rotation value to reach the target (axis1, axis2, axis3) orientation as a rotated XYZ system (axis1, axis2 and axis3 are normalized during this operation)
|
|
@@ -4021,11 +4092,13 @@ export class Quaternion {
|
|
|
4021
4092
|
* @param axis2 defines the second axis
|
|
4022
4093
|
* @param axis3 defines the third axis
|
|
4023
4094
|
* @param ref defines the target quaternion
|
|
4095
|
+
* @returns result input
|
|
4024
4096
|
*/
|
|
4025
4097
|
static RotationQuaternionFromAxisToRef(axis1, axis2, axis3, ref) {
|
|
4026
4098
|
const rotMat = MathTmp.Matrix[0];
|
|
4027
4099
|
Matrix.FromXYZAxesToRef(axis1.normalize(), axis2.normalize(), axis3.normalize(), rotMat);
|
|
4028
4100
|
Quaternion.FromRotationMatrixToRef(rotMat, ref);
|
|
4101
|
+
return ref;
|
|
4029
4102
|
}
|
|
4030
4103
|
/**
|
|
4031
4104
|
* Creates a new rotation value to orient an object to look towards the given forward direction, the up direction being oriented like "up".
|
|
@@ -4045,11 +4118,13 @@ export class Quaternion {
|
|
|
4045
4118
|
* @param forward defines the forward direction - Must be normalized and orthogonal to up.
|
|
4046
4119
|
* @param up defines the up vector for the entity - Must be normalized and orthogonal to forward.
|
|
4047
4120
|
* @param ref defines the target quaternion.
|
|
4121
|
+
* @returns result input
|
|
4048
4122
|
*/
|
|
4049
4123
|
static FromLookDirectionLHToRef(forward, up, ref) {
|
|
4050
4124
|
const rotMat = MathTmp.Matrix[0];
|
|
4051
4125
|
Matrix.LookDirectionLHToRef(forward, up, rotMat);
|
|
4052
4126
|
Quaternion.FromRotationMatrixToRef(rotMat, ref);
|
|
4127
|
+
return ref;
|
|
4053
4128
|
}
|
|
4054
4129
|
/**
|
|
4055
4130
|
* Creates a new rotation value to orient an object to look towards the given forward direction, the up direction being oriented like "up".
|
|
@@ -4069,6 +4144,7 @@ export class Quaternion {
|
|
|
4069
4144
|
* @param forward defines the forward direction - Must be normalized and orthogonal to up.
|
|
4070
4145
|
* @param up defines the up vector for the entity - Must be normalized and orthogonal to forward.
|
|
4071
4146
|
* @param ref defines the target quaternion.
|
|
4147
|
+
* @returns result input
|
|
4072
4148
|
*/
|
|
4073
4149
|
static FromLookDirectionRHToRef(forward, up, ref) {
|
|
4074
4150
|
const rotMat = MathTmp.Matrix[0];
|
|
@@ -4093,6 +4169,7 @@ export class Quaternion {
|
|
|
4093
4169
|
* @param right defines second quaternion
|
|
4094
4170
|
* @param amount defines the gradient to use
|
|
4095
4171
|
* @param result defines the target quaternion
|
|
4172
|
+
* @returns result input
|
|
4096
4173
|
*/
|
|
4097
4174
|
static SlerpToRef(left, right, amount, result) {
|
|
4098
4175
|
let num2;
|
|
@@ -4117,6 +4194,7 @@ export class Quaternion {
|
|
|
4117
4194
|
result.y = num3 * left._y + num2 * right._y;
|
|
4118
4195
|
result.z = num3 * left._z + num2 * right._z;
|
|
4119
4196
|
result.w = num3 * left._w + num2 * right._w;
|
|
4197
|
+
return result;
|
|
4120
4198
|
}
|
|
4121
4199
|
/**
|
|
4122
4200
|
* Interpolate between two quaternions using Hermite interpolation
|
|
@@ -4138,7 +4216,7 @@ export class Quaternion {
|
|
|
4138
4216
|
const y = value1._y * part1 + value2._y * part2 + tangent1._y * part3 + tangent2._y * part4;
|
|
4139
4217
|
const z = value1._z * part1 + value2._z * part2 + tangent1._z * part3 + tangent2._z * part4;
|
|
4140
4218
|
const w = value1._w * part1 + value2._w * part2 + tangent1._w * part3 + tangent2._w * part4;
|
|
4141
|
-
return new
|
|
4219
|
+
return new value1.constructor(x, y, z, w);
|
|
4142
4220
|
}
|
|
4143
4221
|
/**
|
|
4144
4222
|
* Returns a new Quaternion which is the 1st derivative of the Hermite spline defined by the quaternions "value1", "value2", "tangent1", "tangent2".
|
|
@@ -4150,7 +4228,7 @@ export class Quaternion {
|
|
|
4150
4228
|
* @returns 1st derivative
|
|
4151
4229
|
*/
|
|
4152
4230
|
static Hermite1stDerivative(value1, tangent1, value2, tangent2, time) {
|
|
4153
|
-
const result =
|
|
4231
|
+
const result = new value1.constructor();
|
|
4154
4232
|
this.Hermite1stDerivativeToRef(value1, tangent1, value2, tangent2, time, result);
|
|
4155
4233
|
return result;
|
|
4156
4234
|
}
|
|
@@ -4162,6 +4240,7 @@ export class Quaternion {
|
|
|
4162
4240
|
* @param tangent2 defines the second tangent
|
|
4163
4241
|
* @param time define where the derivative must be done
|
|
4164
4242
|
* @param result define where to store the derivative
|
|
4243
|
+
* @returns result input
|
|
4165
4244
|
*/
|
|
4166
4245
|
static Hermite1stDerivativeToRef(value1, tangent1, value2, tangent2, time, result) {
|
|
4167
4246
|
const t2 = time * time;
|
|
@@ -4169,6 +4248,7 @@ export class Quaternion {
|
|
|
4169
4248
|
result.y = (t2 - time) * 6 * value1.y + (3 * t2 - 4 * time + 1) * tangent1.y + (-t2 + time) * 6 * value2.y + (3 * t2 - 2 * time) * tangent2.y;
|
|
4170
4249
|
result.z = (t2 - time) * 6 * value1.z + (3 * t2 - 4 * time + 1) * tangent1.z + (-t2 + time) * 6 * value2.z + (3 * t2 - 2 * time) * tangent2.z;
|
|
4171
4250
|
result.w = (t2 - time) * 6 * value1.w + (3 * t2 - 4 * time + 1) * tangent1.w + (-t2 + time) * 6 * value2.w + (3 * t2 - 2 * time) * tangent2.w;
|
|
4251
|
+
return result;
|
|
4172
4252
|
}
|
|
4173
4253
|
}
|
|
4174
4254
|
/**
|
|
@@ -4355,7 +4435,7 @@ export class Matrix {
|
|
|
4355
4435
|
* @returns a new matrix as the addition of the current matrix and the given one
|
|
4356
4436
|
*/
|
|
4357
4437
|
add(other) {
|
|
4358
|
-
const result = new
|
|
4438
|
+
const result = new this.constructor();
|
|
4359
4439
|
this.addToRef(other, result);
|
|
4360
4440
|
return result;
|
|
4361
4441
|
}
|
|
@@ -4363,7 +4443,7 @@ export class Matrix {
|
|
|
4363
4443
|
* Sets the given matrix "result" to the addition of the current matrix and the given one
|
|
4364
4444
|
* @param other defines the matrix to add
|
|
4365
4445
|
* @param result defines the target matrix
|
|
4366
|
-
* @returns
|
|
4446
|
+
* @returns result input
|
|
4367
4447
|
*/
|
|
4368
4448
|
addToRef(other, result) {
|
|
4369
4449
|
const m = this._m;
|
|
@@ -4373,7 +4453,7 @@ export class Matrix {
|
|
|
4373
4453
|
resultM[index] = m[index] + otherM[index];
|
|
4374
4454
|
}
|
|
4375
4455
|
result.markAsUpdated();
|
|
4376
|
-
return
|
|
4456
|
+
return result;
|
|
4377
4457
|
}
|
|
4378
4458
|
/**
|
|
4379
4459
|
* Adds in place the given matrix to the current matrix
|
|
@@ -4392,12 +4472,12 @@ export class Matrix {
|
|
|
4392
4472
|
/**
|
|
4393
4473
|
* Sets the given matrix to the current inverted Matrix
|
|
4394
4474
|
* @param other defines the target matrix
|
|
4395
|
-
* @returns
|
|
4475
|
+
* @returns result input
|
|
4396
4476
|
*/
|
|
4397
4477
|
invertToRef(other) {
|
|
4398
4478
|
if (this._isIdentity === true) {
|
|
4399
4479
|
Matrix.IdentityToRef(other);
|
|
4400
|
-
return
|
|
4480
|
+
return other;
|
|
4401
4481
|
}
|
|
4402
4482
|
// the inverse of a Matrix is the transpose of cofactor matrix divided by the determinant
|
|
4403
4483
|
const m = this._m;
|
|
@@ -4419,7 +4499,7 @@ export class Matrix {
|
|
|
4419
4499
|
if (det === 0) {
|
|
4420
4500
|
// not invertible
|
|
4421
4501
|
other.copyFrom(this);
|
|
4422
|
-
return
|
|
4502
|
+
return other;
|
|
4423
4503
|
}
|
|
4424
4504
|
const detInv = 1 / det;
|
|
4425
4505
|
const det_12_33 = m12 * m33 - m32 * m13;
|
|
@@ -4447,7 +4527,7 @@ export class Matrix {
|
|
|
4447
4527
|
const cofact_32 = -(m00 * det_11_23 - m01 * det_10_23 + m03 * det_10_21);
|
|
4448
4528
|
const cofact_33 = +(m00 * det_11_22 - m01 * det_10_22 + m02 * det_10_21);
|
|
4449
4529
|
Matrix.FromValuesToRef(cofact_00 * detInv, cofact_10 * detInv, cofact_20 * detInv, cofact_30 * detInv, cofact_01 * detInv, cofact_11 * detInv, cofact_21 * detInv, cofact_31 * detInv, cofact_02 * detInv, cofact_12 * detInv, cofact_22 * detInv, cofact_32 * detInv, cofact_03 * detInv, cofact_13 * detInv, cofact_23 * detInv, cofact_33 * detInv, other);
|
|
4450
|
-
return
|
|
4530
|
+
return other;
|
|
4451
4531
|
}
|
|
4452
4532
|
/**
|
|
4453
4533
|
* add a value at the specified position in the current Matrix
|
|
@@ -4523,7 +4603,7 @@ export class Matrix {
|
|
|
4523
4603
|
result.x = this._m[12];
|
|
4524
4604
|
result.y = this._m[13];
|
|
4525
4605
|
result.z = this._m[14];
|
|
4526
|
-
return
|
|
4606
|
+
return result;
|
|
4527
4607
|
}
|
|
4528
4608
|
/**
|
|
4529
4609
|
* Remove rotation and scaling part from the matrix
|
|
@@ -4541,7 +4621,7 @@ export class Matrix {
|
|
|
4541
4621
|
* @returns a new matrix set with the multiplication result of the current Matrix and the given one
|
|
4542
4622
|
*/
|
|
4543
4623
|
multiply(other) {
|
|
4544
|
-
const result = new
|
|
4624
|
+
const result = new this.constructor();
|
|
4545
4625
|
this.multiplyToRef(other, result);
|
|
4546
4626
|
return result;
|
|
4547
4627
|
}
|
|
@@ -4587,20 +4667,20 @@ export class Matrix {
|
|
|
4587
4667
|
* Sets the given matrix "result" with the multiplication result of the current Matrix and the given one
|
|
4588
4668
|
* @param other defines the second operand
|
|
4589
4669
|
* @param result defines the matrix where to store the multiplication
|
|
4590
|
-
* @returns
|
|
4670
|
+
* @returns result input
|
|
4591
4671
|
*/
|
|
4592
4672
|
multiplyToRef(other, result) {
|
|
4593
4673
|
if (this._isIdentity) {
|
|
4594
4674
|
result.copyFrom(other);
|
|
4595
|
-
return
|
|
4675
|
+
return result;
|
|
4596
4676
|
}
|
|
4597
4677
|
if (other._isIdentity) {
|
|
4598
4678
|
result.copyFrom(this);
|
|
4599
|
-
return
|
|
4679
|
+
return result;
|
|
4600
4680
|
}
|
|
4601
4681
|
this.multiplyToArray(other, result._m, 0);
|
|
4602
4682
|
result.markAsUpdated();
|
|
4603
|
-
return
|
|
4683
|
+
return result;
|
|
4604
4684
|
}
|
|
4605
4685
|
/**
|
|
4606
4686
|
* Sets the Float32Array "result" from the given index "offset" with the multiplication of the current matrix and the given one
|
|
@@ -4677,7 +4757,7 @@ export class Matrix {
|
|
|
4677
4757
|
* @returns a new matrix from the current matrix
|
|
4678
4758
|
*/
|
|
4679
4759
|
clone() {
|
|
4680
|
-
const matrix = new
|
|
4760
|
+
const matrix = new this.constructor();
|
|
4681
4761
|
matrix.copyFrom(this);
|
|
4682
4762
|
return matrix;
|
|
4683
4763
|
}
|
|
@@ -4779,7 +4859,7 @@ export class Matrix {
|
|
|
4779
4859
|
* Gets specific row of the matrix to ref
|
|
4780
4860
|
* @param index defines the number of the row to get
|
|
4781
4861
|
* @param rowVector vector to store the index-th row of the current matrix
|
|
4782
|
-
* @returns
|
|
4862
|
+
* @returns result input
|
|
4783
4863
|
*/
|
|
4784
4864
|
getRowToRef(index, rowVector) {
|
|
4785
4865
|
if (index >= 0 && index < 3) {
|
|
@@ -4789,7 +4869,7 @@ export class Matrix {
|
|
|
4789
4869
|
rowVector.z = this._m[i + 2];
|
|
4790
4870
|
rowVector.w = this._m[i + 3];
|
|
4791
4871
|
}
|
|
4792
|
-
return
|
|
4872
|
+
return rowVector;
|
|
4793
4873
|
}
|
|
4794
4874
|
/**
|
|
4795
4875
|
* Sets the index-th row of the current matrix to the vector4 values
|
|
@@ -4805,16 +4885,18 @@ export class Matrix {
|
|
|
4805
4885
|
* @returns the new transposed matrix
|
|
4806
4886
|
*/
|
|
4807
4887
|
transpose() {
|
|
4808
|
-
|
|
4888
|
+
const result = new this.constructor();
|
|
4889
|
+
Matrix.TransposeToRef(this, result);
|
|
4890
|
+
return result;
|
|
4809
4891
|
}
|
|
4810
4892
|
/**
|
|
4811
4893
|
* Compute the transpose of the matrix and store it in a given matrix
|
|
4812
4894
|
* @param result defines the target matrix
|
|
4813
|
-
* @returns
|
|
4895
|
+
* @returns result input
|
|
4814
4896
|
*/
|
|
4815
4897
|
transposeToRef(result) {
|
|
4816
4898
|
Matrix.TransposeToRef(this, result);
|
|
4817
|
-
return
|
|
4899
|
+
return result;
|
|
4818
4900
|
}
|
|
4819
4901
|
/**
|
|
4820
4902
|
* Sets the index-th row of the current matrix with the given 4 x float values
|
|
@@ -4843,7 +4925,7 @@ export class Matrix {
|
|
|
4843
4925
|
* @returns a new matrix
|
|
4844
4926
|
*/
|
|
4845
4927
|
scale(scale) {
|
|
4846
|
-
const result = new
|
|
4928
|
+
const result = new this.constructor();
|
|
4847
4929
|
this.scaleToRef(scale, result);
|
|
4848
4930
|
return result;
|
|
4849
4931
|
}
|
|
@@ -4851,27 +4933,27 @@ export class Matrix {
|
|
|
4851
4933
|
* Scale the current matrix values by a factor to a given result matrix
|
|
4852
4934
|
* @param scale defines the scale factor
|
|
4853
4935
|
* @param result defines the matrix to store the result
|
|
4854
|
-
* @returns
|
|
4936
|
+
* @returns result input
|
|
4855
4937
|
*/
|
|
4856
4938
|
scaleToRef(scale, result) {
|
|
4857
4939
|
for (let index = 0; index < 16; index++) {
|
|
4858
4940
|
result._m[index] = this._m[index] * scale;
|
|
4859
4941
|
}
|
|
4860
4942
|
result.markAsUpdated();
|
|
4861
|
-
return
|
|
4943
|
+
return result;
|
|
4862
4944
|
}
|
|
4863
4945
|
/**
|
|
4864
4946
|
* Scale the current matrix values by a factor and add the result to a given matrix
|
|
4865
4947
|
* @param scale defines the scale factor
|
|
4866
4948
|
* @param result defines the Matrix to store the result
|
|
4867
|
-
* @returns
|
|
4949
|
+
* @returns result input
|
|
4868
4950
|
*/
|
|
4869
4951
|
scaleAndAddToRef(scale, result) {
|
|
4870
4952
|
for (let index = 0; index < 16; index++) {
|
|
4871
4953
|
result._m[index] += this._m[index] * scale;
|
|
4872
4954
|
}
|
|
4873
4955
|
result.markAsUpdated();
|
|
4874
|
-
return
|
|
4956
|
+
return result;
|
|
4875
4957
|
}
|
|
4876
4958
|
/**
|
|
4877
4959
|
* Writes to the given matrix a normal matrix, computed from this one (using values from identity matrix for fourth row and column).
|
|
@@ -4883,31 +4965,32 @@ export class Matrix {
|
|
|
4883
4965
|
tmp.transposeToRef(ref);
|
|
4884
4966
|
const m = ref._m;
|
|
4885
4967
|
Matrix.FromValuesToRef(m[0], m[1], m[2], 0.0, m[4], m[5], m[6], 0.0, m[8], m[9], m[10], 0.0, 0.0, 0.0, 0.0, 1.0, ref);
|
|
4968
|
+
return ref;
|
|
4886
4969
|
}
|
|
4887
4970
|
/**
|
|
4888
4971
|
* Gets only rotation part of the current matrix
|
|
4889
4972
|
* @returns a new matrix sets to the extracted rotation matrix from the current one
|
|
4890
4973
|
*/
|
|
4891
4974
|
getRotationMatrix() {
|
|
4892
|
-
const result = new
|
|
4975
|
+
const result = new this.constructor();
|
|
4893
4976
|
this.getRotationMatrixToRef(result);
|
|
4894
4977
|
return result;
|
|
4895
4978
|
}
|
|
4896
4979
|
/**
|
|
4897
4980
|
* Extracts the rotation matrix from the current one and sets it as the given "result"
|
|
4898
4981
|
* @param result defines the target matrix to store data to
|
|
4899
|
-
* @returns
|
|
4982
|
+
* @returns result input
|
|
4900
4983
|
*/
|
|
4901
4984
|
getRotationMatrixToRef(result) {
|
|
4902
4985
|
const scale = MathTmp.Vector3[0];
|
|
4903
4986
|
if (!this.decompose(scale)) {
|
|
4904
4987
|
Matrix.IdentityToRef(result);
|
|
4905
|
-
return
|
|
4988
|
+
return result;
|
|
4906
4989
|
}
|
|
4907
4990
|
const m = this._m;
|
|
4908
4991
|
const sx = 1 / scale._x, sy = 1 / scale._y, sz = 1 / scale._z;
|
|
4909
4992
|
Matrix.FromValuesToRef(m[0] * sx, m[1] * sx, m[2] * sx, 0.0, m[4] * sy, m[5] * sy, m[6] * sy, 0.0, m[8] * sz, m[9] * sz, m[10] * sz, 0.0, 0.0, 0.0, 0.0, 1.0, result);
|
|
4910
|
-
return
|
|
4993
|
+
return result;
|
|
4911
4994
|
}
|
|
4912
4995
|
/**
|
|
4913
4996
|
* Toggles model matrix from being right handed to left handed in place and vice versa
|
|
@@ -4920,6 +5003,7 @@ export class Matrix {
|
|
|
4920
5003
|
m[9] *= -1;
|
|
4921
5004
|
m[14] *= -1;
|
|
4922
5005
|
this.markAsUpdated();
|
|
5006
|
+
return this;
|
|
4923
5007
|
}
|
|
4924
5008
|
/**
|
|
4925
5009
|
* Toggles projection matrix from being right handed to left handed in place and vice versa
|
|
@@ -4931,6 +5015,7 @@ export class Matrix {
|
|
|
4931
5015
|
m[10] *= -1;
|
|
4932
5016
|
m[11] *= -1;
|
|
4933
5017
|
this.markAsUpdated();
|
|
5018
|
+
return this;
|
|
4934
5019
|
}
|
|
4935
5020
|
// Statics
|
|
4936
5021
|
/**
|
|
@@ -4949,12 +5034,14 @@ export class Matrix {
|
|
|
4949
5034
|
* @param array defines the source array
|
|
4950
5035
|
* @param offset defines an offset in the source array
|
|
4951
5036
|
* @param result defines the target matrix
|
|
5037
|
+
* @returns result input
|
|
4952
5038
|
*/
|
|
4953
5039
|
static FromArrayToRef(array, offset, result) {
|
|
4954
5040
|
for (let index = 0; index < 16; index++) {
|
|
4955
5041
|
result._m[index] = array[index + offset];
|
|
4956
5042
|
}
|
|
4957
5043
|
result.markAsUpdated();
|
|
5044
|
+
return result;
|
|
4958
5045
|
}
|
|
4959
5046
|
/**
|
|
4960
5047
|
* Stores an array into a matrix after having multiplied each component by a given factor
|
|
@@ -4962,12 +5049,14 @@ export class Matrix {
|
|
|
4962
5049
|
* @param offset defines the offset in the source array
|
|
4963
5050
|
* @param scale defines the scaling factor
|
|
4964
5051
|
* @param result defines the target matrix
|
|
5052
|
+
* @returns result input
|
|
4965
5053
|
*/
|
|
4966
5054
|
static FromFloat32ArrayToRefScaled(array, offset, scale, result) {
|
|
4967
5055
|
for (let index = 0; index < 16; index++) {
|
|
4968
5056
|
result._m[index] = array[index + offset] * scale;
|
|
4969
5057
|
}
|
|
4970
5058
|
result.markAsUpdated();
|
|
5059
|
+
return result;
|
|
4971
5060
|
}
|
|
4972
5061
|
/**
|
|
4973
5062
|
* Gets an identity matrix that must not be updated
|
|
@@ -4994,6 +5083,7 @@ export class Matrix {
|
|
|
4994
5083
|
* @param initialM43 defines 3rd value of 4th row
|
|
4995
5084
|
* @param initialM44 defines 4th value of 4th row
|
|
4996
5085
|
* @param result defines the target matrix
|
|
5086
|
+
* @returns result input
|
|
4997
5087
|
*/
|
|
4998
5088
|
static FromValuesToRef(initialM11, initialM12, initialM13, initialM14, initialM21, initialM22, initialM23, initialM24, initialM31, initialM32, initialM33, initialM34, initialM41, initialM42, initialM43, initialM44, result) {
|
|
4999
5089
|
const m = result._m;
|
|
@@ -5075,6 +5165,7 @@ export class Matrix {
|
|
|
5075
5165
|
* @param rotation defines the rotation quaternion
|
|
5076
5166
|
* @param translation defines the translation vector3
|
|
5077
5167
|
* @param result defines the target matrix
|
|
5168
|
+
* @returns result input
|
|
5078
5169
|
*/
|
|
5079
5170
|
static ComposeToRef(scale, rotation, translation, result) {
|
|
5080
5171
|
const m = result._m;
|
|
@@ -5101,6 +5192,7 @@ export class Matrix {
|
|
|
5101
5192
|
m[14] = translation._z;
|
|
5102
5193
|
m[15] = 1;
|
|
5103
5194
|
result.markAsUpdated();
|
|
5195
|
+
return result;
|
|
5104
5196
|
}
|
|
5105
5197
|
/**
|
|
5106
5198
|
* Creates a new identity matrix
|
|
@@ -5114,10 +5206,12 @@ export class Matrix {
|
|
|
5114
5206
|
/**
|
|
5115
5207
|
* Creates a new identity matrix and stores the result in a given matrix
|
|
5116
5208
|
* @param result defines the target matrix
|
|
5209
|
+
* @returns result input
|
|
5117
5210
|
*/
|
|
5118
5211
|
static IdentityToRef(result) {
|
|
5119
5212
|
Matrix.FromValuesToRef(1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, result);
|
|
5120
5213
|
result._updateIdentityStatus(true);
|
|
5214
|
+
return result;
|
|
5121
5215
|
}
|
|
5122
5216
|
/**
|
|
5123
5217
|
* Creates a new zero matrix
|
|
@@ -5144,7 +5238,7 @@ export class Matrix {
|
|
|
5144
5238
|
* @returns the new matrix
|
|
5145
5239
|
*/
|
|
5146
5240
|
static Invert(source) {
|
|
5147
|
-
const result = new
|
|
5241
|
+
const result = new source.constructor();
|
|
5148
5242
|
source.invertToRef(result);
|
|
5149
5243
|
return result;
|
|
5150
5244
|
}
|
|
@@ -5152,12 +5246,14 @@ export class Matrix {
|
|
|
5152
5246
|
* Creates a new rotation matrix for "angle" radians around the X axis and stores it in a given matrix
|
|
5153
5247
|
* @param angle defines the angle (in radians) to use
|
|
5154
5248
|
* @param result defines the target matrix
|
|
5249
|
+
* @returns result input
|
|
5155
5250
|
*/
|
|
5156
5251
|
static RotationXToRef(angle, result) {
|
|
5157
5252
|
const s = Math.sin(angle);
|
|
5158
5253
|
const c = Math.cos(angle);
|
|
5159
5254
|
Matrix.FromValuesToRef(1.0, 0.0, 0.0, 0.0, 0.0, c, s, 0.0, 0.0, -s, c, 0.0, 0.0, 0.0, 0.0, 1.0, result);
|
|
5160
5255
|
result._updateIdentityStatus(c === 1 && s === 0);
|
|
5256
|
+
return result;
|
|
5161
5257
|
}
|
|
5162
5258
|
/**
|
|
5163
5259
|
* Creates a new rotation matrix for "angle" radians around the Y axis
|
|
@@ -5173,12 +5269,14 @@ export class Matrix {
|
|
|
5173
5269
|
* Creates a new rotation matrix for "angle" radians around the Y axis and stores it in a given matrix
|
|
5174
5270
|
* @param angle defines the angle (in radians) to use
|
|
5175
5271
|
* @param result defines the target matrix
|
|
5272
|
+
* @returns result input
|
|
5176
5273
|
*/
|
|
5177
5274
|
static RotationYToRef(angle, result) {
|
|
5178
5275
|
const s = Math.sin(angle);
|
|
5179
5276
|
const c = Math.cos(angle);
|
|
5180
5277
|
Matrix.FromValuesToRef(c, 0.0, -s, 0.0, 0.0, 1.0, 0.0, 0.0, s, 0.0, c, 0.0, 0.0, 0.0, 0.0, 1.0, result);
|
|
5181
5278
|
result._updateIdentityStatus(c === 1 && s === 0);
|
|
5279
|
+
return result;
|
|
5182
5280
|
}
|
|
5183
5281
|
/**
|
|
5184
5282
|
* Creates a new rotation matrix for "angle" radians around the Z axis
|
|
@@ -5194,12 +5292,14 @@ export class Matrix {
|
|
|
5194
5292
|
* Creates a new rotation matrix for "angle" radians around the Z axis and stores it in a given matrix
|
|
5195
5293
|
* @param angle defines the angle (in radians) to use
|
|
5196
5294
|
* @param result defines the target matrix
|
|
5295
|
+
* @returns result input
|
|
5197
5296
|
*/
|
|
5198
5297
|
static RotationZToRef(angle, result) {
|
|
5199
5298
|
const s = Math.sin(angle);
|
|
5200
5299
|
const c = Math.cos(angle);
|
|
5201
5300
|
Matrix.FromValuesToRef(c, s, 0.0, 0.0, -s, c, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, result);
|
|
5202
5301
|
result._updateIdentityStatus(c === 1 && s === 0);
|
|
5302
|
+
return result;
|
|
5203
5303
|
}
|
|
5204
5304
|
/**
|
|
5205
5305
|
* Creates a new rotation matrix for "angle" radians around the given axis
|
|
@@ -5217,6 +5317,7 @@ export class Matrix {
|
|
|
5217
5317
|
* @param axis defines the axis to use
|
|
5218
5318
|
* @param angle defines the angle (in radians) to use
|
|
5219
5319
|
* @param result defines the target matrix
|
|
5320
|
+
* @returns result input
|
|
5220
5321
|
*/
|
|
5221
5322
|
static RotationAxisToRef(axis, angle, result) {
|
|
5222
5323
|
const s = Math.sin(-angle);
|
|
@@ -5241,6 +5342,7 @@ export class Matrix {
|
|
|
5241
5342
|
m[14] = 0.0;
|
|
5242
5343
|
m[15] = 1.0;
|
|
5243
5344
|
result.markAsUpdated();
|
|
5345
|
+
return result;
|
|
5244
5346
|
}
|
|
5245
5347
|
/**
|
|
5246
5348
|
* Takes normalised vectors and returns a rotation matrix to align "from" with "to".
|
|
@@ -5248,6 +5350,7 @@ export class Matrix {
|
|
|
5248
5350
|
* @param from defines the vector to align
|
|
5249
5351
|
* @param to defines the vector to align to
|
|
5250
5352
|
* @param result defines the target matrix
|
|
5353
|
+
* @returns result input
|
|
5251
5354
|
*/
|
|
5252
5355
|
static RotationAlignToRef(from, to, result) {
|
|
5253
5356
|
const c = Vector3.Dot(to, from);
|
|
@@ -5289,6 +5392,7 @@ export class Matrix {
|
|
|
5289
5392
|
m[14] = 0;
|
|
5290
5393
|
m[15] = 1;
|
|
5291
5394
|
result.markAsUpdated();
|
|
5395
|
+
return result;
|
|
5292
5396
|
}
|
|
5293
5397
|
/**
|
|
5294
5398
|
* Creates a rotation matrix
|
|
@@ -5308,10 +5412,12 @@ export class Matrix {
|
|
|
5308
5412
|
* @param pitch defines the pitch angle in radians (X axis)
|
|
5309
5413
|
* @param roll defines the roll angle in radians (Z axis)
|
|
5310
5414
|
* @param result defines the target matrix
|
|
5415
|
+
* @returns result input
|
|
5311
5416
|
*/
|
|
5312
5417
|
static RotationYawPitchRollToRef(yaw, pitch, roll, result) {
|
|
5313
5418
|
Quaternion.RotationYawPitchRollToRef(yaw, pitch, roll, MathTmp.Quaternion[0]);
|
|
5314
5419
|
MathTmp.Quaternion[0].toRotationMatrix(result);
|
|
5420
|
+
return result;
|
|
5315
5421
|
}
|
|
5316
5422
|
/**
|
|
5317
5423
|
* Creates a scaling matrix
|
|
@@ -5331,10 +5437,12 @@ export class Matrix {
|
|
|
5331
5437
|
* @param y defines the scale factor on Y axis
|
|
5332
5438
|
* @param z defines the scale factor on Z axis
|
|
5333
5439
|
* @param result defines the target matrix
|
|
5440
|
+
* @returns result input
|
|
5334
5441
|
*/
|
|
5335
5442
|
static ScalingToRef(x, y, z, result) {
|
|
5336
5443
|
Matrix.FromValuesToRef(x, 0.0, 0.0, 0.0, 0.0, y, 0.0, 0.0, 0.0, 0.0, z, 0.0, 0.0, 0.0, 0.0, 1.0, result);
|
|
5337
5444
|
result._updateIdentityStatus(x === 1 && y === 1 && z === 1);
|
|
5445
|
+
return result;
|
|
5338
5446
|
}
|
|
5339
5447
|
/**
|
|
5340
5448
|
* Creates a translation matrix
|
|
@@ -5354,10 +5462,12 @@ export class Matrix {
|
|
|
5354
5462
|
* @param y defines the translation on Y axis
|
|
5355
5463
|
* @param z defines the translationon Z axis
|
|
5356
5464
|
* @param result defines the target matrix
|
|
5465
|
+
* @returns result input
|
|
5357
5466
|
*/
|
|
5358
5467
|
static TranslationToRef(x, y, z, result) {
|
|
5359
5468
|
Matrix.FromValuesToRef(1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, x, y, z, 1.0, result);
|
|
5360
5469
|
result._updateIdentityStatus(x === 0 && y === 0 && z === 0);
|
|
5470
|
+
return result;
|
|
5361
5471
|
}
|
|
5362
5472
|
/**
|
|
5363
5473
|
* Returns a new Matrix whose values are the interpolated values for "gradient" (float) between the ones of the matrices "startValue" and "endValue".
|
|
@@ -5367,7 +5477,7 @@ export class Matrix {
|
|
|
5367
5477
|
* @returns the new matrix
|
|
5368
5478
|
*/
|
|
5369
5479
|
static Lerp(startValue, endValue, gradient) {
|
|
5370
|
-
const result = new
|
|
5480
|
+
const result = new startValue.constructor();
|
|
5371
5481
|
Matrix.LerpToRef(startValue, endValue, gradient, result);
|
|
5372
5482
|
return result;
|
|
5373
5483
|
}
|
|
@@ -5377,6 +5487,7 @@ export class Matrix {
|
|
|
5377
5487
|
* @param endValue defines the end value
|
|
5378
5488
|
* @param gradient defines the gradient factor
|
|
5379
5489
|
* @param result defines the Matrix object where to store data
|
|
5490
|
+
* @returns result input
|
|
5380
5491
|
*/
|
|
5381
5492
|
static LerpToRef(startValue, endValue, gradient, result) {
|
|
5382
5493
|
const resultM = result._m;
|
|
@@ -5386,6 +5497,7 @@ export class Matrix {
|
|
|
5386
5497
|
resultM[index] = startM[index] * (1.0 - gradient) + endM[index] * gradient;
|
|
5387
5498
|
}
|
|
5388
5499
|
result.markAsUpdated();
|
|
5500
|
+
return result;
|
|
5389
5501
|
}
|
|
5390
5502
|
/**
|
|
5391
5503
|
* Builds a new matrix whose values are computed by:
|
|
@@ -5398,7 +5510,7 @@ export class Matrix {
|
|
|
5398
5510
|
* @returns the new matrix
|
|
5399
5511
|
*/
|
|
5400
5512
|
static DecomposeLerp(startValue, endValue, gradient) {
|
|
5401
|
-
const result = new
|
|
5513
|
+
const result = new startValue.constructor();
|
|
5402
5514
|
Matrix.DecomposeLerpToRef(startValue, endValue, gradient, result);
|
|
5403
5515
|
return result;
|
|
5404
5516
|
}
|
|
@@ -5411,6 +5523,7 @@ export class Matrix {
|
|
|
5411
5523
|
* @param endValue defines the second matrix
|
|
5412
5524
|
* @param gradient defines the gradient between the two matrices
|
|
5413
5525
|
* @param result defines the target matrix
|
|
5526
|
+
* @returns result input
|
|
5414
5527
|
*/
|
|
5415
5528
|
static DecomposeLerpToRef(startValue, endValue, gradient, result) {
|
|
5416
5529
|
const startScale = MathTmp.Vector3[0];
|
|
@@ -5428,6 +5541,7 @@ export class Matrix {
|
|
|
5428
5541
|
const resultTranslation = MathTmp.Vector3[5];
|
|
5429
5542
|
Vector3.LerpToRef(startTranslation, endTranslation, gradient, resultTranslation);
|
|
5430
5543
|
Matrix.ComposeToRef(resultScale, resultRotation, resultTranslation, result);
|
|
5544
|
+
return result;
|
|
5431
5545
|
}
|
|
5432
5546
|
/**
|
|
5433
5547
|
* Gets a new rotation matrix used to rotate an entity so as it looks at the target vector3, from the eye vector3 position, the up vector3 being oriented like "up"
|
|
@@ -5449,6 +5563,7 @@ export class Matrix {
|
|
|
5449
5563
|
* @param target defines where the entity should look at
|
|
5450
5564
|
* @param up defines the up vector for the entity
|
|
5451
5565
|
* @param result defines the target matrix
|
|
5566
|
+
* @returns result input
|
|
5452
5567
|
*/
|
|
5453
5568
|
static LookAtLHToRef(eye, target, up, result) {
|
|
5454
5569
|
const xAxis = MathTmp.Vector3[0];
|
|
@@ -5495,6 +5610,7 @@ export class Matrix {
|
|
|
5495
5610
|
* @param target defines where the entity should look at
|
|
5496
5611
|
* @param up defines the up vector for the entity
|
|
5497
5612
|
* @param result defines the target matrix
|
|
5613
|
+
* @returns result input
|
|
5498
5614
|
*/
|
|
5499
5615
|
static LookAtRHToRef(eye, target, up, result) {
|
|
5500
5616
|
const xAxis = MathTmp.Vector3[0];
|
|
@@ -5520,6 +5636,7 @@ export class Matrix {
|
|
|
5520
5636
|
const ey = -Vector3.Dot(yAxis, eye);
|
|
5521
5637
|
const ez = -Vector3.Dot(zAxis, eye);
|
|
5522
5638
|
Matrix.FromValuesToRef(xAxis._x, yAxis._x, zAxis._x, 0.0, xAxis._y, yAxis._y, zAxis._y, 0.0, xAxis._z, yAxis._z, zAxis._z, 0.0, ex, ey, ez, 1.0, result);
|
|
5639
|
+
return result;
|
|
5523
5640
|
}
|
|
5524
5641
|
/**
|
|
5525
5642
|
* Gets a new rotation matrix used to rotate an entity so as it looks in the direction specified by forward from the eye position, the up direction being oriented like "up".
|
|
@@ -5539,6 +5656,7 @@ export class Matrix {
|
|
|
5539
5656
|
* @param forward defines the forward direction - Must be normalized and orthogonal to up.
|
|
5540
5657
|
* @param up defines the up vector for the entity - Must be normalized and orthogonal to forward.
|
|
5541
5658
|
* @param result defines the target matrix
|
|
5659
|
+
* @returns result input
|
|
5542
5660
|
*/
|
|
5543
5661
|
static LookDirectionLHToRef(forward, up, result) {
|
|
5544
5662
|
const back = MathTmp.Vector3[0];
|
|
@@ -5548,6 +5666,7 @@ export class Matrix {
|
|
|
5548
5666
|
Vector3.CrossToRef(up, back, left);
|
|
5549
5667
|
// Generate the rotation matrix.
|
|
5550
5668
|
Matrix.FromValuesToRef(left._x, left._y, left._z, 0.0, up._x, up._y, up._z, 0.0, back._x, back._y, back._z, 0.0, 0, 0, 0, 1.0, result);
|
|
5669
|
+
return result;
|
|
5551
5670
|
}
|
|
5552
5671
|
/**
|
|
5553
5672
|
* Gets a new rotation matrix used to rotate an entity so as it looks in the direction specified by forward from the eye position, the up Vector3 being oriented like "up".
|
|
@@ -5567,12 +5686,14 @@ export class Matrix {
|
|
|
5567
5686
|
* @param forward defines the forward direction - Must be normalized and orthogonal to up.
|
|
5568
5687
|
* @param up defines the up vector for the entity - Must be normalized and orthogonal to forward.
|
|
5569
5688
|
* @param result defines the target matrix
|
|
5689
|
+
* @returns result input
|
|
5570
5690
|
*/
|
|
5571
5691
|
static LookDirectionRHToRef(forward, up, result) {
|
|
5572
5692
|
const right = MathTmp.Vector3[2];
|
|
5573
5693
|
Vector3.CrossToRef(up, forward, right);
|
|
5574
5694
|
// Generate the rotation matrix.
|
|
5575
5695
|
Matrix.FromValuesToRef(right._x, right._y, right._z, 0.0, up._x, up._y, up._z, 0.0, forward._x, forward._y, forward._z, 0.0, 0, 0, 0, 1.0, result);
|
|
5696
|
+
return result;
|
|
5576
5697
|
}
|
|
5577
5698
|
/**
|
|
5578
5699
|
* Create a left-handed orthographic projection matrix
|
|
@@ -5596,6 +5717,7 @@ export class Matrix {
|
|
|
5596
5717
|
* @param zfar defines the far clip plane
|
|
5597
5718
|
* @param result defines the target matrix
|
|
5598
5719
|
* @param halfZRange true to generate NDC coordinates between 0 and 1 instead of -1 and 1 (default: false)
|
|
5720
|
+
* @returns result input
|
|
5599
5721
|
*/
|
|
5600
5722
|
static OrthoLHToRef(width, height, znear, zfar, result, halfZRange) {
|
|
5601
5723
|
const n = znear;
|
|
@@ -5609,6 +5731,7 @@ export class Matrix {
|
|
|
5609
5731
|
result.multiplyToRef(mtxConvertNDCToHalfZRange, result);
|
|
5610
5732
|
}
|
|
5611
5733
|
result._updateIdentityStatus(a === 1 && b === 1 && c === 1 && d === 0);
|
|
5734
|
+
return result;
|
|
5612
5735
|
}
|
|
5613
5736
|
/**
|
|
5614
5737
|
* Create a left-handed orthographic projection matrix
|
|
@@ -5636,6 +5759,7 @@ export class Matrix {
|
|
|
5636
5759
|
* @param zfar defines the far clip plane
|
|
5637
5760
|
* @param result defines the target matrix
|
|
5638
5761
|
* @param halfZRange true to generate NDC coordinates between 0 and 1 instead of -1 and 1 (default: false)
|
|
5762
|
+
* @returns result input
|
|
5639
5763
|
*/
|
|
5640
5764
|
static OrthoOffCenterLHToRef(left, right, bottom, top, znear, zfar, result, halfZRange) {
|
|
5641
5765
|
const n = znear;
|
|
@@ -5651,6 +5775,7 @@ export class Matrix {
|
|
|
5651
5775
|
result.multiplyToRef(mtxConvertNDCToHalfZRange, result);
|
|
5652
5776
|
}
|
|
5653
5777
|
result.markAsUpdated();
|
|
5778
|
+
return result;
|
|
5654
5779
|
}
|
|
5655
5780
|
/**
|
|
5656
5781
|
* Creates a right-handed orthographic projection matrix
|
|
@@ -5678,10 +5803,12 @@ export class Matrix {
|
|
|
5678
5803
|
* @param zfar defines the far clip plane
|
|
5679
5804
|
* @param result defines the target matrix
|
|
5680
5805
|
* @param halfZRange true to generate NDC coordinates between 0 and 1 instead of -1 and 1 (default: false)
|
|
5806
|
+
* @returns result input
|
|
5681
5807
|
*/
|
|
5682
5808
|
static OrthoOffCenterRHToRef(left, right, bottom, top, znear, zfar, result, halfZRange) {
|
|
5683
5809
|
Matrix.OrthoOffCenterLHToRef(left, right, bottom, top, znear, zfar, result, halfZRange);
|
|
5684
5810
|
result._m[10] *= -1; // No need to call markAsUpdated as previous function already called it and let _isIdentityDirty to true
|
|
5811
|
+
return result;
|
|
5685
5812
|
}
|
|
5686
5813
|
/**
|
|
5687
5814
|
* Creates a left-handed perspective projection matrix
|
|
@@ -5736,6 +5863,7 @@ export class Matrix {
|
|
|
5736
5863
|
* @param halfZRange true to generate NDC coordinates between 0 and 1 instead of -1 and 1 (default: false)
|
|
5737
5864
|
* @param projectionPlaneTilt optional tilt angle of the projection plane around the X axis (horizontal)
|
|
5738
5865
|
* @param reverseDepthBufferMode true to indicate that we are in a reverse depth buffer mode (meaning znear and zfar have been inverted when calling the function)
|
|
5866
|
+
* @returns result input
|
|
5739
5867
|
*/
|
|
5740
5868
|
static PerspectiveFovLHToRef(fov, aspect, znear, zfar, result, isVerticalFovFixed = true, halfZRange, projectionPlaneTilt = 0, reverseDepthBufferMode = false) {
|
|
5741
5869
|
const n = znear;
|
|
@@ -5751,6 +5879,7 @@ export class Matrix {
|
|
|
5751
5879
|
result.multiplyToRef(mtxConvertNDCToHalfZRange, result);
|
|
5752
5880
|
}
|
|
5753
5881
|
result._updateIdentityStatus(false);
|
|
5882
|
+
return result;
|
|
5754
5883
|
}
|
|
5755
5884
|
/**
|
|
5756
5885
|
* Stores a left-handed perspective projection into a given matrix with depth reversed
|
|
@@ -5762,6 +5891,7 @@ export class Matrix {
|
|
|
5762
5891
|
* @param isVerticalFovFixed defines it the fov is vertically fixed (default) or horizontally
|
|
5763
5892
|
* @param halfZRange true to generate NDC coordinates between 0 and 1 instead of -1 and 1 (default: false)
|
|
5764
5893
|
* @param projectionPlaneTilt optional tilt angle of the projection plane around the X axis (horizontal)
|
|
5894
|
+
* @returns result input
|
|
5765
5895
|
*/
|
|
5766
5896
|
static PerspectiveFovReverseLHToRef(fov, aspect, znear, zfar, result, isVerticalFovFixed = true, halfZRange, projectionPlaneTilt = 0) {
|
|
5767
5897
|
const t = 1.0 / Math.tan(fov * 0.5);
|
|
@@ -5773,6 +5903,7 @@ export class Matrix {
|
|
|
5773
5903
|
result.multiplyToRef(mtxConvertNDCToHalfZRange, result);
|
|
5774
5904
|
}
|
|
5775
5905
|
result._updateIdentityStatus(false);
|
|
5906
|
+
return result;
|
|
5776
5907
|
}
|
|
5777
5908
|
/**
|
|
5778
5909
|
* Creates a right-handed perspective projection matrix
|
|
@@ -5801,6 +5932,7 @@ export class Matrix {
|
|
|
5801
5932
|
* @param halfZRange true to generate NDC coordinates between 0 and 1 instead of -1 and 1 (default: false)
|
|
5802
5933
|
* @param projectionPlaneTilt optional tilt angle of the projection plane around the X axis (horizontal)
|
|
5803
5934
|
* @param reverseDepthBufferMode true to indicate that we are in a reverse depth buffer mode (meaning znear and zfar have been inverted when calling the function)
|
|
5935
|
+
* @returns result input
|
|
5804
5936
|
*/
|
|
5805
5937
|
static PerspectiveFovRHToRef(fov, aspect, znear, zfar, result, isVerticalFovFixed = true, halfZRange, projectionPlaneTilt = 0, reverseDepthBufferMode = false) {
|
|
5806
5938
|
//alternatively this could be expressed as:
|
|
@@ -5820,6 +5952,7 @@ export class Matrix {
|
|
|
5820
5952
|
result.multiplyToRef(mtxConvertNDCToHalfZRange, result);
|
|
5821
5953
|
}
|
|
5822
5954
|
result._updateIdentityStatus(false);
|
|
5955
|
+
return result;
|
|
5823
5956
|
}
|
|
5824
5957
|
/**
|
|
5825
5958
|
* Stores a right-handed perspective projection into a given matrix
|
|
@@ -5831,6 +5964,7 @@ export class Matrix {
|
|
|
5831
5964
|
* @param isVerticalFovFixed defines it the fov is vertically fixed (default) or horizontally
|
|
5832
5965
|
* @param halfZRange true to generate NDC coordinates between 0 and 1 instead of -1 and 1 (default: false)
|
|
5833
5966
|
* @param projectionPlaneTilt optional tilt angle of the projection plane around the X axis (horizontal)
|
|
5967
|
+
* @returns result input
|
|
5834
5968
|
*/
|
|
5835
5969
|
static PerspectiveFovReverseRHToRef(fov, aspect, znear, zfar, result, isVerticalFovFixed = true, halfZRange, projectionPlaneTilt = 0) {
|
|
5836
5970
|
const t = 1.0 / Math.tan(fov * 0.5);
|
|
@@ -5842,6 +5976,7 @@ export class Matrix {
|
|
|
5842
5976
|
result.multiplyToRef(mtxConvertNDCToHalfZRange, result);
|
|
5843
5977
|
}
|
|
5844
5978
|
result._updateIdentityStatus(false);
|
|
5979
|
+
return result;
|
|
5845
5980
|
}
|
|
5846
5981
|
/**
|
|
5847
5982
|
* Stores a perspective projection for WebVR info a given matrix
|
|
@@ -5856,6 +5991,7 @@ export class Matrix {
|
|
|
5856
5991
|
* @param rightHanded defines if the matrix must be in right-handed mode (false by default)
|
|
5857
5992
|
* @param halfZRange true to generate NDC coordinates between 0 and 1 instead of -1 and 1 (default: false)
|
|
5858
5993
|
* @param projectionPlaneTilt optional tilt angle of the projection plane around the X axis (horizontal)
|
|
5994
|
+
* @returns result input
|
|
5859
5995
|
*/
|
|
5860
5996
|
static PerspectiveFovWebVRToRef(fov, znear, zfar, result, rightHanded = false, halfZRange, projectionPlaneTilt = 0) {
|
|
5861
5997
|
const rightHandedFactor = rightHanded ? -1 : 1;
|
|
@@ -5882,6 +6018,7 @@ export class Matrix {
|
|
|
5882
6018
|
result.multiplyToRef(mtxConvertNDCToHalfZRange, result);
|
|
5883
6019
|
}
|
|
5884
6020
|
result.markAsUpdated();
|
|
6021
|
+
return result;
|
|
5885
6022
|
}
|
|
5886
6023
|
/**
|
|
5887
6024
|
* Computes a complete transformation matrix
|
|
@@ -5899,10 +6036,10 @@ export class Matrix {
|
|
|
5899
6036
|
const cx = viewport.x;
|
|
5900
6037
|
const cy = viewport.y;
|
|
5901
6038
|
const viewportMatrix = Matrix.FromValues(cw / 2.0, 0.0, 0.0, 0.0, 0.0, -ch / 2.0, 0.0, 0.0, 0.0, 0.0, zmax - zmin, 0.0, cx + cw / 2.0, ch / 2.0 + cy, zmin, 1.0);
|
|
5902
|
-
const matrix =
|
|
6039
|
+
const matrix = new world.constructor();
|
|
5903
6040
|
world.multiplyToRef(view, matrix);
|
|
5904
6041
|
matrix.multiplyToRef(projection, matrix);
|
|
5905
|
-
return matrix.
|
|
6042
|
+
return matrix.multiplyToRef(viewportMatrix, matrix);
|
|
5906
6043
|
}
|
|
5907
6044
|
/**
|
|
5908
6045
|
* Extracts a 2x2 matrix from a given matrix and store the result in a Float32Array
|
|
@@ -5930,7 +6067,7 @@ export class Matrix {
|
|
|
5930
6067
|
* @returns the new matrix
|
|
5931
6068
|
*/
|
|
5932
6069
|
static Transpose(matrix) {
|
|
5933
|
-
const result = new
|
|
6070
|
+
const result = new matrix.constructor();
|
|
5934
6071
|
Matrix.TransposeToRef(matrix, result);
|
|
5935
6072
|
return result;
|
|
5936
6073
|
}
|
|
@@ -5938,6 +6075,7 @@ export class Matrix {
|
|
|
5938
6075
|
* Compute the transpose of a matrix and store it in a target matrix
|
|
5939
6076
|
* @param matrix defines the matrix to transpose
|
|
5940
6077
|
* @param result defines the target matrix
|
|
6078
|
+
* @returns result input
|
|
5941
6079
|
*/
|
|
5942
6080
|
static TransposeToRef(matrix, result) {
|
|
5943
6081
|
const rm = result._m;
|
|
@@ -5961,6 +6099,7 @@ export class Matrix {
|
|
|
5961
6099
|
result.markAsUpdated();
|
|
5962
6100
|
// identity-ness does not change when transposing
|
|
5963
6101
|
result._updateIdentityStatus(matrix._isIdentity, matrix._isIdentityDirty);
|
|
6102
|
+
return result;
|
|
5964
6103
|
}
|
|
5965
6104
|
/**
|
|
5966
6105
|
* Computes a reflection matrix from a plane
|
|
@@ -5976,6 +6115,7 @@ export class Matrix {
|
|
|
5976
6115
|
* Computes a reflection matrix from a plane
|
|
5977
6116
|
* @param plane defines the reflection plane
|
|
5978
6117
|
* @param result defines the target matrix
|
|
6118
|
+
* @returns result input
|
|
5979
6119
|
*/
|
|
5980
6120
|
static ReflectionToRef(plane, result) {
|
|
5981
6121
|
plane.normalize();
|
|
@@ -5986,6 +6126,7 @@ export class Matrix {
|
|
|
5986
6126
|
const temp2 = -2 * y;
|
|
5987
6127
|
const temp3 = -2 * z;
|
|
5988
6128
|
Matrix.FromValuesToRef(temp * x + 1, temp2 * x, temp3 * x, 0.0, temp * y, temp2 * y + 1, temp3 * y, 0.0, temp * z, temp2 * z, temp3 * z + 1, 0.0, temp * plane.d, temp2 * plane.d, temp3 * plane.d, 1.0, result);
|
|
6129
|
+
return result;
|
|
5989
6130
|
}
|
|
5990
6131
|
/**
|
|
5991
6132
|
* Sets the given matrix as a rotation matrix composed from the 3 left handed axes
|
|
@@ -5993,14 +6134,17 @@ export class Matrix {
|
|
|
5993
6134
|
* @param yaxis defines the value of the 2nd axis
|
|
5994
6135
|
* @param zaxis defines the value of the 3rd axis
|
|
5995
6136
|
* @param result defines the target matrix
|
|
6137
|
+
* @returns result input
|
|
5996
6138
|
*/
|
|
5997
6139
|
static FromXYZAxesToRef(xaxis, yaxis, zaxis, result) {
|
|
5998
6140
|
Matrix.FromValuesToRef(xaxis._x, xaxis._y, xaxis._z, 0.0, yaxis._x, yaxis._y, yaxis._z, 0.0, zaxis._x, zaxis._y, zaxis._z, 0.0, 0.0, 0.0, 0.0, 1.0, result);
|
|
6141
|
+
return result;
|
|
5999
6142
|
}
|
|
6000
6143
|
/**
|
|
6001
6144
|
* Creates a rotation matrix from a quaternion and stores it in a target matrix
|
|
6002
6145
|
* @param quat defines the quaternion to use
|
|
6003
6146
|
* @param result defines the target matrix
|
|
6147
|
+
* @returns result input
|
|
6004
6148
|
*/
|
|
6005
6149
|
static FromQuaternionToRef(quat, result) {
|
|
6006
6150
|
const xx = quat._x * quat._x;
|
|
@@ -6029,6 +6173,7 @@ export class Matrix {
|
|
|
6029
6173
|
result._m[14] = 0.0;
|
|
6030
6174
|
result._m[15] = 1.0;
|
|
6031
6175
|
result.markAsUpdated();
|
|
6176
|
+
return result;
|
|
6032
6177
|
}
|
|
6033
6178
|
}
|
|
6034
6179
|
Matrix._UpdateFlagSeed = 0;
|