omrips / viewstl

Viewstl Javascript plugin - STL/OBJ 3D files Viewer by viewstl.com
MIT License
200 stars 49 forks source link

set_grid method produce "Uncaught ReferenceError: THREE is not defined" #26

Open ldenisey opened 2 years ago

ldenisey commented 2 years ago

Thanks for your work. I am starting to use it. Using release 1.13, adding set_grid call from base example :

<!DOCTYPE html>
<html>
<head>
    <script src="viewstl/stl_viewer.min.js"></script>
</head>
<body>
<div id="stl_cont"></div>
<script>
            var stl_viewer=new StlViewer
            (
                document.getElementById("stl_cont"),
                {
                    models:
                    [{filename:
                    "../cube.stl"
                    }]
                }
            );
            stl_viewer.set_grid(true);
</script>
</body>
</html>

The script loading are automatically added in the head section (including three.min.js), the stl is showed, but not the grid., The error is "Uncaught ReferenceError: THREE is not defined at StlViewer.set_grid (stl_viewer.min.js:2:6412)".

Also, there is a typo in the documentation : set_grid (b), size, divisions instead of set_grid (b, size, divisions).

omrips commented 2 years ago

Hi, thanks for the heads up!

I think you should use "stl_viewer.set_grid(...)" instead of "StlViewer.set_grid(...)"

I fixed the typo - thanks :D

ldenisey commented 2 years ago

Thanks for the example. I fixed the formatting on my original message, it was quite messy. I indeed used "stl_viewer.set_grid(true)". If I remove this line and add a button like you do in your example in the code snippet, it works without error. Any idea why and how I can have it work without any button ?