@babylonjs/core
Version:
Getting started? Play directly with the Babylon.js API using our [playground](https://playground.babylonjs.com/). It also contains a lot of samples to learn how to use it.
61 lines • 2.69 kB
JavaScript
import { FlowGraphExecutionBlockWithOutSignal } from "../../flowGraphExecutionBlockWithOutSignal.js";
import { RichTypeAny } from "../../flowGraphRichTypes.js";
import { RegisterClass } from "../../../Misc/typeStore.js";
/**
* This block will set a property on a given target asset.
* The property name can include dots ("."), which will be interpreted as a path to the property.
* The target asset is an input and can be changed at any time.
* The value of the property is an input and can be changed at any time.
*
* For example, with an input of a mesh asset, the property name "position.x" will set the x component of the position of the mesh.
*
* Note that it is recommended to input the object on which you are working on (i.e. a material) than providing a mesh and then getting the material from it.
*/
export class FlowGraphSetPropertyBlock extends FlowGraphExecutionBlockWithOutSignal {
constructor(
/**
* the configuration of the block
*/
config) {
super(config);
this.config = config;
this.object = this.registerDataInput("object", RichTypeAny, config.target);
this.value = this.registerDataInput("value", RichTypeAny);
this.propertyName = this.registerDataInput("propertyName", RichTypeAny, config.propertyName);
this.customSetFunction = this.registerDataInput("customSetFunction", RichTypeAny);
}
_execute(context, _callingSignal) {
try {
const target = this.object.getValue(context);
const value = this.value.getValue(context);
const setFunction = this.customSetFunction.getValue(context);
if (setFunction) {
setFunction(target, this.propertyName.getValue(context), value, context);
}
else {
this._setPropertyValue(target, this.propertyName.getValue(context), value);
}
}
catch (e) {
this._reportError(context, e);
}
this.out._activateSignal(context);
}
_setPropertyValue(target, propertyName, value) {
const path = propertyName.split(".");
let obj = target;
for (let i = 0; i < path.length - 1; i++) {
const prop = path[i];
if (obj[prop] === undefined) {
obj[prop] = {};
}
obj = obj[prop];
}
obj[path[path.length - 1]] = value;
}
getClassName() {
return "FlowGraphSetPropertyBlock" /* FlowGraphBlockNames.SetProperty */;
}
}
RegisterClass("FlowGraphSetPropertyBlock" /* FlowGraphBlockNames.SetProperty */, FlowGraphSetPropertyBlock);
//# sourceMappingURL=flowGraphSetPropertyBlock.js.map