@polygonjs/polygonjs
Version:
node-based WebGL 3D engine https://polygonjs.com
39 lines (38 loc) • 1.19 kB
JavaScript
;
import { BaseSopOperation } from "./_Base";
import { isBooleanTrue } from "../../../core/BooleanValue";
export class RestAttributesSopOperation extends BaseSopOperation {
static type() {
return "restAttributes";
}
cook(input_contents, params) {
const core_group = input_contents[0];
const objects = core_group.threejsObjectsWithGeo();
if (isBooleanTrue(params.tposition)) {
this._create_rest_attribute(objects, params.position, params.restP);
}
if (isBooleanTrue(params.tnormal)) {
this._create_rest_attribute(objects, params.normal, params.restN);
}
return this.createCoreGroupFromObjects(objects);
}
_create_rest_attribute(objects, attrib_name, rest_attrib_name) {
for (let object of objects) {
const geometry = object.geometry;
if (geometry) {
const src_attrib = geometry.getAttribute(attrib_name);
if (src_attrib) {
geometry.setAttribute(rest_attrib_name, src_attrib.clone());
}
}
}
}
}
RestAttributesSopOperation.DEFAULT_PARAMS = {
tposition: true,
position: "position",
restP: "restP",
tnormal: true,
normal: "normal",
restN: "restN"
};