@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
41 lines (34 loc) • 1.54 kB
text/typescript
import {BaseNodeGlMathFunctionArg2GlNode} from './_BaseMathFunction';
import {ThreeToGl} from '../../../core/ThreeToGl';
import {GlConnectionPointType} from '../utils/io/connections/Gl';
import {ShadersCollectionController} from './code/utils/ShadersCollectionController';
export abstract class BaseNodeGlMathFunctionArgBoolean2GlNode extends BaseNodeGlMathFunctionArg2GlNode {
override initializeNode() {
super.initializeNode();
this.io.connection_points.set_expected_input_types_function(this._expected_input_types.bind(this));
this.io.connection_points.set_expected_output_types_function(this._expected_output_types.bind(this));
}
protected override _expected_input_types() {
return [GlConnectionPointType.BOOL, GlConnectionPointType.BOOL];
}
protected override _expected_output_types() {
return [GlConnectionPointType.BOOL];
}
boolean_operation(): string {
return 'boolean_operation to be defined';
}
override setLines(shaders_collection_controller: ShadersCollectionController) {
const connectionPoints = this.io.inputs.namedInputConnectionPoints();
if (!connectionPoints) {
return;
}
const args = connectionPoints.map((named_input, i) => {
const name = named_input.name();
return ThreeToGl.any(this.variableForInput(name));
});
const joined_args = args.join(` ${this.boolean_operation()} `);
const sum = this.glVarName(this.io.connection_points.output_name(0));
const body_line = `bool ${sum} = ${joined_args}`;
shaders_collection_controller.addBodyLines(this, [body_line]);
}
}