Skip to content

Commit 7288b92

Browse files
SnaveSutitgitbutler-client
authored andcommitted
✨ Update plugin compiler to support modern element rotation format
1 parent 6117993 commit 7288b92

3 files changed

Lines changed: 148 additions & 25 deletions

File tree

schemas/example-plugin-blueprint.json

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,96 @@
9696
}
9797
},
9898
"display_rotation": [90.0, 20.0, 0.0]
99+
},
100+
{
101+
"from": [0.0, 0.0, 0.0],
102+
"to": [1.0, 1.0, 1.0],
103+
"rotation": {
104+
"x": 0,
105+
"y": 0,
106+
"z": 0,
107+
"origin": [0, 0, 0],
108+
"rescale": false
109+
},
110+
"faces": {
111+
"north": {
112+
"uv": [0, 0, 16, 16],
113+
"texture_provider": { "type": "texture", "texture": "custom_texture" }
114+
},
115+
"east": {
116+
"uv": [0, 0, 16, 16],
117+
"texture_provider": {
118+
"type": "texture",
119+
"texture": "reference_texture"
120+
}
121+
},
122+
"south": {
123+
"uv": [0, 0, 16, 16],
124+
"texture_provider": { "type": "texture", "texture": "custom_texture" },
125+
"rotation": 90
126+
},
127+
"west": {
128+
"uv": [0, 0, 16, 16],
129+
"texture_provider": {
130+
"type": "texture",
131+
"texture": "reference_texture"
132+
}
133+
},
134+
"up": {
135+
"uv": [0, 0, 16, 16],
136+
"texture_provider": { "type": "texture", "texture": "custom_texture" }
137+
},
138+
"down": {
139+
"uv": [0, 0, 16, 16],
140+
"texture_provider": {
141+
"type": "texture_palette",
142+
"texture_palette": "default_palette"
143+
}
144+
}
145+
},
146+
"display_rotation": [90.0, 20.0, 0.0]
147+
},
148+
{
149+
"from": [0.0, 0.0, 0.0],
150+
"to": [1.0, 1.0, 1.0],
151+
"rotation": [0, 0, 0],
152+
"faces": {
153+
"north": {
154+
"uv": [0, 0, 16, 16],
155+
"texture_provider": { "type": "texture", "texture": "custom_texture" }
156+
},
157+
"east": {
158+
"uv": [0, 0, 16, 16],
159+
"texture_provider": {
160+
"type": "texture",
161+
"texture": "reference_texture"
162+
}
163+
},
164+
"south": {
165+
"uv": [0, 0, 16, 16],
166+
"texture_provider": { "type": "texture", "texture": "custom_texture" },
167+
"rotation": 90
168+
},
169+
"west": {
170+
"uv": [0, 0, 16, 16],
171+
"texture_provider": {
172+
"type": "texture",
173+
"texture": "reference_texture"
174+
}
175+
},
176+
"up": {
177+
"uv": [0, 0, 16, 16],
178+
"texture_provider": { "type": "texture", "texture": "custom_texture" }
179+
},
180+
"down": {
181+
"uv": [0, 0, 16, 16],
182+
"texture_provider": {
183+
"type": "texture_palette",
184+
"texture_palette": "default_palette"
185+
}
186+
}
187+
},
188+
"display_rotation": [90.0, 20.0, 0.0]
99189
}
100190
]
101191
},

schemas/plugin-blueprint.schema.json

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -319,20 +319,49 @@
319319
"$ref": "#/definitions/vector3"
320320
},
321321
"rotation": {
322-
"type": "object",
323-
"required": ["angle", "axis", "origin"],
324-
"properties": {
325-
"angle": {
326-
"type": "number"
322+
"oneOf": [
323+
{
324+
"type": "object",
325+
"required": ["angle", "axis", "origin"],
326+
"properties": {
327+
"angle": {
328+
"type": "number"
329+
},
330+
"axis": {
331+
"type": "string",
332+
"enum": ["x", "y", "z"]
333+
},
334+
"origin": {
335+
"$ref": "#/definitions/vector3"
336+
}
337+
}
327338
},
328-
"axis": {
329-
"type": "string",
330-
"enum": ["x", "y", "z"]
339+
{
340+
"type": "object",
341+
"required": ["x", "y", "z", "origin"],
342+
"properties": {
343+
"x": {
344+
"type": "number"
345+
},
346+
"y": {
347+
"type": "number"
348+
},
349+
"z": {
350+
"type": "number"
351+
},
352+
"origin": {
353+
"$ref": "#/definitions/vector3"
354+
},
355+
"rescale": {
356+
"type": "boolean",
357+
"default": false
358+
}
359+
}
331360
},
332-
"origin": {
361+
{
333362
"$ref": "#/definitions/vector3"
334363
}
335-
}
364+
]
336365
},
337366
"shade": {
338367
"type": "boolean",

src/systems/pluginCompiler.ts

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,21 @@ type BoneElementFaces = Partial<
6767
Record<'north' | 'east' | 'south' | 'west' | 'up' | 'down', BoneElementFace>
6868
>
6969

70-
interface BoneElementRotation {
71-
angle: number
72-
axis: 'x' | 'y' | 'z'
73-
origin: ArrayVector3
74-
rescale?: boolean
75-
}
70+
type BoneElementRotation =
71+
| {
72+
x: number
73+
y: number
74+
z: number
75+
origin: ArrayVector3
76+
rescale?: boolean
77+
}
78+
| {
79+
angle: number
80+
axis: 'y' | 'x' | 'z'
81+
origin: ArrayVector3
82+
rescale?: boolean
83+
}
84+
| ArrayVector3
7685

7786
interface BoneElement {
7887
from: ArrayVector3
@@ -331,15 +340,7 @@ function serializeBoneElements(
331340
;(faces as any)[dir] = serializedFace
332341
}
333342

334-
const rotation: BoneElementRotation =
335-
el.rotation && !Array.isArray(el.rotation)
336-
? {
337-
angle: el.rotation.angle,
338-
axis: el.rotation.axis as BoneElementRotation['axis'],
339-
origin: el.rotation.origin as ArrayVector3,
340-
rescale: (el.rotation as any).rescale,
341-
}
342-
: { angle: 0, axis: 'y', origin: [0, 0, 0] }
343+
const rotation = el.rotation ?? { angle: 0, axis: 'y', origin: [0, 0, 0] }
343344

344345
return scrubUndefined({
345346
from: el.from as ArrayVector3,
@@ -509,6 +510,7 @@ function serializeAnimation(options: {
509510
}): PluginAnimation {
510511
const { animation, nodeUuidToId } = options
511512

513+
// eslint-disable-next-line @typescript-eslint/naming-convention
512514
const loop_mode: LoopMode =
513515
animation.loop_mode === 'loop'
514516
? { type: 'loop', loop_delay: String(animation.loop_delay ?? 0) }
@@ -518,6 +520,7 @@ function serializeAnimation(options: {
518520

519521
const maxTime = animation.frames.at(-1)?.time ?? 0
520522

523+
// eslint-disable-next-line @typescript-eslint/naming-convention
521524
const node_keyframes: NonNullable<PluginAnimation['node_keyframes']> = {}
522525

523526
for (const frame of animation.frames) {
@@ -563,6 +566,7 @@ function serializeAnimation(options: {
563566
}
564567
}
565568

569+
// eslint-disable-next-line @typescript-eslint/naming-convention
566570
let global_keyframes: NonNullable<PluginAnimation['global_keyframes']> | undefined
567571

568572
// map the baked variant for each frame into the texture keyframes

0 commit comments

Comments
 (0)