UNPKG

@polygonjs/polygonjs

Version:

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

54 lines (49 loc) 1.63 kB
/** * get a material * * */ import {TypedJsNode} from './_Base'; import {NodeParamsConfig, ParamConfig} from '../utils/params/ParamsConfig'; import {JsConnectionPoint, JsConnectionPointType} from '../utils/io/connections/Js'; import {NodeContext} from '../../poly/NodeContext'; import {JsLinesCollectionController} from './code/utils/JsLinesCollectionController'; import {Poly} from '../../Poly'; class GetMaterialJsParamsConfig extends NodeParamsConfig { /** @param the material node */ node = ParamConfig.NODE_PATH('', { nodeSelection: { context: NodeContext.MAT, }, dependentOnFoundNode: false, computeOnDirty: true, }); } const ParamsConfig = new GetMaterialJsParamsConfig(); export class GetMaterialJsNode extends TypedJsNode<GetMaterialJsParamsConfig> { override readonly paramsConfig = ParamsConfig; static override type() { return 'getMaterial'; } override initializeNode() { this.io.outputs.setNamedOutputConnectionPoints([ new JsConnectionPoint(JsConnectionPointType.MATERIAL, JsConnectionPointType.MATERIAL), ]); } override setLines(shadersCollectionController: JsLinesCollectionController) { const node = this.pv.node.node(); if (!(node && node.context() == NodeContext.MAT)) { return; } const nodePath = `'${node.path()}'`; const varName = this.jsVarName(JsConnectionPointType.MATERIAL); const func = Poly.namedFunctionsRegister.getFunction('getMaterial', this, shadersCollectionController); shadersCollectionController.addBodyOrComputed(this, [ { dataType: JsConnectionPointType.MATERIAL, varName, value: func.asString(nodePath), }, ]); } }