Closed Jefemy closed 7 years ago
Please update to three.js 0.82.1 as specified in the package.json
.
Running the example like this:
node examples/render-to-png.js
produces the correct output in temp/example.png
:
I changed my version of three to 82.1 and it started rendering this time the issue is that the model I'm rendering has no lighting
I'm trying to render an OBJ and MTL file with three-obj-loader and three-mtl-loader
Does the softwarerenderer use lights correctly?
const THREE = require("three");
const SoftwareRenderer = require("three-software-renderer");
const PNG = require("pngjs").PNG;
const fs = require("fs");
var OBJLoader = require('three-obj-loader');
OBJLoader(THREE)
var MTLLoader = require('three-mtl-loader');
var canvasInfo = {
x: 512,
y: 512
}
init();
function init() {
max = new THREE.Vector3(0.445184, 0.396998, 0.305262).length() * 4
normal = 1000
camFar = Math.max(max, normal)
camera = new THREE.PerspectiveCamera(70, canvasInfo.x / canvasInfo.y, 0.1, camFar);
var mtlLoader = new MTLLoader();
var objLoader = new THREE.OBJLoader()
var textureData = PNG.sync.read(fs.readFileSync('469.png'))
const tex = new THREE.DataTexture(
Uint8Array.from(textureData.data),
textureData.width,
textureData.height,
THREE.RGBAFormat,
THREE.UnsignedByteType,
THREE.UVMapping
)
tex.needsUpdate = true
camera.position.set(-0.890368, 0.453712, -1.452706);
scene = new THREE.Scene();
var ambient = new THREE.AmbientLight(0x999999, 0);
var hemisphereLight = new THREE.HemisphereLight(0x404040)
var spotLight = new THREE.SpotLight(0xdfdfde, 1)
scene.add(ambient);
scene.add(hemisphereLight);
spotLight.position.set(-50, 30, 0);
scene.add(spotLight);
mtlLoader.load('469.mtl', function(materials) {
materials.preload()
objLoader.load('469.obj', function(object) {
object.traverse(function(child) {
if (child instanceof THREE.Mesh) {
child.material = new
THREE.MeshPhongMaterial({
color: 0x999999,
shininess: 10,
map: tex,
shading: THREE.SmoothShading
})
}
})
scene.add(object);
camera.lookAt(object.position)
spotLight.target = object
scene.add(spotLight.target);
});
})
renderer = new SoftwareRenderer();
render();
}
function render() {
renderer.setSize(canvasInfo.x, canvasInfo.y);
var imagedata = renderer.render(scene, camera);
console.log('making image')
const png = new PNG({
width: canvasInfo.x,
height: canvasInfo.y
});
for(var i=0;i<imagedata.data.length;i++) {
png.data[i] = imagedata.data[i];
}
png.pack().pipe(fs.createWriteStream("output.png"));
console.log('image saved')
}
This is the image produced
Nevermind, did not realize that meshphongmaterial is not supported and falls back to a mesh that doesnt support mapping i fixed it by changing the material used
none of the examples actually do anything the image they output is a blank image im using threejs version 71.1