Universal Three.js in-memory renderer for node.js and the browser
What's this for?
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?
How to use
const THREE = ;const SoftwareRenderer = ;const PNG = PNG;const fs = ;// Build scene with cubeconst width = 1024;const height = 768;const camera = 75 width / height 1 10000;camerapositionz = 500;// Create a simple red cubeconst geometry = 200 200 200;const material = color: 0xff0000;const mesh = geometry material;// Rotate the cube a bitmeshrotationx += 05;meshrotationy += 06;const scene = ;scene;// Render into an Uint8ClampedArray (RGBA).const renderer =alpha: false;renderer;var imagedata = renderer;// Create a PNG from the arrayconst png =width: widthheight: heightfilterType: -1;// Copy byte array to png objectforvar i=0;i<imagedatadatalength;i++pngdatai = imagedatadatai;// Write PNG to diskif !fsfs;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!