UNPKG

@polygonjs/polygonjs

Version:

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

33 lines (32 loc) 1.19 kB
"use strict"; import { BaseSopOperation } from "./_Base"; import { SopType } from "../../poly/registers/nodes/types/Sop"; import { Vector2 } from "three"; import { InputCloneMode } from "../../poly/InputCloneMode"; export class UvTransformSopOperation extends BaseSopOperation { static type() { return SopType.UV_TRANSFORM; } cook(input_contents, params) { const objects = input_contents[0].threejsObjectsWithGeo(); for (let object of objects) { const geometry = object.geometry; const attrib = geometry.getAttribute(params.attribName); const array = attrib.array; const ptsCount = array.length / 2; for (let i = 0; i < ptsCount; i++) { array[i * 2 + 0] = params.t.x + params.pivot.x + params.s.x * (array[i * 2 + 0] - params.pivot.x); array[i * 2 + 1] = params.t.y + params.pivot.y + params.s.y * (array[i * 2 + 1] - params.pivot.y); } attrib.needsUpdate = true; } return input_contents[0]; } } UvTransformSopOperation.DEFAULT_PARAMS = { attribName: "uv", t: new Vector2(0, 0), s: new Vector2(1, 1), pivot: new Vector2(0, 0) }; UvTransformSopOperation.INPUT_CLONED_STATE = InputCloneMode.FROM_NODE;