Git Product home page Git Product logo

beatsaberavatar.js's Introduction

BeatSaberAvatar.js

3D web viewer for Beat Saber multiplayer avatars (Three.js / WebGL).

๐Ÿ‘€ Check out the Demo page

BeatSaberAvatar.js

Installation

Prebuilt

โœ… You can download prebuilt releases from the GitHub releases page ready for web use.

You'll need to host the assets folder in a publicly accessible location.

Building from source

๐Ÿ’€ You can build BeatSaberAvatar.js from source if you prefer.

Prerequisites: Node.js (v16 or newer).

  1. Check out the source code
  2. Install dependencies with npm install
  3. Build using npm run build

For development, you can use npm run watch to get automatic builds on file changes.

Usage

Basic setup

Set up a target element on your page, and include the script. You can now use the BeatSaberAvatar global to access the script's API and get started.

Here's a quick example that will present a random avatar:

<div id="render-target">Placeholder content while loading</div>

<script src="BeatSaberAvatar.js" async defer></script>

<script>
    window.addEventListener('load', function () {
        const renderTarget = document.getElementById('render-target');
        BeatSaberAvatar.setup(renderTarget); // returns renderer instance
    });
</script>

Because the script with Three.js is quite large, it's recommended to load it with async and defer. By then listening to the window.load event you can be sure the script is ready to go.

Setting avatar data

You can define avatar data by creating an instance of BeatSaberAvatarData.

You can pass this as the second argument of the setup() call, or later by calling setAvatarData() on the renderer instance.

// Example of complete avatar data
let avatarData = {
    "headTopId": "OnFire",
    "headTopPrimaryColor": "#a7966dff",
    "headTopSecondaryColor": "#900277ff",
    "glassesId": "Glasses01",
    "glassesColor": "#a7796dff",
    "facialHairId": "Moustache02",
    "facialHairColor": "#a7796dff",
    "handsId": "BareHands",
    "handsColor": "#a7796dff",
    "clothesId": "Hoodie",
    "clothesPrimaryColor": "#cf3384ff",
    "clothesSecondaryColor": "#4b2da5ff",
    "clothesDetailColor": "#000000ff",
    "skinColorId": "Default",
    "eyesId": "Eyes6",
    "mouthId": "Mouth12"
};

let instance = BeatSaberAvatar.setup(renderTarget, avatarData);

// Or, later:
instance.setAvatarData(avatarData);

If you don't provide avatar data or pass null, a random avatar will be presented instead.

Advanced options

You can provide advanced options as the third parameter in the setup call:

const options = {
    assetsBaseDir: "/static/avatar_assets/",
    enableControls: false,
    rotateAnimation: true
};
BeatSaberAvatar.setup(renderTarget, avatarData, options);

Here's an overview of the supported options:

Key Default Description
assetsBaseDir assets/ Base directory from which model and texture assets are loaded.
enableControls true Enable orbit camera controls.
rotateAnimation true If true, the avatar will slowly rotate from side to side.
allowRandomize true If true, missing or invalid parts will be randomized. If false, missing or invalid parts will not be rendered.
enableGlasses false If true, render glasses from avatar data (unused assets).
enableFacialHair false If true, render facial hair from avatar data (unused assets).
initialZoomLevel 1.5 Sets the initial zoom level of the camera (z-depth).

License

This is a fan project for non-commercial purposes. Assets used in this project are unlicensed and are the property of Beat Games.

The code in this repository is available under the MIT license.

For details, see LICENSE.

beatsaberavatar.js's People

Contributors

roydejong avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.