UNPKG

@polygonjs/polygonjs

Version:

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

37 lines (36 loc) 1.17 kB
"use strict"; import { BaseSopOperation } from "./_Base"; import { Quaternion, Vector3 } from "three"; import { InputCloneMode } from "../../../engine/poly/InputCloneMode"; import { CoreLookAt } from "../../../core/LookAt"; const q1 = new Quaternion(); const q2 = new Quaternion(); export class LookAtSopOperation extends BaseSopOperation { static type() { return "lookAt"; } cook(inputCoreGroups, params) { const objects = inputCoreGroups[0].threejsObjects(); for (let object of objects) { object.up.copy(params.up); if (params.lerp >= 1) { CoreLookAt.applyLookAt(object, params.target, params.invertDirection); } else { q1.copy(object.quaternion); CoreLookAt.applyLookAt(object, params.target, params.invertDirection); q2.copy(object.quaternion); q1.slerp(q2, params.lerp); object.quaternion.copy(q1); } object.updateMatrix(); } return inputCoreGroups[0]; } } LookAtSopOperation.DEFAULT_PARAMS = { target: new Vector3(0, 0, 1), up: new Vector3(0, 1, 0), lerp: 1, invertDirection: false }; LookAtSopOperation.INPUT_CLONED_STATE = InputCloneMode.FROM_NODE;