@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
63 lines (57 loc) • 2.23 kB
text/typescript
/**
* Creates a spline from input points
*
*/
import {TypedSopNode} from './_Base';
import {CoreGroup} from '../../../core/geometry/Group';
import {CurveFromPointsSopOperation} from '../../operations/sop/CurveFromPoints';
import {NodeParamsConfig, ParamConfig} from '../utils/params/ParamsConfig';
import {SplineCurveType, SPLINE_CURVE_TYPES} from '../../../core/geometry/Curve';
import {SopType} from '../../poly/registers/nodes/types/Sop';
const DEFAULT = CurveFromPointsSopOperation.DEFAULT_PARAMS;
class CurveFromPointsSopParamsConfig extends NodeParamsConfig {
/** @param points Count */
pointsCount = ParamConfig.INTEGER(DEFAULT.pointsCount, {
range: [2, 1000],
rangeLocked: [true, false],
});
/** @param closed */
closed = ParamConfig.BOOLEAN(DEFAULT.closed);
/** @param curve type */
curveType = ParamConfig.INTEGER(DEFAULT.curveType, {
menu: {
entries: SPLINE_CURVE_TYPES.map((name, value) => ({name, value})),
},
});
/** @param tension */
tension = ParamConfig.FLOAT(DEFAULT.tension, {
range: [0, 1],
rangeLocked: [false, false],
visibleIf: {curveType: SPLINE_CURVE_TYPES.indexOf(SplineCurveType.CATMULLROM)},
});
/** @param add tangent attribute */
tTangent = ParamConfig.BOOLEAN(DEFAULT.tTangent);
/** @param tangent attribute name */
tangentName = ParamConfig.STRING(DEFAULT.tangentName, {
visibleIf: {tTangent: true},
});
/** @param attributes */
// attributesToInterpolate = ParamConfig.STRING(DEFAULT.attributesToInterpolate);
}
const ParamsConfig = new CurveFromPointsSopParamsConfig();
export class CurveFromPointsSopNode extends TypedSopNode<CurveFromPointsSopParamsConfig> {
override readonly paramsConfig = ParamsConfig;
static override type() {
return SopType.CURVE_FROM_POINTS;
}
protected override initializeNode() {
this.io.inputs.setCount(0, 1);
this.io.inputs.initInputsClonedState(CurveFromPointsSopOperation.INPUT_CLONED_STATE);
}
private _operation: CurveFromPointsSopOperation | undefined;
override cook(inputCoreGroups: CoreGroup[]) {
this._operation = this._operation || new CurveFromPointsSopOperation(this._scene, this.states, this);
const coreGroup = this._operation.cook(inputCoreGroups, this.pv);
this.setCoreGroup(coreGroup);
}
}