@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
108 lines (107 loc) • 3.48 kB
JavaScript
;
import { BaseParamConfig } from "../../../utils/code/configs/BaseParamConfig";
import { touchParamRef } from "../../../../../core/reactivity/ParamReactivity";
export class JsParamConfig extends BaseParamConfig {
// private _uniform: IUniform | undefined;
constructor(_type, _name, _defaultValue, _uniformName) {
super(_type, _name, _defaultValue);
this._uniformName = _uniformName;
}
toJSON() {
return {
type: this._type,
name: this._name,
defaultValue: this._defaultValue,
uniformName: this._uniformName
};
}
static fromJSON(json) {
return new JsParamConfig(json.type, json.name, json.defaultValue, json.uniformName);
}
uniformName() {
return this._uniformName;
}
// override applyToNode(node: BaseNodeType) {
// console.warn('not needed in js context');
// }
// uniform() {
// return (this._uniform = this._uniform || this._createUniform());
// }
// private _createUniform() {
// return JsParamConfig.uniformByType(this._type);
// }
_callback(node, param) {
JsParamConfig.callback(node, param.name());
}
static callback(node, paramName) {
touchParamRef(node, paramName);
}
// TODO: refactor that to use the default values map?
// static uniformByType(type: ParamType): IUniform {
// switch (type) {
// case ParamType.BOOLEAN:
// return {value: 0};
// case ParamType.BUTTON:
// return {value: 0};
// case ParamType.COLOR:
// return {value: new Color(0, 0, 0)};
// case ParamType.FLOAT:
// return {value: 0};
// case ParamType.FOLDER:
// return {value: 0};
// case ParamType.INTEGER:
// return {value: 0};
// // case ParamType.OPERATOR_PATH:
// // return {value: 0};
// case ParamType.NODE_PATH:
// return {value: 0};
// case ParamType.PARAM_PATH:
// return {value: 0};
// // case ParamType.STRING: return {type: 't', value: null} // new Texture()}
// case ParamType.RAMP:
// return {value: null}; // new Texture()}
// case ParamType.STRING:
// return {value: null};
// case ParamType.VECTOR2:
// return {value: new Vector2(0, 0)};
// case ParamType.VECTOR3:
// return {value: new Vector3(0, 0, 0)};
// case ParamType.VECTOR4:
// return {value: new Vector4(0, 0, 0, 0)};
// }
// TypeAssert.unreachable(type);
// }
// private static set_uniform_value_from_texture(param: OperatorPathParam, uniform: IUniform) {
// const found_node = param.found_node();
// if (found_node) {
// if (found_node.isDirty()) {
// found_node.compute().then((container) => {
// const texture = container.texture();
// uniform.value = texture;
// });
// } else {
// const container = found_node.containerController.container();
// const texture = container.texture();
// uniform.value = texture;
// }
// } else {
// uniform.value = null;
// }
// }
// private static async setUniformValueFromTextureFromNodePathParam(param: NodePathParam, uniform: IUniform) {
// if (param.isDirty()) {
// await param.compute();
// }
// const node = param.value.nodeWithContext(NodeContext.COP);
// if (node) {
// if (node.isDirty()) {
// await node.compute();
// }
// const container = node.containerController.container();
// const texture = container.texture();
// uniform.value = texture;
// } else {
// uniform.value = null;
// }
// }
}