@ignifx/core 0.6.1 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{color-CpvebMIh.js → color-DrR6GFTd.js} +3 -276
- package/dist/color-DrR6GFTd.js.map +1 -0
- package/dist/{environment-CvVC1lPa.js → environment-mr5wp69e.js} +5 -4
- package/dist/{environment-CvVC1lPa.js.map → environment-mr5wp69e.js.map} +1 -1
- package/dist/{ignifx-error-R1ma_Lzv.js → ignifx-error-CRh89KUJ.js} +4 -1
- package/dist/ignifx-error-CRh89KUJ.js.map +1 -0
- package/dist/index.d.ts +41 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +210 -1664
- package/dist/index.js.map +1 -1
- package/dist/{instanced-mesh-instance-Cgx1H87p.js → instanced-mesh-instance-gguMoIeZ.js} +74 -10
- package/dist/instanced-mesh-instance-gguMoIeZ.js.map +1 -0
- package/dist/{material-plugin-CTaWZXEk.js → material-plugin-Cfw_h_Mg.js} +2 -2
- package/dist/{material-plugin-CTaWZXEk.js.map → material-plugin-Cfw_h_Mg.js.map} +1 -1
- package/dist/math-utils-BcDnL-gi.js +277 -0
- package/dist/math-utils-BcDnL-gi.js.map +1 -0
- package/dist/{post-effect-compiler-Cq6cshjL.js → post-effect-compiler-Rce26Eue.js} +2 -2
- package/dist/{post-effect-compiler-Cq6cshjL.js.map → post-effect-compiler-Rce26Eue.js.map} +1 -1
- package/dist/shader-declaration-5q__jycG.js.map +1 -1
- package/dist/{shader-material-fOI9Upt3.js → shader-material-BIG3UDyu.js} +4 -4
- package/dist/{shader-material-fOI9Upt3.js.map → shader-material-BIG3UDyu.js.map} +1 -1
- package/dist/{shader-material-BzVY0ySR.js → shader-material-U6BKZ8D1.js} +2 -2
- package/dist/{shader-material-BzVY0ySR.js.map → shader-material-U6BKZ8D1.js.map} +1 -1
- package/dist/{shader-pragma-CNAK4SIb.js → shader-pragma-tw6AKaQD.js} +25 -4
- package/dist/shader-pragma-tw6AKaQD.js.map +1 -0
- package/dist/{surface-shader-fJ2MOez0.js → surface-shader-DAWIDdaa.js} +8 -6
- package/dist/{surface-shader-fJ2MOez0.js.map → surface-shader-DAWIDdaa.js.map} +1 -1
- package/dist/vec3-B31o_KF_.js +2458 -0
- package/dist/vec3-B31o_KF_.js.map +1 -0
- package/package.json +1 -1
- package/dist/color-CpvebMIh.js.map +0 -1
- package/dist/ignifx-error-R1ma_Lzv.js.map +0 -1
- package/dist/instanced-mesh-instance-Cgx1H87p.js.map +0 -1
- package/dist/mesh-CnK_PX46.js +0 -811
- package/dist/mesh-CnK_PX46.js.map +0 -1
- package/dist/shader-pragma-CNAK4SIb.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { a as CORE_ERROR_MESSAGES, c as THIRD_PARTY_ERROR_PREFIX, i as isIgnifxError, l as isValidErrorCode, n as assertNever, o as CoreErrorCode, r as formatErrorMessage, s as ErrorRange, t as IgnifxError } from "./ignifx-error-
|
|
2
|
-
import { _ as
|
|
3
|
-
import { A as
|
|
4
|
-
import {
|
|
5
|
-
import { a as
|
|
1
|
+
import { a as CORE_ERROR_MESSAGES, c as THIRD_PARTY_ERROR_PREFIX, i as isIgnifxError, l as isValidErrorCode, n as assertNever, o as CoreErrorCode, r as formatErrorMessage, s as ErrorRange, t as IgnifxError } from "./ignifx-error-CRh89KUJ.js";
|
|
2
|
+
import { _ as smoothStep, a as clamp, c as deltaAngleDegrees, d as lerpAngleDegrees, f as moveTowards, g as sign, h as repeat, i as approximately, l as inverseLerp, m as radToDeg, n as EPSILON, o as clamp01, p as pingPong, r as RAD_TO_DEG, s as degToRad, t as DEG_TO_RAD, u as lerp, v as wrapAngleDegrees } from "./math-utils-BcDnL-gi.js";
|
|
3
|
+
import { $ as basisToQuatToRef, A as setMeshReceiveShadows, B as localPosition, C as overrideSubtreeMaterials, D as setMeshId, E as setMeshBounds, F as updateMeshPositions$1, G as readWorldMatrix, H as localScale, I as updateMeshUvs$1, J as setNodeSelfVisible, K as reparentKeepingWorld, L as createNode, M as setMeshSubtreeVisible, N as updateMeshColors$1, O as setMeshMaterial, P as updateMeshNormals$1, Q as Mat4, R as disposeNode, S as disposeMeshTemplate, T as removeMeshFromScene, U as parentNode, V as localRotation, W as readNodeTag, X as worldMatrixVersion, Y as tagNode, Z as MAT4_IDENTITY, _ as createMeshFromGeometry, a as VEC3_ONE, b as createTorusMesh, c as VEC3_ZERO, d as cloneMeshUnderNode, f as collectSubtreeMeshes, g as createGroundMesh, h as createCylinderMesh, i as VEC3_LEFT, j as setMeshRenderOrder, k as setMeshPickable, l as Vec3, m as createCapsuleMesh, n as VEC3_DOWN, o as VEC3_RIGHT, p as createBoxMesh, q as setNodeName, r as VEC3_FORWARD, s as VEC3_UP, t as VEC3_BACKWARD, u as addMeshToScene, v as createPlaneMesh, w as recomputeMeshBounds, x as detachMeshBounds, y as createSphereMesh, z as linkParent } from "./vec3-B31o_KF_.js";
|
|
4
|
+
import { t as Color } from "./color-DrR6GFTd.js";
|
|
5
|
+
import { a as readSceneImageProcessing, c as setSceneEnvironmentRotation, l as setSceneFog, n as installSceneEnvironment, o as setSceneClearColor, r as loadSceneEnvironment, s as setSceneEnvironmentBlur, t as TONE_MAPPING_NAMES, u as setSceneImageProcessingOptions } from "./environment-mr5wp69e.js";
|
|
6
|
+
import { a as defineMaterialPlugin, c as MATERIAL_ALPHA_MODES, d as createStandardMaterialFromProps, f as markMaterialDirty, g as setPbrMetallicRoughness, h as setPbrBaseColor, i as MATERIAL_PLUGIN_SAMPLER_BUDGET, l as createDefaultMaterial, m as setMaterialAlpha, n as MATERIAL_PLUGIN_DEFAULT_PRIORITY, o as isLiteMaterialPluginPoint, r as MATERIAL_PLUGIN_RESERVED_NAMES, t as LITE_MATERIAL_PLUGIN_POINTS, u as createPbrMaterialFromProps } from "./material-plugin-Cfw_h_Mg.js";
|
|
6
7
|
import { a as postEffectValuesCodec, i as declaredTextureBinding, n as POST_EFFECT_FUNCTION, o as asJsonArray, r as customEffect, s as asJsonObject, t as POST_EFFECT_BUILTIN_UNIFORMS } from "./post-effect-C42XJFmo.js";
|
|
7
8
|
import { a as SHADER_BLEND_MODES, c as SHADER_KINDS, d as SURFACE_HOOK_NAMES, f as SURFACE_UNIFORM_BLOCK, i as SHADER_ATTRIBUTE_NAMES, l as SHADER_TEXTURE_FALLBACKS, o as SHADER_CULL_MODES, r as LITE_SYSTEM_UNIFORM_NAMES, s as SHADER_INSTANCING_MODES, t as IGNIFX_UNIFORM_NAMES, u as SHADER_UNIFORM_TYPES } from "./shader-declaration-5q__jycG.js";
|
|
8
|
-
import { acquireTexture, addTask, addToScene, buildFrameGraphTask, captureScreenshot, cloneTransformNode, createBloomPostProcessTask, createCopyToTextureTask, createCsmDirectionalShadowGenerator, createDirectionalLight, createEngine, createEsmDirectionalShadowGenerator, createFontFromBuffer, createFreeCamera, createGpuPicker, createHemisphericLight, createImageProcessingTask, createMeshFromData, createNullEngine, createPcfDirectionalShadowGenerator, createPcfSpotlightShadowGenerator, createPointLight, createRenderTarget, createRenderTask, createSceneContext, createSmaaPostProcessTask, createSpotLight, createStorageBuffer, createTexture2DFromPixels, disableOrthographicCamera, disposeEngine, disposePicker, disposeScene, disposeStorageBuffer, enableBoneControl, enableDeviceLostSceneRecovery, enableMaterialPlugins, enableMaterialStencil, enableOrthographicCamera, enablePbrLightmap, enableSkeletonShadows, enableStandardSkeleton, forceWebGpuDeviceLossForTesting, getEffectiveAspectRatio, getFrameGraph, getProjectionMatrix, getRenderTaskGpuTimings, getViewMatrix, getViewProjectionMatrix, isShaderMaterial, loadTexture2D, onBeforeRender, pickAsync, pickWithRay, rebuildSceneRenderables, registerScene, registerSceneWithShadowSupport, releaseTexture, removeFromScene, resizeEngine, resolveCameraViewport, setGpuTimingEnabled, setShadowTaskCasterMeshes, setSubtreeVisible, setSurfaceSize, startEngine, stopEngine, updateStorageBuffer, updateTexture2DFromPixels } from "@babylonjs/lite";
|
|
9
|
+
import { acquireTexture, addTask, addToScene, buildFrameGraphTask, captureScreenshot, cloneTransformNode, createBloomPostProcessTask, createCopyToTextureTask, createCsmDirectionalShadowGenerator, createDirectionalLight, createEngine, createEsmDirectionalShadowGenerator, createFontFromBuffer, createFreeCamera, createGpuPicker, createHemisphericLight, createImageProcessingTask, createMeshFromData, createNullEngine, createPcfDirectionalShadowGenerator, createPcfSpotlightShadowGenerator, createPointLight, createRenderTarget, createRenderTask, createSceneContext, createSmaaPostProcessTask, createSpotLight, createStorageBuffer, createTexture2DFromPixels, disableOrthographicCamera, disposeEngine, disposePicker, disposeScene, disposeStorageBuffer, enableBoneControl, enableDeviceLostSceneRecovery, enableMaterialPlugins, enableMaterialStencil, enableOrthographicCamera, enablePbrLightmap, enableSkeletonShadows, enableStandardSkeleton, forceWebGpuDeviceLossForTesting, getEffectiveAspectRatio, getFrameGraph, getProjectionMatrix, getRenderTaskGpuTimings, getViewMatrix, getViewProjectionMatrix, isPbrMaterial, isShaderMaterial, loadTexture2D, onBeforeRender, pickAsync, pickWithRay, rebuildSceneRenderables, registerScene, registerSceneWithShadowSupport, releaseTexture, removeFromScene, resizeEngine, resolveCameraViewport, setGpuTimingEnabled, setShadowTaskCasterMeshes, setSubtreeVisible, setSurfaceSize, startEngine, stopEngine, updateStorageBuffer, updateTexture2DFromPixels } from "@babylonjs/lite";
|
|
9
10
|
//#region src/signal/signal.ts
|
|
10
11
|
/** One attached handler. `handler === null` marks the entry dead and awaiting compaction. */
|
|
11
12
|
var Connection = class {
|
|
@@ -4751,951 +4752,6 @@ function entityInternals(entity) {
|
|
|
4751
4752
|
return entity[ENTITY_INTERNALS];
|
|
4752
4753
|
}
|
|
4753
4754
|
//#endregion
|
|
4754
|
-
//#region src/math/mat4.ts
|
|
4755
|
-
/**
|
|
4756
|
-
* Allocates the 16-element column-major storage a matrix owns, pre-filled with zeroes.
|
|
4757
|
-
*
|
|
4758
|
-
* @returns Fresh, zeroed storage.
|
|
4759
|
-
*/
|
|
4760
|
-
function allocateElements() {
|
|
4761
|
-
return /* @__PURE__ */ new Float32Array(16);
|
|
4762
|
-
}
|
|
4763
|
-
/**
|
|
4764
|
-
* The determinant of the upper-left 3×3 basis. Its sign says whether the matrix mirrors, which is
|
|
4765
|
-
* how Babylon Lite decides the sign of the decomposed Y scale (`lib/math/mat4-decompose.js`).
|
|
4766
|
-
*
|
|
4767
|
-
* @param m - The matrix to measure.
|
|
4768
|
-
* @returns The 3×3 determinant.
|
|
4769
|
-
*/
|
|
4770
|
-
function basisDeterminant(m) {
|
|
4771
|
-
const m0 = m[0] ?? 0;
|
|
4772
|
-
const m1 = m[1] ?? 0;
|
|
4773
|
-
const m2 = m[2] ?? 0;
|
|
4774
|
-
const m4 = m[4] ?? 0;
|
|
4775
|
-
const m5 = m[5] ?? 0;
|
|
4776
|
-
const m6 = m[6] ?? 0;
|
|
4777
|
-
const m8 = m[8] ?? 0;
|
|
4778
|
-
const m9 = m[9] ?? 0;
|
|
4779
|
-
const m10 = m[10] ?? 0;
|
|
4780
|
-
return m0 * (m5 * m10 - m6 * m9) + m1 * (m6 * m8 - m4 * m10) + m2 * (m4 * m9 - m5 * m8);
|
|
4781
|
-
}
|
|
4782
|
-
/**
|
|
4783
|
-
* Writes the unit quaternion of an orthonormal basis into `out`. Arguments are named row-major
|
|
4784
|
-
* (`b<row><column>`), matching Babylon Lite's `_quatFromRotationBasis`
|
|
4785
|
-
* (`lib/math/quat-from-rotation-matrix.js`), which this reproduces branch for branch.
|
|
4786
|
-
*
|
|
4787
|
-
* Shared with the quaternion module; not part of the public API.
|
|
4788
|
-
*
|
|
4789
|
-
* @param b00 - Row 0, column 0.
|
|
4790
|
-
* @param b01 - Row 0, column 1.
|
|
4791
|
-
* @param b02 - Row 0, column 2.
|
|
4792
|
-
* @param b10 - Row 1, column 0.
|
|
4793
|
-
* @param b11 - Row 1, column 1.
|
|
4794
|
-
* @param b12 - Row 1, column 2.
|
|
4795
|
-
* @param b20 - Row 2, column 0.
|
|
4796
|
-
* @param b21 - Row 2, column 1.
|
|
4797
|
-
* @param b22 - Row 2, column 2.
|
|
4798
|
-
* @param out - The quaternion to write.
|
|
4799
|
-
*
|
|
4800
|
-
* @internal
|
|
4801
|
-
*/
|
|
4802
|
-
function basisToQuatToRef(b00, b01, b02, b10, b11, b12, b20, b21, b22, out) {
|
|
4803
|
-
const trace = b00 + b11 + b22;
|
|
4804
|
-
if (trace > 0) {
|
|
4805
|
-
const s = .5 / Math.sqrt(trace + 1);
|
|
4806
|
-
out.set((b21 - b12) * s, (b02 - b20) * s, (b10 - b01) * s, .25 / s);
|
|
4807
|
-
return;
|
|
4808
|
-
}
|
|
4809
|
-
if (b00 > b11 && b00 > b22) {
|
|
4810
|
-
const s = 2 * Math.sqrt(1 + b00 - b11 - b22);
|
|
4811
|
-
out.set(.25 * s, (b01 + b10) / s, (b02 + b20) / s, (b21 - b12) / s);
|
|
4812
|
-
return;
|
|
4813
|
-
}
|
|
4814
|
-
if (b11 > b22) {
|
|
4815
|
-
const s = 2 * Math.sqrt(1 + b11 - b00 - b22);
|
|
4816
|
-
out.set((b01 + b10) / s, .25 * s, (b12 + b21) / s, (b02 - b20) / s);
|
|
4817
|
-
return;
|
|
4818
|
-
}
|
|
4819
|
-
const s = 2 * Math.sqrt(1 + b22 - b00 - b11);
|
|
4820
|
-
out.set((b02 + b20) / s, (b12 + b21) / s, .25 * s, (b10 - b01) / s);
|
|
4821
|
-
}
|
|
4822
|
-
/**
|
|
4823
|
-
* A 4×4 transformation matrix stored column-major in a `Float32Array`, byte-compatible with WGSL's
|
|
4824
|
-
* `mat4x4<f32>` and with Babylon Lite's `Mat4` (translation in slots 12/13/14).
|
|
4825
|
-
*
|
|
4826
|
-
* ignifx is left-handed, Y up, +Z forward (ADR-0011), so the projection helpers are the `LH`
|
|
4827
|
-
* family and they use Lite's **reverse depth** convention: the near plane maps to 1 and the far
|
|
4828
|
-
* plane to 0.
|
|
4829
|
-
*
|
|
4830
|
-
* Instance methods mutate the matrix and return `this`; `ToRef` statics write into their `out`
|
|
4831
|
-
* matrix and allocate nothing, and are safe when `out` aliases an input. The remaining statics
|
|
4832
|
-
* allocate a fresh matrix and say so.
|
|
4833
|
-
*
|
|
4834
|
-
* @example
|
|
4835
|
-
* ```ts
|
|
4836
|
-
* const world = new Mat4();
|
|
4837
|
-
* Mat4.composeToRef(position, rotation, scale, world);
|
|
4838
|
-
*
|
|
4839
|
-
* const inverse = new Mat4();
|
|
4840
|
-
* if (Mat4.invertToRef(world, inverse)) {
|
|
4841
|
-
* Mat4.transformPointToRef(inverse, worldPoint, localPoint);
|
|
4842
|
-
* }
|
|
4843
|
-
* ```
|
|
4844
|
-
*
|
|
4845
|
-
* @public
|
|
4846
|
-
*/
|
|
4847
|
-
var Mat4 = class Mat4 {
|
|
4848
|
-
/**
|
|
4849
|
-
* The 16 elements, column-major (`elements[column * 4 + row]`). This is the object to hand to
|
|
4850
|
-
* anything that wants a {@link Mat4Like} — including Babylon Lite — and the buffer to upload to
|
|
4851
|
-
* the GPU. It is never reallocated, so a reference to it stays valid for the matrix's lifetime.
|
|
4852
|
-
*/
|
|
4853
|
-
elements;
|
|
4854
|
-
/**
|
|
4855
|
-
* Creates an identity matrix.
|
|
4856
|
-
*/
|
|
4857
|
-
constructor() {
|
|
4858
|
-
const e = allocateElements();
|
|
4859
|
-
e[0] = 1;
|
|
4860
|
-
e[5] = 1;
|
|
4861
|
-
e[10] = 1;
|
|
4862
|
-
e[15] = 1;
|
|
4863
|
-
this.elements = e;
|
|
4864
|
-
}
|
|
4865
|
-
/**
|
|
4866
|
-
* Resets this matrix to the identity.
|
|
4867
|
-
*
|
|
4868
|
-
* @returns This matrix.
|
|
4869
|
-
*/
|
|
4870
|
-
identity() {
|
|
4871
|
-
const e = this.elements;
|
|
4872
|
-
e[0] = 1;
|
|
4873
|
-
e[1] = 0;
|
|
4874
|
-
e[2] = 0;
|
|
4875
|
-
e[3] = 0;
|
|
4876
|
-
e[4] = 0;
|
|
4877
|
-
e[5] = 1;
|
|
4878
|
-
e[6] = 0;
|
|
4879
|
-
e[7] = 0;
|
|
4880
|
-
e[8] = 0;
|
|
4881
|
-
e[9] = 0;
|
|
4882
|
-
e[10] = 1;
|
|
4883
|
-
e[11] = 0;
|
|
4884
|
-
e[12] = 0;
|
|
4885
|
-
e[13] = 0;
|
|
4886
|
-
e[14] = 0;
|
|
4887
|
-
e[15] = 1;
|
|
4888
|
-
return this;
|
|
4889
|
-
}
|
|
4890
|
-
/**
|
|
4891
|
-
* Copies every element from another matrix.
|
|
4892
|
-
*
|
|
4893
|
-
* @param m - The matrix to read.
|
|
4894
|
-
* @returns This matrix.
|
|
4895
|
-
*/
|
|
4896
|
-
copyFrom(m) {
|
|
4897
|
-
const e = this.elements;
|
|
4898
|
-
for (let i = 0; i < 16; i++) e[i] = m[i] ?? 0;
|
|
4899
|
-
return this;
|
|
4900
|
-
}
|
|
4901
|
-
/**
|
|
4902
|
-
* Copies this matrix into a new one.
|
|
4903
|
-
*
|
|
4904
|
-
* @returns A new matrix. **Allocates.**
|
|
4905
|
-
*/
|
|
4906
|
-
clone() {
|
|
4907
|
-
return new Mat4().copyFrom(this.elements);
|
|
4908
|
-
}
|
|
4909
|
-
/**
|
|
4910
|
-
* Post-multiplies this matrix by another (`this = this * m`), so `m`'s transform is applied first
|
|
4911
|
-
* when the product acts on a column vector.
|
|
4912
|
-
*
|
|
4913
|
-
* @param m - The right-hand matrix.
|
|
4914
|
-
* @returns This matrix.
|
|
4915
|
-
*/
|
|
4916
|
-
multiply(m) {
|
|
4917
|
-
Mat4.multiplyToRef(this.elements, m, this);
|
|
4918
|
-
return this;
|
|
4919
|
-
}
|
|
4920
|
-
/**
|
|
4921
|
-
* Inverts this matrix in place.
|
|
4922
|
-
*
|
|
4923
|
-
* @returns `true` on success. When the matrix is singular this returns `false` and leaves the
|
|
4924
|
-
* matrix untouched.
|
|
4925
|
-
*/
|
|
4926
|
-
invert() {
|
|
4927
|
-
return Mat4.invertToRef(this.elements, this);
|
|
4928
|
-
}
|
|
4929
|
-
/**
|
|
4930
|
-
* Transposes this matrix in place, swapping rows and columns.
|
|
4931
|
-
*
|
|
4932
|
-
* @returns This matrix.
|
|
4933
|
-
*/
|
|
4934
|
-
transpose() {
|
|
4935
|
-
Mat4.transposeToRef(this.elements, this);
|
|
4936
|
-
return this;
|
|
4937
|
-
}
|
|
4938
|
-
/**
|
|
4939
|
-
* The full 4×4 determinant of this matrix.
|
|
4940
|
-
*
|
|
4941
|
-
* @returns The determinant; zero means the matrix cannot be inverted.
|
|
4942
|
-
*/
|
|
4943
|
-
determinant() {
|
|
4944
|
-
return Mat4.determinant(this.elements);
|
|
4945
|
-
}
|
|
4946
|
-
/**
|
|
4947
|
-
* Compares this matrix with another element by element, with a tolerance.
|
|
4948
|
-
*
|
|
4949
|
-
* @param m - The matrix to compare against.
|
|
4950
|
-
* @param epsilon - The largest per-element difference still considered equal.
|
|
4951
|
-
* @returns `true` when every element matches within `epsilon`.
|
|
4952
|
-
*/
|
|
4953
|
-
equalsWithEpsilon(m, epsilon = EPSILON) {
|
|
4954
|
-
return Mat4.equalsWithEpsilon(this.elements, m, epsilon);
|
|
4955
|
-
}
|
|
4956
|
-
/**
|
|
4957
|
-
* Creates an identity matrix.
|
|
4958
|
-
*
|
|
4959
|
-
* @returns A new identity matrix. **Allocates.**
|
|
4960
|
-
*/
|
|
4961
|
-
static identity() {
|
|
4962
|
-
return new Mat4();
|
|
4963
|
-
}
|
|
4964
|
-
/**
|
|
4965
|
-
* Creates a matrix holding a copy of another matrix's elements.
|
|
4966
|
-
*
|
|
4967
|
-
* @param m - The matrix to copy.
|
|
4968
|
-
* @returns A new matrix. **Allocates.**
|
|
4969
|
-
*/
|
|
4970
|
-
static from(m) {
|
|
4971
|
-
return new Mat4().copyFrom(m);
|
|
4972
|
-
}
|
|
4973
|
-
/**
|
|
4974
|
-
* Builds a translation-rotation-scale matrix, the same composition order Babylon Lite's
|
|
4975
|
-
* `mat4Compose` uses (`translation * rotation * scale`).
|
|
4976
|
-
*
|
|
4977
|
-
* @param position - The translation, in metres.
|
|
4978
|
-
* @param rotation - The rotation; assumed to be a unit quaternion.
|
|
4979
|
-
* @param scale - The per-axis scale.
|
|
4980
|
-
* @returns A new matrix. **Allocates.**
|
|
4981
|
-
*/
|
|
4982
|
-
static compose(position, rotation, scale) {
|
|
4983
|
-
return Mat4.composeToRef(position, rotation, scale, new Mat4());
|
|
4984
|
-
}
|
|
4985
|
-
/**
|
|
4986
|
-
* Writes a translation-rotation-scale matrix into `out`.
|
|
4987
|
-
*
|
|
4988
|
-
* @param position - The translation, in metres.
|
|
4989
|
-
* @param rotation - The rotation; assumed to be a unit quaternion.
|
|
4990
|
-
* @param scale - The per-axis scale.
|
|
4991
|
-
* @param out - The matrix to write.
|
|
4992
|
-
* @returns `out`.
|
|
4993
|
-
*
|
|
4994
|
-
* @example
|
|
4995
|
-
* ```ts
|
|
4996
|
-
* Mat4.composeToRef(transform.localPosition, transform.localRotation, transform.localScale, local);
|
|
4997
|
-
* ```
|
|
4998
|
-
*/
|
|
4999
|
-
static composeToRef(position, rotation, scale, out) {
|
|
5000
|
-
const qx = rotation.x;
|
|
5001
|
-
const qy = rotation.y;
|
|
5002
|
-
const qz = rotation.z;
|
|
5003
|
-
const qw = rotation.w;
|
|
5004
|
-
const sx = scale.x;
|
|
5005
|
-
const sy = scale.y;
|
|
5006
|
-
const sz = scale.z;
|
|
5007
|
-
const xx = qx * qx;
|
|
5008
|
-
const yy = qy * qy;
|
|
5009
|
-
const zz = qz * qz;
|
|
5010
|
-
const xy = qx * qy;
|
|
5011
|
-
const xz = qx * qz;
|
|
5012
|
-
const yz = qy * qz;
|
|
5013
|
-
const wx = qw * qx;
|
|
5014
|
-
const wy = qw * qy;
|
|
5015
|
-
const wz = qw * qz;
|
|
5016
|
-
const e = out.elements;
|
|
5017
|
-
e[0] = (1 - 2 * (yy + zz)) * sx;
|
|
5018
|
-
e[1] = 2 * (xy + wz) * sx;
|
|
5019
|
-
e[2] = 2 * (xz - wy) * sx;
|
|
5020
|
-
e[3] = 0;
|
|
5021
|
-
e[4] = 2 * (xy - wz) * sy;
|
|
5022
|
-
e[5] = (1 - 2 * (xx + zz)) * sy;
|
|
5023
|
-
e[6] = 2 * (yz + wx) * sy;
|
|
5024
|
-
e[7] = 0;
|
|
5025
|
-
e[8] = 2 * (xz + wy) * sz;
|
|
5026
|
-
e[9] = 2 * (yz - wx) * sz;
|
|
5027
|
-
e[10] = (1 - 2 * (xx + yy)) * sz;
|
|
5028
|
-
e[11] = 0;
|
|
5029
|
-
e[12] = position.x;
|
|
5030
|
-
e[13] = position.y;
|
|
5031
|
-
e[14] = position.z;
|
|
5032
|
-
e[15] = 1;
|
|
5033
|
-
return out;
|
|
5034
|
-
}
|
|
5035
|
-
/**
|
|
5036
|
-
* Splits an affine transformation-rotation-scale matrix back into its parts, using Babylon Lite's
|
|
5037
|
-
* convention (`lib/math/mat4-decompose.js`): scales are the lengths of the basis columns, and a
|
|
5038
|
-
* mirrored matrix (negative basis determinant) reports a **negative Y scale** rather than
|
|
5039
|
-
* silently dropping the reflection. Shear is not detected.
|
|
5040
|
-
*
|
|
5041
|
-
* @param m - The matrix to split.
|
|
5042
|
-
* @param outPosition - Receives the translation.
|
|
5043
|
-
* @param outRotation - Receives the rotation as a unit quaternion.
|
|
5044
|
-
* @param outScale - Receives the per-axis scale.
|
|
5045
|
-
* @returns `true` on success; `false` when a basis column has (near) zero length, in which case
|
|
5046
|
-
* the outputs are left untouched.
|
|
5047
|
-
*
|
|
5048
|
-
* @example
|
|
5049
|
-
* ```ts
|
|
5050
|
-
* Mat4.decomposeToRef(node.worldMatrix, position, rotation, scale);
|
|
5051
|
-
* ```
|
|
5052
|
-
*/
|
|
5053
|
-
static decomposeToRef(m, outPosition, outRotation, outScale) {
|
|
5054
|
-
const m0 = m[0] ?? 0;
|
|
5055
|
-
const m1 = m[1] ?? 0;
|
|
5056
|
-
const m2 = m[2] ?? 0;
|
|
5057
|
-
const m4 = m[4] ?? 0;
|
|
5058
|
-
const m5 = m[5] ?? 0;
|
|
5059
|
-
const m6 = m[6] ?? 0;
|
|
5060
|
-
const m8 = m[8] ?? 0;
|
|
5061
|
-
const m9 = m[9] ?? 0;
|
|
5062
|
-
const m10 = m[10] ?? 0;
|
|
5063
|
-
const sx = Math.hypot(m0, m1, m2);
|
|
5064
|
-
const syAbs = Math.hypot(m4, m5, m6);
|
|
5065
|
-
const sz = Math.hypot(m8, m9, m10);
|
|
5066
|
-
if (sx <= 1e-8 || syAbs <= 1e-8 || sz <= 1e-8) return false;
|
|
5067
|
-
const sy = basisDeterminant(m) < 0 ? -syAbs : syAbs;
|
|
5068
|
-
const invSx = 1 / sx;
|
|
5069
|
-
const invSy = 1 / sy;
|
|
5070
|
-
const invSz = 1 / sz;
|
|
5071
|
-
const tx = m[12] ?? 0;
|
|
5072
|
-
const ty = m[13] ?? 0;
|
|
5073
|
-
const tz = m[14] ?? 0;
|
|
5074
|
-
basisToQuatToRef(m0 * invSx, m4 * invSy, m8 * invSz, m1 * invSx, m5 * invSy, m9 * invSz, m2 * invSx, m6 * invSy, m10 * invSz, outRotation);
|
|
5075
|
-
const qx = outRotation.x;
|
|
5076
|
-
const qy = outRotation.y;
|
|
5077
|
-
const qz = outRotation.z;
|
|
5078
|
-
const qw = outRotation.w;
|
|
5079
|
-
const invLength = 1 / Math.hypot(qx, qy, qz, qw);
|
|
5080
|
-
outRotation.set(qx * invLength, qy * invLength, qz * invLength, qw * invLength);
|
|
5081
|
-
outPosition.set(tx, ty, tz);
|
|
5082
|
-
outScale.set(sx, sy, sz);
|
|
5083
|
-
return true;
|
|
5084
|
-
}
|
|
5085
|
-
/**
|
|
5086
|
-
* Multiplies two matrices.
|
|
5087
|
-
*
|
|
5088
|
-
* @param a - The left-hand matrix.
|
|
5089
|
-
* @param b - The right-hand matrix.
|
|
5090
|
-
* @returns A new matrix holding `a * b`. **Allocates.**
|
|
5091
|
-
*/
|
|
5092
|
-
static multiply(a, b) {
|
|
5093
|
-
return Mat4.multiplyToRef(a, b, new Mat4());
|
|
5094
|
-
}
|
|
5095
|
-
/**
|
|
5096
|
-
* Writes `a * b` into `out`. Acting on a column vector, `b` is applied first.
|
|
5097
|
-
*
|
|
5098
|
-
* @param a - The left-hand matrix.
|
|
5099
|
-
* @param b - The right-hand matrix.
|
|
5100
|
-
* @param out - The matrix to write; may alias `a` or `b`.
|
|
5101
|
-
* @returns `out`.
|
|
5102
|
-
*/
|
|
5103
|
-
static multiplyToRef(a, b, out) {
|
|
5104
|
-
const a0 = a[0] ?? 0;
|
|
5105
|
-
const a1 = a[1] ?? 0;
|
|
5106
|
-
const a2 = a[2] ?? 0;
|
|
5107
|
-
const a3 = a[3] ?? 0;
|
|
5108
|
-
const a4 = a[4] ?? 0;
|
|
5109
|
-
const a5 = a[5] ?? 0;
|
|
5110
|
-
const a6 = a[6] ?? 0;
|
|
5111
|
-
const a7 = a[7] ?? 0;
|
|
5112
|
-
const a8 = a[8] ?? 0;
|
|
5113
|
-
const a9 = a[9] ?? 0;
|
|
5114
|
-
const a10 = a[10] ?? 0;
|
|
5115
|
-
const a11 = a[11] ?? 0;
|
|
5116
|
-
const a12 = a[12] ?? 0;
|
|
5117
|
-
const a13 = a[13] ?? 0;
|
|
5118
|
-
const a14 = a[14] ?? 0;
|
|
5119
|
-
const a15 = a[15] ?? 0;
|
|
5120
|
-
const b0 = b[0] ?? 0;
|
|
5121
|
-
const b1 = b[1] ?? 0;
|
|
5122
|
-
const b2 = b[2] ?? 0;
|
|
5123
|
-
const b3 = b[3] ?? 0;
|
|
5124
|
-
const b4 = b[4] ?? 0;
|
|
5125
|
-
const b5 = b[5] ?? 0;
|
|
5126
|
-
const b6 = b[6] ?? 0;
|
|
5127
|
-
const b7 = b[7] ?? 0;
|
|
5128
|
-
const b8 = b[8] ?? 0;
|
|
5129
|
-
const b9 = b[9] ?? 0;
|
|
5130
|
-
const b10 = b[10] ?? 0;
|
|
5131
|
-
const b11 = b[11] ?? 0;
|
|
5132
|
-
const b12 = b[12] ?? 0;
|
|
5133
|
-
const b13 = b[13] ?? 0;
|
|
5134
|
-
const b14 = b[14] ?? 0;
|
|
5135
|
-
const b15 = b[15] ?? 0;
|
|
5136
|
-
const e = out.elements;
|
|
5137
|
-
e[0] = a0 * b0 + a4 * b1 + a8 * b2 + a12 * b3;
|
|
5138
|
-
e[1] = a1 * b0 + a5 * b1 + a9 * b2 + a13 * b3;
|
|
5139
|
-
e[2] = a2 * b0 + a6 * b1 + a10 * b2 + a14 * b3;
|
|
5140
|
-
e[3] = a3 * b0 + a7 * b1 + a11 * b2 + a15 * b3;
|
|
5141
|
-
e[4] = a0 * b4 + a4 * b5 + a8 * b6 + a12 * b7;
|
|
5142
|
-
e[5] = a1 * b4 + a5 * b5 + a9 * b6 + a13 * b7;
|
|
5143
|
-
e[6] = a2 * b4 + a6 * b5 + a10 * b6 + a14 * b7;
|
|
5144
|
-
e[7] = a3 * b4 + a7 * b5 + a11 * b6 + a15 * b7;
|
|
5145
|
-
e[8] = a0 * b8 + a4 * b9 + a8 * b10 + a12 * b11;
|
|
5146
|
-
e[9] = a1 * b8 + a5 * b9 + a9 * b10 + a13 * b11;
|
|
5147
|
-
e[10] = a2 * b8 + a6 * b9 + a10 * b10 + a14 * b11;
|
|
5148
|
-
e[11] = a3 * b8 + a7 * b9 + a11 * b10 + a15 * b11;
|
|
5149
|
-
e[12] = a0 * b12 + a4 * b13 + a8 * b14 + a12 * b15;
|
|
5150
|
-
e[13] = a1 * b12 + a5 * b13 + a9 * b14 + a13 * b15;
|
|
5151
|
-
e[14] = a2 * b12 + a6 * b13 + a10 * b14 + a14 * b15;
|
|
5152
|
-
e[15] = a3 * b12 + a7 * b13 + a11 * b14 + a15 * b15;
|
|
5153
|
-
return out;
|
|
5154
|
-
}
|
|
5155
|
-
/**
|
|
5156
|
-
* Writes the inverse of `m` into `out`.
|
|
5157
|
-
*
|
|
5158
|
-
* @param m - The matrix to invert.
|
|
5159
|
-
* @param out - The matrix to write; may alias `m`. Left untouched when the inverse does not exist.
|
|
5160
|
-
* @returns `true` on success, `false` when `m` is singular. Returning a status rather than `null`
|
|
5161
|
-
* keeps the call allocation-free (coding standards §7).
|
|
5162
|
-
*
|
|
5163
|
-
* @example
|
|
5164
|
-
* ```ts
|
|
5165
|
-
* if (!Mat4.invertToRef(world, worldToLocal)) {
|
|
5166
|
-
* // degenerate scale — skip this entity
|
|
5167
|
-
* }
|
|
5168
|
-
* ```
|
|
5169
|
-
*/
|
|
5170
|
-
static invertToRef(m, out) {
|
|
5171
|
-
const a00 = m[0] ?? 0;
|
|
5172
|
-
const a01 = m[1] ?? 0;
|
|
5173
|
-
const a02 = m[2] ?? 0;
|
|
5174
|
-
const a03 = m[3] ?? 0;
|
|
5175
|
-
const a10 = m[4] ?? 0;
|
|
5176
|
-
const a11 = m[5] ?? 0;
|
|
5177
|
-
const a12 = m[6] ?? 0;
|
|
5178
|
-
const a13 = m[7] ?? 0;
|
|
5179
|
-
const a20 = m[8] ?? 0;
|
|
5180
|
-
const a21 = m[9] ?? 0;
|
|
5181
|
-
const a22 = m[10] ?? 0;
|
|
5182
|
-
const a23 = m[11] ?? 0;
|
|
5183
|
-
const a30 = m[12] ?? 0;
|
|
5184
|
-
const a31 = m[13] ?? 0;
|
|
5185
|
-
const a32 = m[14] ?? 0;
|
|
5186
|
-
const a33 = m[15] ?? 0;
|
|
5187
|
-
const b00 = a00 * a11 - a01 * a10;
|
|
5188
|
-
const b01 = a00 * a12 - a02 * a10;
|
|
5189
|
-
const b02 = a00 * a13 - a03 * a10;
|
|
5190
|
-
const b03 = a01 * a12 - a02 * a11;
|
|
5191
|
-
const b04 = a01 * a13 - a03 * a11;
|
|
5192
|
-
const b05 = a02 * a13 - a03 * a12;
|
|
5193
|
-
const b06 = a20 * a31 - a21 * a30;
|
|
5194
|
-
const b07 = a20 * a32 - a22 * a30;
|
|
5195
|
-
const b08 = a20 * a33 - a23 * a30;
|
|
5196
|
-
const b09 = a21 * a32 - a22 * a31;
|
|
5197
|
-
const b10 = a21 * a33 - a23 * a31;
|
|
5198
|
-
const b11 = a22 * a33 - a23 * a32;
|
|
5199
|
-
const determinant = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
|
|
5200
|
-
if (Math.abs(determinant) < 1e-10) return false;
|
|
5201
|
-
const inv = 1 / determinant;
|
|
5202
|
-
const e = out.elements;
|
|
5203
|
-
e[0] = (a11 * b11 - a12 * b10 + a13 * b09) * inv;
|
|
5204
|
-
e[1] = (a02 * b10 - a01 * b11 - a03 * b09) * inv;
|
|
5205
|
-
e[2] = (a31 * b05 - a32 * b04 + a33 * b03) * inv;
|
|
5206
|
-
e[3] = (a22 * b04 - a21 * b05 - a23 * b03) * inv;
|
|
5207
|
-
e[4] = (a12 * b08 - a10 * b11 - a13 * b07) * inv;
|
|
5208
|
-
e[5] = (a00 * b11 - a02 * b08 + a03 * b07) * inv;
|
|
5209
|
-
e[6] = (a32 * b02 - a30 * b05 - a33 * b01) * inv;
|
|
5210
|
-
e[7] = (a20 * b05 - a22 * b02 + a23 * b01) * inv;
|
|
5211
|
-
e[8] = (a10 * b10 - a11 * b08 + a13 * b06) * inv;
|
|
5212
|
-
e[9] = (a01 * b08 - a00 * b10 - a03 * b06) * inv;
|
|
5213
|
-
e[10] = (a30 * b04 - a31 * b02 + a33 * b00) * inv;
|
|
5214
|
-
e[11] = (a21 * b02 - a20 * b04 - a23 * b00) * inv;
|
|
5215
|
-
e[12] = (a11 * b07 - a10 * b09 - a12 * b06) * inv;
|
|
5216
|
-
e[13] = (a00 * b09 - a01 * b07 + a02 * b06) * inv;
|
|
5217
|
-
e[14] = (a31 * b01 - a30 * b03 - a32 * b00) * inv;
|
|
5218
|
-
e[15] = (a20 * b03 - a21 * b01 + a22 * b00) * inv;
|
|
5219
|
-
return true;
|
|
5220
|
-
}
|
|
5221
|
-
/**
|
|
5222
|
-
* Writes the transpose of `m` into `out`.
|
|
5223
|
-
*
|
|
5224
|
-
* @param m - The matrix to transpose.
|
|
5225
|
-
* @param out - The matrix to write; may alias `m`.
|
|
5226
|
-
* @returns `out`.
|
|
5227
|
-
*/
|
|
5228
|
-
static transposeToRef(m, out) {
|
|
5229
|
-
const m0 = m[0] ?? 0;
|
|
5230
|
-
const m1 = m[1] ?? 0;
|
|
5231
|
-
const m2 = m[2] ?? 0;
|
|
5232
|
-
const m3 = m[3] ?? 0;
|
|
5233
|
-
const m4 = m[4] ?? 0;
|
|
5234
|
-
const m5 = m[5] ?? 0;
|
|
5235
|
-
const m6 = m[6] ?? 0;
|
|
5236
|
-
const m7 = m[7] ?? 0;
|
|
5237
|
-
const m8 = m[8] ?? 0;
|
|
5238
|
-
const m9 = m[9] ?? 0;
|
|
5239
|
-
const m10 = m[10] ?? 0;
|
|
5240
|
-
const m11 = m[11] ?? 0;
|
|
5241
|
-
const m12 = m[12] ?? 0;
|
|
5242
|
-
const m13 = m[13] ?? 0;
|
|
5243
|
-
const m14 = m[14] ?? 0;
|
|
5244
|
-
const m15 = m[15] ?? 0;
|
|
5245
|
-
const e = out.elements;
|
|
5246
|
-
e[0] = m0;
|
|
5247
|
-
e[1] = m4;
|
|
5248
|
-
e[2] = m8;
|
|
5249
|
-
e[3] = m12;
|
|
5250
|
-
e[4] = m1;
|
|
5251
|
-
e[5] = m5;
|
|
5252
|
-
e[6] = m9;
|
|
5253
|
-
e[7] = m13;
|
|
5254
|
-
e[8] = m2;
|
|
5255
|
-
e[9] = m6;
|
|
5256
|
-
e[10] = m10;
|
|
5257
|
-
e[11] = m14;
|
|
5258
|
-
e[12] = m3;
|
|
5259
|
-
e[13] = m7;
|
|
5260
|
-
e[14] = m11;
|
|
5261
|
-
e[15] = m15;
|
|
5262
|
-
return out;
|
|
5263
|
-
}
|
|
5264
|
-
/**
|
|
5265
|
-
* The full 4×4 determinant.
|
|
5266
|
-
*
|
|
5267
|
-
* @param m - The matrix to measure.
|
|
5268
|
-
* @returns The determinant; zero means the matrix cannot be inverted.
|
|
5269
|
-
*/
|
|
5270
|
-
static determinant(m) {
|
|
5271
|
-
const a00 = m[0] ?? 0;
|
|
5272
|
-
const a01 = m[1] ?? 0;
|
|
5273
|
-
const a02 = m[2] ?? 0;
|
|
5274
|
-
const a03 = m[3] ?? 0;
|
|
5275
|
-
const a10 = m[4] ?? 0;
|
|
5276
|
-
const a11 = m[5] ?? 0;
|
|
5277
|
-
const a12 = m[6] ?? 0;
|
|
5278
|
-
const a13 = m[7] ?? 0;
|
|
5279
|
-
const a20 = m[8] ?? 0;
|
|
5280
|
-
const a21 = m[9] ?? 0;
|
|
5281
|
-
const a22 = m[10] ?? 0;
|
|
5282
|
-
const a23 = m[11] ?? 0;
|
|
5283
|
-
const a30 = m[12] ?? 0;
|
|
5284
|
-
const a31 = m[13] ?? 0;
|
|
5285
|
-
const a32 = m[14] ?? 0;
|
|
5286
|
-
const a33 = m[15] ?? 0;
|
|
5287
|
-
const b00 = a00 * a11 - a01 * a10;
|
|
5288
|
-
const b01 = a00 * a12 - a02 * a10;
|
|
5289
|
-
const b02 = a00 * a13 - a03 * a10;
|
|
5290
|
-
const b03 = a01 * a12 - a02 * a11;
|
|
5291
|
-
const b04 = a01 * a13 - a03 * a11;
|
|
5292
|
-
const b05 = a02 * a13 - a03 * a12;
|
|
5293
|
-
const b06 = a20 * a31 - a21 * a30;
|
|
5294
|
-
const b07 = a20 * a32 - a22 * a30;
|
|
5295
|
-
const b08 = a20 * a33 - a23 * a30;
|
|
5296
|
-
const b09 = a21 * a32 - a22 * a31;
|
|
5297
|
-
const b10 = a21 * a33 - a23 * a31;
|
|
5298
|
-
return b00 * (a22 * a33 - a23 * a32) - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
|
|
5299
|
-
}
|
|
5300
|
-
/**
|
|
5301
|
-
* Builds a pure translation matrix.
|
|
5302
|
-
*
|
|
5303
|
-
* @param x - Translation along X, in metres.
|
|
5304
|
-
* @param y - Translation along Y, in metres.
|
|
5305
|
-
* @param z - Translation along Z, in metres.
|
|
5306
|
-
* @returns A new matrix. **Allocates.**
|
|
5307
|
-
*/
|
|
5308
|
-
static translation(x, y, z) {
|
|
5309
|
-
return Mat4.translationToRef(x, y, z, new Mat4());
|
|
5310
|
-
}
|
|
5311
|
-
/**
|
|
5312
|
-
* Writes a pure translation matrix into `out`.
|
|
5313
|
-
*
|
|
5314
|
-
* @param x - Translation along X, in metres.
|
|
5315
|
-
* @param y - Translation along Y, in metres.
|
|
5316
|
-
* @param z - Translation along Z, in metres.
|
|
5317
|
-
* @param out - The matrix to write.
|
|
5318
|
-
* @returns `out`.
|
|
5319
|
-
*/
|
|
5320
|
-
static translationToRef(x, y, z, out) {
|
|
5321
|
-
const e = out.identity().elements;
|
|
5322
|
-
e[12] = x;
|
|
5323
|
-
e[13] = y;
|
|
5324
|
-
e[14] = z;
|
|
5325
|
-
return out;
|
|
5326
|
-
}
|
|
5327
|
-
/**
|
|
5328
|
-
* Builds a pure scaling matrix.
|
|
5329
|
-
*
|
|
5330
|
-
* @param x - Scale along X.
|
|
5331
|
-
* @param y - Scale along Y.
|
|
5332
|
-
* @param z - Scale along Z.
|
|
5333
|
-
* @returns A new matrix. **Allocates.**
|
|
5334
|
-
*/
|
|
5335
|
-
static scaling(x, y, z) {
|
|
5336
|
-
return Mat4.scalingToRef(x, y, z, new Mat4());
|
|
5337
|
-
}
|
|
5338
|
-
/**
|
|
5339
|
-
* Writes a pure scaling matrix into `out`.
|
|
5340
|
-
*
|
|
5341
|
-
* @param x - Scale along X.
|
|
5342
|
-
* @param y - Scale along Y.
|
|
5343
|
-
* @param z - Scale along Z.
|
|
5344
|
-
* @param out - The matrix to write.
|
|
5345
|
-
* @returns `out`.
|
|
5346
|
-
*/
|
|
5347
|
-
static scalingToRef(x, y, z, out) {
|
|
5348
|
-
const e = out.identity().elements;
|
|
5349
|
-
e[0] = x;
|
|
5350
|
-
e[5] = y;
|
|
5351
|
-
e[10] = z;
|
|
5352
|
-
return out;
|
|
5353
|
-
}
|
|
5354
|
-
/**
|
|
5355
|
-
* Builds a pure rotation matrix from a quaternion.
|
|
5356
|
-
*
|
|
5357
|
-
* @param q - The rotation; assumed to be a unit quaternion.
|
|
5358
|
-
* @returns A new matrix. **Allocates.**
|
|
5359
|
-
*/
|
|
5360
|
-
static fromQuat(q) {
|
|
5361
|
-
return Mat4.fromQuatToRef(q, new Mat4());
|
|
5362
|
-
}
|
|
5363
|
-
/**
|
|
5364
|
-
* Writes a pure rotation matrix into `out`.
|
|
5365
|
-
*
|
|
5366
|
-
* @param q - The rotation; assumed to be a unit quaternion.
|
|
5367
|
-
* @param out - The matrix to write.
|
|
5368
|
-
* @returns `out`.
|
|
5369
|
-
*/
|
|
5370
|
-
static fromQuatToRef(q, out) {
|
|
5371
|
-
return Mat4.composeToRef(ZERO_TRANSLATION, q, UNIT_SCALE, out);
|
|
5372
|
-
}
|
|
5373
|
-
/**
|
|
5374
|
-
* Builds a left-handed view matrix that places the camera at `eye` looking at `target`.
|
|
5375
|
-
*
|
|
5376
|
-
* @param eye - The camera position, in metres.
|
|
5377
|
-
* @param target - The point to look at, in metres.
|
|
5378
|
-
* @param up - The camera's up direction.
|
|
5379
|
-
* @returns A new matrix. **Allocates.**
|
|
5380
|
-
*/
|
|
5381
|
-
static lookAtLH(eye, target, up) {
|
|
5382
|
-
return Mat4.lookAtLHToRef(eye, target, up, new Mat4());
|
|
5383
|
-
}
|
|
5384
|
-
/**
|
|
5385
|
-
* Writes a left-handed view matrix into `out`. Reproduces Babylon Lite's `mat4LookAtLHToRef`,
|
|
5386
|
-
* including its degenerate-input behaviour: when `eye` and `target` coincide, or when `up` is
|
|
5387
|
-
* parallel to the view direction, `out` becomes the identity.
|
|
5388
|
-
*
|
|
5389
|
-
* @param eye - The camera position, in metres.
|
|
5390
|
-
* @param target - The point to look at, in metres.
|
|
5391
|
-
* @param up - The camera's up direction.
|
|
5392
|
-
* @param out - The matrix to write.
|
|
5393
|
-
* @returns `out`.
|
|
5394
|
-
*/
|
|
5395
|
-
static lookAtLHToRef(eye, target, up, out) {
|
|
5396
|
-
const ex = eye.x;
|
|
5397
|
-
const ey = eye.y;
|
|
5398
|
-
const ez = eye.z;
|
|
5399
|
-
let zx = target.x - ex;
|
|
5400
|
-
let zy = target.y - ey;
|
|
5401
|
-
let zz = target.z - ez;
|
|
5402
|
-
const zLength = Math.hypot(zx, zy, zz);
|
|
5403
|
-
if (zLength < 1e-10) return out.identity();
|
|
5404
|
-
const invZ = 1 / zLength;
|
|
5405
|
-
zx *= invZ;
|
|
5406
|
-
zy *= invZ;
|
|
5407
|
-
zz *= invZ;
|
|
5408
|
-
let xx = up.y * zz - up.z * zy;
|
|
5409
|
-
let xy = up.z * zx - up.x * zz;
|
|
5410
|
-
let xz = up.x * zy - up.y * zx;
|
|
5411
|
-
const xLength = Math.hypot(xx, xy, xz);
|
|
5412
|
-
if (xLength < 1e-10) return out.identity();
|
|
5413
|
-
const invX = 1 / xLength;
|
|
5414
|
-
xx *= invX;
|
|
5415
|
-
xy *= invX;
|
|
5416
|
-
xz *= invX;
|
|
5417
|
-
const yx = zy * xz - zz * xy;
|
|
5418
|
-
const yy = zz * xx - zx * xz;
|
|
5419
|
-
const yz = zx * xy - zy * xx;
|
|
5420
|
-
const e = out.elements;
|
|
5421
|
-
e[0] = xx;
|
|
5422
|
-
e[1] = yx;
|
|
5423
|
-
e[2] = zx;
|
|
5424
|
-
e[3] = 0;
|
|
5425
|
-
e[4] = xy;
|
|
5426
|
-
e[5] = yy;
|
|
5427
|
-
e[6] = zy;
|
|
5428
|
-
e[7] = 0;
|
|
5429
|
-
e[8] = xz;
|
|
5430
|
-
e[9] = yz;
|
|
5431
|
-
e[10] = zz;
|
|
5432
|
-
e[11] = 0;
|
|
5433
|
-
e[12] = -(xx * ex + xy * ey + xz * ez);
|
|
5434
|
-
e[13] = -(yx * ex + yy * ey + yz * ez);
|
|
5435
|
-
e[14] = -(zx * ex + zy * ey + zz * ez);
|
|
5436
|
-
e[15] = 1;
|
|
5437
|
-
return out;
|
|
5438
|
-
}
|
|
5439
|
-
/**
|
|
5440
|
-
* Builds a left-handed perspective projection.
|
|
5441
|
-
*
|
|
5442
|
-
* @param fovDegrees - The vertical field of view, in degrees.
|
|
5443
|
-
* @param aspect - The viewport's width divided by its height.
|
|
5444
|
-
* @param near - The near plane distance, in metres.
|
|
5445
|
-
* @param far - The far plane distance, in metres.
|
|
5446
|
-
* @returns A new matrix. **Allocates.**
|
|
5447
|
-
*/
|
|
5448
|
-
static perspectiveLH(fovDegrees, aspect, near, far) {
|
|
5449
|
-
return Mat4.perspectiveLHToRef(fovDegrees, aspect, near, far, new Mat4());
|
|
5450
|
-
}
|
|
5451
|
-
/**
|
|
5452
|
-
* Writes a left-handed perspective projection into `out`, matching Babylon Lite's
|
|
5453
|
-
* `mat4PerspectiveLHToRef` — which is a **reverse-depth** projection: the near plane maps to
|
|
5454
|
-
* clip-space depth 1 and the far plane to 0, the arrangement that keeps float depth precise.
|
|
5455
|
-
*
|
|
5456
|
-
* @param fovDegrees - The vertical field of view, in degrees.
|
|
5457
|
-
* @param aspect - The viewport's width divided by its height.
|
|
5458
|
-
* @param near - The near plane distance, in metres.
|
|
5459
|
-
* @param far - The far plane distance, in metres.
|
|
5460
|
-
* @param out - The matrix to write.
|
|
5461
|
-
* @returns `out`.
|
|
5462
|
-
*/
|
|
5463
|
-
static perspectiveLHToRef(fovDegrees, aspect, near, far, out) {
|
|
5464
|
-
const cot = 1 / Math.tan(degToRad(fovDegrees) * .5);
|
|
5465
|
-
const range = far - near;
|
|
5466
|
-
const e = out.elements;
|
|
5467
|
-
e[0] = cot / aspect;
|
|
5468
|
-
e[1] = 0;
|
|
5469
|
-
e[2] = 0;
|
|
5470
|
-
e[3] = 0;
|
|
5471
|
-
e[4] = 0;
|
|
5472
|
-
e[5] = cot;
|
|
5473
|
-
e[6] = 0;
|
|
5474
|
-
e[7] = 0;
|
|
5475
|
-
e[8] = 0;
|
|
5476
|
-
e[9] = 0;
|
|
5477
|
-
e[10] = -near / range;
|
|
5478
|
-
e[11] = 1;
|
|
5479
|
-
e[12] = 0;
|
|
5480
|
-
e[13] = 0;
|
|
5481
|
-
e[14] = far * near / range;
|
|
5482
|
-
e[15] = 0;
|
|
5483
|
-
return out;
|
|
5484
|
-
}
|
|
5485
|
-
/**
|
|
5486
|
-
* Builds a centred left-handed orthographic projection.
|
|
5487
|
-
*
|
|
5488
|
-
* @param width - The view width, in metres.
|
|
5489
|
-
* @param height - The view height, in metres.
|
|
5490
|
-
* @param near - The near plane distance, in metres.
|
|
5491
|
-
* @param far - The far plane distance, in metres.
|
|
5492
|
-
* @returns A new matrix. **Allocates.**
|
|
5493
|
-
*/
|
|
5494
|
-
static orthoLH(width, height, near, far) {
|
|
5495
|
-
return Mat4.orthoLHToRef(width, height, near, far, new Mat4());
|
|
5496
|
-
}
|
|
5497
|
-
/**
|
|
5498
|
-
* Writes a centred left-handed orthographic projection into `out`, with the same reverse-depth
|
|
5499
|
-
* convention as {@link Mat4.perspectiveLHToRef}.
|
|
5500
|
-
*
|
|
5501
|
-
* @param width - The view width, in metres.
|
|
5502
|
-
* @param height - The view height, in metres.
|
|
5503
|
-
* @param near - The near plane distance, in metres.
|
|
5504
|
-
* @param far - The far plane distance, in metres.
|
|
5505
|
-
* @param out - The matrix to write.
|
|
5506
|
-
* @returns `out`.
|
|
5507
|
-
*/
|
|
5508
|
-
static orthoLHToRef(width, height, near, far, out) {
|
|
5509
|
-
const halfWidth = width * .5;
|
|
5510
|
-
const halfHeight = height * .5;
|
|
5511
|
-
return Mat4.orthoOffCenterLHToRef(-halfWidth, halfWidth, -halfHeight, halfHeight, near, far, out);
|
|
5512
|
-
}
|
|
5513
|
-
/**
|
|
5514
|
-
* Writes an off-centre left-handed orthographic projection into `out`, reproducing Babylon Lite's
|
|
5515
|
-
* `mat4OrthoOffCenterLHToRef` (reverse depth).
|
|
5516
|
-
*
|
|
5517
|
-
* @param left - The left clip plane, in metres.
|
|
5518
|
-
* @param right - The right clip plane, in metres.
|
|
5519
|
-
* @param bottom - The bottom clip plane, in metres.
|
|
5520
|
-
* @param top - The top clip plane, in metres.
|
|
5521
|
-
* @param near - The near plane distance, in metres.
|
|
5522
|
-
* @param far - The far plane distance, in metres.
|
|
5523
|
-
* @param out - The matrix to write.
|
|
5524
|
-
* @returns `out`.
|
|
5525
|
-
*/
|
|
5526
|
-
static orthoOffCenterLHToRef(left, right, bottom, top, near, far, out) {
|
|
5527
|
-
const range = far - near;
|
|
5528
|
-
const e = out.elements;
|
|
5529
|
-
e[0] = 2 / (right - left);
|
|
5530
|
-
e[1] = 0;
|
|
5531
|
-
e[2] = 0;
|
|
5532
|
-
e[3] = 0;
|
|
5533
|
-
e[4] = 0;
|
|
5534
|
-
e[5] = 2 / (top - bottom);
|
|
5535
|
-
e[6] = 0;
|
|
5536
|
-
e[7] = 0;
|
|
5537
|
-
e[8] = 0;
|
|
5538
|
-
e[9] = 0;
|
|
5539
|
-
e[10] = -1 / range;
|
|
5540
|
-
e[11] = 0;
|
|
5541
|
-
e[12] = (left + right) / (left - right);
|
|
5542
|
-
e[13] = (top + bottom) / (bottom - top);
|
|
5543
|
-
e[14] = far / range;
|
|
5544
|
-
e[15] = 1;
|
|
5545
|
-
return out;
|
|
5546
|
-
}
|
|
5547
|
-
/**
|
|
5548
|
-
* Reads a matrix's translation.
|
|
5549
|
-
*
|
|
5550
|
-
* @param m - The matrix to read.
|
|
5551
|
-
* @param out - The vector to write.
|
|
5552
|
-
* @returns `out`.
|
|
5553
|
-
*/
|
|
5554
|
-
static getTranslationToRef(m, out) {
|
|
5555
|
-
out.set(m[12] ?? 0, m[13] ?? 0, m[14] ?? 0);
|
|
5556
|
-
return out;
|
|
5557
|
-
}
|
|
5558
|
-
/**
|
|
5559
|
-
* Reads a matrix's per-axis scale as the lengths of its basis columns, negating Y for a mirrored
|
|
5560
|
-
* matrix exactly as {@link Mat4.decomposeToRef} does.
|
|
5561
|
-
*
|
|
5562
|
-
* @param m - The matrix to read.
|
|
5563
|
-
* @param out - The vector to write.
|
|
5564
|
-
* @returns `out`.
|
|
5565
|
-
*/
|
|
5566
|
-
static getScaleToRef(m, out) {
|
|
5567
|
-
const sx = Math.hypot(m[0] ?? 0, m[1] ?? 0, m[2] ?? 0);
|
|
5568
|
-
const syAbs = Math.hypot(m[4] ?? 0, m[5] ?? 0, m[6] ?? 0);
|
|
5569
|
-
const sz = Math.hypot(m[8] ?? 0, m[9] ?? 0, m[10] ?? 0);
|
|
5570
|
-
out.set(sx, basisDeterminant(m) < 0 ? -syAbs : syAbs, sz);
|
|
5571
|
-
return out;
|
|
5572
|
-
}
|
|
5573
|
-
/**
|
|
5574
|
-
* Reads a matrix's rotation, dividing the scale out of the basis first.
|
|
5575
|
-
*
|
|
5576
|
-
* @param m - The matrix to read.
|
|
5577
|
-
* @param out - The quaternion to write. Left untouched when a basis column has zero length.
|
|
5578
|
-
* @returns `out`.
|
|
5579
|
-
*/
|
|
5580
|
-
static getRotationToRef(m, out) {
|
|
5581
|
-
const m0 = m[0] ?? 0;
|
|
5582
|
-
const m1 = m[1] ?? 0;
|
|
5583
|
-
const m2 = m[2] ?? 0;
|
|
5584
|
-
const m4 = m[4] ?? 0;
|
|
5585
|
-
const m5 = m[5] ?? 0;
|
|
5586
|
-
const m6 = m[6] ?? 0;
|
|
5587
|
-
const m8 = m[8] ?? 0;
|
|
5588
|
-
const m9 = m[9] ?? 0;
|
|
5589
|
-
const m10 = m[10] ?? 0;
|
|
5590
|
-
const sx = Math.hypot(m0, m1, m2);
|
|
5591
|
-
const syAbs = Math.hypot(m4, m5, m6);
|
|
5592
|
-
const sz = Math.hypot(m8, m9, m10);
|
|
5593
|
-
if (sx <= 1e-8 || syAbs <= 1e-8 || sz <= 1e-8) return out;
|
|
5594
|
-
const invSx = 1 / sx;
|
|
5595
|
-
const invSy = 1 / (basisDeterminant(m) < 0 ? -syAbs : syAbs);
|
|
5596
|
-
const invSz = 1 / sz;
|
|
5597
|
-
basisToQuatToRef(m0 * invSx, m4 * invSy, m8 * invSz, m1 * invSx, m5 * invSy, m9 * invSz, m2 * invSx, m6 * invSy, m10 * invSz, out);
|
|
5598
|
-
const invLength = 1 / Math.hypot(out.x, out.y, out.z, out.w);
|
|
5599
|
-
out.set(out.x * invLength, out.y * invLength, out.z * invLength, out.w * invLength);
|
|
5600
|
-
return out;
|
|
5601
|
-
}
|
|
5602
|
-
/**
|
|
5603
|
-
* Transforms a point by a matrix, applying translation and the perspective divide.
|
|
5604
|
-
*
|
|
5605
|
-
* @param m - The transformation.
|
|
5606
|
-
* @param point - The point to transform, in metres.
|
|
5607
|
-
* @param out - The vector to write; may alias `point`.
|
|
5608
|
-
* @returns `out`.
|
|
5609
|
-
*/
|
|
5610
|
-
static transformPointToRef(m, point, out) {
|
|
5611
|
-
const x = point.x;
|
|
5612
|
-
const y = point.y;
|
|
5613
|
-
const z = point.z;
|
|
5614
|
-
const rx = x * (m[0] ?? 0) + y * (m[4] ?? 0) + z * (m[8] ?? 0) + (m[12] ?? 0);
|
|
5615
|
-
const ry = x * (m[1] ?? 0) + y * (m[5] ?? 0) + z * (m[9] ?? 0) + (m[13] ?? 0);
|
|
5616
|
-
const rz = x * (m[2] ?? 0) + y * (m[6] ?? 0) + z * (m[10] ?? 0) + (m[14] ?? 0);
|
|
5617
|
-
const invW = 1 / (x * (m[3] ?? 0) + y * (m[7] ?? 0) + z * (m[11] ?? 0) + (m[15] ?? 0));
|
|
5618
|
-
out.set(rx * invW, ry * invW, rz * invW);
|
|
5619
|
-
return out;
|
|
5620
|
-
}
|
|
5621
|
-
/**
|
|
5622
|
-
* Transforms a direction by a matrix, ignoring translation. Note that this is the plain basis
|
|
5623
|
-
* transform: a non-uniformly scaled matrix needs its inverse-transpose to keep normals correct.
|
|
5624
|
-
*
|
|
5625
|
-
* @param m - The transformation.
|
|
5626
|
-
* @param direction - The direction to transform.
|
|
5627
|
-
* @param out - The vector to write; may alias `direction`.
|
|
5628
|
-
* @returns `out`.
|
|
5629
|
-
*/
|
|
5630
|
-
static transformDirectionToRef(m, direction, out) {
|
|
5631
|
-
const x = direction.x;
|
|
5632
|
-
const y = direction.y;
|
|
5633
|
-
const z = direction.z;
|
|
5634
|
-
out.set(x * (m[0] ?? 0) + y * (m[4] ?? 0) + z * (m[8] ?? 0), x * (m[1] ?? 0) + y * (m[5] ?? 0) + z * (m[9] ?? 0), x * (m[2] ?? 0) + y * (m[6] ?? 0) + z * (m[10] ?? 0));
|
|
5635
|
-
return out;
|
|
5636
|
-
}
|
|
5637
|
-
/**
|
|
5638
|
-
* Compares two matrices element by element, with a tolerance.
|
|
5639
|
-
*
|
|
5640
|
-
* @param a - The first matrix.
|
|
5641
|
-
* @param b - The second matrix.
|
|
5642
|
-
* @param epsilon - The largest per-element difference still considered equal.
|
|
5643
|
-
* @returns `true` when every element matches within `epsilon`.
|
|
5644
|
-
*/
|
|
5645
|
-
static equalsWithEpsilon(a, b, epsilon = EPSILON) {
|
|
5646
|
-
for (let i = 0; i < 16; i++) if (Math.abs((a[i] ?? 0) - (b[i] ?? 0)) > epsilon) return false;
|
|
5647
|
-
return true;
|
|
5648
|
-
}
|
|
5649
|
-
};
|
|
5650
|
-
/**
|
|
5651
|
-
* The zero translation {@link Mat4.fromQuatToRef} composes with. Module-scope constant, frozen so it
|
|
5652
|
-
* can never be written through.
|
|
5653
|
-
*/
|
|
5654
|
-
const ZERO_TRANSLATION = Object.freeze({
|
|
5655
|
-
x: 0,
|
|
5656
|
-
y: 0,
|
|
5657
|
-
z: 0
|
|
5658
|
-
});
|
|
5659
|
-
/**
|
|
5660
|
-
* The unit scale {@link Mat4.fromQuatToRef} composes with.
|
|
5661
|
-
*/
|
|
5662
|
-
const UNIT_SCALE = Object.freeze({
|
|
5663
|
-
x: 1,
|
|
5664
|
-
y: 1,
|
|
5665
|
-
z: 1
|
|
5666
|
-
});
|
|
5667
|
-
/**
|
|
5668
|
-
* A frozen identity matrix, for the common case of "no transform". It is a plain {@link Mat4Like}
|
|
5669
|
-
* rather than a {@link Mat4} because a `Float32Array` cannot be frozen — pass it to anything that
|
|
5670
|
-
* reads a matrix, and use `new Mat4()` when you need one you can write to.
|
|
5671
|
-
*
|
|
5672
|
-
* @example
|
|
5673
|
-
* ```ts
|
|
5674
|
-
* Mat4.transformPointToRef(MAT4_IDENTITY, point, out); // copies the point
|
|
5675
|
-
* ```
|
|
5676
|
-
*
|
|
5677
|
-
* @public
|
|
5678
|
-
*/
|
|
5679
|
-
const MAT4_IDENTITY = Object.freeze({
|
|
5680
|
-
length: 16,
|
|
5681
|
-
0: 1,
|
|
5682
|
-
1: 0,
|
|
5683
|
-
2: 0,
|
|
5684
|
-
3: 0,
|
|
5685
|
-
4: 0,
|
|
5686
|
-
5: 1,
|
|
5687
|
-
6: 0,
|
|
5688
|
-
7: 0,
|
|
5689
|
-
8: 0,
|
|
5690
|
-
9: 0,
|
|
5691
|
-
10: 1,
|
|
5692
|
-
11: 0,
|
|
5693
|
-
12: 0,
|
|
5694
|
-
13: 0,
|
|
5695
|
-
14: 0,
|
|
5696
|
-
15: 1
|
|
5697
|
-
});
|
|
5698
|
-
//#endregion
|
|
5699
4755
|
//#region src/lite/camera.ts
|
|
5700
4756
|
/** Scratch inverse view-projection matrix, created on first use (coding standards §4). */
|
|
5701
4757
|
let inverseViewProjection = null;
|
|
@@ -7344,7 +6400,7 @@ function environmentDefinition(overrides = {}) {
|
|
|
7344
6400
|
*
|
|
7345
6401
|
* @param scene - The render scene.
|
|
7346
6402
|
* @param rotationDegrees - The rotation around world Y, in degrees.
|
|
7347
|
-
* @param blur - How blurred the
|
|
6403
|
+
* @param blur - How blurred the visible skybox is, 0 to 1.
|
|
7348
6404
|
*
|
|
7349
6405
|
* @internal
|
|
7350
6406
|
*/
|
|
@@ -7793,7 +6849,7 @@ function environmentSchema() {
|
|
|
7793
6849
|
blur: f32(0, {
|
|
7794
6850
|
min: 0,
|
|
7795
6851
|
max: 1,
|
|
7796
|
-
tooltip: "How blurred the
|
|
6852
|
+
tooltip: "How blurred the visible skybox is, 0 to 1. Reflections and lighting are not blurred."
|
|
7797
6853
|
}),
|
|
7798
6854
|
skybox: record({
|
|
7799
6855
|
enabled: bool(SKYBOX_ENABLED_DEFAULT, { tooltip: "Whether a skybox is drawn; set it in the .environment.json." }),
|
|
@@ -7844,7 +6900,7 @@ let layer = null;
|
|
|
7844
6900
|
* @internal
|
|
7845
6901
|
*/
|
|
7846
6902
|
async function loadInstancedMeshSupport() {
|
|
7847
|
-
const loaded = layer ?? await import("./instanced-mesh-instance-
|
|
6903
|
+
const loaded = layer ?? await import("./instanced-mesh-instance-gguMoIeZ.js");
|
|
7848
6904
|
layer = loaded;
|
|
7849
6905
|
return loaded;
|
|
7850
6906
|
}
|
|
@@ -7872,7 +6928,7 @@ let surfaceLayer = null;
|
|
|
7872
6928
|
* @internal
|
|
7873
6929
|
*/
|
|
7874
6930
|
async function loadShaderSupport() {
|
|
7875
|
-
const loaded = shaderLayer ?? await import("./shader-material-
|
|
6931
|
+
const loaded = shaderLayer ?? await import("./shader-material-BIG3UDyu.js").then((n) => n.n);
|
|
7876
6932
|
shaderLayer = loaded;
|
|
7877
6933
|
await loaded.loadShaderMaterialAdapter();
|
|
7878
6934
|
return loaded;
|
|
@@ -7895,7 +6951,7 @@ function shaderSupport() {
|
|
|
7895
6951
|
* @internal
|
|
7896
6952
|
*/
|
|
7897
6953
|
async function loadSurfaceShaderSupport() {
|
|
7898
|
-
const loaded = surfaceLayer ?? await import("./surface-shader-
|
|
6954
|
+
const loaded = surfaceLayer ?? await import("./surface-shader-DAWIDdaa.js");
|
|
7899
6955
|
surfaceLayer = loaded;
|
|
7900
6956
|
return loaded;
|
|
7901
6957
|
}
|
|
@@ -8115,6 +7171,28 @@ var MaterialAsset = class {
|
|
|
8115
7171
|
return surfaceShaderSupport()?.surfaceShaders(this) ?? [];
|
|
8116
7172
|
}
|
|
8117
7173
|
/**
|
|
7174
|
+
* How far, in world metres, drawing with this material may move a vertex: the shader's
|
|
7175
|
+
* `// @ignifx displace`, or the sum over the enabled surface shaders. Renderers widen their
|
|
7176
|
+
* bounds by it.
|
|
7177
|
+
*
|
|
7178
|
+
* @returns The distance; `0` for a material whose vertex stage moves nothing.
|
|
7179
|
+
*
|
|
7180
|
+
* @internal
|
|
7181
|
+
*/
|
|
7182
|
+
get displacement() {
|
|
7183
|
+
const shader = this.#shader;
|
|
7184
|
+
if (shader !== null) return shader.shader.declaration.displace;
|
|
7185
|
+
const support = surfaceShaderSupport();
|
|
7186
|
+
if (support === null) return 0;
|
|
7187
|
+
const bindings = support.surfaceShaders(this);
|
|
7188
|
+
let total = 0;
|
|
7189
|
+
for (let index = 0; index < bindings.length; index += 1) {
|
|
7190
|
+
const binding = bindings[index];
|
|
7191
|
+
if (binding?.enabled === true) total += binding.shader.declaration.displace;
|
|
7192
|
+
}
|
|
7193
|
+
return total;
|
|
7194
|
+
}
|
|
7195
|
+
/**
|
|
8118
7196
|
* One attached surface shader, by the name it answers to — the `.surface.wgsl` basename unless the
|
|
8119
7197
|
* material renamed it.
|
|
8120
7198
|
*
|
|
@@ -9798,6 +8876,64 @@ function canWarmUp(material) {
|
|
|
9798
8876
|
return !isShaderMaterial(material) || material.storageBufferDecls.length === 0;
|
|
9799
8877
|
}
|
|
9800
8878
|
//#endregion
|
|
8879
|
+
//#region src/lite/pbr-deformers.ts
|
|
8880
|
+
/**
|
|
8881
|
+
* Which kinds of vertex deformation the PBR meshes of a scene use (`docs/architecture/07-rendering.md`
|
|
8882
|
+
* §2.2).
|
|
8883
|
+
*
|
|
8884
|
+
* Everything here is `@internal`.
|
|
8885
|
+
*
|
|
8886
|
+
* ## Why the render layer has to know (verified against `@babylonjs/lite@1.27.0`)
|
|
8887
|
+
*
|
|
8888
|
+
* Lite registers the PBR skinning and morph-target shader fragments only inside a full build of
|
|
8889
|
+
* the PBR group, and only when that build contains a skinned or morphed mesh (`buildPbrRenderables`,
|
|
8890
|
+
* `lib/material/pbr/pbr-renderable.js` 114-117). A mesh added after `registerScene` to a PBR group
|
|
8891
|
+
* that already exists is built at once by the group's `rebuildSingle` instead
|
|
8892
|
+
* (`processMaterialSwaps`, `lib/scene/scene-material-swap.js` 22-45), and that never registers
|
|
8893
|
+
* them. ignifx's warm-up builds the PBR group at start whenever the scene has a light (ADR-0014).
|
|
8894
|
+
*
|
|
8895
|
+
* So the first skinned model a page adds after `app.start()` is composed without its skinning
|
|
8896
|
+
* fragment, and Lite caches that bind-group layout under a key that does not say which fragments
|
|
8897
|
+
* were registered (`getOrCreatePbrBindings`, `lib/material/pbr/pbr-pipeline.js` 33-36). The next
|
|
8898
|
+
* renderable rebuild registers the fragment, reuses the cached layout, and builds a bind group with
|
|
8899
|
+
* one more entry than it: WebGPU rejects every frame from then on ("Binding entry sampler not set",
|
|
8900
|
+
* group 1, entries[3]) and the canvas stays black. The fragments are registered process-wide, so
|
|
8901
|
+
* every later app in the page was fine.
|
|
8902
|
+
*
|
|
8903
|
+
* The render sync system compares what this reports with what a full build has already composed,
|
|
8904
|
+
* and clears Lite's layout caches before the rebuild that first sees a new kind. Until that
|
|
8905
|
+
* rebuild, one frame after the mesh arrives, a skinned mesh draws in its bind pose; a morphed one
|
|
8906
|
+
* gets a shader that does not compile, so WebGPU rejects that frame or two.
|
|
8907
|
+
*/
|
|
8908
|
+
/**
|
|
8909
|
+
* The deformation kinds, as bits of the mask {@link readPbrDeformers} returns.
|
|
8910
|
+
*
|
|
8911
|
+
* @internal
|
|
8912
|
+
*/
|
|
8913
|
+
const PBR_DEFORMER = {
|
|
8914
|
+
/** A mesh skinned by a skeleton. */
|
|
8915
|
+
skin: 1,
|
|
8916
|
+
/** A mesh with morph targets. */
|
|
8917
|
+
morph: 2
|
|
8918
|
+
};
|
|
8919
|
+
/**
|
|
8920
|
+
* Reads which deformation kinds the scene's PBR meshes use.
|
|
8921
|
+
*
|
|
8922
|
+
* @param scene - The scene, or anything with its mesh list.
|
|
8923
|
+
* @returns A mask of {@link PBR_DEFORMER} bits; `0` when no PBR mesh deforms.
|
|
8924
|
+
*
|
|
8925
|
+
* @internal
|
|
8926
|
+
*/
|
|
8927
|
+
function readPbrDeformers(scene) {
|
|
8928
|
+
let kinds = 0;
|
|
8929
|
+
for (const mesh of scene.meshes) {
|
|
8930
|
+
if (!isPbrMaterial(mesh.material)) continue;
|
|
8931
|
+
if (mesh.skeleton) kinds |= PBR_DEFORMER.skin;
|
|
8932
|
+
if (mesh.morphTargets) kinds |= PBR_DEFORMER.morph;
|
|
8933
|
+
}
|
|
8934
|
+
return kinds;
|
|
8935
|
+
}
|
|
8936
|
+
//#endregion
|
|
9801
8937
|
//#region src/lite/render-diagnostics.ts
|
|
9802
8938
|
/**
|
|
9803
8939
|
* Render diagnostics and engine option mapping (`docs/architecture/07-rendering.md` §1 and §5) —
|
|
@@ -10712,6 +9848,11 @@ var RendererImpl = class {
|
|
|
10712
9848
|
needsCasterRebuild = false;
|
|
10713
9849
|
/** `true` once a light gained or lost a shadow generator, so the next rebuild needs fresh layouts. */
|
|
10714
9850
|
needsShadowLayoutReset = false;
|
|
9851
|
+
/**
|
|
9852
|
+
* The PBR deformation kinds (`PBR_DEFORMER` bits) a full renderable build has already composed on
|
|
9853
|
+
* this engine. A kind missing from it gets fresh layouts on its first rebuild (`../lite/pbr-deformers.ts`).
|
|
9854
|
+
*/
|
|
9855
|
+
builtPbrDeformers = 0;
|
|
10715
9856
|
/** `true` once a camera was added, removed, enabled, disabled, or re-prioritised. */
|
|
10716
9857
|
needsCameraSelect = true;
|
|
10717
9858
|
/** `true` once the world has been told it has no enabled camera, so `IGX-0706` is logged once. */
|
|
@@ -11282,6 +10423,7 @@ var RendererImpl = class {
|
|
|
11282
10423
|
*/
|
|
11283
10424
|
markSceneRegistered() {
|
|
11284
10425
|
this.#isSceneRegistered = true;
|
|
10426
|
+
this.builtPbrDeformers = readPbrDeformers(this.scene);
|
|
11285
10427
|
}
|
|
11286
10428
|
/**
|
|
11287
10429
|
* Records whether Babylon Lite's render loop is driving frames, which is what decides whether a
|
|
@@ -11498,6 +10640,7 @@ var InstancedMeshRenderer = class InstancedMeshRenderer extends Component {
|
|
|
11498
10640
|
#appliedCastShadows = false;
|
|
11499
10641
|
#hasAppliedSettings = false;
|
|
11500
10642
|
#hasWarnedAboutLateSetting = false;
|
|
10643
|
+
#hasWarnedAboutLodWithoutCulling = false;
|
|
11501
10644
|
/**
|
|
11502
10645
|
* The Babylon Lite meshes this renderer draws. Unstable escape hatch
|
|
11503
10646
|
* (`docs/architecture/00-overview.md` §3).
|
|
@@ -11619,6 +10762,7 @@ var InstancedMeshRenderer = class InstancedMeshRenderer extends Component {
|
|
|
11619
10762
|
this.#hasAppliedSettings = true;
|
|
11620
10763
|
const instance = this.#instance;
|
|
11621
10764
|
if (instance === null) return changed;
|
|
10765
|
+
instance.applyDisplacement(this.#upload, this.#displacement(), this.entity.transform);
|
|
11622
10766
|
const uploaded = instance.sync(this.#upload, this.#material(renderer), this.receiveShadows, this.renderOrder, this.pickable, this.lod, this.#matrices ?? noMatrices(), this.#count, this.#colors, this.castShadows, this.isEnabledInHierarchy);
|
|
11623
10767
|
return changed || uploaded;
|
|
11624
10768
|
}
|
|
@@ -11691,6 +10835,17 @@ var InstancedMeshRenderer = class InstancedMeshRenderer extends Component {
|
|
|
11691
10835
|
this.app.log.warn(`${CoreErrorCode.instancingSettingTooLate}: {entity} changed {field} on an InstancedMeshRenderer after the scene was registered; the value in use was kept. Set capacity, gpuCulling and lod.mesh before app.start().`, this.entity.name, field);
|
|
11692
10836
|
}
|
|
11693
10837
|
/**
|
|
10838
|
+
* Says once, at warning level, that a LOD partner was declared with GPU culling off. Lite picks
|
|
10839
|
+
* the far instances in the culling pass, so without it the partner never draws.
|
|
10840
|
+
*
|
|
10841
|
+
* @param lod - The `lod` field being applied.
|
|
10842
|
+
*/
|
|
10843
|
+
#warnAboutLodWithoutCulling(lod) {
|
|
10844
|
+
if (this.#hasWarnedAboutLodWithoutCulling || this.gpuCulling || lod === null || lod.mesh === null) return;
|
|
10845
|
+
this.#hasWarnedAboutLodWithoutCulling = true;
|
|
10846
|
+
this.app.log.warn(`${CoreErrorCode.instancingLodWithoutCulling}: {entity} declares an InstancedMeshRenderer lod with gpuCulling off; the LOD mesh never draws. Turn gpuCulling on.`, this.entity.name);
|
|
10847
|
+
}
|
|
10848
|
+
/**
|
|
11694
10849
|
* Builds or rebuilds the meshes when the template or a baked setting changed.
|
|
11695
10850
|
*
|
|
11696
10851
|
* @param renderer - The rendering service, for the scene.
|
|
@@ -11713,6 +10868,7 @@ var InstancedMeshRenderer = class InstancedMeshRenderer extends Component {
|
|
|
11713
10868
|
this.#appliedLodHandle = lodField?.mesh ?? null;
|
|
11714
10869
|
this.#upload.appliedCapacity = capacity;
|
|
11715
10870
|
this.#appliedGpuCulling = this.gpuCulling;
|
|
10871
|
+
this.#warnAboutLodWithoutCulling(lodField);
|
|
11716
10872
|
const template = loaded?.lite.mesh ?? null;
|
|
11717
10873
|
if (template === null) return removed;
|
|
11718
10874
|
const support = instancedMeshSupport();
|
|
@@ -11747,6 +10903,15 @@ var InstancedMeshRenderer = class InstancedMeshRenderer extends Component {
|
|
|
11747
10903
|
return declared?.state === "loaded" ? declared.value.lite.material : renderer.defaultMaterial().lite.material;
|
|
11748
10904
|
}
|
|
11749
10905
|
/**
|
|
10906
|
+
* How far the material's vertex stage may move a vertex: its shaders' `// @ignifx displace`.
|
|
10907
|
+
*
|
|
10908
|
+
* @returns The distance in world metres; `0` for the default material or one still loading.
|
|
10909
|
+
*/
|
|
10910
|
+
#displacement() {
|
|
10911
|
+
const declared = this.materials[0];
|
|
10912
|
+
return declared?.state === "loaded" ? declared.value.displacement : 0;
|
|
10913
|
+
}
|
|
10914
|
+
/**
|
|
11750
10915
|
* Removes the meshes from the scene, when there are any.
|
|
11751
10916
|
*
|
|
11752
10917
|
* @param renderer - The rendering service, for the scene.
|
|
@@ -11829,7 +10994,7 @@ function instancedMeshRendererSchema() {
|
|
|
11829
10994
|
min: 1,
|
|
11830
10995
|
tooltip: "The largest instance count; fixed once the scene is registered."
|
|
11831
10996
|
}),
|
|
11832
|
-
gpuCulling: bool(true, { tooltip: "Cull instances on the GPU; fixed once the scene is registered." }),
|
|
10997
|
+
gpuCulling: bool(true, { tooltip: "Cull instances on the GPU; fixed once the scene is registered. The lod partner needs it." }),
|
|
11833
10998
|
castShadows: bool(true, { tooltip: "Whether the instances are rendered into shadow maps." }),
|
|
11834
10999
|
receiveShadows: bool(true, { tooltip: "Whether shadow maps darken the instances." }),
|
|
11835
11000
|
renderOrder: i32(0, { tooltip: "Sort key within the opaque or transparent phase; lower draws first." }),
|
|
@@ -11844,7 +11009,7 @@ function instancedMeshRendererSchema() {
|
|
|
11844
11009
|
min: 0,
|
|
11845
11010
|
tooltip: "Width of the per-instance dither window centred on the distance."
|
|
11846
11011
|
})
|
|
11847
|
-
}), { tooltip: "An optional coarse mesh for far instances;
|
|
11012
|
+
}), { tooltip: "An optional coarse mesh for far instances; draws only while gpuCulling is on." })
|
|
11848
11013
|
});
|
|
11849
11014
|
}
|
|
11850
11015
|
//#endregion
|
|
@@ -12276,7 +11441,8 @@ function readMaterialEpoch(scene) {
|
|
|
12276
11441
|
* Makes the next renderable rebuild create fresh bind-group layouts for every material.
|
|
12277
11442
|
*
|
|
12278
11443
|
* @remarks
|
|
12279
|
-
* Call it before {@link rebuildRenderables} whenever a light gained or lost a shadow generator
|
|
11444
|
+
* Call it before {@link rebuildRenderables} whenever a light gained or lost a shadow generator,
|
|
11445
|
+
* and when the scene gained its first skinned or morphed PBR mesh (`./pbr-deformers.ts`).
|
|
12280
11446
|
* Lite caches a material's bindings, shadow bind-group layout included, under a key that does not
|
|
12281
11447
|
* name the shadow maps (`getOrCreatePbrBindings`, `lib/material/pbr/pbr-pipeline.js` 36). So after
|
|
12282
11448
|
* the number of shadow-casting lights changes, a rebuild reuses a layout sized for the old number
|
|
@@ -14389,7 +13555,7 @@ let effectLayer = null;
|
|
|
14389
13555
|
* @internal
|
|
14390
13556
|
*/
|
|
14391
13557
|
async function loadPostEffectSupport() {
|
|
14392
|
-
const [compiler, effects] = await Promise.all([compilerLayer ?? import("./post-effect-compiler-
|
|
13558
|
+
const [compiler, effects] = await Promise.all([compilerLayer ?? import("./post-effect-compiler-Rce26Eue.js"), effectLayer ?? import("./effect-task-CMbuO6Kb.js")]);
|
|
14393
13559
|
compilerLayer = compiler;
|
|
14394
13560
|
effectLayer = effects;
|
|
14395
13561
|
}
|
|
@@ -14527,7 +13693,7 @@ function createShaderLoader() {
|
|
|
14527
13693
|
type: SHADER_ASSET_TYPE,
|
|
14528
13694
|
extensions: SHADER_FILE_EXTENSIONS,
|
|
14529
13695
|
async load(ctx) {
|
|
14530
|
-
const [source, pragma] = await Promise.all([ctx.fetchText(), import("./shader-pragma-
|
|
13696
|
+
const [source, pragma] = await Promise.all([ctx.fetchText(), import("./shader-pragma-tw6AKaQD.js")]);
|
|
14531
13697
|
const declaration = pragma.parseShaderDeclaration(source, ctx.address);
|
|
14532
13698
|
await loadShaderSupport();
|
|
14533
13699
|
if (declaration.kind === "surface") await loadSurfaceShaderSupport();
|
|
@@ -15174,6 +14340,12 @@ var MeshInstance = class {
|
|
|
15174
14340
|
#renderOrder = NaN;
|
|
15175
14341
|
#pickable = null;
|
|
15176
14342
|
#visible = false;
|
|
14343
|
+
/** The template's own box, which a displacement margin widens; `null` until one is first applied. */
|
|
14344
|
+
#ownBox = null;
|
|
14345
|
+
/** The object-space margins last written, per axis. */
|
|
14346
|
+
#margin = new Vec3();
|
|
14347
|
+
/** Scratch for the entity's world scale. */
|
|
14348
|
+
#scale = new Vec3();
|
|
15177
14349
|
/**
|
|
15178
14350
|
* Clones a template under an entity's node, tags it, and adds it to the scene.
|
|
15179
14351
|
*
|
|
@@ -15247,6 +14419,36 @@ var MeshInstance = class {
|
|
|
15247
14419
|
}
|
|
15248
14420
|
}
|
|
15249
14421
|
/**
|
|
14422
|
+
* Widens the clone's bounds by how far its material's vertex stage may move a vertex, so a
|
|
14423
|
+
* directional shadow map fitted to them still covers the moved shape.
|
|
14424
|
+
*
|
|
14425
|
+
* @remarks
|
|
14426
|
+
* The margin is in world metres and the bounds are object-local, so each axis is divided by the
|
|
14427
|
+
* entity's world scale along it. Only the clone is widened: it gets bound arrays of its own first,
|
|
14428
|
+
* because a fresh clone shares the template's with every other renderer of the asset.
|
|
14429
|
+
*
|
|
14430
|
+
* @param margin - The material's displacement, in world metres; `0` restores the template's box.
|
|
14431
|
+
* @param transform - The entity's transform, whose world scale the clone inherits.
|
|
14432
|
+
*/
|
|
14433
|
+
applyDisplacement(margin, transform) {
|
|
14434
|
+
const scale = this.#scale;
|
|
14435
|
+
if (margin > 0) transform.lossyScaleToRef(scale);
|
|
14436
|
+
const x = objectMargin(margin, scale.x);
|
|
14437
|
+
const y = objectMargin(margin, scale.y);
|
|
14438
|
+
const z = objectMargin(margin, scale.z);
|
|
14439
|
+
const applied = this.#margin;
|
|
14440
|
+
if (x === applied.x && y === applied.y && z === applied.z) return;
|
|
14441
|
+
applied.set(x, y, z);
|
|
14442
|
+
const mesh = this.mesh;
|
|
14443
|
+
let box = this.#ownBox;
|
|
14444
|
+
if (box === null) {
|
|
14445
|
+
box = readBox(mesh);
|
|
14446
|
+
detachMeshBounds(mesh);
|
|
14447
|
+
this.#ownBox = box;
|
|
14448
|
+
}
|
|
14449
|
+
setMeshBounds(mesh, (box[0] ?? 0) - x, (box[1] ?? 0) - y, (box[2] ?? 0) - z, (box[3] ?? 0) + x, (box[4] ?? 0) + y, (box[5] ?? 0) + z);
|
|
14450
|
+
}
|
|
14451
|
+
/**
|
|
15250
14452
|
* Shows or hides the clone, when the state changed.
|
|
15251
14453
|
*
|
|
15252
14454
|
* @param visible - `entity.activeInHierarchy && component.enabled`.
|
|
@@ -15266,6 +14468,39 @@ var MeshInstance = class {
|
|
|
15266
14468
|
}
|
|
15267
14469
|
};
|
|
15268
14470
|
/**
|
|
14471
|
+
* Converts a world-space margin into the object-space margin along one axis.
|
|
14472
|
+
*
|
|
14473
|
+
* @param margin - The margin, in world metres.
|
|
14474
|
+
* @param scale - The entity's world scale along the axis.
|
|
14475
|
+
* @returns The margin in object units; `0` for no margin or a collapsed axis.
|
|
14476
|
+
*/
|
|
14477
|
+
function objectMargin(margin, scale) {
|
|
14478
|
+
return margin > 0 && scale > 1e-9 ? margin / scale : 0;
|
|
14479
|
+
}
|
|
14480
|
+
/**
|
|
14481
|
+
* Reads a mesh's object-local box into six numbers.
|
|
14482
|
+
*
|
|
14483
|
+
* @remarks
|
|
14484
|
+
* A mesh without bounds falls back to the half-metre cube `computeDirectionalLightMatrix` assumes
|
|
14485
|
+
* for one (`lib/shadow/shadow-base.js` 62).
|
|
14486
|
+
*
|
|
14487
|
+
* @param mesh - The mesh to read.
|
|
14488
|
+
* @returns `minX, minY, minZ, maxX, maxY, maxZ`.
|
|
14489
|
+
*/
|
|
14490
|
+
function readBox(mesh) {
|
|
14491
|
+
const min = mesh.boundMin ?? [
|
|
14492
|
+
-.5,
|
|
14493
|
+
-.5,
|
|
14494
|
+
-.5
|
|
14495
|
+
];
|
|
14496
|
+
const max = mesh.boundMax ?? [
|
|
14497
|
+
.5,
|
|
14498
|
+
.5,
|
|
14499
|
+
.5
|
|
14500
|
+
];
|
|
14501
|
+
return Float64Array.of(min[0], min[1], min[2], max[0], max[1], max[2]);
|
|
14502
|
+
}
|
|
14503
|
+
/**
|
|
15269
14504
|
* Narrows a cloned subtree root to a mesh.
|
|
15270
14505
|
*
|
|
15271
14506
|
* @remarks
|
|
@@ -15384,6 +14619,7 @@ var MeshRenderer = class MeshRenderer extends Component {
|
|
|
15384
14619
|
const instance = this.#instance;
|
|
15385
14620
|
if (instance === null) return changed;
|
|
15386
14621
|
instance.applyMaterial(this.#material(renderer));
|
|
14622
|
+
instance.applyDisplacement(this.#displacement(), this.entity.transform);
|
|
15387
14623
|
instance.applyFlags(this.receiveShadows, this.renderOrder, this.pickable);
|
|
15388
14624
|
instance.applyVisible(this.isEnabledInHierarchy);
|
|
15389
14625
|
return changed;
|
|
@@ -15459,6 +14695,15 @@ var MeshRenderer = class MeshRenderer extends Component {
|
|
|
15459
14695
|
return declared?.state === "loaded" ? declared.value.lite.material : renderer.defaultMaterial().lite.material;
|
|
15460
14696
|
}
|
|
15461
14697
|
/**
|
|
14698
|
+
* How far the material's vertex stage may move a vertex: its shaders' `// @ignifx displace`.
|
|
14699
|
+
*
|
|
14700
|
+
* @returns The distance in world metres; `0` for the default material or one still loading.
|
|
14701
|
+
*/
|
|
14702
|
+
#displacement() {
|
|
14703
|
+
const declared = this.materials[0];
|
|
14704
|
+
return declared?.state === "loaded" ? declared.value.displacement : 0;
|
|
14705
|
+
}
|
|
14706
|
+
/**
|
|
15462
14707
|
* Removes the clone from the scene, when there is one.
|
|
15463
14708
|
*
|
|
15464
14709
|
* @param renderer - The rendering service, for the scene.
|
|
@@ -17327,11 +16572,13 @@ var RenderSyncSystem = class {
|
|
|
17327
16572
|
do {
|
|
17328
16573
|
if (renderer.isHeadless || !renderer.isSceneRegistered) return;
|
|
17329
16574
|
try {
|
|
17330
|
-
|
|
16575
|
+
const deformers = readPbrDeformers(renderer.scene);
|
|
16576
|
+
if (renderer.needsShadowLayoutReset || (deformers & ~renderer.builtPbrDeformers) !== 0) {
|
|
17331
16577
|
renderer.needsShadowLayoutReset = false;
|
|
17332
16578
|
forgetMaterialBindingLayouts(renderer.engine);
|
|
17333
16579
|
}
|
|
17334
16580
|
await rebuildRenderables(renderer.scene);
|
|
16581
|
+
renderer.builtPbrDeformers |= deformers;
|
|
17335
16582
|
} catch (error) {
|
|
17336
16583
|
renderer.app.onError.emit({
|
|
17337
16584
|
error,
|
|
@@ -19500,707 +18747,6 @@ function collectAssetRefs(value, add) {
|
|
|
19500
18747
|
for (const key of Object.keys(object)) collectAssetRefs(object[key] ?? null, add);
|
|
19501
18748
|
}
|
|
19502
18749
|
//#endregion
|
|
19503
|
-
//#region src/math/vec3.ts
|
|
19504
|
-
/**
|
|
19505
|
-
* A 3-component vector: a position or a direction in metres, or a per-axis scale. ignifx is
|
|
19506
|
-
* left-handed with Y up and +Z forward (ADR-0011), so {@link Vec3.forward} is `(0, 0, 1)` and
|
|
19507
|
-
* {@link Vec3.right} is `(1, 0, 0)`.
|
|
19508
|
-
*
|
|
19509
|
-
* The fields are plain mutable numbers, which is what makes a `Vec3` interchangeable with Babylon
|
|
19510
|
-
* Lite's `{ x, y, z }` vectors and with the live {@link MutableVec3} views a `Transform` exposes.
|
|
19511
|
-
*
|
|
19512
|
-
* Three families of operations, and the names say which is which:
|
|
19513
|
-
*
|
|
19514
|
-
* - instance methods mutate the receiver and return `this` (`a.add(b)` means `a += b`);
|
|
19515
|
-
* - `ToRef` statics write into a final `out` argument, allocate nothing, and are safe when `out`
|
|
19516
|
-
* aliases an input — these are what per-frame code uses (coding standards section 7);
|
|
19517
|
-
* - the remaining statics return a fresh vector and are documented as allocating.
|
|
19518
|
-
*
|
|
19519
|
-
* @example
|
|
19520
|
-
* ```ts
|
|
19521
|
-
* // convenience code
|
|
19522
|
-
* const offset = Vec3.add(position, Vec3.scale(direction, distance));
|
|
19523
|
-
*
|
|
19524
|
-
* // per-frame code: no allocation
|
|
19525
|
-
* Vec3.scaleToRef(direction, distance, scratch);
|
|
19526
|
-
* Vec3.addToRef(position, scratch, position);
|
|
19527
|
-
* ```
|
|
19528
|
-
*
|
|
19529
|
-
* @public
|
|
19530
|
-
*/
|
|
19531
|
-
var Vec3 = class Vec3 {
|
|
19532
|
-
/** The X component; positive is right. */
|
|
19533
|
-
x;
|
|
19534
|
-
/** The Y component; positive is up. */
|
|
19535
|
-
y;
|
|
19536
|
-
/** The Z component; positive is forward. */
|
|
19537
|
-
z;
|
|
19538
|
-
/**
|
|
19539
|
-
* Creates a vector.
|
|
19540
|
-
*
|
|
19541
|
-
* @param x - The X component. Defaults to 0.
|
|
19542
|
-
* @param y - The Y component. Defaults to 0.
|
|
19543
|
-
* @param z - The Z component. Defaults to 0.
|
|
19544
|
-
*/
|
|
19545
|
-
constructor(x = 0, y = 0, z = 0) {
|
|
19546
|
-
this.x = x;
|
|
19547
|
-
this.y = y;
|
|
19548
|
-
this.z = z;
|
|
19549
|
-
}
|
|
19550
|
-
/**
|
|
19551
|
-
* Assigns every component at once.
|
|
19552
|
-
*
|
|
19553
|
-
* @param x - The new X component.
|
|
19554
|
-
* @param y - The new Y component.
|
|
19555
|
-
* @param z - The new Z component.
|
|
19556
|
-
* @returns This vector.
|
|
19557
|
-
*/
|
|
19558
|
-
set(x, y, z) {
|
|
19559
|
-
this.x = x;
|
|
19560
|
-
this.y = y;
|
|
19561
|
-
this.z = z;
|
|
19562
|
-
return this;
|
|
19563
|
-
}
|
|
19564
|
-
/**
|
|
19565
|
-
* Copies every component from another vector.
|
|
19566
|
-
*
|
|
19567
|
-
* @param v - The vector to read.
|
|
19568
|
-
* @returns This vector.
|
|
19569
|
-
*/
|
|
19570
|
-
copyFrom(v) {
|
|
19571
|
-
this.x = v.x;
|
|
19572
|
-
this.y = v.y;
|
|
19573
|
-
this.z = v.z;
|
|
19574
|
-
return this;
|
|
19575
|
-
}
|
|
19576
|
-
/**
|
|
19577
|
-
* Copies this vector into a new one.
|
|
19578
|
-
*
|
|
19579
|
-
* @returns A new vector. **Allocates.**
|
|
19580
|
-
*/
|
|
19581
|
-
clone() {
|
|
19582
|
-
return new Vec3(this.x, this.y, this.z);
|
|
19583
|
-
}
|
|
19584
|
-
/**
|
|
19585
|
-
* Adds another vector to this one.
|
|
19586
|
-
*
|
|
19587
|
-
* @param v - The vector to add.
|
|
19588
|
-
* @returns This vector.
|
|
19589
|
-
*/
|
|
19590
|
-
add(v) {
|
|
19591
|
-
this.x += v.x;
|
|
19592
|
-
this.y += v.y;
|
|
19593
|
-
this.z += v.z;
|
|
19594
|
-
return this;
|
|
19595
|
-
}
|
|
19596
|
-
/**
|
|
19597
|
-
* Adds a scaled vector to this one — the "move by velocity times delta time" step, without a
|
|
19598
|
-
* temporary.
|
|
19599
|
-
*
|
|
19600
|
-
* @param v - The vector to add.
|
|
19601
|
-
* @param scale - The factor to multiply `v` by first.
|
|
19602
|
-
* @returns This vector.
|
|
19603
|
-
*
|
|
19604
|
-
* @example
|
|
19605
|
-
* ```ts
|
|
19606
|
-
* position.addScaled(velocity, time.deltaTime);
|
|
19607
|
-
* ```
|
|
19608
|
-
*/
|
|
19609
|
-
addScaled(v, scale) {
|
|
19610
|
-
this.x += v.x * scale;
|
|
19611
|
-
this.y += v.y * scale;
|
|
19612
|
-
this.z += v.z * scale;
|
|
19613
|
-
return this;
|
|
19614
|
-
}
|
|
19615
|
-
/**
|
|
19616
|
-
* Subtracts another vector from this one.
|
|
19617
|
-
*
|
|
19618
|
-
* @param v - The vector to subtract.
|
|
19619
|
-
* @returns This vector.
|
|
19620
|
-
*/
|
|
19621
|
-
subtract(v) {
|
|
19622
|
-
this.x -= v.x;
|
|
19623
|
-
this.y -= v.y;
|
|
19624
|
-
this.z -= v.z;
|
|
19625
|
-
return this;
|
|
19626
|
-
}
|
|
19627
|
-
/**
|
|
19628
|
-
* Multiplies this vector by another component by component.
|
|
19629
|
-
*
|
|
19630
|
-
* @param v - The vector to multiply by.
|
|
19631
|
-
* @returns This vector.
|
|
19632
|
-
*/
|
|
19633
|
-
multiply(v) {
|
|
19634
|
-
this.x *= v.x;
|
|
19635
|
-
this.y *= v.y;
|
|
19636
|
-
this.z *= v.z;
|
|
19637
|
-
return this;
|
|
19638
|
-
}
|
|
19639
|
-
/**
|
|
19640
|
-
* Multiplies every component by a number.
|
|
19641
|
-
*
|
|
19642
|
-
* @param scale - The factor.
|
|
19643
|
-
* @returns This vector.
|
|
19644
|
-
*/
|
|
19645
|
-
scale(scale) {
|
|
19646
|
-
this.x *= scale;
|
|
19647
|
-
this.y *= scale;
|
|
19648
|
-
this.z *= scale;
|
|
19649
|
-
return this;
|
|
19650
|
-
}
|
|
19651
|
-
/**
|
|
19652
|
-
* Flips this vector to point the other way.
|
|
19653
|
-
*
|
|
19654
|
-
* @returns This vector.
|
|
19655
|
-
*/
|
|
19656
|
-
negate() {
|
|
19657
|
-
this.x = -this.x;
|
|
19658
|
-
this.y = -this.y;
|
|
19659
|
-
this.z = -this.z;
|
|
19660
|
-
return this;
|
|
19661
|
-
}
|
|
19662
|
-
/**
|
|
19663
|
-
* Scales this vector to unit length. A zero-length vector is left at zero rather than becoming
|
|
19664
|
-
* `NaN`, so callers can normalize an unchecked direction safely.
|
|
19665
|
-
*
|
|
19666
|
-
* @returns This vector.
|
|
19667
|
-
*/
|
|
19668
|
-
normalize() {
|
|
19669
|
-
const length = Math.hypot(this.x, this.y, this.z);
|
|
19670
|
-
if (length === 0) return this;
|
|
19671
|
-
return this.scale(1 / length);
|
|
19672
|
-
}
|
|
19673
|
-
/**
|
|
19674
|
-
* Replaces this vector with its cross product with another (`this = this x v`).
|
|
19675
|
-
*
|
|
19676
|
-
* @param v - The right-hand vector.
|
|
19677
|
-
* @returns This vector.
|
|
19678
|
-
*/
|
|
19679
|
-
cross(v) {
|
|
19680
|
-
return Vec3.crossToRef(this, v, this);
|
|
19681
|
-
}
|
|
19682
|
-
/**
|
|
19683
|
-
* Moves this vector towards a target by an interpolant.
|
|
19684
|
-
*
|
|
19685
|
-
* @param target - The vector reached at `t === 1`.
|
|
19686
|
-
* @param t - The interpolant; not clamped.
|
|
19687
|
-
* @returns This vector.
|
|
19688
|
-
*/
|
|
19689
|
-
lerp(target, t) {
|
|
19690
|
-
return Vec3.lerpToRef(this, target, t, this);
|
|
19691
|
-
}
|
|
19692
|
-
/**
|
|
19693
|
-
* The dot product of this vector with another.
|
|
19694
|
-
*
|
|
19695
|
-
* @param v - The other vector.
|
|
19696
|
-
* @returns The dot product.
|
|
19697
|
-
*/
|
|
19698
|
-
dot(v) {
|
|
19699
|
-
return this.x * v.x + this.y * v.y + this.z * v.z;
|
|
19700
|
-
}
|
|
19701
|
-
/**
|
|
19702
|
-
* The length of this vector, in metres.
|
|
19703
|
-
*
|
|
19704
|
-
* @returns The length.
|
|
19705
|
-
*/
|
|
19706
|
-
length() {
|
|
19707
|
-
return Math.hypot(this.x, this.y, this.z);
|
|
19708
|
-
}
|
|
19709
|
-
/**
|
|
19710
|
-
* The squared length of this vector. Prefer it over `length()` when comparing distances:
|
|
19711
|
-
* it skips the square root.
|
|
19712
|
-
*
|
|
19713
|
-
* @returns The squared length.
|
|
19714
|
-
*/
|
|
19715
|
-
lengthSquared() {
|
|
19716
|
-
return this.x * this.x + this.y * this.y + this.z * this.z;
|
|
19717
|
-
}
|
|
19718
|
-
/**
|
|
19719
|
-
* The distance from this vector to another, in metres.
|
|
19720
|
-
*
|
|
19721
|
-
* @param v - The other position.
|
|
19722
|
-
* @returns The distance.
|
|
19723
|
-
*/
|
|
19724
|
-
distance(v) {
|
|
19725
|
-
return Math.hypot(this.x - v.x, this.y - v.y, this.z - v.z);
|
|
19726
|
-
}
|
|
19727
|
-
/**
|
|
19728
|
-
* The squared distance from this vector to another.
|
|
19729
|
-
*
|
|
19730
|
-
* @param v - The other position.
|
|
19731
|
-
* @returns The squared distance.
|
|
19732
|
-
*/
|
|
19733
|
-
distanceSquared(v) {
|
|
19734
|
-
return Vec3.distanceSquared(this, v);
|
|
19735
|
-
}
|
|
19736
|
-
/**
|
|
19737
|
-
* Compares this vector with another, component by component, with a tolerance.
|
|
19738
|
-
*
|
|
19739
|
-
* @param v - The vector to compare against.
|
|
19740
|
-
* @param epsilon - The largest per-component difference still considered equal.
|
|
19741
|
-
* @returns `true` when every component matches within `epsilon`.
|
|
19742
|
-
*/
|
|
19743
|
-
equalsWithEpsilon(v, epsilon = EPSILON) {
|
|
19744
|
-
return Vec3.equalsWithEpsilon(this, v, epsilon);
|
|
19745
|
-
}
|
|
19746
|
-
/**
|
|
19747
|
-
* Writes this vector into a `Float32Array`, for GPU upload. The output comes first to mirror
|
|
19748
|
-
* Babylon Lite's `ObservableVec3.toArray`, the shape the adapter has to interoperate with.
|
|
19749
|
-
*
|
|
19750
|
-
* @param out - The array to write into.
|
|
19751
|
-
* @param offset - The index of the X component. Defaults to 0.
|
|
19752
|
-
* @returns `out`.
|
|
19753
|
-
*/
|
|
19754
|
-
toArray(out, offset = 0) {
|
|
19755
|
-
out[offset] = this.x;
|
|
19756
|
-
out[offset + 1] = this.y;
|
|
19757
|
-
out[offset + 2] = this.z;
|
|
19758
|
-
return out;
|
|
19759
|
-
}
|
|
19760
|
-
/**
|
|
19761
|
-
* The zero vector.
|
|
19762
|
-
*
|
|
19763
|
-
* @returns A new `(0, 0, 0)`. **Allocates**; use {@link VEC3_ZERO} when a read-only value will do.
|
|
19764
|
-
*/
|
|
19765
|
-
static zero() {
|
|
19766
|
-
return new Vec3(0, 0, 0);
|
|
19767
|
-
}
|
|
19768
|
-
/**
|
|
19769
|
-
* The vector whose components are all one.
|
|
19770
|
-
*
|
|
19771
|
-
* @returns A new `(1, 1, 1)`. **Allocates.**
|
|
19772
|
-
*/
|
|
19773
|
-
static one() {
|
|
19774
|
-
return new Vec3(1, 1, 1);
|
|
19775
|
-
}
|
|
19776
|
-
/**
|
|
19777
|
-
* The world up direction.
|
|
19778
|
-
*
|
|
19779
|
-
* @returns A new `(0, 1, 0)`. **Allocates**; see {@link VEC3_UP}.
|
|
19780
|
-
*/
|
|
19781
|
-
static up() {
|
|
19782
|
-
return new Vec3(0, 1, 0);
|
|
19783
|
-
}
|
|
19784
|
-
/**
|
|
19785
|
-
* The world down direction.
|
|
19786
|
-
*
|
|
19787
|
-
* @returns A new `(0, -1, 0)`. **Allocates.**
|
|
19788
|
-
*/
|
|
19789
|
-
static down() {
|
|
19790
|
-
return new Vec3(0, -1, 0);
|
|
19791
|
-
}
|
|
19792
|
-
/**
|
|
19793
|
-
* The world right direction.
|
|
19794
|
-
*
|
|
19795
|
-
* @returns A new `(1, 0, 0)`. **Allocates**; see {@link VEC3_RIGHT}.
|
|
19796
|
-
*/
|
|
19797
|
-
static right() {
|
|
19798
|
-
return new Vec3(1, 0, 0);
|
|
19799
|
-
}
|
|
19800
|
-
/**
|
|
19801
|
-
* The world left direction.
|
|
19802
|
-
*
|
|
19803
|
-
* @returns A new `(-1, 0, 0)`. **Allocates.**
|
|
19804
|
-
*/
|
|
19805
|
-
static left() {
|
|
19806
|
-
return new Vec3(-1, 0, 0);
|
|
19807
|
-
}
|
|
19808
|
-
/**
|
|
19809
|
-
* The world forward direction. ignifx is left-handed, so forward is **+Z** (ADR-0011).
|
|
19810
|
-
*
|
|
19811
|
-
* @returns A new `(0, 0, 1)`. **Allocates**; see {@link VEC3_FORWARD}.
|
|
19812
|
-
*/
|
|
19813
|
-
static forward() {
|
|
19814
|
-
return new Vec3(0, 0, 1);
|
|
19815
|
-
}
|
|
19816
|
-
/**
|
|
19817
|
-
* The world backward direction.
|
|
19818
|
-
*
|
|
19819
|
-
* @returns A new `(0, 0, -1)`. **Allocates.**
|
|
19820
|
-
*/
|
|
19821
|
-
static backward() {
|
|
19822
|
-
return new Vec3(0, 0, -1);
|
|
19823
|
-
}
|
|
19824
|
-
/**
|
|
19825
|
-
* Copies any vector-shaped value into a `Vec3`.
|
|
19826
|
-
*
|
|
19827
|
-
* @param v - The vector to copy.
|
|
19828
|
-
* @returns A new vector. **Allocates.**
|
|
19829
|
-
*
|
|
19830
|
-
* @example
|
|
19831
|
-
* ```ts
|
|
19832
|
-
* const position = Vec3.from(node.position); // snapshot of a live Lite view
|
|
19833
|
-
* ```
|
|
19834
|
-
*/
|
|
19835
|
-
static from(v) {
|
|
19836
|
-
return new Vec3(v.x, v.y, v.z);
|
|
19837
|
-
}
|
|
19838
|
-
/**
|
|
19839
|
-
* Adds two vectors.
|
|
19840
|
-
*
|
|
19841
|
-
* @param a - The first vector.
|
|
19842
|
-
* @param b - The second vector.
|
|
19843
|
-
* @returns A new vector. **Allocates**; use {@link Vec3.addToRef} in per-frame code.
|
|
19844
|
-
*/
|
|
19845
|
-
static add(a, b) {
|
|
19846
|
-
return Vec3.addToRef(a, b, new Vec3());
|
|
19847
|
-
}
|
|
19848
|
-
/**
|
|
19849
|
-
* Subtracts one vector from another.
|
|
19850
|
-
*
|
|
19851
|
-
* @param a - The vector to subtract from.
|
|
19852
|
-
* @param b - The vector to subtract.
|
|
19853
|
-
* @returns A new vector holding `a - b`. **Allocates.**
|
|
19854
|
-
*/
|
|
19855
|
-
static subtract(a, b) {
|
|
19856
|
-
return Vec3.subtractToRef(a, b, new Vec3());
|
|
19857
|
-
}
|
|
19858
|
-
/**
|
|
19859
|
-
* Multiplies a vector by a number.
|
|
19860
|
-
*
|
|
19861
|
-
* @param v - The vector to scale.
|
|
19862
|
-
* @param scale - The factor.
|
|
19863
|
-
* @returns A new vector. **Allocates.**
|
|
19864
|
-
*/
|
|
19865
|
-
static scale(v, scale) {
|
|
19866
|
-
return Vec3.scaleToRef(v, scale, new Vec3());
|
|
19867
|
-
}
|
|
19868
|
-
/**
|
|
19869
|
-
* The cross product of two vectors.
|
|
19870
|
-
*
|
|
19871
|
-
* @param a - The left-hand vector.
|
|
19872
|
-
* @param b - The right-hand vector.
|
|
19873
|
-
* @returns A new vector holding `a x b`. **Allocates.**
|
|
19874
|
-
*/
|
|
19875
|
-
static cross(a, b) {
|
|
19876
|
-
return Vec3.crossToRef(a, b, new Vec3());
|
|
19877
|
-
}
|
|
19878
|
-
/**
|
|
19879
|
-
* A unit-length copy of a vector.
|
|
19880
|
-
*
|
|
19881
|
-
* @param v - The vector to normalize.
|
|
19882
|
-
* @returns A new vector. **Allocates.**
|
|
19883
|
-
*/
|
|
19884
|
-
static normalize(v) {
|
|
19885
|
-
return Vec3.normalizeToRef(v, new Vec3());
|
|
19886
|
-
}
|
|
19887
|
-
/**
|
|
19888
|
-
* Linearly interpolates between two vectors.
|
|
19889
|
-
*
|
|
19890
|
-
* @param a - The vector returned at `t === 0`.
|
|
19891
|
-
* @param b - The vector returned at `t === 1`.
|
|
19892
|
-
* @param t - The interpolant; not clamped.
|
|
19893
|
-
* @returns A new vector. **Allocates.**
|
|
19894
|
-
*/
|
|
19895
|
-
static lerp(a, b, t) {
|
|
19896
|
-
return Vec3.lerpToRef(a, b, t, new Vec3());
|
|
19897
|
-
}
|
|
19898
|
-
/**
|
|
19899
|
-
* Writes `a + b` into `out`.
|
|
19900
|
-
*
|
|
19901
|
-
* @param a - The first vector.
|
|
19902
|
-
* @param b - The second vector.
|
|
19903
|
-
* @param out - The vector to write; may alias `a` or `b`.
|
|
19904
|
-
* @returns `out`.
|
|
19905
|
-
*/
|
|
19906
|
-
static addToRef(a, b, out) {
|
|
19907
|
-
out.set(a.x + b.x, a.y + b.y, a.z + b.z);
|
|
19908
|
-
return out;
|
|
19909
|
-
}
|
|
19910
|
-
/**
|
|
19911
|
-
* Writes `a - b` into `out`.
|
|
19912
|
-
*
|
|
19913
|
-
* @param a - The vector to subtract from.
|
|
19914
|
-
* @param b - The vector to subtract.
|
|
19915
|
-
* @param out - The vector to write; may alias `a` or `b`.
|
|
19916
|
-
* @returns `out`.
|
|
19917
|
-
*/
|
|
19918
|
-
static subtractToRef(a, b, out) {
|
|
19919
|
-
out.set(a.x - b.x, a.y - b.y, a.z - b.z);
|
|
19920
|
-
return out;
|
|
19921
|
-
}
|
|
19922
|
-
/**
|
|
19923
|
-
* Writes the component-wise product `a * b` into `out`.
|
|
19924
|
-
*
|
|
19925
|
-
* @param a - The first vector.
|
|
19926
|
-
* @param b - The second vector.
|
|
19927
|
-
* @param out - The vector to write; may alias `a` or `b`.
|
|
19928
|
-
* @returns `out`.
|
|
19929
|
-
*/
|
|
19930
|
-
static multiplyToRef(a, b, out) {
|
|
19931
|
-
out.set(a.x * b.x, a.y * b.y, a.z * b.z);
|
|
19932
|
-
return out;
|
|
19933
|
-
}
|
|
19934
|
-
/**
|
|
19935
|
-
* Writes `v * scale` into `out`.
|
|
19936
|
-
*
|
|
19937
|
-
* @param v - The vector to scale.
|
|
19938
|
-
* @param scale - The factor.
|
|
19939
|
-
* @param out - The vector to write; may alias `v`.
|
|
19940
|
-
* @returns `out`.
|
|
19941
|
-
*/
|
|
19942
|
-
static scaleToRef(v, scale, out) {
|
|
19943
|
-
out.set(v.x * scale, v.y * scale, v.z * scale);
|
|
19944
|
-
return out;
|
|
19945
|
-
}
|
|
19946
|
-
/**
|
|
19947
|
-
* Writes `-v` into `out`.
|
|
19948
|
-
*
|
|
19949
|
-
* @param v - The vector to flip.
|
|
19950
|
-
* @param out - The vector to write; may alias `v`.
|
|
19951
|
-
* @returns `out`.
|
|
19952
|
-
*/
|
|
19953
|
-
static negateToRef(v, out) {
|
|
19954
|
-
out.set(-v.x, -v.y, -v.z);
|
|
19955
|
-
return out;
|
|
19956
|
-
}
|
|
19957
|
-
/**
|
|
19958
|
-
* Writes a unit-length copy of `v` into `out`. A zero-length input is written as zero rather than
|
|
19959
|
-
* `NaN`.
|
|
19960
|
-
*
|
|
19961
|
-
* @param v - The vector to normalize.
|
|
19962
|
-
* @param out - The vector to write; may alias `v`.
|
|
19963
|
-
* @returns `out`.
|
|
19964
|
-
*/
|
|
19965
|
-
static normalizeToRef(v, out) {
|
|
19966
|
-
const length = Math.hypot(v.x, v.y, v.z);
|
|
19967
|
-
if (length === 0) {
|
|
19968
|
-
out.set(0, 0, 0);
|
|
19969
|
-
return out;
|
|
19970
|
-
}
|
|
19971
|
-
const inv = 1 / length;
|
|
19972
|
-
out.set(v.x * inv, v.y * inv, v.z * inv);
|
|
19973
|
-
return out;
|
|
19974
|
-
}
|
|
19975
|
-
/**
|
|
19976
|
-
* Writes `a x b` into `out`.
|
|
19977
|
-
*
|
|
19978
|
-
* @param a - The left-hand vector.
|
|
19979
|
-
* @param b - The right-hand vector.
|
|
19980
|
-
* @param out - The vector to write; may alias `a` or `b`.
|
|
19981
|
-
* @returns `out`.
|
|
19982
|
-
*/
|
|
19983
|
-
static crossToRef(a, b, out) {
|
|
19984
|
-
const ax = a.x;
|
|
19985
|
-
const ay = a.y;
|
|
19986
|
-
const az = a.z;
|
|
19987
|
-
const bx = b.x;
|
|
19988
|
-
const by = b.y;
|
|
19989
|
-
const bz = b.z;
|
|
19990
|
-
out.set(ay * bz - az * by, az * bx - ax * bz, ax * by - ay * bx);
|
|
19991
|
-
return out;
|
|
19992
|
-
}
|
|
19993
|
-
/**
|
|
19994
|
-
* Writes the interpolation of `a` and `b` into `out`.
|
|
19995
|
-
*
|
|
19996
|
-
* @param a - The vector written at `t === 0`.
|
|
19997
|
-
* @param b - The vector written at `t === 1`.
|
|
19998
|
-
* @param t - The interpolant; not clamped.
|
|
19999
|
-
* @param out - The vector to write; may alias `a` or `b`.
|
|
20000
|
-
* @returns `out`.
|
|
20001
|
-
*/
|
|
20002
|
-
static lerpToRef(a, b, t, out) {
|
|
20003
|
-
out.set(lerp(a.x, b.x, t), lerp(a.y, b.y, t), lerp(a.z, b.z, t));
|
|
20004
|
-
return out;
|
|
20005
|
-
}
|
|
20006
|
-
/**
|
|
20007
|
-
* Writes the component-wise minimum of two vectors into `out`.
|
|
20008
|
-
*
|
|
20009
|
-
* @param a - The first vector.
|
|
20010
|
-
* @param b - The second vector.
|
|
20011
|
-
* @param out - The vector to write; may alias `a` or `b`.
|
|
20012
|
-
* @returns `out`.
|
|
20013
|
-
*/
|
|
20014
|
-
static minToRef(a, b, out) {
|
|
20015
|
-
out.set(Math.min(a.x, b.x), Math.min(a.y, b.y), Math.min(a.z, b.z));
|
|
20016
|
-
return out;
|
|
20017
|
-
}
|
|
20018
|
-
/**
|
|
20019
|
-
* Writes the component-wise maximum of two vectors into `out`.
|
|
20020
|
-
*
|
|
20021
|
-
* @param a - The first vector.
|
|
20022
|
-
* @param b - The second vector.
|
|
20023
|
-
* @param out - The vector to write; may alias `a` or `b`.
|
|
20024
|
-
* @returns `out`.
|
|
20025
|
-
*/
|
|
20026
|
-
static maxToRef(a, b, out) {
|
|
20027
|
-
out.set(Math.max(a.x, b.x), Math.max(a.y, b.y), Math.max(a.z, b.z));
|
|
20028
|
-
return out;
|
|
20029
|
-
}
|
|
20030
|
-
/**
|
|
20031
|
-
* Transforms a **position** by a matrix into `out`: the matrix's translation is applied and the
|
|
20032
|
-
* result is divided by w, so a projection matrix gives clip-space coordinates.
|
|
20033
|
-
*
|
|
20034
|
-
* @param v - The position to transform, in metres.
|
|
20035
|
-
* @param m - The transformation, column-major.
|
|
20036
|
-
* @param out - The vector to write; may alias `v`.
|
|
20037
|
-
* @returns `out`.
|
|
20038
|
-
*
|
|
20039
|
-
* @example
|
|
20040
|
-
* ```ts
|
|
20041
|
-
* Vec3.transformCoordinatesToRef(localPoint, node.worldMatrix, worldPoint);
|
|
20042
|
-
* ```
|
|
20043
|
-
*/
|
|
20044
|
-
static transformCoordinatesToRef(v, m, out) {
|
|
20045
|
-
return Mat4.transformPointToRef(m, v, out);
|
|
20046
|
-
}
|
|
20047
|
-
/**
|
|
20048
|
-
* Transforms a **direction** by a matrix into `out`, ignoring the matrix's translation.
|
|
20049
|
-
*
|
|
20050
|
-
* @param v - The direction to transform.
|
|
20051
|
-
* @param m - The transformation, column-major.
|
|
20052
|
-
* @param out - The vector to write; may alias `v`.
|
|
20053
|
-
* @returns `out`.
|
|
20054
|
-
*/
|
|
20055
|
-
static transformNormalToRef(v, m, out) {
|
|
20056
|
-
return Mat4.transformDirectionToRef(m, v, out);
|
|
20057
|
-
}
|
|
20058
|
-
/**
|
|
20059
|
-
* The dot product of two vectors.
|
|
20060
|
-
*
|
|
20061
|
-
* @param a - The first vector.
|
|
20062
|
-
* @param b - The second vector.
|
|
20063
|
-
* @returns The dot product.
|
|
20064
|
-
*/
|
|
20065
|
-
static dot(a, b) {
|
|
20066
|
-
return a.x * b.x + a.y * b.y + a.z * b.z;
|
|
20067
|
-
}
|
|
20068
|
-
/**
|
|
20069
|
-
* The length of a vector, in metres.
|
|
20070
|
-
*
|
|
20071
|
-
* @param v - The vector to measure.
|
|
20072
|
-
* @returns The length.
|
|
20073
|
-
*/
|
|
20074
|
-
static length(v) {
|
|
20075
|
-
return Math.hypot(v.x, v.y, v.z);
|
|
20076
|
-
}
|
|
20077
|
-
/**
|
|
20078
|
-
* The squared length of a vector.
|
|
20079
|
-
*
|
|
20080
|
-
* @param v - The vector to measure.
|
|
20081
|
-
* @returns The squared length.
|
|
20082
|
-
*/
|
|
20083
|
-
static lengthSquared(v) {
|
|
20084
|
-
return v.x * v.x + v.y * v.y + v.z * v.z;
|
|
20085
|
-
}
|
|
20086
|
-
/**
|
|
20087
|
-
* The distance between two positions, in metres.
|
|
20088
|
-
*
|
|
20089
|
-
* @param a - The first position.
|
|
20090
|
-
* @param b - The second position.
|
|
20091
|
-
* @returns The distance.
|
|
20092
|
-
*/
|
|
20093
|
-
static distance(a, b) {
|
|
20094
|
-
return Math.hypot(a.x - b.x, a.y - b.y, a.z - b.z);
|
|
20095
|
-
}
|
|
20096
|
-
/**
|
|
20097
|
-
* The squared distance between two positions. Compare squared distances to avoid a square root.
|
|
20098
|
-
*
|
|
20099
|
-
* @param a - The first position.
|
|
20100
|
-
* @param b - The second position.
|
|
20101
|
-
* @returns The squared distance.
|
|
20102
|
-
*/
|
|
20103
|
-
static distanceSquared(a, b) {
|
|
20104
|
-
const dx = a.x - b.x;
|
|
20105
|
-
const dy = a.y - b.y;
|
|
20106
|
-
const dz = a.z - b.z;
|
|
20107
|
-
return dx * dx + dy * dy + dz * dz;
|
|
20108
|
-
}
|
|
20109
|
-
/**
|
|
20110
|
-
* Compares two vectors component by component, with a tolerance.
|
|
20111
|
-
*
|
|
20112
|
-
* @param a - The first vector.
|
|
20113
|
-
* @param b - The second vector.
|
|
20114
|
-
* @param epsilon - The largest per-component difference still considered equal.
|
|
20115
|
-
* @returns `true` when every component matches within `epsilon`.
|
|
20116
|
-
*/
|
|
20117
|
-
static equalsWithEpsilon(a, b, epsilon = EPSILON) {
|
|
20118
|
-
return Math.abs(a.x - b.x) <= epsilon && Math.abs(a.y - b.y) <= epsilon && Math.abs(a.z - b.z) <= epsilon;
|
|
20119
|
-
}
|
|
20120
|
-
};
|
|
20121
|
-
/**
|
|
20122
|
-
* The frozen zero vector, `(0, 0, 0)`. Read-only: pass it anywhere a {@link Vec3Like} is wanted, and
|
|
20123
|
-
* call {@link Vec3.zero} when you need a vector you can write to.
|
|
20124
|
-
*
|
|
20125
|
-
* @public
|
|
20126
|
-
*/
|
|
20127
|
-
const VEC3_ZERO = Object.freeze({
|
|
20128
|
-
x: 0,
|
|
20129
|
-
y: 0,
|
|
20130
|
-
z: 0
|
|
20131
|
-
});
|
|
20132
|
-
/**
|
|
20133
|
-
* The frozen vector whose components are all one, `(1, 1, 1)` — the identity scale.
|
|
20134
|
-
*
|
|
20135
|
-
* @public
|
|
20136
|
-
*/
|
|
20137
|
-
const VEC3_ONE = Object.freeze({
|
|
20138
|
-
x: 1,
|
|
20139
|
-
y: 1,
|
|
20140
|
-
z: 1
|
|
20141
|
-
});
|
|
20142
|
-
/**
|
|
20143
|
-
* The frozen world up direction, `(0, 1, 0)`.
|
|
20144
|
-
*
|
|
20145
|
-
* @public
|
|
20146
|
-
*/
|
|
20147
|
-
const VEC3_UP = Object.freeze({
|
|
20148
|
-
x: 0,
|
|
20149
|
-
y: 1,
|
|
20150
|
-
z: 0
|
|
20151
|
-
});
|
|
20152
|
-
/**
|
|
20153
|
-
* The frozen world down direction, `(0, -1, 0)`.
|
|
20154
|
-
*
|
|
20155
|
-
* @public
|
|
20156
|
-
*/
|
|
20157
|
-
const VEC3_DOWN = Object.freeze({
|
|
20158
|
-
x: 0,
|
|
20159
|
-
y: -1,
|
|
20160
|
-
z: 0
|
|
20161
|
-
});
|
|
20162
|
-
/**
|
|
20163
|
-
* The frozen world right direction, `(1, 0, 0)`.
|
|
20164
|
-
*
|
|
20165
|
-
* @public
|
|
20166
|
-
*/
|
|
20167
|
-
const VEC3_RIGHT = Object.freeze({
|
|
20168
|
-
x: 1,
|
|
20169
|
-
y: 0,
|
|
20170
|
-
z: 0
|
|
20171
|
-
});
|
|
20172
|
-
/**
|
|
20173
|
-
* The frozen world left direction, `(-1, 0, 0)`.
|
|
20174
|
-
*
|
|
20175
|
-
* @public
|
|
20176
|
-
*/
|
|
20177
|
-
const VEC3_LEFT = Object.freeze({
|
|
20178
|
-
x: -1,
|
|
20179
|
-
y: 0,
|
|
20180
|
-
z: 0
|
|
20181
|
-
});
|
|
20182
|
-
/**
|
|
20183
|
-
* The frozen world forward direction, `(0, 0, 1)`. ignifx is left-handed, so forward is +Z
|
|
20184
|
-
* (ADR-0011).
|
|
20185
|
-
*
|
|
20186
|
-
* @public
|
|
20187
|
-
*/
|
|
20188
|
-
const VEC3_FORWARD = Object.freeze({
|
|
20189
|
-
x: 0,
|
|
20190
|
-
y: 0,
|
|
20191
|
-
z: 1
|
|
20192
|
-
});
|
|
20193
|
-
/**
|
|
20194
|
-
* The frozen world backward direction, `(0, 0, -1)`.
|
|
20195
|
-
*
|
|
20196
|
-
* @public
|
|
20197
|
-
*/
|
|
20198
|
-
const VEC3_BACKWARD = Object.freeze({
|
|
20199
|
-
x: 0,
|
|
20200
|
-
y: 0,
|
|
20201
|
-
z: -1
|
|
20202
|
-
});
|
|
20203
|
-
//#endregion
|
|
20204
18750
|
//#region src/math/quat.ts
|
|
20205
18751
|
/**
|
|
20206
18752
|
* A rotation, stored as a unit quaternion. Quaternions are how ignifx stores every rotation:
|
|
@@ -34341,7 +32887,7 @@ function describeEnvironmentFileFormat() {
|
|
|
34341
32887
|
blur: {
|
|
34342
32888
|
kind: "f32",
|
|
34343
32889
|
default: 0,
|
|
34344
|
-
description: "How blurred the
|
|
32890
|
+
description: "How blurred the visible skybox is, 0 to 1; reflections are not blurred."
|
|
34345
32891
|
},
|
|
34346
32892
|
rotation: {
|
|
34347
32893
|
kind: "f32",
|