@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
67 lines (66 loc) • 2.75 kB
JavaScript
;
import { TypedJsNode } from "./_Base";
import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig";
import { JsConnectionPoint, JsConnectionPointType, JS_CONNECTION_POINT_IN_NODE_DEF } from "../utils/io/connections/Js";
import { Box3 } from "three";
import { Poly } from "../../Poly";
const CONNECTION_OPTIONS = JS_CONNECTION_POINT_IN_NODE_DEF;
class Box3JsParamsConfig extends NodeParamsConfig {
constructor() {
super(...arguments);
/** @param position representing the lower bound of the box */
this.min = ParamConfig.VECTOR3([-1, -1, -1]);
/** @param position representing the upper bound of the box */
this.max = ParamConfig.VECTOR3([1, 1, 1]);
}
}
const ParamsConfig = new Box3JsParamsConfig();
export class Box3JsNode extends TypedJsNode {
constructor() {
super(...arguments);
this.paramsConfig = ParamsConfig;
}
static type() {
return "box3";
}
initializeNode() {
this.io.outputs.setNamedOutputConnectionPoints([
new JsConnectionPoint(JsConnectionPointType.BOX3, JsConnectionPointType.BOX3, CONNECTION_OPTIONS)
]);
}
setLines(shadersCollectionController) {
const min = this.variableForInputParam(shadersCollectionController, this.p.min);
const max = this.variableForInputParam(shadersCollectionController, this.p.max);
const out = this.jsVarName(JsConnectionPointType.BOX3);
const tmpVarName = shadersCollectionController.addVariable(this, new Box3());
const func = Poly.namedFunctionsRegister.getFunction("box3Set", this, shadersCollectionController);
const bodyLine = func.asString(min, max, tmpVarName);
shadersCollectionController.addBodyOrComputed(this, [
{ dataType: JsConnectionPointType.PLANE, varName: out, value: bodyLine }
]);
}
// override initializeNode() {
// super.initializeNode();
// this.io.connection_points.initializeNode();
// // this.io.connection_points.set_input_name_function(this._expectedInputName.bind(this));
// this.io.connection_points.set_output_name_function((index: number) => OUTPUT_NAME);
// this.io.connection_points.set_expected_input_types_function(() => []);
// this.io.connection_points.set_expected_output_types_function(() => [ActorConnectionPointType.BOX3]);
// }
// private _box3 = new Box3();
// private _box3Updated = false;
// public override outputValue(context: ActorNodeTriggerContext) {
// if (!this._box3Updated) {
// this._updateBox3();
// this._box3Updated = true;
// }
// return this._box3;
// }
// static PARAM_CALLBACK_updateBox3(node: Box3ActorNode) {
// node._updateBox3();
// }
// private _updateBox3() {
// this._box3.min.copy(this.pv.min);
// this._box3.max.copy(this.pv.max);
// }
}