Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Completely black output #17

Open
spritefish opened this issue Jul 2, 2018 · 3 comments
Open

Completely black output #17

spritefish opened this issue Jul 2, 2018 · 3 comments

Comments

@spritefish
Copy link

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.

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"));

@spritefish
Copy link
Author

Found solution -- it was not working when I used NPM builds, but it works with latest from github

@ikeough
Copy link

ikeough commented Oct 11, 2018

I saw the same behavior and did some step through debugging. It turns out that three-software-renderer has a dependency on threejs v.0.82.1. If you use it inside another project which references another version of threejs (i.e. there's another version of threejs in node_modules for your project), all calls to instanceof, like those in projector to determine what is drawable, will return false. So nothing is drawn. You see all black. Removing the copy of threejs from three-software-renderer/node_modules causes my app to fall back to the version referenced in myapp/node_modules. I'm pretty sure just updating the threejs reference in package.json to newest would solve this.

@ryanyr
Copy link

ryanyr commented Mar 29, 2022

I saw the same behavior and did some step through debugging. It turns out that three-software-renderer has a dependency on threejs v.0.82.1. If you use it inside another project which references another version of threejs (i.e. there's another version of threejs in node_modules for your project), all calls to instanceof, like those in projector to determine what is drawable, will return false. So nothing is drawn. You see all black. Removing the copy of threejs from three-software-renderer/node_modules causes my app to fall back to the version referenced in myapp/node_modules. I'm pretty sure just updating the threejs reference in package.json to newest would solve this.

I did delete threejs in three-software-renderer/node_modules and deleted three in package.json in three-software-renderer, but it did not work as well, still a black picture.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants