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 = ;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: width height: height filterType: -1; // Copy byte array to png object forvar i=0;i<imagedatadatalength;i++ pngdatai = imagedatadatai; // Write PNG to diskif !fs fs;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!