@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
51 lines (50 loc) • 1.61 kB
JavaScript
;
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 { Poly } from "../../Poly";
class GetMaterialJsParamsConfig extends NodeParamsConfig {
constructor() {
super(...arguments);
/** @param the material node */
this.node = ParamConfig.NODE_PATH("", {
nodeSelection: {
context: NodeContext.MAT
},
dependentOnFoundNode: false,
computeOnDirty: true
});
}
}
const ParamsConfig = new GetMaterialJsParamsConfig();
export class GetMaterialJsNode extends TypedJsNode {
constructor() {
super(...arguments);
this.paramsConfig = ParamsConfig;
}
static type() {
return "getMaterial";
}
initializeNode() {
this.io.outputs.setNamedOutputConnectionPoints([
new JsConnectionPoint(JsConnectionPointType.MATERIAL, JsConnectionPointType.MATERIAL)
]);
}
setLines(shadersCollectionController) {
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)
}
]);
}
}