23 Commits
Author SHA1 Message Date
Clifford Yapp ffdca572a3 Fix edge solver midpoint coordinate calculation
Evaluate the midpoint candidate in the vertex0-relative coordinate
frame by halving the edge delta, then translate each result using the
matching vertex0 coordinate.

The previous calculation halved absolute vertex1 coordinates and used
vertex0's X coordinate when reconstructing Y and Z, which could produce
severely misplaced collapse points and mesh spikes.
2026-08-31 19:22:28 +00:00
Clifford Yapp 04852cddc0 Use else rather than elif (Visual Studio 2026) 2026-06-21 19:28:07 -04:00
Clifford Yapp 9e40c7789a Set VERSION and SOVERSION on the mmesh shared library
The shared library libmmesh.so is currently installed without a SONAME
version number (SONAME = "libmmesh.so", same as the .so symlink name).
Well-behaved shared libraries on Linux follow the libfoo.so.MAJOR
convention so that:
 - The dynamic linker records the SONAME (libmmesh.so.1) in the
   dependent binary, not the unversioned name.
 - Multiple API versions can coexist under the same prefix without
   collisions.
 - Package managers know which .so file represents the library ABI and
   which is the development symlink.
The top-level CMakeLists.txt already declares project(mmesh VERSION 1.0.0),
so PROJECT_VERSION and PROJECT_VERSION_MAJOR are available.  We just need
to apply them to the shared library target via set_target_properties.
2026-04-30 10:23:35 -04:00
Clifford Yapp 49c256083e Fix a couple issues with coplanar cases
Github Copilot spotted a couple of potential issues in planar input cases.
when using MD_FLAGS_PLANAR_MODE. This mode is designed for height fields where
XY coordinates are mostly planar and Z normal inversions should be prevented.

The first issue was in the planar normal inversion detection logic, which
checked if oldnormal[2] * newnormal[2] <= 0.0. For truly coplanar triangles
(both lying in the XY plane), both normal Z components are 0, making their
product 0. This triggered the <= 0.0 condition and incorrectly rejected valid
coplanar decimations.

Solution:

Changed the planar mode normal inversion condition from <= 0.0 to < 0.0 across
all implementations. This allows:

    Coplanar triangles (Z product = 0) to be decimated
    Actual inversions (Z product < 0) to still be rejected
    Same-facing triangles (Z product > 0) to be decimated

The second issue was in the SSE (Streaming SIMD Extensions) optimized code for
planar mode normal inversion checking. In planar mode, the algorithm needs to
detect when triangle normal Z components would flip sign after an edge
collapse, which would indicate an invalid geometric transformation for height
field data.

The SSE code was using _MM_SHUFFLE(3,3,3,3) to extract what it assumed was the
Z component from the normal vector cross product, but this shuffle pattern
actually extracts the W component (index 3) instead of the Z component (index
2). This caused the planar mode normal inversion check to examine the wrong
vector component, leading to incorrect decisions about which triangle collapses
were geometrically valid.

Solution

Changed the SSE shuffle instruction from _MM_SHUFFLE(3,3,3,3) to
_MM_SHUFFLE(2,2,2,2) in both affected SSE functions
(mdEdgeCollapsePenaltyTriangleSSE4p1f and mdEdgeCollapsePenaltyTriangleSSE3f)
to correctly extract the Z component for planar mode normal inversion checks.

Note that there seems to be a broader issue where small triangles densely
packed on the interior of a planar face have unexpectedly high collapse costs,
preventing their decimation. This is counterintuitive since these triangles
should be the "lowest hanging fruit" for simplification, but apparently follows
from how mmesh is doing its penalty calculations.  Noticed in initial DSP tests,
which generated very dense floor meshes but weren't simplified.
2025-09-23 16:53:38 -04:00
Clifford Yapp 7627cc4bbd Turn off some debugging printouts by default 2025-08-19 12:36:11 -04:00
Clifford Yapp 29ded86042 If we're building only static, have that be the mmesh::mmesh exported target 2025-08-14 11:29:16 -04:00
Clifford Yapp f8d65f2a41 Build a static mmesh lib as well 2025-08-14 11:21:26 -04:00
Clifford Yapp 39a7a5c047 clang doesn't like the UTF-8 in these comments 2025-08-14 10:45:52 -04:00
Clifford Yapp 27ca9c29e2 Test out generating a modern find_package config setup for mmesh 2025-08-13 16:36:15 -04:00
Clifford Yapp 9734d5fdda Add a brief README 2025-08-13 16:14:01 -04:00
Clifford Yapp 1955dabe10 Include mm.h to pull in winsock2.h for struct timeval (per suggestion from Alexis) 2023-12-02 00:12:14 -05:00
Clifford Yapp 69b4b161b8 Add mmthread.c from Alexis - the optimizer code needs the implementation of the mtSleep functions on OSX and Windows. 2023-12-02 00:05:13 -05:00
Clifford Yapp 00b53f51be Correction from Alexis for MSVC building 2023-12-01 23:57:54 -05:00
Clifford Yapp 48026792e2 Add meshoptimizer code from Alexis (added MMESH_EXPORT logic to header) 2023-12-01 23:47:47 -05:00
Clifford Yapp 1a386e6ed1 Initialize accumscore 2023-12-01 17:07:18 -05:00
Clifford Yapp 7515ec0722 Another adjustment from Alexis for MSVC compilation 2023-12-01 17:01:33 -05:00
Clifford Yapp 9e7ae2a4af Try adding declspec import/export logic 2023-12-01 16:06:08 -05:00
Clifford Yapp 794b94b94e Updates from Alexis working on fixes for MSVC and OSX compiling 2023-12-01 15:05:29 -05:00
Clifford Yapp 9e72c307ce Remove some stray options and comments 2023-12-01 14:03:40 -05:00
Clifford Yapp 6f0b1737c4 Make a stab at turning on build checks for mmesh 2023-12-01 14:01:20 -05:00
Clifford Yapp 2e7e1550d9 Add a LICENSE file and .gitignore 2023-12-01 13:50:28 -05:00
Clifford Yapp ebc86fe09b Add basic CMake logic to build as a shared library 2023-12-01 13:46:34 -05:00
Clifford Yapp a60a7ab8f7 Initialize with the 2023-12-01 meshdecimate.tar.gz files 2023-12-01 13:43:19 -05:00