ravi2493 / jsc3d

Automatically exported from code.google.com/p/jsc3d
0 stars 0 forks source link

Unable to reset scenes. Old STL data is retained. #44

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. I have code which uses the FileReader object and StlLoader.parseStl to 
preview files locally. The application is intended to only preview one STL file 
at a time. When the first file is loaded I call functions init_viewer() and 
init_scene() and then load the file. If the user previews additional files, 
init_viewer and init_scene are called, however the geometry of the old files is 
visible as a flicker when the user does a mouse move. 

What is the expected output? What do you see instead?
-Expected should be normal rendered view of the most recently loaded STL file. 
Instead, when there is a mouse-move all previously loaded geometry is visible 
as a flicker. 

What version of the product are you using? On what operating system?
1.4.2, on ubuntu. 

Please provide any additional information below.

Relevant code: 

var handle_file_select = function(e) {
    e.stopPropagation()
    e.preventDefault()
    var viewer
    var theScene
    var f = e.target.files[0]
    var reader = new FileReader()
    var ext = f.name.split(".")[1]
    var mycanvas = document.getElementById('upload_canvas');
    var stl_loader = new JSC3D.StlLoader()

    function init_viewer() {
        viewer = new JSC3D.Viewer(mycanvas);
        viewer.setParameter('InitRotationX', 20);
        viewer.setParameter('InitRotationY', 20);
        viewer.setParameter('InitRotationZ', 0);
        viewer.setParameter('ModelColor', '#CAA618');
        viewer.setParameter('BackgroundColor1', '#FFFFFF');
        viewer.setParameter('BackgroundColor2', '#383840');
        viewer.setParameter('RenderMode', "flat");
    }

    function init_scene() {
        theScene = new JSC3D.Scene
        if (!(theScene.isEmpty)) {
            console.log(theScene)
        }
    }

    reader.onload = (function(file) {
        return function(e) {
            console.log("old scene: ", theScene)
            init_viewer()
            init_scene()
            stl_loader.parseStl(theScene, e.target.result)
            viewer.init()
            viewer.replaceScene(theScene)
            viewer.update()
        }
    })(f)

    if (ext.toLowerCase() != "stl") {
        alert("That doesn't appear to be an STL file.");
    } else {
        reader.readAsBinaryString(f)
    }
}

Sorry to post twice today!

Original issue reported on code.google.com by liav.ko...@gmail.com on 2 Oct 2013 at 12:42

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
It seems you just uses a single stl_loader object to load mutiple models. Try 
creating a new instance of JSC3D.StlLoader() each time when you are to load a 
new STL file:

    reader.onload = (function(file) {
        return function(e) {
            ...
            stl_loader = new JSC3D.StlLoader();
            stl_loader.parseStl(theScene, e.target.result);
            ...
        };
    }

Additionally, I notice that in init_viewer() you create a new instance of 
JSC3D.Viewer each time a new model is loaded, which results in multiple viewers 
attached to a same canvas. It should be avoided by moving init_viewer():

    function init_viewer() {
        viewer = new JSC3D.Viewer(mycanvas);
        ...
        viewer.init();
        viewer.update();
    }

to the very beginning of the script and executed only once.

Original comment by Humu2...@gmail.com on 2 Oct 2013 at 4:25

GoogleCodeExporter commented 9 years ago
Hi Humu. I refactored reader.onload to:

reader.onload = (function(file) {
    return function(e) {
        theScene = new JSC3D.Scene
            stl_loader = new JSC3D.StlLoader()
            stl_loader.parseStl(theScene, e.target.result)
            viewer.init()
            viewer.replaceScene(theScene)
            viewer.update()
    }
})(f)

The flicker of old geometry is still there, however -- see the attached screen 
photo. (I had to take a photo of my screen because screen-capture doesn't show 
the effect.)

Original comment by liav.ko...@gmail.com on 2 Oct 2013 at 3:24

Attachments:

GoogleCodeExporter commented 9 years ago
It looks strange. Are you sure there is only a single instance of JSC3D.Viewer 
in your application?

Original comment by Humu2...@gmail.com on 2 Oct 2013 at 4:23

GoogleCodeExporter commented 9 years ago
The only code that touch JSC3d on that page is the code I've posted here. After 
upload there's a redirect to a results page with another canvas/JSC3D instance, 
which pulls STLs from the server. That one works fine.

The issue appears on Chrome and Firefox under both Ubuntu 12.04 and Win7. 

Original comment by liav.ko...@gmail.com on 2 Oct 2013 at 11:43

GoogleCodeExporter commented 9 years ago
Hi, Liav, could you show me some runnable stuff that can reproduce the issue?

Original comment by Humu2...@gmail.com on 3 Oct 2013 at 6:39

GoogleCodeExporter commented 9 years ago
Hi Humu. I sent you the IP for a testing server. 

Original comment by liav.ko...@gmail.com on 3 Oct 2013 at 3:48

GoogleCodeExporter commented 9 years ago
Thanks Liav! I'll see it as soon as possible.

Original comment by Humu2...@gmail.com on 3 Oct 2013 at 3:57