I'm in the process of developing a server/webpage with the following functionality:
- Users can upload an .stl file to be 3D-printed
- The server executes a mesh repair script on the uploaded .stl file
- The corrected .stl file is displayed in the user's browser for verification, ensuring that the script did not negatively impact the file
One challenge I'm encountering pertains to step 3. I am attempting to utilize an example from the three.js repository to render the .stl file:
https://github.com/mrdoob/three.js/blob/master/examples/webgl_loader_stl.html
The issue arises when the model within the .stl file is too large, causing it to extend beyond view. To rectify this and ensure the entire model is visible within the camera frame, adjustments need to be made to the parameters within the mesh.scale.set(x, y, z) function in the following code snippet:
var loader = new THREE.STLLoader();
loader.addEventListener( 'load', function ( event ) {
var geometry = event.content;
var mesh = new THREE.Mesh( geometry, material );
mesh.position.set( 0, - 0.37, 0 );
mesh.rotation.set( - Math.PI / 2, 0, 0 );
mesh.scale.set( 2, 2, 2 );
mesh.castShadow = true;
mesh.receiveShadow = true;
scene.add( mesh );
} );
loader.load( './models/stl/binary/pr2_head_tilt.stl' );
However, my goal is to automatically determine the size of the model in the .stl file and adjust its scale accordingly.
This feature is achievable, as demonstrated by GitHub's STL file viewer. You can experience this functionality by visiting the link below and selecting one of the .stl files:
https://github.com/mrdoob/three.js/tree/master/examples/models/stl/binary
In essence, the GitHub STL file viewer exemplifies what I aim to replicate, seamlessly loading any .stl file without necessitating manual zooming in or out for proper visualization of the model.