Skip to content

Commit 9aee894

Browse files
committed
🚧 Fix some locator rotation issues
1 parent 3ed4098 commit 9aee894

File tree

3 files changed

+74
-16
lines changed

3 files changed

+74
-16
lines changed

src/systems/animationRenderer.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ function getDecomposedTransformation(matrix: THREE.Matrix4) {
4848
return { translation, left_rotation, scale }
4949
}
5050

51+
function threeAxisRotationToTwoAxisRotation(rot: THREE.Quaternion): ArrayVector2 {
52+
const euler = Reusable.vec3.applyQuaternion(rot)
53+
const yaw = Math.atan2(euler.z, euler.x)
54+
const pitch = Math.atan2(euler.y, euler.z)
55+
return [Math.radToDeg(yaw), Math.radToDeg(pitch)]
56+
}
57+
5158
export interface IAnimationNode {
5259
type: 'bone' | 'camera' | 'locator' | 'text_display' | 'item_display' | 'block_display'
5360
name: string
@@ -61,6 +68,8 @@ export interface IAnimationNode {
6168
}
6269
pos: ArrayVector3
6370
rot: ArrayVector3
71+
// The two-axis (entity head) rotation of the node.
72+
head_rot: ArrayVector2
6473
scale: ArrayVector3
6574
interpolation?: 'step' | 'pre-post'
6675
/**
@@ -214,6 +223,7 @@ export function getAnimationNodes(
214223
transformation: decomposed,
215224
pos: [pos.x, pos.y, pos.z],
216225
rot: eulerFromQuaternion(rot).toArray(),
226+
head_rot: threeAxisRotationToTwoAxisRotation(rot),
217227
scale: [scale.x, scale.y, scale.z],
218228
interpolation,
219229
commands,

src/systems/datapackCompiler/animation.mcb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -410,8 +410,8 @@ dir <%export_namespace%> {
410410
^<%roundTo(node.pos[1], 10)%> \
411411
^<%roundTo(node.pos[2], 10)%> \
412412
rotated \
413-
~<%roundTo(node.rot[0], 10)%> \
414-
~<%roundTo(node.rot[1], 10)%> \
413+
~<%roundTo(node.head_rot[0], 10)%> \
414+
~<%roundTo(node.head_rot[1], 10)%> \
415415
run {
416416
<%%
417417
emit.mcb(node.commands)
@@ -425,8 +425,8 @@ dir <%export_namespace%> {
425425
posx: node.pos[0],
426426
posy: node.pos[1],
427427
posz: node.pos[2],
428-
rotx: node.rot[0],
429-
roty: node.rot[1]
428+
rotx: node.head_rot[0],
429+
roty: node.head_rot[1]
430430
}
431431
%%>
432432
}

test_blueprints/armor_stand.ajblueprint

Lines changed: 60 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"meta": {
33
"format": "animated_java_blueprint",
4-
"format_version": "0.5.10",
4+
"format_version": "1.0.0",
55
"uuid": "167b27cd-b559-3f13-a97c-0841fe21f1d1",
66
"save_location": "D:\\github-repos\\animated-java\\animated-java\\test_blueprints\\armor_stand.ajblueprint",
77
"last_used_export_namespace": "armor_stand"
@@ -826,7 +826,8 @@
826826
"config": {
827827
"use_entity": false,
828828
"entity_type": "minecraft:pig",
829-
"ticking_commands": "particle minecraft:bubble ~ ~ ~"
829+
"summon_commands": "",
830+
"ticking_commands": "particle minecraft:bubble ^ ^ ^1\ntp @e[tag=test3,limit=1] ~ ~ ~ ~ ~"
830831
},
831832
"uuid": "7de415a2-9fdd-e4b2-3455-c3bed72eb896",
832833
"type": "locator"
@@ -839,7 +840,10 @@
839840
"visibility": true,
840841
"locked": false,
841842
"config": {
842-
"ticking_commands": "particle minecraft:bubble ~ ~ ~"
843+
"use_entity": false,
844+
"entity_type": "minecraft:pig",
845+
"summon_commands": "",
846+
"ticking_commands": "particle minecraft:bubble ^ ^ ^1\ntp @e[tag=test2,limit=1] ~ ~ ~ ~ ~"
843847
},
844848
"uuid": "7747736f-85e2-338f-207e-53f8d3d2fa39",
845849
"type": "locator"
@@ -1381,7 +1385,7 @@
13811385
"uuid": "215d1b02-0e64-a794-1b88-a9c5a6d7541c",
13821386
"export": true,
13831387
"mirror_uv": false,
1384-
"isOpen": false,
1388+
"isOpen": true,
13851389
"locked": false,
13861390
"visibility": true,
13871391
"autouv": 0,
@@ -1795,7 +1799,7 @@
17951799
"x": 0,
17961800
"y": 0,
17971801
"z": 0,
1798-
"commands": "particle minecraft:flame ~ ~ ~",
1802+
"commands": "tp @e[tag=test,limit=1] ~ ~ ~ ~ ~",
17991803
"execute_condition": "",
18001804
"repeat": true,
18011805
"repeat_frequency": 1
@@ -4110,11 +4114,11 @@
41104114
}
41114115
},
41124116
{
4113-
"uuid": "e7761616-704f-309f-9b63-ded7c7449f4c",
4114-
"name": "long",
4117+
"uuid": "d7aa15ae-b3c0-6aee-e91c-630ca1fcb825",
4118+
"name": "locator_test",
41154119
"loop": "loop",
41164120
"override": false,
4117-
"length": 50,
4121+
"length": 2,
41184122
"snapping": 20,
41194123
"selected": true,
41204124
"saved": false,
@@ -4125,20 +4129,64 @@
41254129
"loop_delay": "0",
41264130
"excluded_nodes": [],
41274131
"animators": {
4128-
"98795982-9c43-6e3e-eed9-2c776a957938": {
4129-
"name": "root",
4132+
"b5b52d2c-097c-08df-6457-372fbae12445": {
4133+
"name": "left_arm",
4134+
"type": "bone",
4135+
"keyframes": [
4136+
{
4137+
"channel": "rotation",
4138+
"data_points": [
4139+
{
4140+
"x": "q.life_time * 180",
4141+
"y": "0",
4142+
"z": "0"
4143+
}
4144+
],
4145+
"uuid": "4a42399c-2453-77e4-1cb9-6403032576a0",
4146+
"time": 0,
4147+
"color": -1,
4148+
"interpolation": "linear",
4149+
"easing": "linear",
4150+
"easingArgs": []
4151+
}
4152+
]
4153+
},
4154+
"215d1b02-0e64-a794-1b88-a9c5a6d7541c": {
4155+
"name": "right_arm",
41304156
"type": "bone",
41314157
"keyframes": [
41324158
{
41334159
"channel": "rotation",
41344160
"data_points": [
41354161
{
41364162
"x": "0",
4137-
"y": "q.life_time * 12.25",
4163+
"y": "q.life_time * 180\n",
41384164
"z": "0"
41394165
}
41404166
],
4141-
"uuid": "387d8220-6ad2-3866-0630-b9f7acc501b6",
4167+
"uuid": "0a15d863-02b8-eb01-0e46-7da15d8306d7",
4168+
"time": 0,
4169+
"color": -1,
4170+
"interpolation": "linear",
4171+
"easing": "linear",
4172+
"easingArgs": []
4173+
}
4174+
]
4175+
},
4176+
"3b35d1a9-befe-066e-60df-e1f3a5ec5a78": {
4177+
"name": "pig",
4178+
"type": "bone",
4179+
"keyframes": [
4180+
{
4181+
"channel": "rotation",
4182+
"data_points": [
4183+
{
4184+
"x": "0",
4185+
"y": "math.cos(q.life_time * 180) * 45\n",
4186+
"z": "math.sin(q.life_time * 180) * 45\n"
4187+
}
4188+
],
4189+
"uuid": "74a92a15-fd3d-6e21-564a-8fd79cebda34",
41424190
"time": 0,
41434191
"color": -1,
41444192
"interpolation": "linear",

0 commit comments

Comments
 (0)