Skip to content

Commit 80a1261

Browse files
committed
Allow passing an offset for the transformation
1 parent a9f5267 commit 80a1261

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

src/Effects/Warp.ts

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,22 @@ import {
1313
} from '../NodeMesh';
1414

1515

16+
/**
17+
* Transform the vertices positions. The new vertice position is equal to `factor * (offset + input) + initialPosition`
18+
**/
1619
export
1720
class Warp extends Effect {
1821

19-
constructor (parent: Block, input: Input, factor: number) {
22+
constructor (parent: Block, input: Input, factor: THREE.Vector3, offset: THREE.Vector3) {
2023
super(parent, input);
2124

22-
this.factorNode = new Nodes.FloatNode(factor);
25+
this.offsetNode = new Nodes.Vector3Node(offset.x, offset.y, offset.z);
26+
this.factorNode = new Nodes.Vector3Node(factor.x, factor.y, factor.z);
27+
28+
this.intermediateTransformNode = new Nodes.OperatorNode(this.offsetNode, this.inputNode, Nodes.OperatorNode.ADD);
2329

2430
this.transformNode = new Nodes.OperatorNode(
25-
this.inputNode,
31+
this.intermediateTransformNode,
2632
this.factorNode,
2733
Nodes.OperatorNode.MUL
2834
);
@@ -38,13 +44,21 @@ class Warp extends Effect {
3844
super.setInput(input);
3945

4046
if (this.initialized) {
41-
this.transformNode.a = this.inputNode;
47+
this.intermediateTransformNode.b = this.inputNode;
4248

4349
this.buildMaterial();
4450
}
4551
}
4652

47-
set factor (value: number) {
53+
set offset (value: THREE.Vector3) {
54+
this.offsetNode.value = value;
55+
}
56+
57+
get offset () {
58+
return this.offsetNode.value;
59+
}
60+
61+
set factor (value: THREE.Vector3) {
4862
this.factorNode.value = value;
4963
}
5064

@@ -58,7 +72,9 @@ class Warp extends Effect {
5872

5973
private initialized: boolean = false;
6074

61-
private factorNode: Nodes.FloatNode;
75+
private offsetNode: Nodes.Vector3Node;
76+
private factorNode: Nodes.Vector3Node;
77+
private intermediateTransformNode: Nodes.OperatorNode;
6278
private transformNode: Nodes.OperatorNode;
6379

6480
protected inputNode: Nodes.Node;

0 commit comments

Comments
 (0)