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

three-software-renderer

v1.2.0

Published

Universal Three.js in-memory renderer

Downloads

662

Readme

three-software-renderer

##Universal Three.js in-memory renderer for node.js and the browser

What's this for?

The SoftwareRenderer is a drop-in renderer for Three.js that can be used on the server and the client, if you need to be GPU independent.

What's the drawback?

Primarily performance. As this renderer does not have access to GPU acceleration and GPU shader units, it's much much slower than the CanvasRenderer or WebGLRenderer. In addition, you'll have to use THREE.DataTexture instead of a normal THREE.Texture for textures when you're in a headless environment (i.e. node.js).

What are possible use cases?

  • Rendering in a web worker, e.g. for static renderings that should happen in the background
  • Rendering on the server, e.g. for preview images of 3D models
  • Tell me, if you have other ideas

Which Three.js version is this compatible with?

So far I have tested 0.69 and 0.71. Please tell me if you tried it with other versions as well :-)

What is this work based on?

First and foremost this is just a modified copy of the SoftwareRenderer found in the Three.js example sources. It also uses the modified THREE.Projector from the examples.

How to use

const THREE = require("three");
const SoftwareRenderer = require("three-software-renderer");
const PNG = require("pngjs").PNG;
const fs = require("fs");

// Build scene with cube
const width = 1024;
const height = 768;

const camera = new THREE.PerspectiveCamera(75, width / height, 1, 10000);
camera.position.z = 500;

// Create a simple red cube
const geometry = new THREE.BoxGeometry(200, 200, 200);
const material = new THREE.MeshBasicMaterial({color: 0xff0000});
const mesh = new THREE.Mesh(geometry, material);

// Rotate the cube a bit
mesh.rotation.x += 0.5;
mesh.rotation.y += 0.6;

const scene = new THREE.Scene();
scene.add(mesh);

// Render into an Uint8ClampedArray (RGBA).
const renderer = new SoftwareRenderer({
  alpha: false
});
renderer.setSize(width, height);
var imagedata = renderer.render(scene, camera);

// Create a PNG from the array
const png = new PNG({
  width: width,
  height: height,
  filterType: -1
});

// Copy byte array to png object  
for(var i=0;i<imagedata.data.length;i++) {
  png.data[i] = imagedata.data[i];
}

// Write PNG to disk
if (!fs.existsSync("temp")) {
  fs.mkdirSync("temp");
}
png.pack().pipe(fs.createWriteStream("temp/example.png"));

I found a bug, how can I help?

Please help me improve this module by opening an issue on Github. If you have an idea what might cause the problem, I'd be very grateful if you'd try to investigate the bug and make a pull request to this repository. If you have any questions or need help doing so, let me know via the issues in this project!