@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
194 lines (193 loc) • 7.41 kB
JavaScript
"use strict";
import { TRIGGER_CONNECTION_NAME, 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 { JsType } from "../../poly/registers/nodes/types/Js";
import { inputObject3D } from "./_BaseObject3D";
import { Poly } from "../../Poly";
import { WatchedValueJsDefinition } from "./utils/JsDefinition";
import { nodeMethodName } from "./code/assemblers/actor/ActorAssemblerUtils";
import { createVariable } from "./code/assemblers/_BaseJsPersistedConfigUtils";
const CONNECTION_OPTIONS = JS_CONNECTION_POINT_IN_NODE_DEF;
var OnChildAttributeUpdateInputName = /* @__PURE__ */ ((OnChildAttributeUpdateInputName2) => {
OnChildAttributeUpdateInputName2["attribName"] = "attribName";
return OnChildAttributeUpdateInputName2;
})(OnChildAttributeUpdateInputName || {});
class OnChildAttributeUpdateJsParamsConfig 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 OnChildAttributeUpdateJsParamsConfig();
const _OnChildAttributeUpdateJsNode = class extends TypedJsNode {
constructor() {
super(...arguments);
this.paramsConfig = ParamsConfig;
this._nextAttribName = "";
}
static type() {
return JsType.ON_CHILD_ATTRIBUTE_UPDATE;
}
isTriggering() {
return true;
}
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.outputs.setNamedOutputConnectionPoints([
new JsConnectionPoint(TRIGGER_CONNECTION_NAME, JsConnectionPointType.TRIGGER, CONNECTION_OPTIONS)
]);
this.io.connection_points.set_expected_input_types_function(() => []);
this.io.connection_points.set_output_name_function(
(index) => [
TRIGGER_CONNECTION_NAME,
_OnChildAttributeUpdateJsNode.OUTPUT_NEW_VALUES,
_OnChildAttributeUpdateJsNode.OUTPUT_PREV_VALUES
][index]
);
this.io.connection_points.set_expected_output_types_function(() => [
JsConnectionPointType.TRIGGER,
...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, 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;
}
}
attributeName() {
return this.params.get("attribName" /* attribName */).value;
}
setLines(shadersCollectionController) {
const type = this.attribType();
const object3D = inputObject3D(this, shadersCollectionController);
const attribName = this.variableForInput(
shadersCollectionController,
"attribName" /* attribName */
);
const getChildrenAttributesRef = Poly.namedFunctionsRegister.getFunction(
"getChildrenAttributesRef",
this,
shadersCollectionController
);
const varName = this.jsVarName("in");
const variable = createVariable(JsConnectionPointTypeToArrayTypeMap[type]);
const tmpVarName = variable ? shadersCollectionController.addVariable(this, variable, varName) : void 0;
if (tmpVarName) {
shadersCollectionController.addDefinitions(this, [
new WatchedValueJsDefinition(
this,
shadersCollectionController,
type,
getChildrenAttributesRef.asString(object3D, attribName, `'${type}'`, tmpVarName),
`this.${nodeMethodName(this)}()`,
{
deep: true
}
)
]);
}
const usedOutputNames = this.io.outputs.used_output_names();
const _val = (propertyName, functionName, type2) => {
if (!usedOutputNames.includes(propertyName)) {
return;
}
const func = Poly.namedFunctionsRegister.getFunction(functionName, this, shadersCollectionController);
const varName2 = this.jsVarName(propertyName);
const variable2 = createVariable(JsConnectionPointTypeToArrayTypeMap[type2]);
const tmpVarName2 = variable2 ? shadersCollectionController.addVariable(this, variable2, varName2) : void 0;
if (tmpVarName2) {
shadersCollectionController.addBodyOrComputed(this, [
{
dataType: type2,
varName: varName2,
value: func.asString(object3D, attribName, `'${type2}'`, tmpVarName2)
}
]);
}
};
_val(_OnChildAttributeUpdateJsNode.OUTPUT_NEW_VALUES, "getChildrenAttributes", type);
_val(_OnChildAttributeUpdateJsNode.OUTPUT_PREV_VALUES, "getChildrenAttributesPrevious", type);
}
setTriggeringLines(shadersCollectionController, triggeredMethods) {
const type = this.attribType();
const object3D = inputObject3D(this, shadersCollectionController);
const attribName = this.variableForInput(
shadersCollectionController,
"attribName" /* attribName */
);
const getChildrenAttributesRef = Poly.namedFunctionsRegister.getFunction(
"getChildrenAttributesRef",
this,
shadersCollectionController
);
const varName = this.jsVarName("in");
const variable = createVariable(JsConnectionPointTypeToArrayTypeMap[type]);
const tmpVarName = variable ? shadersCollectionController.addVariable(this, variable, varName) : void 0;
if (tmpVarName) {
shadersCollectionController.addDefinitions(this, [
new WatchedValueJsDefinition(
this,
shadersCollectionController,
type,
getChildrenAttributesRef.asString(object3D, attribName, `'${type}'`, tmpVarName),
`this.${nodeMethodName(this)}()`,
{
deep: true
}
)
]);
}
shadersCollectionController.addTriggeringLines(this, [triggeredMethods], {
gatherable: false
});
}
};
export let OnChildAttributeUpdateJsNode = _OnChildAttributeUpdateJsNode;
OnChildAttributeUpdateJsNode.OUTPUT_NEW_VALUES = "newValues";
OnChildAttributeUpdateJsNode.OUTPUT_PREV_VALUES = "previousValues";