22import {
33 operatorCalc , cachedValueOf , defineVectorLength , cachedFactory , cachedFunction
44} from '../operator' ;
5+ import { fromEulerYXZ } from '../util' ;
56
67function fallbackWindow ( ) {
78 return {
@@ -10,7 +11,7 @@ function fallbackWindow() {
1011}
1112export function hijackPlayCanvas ( pc ) {
1213 const {
13- Vec2, Vec3, Quat, Mat4
14+ Vec2, Vec3, Quat, Mat4, math
1415 } = pc ;
1516
1617 cachedValueOf ( Vec2 ) ;
@@ -60,14 +61,34 @@ export function hijackPlayCanvas(pc) {
6061 }
6162 } ) ;
6263 pc . quat = cachedFunction ( ( x , y , z , w ) => {
63- if ( typeof dir === 'number' ) {
64+ if ( typeof x === 'number' ) {
6465 return new Quat ( x , y , z , w ) ;
6566 }
6667 if ( ! x ) {
6768 return new Quat ( ) ;
6869 }
70+ if ( typeof y === 'number' ) {
71+ return new Quat ( ) . setFromAxisAngle ( x , y ) ;
72+ }
6973 return new Quat ( ) . setFromMat4 ( new Mat4 ( ) . setLookAt ( Vec3 . ZERO , x , y || Vec3 . UP ) ) ;
7074 } ) ;
75+
76+ const LEFT90 = pc . quat ( Vec3 . LEFT , 90 ) ;
77+
78+ Quat . prototype . setFromOrientation = function ( { alpha, beta, gamma } , orientation ) {
79+ const x = beta * math . DEG_TO_RAD ;
80+ const y = alpha * math . DEG_TO_RAD ;
81+ const z = - gamma * math . DEG_TO_RAD ;
82+ let rot = pc . quat ( fromEulerYXZ ( x , y , z ) ) ;
83+ rot . mul ( LEFT90 ) ;
84+
85+ if ( orientation ) {
86+ const { dir } = rot ;
87+ const local = pc . quat ( dir , orientation ) ;
88+ rot = local . mul ( rot ) ;
89+ }
90+ this . copy ( rot ) ;
91+ } ;
7192}
7293
7394// eslint-disable-next-line no-undef
0 commit comments