Commit Graph

1150 Commits (80c72963160a20deb73b36ccfce568f57b1babfa)

Author SHA1 Message Date
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
whitequark 23feb4cf8f TTF: use metrics of 'A' to determine cap height.
SolveSpace 2.0 used the height of 'A' (i.e. cap height) to determine
the reference height.
SolveSpace 2.1 completely broke that during transition to Freetype,
and used something more or less random, by using FT_Set_Char_Size
with units_per_EM.
SolveSpace 2.2 attempted to fix that, but also used something more
or less random, by using FT_Request_Size with "unit" values.

Turns out that Freetype actually doesn't have a concept of cap height
at all. It is possible to extract it from the TT_OS2 table that is
present in some TrueType fonts, but it is not present in Microsoft
fonts (the msttcorefonts ones), and for those Linux fonts in which
it is present it doesn't appear very reliable.

So instead, use the height of 'A' instead, like version 2.0 did.
This has the advantage that it is quite bulletproof, and also matches
exactly what the old files are measured against.

One downside is that fonts without an 'A' glyph would not render.
We can deal with that when it becomes a problem.
2016-11-02 08:59:33 +00:00
whitequark 7bd6adefd8 TTF: actually use CID as GID when CID-to-GID mapping is absent. 2016-11-02 08:47:02 +00:00
whitequark b8bec35a0c TTF: only call FT_Request_Size once after loading. 2016-11-02 08:46:36 +00:00
whitequark 0e72c606ab tests: fix bugs and inefficiencies in PrepareSavefile. 2016-11-02 03:43:29 +00:00
EvilSpirit 505f503cc3 Don't consider workplane origin point for bounding box calculation. 2016-11-02 02:43:45 +00:00
EvilSpirit 600c39db91 Don't consider arc center point for bounding box calculation. 2016-11-02 02:40:26 +00:00
whitequark cdd6174cfa tests: remove CHECK_RENDER from migrate_from_v* tests.
This is a bit slow, but more importantly creates a race condition
where e.g. a failing "normal" test will be overwritten by
a succeeding "normal_migrate_from_v20".

This shouldn't ever be a problem since saving dumps the entire
internal state, or is supposed to, at least.
2016-11-02 02:40:17 +00:00
whitequark 071a7acc9d tests: bulk add of migrate_from_v22 tests. 2016-11-02 02:33:31 +00:00