Welcome to the free online STL viewer!
View 3D STL files directly in your browser - no software installation is required.
We upload nothing to our server - everything is done client side.
Communicate with / alter model at runtime
When Viewstl is embeded in your site, you can still control it (replace model, set color, set display mode etc.) and get info (volume, size, etc.) - here is how:
Prerequisites
1. Some knownledge in Javascript, as the communication is done only through Javascript commands.
2. Giving an id to the Viewstl's Iframe. At the generated code the default id is "vs_iframe" - we'll use this id at the code snippets below.
3. you have to make sure the Iframe is fully loaded before sending it messages. You can do something like this:
document.getElementById("vs_iframe").onload=function()
{
//... your code here ...
}
Get model info
Use the code below in order to get model info - name, volume, size and color:
document.getElementById("vs_iframe").contentWindow.postMessage('info', '*');
* Please notice - you have to make sure the Iframe is fully loaded before sending it messages (see above)!
Ths code above only sends a message to the Iframe. In order to get the actual info - we need to listen for its answer ... this is how:
window.onmessage = function(e)
{
if (e.origin=="http://www.viewstl.com")
{
alert("Model filename: "+e.data.filename);
alert("Volume: "+e.data.volume);
alert("Color: "+e.data.color);
alert("x: "+e.data.x);
alert("y: "+e.data.y);
alert("z: "+e.data.z);
}
};
As you can see, the returned value is an object with 6 fields:
Filename: The model's filename
Volume: The model's volume (in mm^3 or in^3, depends on file's units)
x / y / z: The model's dimensions (in mm or in, depends on file's units)
Color: The model's color (RGB string value)
Load model by URL
Use the code below in order to load (or re-load) model from an Internet address (URL):
document.getElementById("vs_iframe").contentWindow.postMessage({msg_type:'load', url:'<your url here>'}, '*');
Replace "<your url here>" with a valid URL
Load model from a local file
You can read a model file from the user's local computer. However, for security reasons, it is impossible for you to determine which file to load.
- You must first present the user with a file browsing dialog (or file dragging ability), and only then, send the file to Viewstl.com Iframe
Example for file browsing button (HTML code):
<input type="file" value="internal file" id="fileselect" onchange="load_local_file(this.files[0]);">
The Javascript code:
function load_local_file(f)
{
document.getElementById("vs_iframe").contentWindow.postMessage({msg_type:'load', file:f}, '*');
}
* this option does not work in FireFox