diff options
author | don bright <hugh.m.bright@gmail.com> | 2013-02-25 03:07:37 (GMT) |
---|---|---|
committer | don bright <hugh.m.bright@gmail.com> | 2013-02-25 03:07:37 (GMT) |
commit | 9896b6f15eced6d05a131ece44d60745e200b8f5 (patch) | |
tree | 7d8a362003174ed6b150c439f2827d6a7252674d /src/export_png.cc | |
parent | 8738cdc03451803014ca84f8614bdff1ff393ca9 (diff) |
first working version of opencsg png export from gui binary
also guiopencsgtest introduced. passes 100% of 'normal' tests
Diffstat (limited to 'src/export_png.cc')
-rw-r--r-- | src/export_png.cc | 39 |
1 files changed, 37 insertions, 2 deletions
diff --git a/src/export_png.cc b/src/export_png.cc index 179278a..0626c71 100644 --- a/src/export_png.cc +++ b/src/export_png.cc @@ -46,15 +46,50 @@ void export_png_with_cgal(CGAL_Nef_polyhedron *root_N, std::ostream &output) csgInfo.glview->save(output); } -void export_png_with_opencsg(CGAL_Nef_polyhedron *root_N, std::ostream &output) +#ifdef ENABLE_OPENCSG +#include "OpenCSGRenderer.h" +#include <opencsg.h> +#endif + +void export_png_with_opencsg(Tree &tree, std::ostream &output) { - CsgInfo csgInfo; +#ifdef ENABLE_OPENCSG + CsgInfo_OpenCSG csgInfo = CsgInfo_OpenCSG(); + AbstractNode const *root_node = tree.root(); + int result = opencsg_prep( tree, root_node, csgInfo ); + if ( result == 1 ) { + return; + fprintf(stderr,"Couldn't init OpenCSG chainsn"); + } + try { csgInfo.glview = new OffscreenView(512,512); } catch (int error) { fprintf(stderr,"Can't create OpenGL OffscreenView. Code: %i.\n", error); return; } + + OpenCSGRenderer opencsgRenderer(csgInfo.root_chain, csgInfo.highlights_chain, csgInfo.background_chain, csgInfo.glview->shaderinfo); + + Vector3d center(0,0,0); + double radius = 1.0; + if (csgInfo.root_chain) { + BoundingBox bbox = csgInfo.root_chain->getBoundingBox(); + center = (bbox.min() + bbox.max()) / 2; + radius = (bbox.max() - bbox.min()).norm() / 2; + } + + Vector3d cameradir(1, 1, -0.5); + Vector3d camerapos = center - radius*1.8*cameradir; + csgInfo.glview->setCamera(camerapos, center); + csgInfo.glview->setRenderer(&opencsgRenderer); + OpenCSG::setContext(0); + OpenCSG::setOption(OpenCSG::OffscreenSetting, OpenCSG::FrameBufferObject); + csgInfo.glview->paintGL(); + csgInfo.glview->save(output); +#else + fprintf(stderr,"This openscad was built without OpenCSG support\n"); +#endif } |