Only generate split triangles when exporting if needed.

Before this commit, when exporting a vector file without the shaded
model shown, or similarly when using formats that we do not export
the mesh to, we still generate (and then discard) the mesh in paint
order. This is a waste of time.
pull/4/head
EvilSpirit 2016-04-28 17:10:36 +06:00 committed by whitequark
parent a75bf6e216
commit e1f614101f
2 changed files with 21 additions and 19 deletions

View File

@ -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);

View File

@ -500,8 +500,8 @@ public:
void BezierAsPwl(SBezier *sb);
void BezierAsNonrationalCubic(SBezier *sb, int depth=0);
virtual bool OutputConstraints(IdList<Constraint,hConstraint> *constraint)
{ return false; }
virtual bool OutputConstraints(IdList<Constraint,hConstraint> *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: