UNPKG

@polygonjs/polygonjs

Version:

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

37 lines (36 loc) 1.27 kB
"use strict"; import { TypedGlNode } from "./_Base"; import { ThreeToGl } from "../../../../src/core/ThreeToGl"; import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig"; import { GlConnectionPoint, GlConnectionPointType } from "../utils/io/connections/Gl"; const OUTPUT_NAME = "cross"; class CrossGlParamsConfig extends NodeParamsConfig { constructor() { super(...arguments); this.x = ParamConfig.VECTOR3([0, 0, 1]); this.y = ParamConfig.VECTOR3([0, 1, 0]); } } const ParamsConfig = new CrossGlParamsConfig(); export class CrossGlNode extends TypedGlNode { constructor() { super(...arguments); this.paramsConfig = ParamsConfig; } static type() { return "cross"; } initializeNode() { super.initializeNode(); this.io.outputs.setNamedOutputConnectionPoints([ new GlConnectionPoint(OUTPUT_NAME, GlConnectionPointType.VEC3) ]); } setLines(shaders_collection_controller) { const x = ThreeToGl.float(this.variableForInputParam(this.p.x)); const y = ThreeToGl.float(this.variableForInputParam(this.p.y)); const result = this.glVarName(OUTPUT_NAME); const body_line = `vec3 ${result} = cross(${x}, ${y})`; shaders_collection_controller.addBodyLines(this, [body_line]); } }