FiguraMC / Figura

Extensively customize your character with Figura!
https://modrinth.com/mod/figura
GNU Lesser General Public License v2.1
253 stars 46 forks source link

Grab texture from PNG file instead of a blockbench model #257

Open VideoGames1000 opened 2 months ago

VideoGames1000 commented 2 months ago

Request Description

Simply, allow textures:get() to pull from a .png file in the Avatar's folder instead of needing to be embedded in a blockbench model or encoded. It's a small change on the user end, but it'd be a nice touch for my personal use case.

GrandpaScout commented 2 months ago

You can tell Figura to load files in the avatar's folder with the resources key in the avatar.json metadata. This will cause the files to be uploaded with the avatar so they can be used almost like normal.

resources is a list of file globs.

{
  "resources": [
    "*.res.png", // Loads any file with the extension `.res.png` in the avatar root.
    "**/icon.png", // Loads any file called `icon.png` in any subfolder of the avatar.
    "etc."
  ]
}

These resources can then be loaded with the Resources API.

VideoGames1000 commented 2 months ago

Can you give a practical example for the resource API part? Specifically, I'm trying to make radialmenu icons with this, if that helps.

GrandpaScout commented 2 months ago
local buffer = data:createBuffer()
buffer:readFromStream(resources:get("path/to/file.png")) -- File path starts at avatar's root folder.
buffer:setPosition(0)
local newTexture = textures:read("newTextureName", buffer:readBase64(buffer:getLength()))
buffer:close()

-- After this, any function can reference `newTexture` as the texture to use.

It's not exactly the most pretty thing because you have to deal with Figura's (imo annoying) file IO implementation.