UNPKG

@polygonjs/polygonjs

Version:

node-based WebGL 3D engine https://polygonjs.com

117 lines (116 loc) 3.79 kB
"use strict"; import { TypedGlNode } from "./_Base"; import { ThreeToGl } from "../../../core/ThreeToGl"; import { GlConnectionPointType, GlConnectionPoint } from "../utils/io/connections/Gl"; import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig"; const OUTPUT_NAME_INT = "int"; class FloatToIntGlParamsConfig extends NodeParamsConfig { constructor() { super(...arguments); this.float = ParamConfig.FLOAT(0); } } const ParamsConfigFloatToInt = new FloatToIntGlParamsConfig(); export class FloatToIntGlNode extends TypedGlNode { constructor() { super(...arguments); this.paramsConfig = ParamsConfigFloatToInt; } static type() { return "floatToInt"; } initializeNode() { this.io.outputs.setNamedOutputConnectionPoints([ new GlConnectionPoint(OUTPUT_NAME_INT, GlConnectionPointType.INT) ]); } setLines(shaders_collection_controller) { const float = this.variableForInputParam(this.p.float); const int = this.glVarName(OUTPUT_NAME_INT); const body_line = `int ${int} = int(${ThreeToGl.float(float)})`; shaders_collection_controller.addBodyLines(this, [body_line]); } } const OUTPUT_NAME_FLOAT = "float"; class IntToFloatGlParamsConfig extends NodeParamsConfig { constructor() { super(...arguments); this.int = ParamConfig.INTEGER(0); } } const ParamsConfigIntToFloat = new IntToFloatGlParamsConfig(); export class IntToFloatGlNode extends TypedGlNode { constructor() { super(...arguments); this.paramsConfig = ParamsConfigIntToFloat; } static type() { return "intToFloat"; } initializeNode() { this.io.outputs.setNamedOutputConnectionPoints([ new GlConnectionPoint(OUTPUT_NAME_FLOAT, GlConnectionPointType.FLOAT) ]); } setLines(shaders_collection_controller) { const int = this.variableForInputParam(this.p.int); const float = this.glVarName(OUTPUT_NAME_FLOAT); const body_line = `float ${float} = float(${ThreeToGl.integer(int)})`; shaders_collection_controller.addBodyLines(this, [body_line]); } } const OUTPUT_NAME_BOOL = "bool"; class IntToBoolGlParamsConfig extends NodeParamsConfig { constructor() { super(...arguments); this.int = ParamConfig.INTEGER(0); } } const ParamsConfigIntToBool = new IntToBoolGlParamsConfig(); export class IntToBoolGlNode extends TypedGlNode { constructor() { super(...arguments); this.paramsConfig = ParamsConfigIntToBool; } static type() { return "intToBool"; } initializeNode() { this.io.outputs.setNamedOutputConnectionPoints([ new GlConnectionPoint(OUTPUT_NAME_BOOL, GlConnectionPointType.BOOL) ]); } setLines(shaders_collection_controller) { const int = this.variableForInputParam(this.p.int); const bool = this.glVarName(OUTPUT_NAME_BOOL); const body_line = `bool ${bool} = bool(${ThreeToGl.integer(int)})`; shaders_collection_controller.addBodyLines(this, [body_line]); } } class BoolToIntGlParamsConfig extends NodeParamsConfig { constructor() { super(...arguments); this.bool = ParamConfig.BOOLEAN(0); } } const ParamsConfigBoolToInt = new BoolToIntGlParamsConfig(); export class BoolToIntGlNode extends TypedGlNode { constructor() { super(...arguments); this.paramsConfig = ParamsConfigBoolToInt; } static type() { return "boolToInt"; } initializeNode() { this.io.outputs.setNamedOutputConnectionPoints([ new GlConnectionPoint(OUTPUT_NAME_INT, GlConnectionPointType.INT) ]); } setLines(shaders_collection_controller) { const bool = this.variableForInputParam(this.p.bool); const int = this.glVarName(OUTPUT_NAME_INT); const body_line = `int ${int} = int(${ThreeToGl.bool(bool)})`; shaders_collection_controller.addBodyLines(this, [body_line]); } }