Skip to content

Commit 4a775be

Browse files
committed
Pre/Post keyframe support
1 parent 596ad8e commit 4a775be

File tree

4 files changed

+43
-73
lines changed

4 files changed

+43
-73
lines changed

exporters/datapackExporter/exporter/datapackGen/animatedJavaFolderGen.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -375,8 +375,8 @@ export function generateAnimatedJavaFolder() {
375375
: `execute on passengers run data modify entity @s interpolation_duration set value 0`,
376376
`function ${G.AJ_NAMESPACE}:animations/${anim.name}/tree/leaf_0`,
377377
G.IS_SINGLE_ENTITY_RIG
378-
? `execute store result entity @s interpolation_duration int 1 run scoreboard players get $aj.default_interpolation_duration ${G.SCOREBOARD.i}`
379-
: `execute on passengers store result entity @s interpolation_duration int 1 run scoreboard players get $aj.default_interpolation_duration ${G.SCOREBOARD.i}`,
378+
? `data modify entity @s interpolation_duration set value 1`
379+
: `execute on passengers run data modify entity @s interpolation_duration set value 1`,
380380
`tag @s add ${formatStr(G.TAGS.activeAnim, [anim.name])}`,
381381
])
382382
// ANCHOR - func AJ_NAMESPACE:animations/${anim.name}/resume_as_root
@@ -385,8 +385,8 @@ export function generateAnimatedJavaFolder() {
385385
anim.name,
386386
])} ${G.LOOP_MODES.indexOf(anim.loopMode)}`,
387387
G.IS_SINGLE_ENTITY_RIG
388-
? `execute store result entity @s interpolation_duration int 1 run scoreboard players get $aj.default_interpolation_duration ${G.SCOREBOARD.i}`
389-
: `execute on passengers store result entity @s interpolation_duration int 1 run scoreboard players get $aj.default_interpolation_duration ${G.SCOREBOARD.i}`,
388+
? `data modify entity @s interpolation_duration set value 1`
389+
: `execute on passengers run data modify entity @s interpolation_duration set value 1`,
390390
`tag @s add ${formatStr(G.TAGS.activeAnim, [anim.name])}`,
391391
])
392392
// ANCHOR - func AJ_NAMESPACE:animations/${anim.name}/pause_as_root
@@ -463,10 +463,9 @@ export function generateAnimatedJavaFolder() {
463463
.chainNewFile('end.mcfunction', [
464464
`execute if score @s ${formatStr(G.SCOREBOARD.loopMode, [
465465
anim.name,
466-
])} = $aj.loop_mode.loop aj.i run scoreboard players set @s ${formatStr(
467-
G.SCOREBOARD.localAnimTime,
468-
[anim.name]
469-
)} 0`,
466+
])} = $aj.loop_mode.loop aj.i run function ${G.AJ_NAMESPACE}:animations/${
467+
anim.name
468+
}/end_loop`,
470469
`execute if score @s ${formatStr(G.SCOREBOARD.loopMode, [
471470
anim.name,
472471
])} = $aj.loop_mode.once aj.i run function ${G.NAMESPACE}:animations/${
@@ -478,6 +477,12 @@ export function generateAnimatedJavaFolder() {
478477
anim.name
479478
}/pause`,
480479
])
480+
// ANCHOR - func AJ_NAMESPACE:animations/${anim.name}/end_loop
481+
.chainNewFile('end_loop.mcfunction', [
482+
`scoreboard players set @s ${formatStr(G.SCOREBOARD.localAnimTime, [anim.name])} 0`,
483+
`scoreboard players set @s ${G.SCOREBOARD.animTime} 0`,
484+
`function ${G.AJ_NAMESPACE}:animations/${anim.name}/tree/leaf_0`,
485+
])
481486
// ANCHOR - func AJ_NAMESPACE:animations/${anim.name}/next_frame_as_root
482487
.chainNewFile('next_frame_as_root.mcfunction', [
483488
`function ${G.AJ_NAMESPACE}:animations/${anim.name}/tick_animation`,

exporters/datapackExporter/exporter/datapackGen/animationTreeGen.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,14 @@ export function loadAnimationTreeGenerator() {
2727
const data = new NbtCompound()
2828
.set('transformation', matrixToNbtFloatArray(node.matrix))
2929
.set('start_interpolation', new NbtInt(0))
30-
if (node.interpolation === 'instant') data.set('interpolation_duration', new NbtInt(0))
31-
else if (node.interpolation === 'default')
32-
// FIXME: This does not work if the default interpolation duration scoreboard is changed during runtime
30+
console.log(node.interpolation)
31+
if (node.interpolation === 'instant') {
32+
console.log('a')
33+
data.set('interpolation_duration', new NbtInt(0))
34+
} else if (node.interpolation === 'default') {
35+
console.log('b')
3336
data.set('interpolation_duration', new NbtInt(G.DEFAULT_INTERPOLATION_DURATION))
37+
}
3438
return `execute if entity @s[tag=${formatStr(G.TAGS.namedBoneEntity, [
3539
node.name,
3640
])}] run data modify entity @s {} merge value ${data}`
@@ -82,6 +86,9 @@ export function loadAnimationTreeGenerator() {
8286
commands.push(locatorToString(node))
8387
break
8488
}
89+
default: {
90+
throw new Error(`Unknown node type: ${node.type}`)
91+
}
8592
}
8693
}
8794
return commands

src/rendering/animationRenderer.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ function getNodeMatrix(node: OutlinerElement, scale: number) {
1717
const matrixWorld = node.mesh.matrixWorld.clone()
1818
matrixWorld.setPosition(
1919
new THREE.Vector3().setFromMatrixPosition(matrixWorld).multiplyScalar(1 / 16)
20-
// .multiply(new THREE.Vector3(-1, 1, -1))
2120
)
2221
matrixWorld.scale(new THREE.Vector3().setScalar(scale))
2322
return matrixWorld
@@ -97,8 +96,8 @@ export function getAnimationNodes(
9796
const animator = animation.animators[node.node.uuid]!
9897
if (
9998
animator?.keyframes
100-
.filter(k => k.time === time)
101-
.find(k => k.interpolation === 'step')
99+
.filter(k => k.time === time - 0.05)
100+
.find(k => k.data_points.length === 2)
102101
) {
103102
interpolation = 'instant'
104103
} else if (previousFrame[uuid]?.interpolation === 'instant') {

test_ajmodels/test_project.ajmodel

Lines changed: 18 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -78,19 +78,6 @@
7878
"height": 64
7979
},
8080
"elements": [
81-
{
82-
"name": "pig",
83-
"position": [0, 0, 0],
84-
"rotation": [0, 0, 0],
85-
"ignore_inherited_scale": false,
86-
"visibility": true,
87-
"locked": false,
88-
"modelPath": "",
89-
"entity_type": "minecraft:pig",
90-
"nbt": "{deathLootTable:\"minecraft:entities/bat\"}",
91-
"uuid": "e74b221b-1dd5-a96d-98b8-e2ba36335e13",
92-
"type": "locator"
93-
},
9481
{
9582
"name": "cube",
9683
"box_uv": false,
@@ -129,19 +116,6 @@
129116
},
130117
"type": "cube",
131118
"uuid": "29c15edc-aea1-917e-1210-69c6c9468111"
132-
},
133-
{
134-
"name": "armor_stand_cam",
135-
"path": "",
136-
"position": [0, 64, 0],
137-
"rotation": [0, 0, 0],
138-
"linked_preview": "",
139-
"camera_linked": false,
140-
"visibility": true,
141-
"entity_type": "minecraft:armor_stand",
142-
"nbt": "{}",
143-
"type": "camera",
144-
"uuid": "270ad0fb-c9b7-9fc3-0b93-24e492570533"
145119
}
146120
],
147121
"outliner": [
@@ -157,21 +131,7 @@
157131
"locked": false,
158132
"visibility": true,
159133
"autouv": 0,
160-
"children": ["29c15edc-aea1-917e-1210-69c6c9468111", "270ad0fb-c9b7-9fc3-0b93-24e492570533"]
161-
},
162-
{
163-
"name": "pig",
164-
"origin": [0, 0, 0],
165-
"color": 0,
166-
"nbt": "{}",
167-
"uuid": "9ab6586b-0f27-bd36-c585-4584cdf05d05",
168-
"export": true,
169-
"mirror_uv": false,
170-
"isOpen": true,
171-
"locked": false,
172-
"visibility": true,
173-
"autouv": 0,
174-
"children": ["e74b221b-1dd5-a96d-98b8-e2ba36335e13"]
134+
"children": ["29c15edc-aea1-917e-1210-69c6c9468111"]
175135
}
176136
],
177137
"textures": [
@@ -239,7 +199,7 @@
239199
"name": "test",
240200
"loop": "loop",
241201
"override": false,
242-
"length": 4,
202+
"length": 1,
243203
"snapping": 20,
244204
"selected": true,
245205
"anim_time_update": "",
@@ -254,15 +214,20 @@
254214
"type": "bone",
255215
"keyframes": [
256216
{
257-
"channel": "rotation",
217+
"channel": "position",
258218
"data_points": [
259219
{
260-
"x": "0",
261-
"y": "time * 180",
262-
"z": "22.5 + math.sin(q.life_time * 90) * 22.5"
220+
"x": -16,
221+
"y": "0",
222+
"z": "0"
223+
},
224+
{
225+
"x": "16",
226+
"y": "0",
227+
"z": "0"
263228
}
264229
],
265-
"uuid": "7526a6bf-4eb0-103b-e2b4-30a4dfe0eb06",
230+
"uuid": "5a584adb-bb2f-e98c-f064-6ec08cf2eebd",
266231
"time": 0,
267232
"color": -1,
268233
"interpolation": "linear",
@@ -271,24 +236,18 @@
271236
"bezier_left_value": [0, 0, 0],
272237
"bezier_right_time": [0.1, 0.1, 0.1],
273238
"bezier_right_value": [0, 0, 0]
274-
}
275-
]
276-
},
277-
"9ab6586b-0f27-bd36-c585-4584cdf05d05": {
278-
"name": "pig",
279-
"type": "bone",
280-
"keyframes": [
239+
},
281240
{
282241
"channel": "position",
283242
"data_points": [
284243
{
285-
"x": "math.sin(time * 90) * 100",
286-
"y": "16",
287-
"z": "math.cos(time * 90) * 100"
244+
"x": -16,
245+
"y": 0,
246+
"z": 0
288247
}
289248
],
290-
"uuid": "67370c85-298c-e771-dc13-411c5ca88cec",
291-
"time": 0,
249+
"uuid": "7920351c-ed3d-ca1f-532c-52c86c120329",
250+
"time": 1,
292251
"color": -1,
293252
"interpolation": "linear",
294253
"bezier_linked": true,

0 commit comments

Comments
 (0)