Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tensor: Standardize Vector2, Vector3, Vector4, Color3, Color4, Quaternion, and Matrix #14235

Merged
merged 74 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from 62 commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
35af7f2
Added new types
james-pre Aug 30, 2023
0f5e219
Added Member, Flatten, and tensor
james-pre Aug 30, 2023
09ca803
Updated classes in vector.ts to use Constructor
james-pre Aug 30, 2023
bd84e4a
Removed TensorValue and fixed comments
james-pre Aug 30, 2023
dfeb3b1
Fixed wikipedia link
james-pre Aug 30, 2023
78fc212
Added Tensor to vector and color classes
james-pre Aug 31, 2023
1438578
Added IsTuple types
james-pre Aug 31, 2023
ab26305
Added public to Tensor and Vector members
james-pre Sep 1, 2023
f6fe9da
Fixed types being or not being DeepImmutable
james-pre Aug 24, 2023
1e989fd
Formatting
james-pre Sep 5, 2023
9f9e655
Added Tuple
james-pre Sep 5, 2023
9fda9b5
Updated arrayTools to use new Tuple type
james-pre Sep 11, 2023
1083709
Updated to use object.defineProperty for dimension
james-pre Sep 11, 2023
ecf9981
Fixed dimension values
james-pre Sep 12, 2023
df6d705
Added Dimension
james-pre Sep 12, 2023
94bdb99
Fixed Dimension import
james-pre Sep 12, 2023
57a238e
Fixed Tensor not working with non `number[]` types
james-pre Nov 10, 2023
1474e02
Fixed equalsToFloats not using Flatten
james-pre Nov 10, 2023
21b6534
Made Matrix Tensor-compatible
james-pre Nov 10, 2023
de01663
Updated Quaternion to be Tensor compatible
james-pre Nov 10, 2023
b4d8d06
Renamed I<Math>Like to <Math>Like
james-pre Nov 10, 2023
25769e7
Moved <Math>Like to correct files
james-pre Nov 10, 2023
539f1e6
Merge branch 'master' into tensor
james-pre Nov 10, 2023
25879aa
Fixed duplicate function implementation
james-pre Nov 10, 2023
706709f
Changed dimension to be Readonly
james-pre Nov 10, 2023
5501d33
Fixed mispelling
james-pre Nov 11, 2023
7728fe2
Updated Vector3.asArray and Matrix.asArray
james-pre Nov 11, 2023
e6d5a73
Updated test Playground
james-pre Nov 11, 2023
8094c96
Changed default Tensor value type to unknown[]
james-pre Nov 11, 2023
5e2253b
Added TensorValue
james-pre Nov 11, 2023
4c41e80
Merge branch 'master' into tensor
james-pre Nov 14, 2023
451a316
Fixed stuff from merge
james-pre Nov 14, 2023
e45c03f
Fixed JSDoc comment parameter order
james-pre Nov 14, 2023
9150d62
Added Tensor.rank
james-pre Nov 15, 2023
7ce70a9
Fixed typo
james-pre Nov 15, 2023
25d7989
Formatting
james-pre Nov 15, 2023
a8be563
Merge branch 'master' into tensor
james-pre Jan 6, 2024
ed6f9f0
Formatting
james-pre Jan 8, 2024
ec2ad1a
Merge remote-tracking branch 'upstream/master' into tensor
james-pre Jan 10, 2024
a59d834
Made Matrix.asArray zero-copy
james-pre Jan 10, 2024
3ccba05
Moved from defineProperty to defineProperties
james-pre Jan 11, 2024
2d06268
Reverted *Like changes
james-pre Feb 5, 2024
10f388f
Merge branch 'master' into tensor
james-pre Feb 5, 2024
a853276
Fixed JSDoc comments
james-pre Feb 5, 2024
2ae66a2
Formatting
james-pre Feb 5, 2024
584590e
Formatting (clean install)
james-pre Feb 5, 2024
6e95392
Fixed eslint warnings
james-pre Feb 5, 2024
934b667
Reverted IViewportLike
james-pre Feb 5, 2024
4a0c5cf
Reverted flloat -> number change in math.like
james-pre Feb 5, 2024
3edd805
Fixed imports
james-pre Feb 5, 2024
d30689d
Fixed more imports
james-pre Feb 6, 2024
75fef20
Reverted more organization changes
james-pre Feb 6, 2024
a148331
Updated directionalLightFrustumViewer._createGeometry vectors
james-pre Feb 7, 2024
d009e1a
Added Matrix.toArray backwards compatibility
james-pre Feb 12, 2024
509d5d1
Fixed RecursiveArray spelling
james-pre Feb 13, 2024
193f542
Fixed Tensor description
james-pre Feb 13, 2024
897a071
Fixed Vector description
james-pre Feb 13, 2024
4e38dc4
Comment overhaul
james-pre Feb 13, 2024
1dac6f5
Changed m.length to 16
james-pre Feb 13, 2024
f3fe026
Removed some method implementations from Color3 and Color4
james-pre Feb 13, 2024
9f20dfe
Added internal to doc comment for color methods
james-pre Feb 14, 2024
36d71d1
Removed methods from Quaternion
james-pre Feb 14, 2024
3431e55
Fixed Vector not implementing Vector
james-pre Feb 14, 2024
f1b41b5
made all Tensor instance methods abstract
james-pre Feb 14, 2024
cd2d360
Added abstract to Vector
james-pre Feb 14, 2024
038a9c9
Removed unused types
james-pre Feb 15, 2024
6d4c2ec
Removed Tensor.toString
james-pre Feb 15, 2024
24cd34a
Seperated instance and static of Tensor and Vector into interfaces
james-pre Feb 20, 2024
266017c
Added TensorStatic.prototype
james-pre Feb 20, 2024
0691ccf
Removed type parameters in Tensor and Vector methods
james-pre Feb 20, 2024
60f0496
Added Vector4 static side
james-pre Feb 20, 2024
2bd3676
Added static side to Quaternion
james-pre Feb 21, 2024
55efc41
Merge branch 'master' into tensor
james-pre Mar 2, 2024
c3764d8
Formatting
james-pre Mar 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/dev/core/src/Bones/skeleton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -751,8 +751,8 @@ export class Skeleton implements IAnimatable {
index: bone.getIndex(),
name: bone.name,
id: bone.id,
matrix: bone.getBindMatrix().toArray(),
rest: bone.getRestMatrix().toArray(),
matrix: bone.getBindMatrix().asArray(),
rest: bone.getRestMatrix().asArray(),
linkedTransformNodeId: bone.getTransformNode()?.id,
};

Expand Down
6 changes: 3 additions & 3 deletions packages/dev/core/src/Cameras/camera.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { serialize, SerializationHelper, serializeAsVector3 } from "../Misc/deco
import { SmartArray } from "../Misc/smartArray";
import { Tools } from "../Misc/tools";
import { Observable } from "../Misc/observable";
import type { Nullable } from "../types";
import type { DeepImmutable, Nullable } from "../types";
import type { CameraInputsManager } from "./cameraInputsManager";
import type { Scene } from "../scene";
import { Matrix, Vector3, Quaternion } from "../Maths/math.vector";
Expand Down Expand Up @@ -1417,7 +1417,7 @@ export class Camera extends Node {
* @param localAxis Defines the reference axis to provide a relative direction.
* @returns the direction
*/
public getDirection(localAxis: Vector3): Vector3 {
public getDirection(localAxis: DeepImmutable<Vector3>): Vector3 {
const result = Vector3.Zero();

this.getDirectionToRef(localAxis, result);
Expand All @@ -1439,7 +1439,7 @@ export class Camera extends Node {
* @param localAxis Defines the reference axis to provide a relative direction.
* @param result Defines the vector to store the result in
*/
public getDirectionToRef(localAxis: Vector3, result: Vector3): void {
public getDirectionToRef(localAxis: DeepImmutable<Vector3>, result: Vector3): void {
Vector3.TransformNormalToRef(localAxis, this.getWorldMatrix(), result);
}

Expand Down
12 changes: 6 additions & 6 deletions packages/dev/core/src/Debug/directionalLightFrustumViewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,32 +247,32 @@ export class DirectionalLightFrustumViewer {
this._rootNode = new TransformNode("directionalLightHelperRoot_" + this._light.name, this._scene);
this._rootNode.parent = this._light.parent;

this._nearLinesPoints = [Vector3.ZeroReadOnly, Vector3.ZeroReadOnly, Vector3.ZeroReadOnly, Vector3.ZeroReadOnly, Vector3.ZeroReadOnly];
this._nearLinesPoints = [TmpVectors.Vector3[0], TmpVectors.Vector3[1], TmpVectors.Vector3[2], TmpVectors.Vector3[3], TmpVectors.Vector3[4]];
const nearLines = CreateLines("nearlines", { updatable: true, points: this._nearLinesPoints }, this._scene);
nearLines.parent = this._rootNode;
nearLines.alwaysSelectAsActiveMesh = true;

this._farLinesPoints = [Vector3.ZeroReadOnly, Vector3.ZeroReadOnly, Vector3.ZeroReadOnly, Vector3.ZeroReadOnly, Vector3.ZeroReadOnly];
this._farLinesPoints = [TmpVectors.Vector3[5], TmpVectors.Vector3[6], TmpVectors.Vector3[7], TmpVectors.Vector3[8], TmpVectors.Vector3[9]];
const farLines = CreateLines("farlines", { updatable: true, points: this._farLinesPoints }, this._scene);
farLines.parent = this._rootNode;
farLines.alwaysSelectAsActiveMesh = true;

this._trLinesPoints = [Vector3.ZeroReadOnly, Vector3.ZeroReadOnly];
this._trLinesPoints = [TmpVectors.Vector3[10], TmpVectors.Vector3[11]];
const trLines = CreateLines("trlines", { updatable: true, points: this._trLinesPoints }, this._scene);
trLines.parent = this._rootNode;
trLines.alwaysSelectAsActiveMesh = true;

this._brLinesPoints = [Vector3.ZeroReadOnly, Vector3.ZeroReadOnly];
this._brLinesPoints = [TmpVectors.Vector3[12], TmpVectors.Vector3[0]];
const brLines = CreateLines("brlines", { updatable: true, points: this._brLinesPoints }, this._scene);
brLines.parent = this._rootNode;
brLines.alwaysSelectAsActiveMesh = true;

this._tlLinesPoints = [Vector3.ZeroReadOnly, Vector3.ZeroReadOnly];
this._tlLinesPoints = [TmpVectors.Vector3[1], TmpVectors.Vector3[2]];
const tlLines = CreateLines("tllines", { updatable: true, points: this._tlLinesPoints }, this._scene);
tlLines.parent = this._rootNode;
tlLines.alwaysSelectAsActiveMesh = true;

this._blLinesPoints = [Vector3.ZeroReadOnly, Vector3.ZeroReadOnly];
this._blLinesPoints = [TmpVectors.Vector3[3], TmpVectors.Vector3[4]];
const blLines = CreateLines("bllines", { updatable: true, points: this._blLinesPoints }, this._scene);
blLines.parent = this._rootNode;
blLines.alwaysSelectAsActiveMesh = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ export class NativePipelineContext implements IPipelineContext {
*/
public setMatrix(uniformName: string, matrix: IMatrixLike): void {
if (this._cacheMatrix(uniformName, matrix)) {
if (!this._engine.setMatrices(this._uniforms[uniformName]!, matrix.toArray() as Float32Array)) {
if (!this._engine.setMatrices(this._uniforms[uniformName]!, matrix.asArray() as Float32Array)) {
this._valueCache[uniformName] = null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ export class WebGLPipelineContext implements IPipelineContext {
*/
public setMatrix(uniformName: string, matrix: IMatrixLike): void {
if (this._cacheMatrix(uniformName, matrix)) {
if (!this.engine.setMatrices(this._uniforms[uniformName], matrix.toArray() as Float32Array)) {
if (!this.engine.setMatrices(this._uniforms[uniformName], matrix.asArray() as Float32Array)) {
this._valueCache[uniformName] = null;
}
}
Expand Down
5 changes: 2 additions & 3 deletions packages/dev/core/src/Materials/uniformBuffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import type { DataBuffer } from "../Buffers/dataBuffer";
import type { ThinEngine } from "../Engines/thinEngine";
import type { InternalTexture } from "./Textures/internalTexture";
import { Tools } from "../Misc/tools";

import "../Engines/Extensions/engine.uniformBuffer";

/**
Expand Down Expand Up @@ -466,7 +465,7 @@ export class UniformBuffer {
* @param mat A 4x4 matrix.
*/
public addMatrix(name: string, mat: IMatrixLike) {
this.addUniform(name, Array.prototype.slice.call(mat.toArray()));
this.addUniform(name, Array.prototype.slice.call(mat.asArray()));
}

/**
Expand Down Expand Up @@ -941,7 +940,7 @@ export class UniformBuffer {

private _updateMatrixForUniform(name: string, mat: IMatrixLike) {
if (this._cacheMatrix(name, mat)) {
this.updateUniform(name, <any>mat.toArray(), 16);
this.updateUniform(name, <any>mat.asArray(), 16);
}
}

Expand Down
Loading
Loading