@@ -3,7 +3,7 @@ import { settings } from './settings'
33import { Async } from './util/async'
44import { bus } from './util/bus'
55import { roundToN } from './util/misc'
6- import { hashAnim } from './util/hashAnim '
6+ import * as hash from './util/hash '
77import { store } from './util/store'
88import * as os from 'os'
99import { existsSync , mkdirSync , readFileSync , rmSync , writeFileSync } from 'fs'
@@ -14,7 +14,7 @@ import { tl } from './util/intl'
1414import { format , safeFunctionName } from './util/replace'
1515import { isSceneBased } from './util/hasSceneAsParent'
1616import { CustomError } from './util/customError'
17- store . set ( 'static_animation_uuid ' , '138747e7-2de0-4130-b900-9275ca0e6333' )
17+ store . set ( 'staticAnimationUuid ' , '138747e7-2de0-4130-b900-9275ca0e6333' )
1818
1919function setAnimatorTime ( time ) {
2020 Timeline . setTime ( time , false )
@@ -109,7 +109,7 @@ function getData(animation, renderedGroups) {
109109 y : - thisRot [ 1 ] ,
110110 z : thisRot [ 2 ] ,
111111 } ,
112- scale : scl [ groupName ] ,
112+ scale : scl [ group . name ] ,
113113 }
114114 } )
115115 return res
@@ -127,7 +127,7 @@ const struct = StructTypes.Object({
127127 StructTypes . String ,
128128 StructTypes . Object ( {
129129 pos : vec3 ,
130- rot : StructTypes . ArrayOf ( StructTypes . Float ) ,
130+ rot : vec3 ,
131131 scale : vec3 ,
132132 } )
133133 ) ,
@@ -159,7 +159,7 @@ const Cache = new (class {
159159 settings . watch ( 'animatedJava.cacheMode' , ( ) => {
160160 this . initDiskCache ( )
161161 } )
162- settings . watch ( 'animatedJava.use_cache ' , ( ) => {
162+ settings . watch ( 'animatedJava.useCache ' , ( ) => {
163163 this . clear ( )
164164 } )
165165 this . initDiskCache ( )
@@ -182,7 +182,7 @@ const Cache = new (class {
182182 if ( ! settings . animatedJava . useCache ) return null
183183 if ( this . cache . has ( anim . uuid ) ) {
184184 const old_hash = this . cache . get ( anim . uuid )
185- const new_hash = hashAnim ( anim )
185+ const new_hash = hash . animation ( anim )
186186 const hit = old_hash !== new_hash
187187 if ( ! hit ) {
188188 if ( settings . animatedJava . cacheMode === 'memory' ) {
@@ -198,8 +198,7 @@ const Cache = new (class {
198198 }
199199 return null
200200 } else {
201- const hash = hashAnim ( anim )
202- this . cache . set ( anim . uuid , hash )
201+ this . cache . set ( anim . uuid , hash . animation ( anim ) )
203202 return null
204203 }
205204 }
@@ -213,7 +212,7 @@ const Cache = new (class {
213212 animToWriteable ( value )
214213 )
215214 }
216- this . cache . set ( anim . uuid , hashAnim ( anim ) )
215+ this . cache . set ( anim . uuid , hash . animation ( anim ) )
217216 }
218217 clear ( ) {
219218 this . data = new Map ( )
@@ -222,14 +221,17 @@ const Cache = new (class {
222221} ) ( )
223222
224223// clear the animation cache if the origin or rotation of a group changes
225- const $original_func = NodePreviewController . prototype . updateTransform
226- NodePreviewController . prototype . updateTransform = function ( el ) {
227- if ( Group . selected ) Cache . clear ( )
228- return $original_func . bind ( this ) ( el )
229- }
230- bus . on ( events . LIFECYCLE . CLEANUP , ( ) => {
231- NodePreviewController . prototype . updateTransform = $original_func
232- } )
224+ // const $original_func = NodePreviewController.prototype.updateTransform
225+ // NodePreviewController.prototype.updateTransform = function (el) {
226+ // if (Group.selected) Cache.clear()
227+ // return $original_func.bind(this)(el)
228+ // }
229+ // bus.on(events.LIFECYCLE.CLEANUP, () => {
230+ // NodePreviewController.prototype.updateTransform = $original_func
231+ // })
232+
233+ let boneStructureHash
234+
233235async function renderAnimation ( options ) {
234236 console . groupCollapsed ( 'Render Animations' )
235237 // const timeline_save = get_timeline_save_point();
@@ -240,11 +242,11 @@ async function renderAnimation(options) {
240242
241243 if ( options . generate_static_animation ) {
242244 static_animation = new Animation ( {
243- name : 'animatedJava.static_animation ' ,
245+ name : 'animatedJava.staticSnimation ' ,
244246 snapping : 20 ,
245247 length : 0 ,
246248 } ) . add ( false )
247- static_animation . uuid = store . get ( 'static_animation_uuid ' )
249+ static_animation . uuid = store . get ( 'staticAnimationUuid ' )
248250 }
249251
250252 const totalAnimationLength = Animator . animations . reduce (
@@ -253,7 +255,7 @@ async function renderAnimation(options) {
253255 )
254256 // Accumulated animation length
255257 let accAnimationLength = 0
256- const tldMessage = tl ( 'animatedJava.progress.animationRendering.text ' )
258+ const tldMessage = tl ( 'animatedJava.progress.animationRendering' )
257259 const progressUpdaterID = setInterval ( ( ) => {
258260 console . log ( accAnimationLength , totalAnimationLength )
259261 Blockbench . setStatusBarText (
@@ -271,31 +273,38 @@ async function renderAnimation(options) {
271273 const renderedGroups = Group . all . filter (
272274 ( group ) =>
273275 ! isSceneBased ( group ) &&
276+ group . visibility &&
274277 group . children . find ( ( child ) => child instanceof Cube )
275278 )
276279 console . log ( 'All Groups:' , Group . all )
277280 console . log ( 'Rendered Groups:' , renderedGroups )
278281
282+ const newBoneStructureHash = hash . boneStructure ( )
283+ if ( boneStructureHash !== newBoneStructureHash ) {
284+ boneStructureHash = newBoneStructureHash
285+ Cache . clear ( )
286+ }
287+
279288 for ( const animation of Animator . animations . sort ( ) ) {
280289 if ( animation . snapping != 20 ) {
281290 throw new CustomError ( 'Invalid Snapping Value Error' , {
282291 intentional : true ,
283292 dialog : {
284- id : 'animatedJava_exporter_animationExporter.popup.warning.invalidSnappingValue ' ,
293+ id : 'animatedJava.invalidAnimationSnappingValue ' ,
285294 title : tl (
286- 'animatedJava_exporter_animationExporter.popup.warning.invalidSnappingValue .title'
295+ 'animatedJava.dialogs.errors.invalidAnimationSnappingValue .title'
287296 ) ,
288- lines : format (
297+ lines : [
289298 tl (
290- 'animatedJava_exporter_animationExporter.popup.warning.invalidSnappingValue.body'
299+ 'animatedJava.dialogs.errors.invalidAnimationSnappingValue.body' ,
300+ {
301+ animationName : animation . name ,
302+ snapping : animation . snapping ,
303+ }
291304 ) ,
292- {
293- animationName : animation . name ,
294- snapping : animation . snapping
295- }
296- )
297- . split ( '\n' )
298- . map ( ( line ) => `<p>${ line } </p>` ) ,
305+ ] ,
306+ width : 512 + 256 ,
307+ singleButton : true ,
299308 } ,
300309 } )
301310 }
@@ -305,8 +314,12 @@ async function renderAnimation(options) {
305314 let maxDistance = - Infinity
306315 const frames = [ ]
307316 animation . select ( )
317+ const animLength =
318+ animation . loop === 'loop'
319+ ? animation . length
320+ : animation . length + 0.05
308321
309- for ( let i = 0 ; i <= animation . length ; i += 0.05 ) {
322+ for ( let i = 0 ; i <= animLength ; i += 0.05 ) {
310323 accAnimationLength += 0.05
311324 await Async . wait_if_overflow ( )
312325 setAnimatorTime ( i )
0 commit comments