-
Notifications
You must be signed in to change notification settings - Fork 17
Open
Description
I am seeing completely black output.
OSX node v8.11.3
When running example code, it outputs
THREE.SoftwareRenderer 82
<Buffer 00 00 00 ff 00 00 00 ff 00 00 00 ff 00 00 00 ff 00 00 00 ff 00 00 00 ff 00 00 00 ff 00 00 00 ff 00 00 00 ff 00 00 00 ff 00 00 00 ff 00 00 00 ff 00 00 ... >
and creates a black png of size 4414 bytes.
├── fs@0.0.1-security
├── pngjs@3.3.3
├── three@0.82.1
└─┬ three-software-renderer@1.2.0
└── three@0.82.1
Code being used :
/**
* @author jonaskello / https://github.com/jonaskello
* Simple example that renders a scene with a cube to a PNG image file.
*/
const THREE = require("three");
// Use either named export or default export
//const SoftwareRenderer = require("../");
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;
const scene = new THREE.Scene();
const geometry = new THREE.BoxGeometry(200, 200, 200);
const material = new THREE.MeshBasicMaterial({color: 0xf10000});
const mesh = new THREE.Mesh(geometry, material);
scene.add(mesh);
// Rotate the cube a bit
mesh.rotation.x += 0.5;
mesh.rotation.y += 0.6;
var light = new THREE.AmbientLight( 0x404040 ); // soft white light
scene.add( light );
// Render into pixels-array (RGBA)
const renderer = new SoftwareRenderer();
renderer.setSize(width, height);
var imagedata = renderer.render(scene, camera);
// Create a PNG from the pixels array (RGBA)
const png = new PNG({
width: width,
height: height,
filterType: -1
});
for(var i=0;i<imagedata.data.length;i++) {
png.data[i] = imagedata.data[i];
}
console.log(png.data);
if (!fs.existsSync("temp")) {
fs.mkdirSync("temp");
}
png.pack().pipe(fs.createWriteStream("temp/example2.png"));
Metadata
Metadata
Assignees
Labels
No labels