npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

babylon-atlas

v0.7.0

Published

A texture atlas module for Babylon.js

Downloads

19

Readme

babylon-atlas

Wrangles sprites out of texture atlases for Babylon.js

This module gives two separate (and orthogonal) ways to use texture atlases with Babylon.js, depending on whether you want to work with meshes or textures. Behind the scenes, the mesh APIs deal with vertex UV values, while the texture APIs work with the texture's uvScale/uvOffset properties.

Updates:

  • v0.7.0: Takes babylon as a peer dependency, now uses export/import
  • v0.6.0: Removes dependencies, cleanup
  • v0.4.0: Allow passing in JSON object instead of a URL
  • v0.3.0: API changed to reflect parallel support for mesh/texture-based usage
  • v0.2.0: supports breaking changes in Babylon.js v2.3. When using Babylon 2.2 and below, move this repo to any commit before v0.2.0.

Usage:

var createAtlas = require('babylon-atlas')
var atlas = createAtlas('sprites.png', 'sprites.json', scene)

// making a plane mesh showing frames from the atlas
var mesh = atlas.makeSpriteMesh('player_walk')
atlas.setMeshFrame(mesh, 'player_jump')

// working with textures
var mat = myExistingMesh.material
mat.diffuseTexture = atlas.createSpriteTexture('player_walk')
atlas.setTextureFrame(mat.diffuseTexture, 'player_jump')

Live demo here (outdated).

Format

Expects texture atlas JSON to look something like this:

{
    "meta": {
        "size": {"w":256,"h":256}
    },
    "frames": {
        "frame_001": {"frame": {"x":0, "y":32,"w":22,"h":18} },
        "frame_002": {"frame": {"x":53,"y":0, "w":22,"h":21} }
    }
}

which is, I guess, a sort-of standard format.

Installation

npm install babylon-atlas

Hacking on the local demo is broken right now!

todo: update to use modern imported version of babylon.

API

// import
import { Atlas } from 'babylon-atlas'

// create an atlas - last two args optional
var atlas = createAtlas( imgURL, jsonURL, scene, noMipMap, samplingMode )

// frame names are accessible as an array of strings
// this will be empty until the atlas loads, but other APIs will still work
atlas.frames

// create a mesh showing one sprite from atlas
//    frame: number (frame index) or string (frame name). default: 0
//    material: if omitted a default material will be created
var mesh = atlas.makeSpriteMesh( frame, material ) 

// set frame of existing mesh. 
//    frame: as previous
atlas.setMeshFrame( mesh, frame ) 

// create a texture showing one sprite from atlas
//    frame: number (frame index) or string (frame name). default: 0
var texture = atlas.makeSpriteTexture( frame )

// set frame of texture 
//    frame: as previous
atlas.setTextureFrame( texture, frame ) 

// disposal
atlas.dispose()