chetto1983 / jsc3d

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

stl image #101

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
can jsc3d output a render of the stl file as an image?

Original issue reported on code.google.com by 3do...@gmail.com on 14 Aug 2014 at 10:23

GoogleCodeExporter commented 8 years ago
Do you mean taking screenshots? That's easy. Use canvas.toDataURL() to turn the 
render result to data URI and export it as an image. This discussion 
http://code.google.com/p/jsc3d/issues/detail?id=55 porides a very detailed talk 
on this topic.

If you are to apply the output of Jsc3d viewer to an existing image on page, 
you can first create a viewer object with a hidden canvas (a canvas not in the 
dom tree). Load and render your stl file as usual. Then convert the canvas data 
to data URI using the method mentioned above and set your image.src property 
with it.  It should be noted that since file loading is asynchronous, your 
codes should be wrapped in a call-back function which will be invoked when the 
model is ready:

  // crerate the viewer with a hidden canvas and initialize it as usual
  ...
  viewer.onloadingcomplete = function() {
    yourImage.src = canvas.toDataURL('image/png');
  };

That's it.

Original comment by Humu2...@gmail.com on 15 Aug 2014 at 2:41