greeenphp / jsc3d

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

Replace multi-file scene with multiple stl files #76

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
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 madb...@gmail.com on 19 Jun 2014 at 9:09

Attachments:

GoogleCodeExporter commented 9 years ago
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 Humu2...@gmail.com on 27 Jun 2014 at 11:38

GoogleCodeExporter commented 9 years ago
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 madb...@gmail.com on 9 Jul 2014 at 8:56

GoogleCodeExporter commented 9 years ago
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 Humu2...@gmail.com on 10 Jul 2014 at 11:32