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

mantle-renderer

v1.6.1

Published

A Minecraft-focused WebGL powered 3D renderer built for both the browser and server.

Downloads

608

Readme

Mantle Renderer

A Minecraft-focused WebGL powered 3D renderer built for both the browser and server.

Installation

Install Mantle Renderer into your client or server-side project using npm i mantle-renderer.

Usage

Creation

New renderers can be created attached to canvases. If used server-side, the canvas field should be omitted to let the renderer take care of it.

const renderer = new MantleRenderer({
    live: true,
    platformUtils: new ClientPlatformUtils(),
    canvas: canvasElement,
    player: {
        skin: "https://textures.minecraft.net/texture/7f608010686ff1d32c7323967ae9ee6599983b28f776a3b30f435a1e11822b9c",
        slim: false
    },
    antialias: true,
    fxaa: true,
    controls: true
});

Deletion

Renderers need to manually be destroyed in order to free up memory used by textures and geometries.

renderer.destroy();

Exporting Screenshots

Renderers allow the the scene to be exported as a PNG or JPEG at any resolution.

renderer.screenshot(1920, 1080, "jpeg", 2);

Post-Processing effects like FXAA, SSAA and bloom aren't supported by the screenshot method. Instead, super-sampling can be used as an alternative to anti-aliasing, at the cost of performance.

It should be noted that the screenshot method isn't very useful when used in the browser as you can extract the contents of the HTML canvas directly, including post-processing effects.

Loading Models

Minecraft: Java Edition block models can be converted to the Mantle Renderer format.

const blockModel = {...};
const textureUrl = "https://example.com/texture.png";

const mantleModel = parseJavaBlockModel(blockModel, textureUrl);

The model can then be imported directly into the scene. It's noted that using this technique, you'll need to dispose of the model's geometry, materials and textures yourself.

const mantleModel = parseJavaBlockModel(blockModel, textureUrl);

const { mesh } = await buildModel(mantleModel);

renderer.scene.add(mesh);

Alternatively, the model can be attached directly to a player model. Using this technique, the model's resources will automatically be released when the renderer is destroyed or the model is removed.

const mantleModel = parseJavaBlockModel(blockModel, textureUrl, [0, 0, 0], renderer.player.getBodyPart("head"));

await renderer.player.addModel(model);

Using Headlessly

When using Mantle Renderer in a server environment you're likely using a headless machine. In this case, creating a render may result in the following error:

THREE.WebGLRenderer: Error creating WebGL context.

This is because the machine isn't providing an X11 or an OpenGL environment. To setup this environment on Linux we can use Xvfb or Mesa.

If using Xvfb, its best to create the display environment as you start the Node.js application and close the environment when the application finishes. We can do that using this command:

xvfb-run -s "-ac -screen 0 1280x1024x24" <command to start Node.js application>

Read more about this in the Headless GL documentation.

In order to not depend on a browser, the renderer's platformUtils needs to be adjusted.

const renderer = new MantleRenderer({
    live: false,
    platformUtils: new ServerPlatformUtils()
});

Development Setup

run npm run i instead of npm install in order to download dependencies for both the library and the development environment.

License

This project is MIT licensed.