UNPKG

polygonjs-engine

Version:

node-based webgl 3D engine https://polygonjs.com

37 lines (36 loc) 1.08 kB
import {BaseSopOperation} from "./_Base"; export class RestAttributesSopOperation extends BaseSopOperation { static type() { return "restAttributes"; } cook(input_contents, params) { const core_group = input_contents[0]; const objects = core_group.objectsWithGeo(); if (params.tposition) { this._create_rest_attribute(objects, params.position, params.restP); } if (params.tnormal) { this._create_rest_attribute(objects, params.normal, params.restN); } return this.create_core_group_from_objects(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" };