@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
114 lines (113 loc) • 4.42 kB
JavaScript
;
import { TypedJsNode } from "./_Base";
import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig";
import {
JsConnectionPoint,
JsConnectionPointType,
JsConnectionPointTypeToArrayTypeMap,
JS_CONNECTION_POINT_IN_NODE_DEF,
PARAM_CONVERTIBLE_JS_CONNECTION_POINT_TYPES
} from "../utils/io/connections/Js";
import { inputObject3D } from "./_BaseObject3D";
import { Poly } from "../../Poly";
import { createVariable } from "./code/assemblers/_BaseJsPersistedConfigUtils";
const CONNECTION_OPTIONS = JS_CONNECTION_POINT_IN_NODE_DEF;
var GetChildrenAttributesInputName = /* @__PURE__ */ ((GetChildrenAttributesInputName2) => {
GetChildrenAttributesInputName2["attribName"] = "attribName";
return GetChildrenAttributesInputName2;
})(GetChildrenAttributesInputName || {});
class GetChildrenAttributesJsParamsConfig extends NodeParamsConfig {
constructor() {
super(...arguments);
// attribName = ParamConfig.STRING('');
this.type = ParamConfig.INTEGER(PARAM_CONVERTIBLE_JS_CONNECTION_POINT_TYPES.indexOf(JsConnectionPointType.FLOAT), {
menu: {
entries: PARAM_CONVERTIBLE_JS_CONNECTION_POINT_TYPES.map((name, i) => {
return { name, value: i };
})
}
});
}
}
const ParamsConfig = new GetChildrenAttributesJsParamsConfig();
const _GetChildrenAttributesJsNode = class extends TypedJsNode {
constructor() {
super(...arguments);
this.paramsConfig = ParamsConfig;
// this is used to allow setting attribName before the parameter is created
this._nextAttribName = "";
}
static type() {
return "getChildrenAttributes";
}
initializeNode() {
this.io.inputs.setNamedInputConnectionPoints([
new JsConnectionPoint(JsConnectionPointType.OBJECT_3D, JsConnectionPointType.OBJECT_3D, CONNECTION_OPTIONS),
new JsConnectionPoint(
"attribName" /* attribName */,
JsConnectionPointType.STRING,
CONNECTION_OPTIONS
)
]);
this.io.connection_points.set_expected_input_types_function(() => []);
this.io.connection_points.set_output_name_function((index) => _GetChildrenAttributesJsNode.OUTPUT_NAME);
this.io.connection_points.set_expected_output_types_function(() => [this._currentConnectionType()]);
}
_currentConnectionType() {
if (this.pv.type == null) {
console.warn(`${this.type()} actor node type not valid`);
}
const connectionType = PARAM_CONVERTIBLE_JS_CONNECTION_POINT_TYPES[this.pv.type];
if (connectionType == null) {
console.warn(`${this.type()} actor node type not valid`);
}
const arrayConnectionType = JsConnectionPointTypeToArrayTypeMap[connectionType];
return arrayConnectionType;
}
paramDefaultValue(name) {
return {
["attribName" /* attribName */]: this._nextAttribName
}[name];
}
setAttribType(type) {
this.p.type.set(PARAM_CONVERTIBLE_JS_CONNECTION_POINT_TYPES.indexOf(type));
}
attribType() {
return PARAM_CONVERTIBLE_JS_CONNECTION_POINT_TYPES[this.pv.type];
}
setAttribName(attribName) {
const param = this.params.get("attribName" /* attribName */);
if (param) {
param.set(attribName);
} else {
this._nextAttribName = attribName;
}
}
attribName() {
return this.params.get("attribName" /* attribName */).value;
}
setLines(shadersCollectionController) {
const object3D = inputObject3D(this, shadersCollectionController);
const attribName = this.variableForInput(
shadersCollectionController,
"attribName" /* attribName */
);
const varName = this.jsVarName(_GetChildrenAttributesJsNode.OUTPUT_NAME);
const dataType = PARAM_CONVERTIBLE_JS_CONNECTION_POINT_TYPES[this.pv.type];
const arrayType = JsConnectionPointTypeToArrayTypeMap[dataType];
const variable = createVariable(arrayType);
const tmpVarName = variable ? shadersCollectionController.addVariable(this, variable) : void 0;
if (!tmpVarName) {
return;
}
const func = Poly.namedFunctionsRegister.getFunction(
"getChildrenAttributes",
this,
shadersCollectionController
);
const bodyLine = func.asString(object3D, attribName, `'${dataType}'`, tmpVarName);
shadersCollectionController.addBodyOrComputed(this, [{ dataType, varName, value: bodyLine }]);
}
};
export let GetChildrenAttributesJsNode = _GetChildrenAttributesJsNode;
GetChildrenAttributesJsNode.OUTPUT_NAME = "val";