-
-
Notifications
You must be signed in to change notification settings - Fork 35.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Nodes: Allow JS-like assigns, implement AssignNode (#26795)
* Introduce AssignNode Signed-off-by: Levi Pesin <35454228+LeviPesin@users.noreply.github.com> * Move assign and bypass Signed-off-by: Levi Pesin <35454228+LeviPesin@users.noreply.github.com> * Fix Signed-off-by: Levi Pesin <35454228+LeviPesin@users.noreply.github.com> * Same for temp Signed-off-by: Levi Pesin <35454228+LeviPesin@users.noreply.github.com> * Implement SplitNode.assign() Signed-off-by: Levi Pesin <35454228+LeviPesin@users.noreply.github.com> * Revert bypass and temp change, fix in another way Signed-off-by: Levi Pesin <35454228+LeviPesin@users.noreply.github.com> * Implement ArrayElementNode.assign() Signed-off-by: Levi Pesin <35454228+LeviPesin@users.noreply.github.com> * Add the bonus usecase support Signed-off-by: Levi Pesin <35454228+LeviPesin@users.noreply.github.com> * Fix code issues Signed-off-by: Levi Pesin <35454228+LeviPesin@users.noreply.github.com> * Fixes * Fix, simplify Signed-off-by: Levi Pesin <35454228+LeviPesin@users.noreply.github.com> * Small fix --------- Signed-off-by: Levi Pesin <35454228+LeviPesin@users.noreply.github.com>
- Loading branch information
Showing
5 changed files
with
101 additions
and
32 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
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,65 @@ | ||
import { addNodeClass } from '../core/Node.js'; | ||
import TempNode from '../core/TempNode.js'; | ||
import { addNodeElement, nodeProxy } from '../shadernode/ShaderNode.js'; | ||
|
||
class AssignNode extends TempNode { | ||
|
||
constructor( aNode, bNode ) { | ||
|
||
super(); | ||
|
||
this.aNode = aNode; | ||
this.bNode = bNode; | ||
|
||
} | ||
|
||
hasDependencies( builder ) { | ||
|
||
return false; | ||
|
||
} | ||
|
||
getNodeType( builder, output ) { | ||
|
||
const aNode = this.aNode; | ||
const bNode = this.bNode; | ||
|
||
const typeA = aNode.getNodeType( builder ); | ||
const typeB = bNode.getNodeType( builder ); | ||
|
||
return typeB === 'void' ? 'void' : typeA; | ||
|
||
} | ||
|
||
generate( builder, output ) { | ||
|
||
const aNode = this.aNode; | ||
const bNode = this.bNode; | ||
|
||
const type = this.getNodeType( builder, output ); | ||
|
||
const a = aNode.build( builder, type ); | ||
const b = bNode.build( builder, type ); | ||
|
||
if ( output !== 'void' ) { | ||
|
||
builder.addLineFlowCode( `${a} = ${b}` ); | ||
return a; | ||
|
||
} else if ( type !== 'void' ) { | ||
|
||
return builder.format( `${a} = ${b}`, type, output ); | ||
|
||
} | ||
|
||
} | ||
|
||
} | ||
|
||
export default AssignNode; | ||
|
||
export const assign = nodeProxy( AssignNode ); | ||
|
||
addNodeClass( 'AssignNode', AssignNode ); | ||
|
||
addNodeElement( 'assign', assign ); |
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
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
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