Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
VideoGames1000 opened this issue Sep 6, 2024 · 3 comments
Open

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

VideoGames1000 opened this issue Sep 6, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@VideoGames1000
Copy link

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.

@VideoGames1000 VideoGames1000 added the enhancement New feature or request label Sep 6, 2024
@GrandpaScout
Copy link
Contributor

GrandpaScout commented Sep 6, 2024

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
Copy link
Author

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
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants