STL loading from the Hard Drive

HI guys, I’m a really entry level newby, tring to play a little bit to evaluate the upgrade from my VB 3D engine to the Babylon.

Actually I’m trying to load a STL file from my hdd, tried to write down the file path as I used to have on VB but didn’t work properly.

var Tavola = BABYLON.SceneLoader.ImportMesh("", “”, “C:/PC3D/47900 Models/Table.stl”, scene, function (newMeshes) {
Tavola = newMeshes[0];
Tavola.position=new BABYLON.Vector3(25,10,0);
Tavola.scaling=new BABYLON.Vector3(10,10,10);
Tavmat = new BABYLON.StandardMaterial(“Tavmat”, scene);
Tavola.material = Tavmat;
Tavmat.diffuseColor = new BABYLON.Color3(1,0.5,1);
});

What am I doing wrong?

P.S. Happy to have been acepted on this forum. Nice to meet all you!

Cheers,
Edu

Hi Eduardo,

Are you using localhost to serve the HTML/Javascript file that has the code you posted above? For example, one method is using Node.js Express.

I think due to security reasons, we can’t load assets from our hard drive simply from double-clicking an index.html file.

1 Like

Yep you have to use a local webserver, and also to use relative link.

BJS have a doc’ page about setup a webserver: How to setup a local webserver for BabylonJs - Babylon.js Documentation but IMO it’s too complicated. I’ve a tiny article on my website with better solutions for non-dev: Use a local webserver - Nothing-is-3D (I think I should update the BJS page with these solutions also).

2 Likes

You can also use Python 3 if you have it installed.

Go to the directory with your index.html using a command prompt and type
“python -m http.server”

In your browser go to “localhost:8000”
To refresh the page us ctrl+F5

Put the files you want to load in your project directory or a sub directory and load like this, “./sub directory/file.jpg”
This will still work when you upload to a web server.

3 Likes

Thank you very much guys, I created the web server with IIS, loaded my project as index.html inside wwwroot of inetpub and used the path to localhost/filename.stl Worked like a charm.

Bellow the code:
var Tavola = BABYLON.SceneLoader.ImportMesh("", “”, “http://localhost/SKFFinishedPart.stl”, scene, function (newMeshes){
Tavola = newMeshes[0];
Tavola.position=new BABYLON.Vector3(25,10,0);
Tavola.scaling=new BABYLON.Vector3(0.01,0.01,0.01);
c1mat = new BABYLON.StandardMaterial(“c1mat”, scene);
Tavola.material = c1mat;
c1mat.diffuseColor = new BABYLON.Color3(0.5,0.5,0.5);
});

Cheers,
Edu

2 Likes

Instead of absolute path like “http://localhost/SKFFinishedPart.stl”, use a relative one like “SKFFinishedPart.stl” (or “./SKFFinishedPart.stl”) as JFerret suggested, this way you’ll be able to push online without issue later :wink:

1 Like