diff --git a/src/export.cpp b/src/export.cpp index b6baa9a5..9c99a3a4 100644 --- a/src/export.cpp +++ b/src/export.cpp @@ -304,20 +304,25 @@ void SolveSpaceUI::ExportLinesAndMesh(SEdgeList *sel, SBezierList *sbl, SMesh *s } } - // Use the BSP routines to generate the split triangles in paint order. - SBsp3 *bsp = SBsp3::FromMesh(&smp); SMesh sms = {}; - if(bsp) bsp->GenerateInPaintOrder(&sms); - // And cull the back-facing triangles - STriangle *tr; - sms.l.ClearTags(); - for(tr = sms.l.First(); tr; tr = sms.l.NextAfter(tr)) { - Vector n = tr->Normal(); - if(n.z < 0) { - tr->tag = 1; + + // We need the mesh for occlusion testing, but if we don't/can't export it, + // don't generate it. + if(SS.GW.showShaded && out->CanOutputMesh()) { + // Use the BSP routines to generate the split triangles in paint order. + SBsp3 *bsp = SBsp3::FromMesh(&smp); + if(bsp) bsp->GenerateInPaintOrder(&sms); + // And cull the back-facing triangles + STriangle *tr; + sms.l.ClearTags(); + for(tr = sms.l.First(); tr; tr = sms.l.NextAfter(tr)) { + Vector n = tr->Normal(); + if(n.z < 0) { + tr->tag = 1; + } } + sms.l.RemoveTagged(); } - sms.l.RemoveTagged(); // And now we perform hidden line removal if requested SEdgeList hlrd = {}; @@ -516,12 +521,6 @@ void SolveSpaceUI::ExportLinesAndMesh(SEdgeList *sel, SBezierList *sbl, SMesh *s sblss.AddOpenPath(b); } - // We need the mesh for occlusion testing, but if we don't export it, - // erase it now. - if(!SS.GW.showShaded) { - sms.Clear(); - } - // Now write the lines and triangles to the output file out->OutputLinesAndMesh(&sblss, &sms); diff --git a/src/solvespace.h b/src/solvespace.h index c92b08bc..757c3ff3 100644 --- a/src/solvespace.h +++ b/src/solvespace.h @@ -500,8 +500,8 @@ public: void BezierAsPwl(SBezier *sb); void BezierAsNonrationalCubic(SBezier *sb, int depth=0); - virtual bool OutputConstraints(IdList *constraint) - { return false; } + virtual bool OutputConstraints(IdList *constraint) { return false; } + virtual bool CanOutputMesh() const { return false; } virtual void StartPath( RgbaColor strokeRgb, double lineWidth, bool filled, RgbaColor fillRgb, hStyle hs) = 0; @@ -549,6 +549,7 @@ public: void StartFile(void); void FinishAndCloseFile(void); bool HasCanvasSize(void) { return true; } + bool CanOutputMesh() const { return true; } }; class PdfFileWriter : public VectorFileWriter { public: @@ -566,6 +567,7 @@ public: void StartFile(void); void FinishAndCloseFile(void); bool HasCanvasSize(void) { return true; } + bool CanOutputMesh() const { return true; } }; class SvgFileWriter : public VectorFileWriter { public: @@ -581,6 +583,7 @@ public: void StartFile(void); void FinishAndCloseFile(void); bool HasCanvasSize(void) { return true; } + bool CanOutputMesh() const { return true; } }; class HpglFileWriter : public VectorFileWriter { public: