Created
November 4, 2025 23:00
-
-
Save joncardasis/f030cac441fb2680a6676bda00f3c873 to your computer and use it in GitHub Desktop.
Parse and print contents of a rive file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import fs from 'fs' | |
| import Rive, { | |
| Alignment, | |
| Fit, | |
| Layout, | |
| Rive, | |
| RiveFile, | |
| FileAsset, | |
| useStateMachineInput, | |
| } from '@rive-app/react-webgl2' | |
| async function main() { | |
| const fileBuffer = fs.readFileSync( | |
| '/Users/jon/Workspace/rives/demo.riv' | |
| ) | |
| console.log('File buffer length:', fileBuffer.length) | |
| let arrayBuffer = fileBuffer.buffer.slice( | |
| fileBuffer.byteOffset, | |
| fileBuffer.byteOffset + fileBuffer.byteLength | |
| ) | |
| arrayBuffer = | |
| arrayBuffer instanceof SharedArrayBuffer ? arrayBuffer.slice() : arrayBuffer | |
| const riveFile = new RiveFile({buffer: arrayBuffer}) | |
| await riveFile.init() | |
| // const file = (await rive.load(new Uint8Array(arrayBuffer))) as File | |
| console.log({riveFile, arrayBuffer}) | |
| const file = riveFile.getInstance() | |
| for (let i = 0; i < file.artboardCount(); i++) { | |
| const artboard = file.artboardByIndex(i) | |
| console.log('Artboard Name:', artboard.name) | |
| for (let j = 0; j < artboard.stateMachineCount(); j++) { | |
| const stateMachine = artboard.stateMachineByIndex(j) | |
| console.log(' State Machine Name:', stateMachine.name) | |
| } | |
| for (let j = 0; j < artboard.animationCount(); j++) { | |
| const animation = artboard.animationByIndex(j) | |
| console.log(' Animation Name:', animation.name) | |
| } | |
| } | |
| } | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment