UNPKG

@polygonjs/polygonjs

Version:

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

57 lines (56 loc) 2.04 kB
"use strict"; import { BaseNodeGlMathFunctionArg3GlNode } from "./_BaseMathFunction"; import { GlConnectionPointType } from "../utils/io/connections/Gl"; import { FunctionGLDefinition } from "./utils/GLDefinition"; export function MathFunctionArg3Factory(type, options = {}) { const gl_method_name = options.method || type; const gl_output_name = options.out || "val"; const gl_input_names = options.in || ["in0", "in1", "in2"]; const param_default_values = options.default || {}; const out_type = options.out_type || GlConnectionPointType.FLOAT; const functions = options.functions || []; return class Node extends BaseNodeGlMathFunctionArg3GlNode { static type() { return type; } initializeNode() { super.initializeNode(); this.io.connection_points.set_input_name_function(this._gl_input_name.bind(this)); this.io.connection_points.set_output_name_function(this._gl_output_name.bind(this)); this.io.connection_points.set_expected_output_types_function(this._expected_output_types.bind(this)); } _gl_input_name(index) { return gl_input_names[index]; } _gl_output_name(index) { return gl_output_name; } gl_method_name() { return gl_method_name; } _expected_output_types() { return [out_type]; } paramDefaultValue(name) { return param_default_values[name]; } gl_function_definitions() { return functions.map((f) => new FunctionGLDefinition(this, f)); } }; } export class ClampGlNode extends MathFunctionArg3Factory("clamp", { in: ["value", "min", "max"], default: { max: 1 } }) { _expected_output_types() { return [this._expected_input_types()[0]]; } } export class FaceforwardGlNode extends MathFunctionArg3Factory("faceForward", { in: ["N", "I", "Nref"] }) { } export class SmoothstepGlNode extends MathFunctionArg3Factory("smoothstep", { in: ["edge0", "edge1", "x"], default: { edge1: 1 } }) { _expected_output_types() { return [this._expected_input_types()[0]]; } }