mirror of
https://github.com/jiawanlong/Cesium-Examples.git
synced 2025-07-07 08:47:29 +00:00
62 lines
1.1 KiB
JavaScript
62 lines
1.1 KiB
JavaScript
import Node, { addNodeClass } from './Node.js';
|
|
import { addNodeElement, nodeProxy } from '../shadernode/ShaderNode.js';
|
|
|
|
class ContextNode extends Node {
|
|
|
|
constructor( node, context = {} ) {
|
|
|
|
super();
|
|
|
|
this.isContextNode = true;
|
|
|
|
this.node = node;
|
|
this.context = context;
|
|
|
|
}
|
|
|
|
getNodeType( builder ) {
|
|
|
|
return this.node.getNodeType( builder );
|
|
|
|
}
|
|
|
|
construct( builder ) {
|
|
|
|
const previousContext = builder.getContext();
|
|
|
|
builder.setContext( { ...builder.context, ...this.context } );
|
|
|
|
const node = this.node.build( builder );
|
|
|
|
builder.setContext( previousContext );
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
generate( builder, output ) {
|
|
|
|
const previousContext = builder.getContext();
|
|
|
|
builder.setContext( { ...builder.context, ...this.context } );
|
|
|
|
const snippet = this.node.build( builder, output );
|
|
|
|
builder.setContext( previousContext );
|
|
|
|
return snippet;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
export default ContextNode;
|
|
|
|
export const context = nodeProxy( ContextNode );
|
|
export const label = ( node, name ) => context( node, { label: name } );
|
|
|
|
addNodeElement( 'context', context );
|
|
addNodeElement( 'label', label );
|
|
|
|
addNodeClass( ContextNode );
|