@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
71 lines (70 loc) • 2.74 kB
JavaScript
"use strict";
import { TypedSopNode } from "./_Base";
import { NodeParamsConfig, ParamConfig } from "../utils/params/ParamsConfig";
import { TubeSopOperation } from "../../operations/sop/Tube";
import { SopType } from "../../poly/registers/nodes/types/Sop";
const DEFAULT = TubeSopOperation.DEFAULT_PARAMS;
const step = 1e-5;
class TubeSopParamsConfig extends NodeParamsConfig {
constructor() {
super(...arguments);
/** @param if true, the tube is set with a single radius. If false, it uses a top and bottom radius */
this.singleRadius = ParamConfig.BOOLEAN(DEFAULT.singleRadius);
/** @param radius */
this.radius = ParamConfig.FLOAT(DEFAULT.radius, {
range: [0, 2],
visibleIf: { singleRadius: 1 }
});
/** @param top radius */
this.radiusTop = ParamConfig.FLOAT(DEFAULT.radiusTop, {
range: [0, 2],
visibleIf: { singleRadius: 0 }
});
/** @param bottom radius */
this.radiusBottom = ParamConfig.FLOAT(DEFAULT.radiusBottom, {
range: [0, 2],
visibleIf: { singleRadius: 0 }
});
/** @param tube height */
this.height = ParamConfig.FLOAT(DEFAULT.height, { range: [0, 1] });
/** @param number of segments in the radial direction */
this.segmentsRadial = ParamConfig.INTEGER(DEFAULT.segmentsRadial, { range: [3, 50], rangeLocked: [true, false] });
/** @param number of segments in the height direction */
this.segmentsHeight = ParamConfig.INTEGER(DEFAULT.segmentsHeight, { range: [1, 20], rangeLocked: [true, false] });
/** @param adds caps */
this.cap = ParamConfig.BOOLEAN(1);
/** @param center of the tube */
this.center = ParamConfig.VECTOR3([0, 0, 0]);
/** @param direction of the tube */
this.direction = ParamConfig.VECTOR3([0, 0, 1]);
/** @param if set to 1, you can then set the phiStart, phi_end, thetaStart and theta_end */
this.open = ParamConfig.BOOLEAN(DEFAULT.open);
/** @param start of theta angle */
this.thetaStart = ParamConfig.FLOAT(DEFAULT.thetaStart, {
visibleIf: { open: 1 },
range: [0, Math.PI * 2],
step
});
/** @param length of theta opening */
this.thetaLength = ParamConfig.FLOAT("$PI*2", {
visibleIf: { open: 1 },
range: [0, Math.PI * 2],
step
});
}
}
const ParamsConfig = new TubeSopParamsConfig();
export class TubeSopNode extends TypedSopNode {
constructor() {
super(...arguments);
this.paramsConfig = ParamsConfig;
}
static type() {
return SopType.TUBE;
}
cook(input_contents) {
this._operation = this._operation || new TubeSopOperation(this._scene, this.states, this);
const core_group = this._operation.cook(input_contents, this.pv);
this.setCoreGroup(core_group);
}
}