我需要支持编辑生成3D模型的脚本。然而,我一直在努力,因为我一直在犯错误。
function handleImage(e) {
var reader = new FileReader();
reader.onload = function(event) {
var img = new Image();
img.onload = function() {
canvas.width = img.width;
canvas.height = img.height;
ctx.drawImage(img, 0, 0);
var imgData = ctx.getImageData(0, 0, canvas.width, canvas.height);
var out = [];
// convert image to grayscale and save in array
for (var i = 0; i < imgData.data.length; i += 4) {
var avg = (imgData.data[i] + imgData.data[i + 1] + imgData.data[i + 2]) / 3;
imgData.data[i] = avg;
imgData.data[i + 1] = avg;
imgData.data[i + 2] = avg;
imgData.data[i + 3] = 255;
out.push(avg / 255);
}
ctx.putImageData(imgData, 0, 0);
output.value = JSON.stringify(out);
}
img.src = event.target.result;
}
reader.readAsDataURL(e.target.files[0]);
}
&#13;
<label>Image File:</label>
<br/>
<input type="file" id="imageLoader" name="imageLoader" />
<canvas id="imageCanvas"></canvas>
<textarea rows="10" cols="100" id="output"></textarea>
&#13;
代码应该创建一个类似于this link中的图像的3D文件。我想要的图像是使用OpenJSCAD或OpenSCAD软件在3D模型上。