RoAvatar-Renderer | Animated 3D web renderer for avatars

RoAvatar-Renderer | Animated 3D web renderer for avatars

Links: npm | GitHub | docs


What is it?

RoAvatar-Renderer is an npm package that allows for easy rendering of roblox avatars in the web browser. It has been used in web extensions such as RoAvatar and RoValra.

ezgif-73f5216e76603461

What makes it different from the Roblox 3D thumbnail?

Unlike the Roblox 3D thumbnail renderer RoAvatar-Renderer supports a wider variety of features, including:

  • Animations (including Dynamic Heads)
  • Particles
  • Skinning (doesn’t support new optional bones yet)
  • Transparency
  • Modifying avatar without fully reloading

It also isn’t heavily rate limited like the Roblox thumbnails, as it never makes any requests to the thumbnails API for rendering.

Example code in TypeScript (for an extension environment):

FLAGS.ONLINE_ASSETS = true //loads assets that are usually local from Roblox instead

//actually creating renderer
const success = await RBXRenderer.fullSetup()
if (!success) {
    //roavatar-renderer automatically displays an error, but your own behavior can be included here (like a fallback)
}
//renderer customization
RBXRenderer.setBackgroundColor( 0xbbbbbb )
RBXRenderer.setRendererSize(1000,500)
RBXRenderer.setBackgroundTransparent(false)
//add renderer to document
document.body.appendChild(RBXRenderer.getRendererElement())

//get avatar data for the user with id 1
const outfit = await API.Avatar.GetAvatarDetails(1)
if (!(outfit instanceof Outfit)) throw new Error("Failed to get outfit")

//create renderer for outfit
const auth = new Authentication()
//manages outfit rendering for you
const outfitRenderer = new OutfitRenderer(auth, outfit)
outfitRenderer.startAnimating()
outfitRenderer.setMainAnimation("idle")

The result:

Additional use cases

RoAvatar-Renderer works by creating the structure of an avatar and then rendering each Instance inside. This means RoAvatar-Renderer can be interacted with in a similar way to the actual Roblox engine.

Heres an example in JavaScript where we retrieve an accessory and render a thumbnail for it locally, while using methods that are similar to ones in the real Roblox:

//config
const ASSETID = 1039433 //oh noes hat

FLAGS.ANIMATE_SKELETON = false
FLAGS.UPDATE_SKELETON = true

//create extra scene and setup appearance
const rScene = RBXRenderer.addScene()
setupThumbnailScene(rScene)

//retrieve RBX
const rbxHeader = {"Roblox-AssetFormat":"avatar_meshpart_accessory"} //needed for the accessory to be a meshpart
const accessoryrbx = await API.Asset.GetRBX(`rbxassetid://${ASSETID}`, rbxHeader)

//create instance hierachy and get root instance
const accessory = accessoryrbx.generateTree().GetChildren()[0]
const handle = accessory.FindFirstChildOfClass("MeshPart")

//update handle position if we dont have a camera that will look at the accessory
const cf = handle.Prop("CFrame")
if (!accessory.FindFirstChildOfClass("Camera")) cf.Position = [0,0,0]

//generate thumbnail as a data url
const result = await generateModelThumbnail(new Authentication(), rScene, accessory, [1000,1000], "webp", 0.99)
console.log(result)

Here’s the result for the example above and a similar one that renders an outfit:

6 Likes