jsc3d icon indicating copy to clipboard operation
jsc3d copied to clipboard

Replace multi-file scene with multiple stl files

Open GoogleCodeExporter opened this issue 10 years ago • 3 comments

Hello,
I followed the issues item to add multiple stl files into a single view, which 
works fine.
What I need to do next is to allow for a checkbox click to trigger the 
replacement of the stl files with a different set of files.  I found the issue 
where a single file is replaced, but I need to replace the scene with multiple 
files.
Some parts of the function are working since when I change the 
colors[newLoaded] to newLoaded+1 I get a color change, but I cannot replace the 
actual files.
Thanks


Original issue reported on code.google.com by [email protected] on 19 Jun 2014 at 9:09

Attachments:

GoogleCodeExporter avatar Jul 29 '15 04:07 GoogleCodeExporter

I'm sorry for the late reply!

I just took a quick look into your code and I didn't find any obvious mistake. 
Is it because you forget to update to show the result after the replacement? 
Try to add this single line to newModelLoaded():

  var newModelLoaded = function(scene) {
    ...
    if (++newLoaded == components.length)
      viewer.replaceScene(newScene);
  };

  =>

  var newModelLoaded = function(scene) {
    ...
    if (++newLoaded == components.length) {
      viewer.replaceScene(newScene);
      viewer.update();
    }
  };

It tells the viewer to render a new frame using the new scene.

Besides, I suggest you move the initialization codes to be prior to any 
functional operation of the viewer instance to avoid unnecessary troubles.

Original comment by [email protected] on 27 Jun 2014 at 11:38

GoogleCodeExporter avatar Jul 29 '15 04:07 GoogleCodeExporter

Thanks for the reply. 
I actually went with a "properties" approach.  Because I am displaying multiple 
canvases on the same page the whole thing is wrapped in a for loop, j counter.

function updateview (name,value) {
// Show/hide parts of the models.  Will change all canvases at once.
    var newScene = [];
    var changeMesh = []
    for (var j = 1; j<= numlabs; j++) {
        newScene[j] = viewer[j].getScene();
        changeMesh[j] = newScene[j].getChildren()[name];
        if (value == 1) {changeMesh[j].visible = true;}
           else {changeMesh[j].visible = false;}
        viewer[j].update();
    }
};

Original comment by [email protected] on 9 Jul 2014 at 8:56

GoogleCodeExporter avatar Jul 29 '15 04:07 GoogleCodeExporter

Good! I think this approach should work fine in your application circumstance. 
When a mesh is set to invisible, its runtime cost is trivial.

Original comment by [email protected] on 10 Jul 2014 at 11:32

GoogleCodeExporter avatar Jul 29 '15 04:07 GoogleCodeExporter