Skip to content

Commit 018030d

Browse files
committed
Merge branch 'experimental' of https://github.com/Animated-Java/animated-java
2 parents cae2156 + fa082bd commit 018030d

File tree

23 files changed

+2477
-1301
lines changed

23 files changed

+2477
-1301
lines changed

debug models/train_with_states.ajmodel

Lines changed: 20 additions & 15 deletions
Large diffs are not rendered by default.

debug_resourcepack/armor_stand.ajmodel

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
11
{
22
"meta": {
33
"format_version": "0.0",
4-
"creation_time": 1641650938,
4+
"creation_time": 1641769747,
55
"model_format": "animated_java/ajmodel",
66
"box_uv": false,
77
"settings": {
88
"animatedJava": {
99
"projectName": "armor_stand",
10-
"exporter": "animationExporter",
11-
"verbose": false,
10+
"exporter": "vanillaAnimationExporter",
11+
"verbose": true,
1212
"rigItem": "minecraft:leather_horse_armor",
1313
"rigModelsExportFolder": "C:\\Users\\Snave\\AppData\\Roaming\\.minecraft\\resourcepacks\\Animated Java Testing\\assets\\animated_java\\models\\rigs\\armor_stand",
1414
"predicateFilePath": "C:\\Users\\Snave\\AppData\\Roaming\\.minecraft\\resourcepacks\\Animated Java Testing\\assets\\minecraft\\models\\item\\leather_horse_armor.json",
1515
"transparentTexturePath": "C:\\Users\\Snave\\AppData\\Roaming\\.minecraft\\resourcepacks\\Animated Java Testing\\assets\\minecraft\\textures\\transparent.png"
1616
},
17-
"animatedJava_exporter_statueExporter": {
17+
"vanillaStatueExporter": {
1818
"rootEntityType": "minecraft:marker",
1919
"rootEntityNbt": "{}",
2020
"markerArmorStands": true,
2121
"modelTag": "aj.%projectName",
2222
"rootTag": "aj.%projectName.root",
2323
"allBonesTag": "aj.%projectName.bone",
24+
"boneModelDisplayTag": "aj.%projectName.bone_display",
2425
"individualBoneTag": "aj.%projectName.bone.%boneName",
2526
"internalScoreboardObjective": "aj.i",
2627
"idScoreboardObjective": "aj.id",
@@ -29,7 +30,7 @@
2930
"mcbConfigPath": "",
3031
"dataPackPath": ""
3132
},
32-
"animatedJava_exporter_animationExporter": {
33+
"vanillaAnimationExporter": {
3334
"rootEntityType": "minecraft:marker",
3435
"rootEntityNbt": "{}",
3536
"markerArmorStands": false,
@@ -49,7 +50,7 @@
4950
"exportMode": "mcb",
5051
"mcbFilePath": "C:\\Users\\Snave\\AppData\\Roaming\\.minecraft\\saves\\Animated Java Dev\\datapacks\\Animated Java Development\\src\\armor_stand.mc",
5152
"mcbConfigPath": "",
52-
"dataPackPath": "C:\\Users\\Snave\\AppData\\Roaming\\.minecraft\\saves\\Animated Java Dev\\datapacks\\armor_stand"
53+
"dataPackPath": ""
5354
}
5455
},
5556
"variants": {
@@ -71,6 +72,10 @@
7172
"all_green": {
7273
"9aa33630-8f09-269e-1ff8-4006c170cc10": "f422a623-6d8c-1bd1-4da1-c61940601aaf",
7374
"29f44b0b-5027-de28-9958-e95a32a0cf4c": "transparent"
75+
},
76+
"no_head": {
77+
"29f44b0b-5027-de28-9958-e95a32a0cf4c": "transparent",
78+
"dfa38dd5-689f-f447-7d28-63645345c25d": "transparent"
7479
}
7580
},
7681
"uuid": "6315712c-d94e-91d8-dc54-eb2877b25239"
@@ -947,6 +952,7 @@
947952
],
948953
"autouv": 0,
949954
"color": 1,
955+
"visibility": false,
950956
"rotation": [
951957
-45,
952958
0,

src/animatedJava.ts

Lines changed: 53 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,34 @@
11
import events from './constants/events'
22
import { BuildModel } from './mainEntry'
3-
import { settings } from './settings'
43
import { store } from './util/store'
54
import { bus } from './util/bus'
65
import './bbmods/patchAction'
76
import { format as modelFormat } from './modelFormat'
87
import { tl } from './util/intl'
8+
import { settings } from './settings'
99
import { registerSettingRenderer } from './ui/dialogs/settings'
1010
import './ui/mods/boneConfig'
1111
import './compileLangMC'
1212
import './exporters/statueExporter'
1313
import './exporters/animationExporter'
1414
import './bbmods/modelFormatMod'
1515
import './bbmods/faceTint'
16+
import './util/minecraft/items'
17+
import './util/minecraft/entities'
1618
import { intl } from './util/intl'
1719
import { CustomError } from './util/customError'
18-
import { format } from './util/replace'
20+
21+
const errorMessages = [
22+
'Uh oh!',
23+
"Time to fire up the ol' debugger!",
24+
'Your armor stands are sad :(',
25+
'Ok, who pushed the big red button?',
26+
]
27+
28+
function getRandomErrorMessage() {
29+
const index = Math.round(Math.random() * (errorMessages.length - 1))
30+
return errorMessages[index]
31+
}
1932

2033
function showUnknownErrorDialog(e: CustomError | any) {
2134
// console.log(e.options)
@@ -26,16 +39,23 @@ function showUnknownErrorDialog(e: CustomError | any) {
2639
new Dialog(
2740
Object.assign(
2841
{
29-
id: 'animatedJava.dialog.miscError',
30-
title: tl('animatedJava.dialog.miscError.title'),
42+
id: 'animatedJava.dialogs.miscError',
43+
title: tl('animatedJava.dialogs.errors.misc.title'),
3144
lines: [
32-
format(tl('animatedJava.dialog.miscError.body'), {
33-
buildID: process.env.BUILD_ID,
34-
errorMessage: e.options ? e.options.message : e.message,
35-
errorStack: e.stack,
36-
discordLink: process.env.DISCORD_LINK,
37-
githubLink: process.env.GITHUB_ISSUES_LINK,
38-
}),
45+
tl(
46+
'animatedJava.dialogs.errors.misc.body',
47+
{
48+
buildID: process.env.BUILD_ID,
49+
errorMessage: e.options
50+
? e.options.message
51+
: e.message,
52+
randomErrorMessage: getRandomErrorMessage(),
53+
errorStack: e.stack,
54+
discordLink: process.env.DISCORD_LINK,
55+
githubLink: process.env.GITHUB_ISSUES_LINK,
56+
},
57+
true
58+
),
3959
],
4060
width: 1024,
4161
height: 512,
@@ -103,19 +123,29 @@ Blockbench.events['animated-java-ready'].length = 0
103123

104124
// WOOO TYPING, YAAAAAAY
105125

126+
export interface SettingDescriptor {
127+
readonly value: any
128+
error?: string
129+
isValid?: boolean
130+
setting: any
131+
event: 'get' | 'set' | 'update' | 'dummy'
132+
}
133+
106134
export interface Settings {
107-
animatedJava: {
108-
projectName: string
109-
exporter: string
110-
useCache: boolean
111-
cacheMode: 'memory' | 'disk'
112-
rigItem: string
113-
predicateFilePath: string
114-
rigModelsExportFolder: string
115-
transparentTexturePath: string
116-
boundingBoxRenderMode: 'single' | 'multiple' | 'disabled'
117-
verbose: boolean
118-
}
135+
projectName: string
136+
exporter: string
137+
useCache: boolean
138+
cacheMode: 'memory' | 'disk'
139+
rigItem: string
140+
predicateFilePath: string
141+
rigModelsExportFolder: string
142+
transparentTexturePath: string
143+
boundingBoxRenderMode: 'single' | 'multiple' | 'disabled'
144+
verbose: boolean
145+
}
146+
147+
export interface GlobalSettings {
148+
animatedJava: Settings
119149
[index: string]: any
120150
}
121151

src/animationRenderer.js

Lines changed: 45 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { settings } from './settings'
33
import { Async } from './util/async'
44
import { bus } from './util/bus'
55
import { roundToN } from './util/misc'
6-
import { hashAnim } from './util/hashAnim'
6+
import * as hash from './util/hash'
77
import { store } from './util/store'
88
import * as os from 'os'
99
import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'fs'
@@ -14,7 +14,7 @@ import { tl } from './util/intl'
1414
import { format, safeFunctionName } from './util/replace'
1515
import { isSceneBased } from './util/hasSceneAsParent'
1616
import { 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

1919
function 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+
233235
async 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

Comments
 (0)