Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: martinRenou <martin.renou@gmail.com>
- Loading branch information
1 parent
6c0da1d
commit cb59148
Showing
2 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import * as Nodes from 'three/examples/jsm/nodes/Nodes'; | ||
|
||
import { | ||
Effect, Input, InputDimension | ||
} from '../EffectBlock'; | ||
|
||
import { | ||
Block | ||
} from '../Block'; | ||
|
||
import { | ||
NodeOperation | ||
} from '../NodeMesh'; | ||
|
||
|
||
/** | ||
* Transform the vertices positions. The new vertice position is equal to `factor * input * normal + initialPosition` | ||
**/ | ||
export | ||
class WarpByScalar extends Effect { | ||
|
||
constructor (parent: Block, input: Input, factor: number) { | ||
super(parent, input); | ||
|
||
this.factorNode = new Nodes.FloatNode(factor); | ||
|
||
this.intermediateTransformNode = new Nodes.OperatorNode( | ||
this.factorNode, | ||
this.inputNode, | ||
Nodes.OperatorNode.MUL | ||
); | ||
|
||
this.transformNode = new Nodes.OperatorNode( | ||
this.intermediateTransformNode, | ||
new Nodes.NormalNode(Nodes.NormalNode.WORLD), | ||
Nodes.OperatorNode.MUL | ||
); | ||
|
||
this.addTransformNode(NodeOperation.ADD, this.transformNode); | ||
|
||
this.buildMaterial(); | ||
|
||
this.initialized = true; | ||
|
||
// There is no new geometry specific to this effect, we forward the parent event | ||
this.parent.on('change:geometry', () => { this.trigger('change:geometry'); }); | ||
|
||
this.updateMatrix(); | ||
} | ||
|
||
setInput(input?: Input) : void { | ||
super.setInput(input); | ||
|
||
if (this.initialized) { | ||
this.intermediateTransformNode.b = this.inputNode; | ||
|
||
this.buildMaterial(); | ||
} | ||
} | ||
|
||
set factor (value: number) { | ||
this.factorNode.value = value; | ||
} | ||
|
||
get factor () { | ||
return this.factorNode.value; | ||
} | ||
|
||
get inputDimension () : InputDimension { | ||
return 1; | ||
} | ||
|
||
private initialized: boolean = false; | ||
|
||
private factorNode: Nodes.FloatNode; | ||
private intermediateTransformNode: Nodes.OperatorNode; | ||
private transformNode: Nodes.OperatorNode; | ||
|
||
protected inputNode: Nodes.Node; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters