Skip to content

Commit e8e1d19

Browse files
committed
Fix #267 #261 and #260
- Removed `safe_name` from plugin JSON export. - Fixed incorrect item model paths. - Removed `display_item` from plugin JSON export.
1 parent 9de3ba9 commit e8e1d19

File tree

2 files changed

+34
-17
lines changed

2 files changed

+34
-17
lines changed

src/systems/jsonCompiler.ts

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ type ExportedNodetransform = Omit<
4141
}
4242
type ExportedRenderedNode = Omit<
4343
AnyRenderedNode,
44-
'node' | 'parentNode' | 'model' | 'boundingBox' | 'configs' | 'baseScale'
44+
'node' | 'parentNode' | 'model' | 'boundingBox' | 'configs' | 'baseScale' | 'safe_name'
4545
> & {
4646
default_transform: ExportedNodetransform
4747
bounding_box?: { min: ArrayVector3; max: ArrayVector3 }
@@ -50,7 +50,10 @@ type ExportedRenderedNode = Omit<
5050
type ExportedAnimationFrame = Omit<IRenderedFrame, 'nodes' | 'node_transforms'> & {
5151
node_transforms: Record<string, ExportedNodetransform>
5252
}
53-
type ExportedBakedAnimation = Omit<IRenderedAnimation, 'uuid' | 'frames' | 'modified_nodes'> & {
53+
type ExportedBakedAnimation = Omit<
54+
IRenderedAnimation,
55+
'uuid' | 'frames' | 'modified_nodes' | 'safe_name'
56+
> & {
5457
frames: ExportedAnimationFrame[]
5558
modified_nodes: string[]
5659
}
@@ -95,7 +98,6 @@ type ExportedDynamicAnimation = {
9598
}
9699
interface ExportedTexture {
97100
name: string
98-
id: string
99101
src: string
100102
}
101103
type ExportedVariantModel = Omit<IRenderedVariantModel, 'model_path' | 'resource_location'> & {
@@ -117,7 +119,6 @@ export interface IExportedJSON {
117119
export_namespace: (typeof defaultValues)['export_namespace']
118120
bounding_box: (typeof defaultValues)['bounding_box']
119121
// Resource Pack Settings
120-
display_item: (typeof defaultValues)['display_item']
121122
custom_model_data_offset: (typeof defaultValues)['custom_model_data_offset']
122123
// Plugin Settings
123124
baked_animations: (typeof defaultValues)['baked_animations']
@@ -197,12 +198,19 @@ function serailizeKeyframe(kf: _Keyframe): ExportedKeyframe {
197198
return json
198199
}
199200

200-
function serializeVariant(variant: IRenderedVariant): ExportedVariant {
201+
function serializeVariant(rig: IRenderedRig, variant: IRenderedVariant): ExportedVariant {
201202
const json: ExportedVariant = {
202203
...variant,
203204
models: mapObjEntries(variant.models, (uuid, model) => {
204205
const json: ExportedVariantModel = {
205-
model: model.model,
206+
model: {
207+
...model.model,
208+
// textures: mapObjEntries(model.model.textures, (id, path) => {
209+
// const actualTexture = rig.textures[id]
210+
// if (!actualTexture) return [id, path]
211+
// return [id, actualTexture.uuid]
212+
// }),
213+
},
206214
custom_model_data: model.custom_model_data,
207215
}
208216
return [uuid, json]
@@ -223,10 +231,9 @@ export function exportJSON(options: {
223231

224232
console.log('Exporting JSON...', options)
225233

226-
function serializeTexture(id: string, texture: Texture): ExportedTexture {
234+
function serializeTexture(texture: Texture): ExportedTexture {
227235
return {
228236
name: texture.name,
229-
id,
230237
src: texture.getDataURL(),
231238
}
232239
}
@@ -235,16 +242,18 @@ export function exportJSON(options: {
235242
settings: {
236243
export_namespace: aj.export_namespace,
237244
bounding_box: aj.bounding_box,
238-
display_item: options.displayItemPath,
239245
custom_model_data_offset: aj.custom_model_data_offset,
240246
baked_animations: aj.baked_animations,
241247
},
242-
textures: mapObjEntries(rig.textures, (id, texture) => [
248+
textures: mapObjEntries(rig.textures, (_, texture) => [
243249
texture.uuid,
244-
serializeTexture(id, texture),
250+
serializeTexture(texture),
245251
]),
246252
nodes: mapObjEntries(rig.nodes, (uuid, node) => [uuid, serailizeRenderedNode(node)]),
247-
variants: mapObjEntries(rig.variants, (uuid, variant) => [uuid, serializeVariant(variant)]),
253+
variants: mapObjEntries(rig.variants, (uuid, variant) => [
254+
uuid,
255+
serializeVariant(rig, variant),
256+
]),
248257
animations: {},
249258
}
250259

@@ -311,6 +320,7 @@ function serailizeRenderedNode(node: AnyRenderedNode): ExportedRenderedNode {
311320
const json: any = { ...node }
312321
delete json.node
313322
delete json.parentNode
323+
delete json.safe_name
314324
delete json.model
315325
transferKey(json, 'lineWidth', 'line_width')
316326
transferKey(json, 'backgroundColor', 'background_color')
@@ -343,7 +353,6 @@ function serailizeRenderedNode(node: AnyRenderedNode): ExportedRenderedNode {
343353
function serializeAnimation(animation: IRenderedAnimation): ExportedBakedAnimation {
344354
const json: ExportedBakedAnimation = {
345355
name: animation.name,
346-
safe_name: animation.safe_name,
347356
duration: animation.duration,
348357
loop_delay: animation.loop_delay,
349358
loop_mode: animation.loop_mode,

src/systems/rigRenderer.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ function renderGroup(
321321
if (!group.export) return
322322
const parentId = (group.parent instanceof Group ? group.parent.uuid : group.parent)!
323323

324-
const path = PathModule.join(rig.model_export_folder, group.name + `.json`)
324+
const path = PathModule.join(rig.model_export_folder, 'default', group.name + `.json`)
325325
const parsed = parseResourcePackPath(path)
326326

327327
if (!parsed) {
@@ -577,13 +577,21 @@ function renderVariantModels(variant: Variant, rig: IRenderedRig) {
577577
// Don't export models without any texture changes
578578
if (Object.keys(textures).length === 0) continue
579579

580-
const modelParent = PathModule.join(rig.model_export_folder, bone.name)
580+
const modelParent = PathModule.join(
581+
rig.model_export_folder,
582+
'default',
583+
bone.safe_name + '.json'
584+
)
581585
const parsed = parseResourcePackPath(modelParent)
582586
if (!parsed) {
583-
throw new Error(`Invalid Bone Name: '${bone.name}' -> '${modelParent}'`)
587+
throw new Error(`Invalid Bone Name: '${bone.safe_name}' -> '${modelParent}'`)
584588
}
585589

586-
const modelPath = PathModule.join(modelParent, variant.name + '.json')
590+
const modelPath = PathModule.join(
591+
rig.model_export_folder,
592+
variant.name,
593+
bone.safe_name + '.json'
594+
)
587595
const parsedModelPath = parseResourcePackPath(modelPath)
588596
if (!parsedModelPath) {
589597
throw new Error(`Invalid Variant Name: '${variant.name}' -> '${modelPath}'`)

0 commit comments

Comments
 (0)