@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
34 lines (33 loc) • 1.13 kB
JavaScript
;
import { BaseSopOperation } from "./_Base";
import { Vector3 } from "three";
import { pointsCountFromObject } from "../../../core/geometry/entities/point/CorePointUtils";
import { corePointInstanceFactory } from "../../../core/geometry/CoreObjectFactory";
const _normal = new Vector3();
const _position = new Vector3();
export class PeakSopOperation extends BaseSopOperation {
static type() {
return "peak";
}
cook(inputCoreGroups, params) {
const coreGroup = inputCoreGroups[0];
const objects = coreGroup.allObjects();
for (const object of objects) {
object.traverse((childObject) => {
const corePoint = corePointInstanceFactory(childObject);
const pointsCount = pointsCountFromObject(childObject);
for (let i = 0; i < pointsCount; i++) {
corePoint.setIndex(i);
corePoint.normal(_normal);
corePoint.position(_position);
_position.add(_normal.multiplyScalar(params.amount));
corePoint.setPosition(_position);
}
});
}
return coreGroup;
}
}
PeakSopOperation.DEFAULT_PARAMS = {
amount: 0
};