@@ -9,7 +9,7 @@ import { TextDisplay } from '../outliner/textDisplay'
99import { VanillaBlockDisplay } from '../outliner/vanillaBlockDisplay'
1010import { VanillaItemDisplay } from '../outliner/vanillaItemDisplay'
1111import { toSafeFuntionName } from '../util/minecraftUtil'
12- import { roundToNth } from '../util/misc'
12+ import { eulerFromQuaternion , roundToNth } from '../util/misc'
1313import { AnyRenderedNode , IRenderedRig } from './rigRenderer'
1414import * as crypto from 'crypto'
1515
@@ -29,10 +29,6 @@ function getNodeMatrix(node: OutlinerElement, scale: number) {
2929 matrixWorld . setPosition ( pos )
3030
3131 const scaleVec = new THREE . Vector3 ( ) . setScalar ( scale )
32- // Hacky way to force the matrix to update in-game
33- // scaleVec.x += Math.random() * 0.00001
34- // scaleVec.y += Math.random() * 0.00001
35- // scaleVec.z += Math.random() * 0.00001
3632 matrixWorld . scale ( scaleVec )
3733
3834 if ( node instanceof TextDisplay ) {
@@ -44,15 +40,28 @@ function getNodeMatrix(node: OutlinerElement, scale: number) {
4440 return matrixWorld
4541}
4642
43+ function getDecomposedTransformation ( matrix : THREE . Matrix4 ) {
44+ const translation = new THREE . Vector3 ( )
45+ const left_rotation = new THREE . Quaternion ( )
46+ const scale = new THREE . Vector3 ( )
47+ matrix . decompose ( translation , left_rotation , scale )
48+ return { translation, left_rotation, scale }
49+ }
50+
4751export interface IAnimationNode {
4852 type : 'bone' | 'camera' | 'locator' | 'text_display' | 'item_display' | 'block_display'
4953 name : string
5054 uuid : string
5155 node ?: Group | NullObject | Locator | OutlinerElement | TextDisplay
5256 matrix : THREE . Matrix4
53- pos : THREE . Vector3
54- rot : THREE . Quaternion
55- scale : THREE . Vector3
57+ transformation : {
58+ translation : THREE . Vector3
59+ left_rotation : THREE . Quaternion
60+ scale : THREE . Vector3
61+ }
62+ pos : ArrayVector3
63+ rot : ArrayVector3
64+ scale : ArrayVector3
5665 interpolation ?: 'step' | 'pre-post'
5766 /**
5867 * Commands is only set for locator nodes
@@ -190,16 +199,18 @@ export function getAnimationNodes(
190199 const rot = new THREE . Quaternion ( )
191200 const scale = new THREE . Vector3 ( )
192201 matrix . decompose ( pos , rot , scale )
202+ const decomposed = getDecomposedTransformation ( matrix )
193203
194204 nodes . push ( {
195205 type : node . type ,
196206 name : node . name ,
197207 uuid,
198208 node : node . node ,
199209 matrix,
200- pos,
201- rot,
202- scale,
210+ transformation : decomposed ,
211+ pos : [ pos . x , pos . y , pos . z ] ,
212+ rot : eulerFromQuaternion ( rot ) . toArray ( ) ,
213+ scale : [ scale . x , scale . y , scale . z ] ,
203214 interpolation,
204215 commands,
205216 execute_condition : executeCondition ,
@@ -291,9 +302,9 @@ export function hashAnimations(animations: IRenderedAnimation[]) {
291302 hash . update ( ';' + frame . time . toString ( ) )
292303 for ( const node of frame . nodes ) {
293304 hash . update ( ';' + node . uuid )
294- hash . update ( ';' + node . pos . toArray ( ) . join ( ';' ) )
295- hash . update ( ';' + node . rot . toArray ( ) . join ( ';' ) )
296- hash . update ( ';' + node . scale . toArray ( ) . join ( ';' ) )
305+ hash . update ( ';' + node . pos . join ( ';' ) )
306+ hash . update ( ';' + node . rot . join ( ';' ) )
307+ hash . update ( ';' + node . scale . join ( ';' ) )
297308 node . interpolation && hash . update ( ';' + node . interpolation )
298309 if ( node . commands ) hash . update ( ';' + node . commands )
299310 if ( node . execute_condition ) hash . update ( ';' + node . execute_condition )
0 commit comments