import { Actor } from 'satisfactory-json' ; import { Euler , Mesh , Quaternion , Vector3 } from 'three' ; import Vue from 'vue' ; import { isPowerLine , isSpline } from './entityHelper' ; const up = new Vector3 ( 0 , 0 , 1 ) ; const rotate90 = new Quaternion ( ) . setFromEuler ( new Euler ( 0 , 0 , Math . PI / 2 ) ) ; const rotateNeg90 = new Quaternion ( ) . setFromEuler ( new Euler ( 0 , 0 , - Math . PI / 2 ) ) ; export function applyTranslation ( mesh , translation ) { mesh . position . x = translation [ 1 ] ; mesh . position . y = translation [ 0 ] ; mesh . position . z = translation [ 2 ] ; } export function applyRotation ( mesh , rotation ) { mesh . setRotationFromQuaternion ( new Quaternion ( - rotation [ 1 ] , - rotation [ 0 ] , - rotation [ 2 ] , rotation [ 3 ] ) ) ; } export function applyScale ( mesh , scale ) { mesh . scale . x = scale [ 0 ] ; mesh . scale . y = scale [ 1 ] ; mesh . scale . z = scale [ 2 ] ; } export function updateActorMeshTransform ( mesh , actor ) { applyTranslation ( mesh , actor . transform . translation ) ; const quat = new Quaternion ( - actor . transform . rotation [ 1 ] , - actor . transform . rotation [ 0 ] , - actor . transform . rotation [ 2 ] , actor . transform . rotation [ 3 ] ) ; if ( isSpline ( actor ) ) { mesh . setRotationFromQuaternion ( quat ) ; } else if ( isPowerLine ( actor ) ) { mesh . setRotationFromQuaternion ( new Quaternion ( ) ) ; } else { mesh . setRotationFromQuaternion ( quat . multiply ( rotate90 ) ) ; } applyScale ( mesh , actor . transform . scale3d ) ; } export function applyMeshTransformToActor ( mesh , actor ) { Vue . set ( actor . transform . translation , 1 , mesh . position . x ) ; Vue . set ( actor . transform . translation , 0 , mesh . position . y ) ; Vue . set ( actor . transform . translation , 2 , mesh . position . z ) ; let quat ; if ( isSpline ( actor ) ) { quat = mesh . quaternion ; } else if ( isPowerLine ( actor ) ) { quat = new Quaternion ( ) ; } else { quat = mesh . quaternion . multiply ( rotateNeg90 ) ; } Vue . set ( actor . transform . rotation , 0 , - quat . y ) ; Vue . set ( actor . transform . rotation , 1 , - quat . x ) ; Vue . set ( actor . transform . rotation , 2 , - quat . z ) ; Vue . set ( actor . transform . rotation , 3 , quat . w ) ; Vue . set ( actor . transform . scale3d , 0 , mesh . scale . x ) ; Vue . set ( actor . transform . scale3d , 1 , mesh . scale . y ) ; Vue . set ( actor . transform . scale3d , 2 , mesh . scale . z ) ; }