A three.js plugin that adds labels to your game players (avatars).
JavaScript
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
www
.gitignore
LICENSE-MIT
Label.js
LabelPlugin.js
index.js
package.json
readme.md
voxel-label-avatar.png
voxel-label-large.png
voxel-label.png

readme.md

voxel-label

Voxel-label is a voxeljs module that implements LabelPlugin, a three.js plugin that adds labels to your game players (avatars). It can work in single-player mode as well as with voxel-client for labelling all avatars in a multiplayer game.

Get it running on your machine

npm install

Run the start script:

npm start

This gets the server running on port 8080.

You may view a demo at http://127.0.0.1:8080. The demo adds another player to the Hello World demo. This player gets a label, JayJay. The default Hello World player does not get a label. Click "R" to view both players.

View of both players

API

require('voxel-label')(game)

Initializes the LabelPlugin

LabelPlugin(game)

require('voxel-label').label(labelText, avatar, game, client.playerID)

Create a label for a player:

playerLabel = LabelPlugin.label(labelText, avatar, game, client.playerID)

Multi-player mode:

Make sure that your application populates a registration objects that has a username for the other players ("others"). voxel-app-server has an example of how to do this.

The following code uses the emitter from voxel-client instance to check the update stream every second. It grabs the userInfo (player's username) from the update and adds it to the avatar. It only creates a label when the username does not match the playerId value in the labels array.

setTimeout(function() {
  client.emitter.on('update', function(updates) {
    Object.keys(updates.userInfo).map(function(playerId) {
      var update = updates.userInfo[playerId]
      if (playerId === self.playerID) return  // local playerId
      var playerSkin = this.others[playerId]
      if (playerSkin != null) {
        playerSkin.userInfo = update
        if (labels[playerId] !== playerSkin.userInfo.username) {
          var otherPlayerLabel = LabelPlugin.label(playerSkin.userInfo.username, playerSkin.mesh, game, playerId)
          labels[playerId] = playerSkin.userInfo.username
        }
      }
    })
  })
}, 1000)

Credits:

license

BSD