feat: start impl of skin normalization on frontend

This commit is contained in:
Calum H.
2025-05-29 12:19:19 +01:00
committed by Alejandro González
parent 5fa9a0e812
commit 774950de90
2 changed files with 11 additions and 2 deletions

View File

@@ -1,5 +1,5 @@
import * as THREE from 'three'
import type { Skin, Cape } from '../skins'
import {Skin, Cape, normalize_skin_texture, get_normalized_skin_texture_url} from '../skins'
import { determineModelType } from '../skins'
import { reactive } from 'vue'
import { setupSkinModel, disposeCaches } from '@modrinth/utils'
@@ -185,7 +185,7 @@ export async function generateSkinPreviews(skins: Skin[], capes: Cape[]): Promis
const modelUrl = getModelUrlForVariant(variant)
const cape: Cape | undefined = capes.find((_cape) => _cape.id === skin.cape_id)
const renderResult = await renderer.renderSkin(
skin.texture,
await get_normalized_skin_texture_url(skin),
modelUrl,
cape?.texture,
capeModelUrl,

View File

@@ -142,6 +142,15 @@ export async function remove_custom_skin(skin: Skin): Promise<void> {
})
}
export async function get_normalized_skin_texture_url(skin: Skin): Promise<string> {
const bytes: Uint8Array = await normalize_skin_texture(skin);
return `data:image/png;base64,` + Buffer.from(bytes).toString("base64");
}
export async function normalize_skin_texture(skin: Skin): Promise<Uint8Array> {
return await invoke('plugin:minecraft-skins|normalize_skin_texture', { skin })
}
export async function unequip_skin(): Promise<void> {
await invoke('plugin:minecraft-skins|unequip_skin')
}