Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
79 changes: 74 additions & 5 deletions tsl-testing/TSLCore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,29 @@ test('color', async () => {
node = color(new THREE.Color());
assertConstNode(node, 'color', THREE.Color);

node = color(new THREE.Vector3(1, 0, 0.5));
assertConstNode(node, 'color', THREE.Vector3);

node = color(0, 0.5, 1);
assertConstNode(node, 'color', THREE.Color);

let convertNode: THREE.VarNode<'color', THREE.ConvertNode<'color'>> = color(float(0.5));
assertConvertNode(convertNode, 'color');

convertNode = color(vec3(1, 0, 0.5));
assertConvertNode(convertNode, 'color');

let joinNode: THREE.VarNode<'vec3', THREE.JoinNode<'vec3'>> = color(float(1), 0, 0.5);
assertJoinNode(joinNode, 'vec3');

joinNode = color(new THREE.Vector2(), float(1));
assertJoinNode(joinNode, 'vec3');

joinNode = color(new THREE.Vector2(), 0.5);
assertJoinNode(joinNode, 'vec3');

joinNode = color(1, vec2(0, 0.5));
assertJoinNode(joinNode, 'vec3');
});

test('float', async () => {
Expand Down Expand Up @@ -848,26 +869,74 @@ test('bvec4', async () => {
test('mat2', async () => {
await renderer.init();

let node: THREE.VarNode<'mat2', THREE.ConstNode<'mat2', THREE.Matrix2>> = mat2(new THREE.Matrix2());
let node: THREE.VarNode<'mat2', THREE.ConstNode<'mat2', THREE.Matrix2>> = mat2();
assertConstNode(node, 'mat2', THREE.Matrix2);

node = mat2(1, 0, 1, 0);
assertConstNode(node, 'mat2', THREE.Matrix2);

node = mat2(new THREE.Matrix2());
assertConstNode(node, 'mat2', THREE.Matrix2);

let convertNode: THREE.VarNode<'mat2', THREE.ConvertNode<'mat2'>> = mat2(mat2());
assertConvertNode(convertNode, 'mat2');

let joinNode: THREE.VarNode<'mat2', THREE.JoinNode<'mat2'>> = mat2(vec2(1, 0), new THREE.Vector2());
assertJoinNode(joinNode, 'mat2');

joinNode = mat2(1, 0, 1, float(0));
assertJoinNode(joinNode, 'mat2');
});

test('mat3', async () => {
await renderer.init();

let node: THREE.VarNode<'mat3', THREE.ConstNode<'mat3', THREE.Matrix3>> = mat3(new THREE.Matrix3());
let node: THREE.VarNode<'mat3', THREE.ConstNode<'mat3', THREE.Matrix3>> = mat3();
assertConstNode(node, 'mat3', THREE.Matrix3);

node = mat3();
node = mat3(1, 0, 0, 0, 1, 0, 0, 0, 1);
assertConstNode(node, 'mat3', THREE.Matrix3);

node = mat3(new THREE.Matrix3());
assertConstNode(node, 'mat3', THREE.Matrix3);

let convertNode: THREE.VarNode<'mat3', THREE.ConvertNode<'mat3'>> = mat3(mat3());
assertConvertNode(convertNode, 'mat3');

let joinNode: THREE.VarNode<'mat3', THREE.JoinNode<'mat3'>> = mat3(
vec3(1, 0, 0),
new THREE.Vector3(),
new THREE.Vector3(),
);
assertJoinNode(joinNode, 'mat3');

joinNode = mat3(1, 0, 0, 0, 1, float(0), 0, 0, 1);
assertJoinNode(joinNode, 'mat3');
});

test('mat4', async () => {
await renderer.init();

let node: THREE.VarNode<'mat4', THREE.ConstNode<'mat4', THREE.Matrix4>> = mat4(new THREE.Matrix4());
let node: THREE.VarNode<'mat4', THREE.ConstNode<'mat4', THREE.Matrix4>> = mat4();
assertConstNode(node, 'mat4', THREE.Matrix4);

node = mat4(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1);
assertConstNode(node, 'mat4', THREE.Matrix4);

node = mat4();
node = mat4(new THREE.Matrix4());
assertConstNode(node, 'mat4', THREE.Matrix4);

let convertNode: THREE.VarNode<'mat4', THREE.ConvertNode<'mat4'>> = mat4(mat4());
assertConvertNode(convertNode, 'mat4');

let joinNode: THREE.VarNode<'mat4', THREE.JoinNode<'mat4'>> = mat4(
vec4(1, 0, 0, 0),
new THREE.Vector4(),
new THREE.Vector4(),
new THREE.Vector4(),
);
assertJoinNode(joinNode, 'mat4');

joinNode = mat4(1, 0, 0, 0, 0, 1, float(0), 0, 0, 0, 1, 0, 0, 0, 0, 1);
assertJoinNode(joinNode, 'mat4');
});
173 changes: 124 additions & 49 deletions types/three/src/nodes/tsl/TSLCore.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1824,16 +1824,20 @@ interface ColorFunction {

// The third branch will be triggered if there is a single parameter
// ConstNode
(color: Color): VarNode<"color", ConstNode<"color", Color>>;
(color: Color | Vector3): VarNode<"color", ConstNode<"color", Color>>;
// ConvertNode
// TODO
(node: Node): Node<"color">;
(node: Node<"float">): VarNode<"color", ConvertNode<"color">>;
(node: Node<"vec3"> | Vector3): VarNode<"color", ConvertNode<"color">>;

// The fall-through branch will be triggered if there is more than one parameter, and one of the parameters is an
// object

// JoinNode
// TODO
(
x: Node<"float"> | number,
y: Node<"float"> | number,
z: Node<"float"> | number,
): VarNode<"vec3", JoinNode<"vec3">>;
(xy: Node<"vec2"> | Vector2, z: Node<"float"> | number): VarNode<"vec3", JoinNode<"vec3">>;
(x: Node<"float"> | number, yz: Node<"vec2"> | Vector2): VarNode<"vec3", JoinNode<"vec3">>;
}

export const color: ColorFunction;
Expand Down Expand Up @@ -2218,70 +2222,141 @@ interface Bvec4Function {
export const bvec4: Bvec4Function;

interface Mat2Function {
// The first branch in `ConvertType` will forward the parameters to the `Matrix2` constructor if there are no
// parameters or all the parameters are non-objects
(): VarNode<"mat2", ConstNode<"mat2", Matrix2>>;
(n11: number, n12: number, n21: number, n22: number): VarNode<"mat2", ConstNode<"mat2", Matrix2>>;

// The second branch does not apply because `cacheMap` is `null`

// The third branch will be triggered if there is a single parameter
// ConstNode
(value: Matrix2): VarNode<"mat2", ConstNode<"mat2", Matrix2>>;
(node: Node): Node<"mat2">;
// ConvertNode
(node: Node<"mat2">): VarNode<"mat2", ConvertNode<"mat2">>;

// The fall-through branch will be triggered if there is more than one parameter, and one of the parameters is an
// object
(n1: Node<"vec2"> | Vector2, n2: Node<"vec2"> | Vector2): VarNode<"mat2", JoinNode<"mat2">>;
(
n11: Node<"float"> | number,
n12: Node<"float"> | number,
n21: Node<"float"> | number,
n22: Node<"float"> | number,
): VarNode<"mat2", JoinNode<"mat2">>;
}

export const mat2: Mat2Function;

interface Mat3Function {
// The first branch in `ConvertType` will forward the parameters to the `Matrix3` constructor if there are no
// parameters or all the parameters are non-objects
(): VarNode<"mat3", ConstNode<"mat3", Matrix3>>;
(
n11: number,
n12: number,
n13: number,
n21: number,
n22: number,
n23: number,
n31: number,
n32: number,
n33: number,
): VarNode<"mat3", ConstNode<"mat3", Matrix3>>;

// The second branch does not apply because `cacheMap` is `null`

// The third branch will be triggered if there is a single parameter
// ConstNode
(value: Matrix3): VarNode<"mat3", ConstNode<"mat3", Matrix3>>;
// ConvertNode
(node: Node<"mat3">): VarNode<"mat3", ConvertNode<"mat3">>;

// The fall-through branch will be triggered if there is more than one parameter, and one of the parameters is an
// object
(
n11: number | Node,
n12: number | Node,
n13: number | Node,
n21: number | Node,
n22: number | Node,
n23: number | Node,
n31: number | Node,
n32: number | Node,
n33: number | Node,
): Node<"mat3">;
(): VarNode<"mat3", ConstNode<"mat3", Matrix3>>;
n1: Node<"vec3"> | Vector3,
n2: Node<"vec3"> | Vector3,
n3: Node<"vec3"> | Vector3,
): VarNode<"mat3", JoinNode<"mat3">>;
(
p1: Node,
p2: Node,
p3: Node,
): Node<"mat3">;
(node: Node): Node<"mat3">;
n11: Node<"float"> | number,
n12: Node<"float"> | number,
n13: Node<"float"> | number,
n21: Node<"float"> | number,
n22: Node<"float"> | number,
n23: Node<"float"> | number,
n31: Node<"float"> | number,
n32: Node<"float"> | number,
n33: Node<"float"> | number,
): VarNode<"mat3", JoinNode<"mat3">>;
}

export const mat3: Mat3Function;

interface Mat4Function {
// The first branch in `ConvertType` will forward the parameters to the `Matrix4` constructor if there are no
// parameters or all the parameters are non-objects
(): VarNode<"mat4", ConstNode<"mat4", Matrix4>>;
(
n11: number,
n12: number,
n13: number,
n14: number,
n21: number,
n22: number,
n23: number,
n24: number,
n31: number,
n32: number,
n33: number,
n34: number,
n41: number,
n42: number,
n43: number,
n44: number,
): VarNode<"mat4", ConstNode<"mat4", Matrix4>>;

// The second branch does not apply because `cacheMap` is `null`

// The third branch will be triggered if there is a single parameter
// ConstNode
(value: Matrix4): VarNode<"mat4", ConstNode<"mat4", Matrix4>>;
// ConvertNode
(node: Node<"mat4">): VarNode<"mat4", ConvertNode<"mat4">>;

// The fall-through branch will be triggered if there is more than one parameter, and one of the parameters is an
// object
(
n11: number | Node,
n12: number | Node,
n13: number | Node,
n14: number | Node,
n21: number | Node,
n22: number | Node,
n23: number | Node,
n24: number | Node,
n31: number | Node,
n32: number | Node,
n33: number | Node,
n34: number | Node,
n41: number | Node,
n42: number | Node,
n43: number | Node,
n44: number | Node,
): Node<"mat4">;
(): VarNode<"mat4", ConstNode<"mat4", Matrix4>>;
n1: Node<"vec4"> | Vector4,
n2: Node<"vec4"> | Vector4,
n3: Node<"vec4"> | Vector4,
n4: Node<"vec4"> | Vector4,
): VarNode<"mat4", JoinNode<"mat4">>;
(
p1: Node,
p2: Node,
p3: Node,
p4: Node,
): Node<"mat4">;
(node: Node): Node<"mat4">;
n11: Node<"float"> | number,
n12: Node<"float"> | number,
n13: Node<"float"> | number,
n14: Node<"float"> | number,
n21: Node<"float"> | number,
n22: Node<"float"> | number,
n23: Node<"float"> | number,
n24: Node<"float"> | number,
n31: Node<"float"> | number,
n32: Node<"float"> | number,
n33: Node<"float"> | number,
n34: Node<"float"> | number,
n41: Node<"float"> | number,
n42: Node<"float"> | number,
n43: Node<"float"> | number,
n44: Node<"float"> | number,
): VarNode<"mat4", JoinNode<"mat4">>;
}

export const mat4: Mat4Function;

export const string: (value?: string) => ConstNode<"string", string>;
export const arrayBuffer: (value: ArrayBuffer) => ConstNode<"ArrayBuffer", ArrayBuffer>;
export const string: unknown;
export const arrayBuffer: unknown;

declare module "../core/Node.js" {
interface NodeElements {
Expand Down