@babylonjs/core 5.28.0 → 5.30.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.
Files changed (154) hide show
  1. package/Actions/actionManager.js +2 -0
  2. package/Actions/actionManager.js.map +1 -1
  3. package/Cameras/camera.js +4 -4
  4. package/Cameras/camera.js.map +1 -1
  5. package/Collisions/pickingInfo.d.ts +1 -2
  6. package/Collisions/pickingInfo.js +7 -4
  7. package/Collisions/pickingInfo.js.map +1 -1
  8. package/Culling/ray.d.ts +1 -1
  9. package/Culling/ray.js +5 -6
  10. package/Culling/ray.js.map +1 -1
  11. package/Debug/debugLayer.d.ts +5 -0
  12. package/Debug/debugLayer.js.map +1 -1
  13. package/Engines/Extensions/engine.renderTarget.js +5 -1
  14. package/Engines/Extensions/engine.renderTarget.js.map +1 -1
  15. package/Engines/Extensions/engine.videoTexture.js +6 -3
  16. package/Engines/Extensions/engine.videoTexture.js.map +1 -1
  17. package/Engines/WebGPU/Extensions/engine.renderTarget.js +4 -1
  18. package/Engines/WebGPU/Extensions/engine.renderTarget.js.map +1 -1
  19. package/Engines/WebGPU/webgpuCacheRenderPipeline.js +2 -0
  20. package/Engines/WebGPU/webgpuCacheRenderPipeline.js.map +1 -1
  21. package/Engines/WebGPU/webgpuShaderProcessor.js +3 -7
  22. package/Engines/WebGPU/webgpuShaderProcessor.js.map +1 -1
  23. package/Engines/WebGPU/webgpuTextureHelper.js +2 -0
  24. package/Engines/WebGPU/webgpuTextureHelper.js.map +1 -1
  25. package/Engines/WebGPU/webgpuTintWASM.d.ts +1 -0
  26. package/Engines/WebGPU/webgpuTintWASM.js +7 -1
  27. package/Engines/WebGPU/webgpuTintWASM.js.map +1 -1
  28. package/Engines/constants.d.ts +4 -0
  29. package/Engines/constants.js +4 -0
  30. package/Engines/constants.js.map +1 -1
  31. package/Engines/engine.d.ts +45 -12
  32. package/Engines/renderTargetWrapper.d.ts +2 -1
  33. package/Engines/renderTargetWrapper.js +1 -0
  34. package/Engines/renderTargetWrapper.js.map +1 -1
  35. package/Engines/thinEngine.js +6 -3
  36. package/Engines/thinEngine.js.map +1 -1
  37. package/Engines/webgpuEngine.d.ts +0 -2
  38. package/Engines/webgpuEngine.js +15 -14
  39. package/Engines/webgpuEngine.js.map +1 -1
  40. package/Events/pointerEvents.d.ts +11 -6
  41. package/Events/pointerEvents.js +24 -6
  42. package/Events/pointerEvents.js.map +1 -1
  43. package/IAccessibilityTag.d.ts +29 -0
  44. package/IAccessibilityTag.js +2 -0
  45. package/IAccessibilityTag.js.map +1 -0
  46. package/Inputs/scene.inputManager.d.ts +9 -1
  47. package/Inputs/scene.inputManager.js +83 -37
  48. package/Inputs/scene.inputManager.js.map +1 -1
  49. package/Layers/effectLayer.js +2 -6
  50. package/Layers/effectLayer.js.map +1 -1
  51. package/Materials/Node/Blocks/Fragment/heightToNormalBlock.d.ts +24 -3
  52. package/Materials/Node/Blocks/Fragment/heightToNormalBlock.js +92 -21
  53. package/Materials/Node/Blocks/Fragment/heightToNormalBlock.js.map +1 -1
  54. package/Materials/PBR/pbrMetallicRoughnessMaterial.d.ts +1 -1
  55. package/Materials/PBR/pbrMetallicRoughnessMaterial.js +1 -1
  56. package/Materials/PBR/pbrMetallicRoughnessMaterial.js.map +1 -1
  57. package/Materials/Textures/htmlElementTexture.d.ts +5 -0
  58. package/Materials/Textures/htmlElementTexture.js +4 -1
  59. package/Materials/Textures/htmlElementTexture.js.map +1 -1
  60. package/Materials/Textures/renderTargetTexture.d.ts +1 -1
  61. package/Materials/Textures/renderTargetTexture.js +2 -2
  62. package/Materials/Textures/renderTargetTexture.js.map +1 -1
  63. package/Materials/Textures/videoTexture.d.ts +6 -1
  64. package/Materials/Textures/videoTexture.js +7 -2
  65. package/Materials/Textures/videoTexture.js.map +1 -1
  66. package/Maths/math.vector.d.ts +460 -337
  67. package/Maths/math.vector.js +370 -184
  68. package/Maths/math.vector.js.map +1 -1
  69. package/Meshes/Builders/decalBuilder.d.ts +8 -0
  70. package/Meshes/Builders/decalBuilder.js +270 -51
  71. package/Meshes/Builders/decalBuilder.js.map +1 -1
  72. package/Meshes/mesh.d.ts +1 -1
  73. package/Meshes/mesh.js +42 -1
  74. package/Meshes/mesh.js.map +1 -1
  75. package/Misc/PerformanceViewer/performanceViewerCollectionStrategies.d.ts +17 -4
  76. package/Misc/PerformanceViewer/performanceViewerCollectionStrategies.js +49 -9
  77. package/Misc/PerformanceViewer/performanceViewerCollectionStrategies.js.map +1 -1
  78. package/Misc/iInspectable.d.ts +5 -1
  79. package/Misc/iInspectable.js +4 -0
  80. package/Misc/iInspectable.js.map +1 -1
  81. package/Misc/index.d.ts +1 -1
  82. package/Misc/index.js +1 -1
  83. package/Misc/index.js.map +1 -1
  84. package/Misc/khronosTextureContainer2.js +41 -46
  85. package/Misc/khronosTextureContainer2.js.map +1 -1
  86. package/Misc/observable.js +4 -4
  87. package/Misc/observable.js.map +1 -1
  88. package/Misc/pressureObserverWrapper.d.ts +36 -0
  89. package/Misc/pressureObserverWrapper.js +68 -0
  90. package/Misc/pressureObserverWrapper.js.map +1 -0
  91. package/Misc/screenshotTools.js +0 -1
  92. package/Misc/screenshotTools.js.map +1 -1
  93. package/Particles/particleSystem.d.ts +4 -0
  94. package/Particles/particleSystem.js +12 -4
  95. package/Particles/particleSystem.js.map +1 -1
  96. package/PostProcesses/RenderPipeline/Pipelines/defaultRenderingPipeline.d.ts +14 -8
  97. package/PostProcesses/RenderPipeline/Pipelines/defaultRenderingPipeline.js +16 -6
  98. package/PostProcesses/RenderPipeline/Pipelines/defaultRenderingPipeline.js.map +1 -1
  99. package/PostProcesses/blurPostProcess.d.ts +2 -1
  100. package/PostProcesses/blurPostProcess.js +3 -2
  101. package/PostProcesses/blurPostProcess.js.map +1 -1
  102. package/PostProcesses/circleOfConfusionPostProcess.js +2 -1
  103. package/PostProcesses/circleOfConfusionPostProcess.js.map +1 -1
  104. package/PostProcesses/depthOfFieldBlurPostProcess.d.ts +2 -1
  105. package/PostProcesses/depthOfFieldBlurPostProcess.js +3 -5
  106. package/PostProcesses/depthOfFieldBlurPostProcess.js.map +1 -1
  107. package/PostProcesses/depthOfFieldEffect.js +9 -4
  108. package/PostProcesses/depthOfFieldEffect.js.map +1 -1
  109. package/PostProcesses/depthOfFieldMergePostProcess.js.map +1 -1
  110. package/PostProcesses/postProcess.js +4 -4
  111. package/PostProcesses/postProcess.js.map +1 -1
  112. package/PostProcesses/volumetricLightScatteringPostProcess.js +2 -6
  113. package/PostProcesses/volumetricLightScatteringPostProcess.js.map +1 -1
  114. package/Rendering/depthPeelingRenderer.js +4 -0
  115. package/Rendering/depthPeelingRenderer.js.map +1 -1
  116. package/Rendering/depthRenderer.js +2 -6
  117. package/Rendering/depthRenderer.js.map +1 -1
  118. package/Rendering/geometryBufferRenderer.js +2 -6
  119. package/Rendering/geometryBufferRenderer.js.map +1 -1
  120. package/Rendering/renderingGroup.d.ts +4 -0
  121. package/Rendering/renderingGroup.js +7 -1
  122. package/Rendering/renderingGroup.js.map +1 -1
  123. package/Rendering/renderingManager.d.ts +8 -0
  124. package/Rendering/renderingManager.js +18 -0
  125. package/Rendering/renderingManager.js.map +1 -1
  126. package/Shaders/ShadersInclude/shadowsFragmentFunctions.js +18 -13
  127. package/Shaders/ShadersInclude/shadowsFragmentFunctions.js.map +1 -1
  128. package/Shaders/circleOfConfusion.fragment.js +1 -1
  129. package/Shaders/circleOfConfusion.fragment.js.map +1 -1
  130. package/Shaders/depthOfFieldMerge.fragment.js +1 -1
  131. package/Shaders/depthOfFieldMerge.fragment.js.map +1 -1
  132. package/Shaders/fxaa.fragment.js +10 -5
  133. package/Shaders/fxaa.fragment.js.map +1 -1
  134. package/Shaders/kernelBlur.fragment.js +2 -2
  135. package/Shaders/kernelBlur.fragment.js.map +1 -1
  136. package/Shaders/particles.vertex.js +4 -1
  137. package/Shaders/particles.vertex.js.map +1 -1
  138. package/Shaders/spriteMap.fragment.js +7 -2
  139. package/Shaders/spriteMap.fragment.js.map +1 -1
  140. package/XR/features/WebXRControllerPointerSelection.js +1 -0
  141. package/XR/features/WebXRControllerPointerSelection.js.map +1 -1
  142. package/XR/features/WebXRNearInteraction.js.map +1 -1
  143. package/XR/webXRRenderTargetTextureProvider.js +1 -0
  144. package/XR/webXRRenderTargetTextureProvider.js.map +1 -1
  145. package/node.d.ts +8 -0
  146. package/node.js +13 -1
  147. package/node.js.map +1 -1
  148. package/package.json +1 -1
  149. package/scene.d.ts +6 -8
  150. package/scene.js +11 -30
  151. package/scene.js.map +1 -1
  152. package/Misc/computePressure.d.ts +0 -57
  153. package/Misc/computePressure.js +0 -48
  154. package/Misc/computePressure.js.map +0 -1
@@ -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 Vector3
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 Vector2(this.x + otherVector.x, this.y + otherVector.y);
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 the unmodified current Vector2
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 this;
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 Vector2(this.x + otherVector.x, this.y + otherVector.y);
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 Vector2(this.x - otherVector.x, this.y - otherVector.y);
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 the unmodified current Vector2
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 this;
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 Vector2(this.x * otherVector.x, this.y * otherVector.y);
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 the unmodified current Vector2
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 this;
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 Vector2(this.x * x, this.y * y);
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 Vector2(this.x / otherVector.x, this.y / otherVector.y);
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 the unmodified current Vector2
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 this;
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 Vector2(-this.x, -this.y);
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 Vector2(0, 0);
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 the unmodified current Vector2
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 this;
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 the unmodified current Vector2
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 this;
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 Vector2(Math.floor(this.x), Math.floor(this.y));
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 Vector2(this.x - Math.floor(this.x), this.y - Math.floor(this.y));
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 the current vector
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 this;
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 Vector2(this.x, this.y);
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 Vector2(x, y);
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 Vector2(x, y);
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 Vector2(x, y);
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 = Vector2.Zero();
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 Vector2(x, y);
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 = Vector2.Zero();
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 Vector2(x, y);
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 Vector2(x, y);
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 r = Vector2.Zero();
642
- Vector2.TransformToRef(vector, transformation, r);
643
- return r;
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
- return Vector2.CenterToRef(value1, value2, Vector2.Zero());
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 Vector3(this._x + otherVector._x, this._y + otherVector._y, this._z + otherVector._z);
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 Vector3(this._x - otherVector._x, this._y - otherVector._y, this._z - otherVector._z);
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 Vector3(this._x - x, this._y - y, this._z - z);
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 Vector3(-this._x, -this._y, -this._z);
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 Vector3(this._x * scale, this._y * scale, this._z * scale);
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
@@ -1009,11 +1018,16 @@ export class Vector3 {
1009
1018
  }
1010
1019
  /**
1011
1020
  * Creates a vector normal (perpendicular) to the current Vector3 and stores the result in the given vector
1021
+ * Out of the infinite possibilities the normal chosen is the one formed by rotating the current vector
1022
+ * 90 degrees about an axis which lies perpendicular to the current vector
1023
+ * and its projection on the xz plane. In the case of a current vector in the xz plane
1024
+ * the normal is calculated to be along the y axis.
1025
+ * Example Playground https://playground.babylonjs.com/#R1F8YU#230
1026
+ * Example Playground https://playground.babylonjs.com/#R1F8YU#231
1012
1027
  * @param result defines the Vector3 object where to store the resultant normal
1013
1028
  * returns the result
1014
- * @hidden
1015
1029
  */
1016
- _getNormalToRef(result) {
1030
+ getNormalToRef(result) {
1017
1031
  /**
1018
1032
  * Calculates the spherical coordinates of the current vector
1019
1033
  * so saves on memory rather than importing whole Spherical Class
@@ -1068,14 +1082,14 @@ export class Vector3 {
1068
1082
  * @returns a new Vector3
1069
1083
  */
1070
1084
  applyRotationQuaternion(q) {
1071
- return this.applyRotationQuaternionToRef(q, Vector3.Zero());
1085
+ return this.applyRotationQuaternionToRef(q, new this.constructor());
1072
1086
  }
1073
1087
  /**
1074
1088
  * Scale the current Vector3 values by a factor and add the result to a given Vector3
1075
1089
  * Example Playground https://playground.babylonjs.com/#R1F8YU#55
1076
1090
  * @param scale defines the scale factor
1077
1091
  * @param result defines the Vector3 object where to store the result
1078
- * @returns the unmodified current Vector3
1092
+ * @returns result input
1079
1093
  */
1080
1094
  scaleAndAddToRef(scale, result) {
1081
1095
  return result.addInPlaceFromFloats(this._x * scale, this._y * scale, this._z * scale);
@@ -1088,7 +1102,7 @@ export class Vector3 {
1088
1102
  * @returns the projected vector3
1089
1103
  */
1090
1104
  projectOnPlane(plane, origin) {
1091
- const result = Vector3.Zero();
1105
+ const result = new this.constructor();
1092
1106
  this.projectOnPlaneToRef(plane, origin, result);
1093
1107
  return result;
1094
1108
  }
@@ -1098,6 +1112,7 @@ export class Vector3 {
1098
1112
  * @param plane defines the plane to project to
1099
1113
  * @param origin defines the origin of the projection ray
1100
1114
  * @param result defines the Vector3 where to store the result
1115
+ * @returns result input
1101
1116
  */
1102
1117
  projectOnPlaneToRef(plane, origin, result) {
1103
1118
  const n = plane.normal;
@@ -1117,6 +1132,7 @@ export class Vector3 {
1117
1132
  const scaledV = V.scaleInPlace(t);
1118
1133
  origin.addToRef(scaledV, result);
1119
1134
  }
1135
+ return result;
1120
1136
  }
1121
1137
  /**
1122
1138
  * Returns true if the current Vector3 and the given vector coordinates are strictly equal
@@ -1191,7 +1207,7 @@ export class Vector3 {
1191
1207
  * @returns the new Vector3
1192
1208
  */
1193
1209
  multiplyByFloats(x, y, z) {
1194
- return new Vector3(this._x * x, this._y * y, this._z * z);
1210
+ return new this.constructor(this._x * x, this._y * y, this._z * z);
1195
1211
  }
1196
1212
  /**
1197
1213
  * Returns a new Vector3 set with the result of the division of the current Vector3 coordinates by the given ones
@@ -1200,7 +1216,7 @@ export class Vector3 {
1200
1216
  * @returns the new Vector3
1201
1217
  */
1202
1218
  divide(otherVector) {
1203
- return new Vector3(this._x / otherVector._x, this._y / otherVector._y, this._z / otherVector._z);
1219
+ return new this.constructor(this._x / otherVector._x, this._y / otherVector._y, this._z / otherVector._z);
1204
1220
  }
1205
1221
  /**
1206
1222
  * Divides the current Vector3 coordinates by the given ones and stores the result in the given vector "result"
@@ -1321,7 +1337,7 @@ export class Vector3 {
1321
1337
  * @returns a new Vector3
1322
1338
  */
1323
1339
  floor() {
1324
- return new Vector3(Math.floor(this._x), Math.floor(this._y), Math.floor(this._z));
1340
+ return new this.constructor(Math.floor(this._x), Math.floor(this._y), Math.floor(this._z));
1325
1341
  }
1326
1342
  /**
1327
1343
  * Gets a new Vector3 from current Vector3 fractional values
@@ -1329,7 +1345,7 @@ export class Vector3 {
1329
1345
  * @returns a new Vector3
1330
1346
  */
1331
1347
  fract() {
1332
- return new Vector3(this._x - Math.floor(this._x), this._y - Math.floor(this._y), this._z - Math.floor(this._z));
1348
+ return new this.constructor(this._x - Math.floor(this._x), this._y - Math.floor(this._y), this._z - Math.floor(this._z));
1333
1349
  }
1334
1350
  // Properties
1335
1351
  /**
@@ -1415,7 +1431,8 @@ export class Vector3 {
1415
1431
  * @returns the cross product
1416
1432
  */
1417
1433
  cross(other) {
1418
- return Vector3.Cross(this, other);
1434
+ const result = new this.constructor();
1435
+ return Vector3.CrossToRef(this, other, result);
1419
1436
  }
1420
1437
  /**
1421
1438
  * Normalize the current Vector3 with the given input length.
@@ -1436,7 +1453,7 @@ export class Vector3 {
1436
1453
  * @returns the new Vector3
1437
1454
  */
1438
1455
  normalizeToNew() {
1439
- const normalized = new Vector3(0, 0, 0);
1456
+ const normalized = new this.constructor(0, 0, 0);
1440
1457
  this.normalizeToRef(normalized);
1441
1458
  return normalized;
1442
1459
  }
@@ -1459,7 +1476,7 @@ export class Vector3 {
1459
1476
  * @returns the new Vector3
1460
1477
  */
1461
1478
  clone() {
1462
- return new Vector3(this._x, this._y, this._z);
1479
+ return new this.constructor(this._x, this._y, this._z);
1463
1480
  }
1464
1481
  /**
1465
1482
  * Copies the given vector coordinates to the current Vector3 ones
@@ -1635,6 +1652,7 @@ export class Vector3 {
1635
1652
  vector1Dir.scaleInPlace(scale1);
1636
1653
  result.copyFrom(vector0Dir).addInPlace(vector1Dir);
1637
1654
  result.scaleInPlace(Scalar.Lerp(vector0Length, vector1Length, slerp));
1655
+ return result;
1638
1656
  }
1639
1657
  /**
1640
1658
  * Smooth interpolation between two vectors using Slerp
@@ -1647,6 +1665,7 @@ export class Vector3 {
1647
1665
  */
1648
1666
  static SmoothToRef(source, goal, deltaTime, lerpTime, result) {
1649
1667
  Vector3.SlerpToRef(source, goal, lerpTime === 0 ? 1 : deltaTime / lerpTime, result);
1668
+ return result;
1650
1669
  }
1651
1670
  /**
1652
1671
  * Returns a new Vector3 set from the index "offset" of the given array
@@ -1674,11 +1693,13 @@ export class Vector3 {
1674
1693
  * @param array defines the source array
1675
1694
  * @param offset defines the offset in the source array
1676
1695
  * @param result defines the Vector3 where to store the result
1696
+ * @returns result input
1677
1697
  */
1678
1698
  static FromArrayToRef(array, offset, result) {
1679
1699
  result.x = array[offset];
1680
1700
  result.y = array[offset + 1];
1681
1701
  result.z = array[offset + 2];
1702
+ return result;
1682
1703
  }
1683
1704
  /**
1684
1705
  * Sets the given vector "result" with the element values from the index "offset" of the given Float32Array
@@ -1700,6 +1721,7 @@ export class Vector3 {
1700
1721
  */
1701
1722
  static FromFloatsToRef(x, y, z, result) {
1702
1723
  result.copyFromFloats(x, y, z);
1724
+ return result;
1703
1725
  }
1704
1726
  /**
1705
1727
  * Returns a new Vector3 set to (0.0, 0.0, 0.0)
@@ -1827,9 +1849,11 @@ export class Vector3 {
1827
1849
  * @param vector defines the Vector3 to transform
1828
1850
  * @param transformation defines the transformation matrix
1829
1851
  * @param result defines the Vector3 where to store the result
1852
+ * @returns result input
1830
1853
  */
1831
1854
  static TransformCoordinatesToRef(vector, transformation, result) {
1832
1855
  Vector3.TransformCoordinatesFromFloatsToRef(vector._x, vector._y, vector._z, transformation, result);
1856
+ return result;
1833
1857
  }
1834
1858
  /**
1835
1859
  * 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 +1864,7 @@ export class Vector3 {
1840
1864
  * @param z define the z coordinate of the source vector
1841
1865
  * @param transformation defines the transformation matrix
1842
1866
  * @param result defines the Vector3 where to store the result
1867
+ * @returns result input
1843
1868
  */
1844
1869
  static TransformCoordinatesFromFloatsToRef(x, y, z, transformation, result) {
1845
1870
  const m = transformation.m;
@@ -1850,6 +1875,7 @@ export class Vector3 {
1850
1875
  result.x = rx * rw;
1851
1876
  result.y = ry * rw;
1852
1877
  result.z = rz * rw;
1878
+ return result;
1853
1879
  }
1854
1880
  /**
1855
1881
  * Returns a new Vector3 set with the result of the normal transformation by the given matrix of the given vector
@@ -1871,9 +1897,11 @@ export class Vector3 {
1871
1897
  * @param vector defines the Vector3 to transform
1872
1898
  * @param transformation defines the transformation matrix
1873
1899
  * @param result defines the Vector3 where to store the result
1900
+ * @returns result input
1874
1901
  */
1875
1902
  static TransformNormalToRef(vector, transformation, result) {
1876
1903
  this.TransformNormalFromFloatsToRef(vector._x, vector._y, vector._z, transformation, result);
1904
+ return result;
1877
1905
  }
1878
1906
  /**
1879
1907
  * 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 +1912,14 @@ export class Vector3 {
1884
1912
  * @param z define the z coordinate of the source vector
1885
1913
  * @param transformation defines the transformation matrix
1886
1914
  * @param result defines the Vector3 where to store the result
1915
+ * @returns result input
1887
1916
  */
1888
1917
  static TransformNormalFromFloatsToRef(x, y, z, transformation, result) {
1889
1918
  const m = transformation.m;
1890
1919
  result.x = x * m[0] + y * m[4] + z * m[8];
1891
1920
  result.y = x * m[1] + y * m[5] + z * m[9];
1892
1921
  result.z = x * m[2] + y * m[6] + z * m[10];
1922
+ return result;
1893
1923
  }
1894
1924
  /**
1895
1925
  * Returns a new Vector3 located for "amount" on the CatmullRom interpolation spline defined by the vectors "value1", "value2", "value3", "value4"
@@ -1919,7 +1949,7 @@ export class Vector3 {
1919
1949
  (-value1._z + value3._z) * amount +
1920
1950
  (2.0 * value1._z - 5.0 * value2._z + 4.0 * value3._z - value4._z) * squared +
1921
1951
  (-value1._z + 3.0 * value2._z - 3.0 * value3._z + value4._z) * cubed);
1922
- return new Vector3(x, y, z);
1952
+ return new value1.constructor(x, y, z);
1923
1953
  }
1924
1954
  /**
1925
1955
  * 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 +1962,9 @@ export class Vector3 {
1932
1962
  * @returns the new Vector3
1933
1963
  */
1934
1964
  static Clamp(value, min, max) {
1935
- const v = new Vector3();
1936
- Vector3.ClampToRef(value, min, max, v);
1937
- return v;
1965
+ const result = new value.constructor();
1966
+ Vector3.ClampToRef(value, min, max, result);
1967
+ return result;
1938
1968
  }
1939
1969
  /**
1940
1970
  * 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 +1975,7 @@ export class Vector3 {
1945
1975
  * @param min defines the lower range value
1946
1976
  * @param max defines the upper range value
1947
1977
  * @param result defines the Vector3 where to store the result
1978
+ * @returns result input
1948
1979
  */
1949
1980
  static ClampToRef(value, min, max, result) {
1950
1981
  let x = value._x;
@@ -1957,6 +1988,7 @@ export class Vector3 {
1957
1988
  z = z > max._z ? max._z : z;
1958
1989
  z = z < min._z ? min._z : z;
1959
1990
  result.copyFromFloats(x, y, z);
1991
+ return result;
1960
1992
  }
1961
1993
  /**
1962
1994
  * Checks if a given vector is inside a specific range
@@ -1989,7 +2021,7 @@ export class Vector3 {
1989
2021
  const x = value1._x * part1 + value2._x * part2 + tangent1._x * part3 + tangent2._x * part4;
1990
2022
  const y = value1._y * part1 + value2._y * part2 + tangent1._y * part3 + tangent2._y * part4;
1991
2023
  const z = value1._z * part1 + value2._z * part2 + tangent1._z * part3 + tangent2._z * part4;
1992
- return new Vector3(x, y, z);
2024
+ return new value1.constructor(x, y, z);
1993
2025
  }
1994
2026
  /**
1995
2027
  * Returns a new Vector3 which is the 1st derivative of the Hermite spline defined by the vectors "value1", "value2", "tangent1", "tangent2".
@@ -2002,7 +2034,7 @@ export class Vector3 {
2002
2034
  * @returns 1st derivative
2003
2035
  */
2004
2036
  static Hermite1stDerivative(value1, tangent1, value2, tangent2, time) {
2005
- const result = Vector3.Zero();
2037
+ const result = new value1.constructor();
2006
2038
  this.Hermite1stDerivativeToRef(value1, tangent1, value2, tangent2, time, result);
2007
2039
  return result;
2008
2040
  }
@@ -2015,12 +2047,14 @@ export class Vector3 {
2015
2047
  * @param tangent2 defines the second tangent
2016
2048
  * @param time define where the derivative must be done
2017
2049
  * @param result define where to store the derivative
2050
+ * @returns result input
2018
2051
  */
2019
2052
  static Hermite1stDerivativeToRef(value1, tangent1, value2, tangent2, time, result) {
2020
2053
  const t2 = time * time;
2021
2054
  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
2055
  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
2056
  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;
2057
+ return result;
2024
2058
  }
2025
2059
  /**
2026
2060
  * Returns a new Vector3 located for "amount" (float) on the linear interpolation between the vectors "start" and "end"
@@ -2031,7 +2065,7 @@ export class Vector3 {
2031
2065
  * @returns the new Vector3
2032
2066
  */
2033
2067
  static Lerp(start, end, amount) {
2034
- const result = new Vector3(0, 0, 0);
2068
+ const result = new start.constructor(0, 0, 0);
2035
2069
  Vector3.LerpToRef(start, end, amount, result);
2036
2070
  return result;
2037
2071
  }
@@ -2042,11 +2076,13 @@ export class Vector3 {
2042
2076
  * @param end defines the end value
2043
2077
  * @param amount max defines amount between both (between 0 and 1)
2044
2078
  * @param result defines the Vector3 where to store the result
2079
+ * @returns result input
2045
2080
  */
2046
2081
  static LerpToRef(start, end, amount, result) {
2047
2082
  result.x = start._x + (end._x - start._x) * amount;
2048
2083
  result.y = start._y + (end._y - start._y) * amount;
2049
2084
  result.z = start._z + (end._z - start._z) * amount;
2085
+ return result;
2050
2086
  }
2051
2087
  /**
2052
2088
  * Returns the dot product (float) between the vectors "left" and "right"
@@ -2067,7 +2103,7 @@ export class Vector3 {
2067
2103
  * @returns the cross product
2068
2104
  */
2069
2105
  static Cross(left, right) {
2070
- const result = Vector3.Zero();
2106
+ const result = new left.constructor();
2071
2107
  Vector3.CrossToRef(left, right, result);
2072
2108
  return result;
2073
2109
  }
@@ -2078,12 +2114,14 @@ export class Vector3 {
2078
2114
  * @param left defines the left operand
2079
2115
  * @param right defines the right operand
2080
2116
  * @param result defines the Vector3 where to store the result
2117
+ * @returns result input
2081
2118
  */
2082
2119
  static CrossToRef(left, right, result) {
2083
2120
  const x = left._y * right._z - left._z * right._y;
2084
2121
  const y = left._z * right._x - left._x * right._z;
2085
2122
  const z = left._x * right._y - left._y * right._x;
2086
2123
  result.copyFromFloats(x, y, z);
2124
+ return result;
2087
2125
  }
2088
2126
  /**
2089
2127
  * Returns a new Vector3 as the normalization of the given vector
@@ -2101,9 +2139,11 @@ export class Vector3 {
2101
2139
  * Example Playground https://playground.babylonjs.com/#R1F8YU#98
2102
2140
  * @param vector defines the Vector3 to normalize
2103
2141
  * @param result defines the Vector3 where to store the result
2142
+ * @returns result input
2104
2143
  */
2105
2144
  static NormalizeToRef(vector, result) {
2106
2145
  vector.normalizeToRef(result);
2146
+ return result;
2107
2147
  }
2108
2148
  /**
2109
2149
  * Project a Vector3 onto screen space
@@ -2115,7 +2155,7 @@ export class Vector3 {
2115
2155
  * @returns the new Vector3
2116
2156
  */
2117
2157
  static Project(vector, world, transform, viewport) {
2118
- const result = new Vector3();
2158
+ const result = new vector.constructor();
2119
2159
  Vector3.ProjectToRef(vector, world, transform, viewport, result);
2120
2160
  return result;
2121
2161
  }
@@ -2127,7 +2167,7 @@ export class Vector3 {
2127
2167
  * @param transform defines the transform (view x projection) matrix to use
2128
2168
  * @param viewport defines the screen viewport to use
2129
2169
  * @param result the vector in which the screen space will be stored
2130
- * @returns the new Vector3
2170
+ * @returns result input
2131
2171
  */
2132
2172
  static ProjectToRef(vector, world, transform, viewport, result) {
2133
2173
  const cw = viewport.width;
@@ -2152,6 +2192,7 @@ export class Vector3 {
2152
2192
  if (Scalar.WithinEpsilon(num, 1.0)) {
2153
2193
  result.scaleInPlace(1.0 / num);
2154
2194
  }
2195
+ return result;
2155
2196
  }
2156
2197
  /**
2157
2198
  * Unproject from screen space to object space
@@ -2178,7 +2219,7 @@ export class Vector3 {
2178
2219
  * @returns the new Vector3
2179
2220
  */
2180
2221
  static Unproject(source, viewportWidth, viewportHeight, world, view, projection) {
2181
- const result = Vector3.Zero();
2222
+ const result = new source.constructor();
2182
2223
  Vector3.UnprojectToRef(source, viewportWidth, viewportHeight, world, view, projection, result);
2183
2224
  return result;
2184
2225
  }
@@ -2192,9 +2233,11 @@ export class Vector3 {
2192
2233
  * @param view defines the view matrix to use
2193
2234
  * @param projection defines the projection matrix to use
2194
2235
  * @param result defines the Vector3 where to store the result
2236
+ * @returns result input
2195
2237
  */
2196
2238
  static UnprojectToRef(source, viewportWidth, viewportHeight, world, view, projection, result) {
2197
2239
  Vector3.UnprojectFloatsToRef(source._x, source._y, source._z, viewportWidth, viewportHeight, world, view, projection, result);
2240
+ return result;
2198
2241
  }
2199
2242
  /**
2200
2243
  * Unproject from screen space to object space
@@ -2208,6 +2251,7 @@ export class Vector3 {
2208
2251
  * @param view defines the view matrix to use
2209
2252
  * @param projection defines the projection matrix to use
2210
2253
  * @param result defines the Vector3 where to store the result
2254
+ * @returns result input
2211
2255
  */
2212
2256
  static UnprojectFloatsToRef(sourceX, sourceY, sourceZ, viewportWidth, viewportHeight, world, view, projection, result) {
2213
2257
  var _a;
@@ -2225,6 +2269,7 @@ export class Vector3 {
2225
2269
  screenSource.z = 2 * sourceZ - 1.0;
2226
2270
  }
2227
2271
  Vector3._UnprojectFromInvertedMatrixToRef(screenSource, matrix, result);
2272
+ return result;
2228
2273
  }
2229
2274
  /**
2230
2275
  * Gets the minimal coordinate values between two Vector3
@@ -2234,7 +2279,8 @@ export class Vector3 {
2234
2279
  * @returns the new Vector3
2235
2280
  */
2236
2281
  static Minimize(left, right) {
2237
- const min = left.clone();
2282
+ const min = new left.constructor();
2283
+ min.copyFrom(left);
2238
2284
  min.minimizeInPlace(right);
2239
2285
  return min;
2240
2286
  }
@@ -2246,7 +2292,8 @@ export class Vector3 {
2246
2292
  * @returns the new Vector3
2247
2293
  */
2248
2294
  static Maximize(left, right) {
2249
- const max = left.clone();
2295
+ const max = new left.constructor();
2296
+ max.copyFrom(left);
2250
2297
  max.maximizeInPlace(right);
2251
2298
  return max;
2252
2299
  }
@@ -2447,7 +2494,7 @@ export class Vector3 {
2447
2494
  * @see https://doc.babylonjs.com/divingDeeper/mesh/transforms/center_origin/target_align
2448
2495
  */
2449
2496
  static RotationFromAxis(axis1, axis2, axis3) {
2450
- const rotation = Vector3.Zero();
2497
+ const rotation = new axis1.constructor();
2451
2498
  Vector3.RotationFromAxisToRef(axis1, axis2, axis3, rotation);
2452
2499
  return rotation;
2453
2500
  }
@@ -2458,11 +2505,13 @@ export class Vector3 {
2458
2505
  * @param axis2 defines the second axis
2459
2506
  * @param axis3 defines the third axis
2460
2507
  * @param ref defines the Vector3 where to store the result
2508
+ * @returns result input
2461
2509
  */
2462
2510
  static RotationFromAxisToRef(axis1, axis2, axis3, ref) {
2463
2511
  const quat = MathTmp.Quaternion[0];
2464
2512
  Quaternion.RotationQuaternionFromAxisToRef(axis1, axis2, axis3, quat);
2465
2513
  quat.toEulerAnglesToRef(ref);
2514
+ return ref;
2466
2515
  }
2467
2516
  }
2468
2517
  Vector3._UpReadOnly = Vector3.Up();
@@ -2485,13 +2534,13 @@ export class Vector4 {
2485
2534
  */
2486
2535
  constructor(
2487
2536
  /** x value of the vector */
2488
- x,
2537
+ x = 0,
2489
2538
  /** y value of the vector */
2490
- y,
2539
+ y = 0,
2491
2540
  /** z value of the vector */
2492
- z,
2541
+ z = 0,
2493
2542
  /** w value of the vector */
2494
- w) {
2543
+ w = 0) {
2495
2544
  this.x = x;
2496
2545
  this.y = y;
2497
2546
  this.z = z;
@@ -2580,20 +2629,20 @@ export class Vector4 {
2580
2629
  * @returns the resulting vector
2581
2630
  */
2582
2631
  add(otherVector) {
2583
- return new Vector4(this.x + otherVector.x, this.y + otherVector.y, this.z + otherVector.z, this.w + otherVector.w);
2632
+ return new this.constructor(this.x + otherVector.x, this.y + otherVector.y, this.z + otherVector.z, this.w + otherVector.w);
2584
2633
  }
2585
2634
  /**
2586
2635
  * Updates the given vector "result" with the result of the addition of the current Vector4 and the given one.
2587
2636
  * @param otherVector the vector to add
2588
2637
  * @param result the vector to store the result
2589
- * @returns the current Vector4.
2638
+ * @returns result input
2590
2639
  */
2591
2640
  addToRef(otherVector, result) {
2592
2641
  result.x = this.x + otherVector.x;
2593
2642
  result.y = this.y + otherVector.y;
2594
2643
  result.z = this.z + otherVector.z;
2595
2644
  result.w = this.w + otherVector.w;
2596
- return this;
2645
+ return result;
2597
2646
  }
2598
2647
  /**
2599
2648
  * Subtract in place the given vector from the current Vector4.
@@ -2613,20 +2662,20 @@ export class Vector4 {
2613
2662
  * @returns the new vector with the result
2614
2663
  */
2615
2664
  subtract(otherVector) {
2616
- return new Vector4(this.x - otherVector.x, this.y - otherVector.y, this.z - otherVector.z, this.w - otherVector.w);
2665
+ return new this.constructor(this.x - otherVector.x, this.y - otherVector.y, this.z - otherVector.z, this.w - otherVector.w);
2617
2666
  }
2618
2667
  /**
2619
2668
  * Sets the given vector "result" with the result of the subtraction of the given vector from the current Vector4.
2620
2669
  * @param otherVector the vector to subtract
2621
2670
  * @param result the vector to store the result
2622
- * @returns the current Vector4.
2671
+ * @returns result input
2623
2672
  */
2624
2673
  subtractToRef(otherVector, result) {
2625
2674
  result.x = this.x - otherVector.x;
2626
2675
  result.y = this.y - otherVector.y;
2627
2676
  result.z = this.z - otherVector.z;
2628
2677
  result.w = this.w - otherVector.w;
2629
- return this;
2678
+ return result;
2630
2679
  }
2631
2680
  /**
2632
2681
  * Returns a new Vector4 set with the result of the subtraction of the given floats from the current Vector4 coordinates.
@@ -2640,7 +2689,7 @@ export class Vector4 {
2640
2689
  * @returns new vector containing the result
2641
2690
  */
2642
2691
  subtractFromFloats(x, y, z, w) {
2643
- return new Vector4(this.x - x, this.y - y, this.z - z, this.w - w);
2692
+ return new this.constructor(this.x - x, this.y - y, this.z - z, this.w - w);
2644
2693
  }
2645
2694
  /**
2646
2695
  * Sets the given vector "result" set with the result of the subtraction of the given floats from the current Vector4 coordinates.
@@ -2649,21 +2698,21 @@ export class Vector4 {
2649
2698
  * @param z value to subtract
2650
2699
  * @param w value to subtract
2651
2700
  * @param result the vector to store the result in
2652
- * @returns the current Vector4.
2701
+ * @returns result input
2653
2702
  */
2654
2703
  subtractFromFloatsToRef(x, y, z, w, result) {
2655
2704
  result.x = this.x - x;
2656
2705
  result.y = this.y - y;
2657
2706
  result.z = this.z - z;
2658
2707
  result.w = this.w - w;
2659
- return this;
2708
+ return result;
2660
2709
  }
2661
2710
  /**
2662
2711
  * Returns a new Vector4 set with the current Vector4 negated coordinates.
2663
2712
  * @returns a new vector with the negated values
2664
2713
  */
2665
2714
  negate() {
2666
- return new Vector4(-this.x, -this.y, -this.z, -this.w);
2715
+ return new this.constructor(-this.x, -this.y, -this.z, -this.w);
2667
2716
  }
2668
2717
  /**
2669
2718
  * Negate this vector in place
@@ -2702,33 +2751,33 @@ export class Vector4 {
2702
2751
  * @returns a new vector with the result
2703
2752
  */
2704
2753
  scale(scale) {
2705
- return new Vector4(this.x * scale, this.y * scale, this.z * scale, this.w * scale);
2754
+ return new this.constructor(this.x * scale, this.y * scale, this.z * scale, this.w * scale);
2706
2755
  }
2707
2756
  /**
2708
2757
  * Sets the given vector "result" with the current Vector4 coordinates multiplied by scale (float).
2709
2758
  * @param scale the number to scale with
2710
2759
  * @param result a vector to store the result in
2711
- * @returns the current Vector4.
2760
+ * @returns result input
2712
2761
  */
2713
2762
  scaleToRef(scale, result) {
2714
2763
  result.x = this.x * scale;
2715
2764
  result.y = this.y * scale;
2716
2765
  result.z = this.z * scale;
2717
2766
  result.w = this.w * scale;
2718
- return this;
2767
+ return result;
2719
2768
  }
2720
2769
  /**
2721
2770
  * Scale the current Vector4 values by a factor and add the result to a given Vector4
2722
2771
  * @param scale defines the scale factor
2723
2772
  * @param result defines the Vector4 object where to store the result
2724
- * @returns the unmodified current Vector4
2773
+ * @returns result input
2725
2774
  */
2726
2775
  scaleAndAddToRef(scale, result) {
2727
2776
  result.x += this.x * scale;
2728
2777
  result.y += this.y * scale;
2729
2778
  result.z += this.z * scale;
2730
2779
  result.w += this.w * scale;
2731
- return this;
2780
+ return result;
2732
2781
  }
2733
2782
  /**
2734
2783
  * Boolean : True if the current Vector4 coordinates are stricly equal to the given ones.
@@ -2780,20 +2829,20 @@ export class Vector4 {
2780
2829
  * @returns resulting new vector
2781
2830
  */
2782
2831
  multiply(otherVector) {
2783
- return new Vector4(this.x * otherVector.x, this.y * otherVector.y, this.z * otherVector.z, this.w * otherVector.w);
2832
+ return new this.constructor(this.x * otherVector.x, this.y * otherVector.y, this.z * otherVector.z, this.w * otherVector.w);
2784
2833
  }
2785
2834
  /**
2786
2835
  * Updates the given vector "result" with the multiplication result of the current Vector4 and the given one.
2787
2836
  * @param otherVector vector to multiple with
2788
2837
  * @param result vector to store the result
2789
- * @returns the current Vector4.
2838
+ * @returns result input
2790
2839
  */
2791
2840
  multiplyToRef(otherVector, result) {
2792
2841
  result.x = this.x * otherVector.x;
2793
2842
  result.y = this.y * otherVector.y;
2794
2843
  result.z = this.z * otherVector.z;
2795
2844
  result.w = this.w * otherVector.w;
2796
- return this;
2845
+ return result;
2797
2846
  }
2798
2847
  /**
2799
2848
  * Returns a new Vector4 set with the multiplication result of the given floats and the current Vector4 coordinates.
@@ -2804,7 +2853,7 @@ export class Vector4 {
2804
2853
  * @returns resulting new vector
2805
2854
  */
2806
2855
  multiplyByFloats(x, y, z, w) {
2807
- return new Vector4(this.x * x, this.y * y, this.z * z, this.w * w);
2856
+ return new this.constructor(this.x * x, this.y * y, this.z * z, this.w * w);
2808
2857
  }
2809
2858
  /**
2810
2859
  * Returns a new Vector4 set with the division result of the current Vector4 by the given one.
@@ -2812,20 +2861,20 @@ export class Vector4 {
2812
2861
  * @returns resulting new vector
2813
2862
  */
2814
2863
  divide(otherVector) {
2815
- return new Vector4(this.x / otherVector.x, this.y / otherVector.y, this.z / otherVector.z, this.w / otherVector.w);
2864
+ return new this.constructor(this.x / otherVector.x, this.y / otherVector.y, this.z / otherVector.z, this.w / otherVector.w);
2816
2865
  }
2817
2866
  /**
2818
2867
  * Updates the given vector "result" with the division result of the current Vector4 by the given one.
2819
2868
  * @param otherVector vector to devide with
2820
2869
  * @param result vector to store the result
2821
- * @returns the current Vector4.
2870
+ * @returns result input
2822
2871
  */
2823
2872
  divideToRef(otherVector, result) {
2824
2873
  result.x = this.x / otherVector.x;
2825
2874
  result.y = this.y / otherVector.y;
2826
2875
  result.z = this.z / otherVector.z;
2827
2876
  result.w = this.w / otherVector.w;
2828
- return this;
2877
+ return result;
2829
2878
  }
2830
2879
  /**
2831
2880
  * Divides the current Vector3 coordinates by the given ones.
@@ -2880,14 +2929,14 @@ export class Vector4 {
2880
2929
  * @returns a new Vector4
2881
2930
  */
2882
2931
  floor() {
2883
- return new Vector4(Math.floor(this.x), Math.floor(this.y), Math.floor(this.z), Math.floor(this.w));
2932
+ return new this.constructor(Math.floor(this.x), Math.floor(this.y), Math.floor(this.z), Math.floor(this.w));
2884
2933
  }
2885
2934
  /**
2886
2935
  * Gets a new Vector4 from current Vector4 fractional values
2887
2936
  * @returns a new Vector4
2888
2937
  */
2889
2938
  fract() {
2890
- return new Vector4(this.x - Math.floor(this.x), this.y - Math.floor(this.y), this.z - Math.floor(this.z), this.w - Math.floor(this.w));
2939
+ 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
2940
  }
2892
2941
  // Properties
2893
2942
  /**
@@ -2928,7 +2977,7 @@ export class Vector4 {
2928
2977
  * @returns the new cloned vector
2929
2978
  */
2930
2979
  clone() {
2931
- return new Vector4(this.x, this.y, this.z, this.w);
2980
+ return new this.constructor(this.x, this.y, this.z, this.w);
2932
2981
  }
2933
2982
  /**
2934
2983
  * Updates the current Vector4 with the given one coordinates.
@@ -2995,21 +3044,25 @@ export class Vector4 {
2995
3044
  * @param array the array to pull values from
2996
3045
  * @param offset the offset into the array to start at
2997
3046
  * @param result the vector to store the result in
3047
+ * @returns result input
2998
3048
  */
2999
3049
  static FromArrayToRef(array, offset, result) {
3000
3050
  result.x = array[offset];
3001
3051
  result.y = array[offset + 1];
3002
3052
  result.z = array[offset + 2];
3003
3053
  result.w = array[offset + 3];
3054
+ return result;
3004
3055
  }
3005
3056
  /**
3006
3057
  * Updates the given vector "result" from the starting index of the given Float32Array.
3007
3058
  * @param array the array to pull values from
3008
3059
  * @param offset the offset into the array to start at
3009
3060
  * @param result the vector to store the result in
3061
+ * @returns result input
3010
3062
  */
3011
3063
  static FromFloatArrayToRef(array, offset, result) {
3012
3064
  Vector4.FromArrayToRef(array, offset, result);
3065
+ return result;
3013
3066
  }
3014
3067
  /**
3015
3068
  * Updates the given vector "result" coordinates from the given floats.
@@ -3018,12 +3071,14 @@ export class Vector4 {
3018
3071
  * @param z float to set from
3019
3072
  * @param w float to set from
3020
3073
  * @param result the vector to the floats in
3074
+ * @returns result input
3021
3075
  */
3022
3076
  static FromFloatsToRef(x, y, z, w, result) {
3023
3077
  result.x = x;
3024
3078
  result.y = y;
3025
3079
  result.z = z;
3026
3080
  result.w = w;
3081
+ return result;
3027
3082
  }
3028
3083
  /**
3029
3084
  * Returns a new Vector4 set to (0.0, 0.0, 0.0, 0.0)
@@ -3059,10 +3114,12 @@ export class Vector4 {
3059
3114
  * Updates the given vector "result" from the normalization of the given one.
3060
3115
  * @param vector the vector to normalize
3061
3116
  * @param result the vector to store the result in
3117
+ * @returns result input
3062
3118
  */
3063
3119
  static NormalizeToRef(vector, result) {
3064
3120
  result.copyFrom(vector);
3065
3121
  result.normalize();
3122
+ return result;
3066
3123
  }
3067
3124
  /**
3068
3125
  * Returns a vector with the minimum values from the left and right vectors
@@ -3071,7 +3128,8 @@ export class Vector4 {
3071
3128
  * @returns a new vector with the minimum of the left and right vector values
3072
3129
  */
3073
3130
  static Minimize(left, right) {
3074
- const min = left.clone();
3131
+ const min = new left.constructor();
3132
+ min.copyFrom(left);
3075
3133
  min.minimizeInPlace(right);
3076
3134
  return min;
3077
3135
  }
@@ -3082,7 +3140,8 @@ export class Vector4 {
3082
3140
  * @returns a new vector with the maximum of the left and right vector values
3083
3141
  */
3084
3142
  static Maximize(left, right) {
3085
- const max = left.clone();
3143
+ const max = new left.constructor();
3144
+ max.copyFrom(left);
3086
3145
  max.maximizeInPlace(right);
3087
3146
  return max;
3088
3147
  }
@@ -3147,9 +3206,11 @@ export class Vector4 {
3147
3206
  * @param vector defines the Vector3 to transform
3148
3207
  * @param transformation defines the transformation matrix
3149
3208
  * @param result defines the Vector4 where to store the result
3209
+ * @returns result input
3150
3210
  */
3151
3211
  static TransformCoordinatesToRef(vector, transformation, result) {
3152
3212
  Vector4.TransformCoordinatesFromFloatsToRef(vector._x, vector._y, vector._z, transformation, result);
3213
+ return result;
3153
3214
  }
3154
3215
  /**
3155
3216
  * 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 +3221,7 @@ export class Vector4 {
3160
3221
  * @param z define the z coordinate of the source vector
3161
3222
  * @param transformation defines the transformation matrix
3162
3223
  * @param result defines the Vector4 where to store the result
3224
+ * @returns result input
3163
3225
  */
3164
3226
  static TransformCoordinatesFromFloatsToRef(x, y, z, transformation, result) {
3165
3227
  const m = transformation.m;
@@ -3171,6 +3233,7 @@ export class Vector4 {
3171
3233
  result.y = ry;
3172
3234
  result.z = rz;
3173
3235
  result.w = rw;
3236
+ return result;
3174
3237
  }
3175
3238
  /**
3176
3239
  * Returns a new Vector4 set with the result of the normal transformation by the given matrix of the given vector.
@@ -3180,7 +3243,7 @@ export class Vector4 {
3180
3243
  * @returns the new vector
3181
3244
  */
3182
3245
  static TransformNormal(vector, transformation) {
3183
- const result = Vector4.Zero();
3246
+ const result = new vector.constructor();
3184
3247
  Vector4.TransformNormalToRef(vector, transformation, result);
3185
3248
  return result;
3186
3249
  }
@@ -3190,6 +3253,7 @@ export class Vector4 {
3190
3253
  * @param vector the vector to transform
3191
3254
  * @param transformation the transformation matrix to apply
3192
3255
  * @param result the vector to store the result in
3256
+ * @returns result input
3193
3257
  */
3194
3258
  static TransformNormalToRef(vector, transformation, result) {
3195
3259
  const m = transformation.m;
@@ -3200,6 +3264,7 @@ export class Vector4 {
3200
3264
  result.y = y;
3201
3265
  result.z = z;
3202
3266
  result.w = vector.w;
3267
+ return result;
3203
3268
  }
3204
3269
  /**
3205
3270
  * 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 +3275,7 @@ export class Vector4 {
3210
3275
  * @param w value to transform
3211
3276
  * @param transformation the transformation matrix to apply
3212
3277
  * @param result the vector to store the results in
3278
+ * @returns result input
3213
3279
  */
3214
3280
  static TransformNormalFromFloatsToRef(x, y, z, w, transformation, result) {
3215
3281
  const m = transformation.m;
@@ -3217,6 +3283,7 @@ export class Vector4 {
3217
3283
  result.y = x * m[1] + y * m[5] + z * m[9];
3218
3284
  result.z = x * m[2] + y * m[6] + z * m[10];
3219
3285
  result.w = w;
3286
+ return result;
3220
3287
  }
3221
3288
  /**
3222
3289
  * Creates a new Vector4 from a Vector3
@@ -3231,6 +3298,7 @@ export class Vector4 {
3231
3298
  Vector4._ZeroReadOnly = Vector4.Zero();
3232
3299
  /**
3233
3300
  * Class used to store quaternion data
3301
+ * Example Playground - Overview - https://playground.babylonjs.com/#L49EJ7#100
3234
3302
  * @see https://en.wikipedia.org/wiki/Quaternion
3235
3303
  * @see https://doc.babylonjs.com/features/position,_rotation,_scaling
3236
3304
  */
@@ -3313,6 +3381,7 @@ export class Quaternion {
3313
3381
  }
3314
3382
  /**
3315
3383
  * Copy the quaternion to an array
3384
+ * Example Playground https://playground.babylonjs.com/#L49EJ7#13
3316
3385
  * @returns a new array populated with 4 elements from the quaternion coordinates
3317
3386
  */
3318
3387
  asArray() {
@@ -3320,6 +3389,7 @@ export class Quaternion {
3320
3389
  }
3321
3390
  /**
3322
3391
  * Stores from the starting index in the given array the Quaternion successive values
3392
+ * Example Playground https://playground.babylonjs.com/#L49EJ7#59
3323
3393
  * @param array defines the array where to store the x,y,z,w components
3324
3394
  * @param index defines an optional index in the target array to define where to start storing values
3325
3395
  * @returns the current Quaternion object
@@ -3333,6 +3403,7 @@ export class Quaternion {
3333
3403
  }
3334
3404
  /**
3335
3405
  * Check if two quaternions are equals
3406
+ * Example Playground https://playground.babylonjs.com/#L49EJ7#38
3336
3407
  * @param otherQuaternion defines the second operand
3337
3408
  * @returns true if the current quaternion and the given one coordinates are strictly equals
3338
3409
  */
@@ -3341,6 +3412,7 @@ export class Quaternion {
3341
3412
  }
3342
3413
  /**
3343
3414
  * Gets a boolean if two quaternions are equals (using an epsilon value)
3415
+ * Example Playground https://playground.babylonjs.com/#L49EJ7#37
3344
3416
  * @param otherQuaternion defines the other quaternion
3345
3417
  * @param epsilon defines the minimal distance to consider equality
3346
3418
  * @returns true if the given quaternion coordinates are close to the current ones by a distance of epsilon.
@@ -3354,13 +3426,15 @@ export class Quaternion {
3354
3426
  }
3355
3427
  /**
3356
3428
  * Clone the current quaternion
3429
+ * Example Playground https://playground.babylonjs.com/#L49EJ7#12
3357
3430
  * @returns a new quaternion copied from the current one
3358
3431
  */
3359
3432
  clone() {
3360
- return new Quaternion(this._x, this._y, this._z, this._w);
3433
+ return new this.constructor(this._x, this._y, this._z, this._w);
3361
3434
  }
3362
3435
  /**
3363
3436
  * Copy a quaternion to the current one
3437
+ * Example Playground https://playground.babylonjs.com/#L49EJ7#86
3364
3438
  * @param other defines the other quaternion
3365
3439
  * @returns the updated current quaternion
3366
3440
  */
@@ -3373,6 +3447,7 @@ export class Quaternion {
3373
3447
  }
3374
3448
  /**
3375
3449
  * Updates the current quaternion with the given float coordinates
3450
+ * Example Playground https://playground.babylonjs.com/#L49EJ7#87
3376
3451
  * @param x defines the x coordinate
3377
3452
  * @param y defines the y coordinate
3378
3453
  * @param z defines the z coordinate
@@ -3388,6 +3463,7 @@ export class Quaternion {
3388
3463
  }
3389
3464
  /**
3390
3465
  * Updates the current quaternion from the given float coordinates
3466
+ * Example Playground https://playground.babylonjs.com/#L49EJ7#56
3391
3467
  * @param x defines the x coordinate
3392
3468
  * @param y defines the y coordinate
3393
3469
  * @param z defines the z coordinate
@@ -3399,14 +3475,16 @@ export class Quaternion {
3399
3475
  }
3400
3476
  /**
3401
3477
  * Adds two quaternions
3478
+ * Example Playground https://playground.babylonjs.com/#L49EJ7#10
3402
3479
  * @param other defines the second operand
3403
3480
  * @returns a new quaternion as the addition result of the given one and the current quaternion
3404
3481
  */
3405
3482
  add(other) {
3406
- return new Quaternion(this._x + other._x, this._y + other._y, this._z + other._z, this._w + other._w);
3483
+ return new this.constructor(this._x + other._x, this._y + other._y, this._z + other._z, this._w + other._w);
3407
3484
  }
3408
3485
  /**
3409
3486
  * Add a quaternion to the current one
3487
+ * Example Playground https://playground.babylonjs.com/#L49EJ7#11
3410
3488
  * @param other defines the quaternion to add
3411
3489
  * @returns the current quaternion
3412
3490
  */
@@ -3419,14 +3497,16 @@ export class Quaternion {
3419
3497
  }
3420
3498
  /**
3421
3499
  * Subtract two quaternions
3500
+ * Example Playground https://playground.babylonjs.com/#L49EJ7#57
3422
3501
  * @param other defines the second operand
3423
3502
  * @returns a new quaternion as the subtraction result of the given one from the current one
3424
3503
  */
3425
3504
  subtract(other) {
3426
- return new Quaternion(this._x - other._x, this._y - other._y, this._z - other._z, this._w - other._w);
3505
+ return new this.constructor(this._x - other._x, this._y - other._y, this._z - other._z, this._w - other._w);
3427
3506
  }
3428
3507
  /**
3429
3508
  * Subtract a quaternion to the current one
3509
+ * Example Playground https://playground.babylonjs.com/#L49EJ7#58
3430
3510
  * @param other defines the quaternion to subtract
3431
3511
  * @returns the current quaternion
3432
3512
  */
@@ -3439,27 +3519,30 @@ export class Quaternion {
3439
3519
  }
3440
3520
  /**
3441
3521
  * Multiplies the current quaternion by a scale factor
3522
+ * Example Playground https://playground.babylonjs.com/#L49EJ7#88
3442
3523
  * @param value defines the scale factor
3443
3524
  * @returns a new quaternion set by multiplying the current quaternion coordinates by the float "scale"
3444
3525
  */
3445
3526
  scale(value) {
3446
- return new Quaternion(this._x * value, this._y * value, this._z * value, this._w * value);
3527
+ return new this.constructor(this._x * value, this._y * value, this._z * value, this._w * value);
3447
3528
  }
3448
3529
  /**
3449
3530
  * Scale the current quaternion values by a factor and stores the result to a given quaternion
3531
+ * Example Playground https://playground.babylonjs.com/#L49EJ7#89
3450
3532
  * @param scale defines the scale factor
3451
3533
  * @param result defines the Quaternion object where to store the result
3452
- * @returns the unmodified current quaternion
3534
+ * @returns result input
3453
3535
  */
3454
3536
  scaleToRef(scale, result) {
3455
3537
  result.x = this._x * scale;
3456
3538
  result.y = this._y * scale;
3457
3539
  result.z = this._z * scale;
3458
3540
  result.w = this._w * scale;
3459
- return this;
3541
+ return result;
3460
3542
  }
3461
3543
  /**
3462
3544
  * Multiplies in place the current quaternion by a scale factor
3545
+ * Example Playground https://playground.babylonjs.com/#L49EJ7#90
3463
3546
  * @param value defines the scale factor
3464
3547
  * @returns the current modified quaternion
3465
3548
  */
@@ -3472,29 +3555,32 @@ export class Quaternion {
3472
3555
  }
3473
3556
  /**
3474
3557
  * Scale the current quaternion values by a factor and add the result to a given quaternion
3558
+ * Example Playground https://playground.babylonjs.com/#L49EJ7#91
3475
3559
  * @param scale defines the scale factor
3476
3560
  * @param result defines the Quaternion object where to store the result
3477
- * @returns the unmodified current quaternion
3561
+ * @returns result input
3478
3562
  */
3479
3563
  scaleAndAddToRef(scale, result) {
3480
3564
  result.x += this._x * scale;
3481
3565
  result.y += this._y * scale;
3482
3566
  result.z += this._z * scale;
3483
3567
  result.w += this._w * scale;
3484
- return this;
3568
+ return result;
3485
3569
  }
3486
3570
  /**
3487
3571
  * Multiplies two quaternions
3572
+ * Example Playground https://playground.babylonjs.com/#L49EJ7#43
3488
3573
  * @param q1 defines the second operand
3489
3574
  * @returns a new quaternion set as the multiplication result of the current one with the given one "q1"
3490
3575
  */
3491
3576
  multiply(q1) {
3492
- const result = new Quaternion(0, 0, 0, 1.0);
3577
+ const result = new this.constructor(0, 0, 0, 1.0);
3493
3578
  this.multiplyToRef(q1, result);
3494
3579
  return result;
3495
3580
  }
3496
3581
  /**
3497
3582
  * Sets the given "result" as the the multiplication result of the current one with the given one "q1"
3583
+ * Example Playground https://playground.babylonjs.com/#L49EJ7#45
3498
3584
  * @param q1 defines the second operand
3499
3585
  * @param result defines the target quaternion
3500
3586
  * @returns the current quaternion
@@ -3505,10 +3591,11 @@ export class Quaternion {
3505
3591
  const z = this._x * q1._y - this._y * q1._x + this._z * q1._w + this._w * q1._z;
3506
3592
  const w = -this._x * q1._x - this._y * q1._y - this._z * q1._z + this._w * q1._w;
3507
3593
  result.copyFromFloats(x, y, z, w);
3508
- return this;
3594
+ return result;
3509
3595
  }
3510
3596
  /**
3511
3597
  * Updates the current quaternion with the multiplication of itself with the given one "q1"
3598
+ * Example Playground https://playground.babylonjs.com/#L49EJ7#46
3512
3599
  * @param q1 defines the second operand
3513
3600
  * @returns the currentupdated quaternion
3514
3601
  */
@@ -3518,15 +3605,17 @@ export class Quaternion {
3518
3605
  }
3519
3606
  /**
3520
3607
  * Conjugates the current quaternion and stores the result in the given quaternion
3608
+ * Example Playground https://playground.babylonjs.com/#L49EJ7#81
3521
3609
  * @param ref defines the target quaternion
3522
- * @returns the current quaternion
3610
+ * @returns result input
3523
3611
  */
3524
3612
  conjugateToRef(ref) {
3525
3613
  ref.copyFromFloats(-this._x, -this._y, -this._z, this._w);
3526
- return this;
3614
+ return ref;
3527
3615
  }
3528
3616
  /**
3529
3617
  * Conjugates in place the current quaternion
3618
+ * Example Playground https://playground.babylonjs.com/#L49EJ7#82
3530
3619
  * @returns the current updated quaternion
3531
3620
  */
3532
3621
  conjugateInPlace() {
@@ -3537,13 +3626,15 @@ export class Quaternion {
3537
3626
  }
3538
3627
  /**
3539
3628
  * Conjugates (1-q) the current quaternion
3629
+ * Example Playground https://playground.babylonjs.com/#L49EJ7#83
3540
3630
  * @returns a new quaternion
3541
3631
  */
3542
3632
  conjugate() {
3543
- return new Quaternion(-this._x, -this._y, -this._z, this._w);
3633
+ return new this.constructor(-this._x, -this._y, -this._z, this._w);
3544
3634
  }
3545
3635
  /**
3546
3636
  * Returns the inverse of the current quaternion
3637
+ * Example Playground https://playground.babylonjs.com/#L49EJ7#84
3547
3638
  * @returns a new quaternion
3548
3639
  */
3549
3640
  invert() {
@@ -3557,6 +3648,7 @@ export class Quaternion {
3557
3648
  }
3558
3649
  /**
3559
3650
  * Invert in place the current quaternion
3651
+ * Example Playground https://playground.babylonjs.com/#L49EJ7#85
3560
3652
  * @returns this quaternion
3561
3653
  */
3562
3654
  invertInPlace() {
@@ -3570,6 +3662,7 @@ export class Quaternion {
3570
3662
  }
3571
3663
  /**
3572
3664
  * Gets squared length of current quaternion
3665
+ * Example Playground https://playground.babylonjs.com/#L49EJ7#29
3573
3666
  * @returns the quaternion length (float)
3574
3667
  */
3575
3668
  lengthSquared() {
@@ -3577,6 +3670,7 @@ export class Quaternion {
3577
3670
  }
3578
3671
  /**
3579
3672
  * Gets length of current quaternion
3673
+ * Example Playground https://playground.babylonjs.com/#L49EJ7#28
3580
3674
  * @returns the quaternion length (float)
3581
3675
  */
3582
3676
  length() {
@@ -3584,6 +3678,7 @@ export class Quaternion {
3584
3678
  }
3585
3679
  /**
3586
3680
  * Normalize in place the current quaternion
3681
+ * Example Playground https://playground.babylonjs.com/#L49EJ7#54
3587
3682
  * @returns the current updated quaternion
3588
3683
  */
3589
3684
  normalize() {
@@ -3597,6 +3692,7 @@ export class Quaternion {
3597
3692
  }
3598
3693
  /**
3599
3694
  * Normalize a copy of the current quaternion
3695
+ * Example Playground https://playground.babylonjs.com/#L49EJ7#55
3600
3696
  * @returns the normalized quaternion
3601
3697
  */
3602
3698
  normalizeToNew() {
@@ -3609,6 +3705,7 @@ export class Quaternion {
3609
3705
  }
3610
3706
  /**
3611
3707
  * Returns a new Vector3 set with the Euler angles translated from the current quaternion
3708
+ * Example Playground https://playground.babylonjs.com/#L49EJ7#32
3612
3709
  * @returns a new Vector3 containing the Euler angles
3613
3710
  * @see https://doc.babylonjs.com/divingDeeper/mesh/transforms/center_origin/rotation_conventions
3614
3711
  */
@@ -3619,8 +3716,9 @@ export class Quaternion {
3619
3716
  }
3620
3717
  /**
3621
3718
  * Sets the given vector3 "result" with the Euler angles translated from the current quaternion
3719
+ * Example Playground https://playground.babylonjs.com/#L49EJ7#31
3622
3720
  * @param result defines the vector which will be filled with the Euler angles
3623
- * @returns the current unchanged quaternion
3721
+ * @returns result input
3624
3722
  * @see https://doc.babylonjs.com/divingDeeper/mesh/transforms/center_origin/rotation_conventions
3625
3723
  */
3626
3724
  toEulerAnglesToRef(result) {
@@ -3649,19 +3747,21 @@ export class Quaternion {
3649
3747
  result.x = Math.asin(-2.0 * zAxisY);
3650
3748
  result.y = Math.atan2(2.0 * (qz * qx + qy * qw), sqz - sqx - sqy + sqw);
3651
3749
  }
3652
- return this;
3750
+ return result;
3653
3751
  }
3654
3752
  /**
3655
3753
  * Updates the given rotation matrix with the current quaternion values
3754
+ * Example Playground https://playground.babylonjs.com/#L49EJ7#67
3656
3755
  * @param result defines the target matrix
3657
3756
  * @returns the current unchanged quaternion
3658
3757
  */
3659
3758
  toRotationMatrix(result) {
3660
3759
  Matrix.FromQuaternionToRef(this, result);
3661
- return this;
3760
+ return result;
3662
3761
  }
3663
3762
  /**
3664
3763
  * Updates the current quaternion from the given rotation matrix values
3764
+ * Example Playground https://playground.babylonjs.com/#L49EJ7#41
3665
3765
  * @param matrix defines the source matrix
3666
3766
  * @returns the current updated quaternion
3667
3767
  */
@@ -3672,6 +3772,7 @@ export class Quaternion {
3672
3772
  // Statics
3673
3773
  /**
3674
3774
  * Creates a new quaternion from a rotation matrix
3775
+ * Example Playground https://playground.babylonjs.com/#L49EJ7#101
3675
3776
  * @param matrix defines the source matrix
3676
3777
  * @returns a new quaternion created from the given rotation matrix values
3677
3778
  */
@@ -3682,8 +3783,10 @@ export class Quaternion {
3682
3783
  }
3683
3784
  /**
3684
3785
  * Updates the given quaternion with the given rotation matrix values
3786
+ * Example Playground https://playground.babylonjs.com/#L49EJ7#102
3685
3787
  * @param matrix defines the source matrix
3686
3788
  * @param result defines the target quaternion
3789
+ * @returns result input
3687
3790
  */
3688
3791
  static FromRotationMatrixToRef(matrix, result) {
3689
3792
  const data = matrix.m;
@@ -3720,37 +3823,11 @@ export class Quaternion {
3720
3823
  result.y = (m23 + m32) / s;
3721
3824
  result.z = 0.25 * s;
3722
3825
  }
3723
- }
3724
- /**
3725
- * Creates the rotation quaternion needed to rotate from one Vector3 onto another Vector3
3726
- * Example PG https://playground.babylonjs.com/#L49EJ7#2
3727
- * @param fromVector the starting vector
3728
- * @param toVector the ending vector
3729
- * @returns the rotation quaternion needed
3730
- */
3731
- static RotationQuaternionFromOnto(fromVector, toVector) {
3732
- const ref = Quaternion.Zero();
3733
- return Quaternion.RotationQuaternionFromOntoToRef(fromVector, toVector, ref);
3734
- }
3735
- /**
3736
- * Creates the rotation quaternion needed to rotate from one Vector3 onto another Vector3 and stores in a result Quaternion
3737
- * Example PG https://playground.babylonjs.com/#L49EJ7#3
3738
- * @param fromVector the starting vector
3739
- * @param toVector the ending vector
3740
- * @param result the rotation quaternion needed
3741
- * @returns the result
3742
- */
3743
- static RotationQuaternionFromOntoToRef(fromVector, toVector, result) {
3744
- const normal = TmpVectors.Vector3[0];
3745
- Vector3.CrossToRef(fromVector, toVector, normal);
3746
- if (normal.equals(Vector3.ZeroReadOnly)) {
3747
- fromVector._getNormalToRef(normal);
3748
- }
3749
- const angle = Vector3.GetAngleBetweenVectors(fromVector, toVector, normal);
3750
- return Quaternion.RotationAxisToRef(normal, angle, result);
3826
+ return result;
3751
3827
  }
3752
3828
  /**
3753
3829
  * Returns the dot product (float) between the quaternions "left" and "right"
3830
+ * Example Playground https://playground.babylonjs.com/#L49EJ7#61
3754
3831
  * @param left defines the left operand
3755
3832
  * @param right defines the right operand
3756
3833
  * @returns the dot product
@@ -3760,6 +3837,7 @@ export class Quaternion {
3760
3837
  }
3761
3838
  /**
3762
3839
  * Checks if the orientations of two rotation quaternions are close to each other
3840
+ * Example Playground https://playground.babylonjs.com/#L49EJ7#60
3763
3841
  * @param quat0 defines the first quaternion to check
3764
3842
  * @param quat1 defines the second quaternion to check
3765
3843
  * @param epsilon defines closeness, 0 same orientation, 1 PI apart, default 0.1
@@ -3771,7 +3849,7 @@ export class Quaternion {
3771
3849
  }
3772
3850
  /**
3773
3851
  * Smooth interpolation between two quaternions using Slerp
3774
- *
3852
+ * Example Playground https://playground.babylonjs.com/#L49EJ7#93
3775
3853
  * @param source source quaternion
3776
3854
  * @param goal goal quaternion
3777
3855
  * @param deltaTime current interpolation frame
@@ -3782,6 +3860,7 @@ export class Quaternion {
3782
3860
  let slerp = lerpTime === 0 ? 1 : deltaTime / lerpTime;
3783
3861
  slerp = Scalar.Clamp(slerp, 0, 1);
3784
3862
  Quaternion.SlerpToRef(source, goal, slerp, result);
3863
+ return result;
3785
3864
  }
3786
3865
  /**
3787
3866
  * Creates an empty quaternion
@@ -3792,14 +3871,16 @@ export class Quaternion {
3792
3871
  }
3793
3872
  /**
3794
3873
  * Inverse a given quaternion
3874
+ * Example Playground https://playground.babylonjs.com/#L49EJ7#103
3795
3875
  * @param q defines the source quaternion
3796
3876
  * @returns a new quaternion as the inverted current quaternion
3797
3877
  */
3798
3878
  static Inverse(q) {
3799
- return new Quaternion(-q._x, -q._y, -q._z, q._w);
3879
+ return new q.constructor(-q._x, -q._y, -q._z, q._w);
3800
3880
  }
3801
3881
  /**
3802
3882
  * Inverse a given quaternion
3883
+ * Example Playground https://playground.babylonjs.com/#L49EJ7#104
3803
3884
  * @param q defines the source quaternion
3804
3885
  * @param result the quaternion the result will be stored in
3805
3886
  * @returns the result quaternion
@@ -3825,6 +3906,7 @@ export class Quaternion {
3825
3906
  }
3826
3907
  /**
3827
3908
  * Creates a quaternion from a rotation around an axis
3909
+ * Example Playground https://playground.babylonjs.com/#L49EJ7#72
3828
3910
  * @param axis defines the axis to use
3829
3911
  * @param angle defines the angle to use
3830
3912
  * @returns a new quaternion created from the given axis (Vector3) and angle in radians (float)
@@ -3834,6 +3916,7 @@ export class Quaternion {
3834
3916
  }
3835
3917
  /**
3836
3918
  * Creates a rotation around an axis and stores it into the given quaternion
3919
+ * Example Playground https://playground.babylonjs.com/#L49EJ7#73
3837
3920
  * @param axis defines the axis to use
3838
3921
  * @param angle defines the angle to use
3839
3922
  * @param result defines the target quaternion
@@ -3850,6 +3933,7 @@ export class Quaternion {
3850
3933
  }
3851
3934
  /**
3852
3935
  * Creates a new quaternion from data stored into an array
3936
+ * Example Playground https://playground.babylonjs.com/#L49EJ7#63
3853
3937
  * @param array defines the data source
3854
3938
  * @param offset defines the offset in the source array where the data starts
3855
3939
  * @returns a new quaternion
@@ -3862,18 +3946,22 @@ export class Quaternion {
3862
3946
  }
3863
3947
  /**
3864
3948
  * Updates the given quaternion "result" from the starting index of the given array.
3949
+ * Example Playground https://playground.babylonjs.com/#L49EJ7#64
3865
3950
  * @param array the array to pull values from
3866
3951
  * @param offset the offset into the array to start at
3867
3952
  * @param result the quaternion to store the result in
3953
+ * @returns result input
3868
3954
  */
3869
3955
  static FromArrayToRef(array, offset, result) {
3870
3956
  result.x = array[offset];
3871
3957
  result.y = array[offset + 1];
3872
3958
  result.z = array[offset + 2];
3873
3959
  result.w = array[offset + 3];
3960
+ return result;
3874
3961
  }
3875
3962
  /**
3876
3963
  * Create a quaternion from Euler rotation angles
3964
+ * Example Playground https://playground.babylonjs.com/#L49EJ7#33
3877
3965
  * @param x Pitch
3878
3966
  * @param y Yaw
3879
3967
  * @param z Roll
@@ -3886,6 +3974,7 @@ export class Quaternion {
3886
3974
  }
3887
3975
  /**
3888
3976
  * Updates a quaternion from Euler rotation angles
3977
+ * Example Playground https://playground.babylonjs.com/#L49EJ7#34
3889
3978
  * @param x Pitch
3890
3979
  * @param y Yaw
3891
3980
  * @param z Roll
@@ -3898,6 +3987,7 @@ export class Quaternion {
3898
3987
  }
3899
3988
  /**
3900
3989
  * Create a quaternion from Euler rotation vector
3990
+ * Example Playground https://playground.babylonjs.com/#L49EJ7#35
3901
3991
  * @param vec the Euler vector (x Pitch, y Yaw, z Roll)
3902
3992
  * @returns the new Quaternion
3903
3993
  */
@@ -3908,6 +3998,7 @@ export class Quaternion {
3908
3998
  }
3909
3999
  /**
3910
4000
  * Updates a quaternion from Euler rotation vector
4001
+ * Example Playground https://playground.babylonjs.com/#L49EJ7#36
3911
4002
  * @param vec the Euler vector (x Pitch, y Yaw, z Roll)
3912
4003
  * @param result the quaternion to store the result
3913
4004
  * @returns the updated quaternion
@@ -3918,6 +4009,7 @@ export class Quaternion {
3918
4009
  }
3919
4010
  /**
3920
4011
  * Updates a quaternion so that it rotates vector vecFrom to vector vecTo
4012
+ * Example Playground - https://playground.babylonjs.com/#L49EJ7#70
3921
4013
  * @param vecFrom defines the direction vector from which to rotate
3922
4014
  * @param vecTo defines the direction vector to which to rotate
3923
4015
  * @param result the quaternion to store the result
@@ -3941,6 +4033,7 @@ export class Quaternion {
3941
4033
  }
3942
4034
  /**
3943
4035
  * Creates a new quaternion from the given Euler float angles (y, x, z)
4036
+ * Example Playground https://playground.babylonjs.com/#L49EJ7#77
3944
4037
  * @param yaw defines the rotation around Y axis
3945
4038
  * @param pitch defines the rotation around X axis
3946
4039
  * @param roll defines the rotation around Z axis
@@ -3953,10 +4046,12 @@ export class Quaternion {
3953
4046
  }
3954
4047
  /**
3955
4048
  * Creates a new rotation from the given Euler float angles (y, x, z) and stores it in the target quaternion
4049
+ * Example Playground https://playground.babylonjs.com/#L49EJ7#78
3956
4050
  * @param yaw defines the rotation around Y axis
3957
4051
  * @param pitch defines the rotation around X axis
3958
4052
  * @param roll defines the rotation around Z axis
3959
4053
  * @param result defines the target quaternion
4054
+ * @returns result input
3960
4055
  */
3961
4056
  static RotationYawPitchRollToRef(yaw, pitch, roll, result) {
3962
4057
  // Produces a quaternion from Euler angles in the z-y-x orientation (Tait-Bryan angles)
@@ -3973,9 +4068,11 @@ export class Quaternion {
3973
4068
  result.y = sinYaw * cosPitch * cosRoll - cosYaw * sinPitch * sinRoll;
3974
4069
  result.z = cosYaw * cosPitch * sinRoll - sinYaw * sinPitch * cosRoll;
3975
4070
  result.w = cosYaw * cosPitch * cosRoll + sinYaw * sinPitch * sinRoll;
4071
+ return result;
3976
4072
  }
3977
4073
  /**
3978
4074
  * Creates a new quaternion from the given Euler float angles expressed in z-x-z orientation
4075
+ * Example Playground https://playground.babylonjs.com/#L49EJ7#68
3979
4076
  * @param alpha defines the rotation around first axis
3980
4077
  * @param beta defines the rotation around second axis
3981
4078
  * @param gamma defines the rotation around third axis
@@ -3988,10 +4085,12 @@ export class Quaternion {
3988
4085
  }
3989
4086
  /**
3990
4087
  * Creates a new quaternion from the given Euler float angles expressed in z-x-z orientation and stores it in the target quaternion
4088
+ * Example Playground https://playground.babylonjs.com/#L49EJ7#69
3991
4089
  * @param alpha defines the rotation around first axis
3992
4090
  * @param beta defines the rotation around second axis
3993
4091
  * @param gamma defines the rotation around third axis
3994
4092
  * @param result defines the target quaternion
4093
+ * @returns result input
3995
4094
  */
3996
4095
  static RotationAlphaBetaGammaToRef(alpha, beta, gamma, result) {
3997
4096
  // Produces a quaternion from Euler angles in the z-x-z orientation
@@ -4002,9 +4101,11 @@ export class Quaternion {
4002
4101
  result.y = Math.sin(halfGammaMinusAlpha) * Math.sin(halfBeta);
4003
4102
  result.z = Math.sin(halfGammaPlusAlpha) * Math.cos(halfBeta);
4004
4103
  result.w = Math.cos(halfGammaPlusAlpha) * Math.cos(halfBeta);
4104
+ return result;
4005
4105
  }
4006
4106
  /**
4007
4107
  * 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)
4108
+ * Example Playground https://playground.babylonjs.com/#L49EJ7#75
4008
4109
  * @param axis1 defines the first axis
4009
4110
  * @param axis2 defines the second axis
4010
4111
  * @param axis3 defines the third axis
@@ -4017,19 +4118,23 @@ export class Quaternion {
4017
4118
  }
4018
4119
  /**
4019
4120
  * Creates a rotation value to reach the target (axis1, axis2, axis3) orientation as a rotated XYZ system (axis1, axis2 and axis3 are normalized during this operation) and stores it in the target quaternion
4121
+ * Example Playground https://playground.babylonjs.com/#L49EJ7#76
4020
4122
  * @param axis1 defines the first axis
4021
4123
  * @param axis2 defines the second axis
4022
4124
  * @param axis3 defines the third axis
4023
4125
  * @param ref defines the target quaternion
4126
+ * @returns result input
4024
4127
  */
4025
4128
  static RotationQuaternionFromAxisToRef(axis1, axis2, axis3, ref) {
4026
4129
  const rotMat = MathTmp.Matrix[0];
4027
4130
  Matrix.FromXYZAxesToRef(axis1.normalize(), axis2.normalize(), axis3.normalize(), rotMat);
4028
4131
  Quaternion.FromRotationMatrixToRef(rotMat, ref);
4132
+ return ref;
4029
4133
  }
4030
4134
  /**
4031
4135
  * Creates a new rotation value to orient an object to look towards the given forward direction, the up direction being oriented like "up".
4032
4136
  * This function works in left handed mode
4137
+ * Example Playground https://playground.babylonjs.com/#L49EJ7#96
4033
4138
  * @param forward defines the forward direction - Must be normalized and orthogonal to up.
4034
4139
  * @param up defines the up vector for the entity - Must be normalized and orthogonal to forward.
4035
4140
  * @returns A new quaternion oriented toward the specified forward and up.
@@ -4042,18 +4147,22 @@ export class Quaternion {
4042
4147
  /**
4043
4148
  * Creates a new rotation value to orient an object to look towards the given forward direction with the up direction being oriented like "up", and stores it in the target quaternion.
4044
4149
  * This function works in left handed mode
4150
+ * Example Playground https://playground.babylonjs.com/#L49EJ7#97
4045
4151
  * @param forward defines the forward direction - Must be normalized and orthogonal to up.
4046
4152
  * @param up defines the up vector for the entity - Must be normalized and orthogonal to forward.
4047
4153
  * @param ref defines the target quaternion.
4154
+ * @returns result input
4048
4155
  */
4049
4156
  static FromLookDirectionLHToRef(forward, up, ref) {
4050
4157
  const rotMat = MathTmp.Matrix[0];
4051
4158
  Matrix.LookDirectionLHToRef(forward, up, rotMat);
4052
4159
  Quaternion.FromRotationMatrixToRef(rotMat, ref);
4160
+ return ref;
4053
4161
  }
4054
4162
  /**
4055
4163
  * Creates a new rotation value to orient an object to look towards the given forward direction, the up direction being oriented like "up".
4056
4164
  * This function works in right handed mode
4165
+ * Example Playground https://playground.babylonjs.com/#L49EJ7#98
4057
4166
  * @param forward defines the forward direction - Must be normalized and orthogonal to up.
4058
4167
  * @param up defines the up vector for the entity - Must be normalized and orthogonal to forward.
4059
4168
  * @returns A new quaternion oriented toward the specified forward and up.
@@ -4066,9 +4175,11 @@ export class Quaternion {
4066
4175
  /**
4067
4176
  * Creates a new rotation value to orient an object to look towards the given forward direction with the up direction being oriented like "up", and stores it in the target quaternion.
4068
4177
  * This function works in right handed mode
4178
+ * Example Playground https://playground.babylonjs.com/#L49EJ7#105
4069
4179
  * @param forward defines the forward direction - Must be normalized and orthogonal to up.
4070
4180
  * @param up defines the up vector for the entity - Must be normalized and orthogonal to forward.
4071
4181
  * @param ref defines the target quaternion.
4182
+ * @returns result input
4072
4183
  */
4073
4184
  static FromLookDirectionRHToRef(forward, up, ref) {
4074
4185
  const rotMat = MathTmp.Matrix[0];
@@ -4077,6 +4188,7 @@ export class Quaternion {
4077
4188
  }
4078
4189
  /**
4079
4190
  * Interpolates between two quaternions
4191
+ * Example Playground https://playground.babylonjs.com/#L49EJ7#79
4080
4192
  * @param left defines first quaternion
4081
4193
  * @param right defines second quaternion
4082
4194
  * @param amount defines the gradient to use
@@ -4089,10 +4201,12 @@ export class Quaternion {
4089
4201
  }
4090
4202
  /**
4091
4203
  * Interpolates between two quaternions and stores it into a target quaternion
4204
+ * Example Playground https://playground.babylonjs.com/#L49EJ7#92
4092
4205
  * @param left defines first quaternion
4093
4206
  * @param right defines second quaternion
4094
4207
  * @param amount defines the gradient to use
4095
4208
  * @param result defines the target quaternion
4209
+ * @returns result input
4096
4210
  */
4097
4211
  static SlerpToRef(left, right, amount, result) {
4098
4212
  let num2;
@@ -4117,9 +4231,12 @@ export class Quaternion {
4117
4231
  result.y = num3 * left._y + num2 * right._y;
4118
4232
  result.z = num3 * left._z + num2 * right._z;
4119
4233
  result.w = num3 * left._w + num2 * right._w;
4234
+ return result;
4120
4235
  }
4121
4236
  /**
4122
4237
  * Interpolate between two quaternions using Hermite interpolation
4238
+ * Example Playground https://playground.babylonjs.com/#L49EJ7#47
4239
+ * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/drawCurves#hermite-quaternion-spline
4123
4240
  * @param value1 defines first quaternion
4124
4241
  * @param tangent1 defines the incoming tangent
4125
4242
  * @param value2 defines second quaternion
@@ -4138,10 +4255,11 @@ export class Quaternion {
4138
4255
  const y = value1._y * part1 + value2._y * part2 + tangent1._y * part3 + tangent2._y * part4;
4139
4256
  const z = value1._z * part1 + value2._z * part2 + tangent1._z * part3 + tangent2._z * part4;
4140
4257
  const w = value1._w * part1 + value2._w * part2 + tangent1._w * part3 + tangent2._w * part4;
4141
- return new Quaternion(x, y, z, w);
4258
+ return new value1.constructor(x, y, z, w);
4142
4259
  }
4143
4260
  /**
4144
4261
  * Returns a new Quaternion which is the 1st derivative of the Hermite spline defined by the quaternions "value1", "value2", "tangent1", "tangent2".
4262
+ * Example Playground https://playground.babylonjs.com/#L49EJ7#48
4145
4263
  * @param value1 defines the first control point
4146
4264
  * @param tangent1 defines the first tangent
4147
4265
  * @param value2 defines the second control point
@@ -4150,18 +4268,20 @@ export class Quaternion {
4150
4268
  * @returns 1st derivative
4151
4269
  */
4152
4270
  static Hermite1stDerivative(value1, tangent1, value2, tangent2, time) {
4153
- const result = Quaternion.Zero();
4271
+ const result = new value1.constructor();
4154
4272
  this.Hermite1stDerivativeToRef(value1, tangent1, value2, tangent2, time, result);
4155
4273
  return result;
4156
4274
  }
4157
4275
  /**
4158
4276
  * Update a Quaternion with the 1st derivative of the Hermite spline defined by the quaternions "value1", "value2", "tangent1", "tangent2".
4277
+ * Example Playground https://playground.babylonjs.com/#L49EJ7#49
4159
4278
  * @param value1 defines the first control point
4160
4279
  * @param tangent1 defines the first tangent
4161
4280
  * @param value2 defines the second control point
4162
4281
  * @param tangent2 defines the second tangent
4163
4282
  * @param time define where the derivative must be done
4164
4283
  * @param result define where to store the derivative
4284
+ * @returns result input
4165
4285
  */
4166
4286
  static Hermite1stDerivativeToRef(value1, tangent1, value2, tangent2, time, result) {
4167
4287
  const t2 = time * time;
@@ -4169,6 +4289,7 @@ export class Quaternion {
4169
4289
  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
4290
  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
4291
  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;
4292
+ return result;
4172
4293
  }
4173
4294
  }
4174
4295
  /**
@@ -4355,7 +4476,7 @@ export class Matrix {
4355
4476
  * @returns a new matrix as the addition of the current matrix and the given one
4356
4477
  */
4357
4478
  add(other) {
4358
- const result = new Matrix();
4479
+ const result = new this.constructor();
4359
4480
  this.addToRef(other, result);
4360
4481
  return result;
4361
4482
  }
@@ -4363,7 +4484,7 @@ export class Matrix {
4363
4484
  * Sets the given matrix "result" to the addition of the current matrix and the given one
4364
4485
  * @param other defines the matrix to add
4365
4486
  * @param result defines the target matrix
4366
- * @returns the current matrix
4487
+ * @returns result input
4367
4488
  */
4368
4489
  addToRef(other, result) {
4369
4490
  const m = this._m;
@@ -4373,7 +4494,7 @@ export class Matrix {
4373
4494
  resultM[index] = m[index] + otherM[index];
4374
4495
  }
4375
4496
  result.markAsUpdated();
4376
- return this;
4497
+ return result;
4377
4498
  }
4378
4499
  /**
4379
4500
  * Adds in place the given matrix to the current matrix
@@ -4392,12 +4513,12 @@ export class Matrix {
4392
4513
  /**
4393
4514
  * Sets the given matrix to the current inverted Matrix
4394
4515
  * @param other defines the target matrix
4395
- * @returns the unmodified current matrix
4516
+ * @returns result input
4396
4517
  */
4397
4518
  invertToRef(other) {
4398
4519
  if (this._isIdentity === true) {
4399
4520
  Matrix.IdentityToRef(other);
4400
- return this;
4521
+ return other;
4401
4522
  }
4402
4523
  // the inverse of a Matrix is the transpose of cofactor matrix divided by the determinant
4403
4524
  const m = this._m;
@@ -4419,7 +4540,7 @@ export class Matrix {
4419
4540
  if (det === 0) {
4420
4541
  // not invertible
4421
4542
  other.copyFrom(this);
4422
- return this;
4543
+ return other;
4423
4544
  }
4424
4545
  const detInv = 1 / det;
4425
4546
  const det_12_33 = m12 * m33 - m32 * m13;
@@ -4447,7 +4568,7 @@ export class Matrix {
4447
4568
  const cofact_32 = -(m00 * det_11_23 - m01 * det_10_23 + m03 * det_10_21);
4448
4569
  const cofact_33 = +(m00 * det_11_22 - m01 * det_10_22 + m02 * det_10_21);
4449
4570
  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 this;
4571
+ return other;
4451
4572
  }
4452
4573
  /**
4453
4574
  * add a value at the specified position in the current Matrix
@@ -4523,7 +4644,7 @@ export class Matrix {
4523
4644
  result.x = this._m[12];
4524
4645
  result.y = this._m[13];
4525
4646
  result.z = this._m[14];
4526
- return this;
4647
+ return result;
4527
4648
  }
4528
4649
  /**
4529
4650
  * Remove rotation and scaling part from the matrix
@@ -4541,7 +4662,7 @@ export class Matrix {
4541
4662
  * @returns a new matrix set with the multiplication result of the current Matrix and the given one
4542
4663
  */
4543
4664
  multiply(other) {
4544
- const result = new Matrix();
4665
+ const result = new this.constructor();
4545
4666
  this.multiplyToRef(other, result);
4546
4667
  return result;
4547
4668
  }
@@ -4587,20 +4708,20 @@ export class Matrix {
4587
4708
  * Sets the given matrix "result" with the multiplication result of the current Matrix and the given one
4588
4709
  * @param other defines the second operand
4589
4710
  * @param result defines the matrix where to store the multiplication
4590
- * @returns the current matrix
4711
+ * @returns result input
4591
4712
  */
4592
4713
  multiplyToRef(other, result) {
4593
4714
  if (this._isIdentity) {
4594
4715
  result.copyFrom(other);
4595
- return this;
4716
+ return result;
4596
4717
  }
4597
4718
  if (other._isIdentity) {
4598
4719
  result.copyFrom(this);
4599
- return this;
4720
+ return result;
4600
4721
  }
4601
4722
  this.multiplyToArray(other, result._m, 0);
4602
4723
  result.markAsUpdated();
4603
- return this;
4724
+ return result;
4604
4725
  }
4605
4726
  /**
4606
4727
  * Sets the Float32Array "result" from the given index "offset" with the multiplication of the current matrix and the given one
@@ -4677,7 +4798,7 @@ export class Matrix {
4677
4798
  * @returns a new matrix from the current matrix
4678
4799
  */
4679
4800
  clone() {
4680
- const matrix = new Matrix();
4801
+ const matrix = new this.constructor();
4681
4802
  matrix.copyFrom(this);
4682
4803
  return matrix;
4683
4804
  }
@@ -4779,7 +4900,7 @@ export class Matrix {
4779
4900
  * Gets specific row of the matrix to ref
4780
4901
  * @param index defines the number of the row to get
4781
4902
  * @param rowVector vector to store the index-th row of the current matrix
4782
- * @returns the current matrix
4903
+ * @returns result input
4783
4904
  */
4784
4905
  getRowToRef(index, rowVector) {
4785
4906
  if (index >= 0 && index < 3) {
@@ -4789,7 +4910,7 @@ export class Matrix {
4789
4910
  rowVector.z = this._m[i + 2];
4790
4911
  rowVector.w = this._m[i + 3];
4791
4912
  }
4792
- return this;
4913
+ return rowVector;
4793
4914
  }
4794
4915
  /**
4795
4916
  * Sets the index-th row of the current matrix to the vector4 values
@@ -4805,16 +4926,18 @@ export class Matrix {
4805
4926
  * @returns the new transposed matrix
4806
4927
  */
4807
4928
  transpose() {
4808
- return Matrix.Transpose(this);
4929
+ const result = new this.constructor();
4930
+ Matrix.TransposeToRef(this, result);
4931
+ return result;
4809
4932
  }
4810
4933
  /**
4811
4934
  * Compute the transpose of the matrix and store it in a given matrix
4812
4935
  * @param result defines the target matrix
4813
- * @returns the current matrix
4936
+ * @returns result input
4814
4937
  */
4815
4938
  transposeToRef(result) {
4816
4939
  Matrix.TransposeToRef(this, result);
4817
- return this;
4940
+ return result;
4818
4941
  }
4819
4942
  /**
4820
4943
  * Sets the index-th row of the current matrix with the given 4 x float values
@@ -4843,7 +4966,7 @@ export class Matrix {
4843
4966
  * @returns a new matrix
4844
4967
  */
4845
4968
  scale(scale) {
4846
- const result = new Matrix();
4969
+ const result = new this.constructor();
4847
4970
  this.scaleToRef(scale, result);
4848
4971
  return result;
4849
4972
  }
@@ -4851,27 +4974,27 @@ export class Matrix {
4851
4974
  * Scale the current matrix values by a factor to a given result matrix
4852
4975
  * @param scale defines the scale factor
4853
4976
  * @param result defines the matrix to store the result
4854
- * @returns the current matrix
4977
+ * @returns result input
4855
4978
  */
4856
4979
  scaleToRef(scale, result) {
4857
4980
  for (let index = 0; index < 16; index++) {
4858
4981
  result._m[index] = this._m[index] * scale;
4859
4982
  }
4860
4983
  result.markAsUpdated();
4861
- return this;
4984
+ return result;
4862
4985
  }
4863
4986
  /**
4864
4987
  * Scale the current matrix values by a factor and add the result to a given matrix
4865
4988
  * @param scale defines the scale factor
4866
4989
  * @param result defines the Matrix to store the result
4867
- * @returns the current matrix
4990
+ * @returns result input
4868
4991
  */
4869
4992
  scaleAndAddToRef(scale, result) {
4870
4993
  for (let index = 0; index < 16; index++) {
4871
4994
  result._m[index] += this._m[index] * scale;
4872
4995
  }
4873
4996
  result.markAsUpdated();
4874
- return this;
4997
+ return result;
4875
4998
  }
4876
4999
  /**
4877
5000
  * Writes to the given matrix a normal matrix, computed from this one (using values from identity matrix for fourth row and column).
@@ -4883,31 +5006,32 @@ export class Matrix {
4883
5006
  tmp.transposeToRef(ref);
4884
5007
  const m = ref._m;
4885
5008
  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);
5009
+ return ref;
4886
5010
  }
4887
5011
  /**
4888
5012
  * Gets only rotation part of the current matrix
4889
5013
  * @returns a new matrix sets to the extracted rotation matrix from the current one
4890
5014
  */
4891
5015
  getRotationMatrix() {
4892
- const result = new Matrix();
5016
+ const result = new this.constructor();
4893
5017
  this.getRotationMatrixToRef(result);
4894
5018
  return result;
4895
5019
  }
4896
5020
  /**
4897
5021
  * Extracts the rotation matrix from the current one and sets it as the given "result"
4898
5022
  * @param result defines the target matrix to store data to
4899
- * @returns the current matrix
5023
+ * @returns result input
4900
5024
  */
4901
5025
  getRotationMatrixToRef(result) {
4902
5026
  const scale = MathTmp.Vector3[0];
4903
5027
  if (!this.decompose(scale)) {
4904
5028
  Matrix.IdentityToRef(result);
4905
- return this;
5029
+ return result;
4906
5030
  }
4907
5031
  const m = this._m;
4908
5032
  const sx = 1 / scale._x, sy = 1 / scale._y, sz = 1 / scale._z;
4909
5033
  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 this;
5034
+ return result;
4911
5035
  }
4912
5036
  /**
4913
5037
  * Toggles model matrix from being right handed to left handed in place and vice versa
@@ -4920,6 +5044,7 @@ export class Matrix {
4920
5044
  m[9] *= -1;
4921
5045
  m[14] *= -1;
4922
5046
  this.markAsUpdated();
5047
+ return this;
4923
5048
  }
4924
5049
  /**
4925
5050
  * Toggles projection matrix from being right handed to left handed in place and vice versa
@@ -4931,6 +5056,7 @@ export class Matrix {
4931
5056
  m[10] *= -1;
4932
5057
  m[11] *= -1;
4933
5058
  this.markAsUpdated();
5059
+ return this;
4934
5060
  }
4935
5061
  // Statics
4936
5062
  /**
@@ -4949,12 +5075,14 @@ export class Matrix {
4949
5075
  * @param array defines the source array
4950
5076
  * @param offset defines an offset in the source array
4951
5077
  * @param result defines the target matrix
5078
+ * @returns result input
4952
5079
  */
4953
5080
  static FromArrayToRef(array, offset, result) {
4954
5081
  for (let index = 0; index < 16; index++) {
4955
5082
  result._m[index] = array[index + offset];
4956
5083
  }
4957
5084
  result.markAsUpdated();
5085
+ return result;
4958
5086
  }
4959
5087
  /**
4960
5088
  * Stores an array into a matrix after having multiplied each component by a given factor
@@ -4962,12 +5090,14 @@ export class Matrix {
4962
5090
  * @param offset defines the offset in the source array
4963
5091
  * @param scale defines the scaling factor
4964
5092
  * @param result defines the target matrix
5093
+ * @returns result input
4965
5094
  */
4966
5095
  static FromFloat32ArrayToRefScaled(array, offset, scale, result) {
4967
5096
  for (let index = 0; index < 16; index++) {
4968
5097
  result._m[index] = array[index + offset] * scale;
4969
5098
  }
4970
5099
  result.markAsUpdated();
5100
+ return result;
4971
5101
  }
4972
5102
  /**
4973
5103
  * Gets an identity matrix that must not be updated
@@ -4994,6 +5124,7 @@ export class Matrix {
4994
5124
  * @param initialM43 defines 3rd value of 4th row
4995
5125
  * @param initialM44 defines 4th value of 4th row
4996
5126
  * @param result defines the target matrix
5127
+ * @returns result input
4997
5128
  */
4998
5129
  static FromValuesToRef(initialM11, initialM12, initialM13, initialM14, initialM21, initialM22, initialM23, initialM24, initialM31, initialM32, initialM33, initialM34, initialM41, initialM42, initialM43, initialM44, result) {
4999
5130
  const m = result._m;
@@ -5075,6 +5206,7 @@ export class Matrix {
5075
5206
  * @param rotation defines the rotation quaternion
5076
5207
  * @param translation defines the translation vector3
5077
5208
  * @param result defines the target matrix
5209
+ * @returns result input
5078
5210
  */
5079
5211
  static ComposeToRef(scale, rotation, translation, result) {
5080
5212
  const m = result._m;
@@ -5101,6 +5233,7 @@ export class Matrix {
5101
5233
  m[14] = translation._z;
5102
5234
  m[15] = 1;
5103
5235
  result.markAsUpdated();
5236
+ return result;
5104
5237
  }
5105
5238
  /**
5106
5239
  * Creates a new identity matrix
@@ -5114,10 +5247,12 @@ export class Matrix {
5114
5247
  /**
5115
5248
  * Creates a new identity matrix and stores the result in a given matrix
5116
5249
  * @param result defines the target matrix
5250
+ * @returns result input
5117
5251
  */
5118
5252
  static IdentityToRef(result) {
5119
5253
  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
5254
  result._updateIdentityStatus(true);
5255
+ return result;
5121
5256
  }
5122
5257
  /**
5123
5258
  * Creates a new zero matrix
@@ -5144,7 +5279,7 @@ export class Matrix {
5144
5279
  * @returns the new matrix
5145
5280
  */
5146
5281
  static Invert(source) {
5147
- const result = new Matrix();
5282
+ const result = new source.constructor();
5148
5283
  source.invertToRef(result);
5149
5284
  return result;
5150
5285
  }
@@ -5152,12 +5287,14 @@ export class Matrix {
5152
5287
  * Creates a new rotation matrix for "angle" radians around the X axis and stores it in a given matrix
5153
5288
  * @param angle defines the angle (in radians) to use
5154
5289
  * @param result defines the target matrix
5290
+ * @returns result input
5155
5291
  */
5156
5292
  static RotationXToRef(angle, result) {
5157
5293
  const s = Math.sin(angle);
5158
5294
  const c = Math.cos(angle);
5159
5295
  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
5296
  result._updateIdentityStatus(c === 1 && s === 0);
5297
+ return result;
5161
5298
  }
5162
5299
  /**
5163
5300
  * Creates a new rotation matrix for "angle" radians around the Y axis
@@ -5173,12 +5310,14 @@ export class Matrix {
5173
5310
  * Creates a new rotation matrix for "angle" radians around the Y axis and stores it in a given matrix
5174
5311
  * @param angle defines the angle (in radians) to use
5175
5312
  * @param result defines the target matrix
5313
+ * @returns result input
5176
5314
  */
5177
5315
  static RotationYToRef(angle, result) {
5178
5316
  const s = Math.sin(angle);
5179
5317
  const c = Math.cos(angle);
5180
5318
  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
5319
  result._updateIdentityStatus(c === 1 && s === 0);
5320
+ return result;
5182
5321
  }
5183
5322
  /**
5184
5323
  * Creates a new rotation matrix for "angle" radians around the Z axis
@@ -5194,12 +5333,14 @@ export class Matrix {
5194
5333
  * Creates a new rotation matrix for "angle" radians around the Z axis and stores it in a given matrix
5195
5334
  * @param angle defines the angle (in radians) to use
5196
5335
  * @param result defines the target matrix
5336
+ * @returns result input
5197
5337
  */
5198
5338
  static RotationZToRef(angle, result) {
5199
5339
  const s = Math.sin(angle);
5200
5340
  const c = Math.cos(angle);
5201
5341
  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
5342
  result._updateIdentityStatus(c === 1 && s === 0);
5343
+ return result;
5203
5344
  }
5204
5345
  /**
5205
5346
  * Creates a new rotation matrix for "angle" radians around the given axis
@@ -5217,6 +5358,7 @@ export class Matrix {
5217
5358
  * @param axis defines the axis to use
5218
5359
  * @param angle defines the angle (in radians) to use
5219
5360
  * @param result defines the target matrix
5361
+ * @returns result input
5220
5362
  */
5221
5363
  static RotationAxisToRef(axis, angle, result) {
5222
5364
  const s = Math.sin(-angle);
@@ -5241,6 +5383,7 @@ export class Matrix {
5241
5383
  m[14] = 0.0;
5242
5384
  m[15] = 1.0;
5243
5385
  result.markAsUpdated();
5386
+ return result;
5244
5387
  }
5245
5388
  /**
5246
5389
  * Takes normalised vectors and returns a rotation matrix to align "from" with "to".
@@ -5248,6 +5391,7 @@ export class Matrix {
5248
5391
  * @param from defines the vector to align
5249
5392
  * @param to defines the vector to align to
5250
5393
  * @param result defines the target matrix
5394
+ * @returns result input
5251
5395
  */
5252
5396
  static RotationAlignToRef(from, to, result) {
5253
5397
  const c = Vector3.Dot(to, from);
@@ -5289,6 +5433,7 @@ export class Matrix {
5289
5433
  m[14] = 0;
5290
5434
  m[15] = 1;
5291
5435
  result.markAsUpdated();
5436
+ return result;
5292
5437
  }
5293
5438
  /**
5294
5439
  * Creates a rotation matrix
@@ -5308,10 +5453,12 @@ export class Matrix {
5308
5453
  * @param pitch defines the pitch angle in radians (X axis)
5309
5454
  * @param roll defines the roll angle in radians (Z axis)
5310
5455
  * @param result defines the target matrix
5456
+ * @returns result input
5311
5457
  */
5312
5458
  static RotationYawPitchRollToRef(yaw, pitch, roll, result) {
5313
5459
  Quaternion.RotationYawPitchRollToRef(yaw, pitch, roll, MathTmp.Quaternion[0]);
5314
5460
  MathTmp.Quaternion[0].toRotationMatrix(result);
5461
+ return result;
5315
5462
  }
5316
5463
  /**
5317
5464
  * Creates a scaling matrix
@@ -5331,10 +5478,12 @@ export class Matrix {
5331
5478
  * @param y defines the scale factor on Y axis
5332
5479
  * @param z defines the scale factor on Z axis
5333
5480
  * @param result defines the target matrix
5481
+ * @returns result input
5334
5482
  */
5335
5483
  static ScalingToRef(x, y, z, result) {
5336
5484
  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
5485
  result._updateIdentityStatus(x === 1 && y === 1 && z === 1);
5486
+ return result;
5338
5487
  }
5339
5488
  /**
5340
5489
  * Creates a translation matrix
@@ -5354,10 +5503,12 @@ export class Matrix {
5354
5503
  * @param y defines the translation on Y axis
5355
5504
  * @param z defines the translationon Z axis
5356
5505
  * @param result defines the target matrix
5506
+ * @returns result input
5357
5507
  */
5358
5508
  static TranslationToRef(x, y, z, result) {
5359
5509
  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
5510
  result._updateIdentityStatus(x === 0 && y === 0 && z === 0);
5511
+ return result;
5361
5512
  }
5362
5513
  /**
5363
5514
  * Returns a new Matrix whose values are the interpolated values for "gradient" (float) between the ones of the matrices "startValue" and "endValue".
@@ -5367,7 +5518,7 @@ export class Matrix {
5367
5518
  * @returns the new matrix
5368
5519
  */
5369
5520
  static Lerp(startValue, endValue, gradient) {
5370
- const result = new Matrix();
5521
+ const result = new startValue.constructor();
5371
5522
  Matrix.LerpToRef(startValue, endValue, gradient, result);
5372
5523
  return result;
5373
5524
  }
@@ -5377,6 +5528,7 @@ export class Matrix {
5377
5528
  * @param endValue defines the end value
5378
5529
  * @param gradient defines the gradient factor
5379
5530
  * @param result defines the Matrix object where to store data
5531
+ * @returns result input
5380
5532
  */
5381
5533
  static LerpToRef(startValue, endValue, gradient, result) {
5382
5534
  const resultM = result._m;
@@ -5386,6 +5538,7 @@ export class Matrix {
5386
5538
  resultM[index] = startM[index] * (1.0 - gradient) + endM[index] * gradient;
5387
5539
  }
5388
5540
  result.markAsUpdated();
5541
+ return result;
5389
5542
  }
5390
5543
  /**
5391
5544
  * Builds a new matrix whose values are computed by:
@@ -5398,7 +5551,7 @@ export class Matrix {
5398
5551
  * @returns the new matrix
5399
5552
  */
5400
5553
  static DecomposeLerp(startValue, endValue, gradient) {
5401
- const result = new Matrix();
5554
+ const result = new startValue.constructor();
5402
5555
  Matrix.DecomposeLerpToRef(startValue, endValue, gradient, result);
5403
5556
  return result;
5404
5557
  }
@@ -5411,6 +5564,7 @@ export class Matrix {
5411
5564
  * @param endValue defines the second matrix
5412
5565
  * @param gradient defines the gradient between the two matrices
5413
5566
  * @param result defines the target matrix
5567
+ * @returns result input
5414
5568
  */
5415
5569
  static DecomposeLerpToRef(startValue, endValue, gradient, result) {
5416
5570
  const startScale = MathTmp.Vector3[0];
@@ -5428,6 +5582,7 @@ export class Matrix {
5428
5582
  const resultTranslation = MathTmp.Vector3[5];
5429
5583
  Vector3.LerpToRef(startTranslation, endTranslation, gradient, resultTranslation);
5430
5584
  Matrix.ComposeToRef(resultScale, resultRotation, resultTranslation, result);
5585
+ return result;
5431
5586
  }
5432
5587
  /**
5433
5588
  * 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 +5604,7 @@ export class Matrix {
5449
5604
  * @param target defines where the entity should look at
5450
5605
  * @param up defines the up vector for the entity
5451
5606
  * @param result defines the target matrix
5607
+ * @returns result input
5452
5608
  */
5453
5609
  static LookAtLHToRef(eye, target, up, result) {
5454
5610
  const xAxis = MathTmp.Vector3[0];
@@ -5495,6 +5651,7 @@ export class Matrix {
5495
5651
  * @param target defines where the entity should look at
5496
5652
  * @param up defines the up vector for the entity
5497
5653
  * @param result defines the target matrix
5654
+ * @returns result input
5498
5655
  */
5499
5656
  static LookAtRHToRef(eye, target, up, result) {
5500
5657
  const xAxis = MathTmp.Vector3[0];
@@ -5520,6 +5677,7 @@ export class Matrix {
5520
5677
  const ey = -Vector3.Dot(yAxis, eye);
5521
5678
  const ez = -Vector3.Dot(zAxis, eye);
5522
5679
  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);
5680
+ return result;
5523
5681
  }
5524
5682
  /**
5525
5683
  * 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 +5697,7 @@ export class Matrix {
5539
5697
  * @param forward defines the forward direction - Must be normalized and orthogonal to up.
5540
5698
  * @param up defines the up vector for the entity - Must be normalized and orthogonal to forward.
5541
5699
  * @param result defines the target matrix
5700
+ * @returns result input
5542
5701
  */
5543
5702
  static LookDirectionLHToRef(forward, up, result) {
5544
5703
  const back = MathTmp.Vector3[0];
@@ -5548,6 +5707,7 @@ export class Matrix {
5548
5707
  Vector3.CrossToRef(up, back, left);
5549
5708
  // Generate the rotation matrix.
5550
5709
  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);
5710
+ return result;
5551
5711
  }
5552
5712
  /**
5553
5713
  * 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 +5727,14 @@ export class Matrix {
5567
5727
  * @param forward defines the forward direction - Must be normalized and orthogonal to up.
5568
5728
  * @param up defines the up vector for the entity - Must be normalized and orthogonal to forward.
5569
5729
  * @param result defines the target matrix
5730
+ * @returns result input
5570
5731
  */
5571
5732
  static LookDirectionRHToRef(forward, up, result) {
5572
5733
  const right = MathTmp.Vector3[2];
5573
5734
  Vector3.CrossToRef(up, forward, right);
5574
5735
  // Generate the rotation matrix.
5575
5736
  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);
5737
+ return result;
5576
5738
  }
5577
5739
  /**
5578
5740
  * Create a left-handed orthographic projection matrix
@@ -5596,6 +5758,7 @@ export class Matrix {
5596
5758
  * @param zfar defines the far clip plane
5597
5759
  * @param result defines the target matrix
5598
5760
  * @param halfZRange true to generate NDC coordinates between 0 and 1 instead of -1 and 1 (default: false)
5761
+ * @returns result input
5599
5762
  */
5600
5763
  static OrthoLHToRef(width, height, znear, zfar, result, halfZRange) {
5601
5764
  const n = znear;
@@ -5609,6 +5772,7 @@ export class Matrix {
5609
5772
  result.multiplyToRef(mtxConvertNDCToHalfZRange, result);
5610
5773
  }
5611
5774
  result._updateIdentityStatus(a === 1 && b === 1 && c === 1 && d === 0);
5775
+ return result;
5612
5776
  }
5613
5777
  /**
5614
5778
  * Create a left-handed orthographic projection matrix
@@ -5636,6 +5800,7 @@ export class Matrix {
5636
5800
  * @param zfar defines the far clip plane
5637
5801
  * @param result defines the target matrix
5638
5802
  * @param halfZRange true to generate NDC coordinates between 0 and 1 instead of -1 and 1 (default: false)
5803
+ * @returns result input
5639
5804
  */
5640
5805
  static OrthoOffCenterLHToRef(left, right, bottom, top, znear, zfar, result, halfZRange) {
5641
5806
  const n = znear;
@@ -5651,6 +5816,7 @@ export class Matrix {
5651
5816
  result.multiplyToRef(mtxConvertNDCToHalfZRange, result);
5652
5817
  }
5653
5818
  result.markAsUpdated();
5819
+ return result;
5654
5820
  }
5655
5821
  /**
5656
5822
  * Creates a right-handed orthographic projection matrix
@@ -5678,10 +5844,12 @@ export class Matrix {
5678
5844
  * @param zfar defines the far clip plane
5679
5845
  * @param result defines the target matrix
5680
5846
  * @param halfZRange true to generate NDC coordinates between 0 and 1 instead of -1 and 1 (default: false)
5847
+ * @returns result input
5681
5848
  */
5682
5849
  static OrthoOffCenterRHToRef(left, right, bottom, top, znear, zfar, result, halfZRange) {
5683
5850
  Matrix.OrthoOffCenterLHToRef(left, right, bottom, top, znear, zfar, result, halfZRange);
5684
5851
  result._m[10] *= -1; // No need to call markAsUpdated as previous function already called it and let _isIdentityDirty to true
5852
+ return result;
5685
5853
  }
5686
5854
  /**
5687
5855
  * Creates a left-handed perspective projection matrix
@@ -5736,6 +5904,7 @@ export class Matrix {
5736
5904
  * @param halfZRange true to generate NDC coordinates between 0 and 1 instead of -1 and 1 (default: false)
5737
5905
  * @param projectionPlaneTilt optional tilt angle of the projection plane around the X axis (horizontal)
5738
5906
  * @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)
5907
+ * @returns result input
5739
5908
  */
5740
5909
  static PerspectiveFovLHToRef(fov, aspect, znear, zfar, result, isVerticalFovFixed = true, halfZRange, projectionPlaneTilt = 0, reverseDepthBufferMode = false) {
5741
5910
  const n = znear;
@@ -5751,6 +5920,7 @@ export class Matrix {
5751
5920
  result.multiplyToRef(mtxConvertNDCToHalfZRange, result);
5752
5921
  }
5753
5922
  result._updateIdentityStatus(false);
5923
+ return result;
5754
5924
  }
5755
5925
  /**
5756
5926
  * Stores a left-handed perspective projection into a given matrix with depth reversed
@@ -5762,6 +5932,7 @@ export class Matrix {
5762
5932
  * @param isVerticalFovFixed defines it the fov is vertically fixed (default) or horizontally
5763
5933
  * @param halfZRange true to generate NDC coordinates between 0 and 1 instead of -1 and 1 (default: false)
5764
5934
  * @param projectionPlaneTilt optional tilt angle of the projection plane around the X axis (horizontal)
5935
+ * @returns result input
5765
5936
  */
5766
5937
  static PerspectiveFovReverseLHToRef(fov, aspect, znear, zfar, result, isVerticalFovFixed = true, halfZRange, projectionPlaneTilt = 0) {
5767
5938
  const t = 1.0 / Math.tan(fov * 0.5);
@@ -5773,6 +5944,7 @@ export class Matrix {
5773
5944
  result.multiplyToRef(mtxConvertNDCToHalfZRange, result);
5774
5945
  }
5775
5946
  result._updateIdentityStatus(false);
5947
+ return result;
5776
5948
  }
5777
5949
  /**
5778
5950
  * Creates a right-handed perspective projection matrix
@@ -5801,6 +5973,7 @@ export class Matrix {
5801
5973
  * @param halfZRange true to generate NDC coordinates between 0 and 1 instead of -1 and 1 (default: false)
5802
5974
  * @param projectionPlaneTilt optional tilt angle of the projection plane around the X axis (horizontal)
5803
5975
  * @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)
5976
+ * @returns result input
5804
5977
  */
5805
5978
  static PerspectiveFovRHToRef(fov, aspect, znear, zfar, result, isVerticalFovFixed = true, halfZRange, projectionPlaneTilt = 0, reverseDepthBufferMode = false) {
5806
5979
  //alternatively this could be expressed as:
@@ -5820,6 +5993,7 @@ export class Matrix {
5820
5993
  result.multiplyToRef(mtxConvertNDCToHalfZRange, result);
5821
5994
  }
5822
5995
  result._updateIdentityStatus(false);
5996
+ return result;
5823
5997
  }
5824
5998
  /**
5825
5999
  * Stores a right-handed perspective projection into a given matrix
@@ -5831,6 +6005,7 @@ export class Matrix {
5831
6005
  * @param isVerticalFovFixed defines it the fov is vertically fixed (default) or horizontally
5832
6006
  * @param halfZRange true to generate NDC coordinates between 0 and 1 instead of -1 and 1 (default: false)
5833
6007
  * @param projectionPlaneTilt optional tilt angle of the projection plane around the X axis (horizontal)
6008
+ * @returns result input
5834
6009
  */
5835
6010
  static PerspectiveFovReverseRHToRef(fov, aspect, znear, zfar, result, isVerticalFovFixed = true, halfZRange, projectionPlaneTilt = 0) {
5836
6011
  const t = 1.0 / Math.tan(fov * 0.5);
@@ -5842,6 +6017,7 @@ export class Matrix {
5842
6017
  result.multiplyToRef(mtxConvertNDCToHalfZRange, result);
5843
6018
  }
5844
6019
  result._updateIdentityStatus(false);
6020
+ return result;
5845
6021
  }
5846
6022
  /**
5847
6023
  * Stores a perspective projection for WebVR info a given matrix
@@ -5856,6 +6032,7 @@ export class Matrix {
5856
6032
  * @param rightHanded defines if the matrix must be in right-handed mode (false by default)
5857
6033
  * @param halfZRange true to generate NDC coordinates between 0 and 1 instead of -1 and 1 (default: false)
5858
6034
  * @param projectionPlaneTilt optional tilt angle of the projection plane around the X axis (horizontal)
6035
+ * @returns result input
5859
6036
  */
5860
6037
  static PerspectiveFovWebVRToRef(fov, znear, zfar, result, rightHanded = false, halfZRange, projectionPlaneTilt = 0) {
5861
6038
  const rightHandedFactor = rightHanded ? -1 : 1;
@@ -5882,6 +6059,7 @@ export class Matrix {
5882
6059
  result.multiplyToRef(mtxConvertNDCToHalfZRange, result);
5883
6060
  }
5884
6061
  result.markAsUpdated();
6062
+ return result;
5885
6063
  }
5886
6064
  /**
5887
6065
  * Computes a complete transformation matrix
@@ -5899,10 +6077,10 @@ export class Matrix {
5899
6077
  const cx = viewport.x;
5900
6078
  const cy = viewport.y;
5901
6079
  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 = MathTmp.Matrix[0];
6080
+ const matrix = new world.constructor();
5903
6081
  world.multiplyToRef(view, matrix);
5904
6082
  matrix.multiplyToRef(projection, matrix);
5905
- return matrix.multiply(viewportMatrix);
6083
+ return matrix.multiplyToRef(viewportMatrix, matrix);
5906
6084
  }
5907
6085
  /**
5908
6086
  * Extracts a 2x2 matrix from a given matrix and store the result in a Float32Array
@@ -5930,7 +6108,7 @@ export class Matrix {
5930
6108
  * @returns the new matrix
5931
6109
  */
5932
6110
  static Transpose(matrix) {
5933
- const result = new Matrix();
6111
+ const result = new matrix.constructor();
5934
6112
  Matrix.TransposeToRef(matrix, result);
5935
6113
  return result;
5936
6114
  }
@@ -5938,6 +6116,7 @@ export class Matrix {
5938
6116
  * Compute the transpose of a matrix and store it in a target matrix
5939
6117
  * @param matrix defines the matrix to transpose
5940
6118
  * @param result defines the target matrix
6119
+ * @returns result input
5941
6120
  */
5942
6121
  static TransposeToRef(matrix, result) {
5943
6122
  const rm = result._m;
@@ -5961,6 +6140,7 @@ export class Matrix {
5961
6140
  result.markAsUpdated();
5962
6141
  // identity-ness does not change when transposing
5963
6142
  result._updateIdentityStatus(matrix._isIdentity, matrix._isIdentityDirty);
6143
+ return result;
5964
6144
  }
5965
6145
  /**
5966
6146
  * Computes a reflection matrix from a plane
@@ -5976,6 +6156,7 @@ export class Matrix {
5976
6156
  * Computes a reflection matrix from a plane
5977
6157
  * @param plane defines the reflection plane
5978
6158
  * @param result defines the target matrix
6159
+ * @returns result input
5979
6160
  */
5980
6161
  static ReflectionToRef(plane, result) {
5981
6162
  plane.normalize();
@@ -5986,6 +6167,7 @@ export class Matrix {
5986
6167
  const temp2 = -2 * y;
5987
6168
  const temp3 = -2 * z;
5988
6169
  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);
6170
+ return result;
5989
6171
  }
5990
6172
  /**
5991
6173
  * Sets the given matrix as a rotation matrix composed from the 3 left handed axes
@@ -5993,14 +6175,17 @@ export class Matrix {
5993
6175
  * @param yaxis defines the value of the 2nd axis
5994
6176
  * @param zaxis defines the value of the 3rd axis
5995
6177
  * @param result defines the target matrix
6178
+ * @returns result input
5996
6179
  */
5997
6180
  static FromXYZAxesToRef(xaxis, yaxis, zaxis, result) {
5998
6181
  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);
6182
+ return result;
5999
6183
  }
6000
6184
  /**
6001
6185
  * Creates a rotation matrix from a quaternion and stores it in a target matrix
6002
6186
  * @param quat defines the quaternion to use
6003
6187
  * @param result defines the target matrix
6188
+ * @returns result input
6004
6189
  */
6005
6190
  static FromQuaternionToRef(quat, result) {
6006
6191
  const xx = quat._x * quat._x;
@@ -6029,6 +6214,7 @@ export class Matrix {
6029
6214
  result._m[14] = 0.0;
6030
6215
  result._m[15] = 1.0;
6031
6216
  result.markAsUpdated();
6217
+ return result;
6032
6218
  }
6033
6219
  }
6034
6220
  Matrix._UpdateFlagSeed = 0;