Skip to content

Commit ade7351

Browse files
committed
🛠️ Fixed #309
1 parent eebec87 commit ade7351

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

src/systems/resourcepackCompiler.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ export async function compileResourcePack(options: {
289289
for (const variant of Object.values(rig.variants)) {
290290
for (const [boneUuid, variantModel] of Object.entries(variant.models)) {
291291
const bone = rig.nodes[boneUuid] as IRenderedNodes['Bone']
292+
if (variantModel.custom_model_data !== -1) continue
292293
variantModel.custom_model_data = displayItemModel.addOverride(
293294
variantModel.resource_location
294295
)

src/systems/rigRenderer.ts

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,6 @@ export type AnyRenderedNode = IRenderedNodes[keyof IRenderedNodes]
150150
export interface IRenderedVariantModel {
151151
model: IRenderedModel | null
152152
custom_model_data: number
153-
model_path: string
154153
resource_location: string
155154
}
156155

@@ -350,7 +349,6 @@ function renderGroup(
350349
display: { head: { rotation: [0, 180, 0] } },
351350
},
352351
custom_model_data: -1, // This is calculated when constructing the resource pack.
353-
model_path: path,
354352
resource_location: parsed.resourceLocation,
355353
}
356354
}
@@ -554,20 +552,25 @@ function renderCamera(camera: ICamera, rig: IRenderedRig) {
554552
function renderVariantModels(variant: Variant, rig: IRenderedRig) {
555553
const models: Record<string, IRenderedVariantModel> = {}
556554

555+
const defaultVariant = Variant.getDefault()
556+
const defaultModels = rig.variants[defaultVariant.uuid].models
557+
558+
// debugger
557559
for (const [uuid, bone] of Object.entries(rig.nodes)) {
558560
if (bone.type !== 'bone') continue
559561
if (variant.excludedNodes.find(v => v.value === uuid)) continue
560562
const textures: IRenderedModel['textures'] = {}
561563

562-
// Is set false if any texture other than the internal transparency texture is found.
563-
let isTransparent = true
564+
let isOnlyTransparent = true
565+
const unreplacedTextures = new Set<string>(Object.keys(defaultModels[uuid].model!.textures))
564566

565567
for (const [fromUUID, toUUID] of variant.textureMap.map.entries()) {
566568
const fromTexture = Texture.all.find(t => t.uuid === fromUUID)
567569
if (!fromTexture) throw new Error(`From texture not found: ${fromUUID}`)
568570
if (toUUID === TRANSPARENT_TEXTURE.uuid) {
569571
textures[fromTexture.id] = TRANSPARENT_TEXTURE_RESOURCE_LOCATION
570572
rig.textures[TRANSPARENT_TEXTURE.id] = TRANSPARENT_TEXTURE
573+
unreplacedTextures.delete(fromTexture.id)
571574
} else {
572575
const toTexture = Texture.all.find(t => t.uuid === toUUID)
573576
if (!toTexture) throw new Error(`To texture not found: ${toUUID}`)
@@ -576,12 +579,22 @@ function renderVariantModels(variant: Variant, rig: IRenderedRig) {
576579
rig
577580
).resourceLocation
578581
rig.textures[toTexture.id] = toTexture
579-
isTransparent = false
582+
isOnlyTransparent = false
580583
}
581584
}
582585

583-
// Don't export models without any texture changes, or that are fully transparent.
584-
if (isTransparent || Object.keys(textures).length === 0) continue
586+
// Don't export models without any texture changes
587+
if (Object.keys(textures).length === 0) continue
588+
589+
// Use empty model if all textures are transparent
590+
if (isOnlyTransparent && unreplacedTextures.size === 0) {
591+
models[uuid] = {
592+
model: null,
593+
custom_model_data: 1,
594+
resource_location: 'animated_java:empty',
595+
}
596+
continue
597+
}
585598

586599
const modelParent = PathModule.join(
587600
rig.model_export_folder,
@@ -609,7 +622,6 @@ function renderVariantModels(variant: Variant, rig: IRenderedRig) {
609622
textures,
610623
},
611624
custom_model_data: -1, // This is calculated when constructing the resource pack.
612-
model_path: modelPath,
613625
resource_location: parsedModelPath.resourceLocation,
614626
}
615627
}

src/variants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ export class TextureMap {
7474

7575
public verifyTextures() {
7676
for (const [key, value] of this.map) {
77+
if (value === TRANSPARENT_TEXTURE.uuid) continue
7778
if (!Texture.all.some(t => t.uuid === value)) {
7879
this.map.delete(key)
7980
}

0 commit comments

Comments
 (0)