@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
46 lines (39 loc) • 2.25 kB
text/typescript
import {TRIGGER_CONNECTION_NAME, TypedJsNode} from './_Base';
import {NodeParamsConfig, ParamConfig} from '../utils/params/ParamsConfig';
import {JsConnectionPoint, JsConnectionPointType, JS_CONNECTION_POINT_IN_NODE_DEF} from '../utils/io/connections/Js';
import {inputObject3DMaterial, setObject3DOutputLine} from './_BaseObject3D';
import {JsLinesCollectionController} from './code/utils/JsLinesCollectionController';
import {Poly} from '../../Poly';
const CONNECTION_OPTIONS = JS_CONNECTION_POINT_IN_NODE_DEF;
class BaseSetMaterialColorJsParamsConfig extends NodeParamsConfig {
/** @param color */
color = ParamConfig.COLOR([1, 1, 1]);
/** @param lerp factor */
lerp = ParamConfig.FLOAT(1);
}
const ParamsConfig = new BaseSetMaterialColorJsParamsConfig();
export abstract class BaseSetMaterialColorJsNode extends TypedJsNode<BaseSetMaterialColorJsParamsConfig> {
override readonly paramsConfig = ParamsConfig;
override initializeNode() {
this.io.inputs.setNamedInputConnectionPoints([
new JsConnectionPoint(TRIGGER_CONNECTION_NAME, JsConnectionPointType.TRIGGER, CONNECTION_OPTIONS),
new JsConnectionPoint(JsConnectionPointType.MATERIAL, JsConnectionPointType.MATERIAL, CONNECTION_OPTIONS),
]);
this.io.outputs.setNamedOutputConnectionPoints([
new JsConnectionPoint(TRIGGER_CONNECTION_NAME, JsConnectionPointType.TRIGGER),
new JsConnectionPoint(JsConnectionPointType.MATERIAL, JsConnectionPointType.MATERIAL, CONNECTION_OPTIONS),
]);
}
override setLines(linesController: JsLinesCollectionController) {
setObject3DOutputLine(this, linesController);
}
override setTriggerableLines(shadersCollectionController: JsLinesCollectionController) {
const material = inputObject3DMaterial(this, shadersCollectionController);
const color = this.variableForInputParam(shadersCollectionController, this.p.color);
const lerp = this.variableForInputParam(shadersCollectionController, this.p.lerp);
const func = Poly.namedFunctionsRegister.getFunction(this._functionName(), this, shadersCollectionController);
const bodyLine = func.asString(material, color, lerp);
shadersCollectionController.addTriggerableLines(this, [bodyLine]);
}
abstract _functionName(): 'setMaterialColor' | 'setMaterialEmissiveColor';
}