Commit Graph

1308 Commits (7d181f0d0fbd2d5df4b2c246fa474738d39d63e9)

Author SHA1 Message Date
EvilSpirit dbc567ed89 Reload linked files before upgrading legacy data.
Before this commit, if constraints with newly introduced params were
loaded from a file that linked other files, the upgrade code would
attempt to look up a non-existent entity.
2016-11-28 16:58:31 +00:00
whitequark 9301dec98d Use the same code for loading resources in all executables.
All of our executables need resources; e.g. the vector font is
a resource and it is necessary for generation. Before this commit,
the GUI executable loaded the resources in a nice way, and everything
else did it in a very ad-hoc, fragile way.

After this commit, all executables are placed in <build>/bin and
follow the same algorithm:
  * On Windows, resources are compiled and linked into every
    executable.
  * On Linux, resources are copied into <build>/res (which is
    tried first) and <prefix>/share/solvespace (which is tried
    second).
  * On macOS, resources are copied into <build>/res (which is
    tried first) and <build>/bin/solvespace.app/Contents/Resources
    (which is tried second).

In practice this means that we can add as many executables as we want
without duplicating lots of code. In addition, on macOS, we can
place supplementary executables into the bundle, and they can use
resources from the bundle transparently.
2016-11-28 06:18:42 +00:00
EvilSpirit 7681f6df74 Refactor insertion into BSP tree.
Before this commit, inserting into BSP tree could easily overflow
the stack because we allocate very large stack frames and, on
convex geometries (e.g. a sphere), the BSP tree degenerates into
a "BSP list", thus requiring one large stack frame per triangle.
This can be reproduced by exporting a 2d shaded view of sphere.

After this commit, the stack frames only contan a pointer to
a supplementary data structure, and moreover it only allocates
its fields on demand, conserving heap memory as well.

As a side effect, an arbitrary classifier limit of 50 vertices
is removed.
2016-11-27 21:04:31 +00:00
EvilSpirit d37f53e190 Improve performance of face picking.
This commit implements two improvements. First, it rewrites
SMesh::FirstIntersectionWith() to use an optimal (as currently known)
ray tracing algorithm. Second, it rejects triangles without
an associated face entity outright.
2016-11-27 15:14:10 +00:00
whitequark 7758844f96 Do not re-solve groups that converge but fail rank test.
This partially reverts commit 3a585ea.

We no longer need this because the VectorsParallel() is gone, and
there is no chance of pivoting wrong when solving.
2016-11-27 14:25:53 +00:00
EvilSpirit f5485cbf24 Rewrite equations generated for same-orientation constraints.
This has the same motivations and implementation as in 3d6d873.
2016-11-27 14:25:50 +00:00
EvilSpirit 78d141cf9c Rewrite equations generated for curve-line tangent constraints (in 3d).
This has the same motivations and implementation as in 3d6d873.
2016-11-27 14:25:44 +00:00
EvilSpirit 3d6d873906 Rewrite equations generated for parallel constraints (in 3d).
Before this commit, parallel constraints in 3d are fragile:
constraints that are geometrically fine can end up singular anyway
because VectorsParallel() pivots wrong but converges anyway.
After this commit, much like in cc07058, the constraints are written
in a different form: instead of trying to remove two degrees of
freedom out of three, all three are removed, and one added; namely,
the constraint introduces a free parameter, signed length ratio.
2016-11-27 13:43:48 +00:00
EvilSpirit cc07058e48 Rewrite equations generated for pt-on-line constraints.
Before this commit, pt-on-line constraints are buggy. To reproduce,
extrude a circle, then add a datum point and constrain it to the
axis of the circle, then move it. The cylinder will collapse.

To quote Jonathan:

> On investigation, I (a) confirm that the problem is
> the unconstrained extrusion depth going to zero, and (b) retract
> my earlier statement blaming extrude and other similar non-entity
> parameter treatment for this problem; you can easily reproduce it
> with a point in 3d constrained to lie on any line whose length
> is free.
>
> PT_ON_LINE is written using VectorsParallel, for no obvious reason.
> Rewriting that constraint to work on two projected distances (using
> any two basis vectors perpendicular to the line) should fix that
> problem, since replacing the "point on line in 3d" constraint with
> two "point on line in 2d" constraints works. That still has
> the hairy ball problem of choosing the basis vectors, which you
> can't do with a continuous function; you'd need Vector::Normal()
> or equivalent.
>
> You could write three equations and make the constraint itself
> introduce one new parameter for t. I don't know how well that
> would work numerically, but it would avoid the hairy ball problem,
> perhaps elegant at the cost of speed.

Indeed, this commit implements the latter solution: it introduces
an additional free parameter. The point being coincident with
the start of the line corresponds to the parameter being zero, and
point being coincident with the end corresponds to one).

In effect, instead of constraining two of three degrees of freedom
(for which the equations do not exist because of the hairy ball
theorem), it constrains three and adds one more.
2016-11-26 19:35:38 +00:00
EvilSpirit 8f93136d8a DXF: Import Z coordinate from DXF/DWG files. 2016-11-26 08:25:54 +00:00
whitequark 41365c5f9f DXF: Fix export of wireframe as 3D DXF.
Before this commit, polylines got flattened but all other entities
got exported with the proper Z coordinate. After this commit, all
entities are exported with proper Z coordinate.

Also, instead of exporting LWPOLYLINE (2d only), POLYLINE (2d/3d)
is exported; as a bonus it is more compatible with 3rd party
software, since it is older.
2016-11-26 08:18:14 +00:00
EvilSpirit aaab8a09d4 Fix a crash when extruding TTF text. 2016-11-21 17:35:24 +00:00
whitequark 43629549c1 Update ANGLE. 2016-11-19 09:50:41 +00:00
EvilSpirit 37defcbc33 Unbreak Camera::UnProjectPoint3.
The handedness was wrong, and this resulted in weird glitches
while drawing anything that depends on AlignToPixelGrid, like
normals.
2016-11-19 09:50:00 +00:00
EvilSpirit 01ae452507 Unbreak drawing of DEPTH_ONLY meshes via OpenGL 2 batch canvas. 2016-11-19 09:04:47 +00:00
Elvira Khabirova 61f248899a Refactor expression parsing.
The new expression parser is significantly simpler, more robust
and easier to understand; it also doesn't use longjmp or pollutes
Expr::Op anymore.
2016-11-19 09:02:14 +00:00
whitequark 8dc60f61c1 Fix Windows build with -DOPENGL=1.
This is mostly useful when testing the Windows functionality
on Linux, as wine is currently unable to compile the shaders
that ANGLE outputs.
2016-11-19 05:14:06 +00:00
whitequark d3f2ac7513 Remove most dependencies on config.h.
The only thing we need it anymore is the package version and platform
configuration, so only include it for that. As a result, less files
are rebuilt when the git commit changes and config.h is regenerated.
2016-11-19 01:00:11 +00:00
whitequark 369b0a378c Optimize toggling visibility of normals, points, edges, outlines.
Before this commit, any visibility toggle would cause a regeneration.
After this commit, toggling visibility of normals and points never
causes a regeneration, and toggling visibility of edges and outlines
only causes a regeneration when they weren't already generated.
2016-11-18 15:26:01 +00:00
EvilSpirit 683ac78ca2 Optimize FromTransformationOf for performing identity transformation.
FromTransformationOf is called with an identity rotation or
translation for translation and rotation groups, and for every
group that doesn't produce a solid model. This commit omits any
calculations from it when the relevant part of transformation
would change nothing.

This commit results in a ~10% improvement on testcase
woodworking/big-big-big-woodworking-asm, and splitting the condition
into three parts results in a ~5% improvement on testcase
stress/rotate_groups_0.
2016-11-18 14:51:47 +00:00
whitequark 0ae0343fc7 Add a simple benchmarking harness. 2016-11-18 13:55:24 +00:00
whitequark 9a0f2c3601 Fix detection of transparent meshes.
SSurface::TriangulateInto first populates the mesh with triangles
that have no color, and then paints them, which confused the code
that detects if a mesh is transparent into thinking that all of them
are; and that broke the "draw back faces in red" feature, since it
is disabled for transparent meshes.
2016-11-18 11:38:45 +00:00
whitequark 73844f7202 Draw triangle back faces like the front, unless we draw them in red.
The configuration option "draw back faces in red" aids debugging,
in that it allows to visually identify a non-watertight mesh.
When it is disabled, or when the mesh is transparent, we used to not
draw them at all before this commit; after, they are drawn just like
the front faces.

This has two consequences:
  1. Inner surfaces of non-watertight meshes are not see-through
     anymore. That used to be the behavior in version 2.0, and it
     was accidentally broken in 2.1.
  2. Transparent meshes look *much* better.
  3. Solids made from a union of a non-transparent and a transparent
     one look sensibly at all.

This commit also updates the OpenGL 1 renderer to let it render
such meshes correctly.
2016-11-18 11:38:45 +00:00
whitequark c8ff17f4a2 Add OpenGL 2 support on Windows using ANGLE.
This commit performs two main changes:
  * Alters the shaders to use only strictly conformant GLSL 2.0.
  * Alters the Windows UI to use ANGLE via GL ES 2.0 and EGL 1.4.

This commit also drops official support for Windows XP, since ANGLE
requires a non-XP toolset to build. It is still possible to build
SolveSpace for Windows XP using:

  cmake -T v120_xp -DOPENGL=1
2016-11-18 11:38:45 +00:00
whitequark 9db50ed077 Refactor the renderer frame flush functionality.
This commit does three things:
  * Recognizes that BeginFrame()/EndFrame() are badly named, since
    BeginFrame() sets up framebuffer, and EndFrame() flushes a frame,
    and they do not have to be called in pairs; and so renames them
    to NewFrame()/FlushFrame().
  * Reduces the amount of frame flushes in GraphicsWindow::Paint()
    to two, which is the minimum since we use two different cameras
    for geometry and UI;
  * Changes the FPS measurement code to only take into account
    the time spent rendering our main geometry, and not the UI
    rendering or window system interaction time.
2016-11-18 04:05:12 +00:00
whitequark 156fe73bee Allow using z-index in UiCanvas, and use it for tooltips.
Before this commit, tooltips in the text window are drawn under
the red "X" indicating a disabled button. After this commit, they
are moved on top of that.

This commit also alters the OpenGL renderers' SetCamera() method
to clear the depth buffer, as that would interfere with drawing
the UI; the toolbar would get occluded by geometry.
2016-11-18 04:05:12 +00:00
EvilSpirit 92773a5770 Implement BatchCanvas for GL2. 2016-11-18 04:05:12 +00:00
EvilSpirit 52557ee979 Add an interface for view-independent rendering.
To actually achieve improved performance with the OpenGL 2 renderer,
we have to cache geometry that doesn't change when the viewport does
(note that the rendered pixels can change quite dramatically because
we can reconfigure shaders; e.g. stippling can be drawn in screen
coordinates).

This commit adds a BatchCanvas interface that can be implemented
by renderers, and uses it for drawing entities such as lines and
points.
2016-11-18 04:04:32 +00:00
EvilSpirit 6d2c2aecff Implement an OpenGL 2 renderer.
There are two main reasons to desire an OpenGL 2 renderer:
 1. Compatibility. The compatibility profile, ironically, does not
    offer a lot of compatibility, and our OpenGL 1 renderer will not
    run on Android, iOS, or WebGL.
 2. Performance. The immediate mode does not scale, and in fact
    becomes very slow with only a moderate amount of lines on screen,
    and only a somewhat large amount of triangles.

This commit implements a basic OpenGL 2 renderer that uses only
features from the (OpenGL 3.2) core profile. It is not yet faster
than the OpenGL 1 renderer, primarily because it uses a lot of small
draw calls.

This commit uses OpenGL 2 on Linux and Mac OS X directly (i.e. links
to the GL symbols from version 2+); on Windows this is impossible
with the default drivers, so for now OpenGL 1 is still used there.
2016-11-18 04:04:29 +00:00
EvilSpirit f8824e1fb2 Reimplement drawing of the mesh wireframe.
OpenGL 2 and newer do not have the glPolygonMode(..., GL_LINES) API,
so produce the wireframe on our side. It's somewhat slow, and draws
every line three times, but it is cached when the OpenGL 2 renderer
is used, and this should do for a debugging feature.
2016-11-18 02:40:43 +00:00
whitequark e56630e71d Fix creation of workplane based on a workplane.
This fixes functionality introduced by commit 3c45158, which did not
take into account reference groups.
2016-11-17 15:51:19 +00:00
whitequark c97ba6b928 Optimize IdList::MaximumId() from O(n) to O(1).
This specific implementation seems to have lingered from the days
before IdList was stored sorted. This commit has resulted in a ~5%
improvement in Generate::DIRTY time for modelisation.slvs on a GCC 6
release build.
2016-11-17 14:14:56 +00:00
whitequark ea0a1b743a Fix uninitialized variable warnings.
gcc 6 displays these when compiling in release mode; all of these
warnings except the rankOk one were benign because there would have
been an error about the incomplete switch statement.

The rankOk warning highlighted a real problem: bailing early to
didnt_converge would have branched on an uninitialized variable.
2016-11-17 13:59:51 +00:00
whitequark 802d092b13 When exporting files, initially fill in the basename of the sketch.
This is a common and convenient behavior; the basename is
pre-selected, so exporting multiple views requires just one keystroke
to put the cursor after the basename.
2016-11-17 12:54:02 +00:00
whitequark e681ba3218 Rephrase the error message for sketch in workplane creation.
The old message was confusing because it seemingly talked about
a point that was orthogonal to coordinate axes.
2016-11-17 10:07:33 +00:00
Elvira Khabirova 3c451586d7 Add an ability to create a workplane with another workplane.
This is useful in case one wants to create a workplane based on
one of the reference ones, to be explicit, or to avoid fishing out
again the line segments used to create a workplane at an angle.
2016-11-17 10:04:38 +00:00
whitequark c7277521f3 Fix error message shown when exporting mesh with wrong extension. 2016-11-17 06:52:44 +00:00
Elvira Khabirova 489ae66e96 Fix crash when trying to import not .dxf or .dwg files 2016-11-17 06:52:12 +00:00
Evil-Spirit fdd08cbead Warn if exporting a non-watertight mesh.
If a generated mesh is non-watertight, and this is not noticed for
some reason (e.g. the markers are dismissed), and the mesh is
exported for further processing, it could cause problems down
the line.
2016-11-17 00:53:28 +00:00
Evil-Spirit 3b241392d4 Fix rendering of horizontal/vertical constraint labels.
This was a regression from 2.2 to 3.0, caused by the Canvas
transition.
2016-11-17 00:48:47 +00:00
whitequark 1ec36fc657 Add missing newline in OutputDebugStringA invocation.
Before this commit, every debug message was correctly printed
to stdout, but they were all concatenated onto a single line in
the Visual Studio "Output" pane.
2016-11-16 05:57:06 +00:00
whitequark 9673225648 Fix a crash when adding a symmetric constraint on a line.
This is the same problem as in ffd9c62.
2016-11-16 02:25:21 +00:00
EvilSpirit a0d7f1dadb Optimize GroupsInOrder.
GroupsInOrder is an extremely hot function, especially during object
picking: before this commit, it was easy to get second plus latencies
on picking, and after this commit picking is almost real-time.
2016-11-15 08:56:43 +00:00
EvilSpirit 13d4a1bb6a Fix memory leak in RemoveTagged. 2016-11-15 08:56:40 +00:00
EvilSpirit 7b9d730a23 Hide OpenGL implementation details.
Abstract the exact details of the OpenGL renderer in the render.h
header; this allows us to use GL-specific types in the renderer
class and functions without including OpenGL (and Windows, where
applicable) headers in every source file.
2016-11-14 20:30:46 +00:00
whitequark f5e955a015 README: add gdb and lldb debugging instructions. 2016-11-14 02:35:04 +00:00
whitequark afecbccb0f OS X: fix another out-of-bounds TW.META access.
See also f5a37ae.
2016-11-05 17:05:17 +00:00
whitequark d151eb56fc CMake: reject in-tree builds.
We do not support clobbering the source tree with build products,
nor recommend this in any documentation, and this already leads to
weird bugs with the resource system. Show an explicit error in this
case to avoid confusion.
2016-11-03 07:25:57 +00:00
whitequark b846401c73 Update CHANGELOG. 2016-11-02 10:18:07 +00:00
whitequark 74cb1f589c Add two more points to the TTF text request.
These points can be used for constraining the width of the text
(or to the width of the text).

The main parts of the commit are:
  * TtfFont is restructured to be able to return the aspect ratio
    for a given string.
  * This aspect ratio is written to the savefile, such that even if
    the font is missing, the sketch would still be solved correctly.
  * The two additional points are constrained via perpendicularly
    to the two main points (which form a v vector).

The compatibility features are as follows:
  * When the font is missing in old files, 1:1 aspect ratio is used,
    which works for the replacement symbol anyhow.
  * When the two additional points are missing in old files, their
    would-be positions are calculated and they are moved there,
    avoiding 'jumping' of underconstrained sketches.
2016-11-02 09:22:18 +00:00