2009-07-08 09:44:13 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// The 2d vector output stuff that isn't specific to any particular file
|
|
|
|
// format: getting the appropriate lines and curves, performing hidden line
|
|
|
|
// removal, calculating bounding boxes, and so on. Also raster and triangle
|
|
|
|
// mesh output.
|
2013-07-28 22:08:34 +00:00
|
|
|
//
|
|
|
|
// Copyright 2008-2013 Jonathan Westhues.
|
2009-07-08 09:44:13 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
2008-07-08 07:45:47 +00:00
|
|
|
#include "solvespace.h"
|
|
|
|
|
2015-12-27 01:03:24 +00:00
|
|
|
void SolveSpaceUI::ExportSectionTo(const std::string &filename) {
|
2008-07-08 07:45:47 +00:00
|
|
|
Vector gn = (SS.GW.projRight).Cross(SS.GW.projUp);
|
|
|
|
gn = gn.WithMagnitude(1);
|
|
|
|
|
2009-04-19 05:53:16 +00:00
|
|
|
Group *g = SK.GetGroup(SS.GW.activeGroup);
|
2009-05-21 09:06:26 +00:00
|
|
|
g->GenerateDisplayItems();
|
2009-05-24 11:37:07 +00:00
|
|
|
if(g->displayMesh.IsEmpty()) {
|
2009-01-14 05:10:42 +00:00
|
|
|
Error("No solid model present; draw one with extrudes and revolves, "
|
|
|
|
"or use Export 2d View to export bare lines and curves.");
|
|
|
|
return;
|
|
|
|
}
|
2015-03-29 00:30:52 +00:00
|
|
|
|
2008-07-08 07:45:47 +00:00
|
|
|
// The plane in which the exported section lies; need this because we'll
|
|
|
|
// reorient from that plane into the xy plane before exporting.
|
2009-01-14 05:10:42 +00:00
|
|
|
Vector origin, u, v, n;
|
2008-07-08 07:45:47 +00:00
|
|
|
double d;
|
|
|
|
|
2009-01-14 05:10:42 +00:00
|
|
|
SS.GW.GroupSelection();
|
2016-10-10 12:34:10 +00:00
|
|
|
auto const &gs = SS.GW.gs;
|
2009-01-14 05:10:42 +00:00
|
|
|
if((gs.n == 0 && g->activeWorkplane.v != Entity::FREE_IN_3D.v)) {
|
2009-04-19 05:53:16 +00:00
|
|
|
Entity *wrkpl = SK.GetEntity(g->activeWorkplane);
|
2009-01-14 05:10:42 +00:00
|
|
|
origin = wrkpl->WorkplaneGetOffset();
|
|
|
|
n = wrkpl->Normal()->NormalN();
|
|
|
|
u = wrkpl->Normal()->NormalU();
|
|
|
|
v = wrkpl->Normal()->NormalV();
|
|
|
|
} else if(gs.n == 1 && gs.faces == 1) {
|
2009-04-19 05:53:16 +00:00
|
|
|
Entity *face = SK.GetEntity(gs.entity[0]);
|
2009-01-14 05:10:42 +00:00
|
|
|
origin = face->FaceGetPointNum();
|
|
|
|
n = face->FaceGetNormalNum();
|
2008-07-08 07:45:47 +00:00
|
|
|
if(n.Dot(gn) < 0) n = n.ScaledBy(-1);
|
|
|
|
u = n.Normal(0);
|
|
|
|
v = n.Normal(1);
|
2009-01-14 05:10:42 +00:00
|
|
|
} else if(gs.n == 3 && gs.vectors == 2 && gs.points == 1) {
|
2009-04-19 05:53:16 +00:00
|
|
|
Vector ut = SK.GetEntity(gs.entity[0])->VectorGetNum(),
|
|
|
|
vt = SK.GetEntity(gs.entity[1])->VectorGetNum();
|
2009-01-14 05:10:42 +00:00
|
|
|
ut = ut.WithMagnitude(1);
|
|
|
|
vt = vt.WithMagnitude(1);
|
|
|
|
|
|
|
|
if(fabs(SS.GW.projUp.Dot(vt)) < fabs(SS.GW.projUp.Dot(ut))) {
|
2015-03-27 15:43:28 +00:00
|
|
|
swap(ut, vt);
|
2009-01-14 05:10:42 +00:00
|
|
|
}
|
|
|
|
if(SS.GW.projRight.Dot(ut) < 0) ut = ut.ScaledBy(-1);
|
|
|
|
if(SS.GW.projUp. Dot(vt) < 0) vt = vt.ScaledBy(-1);
|
|
|
|
|
2009-04-19 05:53:16 +00:00
|
|
|
origin = SK.GetEntity(gs.point[0])->PointGetNum();
|
2009-01-14 05:10:42 +00:00
|
|
|
n = ut.Cross(vt);
|
|
|
|
u = ut.WithMagnitude(1);
|
|
|
|
v = (n.Cross(u)).WithMagnitude(1);
|
|
|
|
} else {
|
2010-01-16 18:15:40 +00:00
|
|
|
Error("Bad selection for export section. Please select:\n\n"
|
2009-01-14 05:10:42 +00:00
|
|
|
" * nothing, with an active workplane "
|
2010-01-16 18:15:40 +00:00
|
|
|
"(workplane is section plane)\n"
|
|
|
|
" * a face (section plane through face)\n"
|
2009-01-14 05:10:42 +00:00
|
|
|
" * a point and two line segments "
|
2010-01-16 18:15:40 +00:00
|
|
|
"(plane through point and parallel to lines)\n");
|
2009-01-14 05:10:42 +00:00
|
|
|
return;
|
2008-07-08 07:45:47 +00:00
|
|
|
}
|
2009-01-14 05:10:42 +00:00
|
|
|
SS.GW.ClearSelection();
|
2008-07-08 07:45:47 +00:00
|
|
|
|
2009-01-14 05:10:42 +00:00
|
|
|
n = n.WithMagnitude(1);
|
|
|
|
d = origin.Dot(n);
|
2008-07-08 07:45:47 +00:00
|
|
|
|
2015-03-27 15:31:23 +00:00
|
|
|
SEdgeList el = {};
|
|
|
|
SBezierList bl = {};
|
2009-04-14 04:19:23 +00:00
|
|
|
|
2009-05-28 07:07:54 +00:00
|
|
|
// If there's a mesh, then grab the edges from it.
|
|
|
|
g->runningMesh.MakeEdgesInPlaneInto(&el, n, d);
|
|
|
|
|
|
|
|
// If there's a shell, then grab the edges and possibly Beziers.
|
2009-04-14 04:19:23 +00:00
|
|
|
g->runningShell.MakeSectionEdgesInto(n, d,
|
2015-03-29 00:30:52 +00:00
|
|
|
&el,
|
2009-04-16 04:42:51 +00:00
|
|
|
(SS.exportPwlCurves || fabs(SS.exportOffset) > LENGTH_EPS) ? NULL : &bl);
|
2009-04-14 04:19:23 +00:00
|
|
|
|
2009-09-22 05:46:30 +00:00
|
|
|
// All of these are solid model edges, so use the appropriate style.
|
|
|
|
SEdge *se;
|
|
|
|
for(se = el.l.First(); se; se = el.l.NextAfter(se)) {
|
|
|
|
se->auxA = Style::SOLID_EDGE;
|
|
|
|
}
|
|
|
|
SBezier *sb;
|
|
|
|
for(sb = bl.l.First(); sb; sb = bl.l.NextAfter(sb)) {
|
|
|
|
sb->auxA = Style::SOLID_EDGE;
|
|
|
|
}
|
|
|
|
|
2009-04-14 04:19:23 +00:00
|
|
|
el.CullExtraneousEdges();
|
2009-04-15 02:55:18 +00:00
|
|
|
bl.CullIdenticalBeziers();
|
2009-01-14 05:10:42 +00:00
|
|
|
|
2009-03-17 16:33:46 +00:00
|
|
|
// And write the edges.
|
2009-01-14 05:10:42 +00:00
|
|
|
VectorFileWriter *out = VectorFileWriter::ForFile(filename);
|
|
|
|
if(out) {
|
2009-03-17 16:33:46 +00:00
|
|
|
// parallel projection (no perspective), and no mesh
|
2009-04-14 04:19:23 +00:00
|
|
|
ExportLinesAndMesh(&el, &bl, NULL,
|
2009-03-17 16:33:46 +00:00
|
|
|
u, v, n, origin, 0,
|
|
|
|
out);
|
2009-01-14 05:10:42 +00:00
|
|
|
}
|
2009-03-17 16:33:46 +00:00
|
|
|
el.Clear();
|
2009-04-14 04:19:23 +00:00
|
|
|
bl.Clear();
|
2009-01-14 05:10:42 +00:00
|
|
|
}
|
2008-07-08 07:45:47 +00:00
|
|
|
|
Abstract all (ex-OpenGL) drawing operations into a Canvas interface.
This has several desirable consequences:
* It is now possible to port SolveSpace to a later version of
OpenGL, such as OpenGLES 2, so that it runs on platforms that
only have that OpenGL version;
* The majority of geometry is now rendered without references to
the camera in C++ code, so a renderer can now submit it to
the video card once and re-rasterize with a different projection
matrix every time the projection is changed, avoiding expensive
reuploads;
* The DOGD (draw or get distance) interface is now
a straightforward Canvas implementation;
* There are no more direct references to SS.GW.(projection)
in sketch rendering code, which allows rendering to multiple
viewports;
* There are no more unnecessary framebuffer flips on CPU on Cocoa
and GTK;
* The platform-dependent GL code is now confined to rendergl1.cpp.
* The Microsoft and Apple headers required by it that are prone to
identifier conflicts are no longer included globally;
* The rendergl1.cpp implementation can now be omitted from
compilation to run SolveSpace headless or with a different
OpenGL version.
Note these implementation details of Canvas:
* GetCamera currently always returns a reference to the field
`Camera camera;`. This is so that a future renderer that caches
geometry in the video memory can define it as asserting, which
would provide assurance against code that could accidentally
put something projection-dependent in the cache;
* Line and triangle rendering is specified through a level of
indirection, hStroke and hFill. This is so that a future renderer
that batches geometry could cheaply group identical styles.
* DrawPixmap and DrawVectorText accept a (o,u,v) and not a matrix.
This is so that a future renderer into an output format that
uses 2d transforms (e.g. SVG) could easily derive those.
Some additional internal changes were required to enable this:
* Pixmap is now always passed as std::shared_ptr<{const ,}Pixmap>.
This is so that the renderer could cache uploaded textures
between API calls, which requires it to capture a (weak)
reference.
* The PlatformPathEqual function was properly extracted into
platform-specific code. This is so that the <windows.h> header
could be included only where needed (in platform/w32* as well
as rendergl1.cpp).
* The SBsp{2,3}::DebugDraw functions were removed. They can be
rewritten using the Canvas API if they are ever needed.
While no visual changes were originally intended, some minor fixes
happened anyway:
* The "emphasis" yellow line from top-left corner is now correctly
rendered much wider.
* The marquee rectangle is now pixel grid aligned.
* The hidden entities now do not clobber the depth buffer, removing
some minor artifacts.
* The workplane "tab" now scales with the font used to render
the workplane name.
* The workplane name font is now taken from the normals style.
* Workplane and constraint line stipple is insignificantly
different. This is so that it can reuse the existing stipple
codepaths; rendering of workplanes and constraints predates
those.
Some debug functionality was added:
* In graphics window, an fps counter that becomes red when
rendering under 60fps is drawn.
2016-05-31 00:55:13 +00:00
|
|
|
// This is an awful temporary hack to replace Constraint::GetEdges until we have proper
|
|
|
|
// export through Canvas.
|
|
|
|
class GetEdgesCanvas : public Canvas {
|
|
|
|
public:
|
|
|
|
Camera camera;
|
|
|
|
SEdgeList *edges;
|
|
|
|
|
|
|
|
const Camera &GetCamera() const override {
|
|
|
|
return camera;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DrawLine(const Vector &a, const Vector &b, hStroke hcs) override {
|
|
|
|
edges->AddEdge(a, b, Style::CONSTRAINT);
|
|
|
|
}
|
|
|
|
void DrawEdges(const SEdgeList &el, hStroke hcs) override {
|
|
|
|
for(const SEdge &e : el.l) {
|
|
|
|
edges->AddEdge(e.a, e.b, Style::CONSTRAINT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void DrawVectorText(const std::string &text, double height,
|
|
|
|
const Vector &o, const Vector &u, const Vector &v,
|
|
|
|
hStroke hcs) override {
|
|
|
|
auto traceEdge = [&](Vector a, Vector b) { edges->AddEdge(a, b, Style::CONSTRAINT); };
|
|
|
|
VectorFont::Builtin()->Trace(height, o, u, v, text, traceEdge, camera);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DrawQuad(const Vector &a, const Vector &b, const Vector &c, const Vector &d,
|
|
|
|
hFill hcf) override {
|
|
|
|
// Do nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DrawBeziers(const SBezierList &bl, hStroke hcs) override {
|
|
|
|
ssassert(false, "Not implemented");
|
|
|
|
}
|
2016-06-26 06:39:27 +00:00
|
|
|
void DrawOutlines(const SOutlineList &ol, hStroke hcs, DrawOutlinesAs drawAs) override {
|
Abstract all (ex-OpenGL) drawing operations into a Canvas interface.
This has several desirable consequences:
* It is now possible to port SolveSpace to a later version of
OpenGL, such as OpenGLES 2, so that it runs on platforms that
only have that OpenGL version;
* The majority of geometry is now rendered without references to
the camera in C++ code, so a renderer can now submit it to
the video card once and re-rasterize with a different projection
matrix every time the projection is changed, avoiding expensive
reuploads;
* The DOGD (draw or get distance) interface is now
a straightforward Canvas implementation;
* There are no more direct references to SS.GW.(projection)
in sketch rendering code, which allows rendering to multiple
viewports;
* There are no more unnecessary framebuffer flips on CPU on Cocoa
and GTK;
* The platform-dependent GL code is now confined to rendergl1.cpp.
* The Microsoft and Apple headers required by it that are prone to
identifier conflicts are no longer included globally;
* The rendergl1.cpp implementation can now be omitted from
compilation to run SolveSpace headless or with a different
OpenGL version.
Note these implementation details of Canvas:
* GetCamera currently always returns a reference to the field
`Camera camera;`. This is so that a future renderer that caches
geometry in the video memory can define it as asserting, which
would provide assurance against code that could accidentally
put something projection-dependent in the cache;
* Line and triangle rendering is specified through a level of
indirection, hStroke and hFill. This is so that a future renderer
that batches geometry could cheaply group identical styles.
* DrawPixmap and DrawVectorText accept a (o,u,v) and not a matrix.
This is so that a future renderer into an output format that
uses 2d transforms (e.g. SVG) could easily derive those.
Some additional internal changes were required to enable this:
* Pixmap is now always passed as std::shared_ptr<{const ,}Pixmap>.
This is so that the renderer could cache uploaded textures
between API calls, which requires it to capture a (weak)
reference.
* The PlatformPathEqual function was properly extracted into
platform-specific code. This is so that the <windows.h> header
could be included only where needed (in platform/w32* as well
as rendergl1.cpp).
* The SBsp{2,3}::DebugDraw functions were removed. They can be
rewritten using the Canvas API if they are ever needed.
While no visual changes were originally intended, some minor fixes
happened anyway:
* The "emphasis" yellow line from top-left corner is now correctly
rendered much wider.
* The marquee rectangle is now pixel grid aligned.
* The hidden entities now do not clobber the depth buffer, removing
some minor artifacts.
* The workplane "tab" now scales with the font used to render
the workplane name.
* The workplane name font is now taken from the normals style.
* Workplane and constraint line stipple is insignificantly
different. This is so that it can reuse the existing stipple
codepaths; rendering of workplanes and constraints predates
those.
Some debug functionality was added:
* In graphics window, an fps counter that becomes red when
rendering under 60fps is drawn.
2016-05-31 00:55:13 +00:00
|
|
|
ssassert(false, "Not implemented");
|
|
|
|
}
|
|
|
|
void DrawPoint(const Vector &o, double d, hFill hcf) override {
|
|
|
|
ssassert(false, "Not implemented");
|
|
|
|
}
|
|
|
|
void DrawPolygon(const SPolygon &p, hFill hcf) override {
|
|
|
|
ssassert(false, "Not implemented");
|
|
|
|
}
|
|
|
|
void DrawMesh(const SMesh &m, hFill hcfFront, hFill hcfBack = {},
|
|
|
|
hStroke hcsTriangles = {}) override {
|
|
|
|
ssassert(false, "Not implemented");
|
|
|
|
}
|
|
|
|
void DrawFaces(const SMesh &m, const std::vector<uint32_t> &faces, hFill hcf) override {
|
|
|
|
ssassert(false, "Not implemented");
|
|
|
|
}
|
|
|
|
void DrawPixmap(std::shared_ptr<const Pixmap> pm,
|
|
|
|
const Vector &o, const Vector &u, const Vector &v,
|
|
|
|
const Point2d &ta, const Point2d &tb, hFill hcf) override {
|
|
|
|
ssassert(false, "Not implemented");
|
|
|
|
}
|
|
|
|
void InvalidatePixmap(std::shared_ptr<const Pixmap> pm) override {
|
|
|
|
ssassert(false, "Not implemented");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-05-25 12:08:19 +00:00
|
|
|
void SolveSpaceUI::ExportViewOrWireframeTo(const std::string &filename, bool exportWireframe) {
|
2009-01-14 05:10:42 +00:00
|
|
|
int i;
|
2015-03-27 15:31:23 +00:00
|
|
|
SEdgeList edges = {};
|
|
|
|
SBezierList beziers = {};
|
2008-07-08 07:45:47 +00:00
|
|
|
|
2016-01-06 12:40:17 +00:00
|
|
|
VectorFileWriter *out = VectorFileWriter::ForFile(filename);
|
|
|
|
if(!out) return;
|
|
|
|
|
2016-01-27 04:07:54 +00:00
|
|
|
SS.exportMode = true;
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
GenerateAll(Generate::ALL);
|
2016-01-27 04:07:54 +00:00
|
|
|
|
2009-03-17 16:33:46 +00:00
|
|
|
SMesh *sm = NULL;
|
2016-08-13 09:02:12 +00:00
|
|
|
if(SS.GW.showShaded || SS.GW.drawOccludedAs != GraphicsWindow::DrawOccludedAs::VISIBLE) {
|
2009-05-21 09:06:26 +00:00
|
|
|
Group *g = SK.GetGroup(SS.GW.activeGroup);
|
|
|
|
g->GenerateDisplayItems();
|
|
|
|
sm = &(g->displayMesh);
|
2009-03-17 16:33:46 +00:00
|
|
|
}
|
2009-09-22 06:47:11 +00:00
|
|
|
if(sm && sm->IsEmpty()) {
|
2009-04-15 02:55:18 +00:00
|
|
|
sm = NULL;
|
|
|
|
}
|
2008-07-08 07:45:47 +00:00
|
|
|
|
2009-04-19 05:53:16 +00:00
|
|
|
for(i = 0; i < SK.entity.n; i++) {
|
|
|
|
Entity *e = &(SK.entity.elem[i]);
|
2009-04-14 04:19:23 +00:00
|
|
|
if(!e->IsVisible()) continue;
|
2009-04-16 04:42:51 +00:00
|
|
|
if(e->construction) continue;
|
2009-04-14 04:19:23 +00:00
|
|
|
|
2016-03-09 04:53:46 +00:00
|
|
|
if(SS.exportPwlCurves || sm || fabs(SS.exportOffset) > LENGTH_EPS)
|
2009-04-16 04:42:51 +00:00
|
|
|
{
|
2009-04-14 04:19:23 +00:00
|
|
|
// We will be doing hidden line removal, which we can't do on
|
2009-04-16 04:42:51 +00:00
|
|
|
// exact curves; so we need things broken down to pwls. Same
|
|
|
|
// problem with cutter radius compensation.
|
2009-04-14 04:19:23 +00:00
|
|
|
e->GenerateEdges(&edges);
|
|
|
|
} else {
|
|
|
|
e->GenerateBezierCurves(&beziers);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-14 00:55:27 +00:00
|
|
|
if(SS.GW.showEdges || SS.GW.showOutlines) {
|
2009-05-21 09:06:26 +00:00
|
|
|
Group *g = SK.GetGroup(SS.GW.activeGroup);
|
|
|
|
g->GenerateDisplayItems();
|
2016-08-14 00:55:27 +00:00
|
|
|
if(SS.GW.showEdges) {
|
|
|
|
g->displayOutlines.ListTaggedInto(&edges, Style::SOLID_EDGE);
|
|
|
|
}
|
2009-03-18 04:26:04 +00:00
|
|
|
}
|
|
|
|
|
2009-07-03 20:55:57 +00:00
|
|
|
if(SS.GW.showConstraints) {
|
2016-01-06 12:40:17 +00:00
|
|
|
if(!out->OutputConstraints(&SK.constraint)) {
|
Abstract all (ex-OpenGL) drawing operations into a Canvas interface.
This has several desirable consequences:
* It is now possible to port SolveSpace to a later version of
OpenGL, such as OpenGLES 2, so that it runs on platforms that
only have that OpenGL version;
* The majority of geometry is now rendered without references to
the camera in C++ code, so a renderer can now submit it to
the video card once and re-rasterize with a different projection
matrix every time the projection is changed, avoiding expensive
reuploads;
* The DOGD (draw or get distance) interface is now
a straightforward Canvas implementation;
* There are no more direct references to SS.GW.(projection)
in sketch rendering code, which allows rendering to multiple
viewports;
* There are no more unnecessary framebuffer flips on CPU on Cocoa
and GTK;
* The platform-dependent GL code is now confined to rendergl1.cpp.
* The Microsoft and Apple headers required by it that are prone to
identifier conflicts are no longer included globally;
* The rendergl1.cpp implementation can now be omitted from
compilation to run SolveSpace headless or with a different
OpenGL version.
Note these implementation details of Canvas:
* GetCamera currently always returns a reference to the field
`Camera camera;`. This is so that a future renderer that caches
geometry in the video memory can define it as asserting, which
would provide assurance against code that could accidentally
put something projection-dependent in the cache;
* Line and triangle rendering is specified through a level of
indirection, hStroke and hFill. This is so that a future renderer
that batches geometry could cheaply group identical styles.
* DrawPixmap and DrawVectorText accept a (o,u,v) and not a matrix.
This is so that a future renderer into an output format that
uses 2d transforms (e.g. SVG) could easily derive those.
Some additional internal changes were required to enable this:
* Pixmap is now always passed as std::shared_ptr<{const ,}Pixmap>.
This is so that the renderer could cache uploaded textures
between API calls, which requires it to capture a (weak)
reference.
* The PlatformPathEqual function was properly extracted into
platform-specific code. This is so that the <windows.h> header
could be included only where needed (in platform/w32* as well
as rendergl1.cpp).
* The SBsp{2,3}::DebugDraw functions were removed. They can be
rewritten using the Canvas API if they are ever needed.
While no visual changes were originally intended, some minor fixes
happened anyway:
* The "emphasis" yellow line from top-left corner is now correctly
rendered much wider.
* The marquee rectangle is now pixel grid aligned.
* The hidden entities now do not clobber the depth buffer, removing
some minor artifacts.
* The workplane "tab" now scales with the font used to render
the workplane name.
* The workplane name font is now taken from the normals style.
* Workplane and constraint line stipple is insignificantly
different. This is so that it can reuse the existing stipple
codepaths; rendering of workplanes and constraints predates
those.
Some debug functionality was added:
* In graphics window, an fps counter that becomes red when
rendering under 60fps is drawn.
2016-05-31 00:55:13 +00:00
|
|
|
GetEdgesCanvas canvas = {};
|
|
|
|
canvas.camera = SS.GW.GetCamera();
|
|
|
|
canvas.edges = &edges;
|
|
|
|
|
2016-01-06 12:40:17 +00:00
|
|
|
// The output format cannot represent constraints directly,
|
|
|
|
// so convert them to edges.
|
Abstract all (ex-OpenGL) drawing operations into a Canvas interface.
This has several desirable consequences:
* It is now possible to port SolveSpace to a later version of
OpenGL, such as OpenGLES 2, so that it runs on platforms that
only have that OpenGL version;
* The majority of geometry is now rendered without references to
the camera in C++ code, so a renderer can now submit it to
the video card once and re-rasterize with a different projection
matrix every time the projection is changed, avoiding expensive
reuploads;
* The DOGD (draw or get distance) interface is now
a straightforward Canvas implementation;
* There are no more direct references to SS.GW.(projection)
in sketch rendering code, which allows rendering to multiple
viewports;
* There are no more unnecessary framebuffer flips on CPU on Cocoa
and GTK;
* The platform-dependent GL code is now confined to rendergl1.cpp.
* The Microsoft and Apple headers required by it that are prone to
identifier conflicts are no longer included globally;
* The rendergl1.cpp implementation can now be omitted from
compilation to run SolveSpace headless or with a different
OpenGL version.
Note these implementation details of Canvas:
* GetCamera currently always returns a reference to the field
`Camera camera;`. This is so that a future renderer that caches
geometry in the video memory can define it as asserting, which
would provide assurance against code that could accidentally
put something projection-dependent in the cache;
* Line and triangle rendering is specified through a level of
indirection, hStroke and hFill. This is so that a future renderer
that batches geometry could cheaply group identical styles.
* DrawPixmap and DrawVectorText accept a (o,u,v) and not a matrix.
This is so that a future renderer into an output format that
uses 2d transforms (e.g. SVG) could easily derive those.
Some additional internal changes were required to enable this:
* Pixmap is now always passed as std::shared_ptr<{const ,}Pixmap>.
This is so that the renderer could cache uploaded textures
between API calls, which requires it to capture a (weak)
reference.
* The PlatformPathEqual function was properly extracted into
platform-specific code. This is so that the <windows.h> header
could be included only where needed (in platform/w32* as well
as rendergl1.cpp).
* The SBsp{2,3}::DebugDraw functions were removed. They can be
rewritten using the Canvas API if they are ever needed.
While no visual changes were originally intended, some minor fixes
happened anyway:
* The "emphasis" yellow line from top-left corner is now correctly
rendered much wider.
* The marquee rectangle is now pixel grid aligned.
* The hidden entities now do not clobber the depth buffer, removing
some minor artifacts.
* The workplane "tab" now scales with the font used to render
the workplane name.
* The workplane name font is now taken from the normals style.
* Workplane and constraint line stipple is insignificantly
different. This is so that it can reuse the existing stipple
codepaths; rendering of workplanes and constraints predates
those.
Some debug functionality was added:
* In graphics window, an fps counter that becomes red when
rendering under 60fps is drawn.
2016-05-31 00:55:13 +00:00
|
|
|
for(Constraint &c : SK.constraint) {
|
|
|
|
c.Draw(Constraint::DrawAs::DEFAULT, &canvas);
|
2016-01-06 12:40:17 +00:00
|
|
|
}
|
2016-08-07 19:33:42 +00:00
|
|
|
|
|
|
|
canvas.Clear();
|
2009-07-03 20:55:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-25 12:08:19 +00:00
|
|
|
if(exportWireframe) {
|
2016-01-06 12:40:17 +00:00
|
|
|
Vector u = Vector::From(1.0, 0.0, 0.0),
|
|
|
|
v = Vector::From(0.0, 1.0, 0.0),
|
|
|
|
n = Vector::From(0.0, 0.0, 1.0),
|
|
|
|
origin = Vector::From(0.0, 0.0, 0.0);
|
|
|
|
double cameraTan = 0.0,
|
|
|
|
scale = 1.0;
|
|
|
|
|
|
|
|
out->SetModelviewProjection(u, v, n, origin, cameraTan, scale);
|
|
|
|
|
|
|
|
ExportWireframeCurves(&edges, &beziers, out);
|
2009-10-12 10:40:48 +00:00
|
|
|
} else {
|
|
|
|
Vector u = SS.GW.projRight,
|
|
|
|
v = SS.GW.projUp,
|
|
|
|
n = u.Cross(v),
|
|
|
|
origin = SS.GW.offset.ScaledBy(-1);
|
|
|
|
|
2016-01-06 12:40:17 +00:00
|
|
|
out->SetModelviewProjection(u, v, n, origin,
|
|
|
|
SS.CameraTangent()*SS.GW.scale, SS.exportScale);
|
2010-01-14 05:24:32 +00:00
|
|
|
|
2016-01-06 12:40:17 +00:00
|
|
|
ExportLinesAndMesh(&edges, &beziers, sm,
|
|
|
|
u, v, n, origin, SS.CameraTangent()*SS.GW.scale,
|
|
|
|
out);
|
|
|
|
|
|
|
|
if(!out->HasCanvasSize()) {
|
2010-01-14 05:24:32 +00:00
|
|
|
// These file formats don't have a canvas size, so they just
|
|
|
|
// get exported in the raw coordinate system. So indicate what
|
|
|
|
// that was on-screen.
|
2016-01-27 04:07:54 +00:00
|
|
|
SS.justExportedInfo.showOrigin = true;
|
2010-01-14 05:24:32 +00:00
|
|
|
SS.justExportedInfo.pt = origin;
|
|
|
|
SS.justExportedInfo.u = u;
|
|
|
|
SS.justExportedInfo.v = v;
|
2016-01-27 04:07:54 +00:00
|
|
|
} else {
|
|
|
|
SS.justExportedInfo.showOrigin = false;
|
2010-01-14 05:24:32 +00:00
|
|
|
}
|
2016-01-27 04:07:54 +00:00
|
|
|
|
|
|
|
SS.justExportedInfo.draw = true;
|
|
|
|
InvalidateGraphics();
|
2009-01-14 05:10:42 +00:00
|
|
|
}
|
2009-10-12 10:40:48 +00:00
|
|
|
|
2009-01-14 05:10:42 +00:00
|
|
|
edges.Clear();
|
2009-04-14 04:19:23 +00:00
|
|
|
beziers.Clear();
|
2009-01-14 05:10:42 +00:00
|
|
|
}
|
2008-07-08 07:45:47 +00:00
|
|
|
|
2015-03-23 17:49:04 +00:00
|
|
|
void SolveSpaceUI::ExportWireframeCurves(SEdgeList *sel, SBezierList *sbl,
|
2009-10-12 10:40:48 +00:00
|
|
|
VectorFileWriter *out)
|
|
|
|
{
|
2015-03-27 15:31:23 +00:00
|
|
|
SBezierLoopSetSet sblss = {};
|
2009-10-12 10:40:48 +00:00
|
|
|
SEdge *se;
|
|
|
|
for(se = sel->l.First(); se; se = sel->l.NextAfter(se)) {
|
2009-10-30 10:38:34 +00:00
|
|
|
SBezier sb = SBezier::From(
|
|
|
|
(se->a).ScaledBy(1.0 / SS.exportScale),
|
|
|
|
(se->b).ScaledBy(1.0 / SS.exportScale));
|
|
|
|
sblss.AddOpenPath(&sb);
|
|
|
|
}
|
|
|
|
|
|
|
|
sbl->ScaleSelfBy(1.0/SS.exportScale);
|
|
|
|
SBezier *sb;
|
|
|
|
for(sb = sbl->l.First(); sb; sb = sbl->l.NextAfter(sb)) {
|
|
|
|
sblss.AddOpenPath(sb);
|
2009-10-12 10:40:48 +00:00
|
|
|
}
|
2009-10-30 10:38:34 +00:00
|
|
|
|
2016-01-06 12:40:17 +00:00
|
|
|
out->OutputLinesAndMesh(&sblss, NULL);
|
2009-10-30 10:38:34 +00:00
|
|
|
sblss.Clear();
|
2009-10-12 10:40:48 +00:00
|
|
|
}
|
|
|
|
|
2015-03-23 17:49:04 +00:00
|
|
|
void SolveSpaceUI::ExportLinesAndMesh(SEdgeList *sel, SBezierList *sbl, SMesh *sm,
|
2016-05-21 05:18:00 +00:00
|
|
|
Vector u, Vector v, Vector n,
|
|
|
|
Vector origin, double cameraTan,
|
|
|
|
VectorFileWriter *out)
|
2009-01-14 05:10:42 +00:00
|
|
|
{
|
2009-03-17 16:33:46 +00:00
|
|
|
double s = 1.0 / SS.exportScale;
|
|
|
|
|
2008-08-14 08:28:25 +00:00
|
|
|
// Project into the export plane; so when we're done, z doesn't matter,
|
|
|
|
// and x and y are what goes in the DXF.
|
2009-03-17 16:33:46 +00:00
|
|
|
SEdge *e;
|
|
|
|
for(e = sel->l.First(); e; e = sel->l.NextAfter(e)) {
|
|
|
|
// project into the specified csys, and apply export scale
|
|
|
|
(e->a) = e->a.InPerspective(u, v, n, origin, cameraTan).ScaledBy(s);
|
|
|
|
(e->b) = e->b.InPerspective(u, v, n, origin, cameraTan).ScaledBy(s);
|
2008-08-14 08:28:25 +00:00
|
|
|
}
|
|
|
|
|
2009-04-14 04:19:23 +00:00
|
|
|
SBezier *b;
|
|
|
|
if(sbl) {
|
|
|
|
for(b = sbl->l.First(); b; b = sbl->l.NextAfter(b)) {
|
|
|
|
*b = b->InPerspective(u, v, n, origin, cameraTan);
|
|
|
|
int i;
|
|
|
|
for(i = 0; i <= b->deg; i++) {
|
|
|
|
b->ctrl[i] = (b->ctrl[i]).ScaledBy(s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-17 16:33:46 +00:00
|
|
|
// If cutter radius compensation is requested, then perform it now
|
2008-08-14 08:28:25 +00:00
|
|
|
if(fabs(SS.exportOffset) > LENGTH_EPS) {
|
2009-03-17 16:33:46 +00:00
|
|
|
// assemble those edges into a polygon, and clear the edge list
|
2015-03-27 15:31:23 +00:00
|
|
|
SPolygon sp = {};
|
2009-03-17 16:33:46 +00:00
|
|
|
sel->AssemblePolygon(&sp, NULL);
|
|
|
|
sel->Clear();
|
|
|
|
|
2015-03-27 15:31:23 +00:00
|
|
|
SPolygon compd = {};
|
2009-03-17 16:33:46 +00:00
|
|
|
sp.normal = Vector::From(0, 0, -1);
|
|
|
|
sp.FixContourDirections();
|
2009-09-03 08:13:09 +00:00
|
|
|
sp.OffsetInto(&compd, SS.exportOffset*s);
|
2009-03-17 16:33:46 +00:00
|
|
|
sp.Clear();
|
|
|
|
|
|
|
|
compd.MakeEdgesInto(sel);
|
|
|
|
compd.Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now the triangle mesh; project, then build a BSP to perform
|
|
|
|
// occlusion testing and generated the shaded surfaces.
|
2015-03-27 15:31:23 +00:00
|
|
|
SMesh smp = {};
|
2009-03-17 16:33:46 +00:00
|
|
|
if(sm) {
|
|
|
|
Vector l0 = (SS.lightDir[0]).WithMagnitude(1),
|
|
|
|
l1 = (SS.lightDir[1]).WithMagnitude(1);
|
|
|
|
STriangle *tr;
|
|
|
|
for(tr = sm->l.First(); tr; tr = sm->l.NextAfter(tr)) {
|
|
|
|
STriangle tt = *tr;
|
|
|
|
tt.a = (tt.a).InPerspective(u, v, n, origin, cameraTan).ScaledBy(s);
|
|
|
|
tt.b = (tt.b).InPerspective(u, v, n, origin, cameraTan).ScaledBy(s);
|
|
|
|
tt.c = (tt.c).InPerspective(u, v, n, origin, cameraTan).ScaledBy(s);
|
|
|
|
|
|
|
|
// And calculate lighting for the triangle
|
|
|
|
Vector n = tt.Normal().WithMagnitude(1);
|
|
|
|
double lighting = SS.ambientIntensity +
|
2015-03-27 15:43:28 +00:00
|
|
|
max(0.0, (SS.lightIntensity[0])*(n.Dot(l0))) +
|
|
|
|
max(0.0, (SS.lightIntensity[1])*(n.Dot(l1)));
|
|
|
|
double r = min(1.0, tt.meta.color.redF() * lighting),
|
|
|
|
g = min(1.0, tt.meta.color.greenF() * lighting),
|
|
|
|
b = min(1.0, tt.meta.color.blueF() * lighting);
|
2009-03-17 16:33:46 +00:00
|
|
|
tt.meta.color = RGBf(r, g, b);
|
|
|
|
smp.AddTriangle(&tt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-27 15:31:23 +00:00
|
|
|
SMesh sms = {};
|
2016-04-28 11:10:36 +00:00
|
|
|
|
|
|
|
// 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;
|
|
|
|
}
|
2009-03-17 16:33:46 +00:00
|
|
|
}
|
2016-04-28 11:10:36 +00:00
|
|
|
sms.l.RemoveTagged();
|
2009-03-17 16:33:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// And now we perform hidden line removal if requested
|
2015-03-27 15:31:23 +00:00
|
|
|
SEdgeList hlrd = {};
|
2016-03-09 04:53:46 +00:00
|
|
|
if(sm) {
|
2009-03-17 16:33:46 +00:00
|
|
|
SKdNode *root = SKdNode::From(&smp);
|
2009-03-18 04:26:04 +00:00
|
|
|
|
|
|
|
// Generate the edges where a curved surface turns from front-facing
|
|
|
|
// to back-facing.
|
2016-08-14 00:55:27 +00:00
|
|
|
if(SS.GW.showEdges || SS.GW.showOutlines) {
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
root->MakeCertainEdgesInto(sel, EdgeKind::TURNING,
|
2016-03-14 16:14:24 +00:00
|
|
|
/*coplanarIsInter=*/false, NULL, NULL,
|
|
|
|
GW.showOutlines ? Style::OUTLINE : Style::SOLID_EDGE);
|
2009-03-18 04:26:04 +00:00
|
|
|
}
|
|
|
|
|
2009-03-17 16:33:46 +00:00
|
|
|
root->ClearTags();
|
|
|
|
int cnt = 1234;
|
|
|
|
|
|
|
|
SEdge *se;
|
|
|
|
for(se = sel->l.First(); se; se = sel->l.NextAfter(se)) {
|
2009-09-22 06:47:11 +00:00
|
|
|
if(se->auxA == Style::CONSTRAINT) {
|
|
|
|
// Constraints should not get hidden line removed; they're
|
|
|
|
// always on top.
|
|
|
|
hlrd.AddEdge(se->a, se->b, se->auxA);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-03-09 04:53:46 +00:00
|
|
|
SEdgeList edges = {};
|
2009-03-17 16:33:46 +00:00
|
|
|
// Split the original edge against the mesh
|
2016-03-09 04:53:46 +00:00
|
|
|
edges.AddEdge(se->a, se->b, se->auxA);
|
2016-07-21 20:27:53 +00:00
|
|
|
root->OcclusionTestLine(*se, &edges, cnt);
|
2016-08-13 09:02:12 +00:00
|
|
|
if(SS.GW.drawOccludedAs == GraphicsWindow::DrawOccludedAs::STIPPLED) {
|
2016-07-21 20:27:53 +00:00
|
|
|
for(SEdge &se : edges.l) {
|
|
|
|
if(se.tag == 1) {
|
|
|
|
se.auxA = Style::HIDDEN_EDGE;
|
|
|
|
}
|
|
|
|
}
|
2016-08-13 09:02:12 +00:00
|
|
|
} else if(SS.GW.drawOccludedAs == GraphicsWindow::DrawOccludedAs::INVISIBLE) {
|
2016-07-21 20:27:53 +00:00
|
|
|
edges.l.RemoveTagged();
|
|
|
|
}
|
|
|
|
|
2009-04-08 04:54:07 +00:00
|
|
|
// the occlusion test splits unnecessarily; so fix those
|
2016-03-09 04:53:46 +00:00
|
|
|
edges.MergeCollinearSegments(se->a, se->b);
|
2009-03-17 16:33:46 +00:00
|
|
|
cnt++;
|
|
|
|
// And add the results to our output
|
|
|
|
SEdge *sen;
|
2016-03-09 04:53:46 +00:00
|
|
|
for(sen = edges.l.First(); sen; sen = edges.l.NextAfter(sen)) {
|
2009-09-22 06:47:11 +00:00
|
|
|
hlrd.AddEdge(sen->a, sen->b, sen->auxA);
|
2009-03-17 16:33:46 +00:00
|
|
|
}
|
2016-03-09 04:53:46 +00:00
|
|
|
edges.Clear();
|
2009-03-17 16:33:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sel = &hlrd;
|
2009-01-14 05:10:42 +00:00
|
|
|
}
|
|
|
|
|
2016-03-13 09:27:59 +00:00
|
|
|
// Clean up: remove overlapping line segments and
|
|
|
|
// segments with zero-length projections.
|
|
|
|
sel->l.ClearTags();
|
|
|
|
for(int i = 0; i < sel->l.n; ++i) {
|
|
|
|
SEdge *sei = &sel->l.elem[i];
|
|
|
|
hStyle hsi = { (uint32_t)sei->auxA };
|
|
|
|
Style *si = Style::Get(hsi);
|
|
|
|
if(sei->tag != 0) continue;
|
|
|
|
|
|
|
|
// Remove segments with zero length projections.
|
|
|
|
Vector ai = sei->a;
|
|
|
|
ai.z = 0.0;
|
|
|
|
Vector bi = sei->b;
|
|
|
|
bi.z = 0.0;
|
|
|
|
Vector di = bi.Minus(ai);
|
|
|
|
if(fabs(di.x) < LENGTH_EPS && fabs(di.y) < LENGTH_EPS) {
|
|
|
|
sei->tag = 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(int j = i + 1; j < sel->l.n; ++j) {
|
|
|
|
SEdge *sej = &sel->l.elem[j];
|
|
|
|
if(sej->tag != 0) continue;
|
|
|
|
|
|
|
|
Vector *pAj = &sej->a;
|
|
|
|
Vector *pBj = &sej->b;
|
|
|
|
|
|
|
|
// Remove segments with zero length projections.
|
|
|
|
Vector aj = sej->a;
|
|
|
|
aj.z = 0.0;
|
|
|
|
Vector bj = sej->b;
|
|
|
|
bj.z = 0.0;
|
|
|
|
Vector dj = bj.Minus(aj);
|
|
|
|
if(fabs(dj.x) < LENGTH_EPS && fabs(dj.y) < LENGTH_EPS) {
|
|
|
|
sej->tag = 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Skip non-collinear segments.
|
|
|
|
const double eps = 1e-6;
|
|
|
|
if(aj.DistanceToLine(ai, di) > eps) continue;
|
|
|
|
if(bj.DistanceToLine(ai, di) > eps) continue;
|
|
|
|
|
|
|
|
double ta = aj.Minus(ai).Dot(di) / di.Dot(di);
|
|
|
|
double tb = bj.Minus(ai).Dot(di) / di.Dot(di);
|
|
|
|
if(ta > tb) {
|
|
|
|
std::swap(pAj, pBj);
|
|
|
|
std::swap(ta, tb);
|
|
|
|
}
|
|
|
|
|
|
|
|
hStyle hsj = { (uint32_t)sej->auxA };
|
|
|
|
Style *sj = Style::Get(hsj);
|
|
|
|
|
|
|
|
bool canRemoveI = sej->auxA == sei->auxA || si->zIndex < sj->zIndex;
|
|
|
|
bool canRemoveJ = sej->auxA == sei->auxA || sj->zIndex < si->zIndex;
|
|
|
|
|
|
|
|
if(canRemoveJ) {
|
|
|
|
// j-segment inside i-segment
|
|
|
|
if(ta > 0.0 - eps && tb < 1.0 + eps) {
|
|
|
|
sej->tag = 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// cut segment
|
|
|
|
bool aInside = ta > 0.0 - eps && ta < 1.0 + eps;
|
|
|
|
if(tb > 1.0 - eps && aInside) {
|
|
|
|
*pAj = sei->b;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// cut segment
|
|
|
|
bool bInside = tb > 0.0 - eps && tb < 1.0 + eps;
|
|
|
|
if(ta < 0.0 - eps && bInside) {
|
|
|
|
*pBj = sei->a;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// split segment
|
|
|
|
if(ta < 0.0 - eps && tb > 1.0 + eps) {
|
|
|
|
sel->AddEdge(sei->b, *pBj, sej->auxA, sej->auxB);
|
|
|
|
*pBj = sei->a;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(canRemoveI) {
|
|
|
|
// j-segment inside i-segment
|
|
|
|
if(ta < 0.0 + eps && tb > 1.0 - eps) {
|
|
|
|
sei->tag = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// cut segment
|
|
|
|
bool aInside = ta > 0.0 + eps && ta < 1.0 - eps;
|
|
|
|
if(tb > 1.0 - eps && aInside) {
|
|
|
|
sei->b = *pAj;
|
|
|
|
i--;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// cut segment
|
|
|
|
bool bInside = tb > 0.0 + eps && tb < 1.0 - eps;
|
|
|
|
if(ta < 0.0 + eps && bInside) {
|
|
|
|
sei->a = *pBj;
|
|
|
|
i--;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// split segment
|
|
|
|
if(ta > 0.0 + eps && tb < 1.0 - eps) {
|
|
|
|
sel->AddEdge(*pBj, sei->b, sei->auxA, sei->auxB);
|
|
|
|
sei->b = *pAj;
|
|
|
|
i--;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sel->l.RemoveTagged();
|
|
|
|
|
2009-10-30 10:38:34 +00:00
|
|
|
// We kept the line segments and Beziers separate until now; but put them
|
|
|
|
// all together, and also project everything into the xy plane, since not
|
|
|
|
// all export targets ignore the z component of the points.
|
|
|
|
for(e = sel->l.First(); e; e = sel->l.NextAfter(e)) {
|
|
|
|
SBezier sb = SBezier::From(e->a, e->b);
|
|
|
|
sb.auxA = e->auxA;
|
|
|
|
sbl->l.Add(&sb);
|
|
|
|
}
|
|
|
|
for(b = sbl->l.First(); b; b = sbl->l.NextAfter(b)) {
|
|
|
|
for(int i = 0; i <= b->deg; i++) {
|
|
|
|
b->ctrl[i].z = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If possible, then we will assemble these output curves into loops. They
|
|
|
|
// will then get exported as closed paths.
|
2015-03-27 15:31:23 +00:00
|
|
|
SBezierLoopSetSet sblss = {};
|
|
|
|
SBezierList leftovers = {};
|
2009-10-30 10:38:34 +00:00
|
|
|
SSurface srf = SSurface::FromPlane(Vector::From(0, 0, 0),
|
|
|
|
Vector::From(1, 0, 0),
|
|
|
|
Vector::From(0, 1, 0));
|
2015-03-27 15:31:23 +00:00
|
|
|
SPolygon spxyz = {};
|
2009-10-30 10:38:34 +00:00
|
|
|
bool allClosed;
|
|
|
|
SEdge notClosedAt;
|
|
|
|
sbl->l.ClearTags();
|
|
|
|
sblss.FindOuterFacesFrom(sbl, &spxyz, &srf,
|
2016-01-27 04:07:54 +00:00
|
|
|
SS.ExportChordTolMm(),
|
2009-10-30 10:38:34 +00:00
|
|
|
&allClosed, ¬ClosedAt,
|
|
|
|
NULL, NULL,
|
|
|
|
&leftovers);
|
|
|
|
for(b = leftovers.l.First(); b; b = leftovers.l.NextAfter(b)) {
|
|
|
|
sblss.AddOpenPath(b);
|
|
|
|
}
|
|
|
|
|
2009-03-17 16:33:46 +00:00
|
|
|
// Now write the lines and triangles to the output file
|
2016-01-06 12:40:17 +00:00
|
|
|
out->OutputLinesAndMesh(&sblss, &sms);
|
2009-03-17 16:33:46 +00:00
|
|
|
|
2009-10-30 10:38:34 +00:00
|
|
|
leftovers.Clear();
|
|
|
|
spxyz.Clear();
|
|
|
|
sblss.Clear();
|
2009-03-17 16:33:46 +00:00
|
|
|
smp.Clear();
|
|
|
|
sms.Clear();
|
|
|
|
hlrd.Clear();
|
2009-01-14 05:10:42 +00:00
|
|
|
}
|
|
|
|
|
2009-04-15 06:50:06 +00:00
|
|
|
double VectorFileWriter::MmToPts(double mm) {
|
|
|
|
// 72 points in an inch
|
|
|
|
return (mm/25.4)*72;
|
|
|
|
}
|
|
|
|
|
2015-12-27 01:03:24 +00:00
|
|
|
VectorFileWriter *VectorFileWriter::ForFile(const std::string &filename) {
|
2009-01-14 05:10:42 +00:00
|
|
|
VectorFileWriter *ret;
|
2015-12-25 08:29:08 +00:00
|
|
|
bool needOpen = true;
|
2015-12-27 01:03:24 +00:00
|
|
|
if(FilenameHasExtension(filename, ".dxf")) {
|
2009-01-14 05:10:42 +00:00
|
|
|
static DxfFileWriter DxfWriter;
|
|
|
|
ret = &DxfWriter;
|
2015-12-25 08:29:08 +00:00
|
|
|
needOpen = false;
|
2015-12-27 01:03:24 +00:00
|
|
|
} else if(FilenameHasExtension(filename, ".ps") || FilenameHasExtension(filename, ".eps")) {
|
2009-01-27 05:48:40 +00:00
|
|
|
static EpsFileWriter EpsWriter;
|
|
|
|
ret = &EpsWriter;
|
2015-12-27 01:03:24 +00:00
|
|
|
} else if(FilenameHasExtension(filename, ".pdf")) {
|
2009-04-15 06:50:06 +00:00
|
|
|
static PdfFileWriter PdfWriter;
|
|
|
|
ret = &PdfWriter;
|
2015-12-27 01:03:24 +00:00
|
|
|
} else if(FilenameHasExtension(filename, ".svg")) {
|
2009-01-27 05:48:40 +00:00
|
|
|
static SvgFileWriter SvgWriter;
|
|
|
|
ret = &SvgWriter;
|
2015-12-27 01:03:24 +00:00
|
|
|
} else if(FilenameHasExtension(filename, ".plt")||FilenameHasExtension(filename, ".hpgl")) {
|
2009-01-27 05:48:40 +00:00
|
|
|
static HpglFileWriter HpglWriter;
|
|
|
|
ret = &HpglWriter;
|
2015-12-27 01:03:24 +00:00
|
|
|
} else if(FilenameHasExtension(filename, ".step")||FilenameHasExtension(filename, ".stp")) {
|
2009-06-11 05:57:23 +00:00
|
|
|
static Step2dFileWriter Step2dWriter;
|
|
|
|
ret = &Step2dWriter;
|
2016-08-25 02:57:29 +00:00
|
|
|
} else if(FilenameHasExtension(filename, ".txt")||FilenameHasExtension(filename, ".ngc")) {
|
2010-01-14 04:47:17 +00:00
|
|
|
static GCodeFileWriter GCodeWriter;
|
|
|
|
ret = &GCodeWriter;
|
2009-01-14 05:10:42 +00:00
|
|
|
} else {
|
2009-01-27 05:48:40 +00:00
|
|
|
Error("Can't identify output file type from file extension of "
|
2010-01-14 04:47:17 +00:00
|
|
|
"filename '%s'; try "
|
2016-08-25 02:57:29 +00:00
|
|
|
".step, .stp, .dxf, .svg, .plt, .hpgl, .pdf, .txt, .ngc, "
|
2009-06-11 05:57:23 +00:00
|
|
|
".eps, or .ps.",
|
2015-12-27 01:03:24 +00:00
|
|
|
filename.c_str());
|
2009-01-14 05:10:42 +00:00
|
|
|
return NULL;
|
2008-08-14 08:28:25 +00:00
|
|
|
}
|
2015-12-25 08:29:08 +00:00
|
|
|
ret->filename = filename;
|
|
|
|
if(!needOpen) return ret;
|
2008-08-14 08:28:25 +00:00
|
|
|
|
2015-12-27 08:09:00 +00:00
|
|
|
FILE *f = ssfopen(filename, "wb");
|
2008-07-08 07:45:47 +00:00
|
|
|
if(!f) {
|
2015-12-27 01:03:24 +00:00
|
|
|
Error("Couldn't write to '%s'", filename.c_str());
|
2009-01-14 05:10:42 +00:00
|
|
|
return NULL;
|
2008-07-08 07:45:47 +00:00
|
|
|
}
|
2009-01-14 05:10:42 +00:00
|
|
|
ret->f = f;
|
|
|
|
return ret;
|
|
|
|
}
|
2008-07-08 07:45:47 +00:00
|
|
|
|
2016-01-06 12:40:17 +00:00
|
|
|
void VectorFileWriter::SetModelviewProjection(const Vector &u, const Vector &v, const Vector &n,
|
|
|
|
const Vector &origin, double cameraTan,
|
|
|
|
double scale) {
|
|
|
|
this->u = u;
|
|
|
|
this->v = v;
|
|
|
|
this->n = n;
|
|
|
|
this->origin = origin;
|
|
|
|
this->cameraTan = cameraTan;
|
|
|
|
this->scale = scale;
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector VectorFileWriter::Transform(Vector &pos) const {
|
|
|
|
return pos.InPerspective(u, v, n, origin, cameraTan).ScaledBy(1.0 / scale);
|
|
|
|
}
|
|
|
|
|
|
|
|
void VectorFileWriter::OutputLinesAndMesh(SBezierLoopSetSet *sblss, SMesh *sm) {
|
2009-03-17 16:33:46 +00:00
|
|
|
STriangle *tr;
|
2009-04-14 04:19:23 +00:00
|
|
|
SBezier *b;
|
2009-01-27 05:48:40 +00:00
|
|
|
|
|
|
|
// First calculate the bounding box.
|
|
|
|
ptMin = Vector::From(VERY_POSITIVE, VERY_POSITIVE, VERY_POSITIVE);
|
|
|
|
ptMax = Vector::From(VERY_NEGATIVE, VERY_NEGATIVE, VERY_NEGATIVE);
|
2009-03-17 16:33:46 +00:00
|
|
|
if(sm) {
|
|
|
|
for(tr = sm->l.First(); tr; tr = sm->l.NextAfter(tr)) {
|
|
|
|
(tr->a).MakeMaxMin(&ptMax, &ptMin);
|
|
|
|
(tr->b).MakeMaxMin(&ptMax, &ptMin);
|
|
|
|
(tr->c).MakeMaxMin(&ptMax, &ptMin);
|
2009-01-27 05:48:40 +00:00
|
|
|
}
|
|
|
|
}
|
2009-10-30 10:38:34 +00:00
|
|
|
if(sblss) {
|
|
|
|
SBezierLoopSet *sbls;
|
|
|
|
for(sbls = sblss->l.First(); sbls; sbls = sblss->l.NextAfter(sbls)) {
|
|
|
|
SBezierLoop *sbl;
|
|
|
|
for(sbl = sbls->l.First(); sbl; sbl = sbls->l.NextAfter(sbl)) {
|
|
|
|
for(b = sbl->l.First(); b; b = sbl->l.NextAfter(b)) {
|
|
|
|
for(int i = 0; i <= b->deg; i++) {
|
|
|
|
(b->ctrl[i]).MakeMaxMin(&ptMax, &ptMin);
|
|
|
|
}
|
|
|
|
}
|
2009-04-14 04:19:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-01-27 05:48:40 +00:00
|
|
|
|
2009-09-03 08:13:09 +00:00
|
|
|
// And now we compute the canvas size.
|
|
|
|
double s = 1.0 / SS.exportScale;
|
|
|
|
if(SS.exportCanvasSizeAuto) {
|
|
|
|
// It's based on the calculated bounding box; we grow it along each
|
|
|
|
// boundary by the specified amount.
|
|
|
|
ptMin.x -= s*SS.exportMargin.left;
|
|
|
|
ptMax.x += s*SS.exportMargin.right;
|
|
|
|
ptMin.y -= s*SS.exportMargin.bottom;
|
|
|
|
ptMax.y += s*SS.exportMargin.top;
|
|
|
|
} else {
|
|
|
|
ptMin.x = -(s*SS.exportCanvas.dx);
|
|
|
|
ptMin.y = -(s*SS.exportCanvas.dy);
|
|
|
|
ptMax.x = ptMin.x + (s*SS.exportCanvas.width);
|
|
|
|
ptMax.y = ptMin.y + (s*SS.exportCanvas.height);
|
|
|
|
}
|
|
|
|
|
2009-01-27 05:48:40 +00:00
|
|
|
StartFile();
|
2009-03-18 04:26:04 +00:00
|
|
|
if(sm && SS.exportShadedTriangles) {
|
2009-03-17 16:33:46 +00:00
|
|
|
for(tr = sm->l.First(); tr; tr = sm->l.NextAfter(tr)) {
|
|
|
|
Triangle(tr);
|
|
|
|
}
|
|
|
|
}
|
2009-10-30 10:38:34 +00:00
|
|
|
if(sblss) {
|
|
|
|
SBezierLoopSet *sbls;
|
|
|
|
for(sbls = sblss->l.First(); sbls; sbls = sblss->l.NextAfter(sbls)) {
|
|
|
|
SBezierLoop *sbl;
|
|
|
|
sbl = sbls->l.First();
|
|
|
|
if(!sbl) continue;
|
|
|
|
b = sbl->l.First();
|
|
|
|
if(!b || !Style::Exportable(b->auxA)) continue;
|
|
|
|
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 05:45:13 +00:00
|
|
|
hStyle hs = { (uint32_t)b->auxA };
|
2009-10-30 10:38:34 +00:00
|
|
|
Style *stl = Style::Get(hs);
|
Replaced RGB-color integers with dedicated data structure
RGB colors were represented using a uint32_t with the red, green and blue
values stuffed into the lower three octets (i.e. 0x00BBGGRR), like
Microsoft's COLORREF. This approach did not lend itself to type safety,
however, so this change replaces it with an RgbColor class that provides
the same infomation plus a handful of useful methods to work with it. (Note
that sizeof(RgbColor) == sizeof(uint32_t), so this change should not lead
to memory bloat.)
Some of the new methods/fields replace what were previously macro calls;
e.g. RED(c) is now c.red, REDf(c) is now c.redF(). The .Equals() method is
now used instead of == to compare colors.
RGB colors still need to be represented as packed integers in file I/O and
preferences, so the methods .FromPackedInt() and .ToPackedInt() are
provided. Also implemented are Cnf{Freeze,Thaw}Color(), type-safe wrappers
around Cnf{Freeze,Thaw}Int() that facilitate I/O with preferences.
(Cnf{Freeze,Thaw}Color() are defined outside of the system-dependent code
to minimize the footprint of the latter; because the same can be done with
Cnf{Freeze,Thaw}Bool(), those are also moved out of the system code with
this commit.)
Color integers were being OR'ed with 0x80000000 in some places for two
distinct purposes: One, to indicate use of a default color in
glxFillMesh(); this has been replaced by use of the .UseDefault() method.
Two, to indicate to TextWindow::Printf() that the format argument of a
"%Bp"/"%Fp" specifier is an RGB color rather than a color "code" from
TextWindow::bgColors[] or TextWindow::fgColors[] (as the specifier can
accept either); instead, we define a new flag "z" (as in "%Bz" or "%Fz") to
indicate an RGBcolor pointer, leaving "%Bp"/"%Fp" to indicate a color code
exclusively.
(This also allows TextWindow::meta[][].bg to be a char instead of an int,
partly compensating for the new .bgRgb field added immediately after.)
In array declarations, RGB colors could previously be specified as 0 (often
in a terminating element). As that no longer works, we define NULL_COLOR,
which serves much the same purpose for RgbColor variables as NULL serves
for pointers.
2013-10-16 20:00:58 +00:00
|
|
|
double lineWidth = Style::WidthMm(b->auxA)*s;
|
2016-05-25 12:08:19 +00:00
|
|
|
RgbaColor strokeRgb = Style::Color(hs, /*forExport=*/true);
|
|
|
|
RgbaColor fillRgb = Style::FillColor(hs, /*forExport=*/true);
|
2009-10-30 10:38:34 +00:00
|
|
|
|
2016-04-12 23:57:49 +00:00
|
|
|
StartPath(strokeRgb, lineWidth, stl->filled, fillRgb, hs);
|
2009-10-30 10:38:34 +00:00
|
|
|
for(sbl = sbls->l.First(); sbl; sbl = sbls->l.NextAfter(sbl)) {
|
|
|
|
for(b = sbl->l.First(); b; b = sbl->l.NextAfter(b)) {
|
|
|
|
Bezier(b);
|
|
|
|
}
|
|
|
|
}
|
2016-04-12 23:57:49 +00:00
|
|
|
FinishPath(strokeRgb, lineWidth, stl->filled, fillRgb, hs);
|
2009-04-14 04:19:23 +00:00
|
|
|
}
|
|
|
|
}
|
2009-01-27 05:48:40 +00:00
|
|
|
FinishAndCloseFile();
|
|
|
|
}
|
|
|
|
|
2009-10-30 10:38:34 +00:00
|
|
|
void VectorFileWriter::BezierAsPwl(SBezier *sb) {
|
2015-03-27 15:31:23 +00:00
|
|
|
List<Vector> lv = {};
|
2016-01-27 04:07:54 +00:00
|
|
|
sb->MakePwlInto(&lv, SS.ExportChordTolMm());
|
2009-04-14 04:19:23 +00:00
|
|
|
int i;
|
|
|
|
for(i = 1; i < lv.n; i++) {
|
2009-10-30 10:38:34 +00:00
|
|
|
SBezier sb = SBezier::From(lv.elem[i-1], lv.elem[i]);
|
|
|
|
Bezier(&sb);
|
2009-04-14 04:19:23 +00:00
|
|
|
}
|
|
|
|
lv.Clear();
|
|
|
|
}
|
|
|
|
|
2009-10-30 10:38:34 +00:00
|
|
|
void VectorFileWriter::BezierAsNonrationalCubic(SBezier *sb, int depth) {
|
2009-04-15 06:50:06 +00:00
|
|
|
Vector t0 = sb->TangentAt(0), t1 = sb->TangentAt(1);
|
|
|
|
// The curve is correct, and the first derivatives are correct, at the
|
|
|
|
// endpoints.
|
|
|
|
SBezier bnr = SBezier::From(
|
|
|
|
sb->Start(),
|
|
|
|
sb->Start().Plus(t0.ScaledBy(1.0/3)),
|
|
|
|
sb->Finish().Minus(t1.ScaledBy(1.0/3)),
|
|
|
|
sb->Finish());
|
|
|
|
|
2016-01-27 04:07:54 +00:00
|
|
|
double tol = SS.ExportChordTolMm();
|
2009-04-15 06:50:06 +00:00
|
|
|
// Arbitrary choice, but make it a little finer than pwl tolerance since
|
|
|
|
// it should be easier to achieve that with the smooth curves.
|
|
|
|
tol /= 2;
|
|
|
|
|
|
|
|
bool closeEnough = true;
|
|
|
|
int i;
|
|
|
|
for(i = 1; i <= 3; i++) {
|
|
|
|
double t = i/4.0;
|
|
|
|
Vector p0 = sb->PointAt(t),
|
|
|
|
pn = bnr.PointAt(t);
|
|
|
|
double d = (p0.Minus(pn)).Magnitude();
|
|
|
|
if(d > tol) {
|
|
|
|
closeEnough = false;
|
|
|
|
}
|
|
|
|
}
|
2015-03-29 00:30:52 +00:00
|
|
|
|
2009-04-15 06:50:06 +00:00
|
|
|
if(closeEnough || depth > 3) {
|
2009-10-30 10:38:34 +00:00
|
|
|
Bezier(&bnr);
|
2009-04-15 06:50:06 +00:00
|
|
|
} else {
|
|
|
|
SBezier bef, aft;
|
|
|
|
sb->SplitAt(0.5, &bef, &aft);
|
2009-10-30 10:38:34 +00:00
|
|
|
BezierAsNonrationalCubic(&bef, depth+1);
|
|
|
|
BezierAsNonrationalCubic(&aft, depth+1);
|
2009-04-15 06:50:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-27 05:48:40 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
2009-10-12 11:34:43 +00:00
|
|
|
// Export a triangle mesh, in the requested format.
|
2009-01-27 05:48:40 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
2015-12-27 01:03:24 +00:00
|
|
|
void SolveSpaceUI::ExportMeshTo(const std::string &filename) {
|
2016-01-27 04:07:54 +00:00
|
|
|
SS.exportMode = true;
|
Convert all enumerations to use `enum class`.
Specifically, take the old code that looks like this:
class Foo {
enum { X = 1, Y = 2 };
int kind;
}
... foo.kind = Foo::X; ...
and convert it to this:
class Foo {
enum class Kind : uint32_t { X = 1, Y = 2 };
Kind kind;
}
... foo.kind = Foo::Kind::X;
(In some cases the enumeration would not be in the class namespace,
such as when it is generally useful.)
The benefits are as follows:
* The type of the field gives a clear indication of intent, both
to humans and tools (such as binding generators).
* The compiler is able to automatically warn when a switch is not
exhaustive; but this is currently suppressed by the
default: ssassert(false, ...)
idiom.
* Integers and plain enums are weakly type checked: they implicitly
convert into each other. This can hide bugs where type conversion
is performed but not intended. Enum classes are strongly type
checked.
* Plain enums pollute parent namespaces; enum classes do not.
Almost every defined enum we have already has a kind of ad-hoc
namespacing via `NAMESPACE_`, which is now explicit.
* Plain enums do not have a well-defined ABI size, which is
important for bindings. Enum classes can have it, if specified.
We specify the base type for all enums as uint32_t, which is
a safe choice and allows us to not change the numeric values
of any variants.
This commit introduces absolutely no functional change to the code,
just renaming and change of types. It handles almost all cases,
except GraphicsWindow::pending.operation, which needs minor
functional change.
2016-05-20 08:31:20 +00:00
|
|
|
GenerateAll(Generate::ALL);
|
2016-01-27 04:07:54 +00:00
|
|
|
|
|
|
|
Group *g = SK.GetGroup(SS.GW.activeGroup);
|
|
|
|
g->GenerateDisplayItems();
|
|
|
|
|
2009-05-21 09:06:26 +00:00
|
|
|
SMesh *m = &(SK.GetGroup(SS.GW.activeGroup)->displayMesh);
|
2009-05-24 11:37:07 +00:00
|
|
|
if(m->IsEmpty()) {
|
2008-07-08 07:45:47 +00:00
|
|
|
Error("Active group mesh is empty; nothing to export.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-12-27 08:09:00 +00:00
|
|
|
FILE *f = ssfopen(filename, "wb");
|
2008-07-08 07:45:47 +00:00
|
|
|
if(!f) {
|
2015-12-27 01:03:24 +00:00
|
|
|
Error("Couldn't write to '%s'", filename.c_str());
|
2008-07-08 07:45:47 +00:00
|
|
|
return;
|
|
|
|
}
|
2009-10-12 11:34:43 +00:00
|
|
|
|
2015-12-27 01:03:24 +00:00
|
|
|
if(FilenameHasExtension(filename, ".stl")) {
|
2009-10-12 11:34:43 +00:00
|
|
|
ExportMeshAsStlTo(f, m);
|
2015-12-27 01:03:24 +00:00
|
|
|
} else if(FilenameHasExtension(filename, ".obj")) {
|
2009-10-12 11:34:43 +00:00
|
|
|
ExportMeshAsObjTo(f, m);
|
2016-01-11 10:53:04 +00:00
|
|
|
} else if(FilenameHasExtension(filename, ".js") ||
|
|
|
|
FilenameHasExtension(filename, ".html")) {
|
2016-06-26 06:39:27 +00:00
|
|
|
SOutlineList *e = &(SK.GetGroup(SS.GW.activeGroup)->displayOutlines);
|
2015-08-31 19:33:57 +00:00
|
|
|
ExportMeshAsThreeJsTo(f, filename, m, e);
|
2009-10-12 11:34:43 +00:00
|
|
|
} else {
|
|
|
|
Error("Can't identify output file type from file extension of "
|
2015-12-27 01:03:24 +00:00
|
|
|
"filename '%s'; try .stl, .obj, .js.", filename.c_str());
|
2009-10-12 11:34:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fclose(f);
|
2016-01-27 04:07:54 +00:00
|
|
|
|
|
|
|
SS.justExportedInfo.showOrigin = false;
|
|
|
|
SS.justExportedInfo.draw = true;
|
|
|
|
InvalidateGraphics();
|
2009-10-12 11:34:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Export the mesh as an STL file; it should always be vertex-to-vertex and
|
|
|
|
// not self-intersecting, so not much to do.
|
|
|
|
//-----------------------------------------------------------------------------
|
2015-03-23 17:49:04 +00:00
|
|
|
void SolveSpaceUI::ExportMeshAsStlTo(FILE *f, SMesh *sm) {
|
2015-03-27 15:31:23 +00:00
|
|
|
char str[80] = {};
|
2008-07-08 07:45:47 +00:00
|
|
|
strcpy(str, "STL exported mesh");
|
|
|
|
fwrite(str, 1, 80, f);
|
|
|
|
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 05:45:13 +00:00
|
|
|
uint32_t n = sm->l.n;
|
2008-07-08 07:45:47 +00:00
|
|
|
fwrite(&n, 4, 1, f);
|
|
|
|
|
|
|
|
double s = SS.exportScale;
|
|
|
|
int i;
|
2009-10-12 11:34:43 +00:00
|
|
|
for(i = 0; i < sm->l.n; i++) {
|
|
|
|
STriangle *tr = &(sm->l.elem[i]);
|
2008-07-08 07:45:47 +00:00
|
|
|
Vector n = tr->Normal().WithMagnitude(1);
|
|
|
|
float w;
|
|
|
|
w = (float)n.x; fwrite(&w, 4, 1, f);
|
|
|
|
w = (float)n.y; fwrite(&w, 4, 1, f);
|
|
|
|
w = (float)n.z; fwrite(&w, 4, 1, f);
|
|
|
|
w = (float)((tr->a.x)/s); fwrite(&w, 4, 1, f);
|
|
|
|
w = (float)((tr->a.y)/s); fwrite(&w, 4, 1, f);
|
|
|
|
w = (float)((tr->a.z)/s); fwrite(&w, 4, 1, f);
|
|
|
|
w = (float)((tr->b.x)/s); fwrite(&w, 4, 1, f);
|
|
|
|
w = (float)((tr->b.y)/s); fwrite(&w, 4, 1, f);
|
|
|
|
w = (float)((tr->b.z)/s); fwrite(&w, 4, 1, f);
|
|
|
|
w = (float)((tr->c.x)/s); fwrite(&w, 4, 1, f);
|
|
|
|
w = (float)((tr->c.y)/s); fwrite(&w, 4, 1, f);
|
|
|
|
w = (float)((tr->c.z)/s); fwrite(&w, 4, 1, f);
|
|
|
|
fputc(0, f);
|
|
|
|
fputc(0, f);
|
|
|
|
}
|
2009-10-12 11:34:43 +00:00
|
|
|
}
|
2008-07-08 07:45:47 +00:00
|
|
|
|
2009-10-12 11:34:43 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Export the mesh as Wavefront OBJ format. This requires us to reduce all the
|
|
|
|
// identical vertices to the same identifier, so do that first.
|
|
|
|
//-----------------------------------------------------------------------------
|
2015-03-23 17:49:04 +00:00
|
|
|
void SolveSpaceUI::ExportMeshAsObjTo(FILE *f, SMesh *sm) {
|
2015-03-27 15:31:23 +00:00
|
|
|
SPointList spl = {};
|
2009-10-12 11:34:43 +00:00
|
|
|
STriangle *tr;
|
|
|
|
for(tr = sm->l.First(); tr; tr = sm->l.NextAfter(tr)) {
|
|
|
|
spl.IncrementTagFor(tr->a);
|
|
|
|
spl.IncrementTagFor(tr->b);
|
|
|
|
spl.IncrementTagFor(tr->c);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Output all the vertices.
|
|
|
|
SPoint *sp;
|
|
|
|
for(sp = spl.l.First(); sp; sp = spl.l.NextAfter(sp)) {
|
|
|
|
fprintf(f, "v %.10f %.10f %.10f\r\n",
|
|
|
|
sp->p.x / SS.exportScale,
|
|
|
|
sp->p.y / SS.exportScale,
|
|
|
|
sp->p.z / SS.exportScale);
|
|
|
|
}
|
|
|
|
|
|
|
|
// And now all the triangular faces, in terms of those vertices. The
|
|
|
|
// file format counts from 1, not 0.
|
|
|
|
for(tr = sm->l.First(); tr; tr = sm->l.NextAfter(tr)) {
|
|
|
|
fprintf(f, "f %d %d %d\r\n",
|
|
|
|
spl.IndexForPoint(tr->a) + 1,
|
|
|
|
spl.IndexForPoint(tr->b) + 1,
|
|
|
|
spl.IndexForPoint(tr->c) + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
spl.Clear();
|
2008-07-08 07:45:47 +00:00
|
|
|
}
|
|
|
|
|
2009-01-27 05:48:40 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
2015-08-31 19:33:57 +00:00
|
|
|
// Export the mesh as a JavaScript script, which is compatible with Three.js.
|
|
|
|
//-----------------------------------------------------------------------------
|
2016-01-11 10:53:04 +00:00
|
|
|
void SolveSpaceUI::ExportMeshAsThreeJsTo(FILE *f, const std::string &filename,
|
2016-06-26 06:39:27 +00:00
|
|
|
SMesh *sm, SOutlineList *sol)
|
2015-08-31 19:33:57 +00:00
|
|
|
{
|
2015-03-27 15:31:23 +00:00
|
|
|
SPointList spl = {};
|
2015-08-31 19:33:57 +00:00
|
|
|
STriangle *tr;
|
|
|
|
Vector bndl, bndh;
|
2016-05-18 11:44:32 +00:00
|
|
|
const char htmlbegin[] = R"(
|
2016-05-06 17:24:18 +00:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<html lang="en">
|
|
|
|
<head>
|
|
|
|
<meta charset="utf-8"></meta>
|
|
|
|
<title>Three.js Solvespace Mesh</title>
|
2016-05-18 11:44:32 +00:00
|
|
|
<script id="three-r76.js">%s</script>
|
|
|
|
<script id="hammer-2.0.8.js">%s</script>
|
|
|
|
<script id="SolveSpaceControls.js">%s</script>
|
2016-05-06 17:24:18 +00:00
|
|
|
<style type="text/css">
|
|
|
|
body { margin: 0; overflow: hidden; }
|
|
|
|
</style>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<script>
|
|
|
|
)";
|
|
|
|
const char htmlend[] = R"(
|
2016-06-11 23:08:12 +00:00
|
|
|
document.body.appendChild(solvespace(solvespace_model_%s, {
|
|
|
|
scale: %g,
|
|
|
|
offset: new THREE.Vector3(%g, %g, %g),
|
|
|
|
projUp: new THREE.Vector3(%g, %g, %g),
|
|
|
|
projRight: new THREE.Vector3(%g, %g, %g)
|
|
|
|
}));
|
2016-05-06 17:24:18 +00:00
|
|
|
</script>
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
)";
|
2015-08-31 19:33:57 +00:00
|
|
|
|
|
|
|
// A default three.js viewer with OrthographicTrackballControls is
|
|
|
|
// generated as a comment preceding the data.
|
|
|
|
|
|
|
|
// x bounds should be the range of x or y, whichever
|
|
|
|
// is larger, before aspect ratio correction is applied.
|
|
|
|
// y bounds should be the range of x or y, whichever is
|
|
|
|
// larger. No aspect ratio correction is applied.
|
|
|
|
// Near plane should be 1.
|
|
|
|
// Camera's z-position should be the range of z + 1 or the larger of
|
|
|
|
// the x or y bounds, whichever is larger.
|
|
|
|
// Far plane should be at least twice as much as the camera's
|
|
|
|
// z-position.
|
|
|
|
// Edge projection bias should be about 1/500 of the far plane's distance.
|
|
|
|
// Further corrections will be applied to the z-position and far plane in
|
|
|
|
// the default viewer, but the defaults are fine for a model which
|
|
|
|
// only rotates about the world origin.
|
|
|
|
|
|
|
|
sm->GetBounding(&bndh, &bndl);
|
|
|
|
double largerBoundXY = max((bndh.x - bndl.x), (bndh.y - bndl.y));
|
|
|
|
double largerBoundZ = max(largerBoundXY, (bndh.z - bndl.z + 1));
|
|
|
|
|
2016-01-11 10:53:04 +00:00
|
|
|
std::string extension = filename,
|
|
|
|
noExtFilename = filename;
|
|
|
|
size_t dot = noExtFilename.rfind('.');
|
|
|
|
extension.erase(0, dot + 1);
|
|
|
|
noExtFilename.erase(dot);
|
2015-08-31 19:33:57 +00:00
|
|
|
|
2016-01-11 10:53:04 +00:00
|
|
|
std::string baseFilename = noExtFilename;
|
2015-12-27 06:35:46 +00:00
|
|
|
size_t lastSlash = baseFilename.rfind(PATH_SEP);
|
2016-05-18 22:51:36 +00:00
|
|
|
ssassert(lastSlash != std::string::npos, "Expected at least one path separator");
|
2015-12-27 01:03:24 +00:00
|
|
|
baseFilename.erase(0, lastSlash + 1);
|
2015-08-31 19:33:57 +00:00
|
|
|
|
2016-02-12 05:25:19 +00:00
|
|
|
for(size_t i = 0; i < baseFilename.length(); i++) {
|
2015-08-31 19:33:57 +00:00
|
|
|
if(!isalpha(baseFilename[i]) &&
|
|
|
|
/* also permit UTF-8 */ !((unsigned char)baseFilename[i] >= 0x80))
|
|
|
|
baseFilename[i] = '_';
|
|
|
|
}
|
|
|
|
|
2016-05-06 17:24:18 +00:00
|
|
|
if(extension == "html") {
|
2016-05-18 11:44:32 +00:00
|
|
|
fprintf(f, htmlbegin,
|
|
|
|
LoadStringFromGzip("threejs/three-r76.js.gz").c_str(),
|
|
|
|
LoadStringFromGzip("threejs/hammer-2.0.8.js.gz").c_str(),
|
|
|
|
LoadString("threejs/SolveSpaceControls.js").c_str());
|
2016-05-06 17:24:18 +00:00
|
|
|
}
|
2016-01-11 10:53:04 +00:00
|
|
|
|
|
|
|
fprintf(f, "var solvespace_model_%s = {\n"
|
2015-08-31 19:33:57 +00:00
|
|
|
" bounds: {\n"
|
|
|
|
" x: %f, y: %f, near: %f, far: %f, z: %f, edgeBias: %f\n"
|
|
|
|
" },\n",
|
2016-01-11 07:52:46 +00:00
|
|
|
baseFilename.c_str(),
|
|
|
|
largerBoundXY,
|
|
|
|
largerBoundXY,
|
|
|
|
1.0,
|
|
|
|
largerBoundZ * 2,
|
|
|
|
largerBoundZ,
|
|
|
|
largerBoundZ / 250);
|
2015-08-31 19:33:57 +00:00
|
|
|
|
|
|
|
// Output lighting information.
|
|
|
|
fputs(" lights: {\n"
|
|
|
|
" d: [\n", f);
|
|
|
|
|
|
|
|
// Directional.
|
|
|
|
int lightCount;
|
|
|
|
for(lightCount = 0; lightCount < 2; lightCount++)
|
|
|
|
{
|
|
|
|
fprintf(f, " {\n"
|
|
|
|
" intensity: %f, direction: [%f, %f, %f]\n"
|
|
|
|
" },\n",
|
2016-01-11 07:52:46 +00:00
|
|
|
SS.lightIntensity[lightCount],
|
|
|
|
CO(SS.lightDir[lightCount]));
|
2015-08-31 19:33:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Global Ambience.
|
|
|
|
fprintf(f, " ],\n"
|
|
|
|
" a: %f\n", SS.ambientIntensity);
|
|
|
|
|
|
|
|
for(tr = sm->l.First(); tr; tr = sm->l.NextAfter(tr)) {
|
|
|
|
spl.IncrementTagFor(tr->a);
|
|
|
|
spl.IncrementTagFor(tr->b);
|
|
|
|
spl.IncrementTagFor(tr->c);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Output all the vertices.
|
|
|
|
SPoint *sp;
|
|
|
|
fputs(" },\n"
|
|
|
|
" points: [\n", f);
|
|
|
|
for(sp = spl.l.First(); sp; sp = spl.l.NextAfter(sp)) {
|
|
|
|
fprintf(f, " [%f, %f, %f],\n",
|
2016-01-11 07:52:46 +00:00
|
|
|
sp->p.x / SS.exportScale,
|
|
|
|
sp->p.y / SS.exportScale,
|
|
|
|
sp->p.z / SS.exportScale);
|
2015-08-31 19:33:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fputs(" ],\n"
|
|
|
|
" faces: [\n", f);
|
|
|
|
// And now all the triangular faces, in terms of those vertices.
|
|
|
|
// This time we count from zero.
|
|
|
|
for(tr = sm->l.First(); tr; tr = sm->l.NextAfter(tr)) {
|
|
|
|
fprintf(f, " [%d, %d, %d],\n",
|
2016-01-11 07:52:46 +00:00
|
|
|
spl.IndexForPoint(tr->a),
|
|
|
|
spl.IndexForPoint(tr->b),
|
|
|
|
spl.IndexForPoint(tr->c));
|
2015-08-31 19:33:57 +00:00
|
|
|
}
|
|
|
|
|
2016-01-11 07:52:46 +00:00
|
|
|
// Output face normals.
|
2015-08-31 19:33:57 +00:00
|
|
|
fputs(" ],\n"
|
2016-01-11 07:52:46 +00:00
|
|
|
" normals: [\n", f);
|
2015-08-31 19:33:57 +00:00
|
|
|
for(tr = sm->l.First(); tr; tr = sm->l.NextAfter(tr)) {
|
2016-01-11 07:52:46 +00:00
|
|
|
fprintf(f, " [[%f, %f, %f], [%f, %f, %f], [%f, %f, %f]],\n",
|
|
|
|
CO(tr->an), CO(tr->bn), CO(tr->cn));
|
2015-08-31 19:33:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fputs(" ],\n"
|
2016-01-11 07:52:46 +00:00
|
|
|
" colors: [\n", f);
|
|
|
|
// Output triangle colors.
|
2015-08-31 19:33:57 +00:00
|
|
|
for(tr = sm->l.First(); tr; tr = sm->l.NextAfter(tr)) {
|
2016-01-11 07:52:46 +00:00
|
|
|
fprintf(f, " 0x%x,\n", tr->meta.color.ToARGB32());
|
2015-08-31 19:33:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fputs(" ],\n"
|
|
|
|
" edges: [\n", f);
|
|
|
|
// Output edges. Assume user's model colors do not obscure white edges.
|
2016-06-26 06:39:27 +00:00
|
|
|
for(const SOutline &so : sol->l) {
|
|
|
|
if(so.tag == 0) continue;
|
2015-08-31 19:33:57 +00:00
|
|
|
fprintf(f, " [[%f, %f, %f], [%f, %f, %f]],\n",
|
2016-06-26 06:39:27 +00:00
|
|
|
so.a.x / SS.exportScale,
|
|
|
|
so.a.y / SS.exportScale,
|
|
|
|
so.a.z / SS.exportScale,
|
|
|
|
so.b.x / SS.exportScale,
|
|
|
|
so.b.y / SS.exportScale,
|
|
|
|
so.b.z / SS.exportScale);
|
2015-08-31 19:33:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fputs(" ]\n};\n", f);
|
2016-01-11 10:53:04 +00:00
|
|
|
|
|
|
|
if(extension == "html")
|
2016-06-11 23:08:12 +00:00
|
|
|
fprintf(f, htmlend,
|
|
|
|
baseFilename.c_str(),
|
|
|
|
SS.GW.scale,
|
|
|
|
CO(SS.GW.offset),
|
|
|
|
CO(SS.GW.projUp),
|
|
|
|
CO(SS.GW.projRight));
|
2016-01-11 10:53:04 +00:00
|
|
|
|
2015-08-31 19:33:57 +00:00
|
|
|
spl.Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2009-01-27 05:48:40 +00:00
|
|
|
// Export a view of the model as an image; we just take a screenshot, by
|
|
|
|
// rendering the view in the usual way and then copying the pixels.
|
|
|
|
//-----------------------------------------------------------------------------
|
2015-12-27 01:03:24 +00:00
|
|
|
void SolveSpaceUI::ExportAsPngTo(const std::string &filename) {
|
2016-07-25 19:37:48 +00:00
|
|
|
#if !defined(HEADLESS)
|
2016-08-13 09:55:37 +00:00
|
|
|
// Somewhat hacky way to invoke glReadPixels without dragging in all OpenGL headers.
|
|
|
|
OpenGl1Renderer canvas = {};
|
|
|
|
canvas.camera = SS.GW.GetCamera();
|
|
|
|
std::shared_ptr<Pixmap> screenshot;
|
|
|
|
|
2008-07-08 07:45:47 +00:00
|
|
|
// No guarantee that the back buffer contains anything valid right now,
|
2009-01-14 05:10:42 +00:00
|
|
|
// so repaint the scene. And hide the toolbar too.
|
Use C99 integer types and C++ boolean types/values
This change comprehensively replaces the use of Microsoft-standard integer
and boolean types with their C99/C++ standard equivalents, as the latter is
more appropriate for a cross-platform application. With matter-of-course
exceptions in the Win32-specific code, the types/values have been converted
as follows:
QWORD --> uint64_t
SQWORD --> int64_t
DWORD --> uint32_t
SDWORD --> int32_t
WORD --> uint16_t
SWORD --> int16_t
BYTE --> uint8_t
BOOL --> bool
TRUE --> true
FALSE --> false
The following related changes are also included:
* Added C99 integer type definitions for Windows, as stdint.h is not
available prior to Visual Studio 2010
* Changed types of some variables in the SolveSpace class from 'int' to
'bool', as they actually represent boolean settings
* Implemented new Cnf{Freeze,Thaw}Bool() functions to support boolean
variables in the Registry
* Cnf{Freeze,Thaw}DWORD() are now Cnf{Freeze,Thaw}Int()
* TtfFont::Get{WORD,DWORD}() are now TtfFont::Get{USHORT,ULONG}() (names
inspired by the OpenType spec)
* RGB colors are packed into an integer of type uint32_t (nee DWORD), but
in a few places, these were represented by an int; these have been
corrected to uint32_t
2013-10-02 05:45:13 +00:00
|
|
|
bool prevShowToolbar = SS.showToolbar;
|
2009-01-14 05:10:42 +00:00
|
|
|
SS.showToolbar = false;
|
2016-07-25 19:37:48 +00:00
|
|
|
#if !defined(WIN32)
|
2016-07-24 14:42:44 +00:00
|
|
|
GlOffscreen offscreen;
|
|
|
|
offscreen.Render((int)SS.GW.width, (int)SS.GW.height, [&] {
|
|
|
|
SS.GW.Paint();
|
2016-08-13 09:55:37 +00:00
|
|
|
screenshot = canvas.ReadFrame();
|
2016-07-24 14:42:44 +00:00
|
|
|
});
|
2016-08-13 09:55:37 +00:00
|
|
|
#else
|
|
|
|
SS.GW.Paint();
|
|
|
|
screenshot = canvas.ReadFrame();
|
2016-03-03 09:53:10 +00:00
|
|
|
#endif
|
2009-01-14 05:10:42 +00:00
|
|
|
SS.showToolbar = prevShowToolbar;
|
2015-03-29 00:30:52 +00:00
|
|
|
|
2016-08-13 09:55:37 +00:00
|
|
|
#if defined(WIN32) || defined(HAVE_GTK)
|
|
|
|
bool flip = true;
|
|
|
|
#else
|
|
|
|
bool flip = false;
|
|
|
|
#endif
|
2015-03-29 00:30:52 +00:00
|
|
|
|
Abstract all (ex-OpenGL) drawing operations into a Canvas interface.
This has several desirable consequences:
* It is now possible to port SolveSpace to a later version of
OpenGL, such as OpenGLES 2, so that it runs on platforms that
only have that OpenGL version;
* The majority of geometry is now rendered without references to
the camera in C++ code, so a renderer can now submit it to
the video card once and re-rasterize with a different projection
matrix every time the projection is changed, avoiding expensive
reuploads;
* The DOGD (draw or get distance) interface is now
a straightforward Canvas implementation;
* There are no more direct references to SS.GW.(projection)
in sketch rendering code, which allows rendering to multiple
viewports;
* There are no more unnecessary framebuffer flips on CPU on Cocoa
and GTK;
* The platform-dependent GL code is now confined to rendergl1.cpp.
* The Microsoft and Apple headers required by it that are prone to
identifier conflicts are no longer included globally;
* The rendergl1.cpp implementation can now be omitted from
compilation to run SolveSpace headless or with a different
OpenGL version.
Note these implementation details of Canvas:
* GetCamera currently always returns a reference to the field
`Camera camera;`. This is so that a future renderer that caches
geometry in the video memory can define it as asserting, which
would provide assurance against code that could accidentally
put something projection-dependent in the cache;
* Line and triangle rendering is specified through a level of
indirection, hStroke and hFill. This is so that a future renderer
that batches geometry could cheaply group identical styles.
* DrawPixmap and DrawVectorText accept a (o,u,v) and not a matrix.
This is so that a future renderer into an output format that
uses 2d transforms (e.g. SVG) could easily derive those.
Some additional internal changes were required to enable this:
* Pixmap is now always passed as std::shared_ptr<{const ,}Pixmap>.
This is so that the renderer could cache uploaded textures
between API calls, which requires it to capture a (weak)
reference.
* The PlatformPathEqual function was properly extracted into
platform-specific code. This is so that the <windows.h> header
could be included only where needed (in platform/w32* as well
as rendergl1.cpp).
* The SBsp{2,3}::DebugDraw functions were removed. They can be
rewritten using the Canvas API if they are ever needed.
While no visual changes were originally intended, some minor fixes
happened anyway:
* The "emphasis" yellow line from top-left corner is now correctly
rendered much wider.
* The marquee rectangle is now pixel grid aligned.
* The hidden entities now do not clobber the depth buffer, removing
some minor artifacts.
* The workplane "tab" now scales with the font used to render
the workplane name.
* The workplane name font is now taken from the normals style.
* Workplane and constraint line stipple is insignificantly
different. This is so that it can reuse the existing stipple
codepaths; rendering of workplanes and constraints predates
those.
Some debug functionality was added:
* In graphics window, an fps counter that becomes red when
rendering under 60fps is drawn.
2016-05-31 00:55:13 +00:00
|
|
|
FILE *f = ssfopen(filename, "wb");
|
2016-08-13 09:55:37 +00:00
|
|
|
if(!f || !screenshot->WritePng(f, flip)) {
|
Abstract all (ex-OpenGL) drawing operations into a Canvas interface.
This has several desirable consequences:
* It is now possible to port SolveSpace to a later version of
OpenGL, such as OpenGLES 2, so that it runs on platforms that
only have that OpenGL version;
* The majority of geometry is now rendered without references to
the camera in C++ code, so a renderer can now submit it to
the video card once and re-rasterize with a different projection
matrix every time the projection is changed, avoiding expensive
reuploads;
* The DOGD (draw or get distance) interface is now
a straightforward Canvas implementation;
* There are no more direct references to SS.GW.(projection)
in sketch rendering code, which allows rendering to multiple
viewports;
* There are no more unnecessary framebuffer flips on CPU on Cocoa
and GTK;
* The platform-dependent GL code is now confined to rendergl1.cpp.
* The Microsoft and Apple headers required by it that are prone to
identifier conflicts are no longer included globally;
* The rendergl1.cpp implementation can now be omitted from
compilation to run SolveSpace headless or with a different
OpenGL version.
Note these implementation details of Canvas:
* GetCamera currently always returns a reference to the field
`Camera camera;`. This is so that a future renderer that caches
geometry in the video memory can define it as asserting, which
would provide assurance against code that could accidentally
put something projection-dependent in the cache;
* Line and triangle rendering is specified through a level of
indirection, hStroke and hFill. This is so that a future renderer
that batches geometry could cheaply group identical styles.
* DrawPixmap and DrawVectorText accept a (o,u,v) and not a matrix.
This is so that a future renderer into an output format that
uses 2d transforms (e.g. SVG) could easily derive those.
Some additional internal changes were required to enable this:
* Pixmap is now always passed as std::shared_ptr<{const ,}Pixmap>.
This is so that the renderer could cache uploaded textures
between API calls, which requires it to capture a (weak)
reference.
* The PlatformPathEqual function was properly extracted into
platform-specific code. This is so that the <windows.h> header
could be included only where needed (in platform/w32* as well
as rendergl1.cpp).
* The SBsp{2,3}::DebugDraw functions were removed. They can be
rewritten using the Canvas API if they are ever needed.
While no visual changes were originally intended, some minor fixes
happened anyway:
* The "emphasis" yellow line from top-left corner is now correctly
rendered much wider.
* The marquee rectangle is now pixel grid aligned.
* The hidden entities now do not clobber the depth buffer, removing
some minor artifacts.
* The workplane "tab" now scales with the font used to render
the workplane name.
* The workplane name font is now taken from the normals style.
* Workplane and constraint line stipple is insignificantly
different. This is so that it can reuse the existing stipple
codepaths; rendering of workplanes and constraints predates
those.
Some debug functionality was added:
* In graphics window, an fps counter that becomes red when
rendering under 60fps is drawn.
2016-05-31 00:55:13 +00:00
|
|
|
Error("Couldn't write to '%s'", filename.c_str());
|
2008-07-08 07:45:47 +00:00
|
|
|
}
|
|
|
|
if(f) fclose(f);
|
2016-07-24 14:42:44 +00:00
|
|
|
|
2016-07-25 19:37:48 +00:00
|
|
|
#if !defined(WIN32)
|
2016-07-24 14:42:44 +00:00
|
|
|
offscreen.Clear();
|
|
|
|
#endif
|
|
|
|
|
2008-07-08 07:45:47 +00:00
|
|
|
return;
|
2016-07-25 19:37:48 +00:00
|
|
|
#endif
|
2008-07-08 07:45:47 +00:00
|
|
|
}
|
|
|
|
|