My current project involves creating a web application that allows users to upload and view STL files generated by MATLAB code. However, I'm encountering difficulties when it comes to passing parameters in the STL load function.
As I searched for solutions, I came across a helpful thread on user uploaded textures in three.js which I attempted to follow.
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$('#blah').html( e.target.result);
console.log(e.target.result);
var loader = new THREE.STLLoader();
loader.load(e.target.result) , function ( geometry ) {
var material = new THREE.MeshPhongMaterial( { color: 0xff5533, specular: 0x111111, shininess: 200 } );
var mesh = new THREE.Mesh( geometry, material );
mesh.position.set( 0, - 0.25, 0.6 );
mesh.rotation.set( 0, - Math.PI / 2, 0 );
mesh.scale.set( 0.005, 0.005, 0.005 );
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add( mesh );
} );
}
reader.readAsDataURL(input.files[0]);
}
}
$("#imgInp").change(function () {
readURL(this);
});
I am hopeful that the STL model will be successfully rendered on the web app.