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 🙏

© 2026 – Pkg Stats / Ryan Hefner

blockymodel-texture

v0.1.1

Published

Texture application and UV mapping for BlockyModel format

Readme

blockymodel-texture

Texture application and UV mapping for BlockyModel format.

This package provides the core texture rendering logic for Hytale's BlockyModel 3D format, including:

  • Per-face UV mapping with offset, mirror, and rotation support
  • Pixel-art texture configuration (nearest-neighbor filtering)
  • Box and quad geometry texture layout application

Installation

npm install blockymodel-texture three

Note: three is a peer dependency and must be installed separately.

Usage

Apply texture to a loaded model

import { applyTextureToModel } from "blockymodel-texture";
import * as THREE from "three";

// Load your model and texture...
const model: THREE.Group = /* loaded BlockyModel */;
const texture = new THREE.TextureLoader().load("texture.png");

// Apply texture with pixel-art settings
applyTextureToModel(model, texture);

// Or with custom options
applyTextureToModel(model, texture, {
  pixelArt: true,      // Use nearest-neighbor filtering (default: true)
  transparent: true,   // Enable PNG alpha support (default: true)
  alphaTest: 0.1,      // Alpha threshold (default: 0.1)
});

Apply UV layout to a single geometry

import { applyTextureLayoutToBox, applyTextureLayoutToQuad } from "blockymodel-texture";
import type { TextureLayout } from "blockymodel-texture";

const layout: TextureLayout = {
  front: { offset: { x: 0, y: 0 }, mirror: { x: false, y: false }, angle: 0 },
  back: { offset: { x: 8, y: 0 }, mirror: { x: false, y: false }, angle: 0 },
  // ... other faces
};

// For box geometries
applyTextureLayoutToBox(
  boxGeometry,
  layout,
  64,  // texture width
  64,  // texture height
  { x: 8, y: 8, z: 8 }  // box size in pixels
);

// For quad/plane geometries
applyTextureLayoutToQuad(
  planeGeometry,
  layout,
  64,
  64,
  { x: 8, y: 8, z: 1 },
  "+Z"  // normal direction
);

Calculate UV coordinates directly

import { calculateFaceUVs } from "blockymodel-texture";
import type { FaceUV } from "blockymodel-texture";

const faceUV: FaceUV = {
  offset: { x: 16, y: 8 },
  mirror: { x: false, y: false },
  angle: 90,
};

const [u1, v1, u2, v2] = calculateFaceUVs(
  faceUV,
  8,   // face width in pixels
  4,   // face height in pixels
  64,  // texture width
  64   // texture height
);

Types

interface FaceUV {
  offset: Vec2;                        // Top-left pixel coordinate
  mirror: { x: boolean; y: boolean };  // Flip sampling direction
  angle: 0 | 90 | 180 | 270;           // Rotation in degrees
}

interface TextureLayout {
  front?: FaceUV;   // +Z face
  back?: FaceUV;    // -Z face
  left?: FaceUV;    // -X face
  right?: FaceUV;   // +X face
  top?: FaceUV;     // +Y face
  bottom?: FaceUV;  // -Y face
}

UV Mapping Algorithm

Based on Hytale's Blockbench Plugin implementation:

  1. Offset: Specifies top-left corner of texture region in pixel coordinates
  2. Mirror: Flips the sampling direction (reverses UV range)
  3. Angle: Rotates the UV region:
    • 0°: No rotation
    • 90°: Swap dimensions, adjust mirrors
    • 180°: Flip both axes
    • 270°: Swap dimensions, flip different axis

The V coordinate is flipped during application because Hytale uses image coordinates (top-left origin, Y increases downward) while Three.js UV uses bottom-left origin (V increases upward).

License

MIT