rqmesh 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,9 @@
1
+ __pycache__/
2
+ *.pyc
3
+ *.egg-info/
4
+ build/
5
+ dist/
6
+ .venv/
7
+ .pytest_cache/
8
+ *.obj
9
+ !examples/*.obj
@@ -0,0 +1,15 @@
1
+ # Changelog
2
+
3
+ This project follows [semantic versioning](https://semver.org/); before 1.0 the API may change in minor versions.
4
+
5
+ ## 0.1.0 — unreleased
6
+
7
+ First public version, carved out of thirteen internal research rounds.
8
+
9
+ - Edge-ring simplification with 3-1 and gentle (4-2, 5-3, 6-4) strip transitions, QEM placement, symmetry, UVs.
10
+ - Isolation loops: openings, isolating rings, protected loops around eyes, mouths and selected regions.
11
+ - Pole fixing with refills, a trial cache (2.2x faster) and guarded isolation rings.
12
+ - Base-cage recovery for Catmull-Clark, simple, Loop and midpoint subdivision, with creases and UVs.
13
+ - Structure analysis and workflow recommendation.
14
+ - Scale-matched cross fields for sculpts, with automatic setting selection.
15
+ - NumPy-only operation (Blender's Python); SciPy used when available.
@@ -0,0 +1,15 @@
1
+ cff-version: 1.2.0
2
+ message: "If you use this software, please cite it as below."
3
+ title: "rqmesh: structure-aware quad remeshing, simplification and retopology"
4
+ type: software
5
+ authors:
6
+ - family-names: Sandner
7
+ given-names: Daniel
8
+ repository-code: "https://github.com/sandner-art/rqmesh"
9
+ license: Apache-2.0
10
+ version: 0.1.0
11
+ keywords:
12
+ - quad mesh
13
+ - remeshing
14
+ - retopology
15
+ - geometry processing
rqmesh-0.1.0/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
rqmesh-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,110 @@
1
+ Metadata-Version: 2.5
2
+ Name: rqmesh
3
+ Version: 0.1.0
4
+ Summary: Structure-aware quad remeshing, simplification and retopology (pure Python + NumPy)
5
+ Project-URL: Homepage, https://github.com/sandner-art/rqmesh
6
+ Project-URL: Issues, https://github.com/sandner-art/rqmesh/issues
7
+ Project-URL: Blender add-on, https://github.com/sandner-art/rqmesh-blender
8
+ Author: Daniel Sandner
9
+ License-Expression: Apache-2.0
10
+ License-File: LICENSE
11
+ Keywords: blender,geometry processing,quad mesh,remeshing,retopology,subdivision
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Intended Audience :: Science/Research
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Topic :: Multimedia :: Graphics :: 3D Modeling
20
+ Classifier: Topic :: Scientific/Engineering :: Mathematics
21
+ Requires-Python: >=3.11
22
+ Requires-Dist: numpy>=1.24
23
+ Provides-Extra: scipy
24
+ Requires-Dist: scipy>=1.10; extra == 'scipy'
25
+ Provides-Extra: test
26
+ Requires-Dist: pytest>=8; extra == 'test'
27
+ Description-Content-Type: text/markdown
28
+
29
+ # rqmesh
30
+
31
+ Structure-aware quad remeshing, simplification and retopology, in pure Python + NumPy (SciPy is used when present).
32
+
33
+ rqmesh works *with* the edge flow a mesh already has rather than starting over:
34
+
35
+ - **Simplify by edge rings.** It removes whole rings of quads and places transitions (3-1, or gentle 4-2 / 5-3 / 6-4 strips), so the result stays all quads and keeps its loops. It can also keep isolation loops around openings such as eyes and mouths.
36
+ - **Fix poles.** It improves irregular vertices with rotations, collapses, loop moves and minimal pattern refills, without breaking guarded isolation rings.
37
+ - **Recover base cages.** Given a mesh subdivided with Catmull-Clark, simple, Loop or midpoint subdivision, it recovers the original cage exactly, including creases and UVs.
38
+ - **Analyse structure.** It reports what kind of mesh it is (subdivided, structured, sculpt-like) and which workflow fits.
39
+ - **Scale-matched cross fields for sculpts.** These are curvature fields measured at the size of the target quads. They can drive the optional QuadWild-BiMDF back-end.
40
+
41
+ The Blender extension built on it is [rqmesh-blender](https://github.com/sandner-art/rqmesh-blender). The optional
42
+ GPL back-end is [rqmesh-backend-quadwild](https://github.com/sandner-art/rqmesh-backend-quadwild).
43
+
44
+ **Status:** alpha (0.x). The API may change between minor versions.
45
+
46
+ ## Install
47
+
48
+ ```
49
+ pip install rqmesh # once released on PyPI
50
+ pip install rqmesh[scipy] # with SciPy: faster spatial queries and solvers
51
+ pip install git+https://github.com/sandner-art/rqmesh # from source
52
+ ```
53
+
54
+ Requires Python 3.11+ and NumPy.
55
+
56
+ ## Quick start
57
+
58
+ ```python
59
+ from rqmesh.meshio_min import read_obj_uv, write_obj_uv
60
+ from rqmesh import transitions, topofix
61
+
62
+ V, F, UV, FUV = read_obj_uv("model.obj")
63
+ V2, F2, FUV2, UV2, info = transitions.adaptive_simplify(
64
+ V, F, target=len(F) // 3, UV=UV, FUV=FUV,
65
+ feature_deg=35, local="adaptive", cost_mode="qem", transitions="auto")
66
+
67
+ pf = topofix.PoleFixer(V2, F2, 30.0)
68
+ pf.guard_isolation(2) # keep the innermost 2 rings around every opening
69
+ pf.improve(); pf.refill_poles(); pf.improve(); pf.relax(10)
70
+ V3, F3 = pf.result()
71
+ write_obj_uv("model_simplified.obj", V3, F3, None, None)
72
+ ```
73
+
74
+ More in [`examples/`](examples/). Most modules also work as command-line tools, for example
75
+ `python -m rqmesh.transitions --help` and `python -m rqmesh.isolation model.obj`.
76
+
77
+ ## Modules
78
+
79
+ | Module | Purpose |
80
+ |---|---|
81
+ | `structsimp`, `transitions` | Ring collapse, strip transitions, the error ladder (`adaptive_simplify`) |
82
+ | `topofix` | Pole fixing, refills, isolation-ring guard |
83
+ | `isolation` | Openings, isolating rings, protected loops, reports |
84
+ | `subdiv`, `subdiv_tri` | Base-cage recovery for quad and triangle subdivision schemes |
85
+ | `features`, `crease_split`, `symmetry` | Sharp features, crease splitting, mirror planes |
86
+ | `analyze` | Structure report and recommendation |
87
+ | `scalefield`, `defofield` | Cross fields (scale-matched for sculpts; deformation) |
88
+ | `repair` | Welding, small holes, degenerate faces |
89
+ | `qw_driver`, `strip_bounds` | Driver for the optional QuadWild-BiMDF back-end package |
90
+ | `meshio_min`, `compat`, `rosy` | I/O and NumPy-only stand-ins |
91
+
92
+ ## Development
93
+
94
+ ```
95
+ pip install -e .[test,scipy]
96
+ pytest
97
+ ```
98
+
99
+ The CI runs the tests on Linux, Windows and macOS, on Python 3.11 and 3.13, with and without SciPy.
100
+ Blender's bundled Python has NumPy but no SciPy, so the NumPy-only path has to keep working.
101
+
102
+ ## Licence
103
+
104
+ Apache-2.0 (see [LICENSE](LICENSE)). Apache-2.0 is compatible with the GPL-3.0, so the Blender extension (GPL) can
105
+ bundle this library.
106
+
107
+ ## Citing
108
+
109
+ If you use rqmesh in research, please cite it using [CITATION.cff](CITATION.cff); GitHub shows a "Cite this
110
+ repository" button.
rqmesh-0.1.0/README.md ADDED
@@ -0,0 +1,82 @@
1
+ # rqmesh
2
+
3
+ Structure-aware quad remeshing, simplification and retopology, in pure Python + NumPy (SciPy is used when present).
4
+
5
+ rqmesh works *with* the edge flow a mesh already has rather than starting over:
6
+
7
+ - **Simplify by edge rings.** It removes whole rings of quads and places transitions (3-1, or gentle 4-2 / 5-3 / 6-4 strips), so the result stays all quads and keeps its loops. It can also keep isolation loops around openings such as eyes and mouths.
8
+ - **Fix poles.** It improves irregular vertices with rotations, collapses, loop moves and minimal pattern refills, without breaking guarded isolation rings.
9
+ - **Recover base cages.** Given a mesh subdivided with Catmull-Clark, simple, Loop or midpoint subdivision, it recovers the original cage exactly, including creases and UVs.
10
+ - **Analyse structure.** It reports what kind of mesh it is (subdivided, structured, sculpt-like) and which workflow fits.
11
+ - **Scale-matched cross fields for sculpts.** These are curvature fields measured at the size of the target quads. They can drive the optional QuadWild-BiMDF back-end.
12
+
13
+ The Blender extension built on it is [rqmesh-blender](https://github.com/sandner-art/rqmesh-blender). The optional
14
+ GPL back-end is [rqmesh-backend-quadwild](https://github.com/sandner-art/rqmesh-backend-quadwild).
15
+
16
+ **Status:** alpha (0.x). The API may change between minor versions.
17
+
18
+ ## Install
19
+
20
+ ```
21
+ pip install rqmesh # once released on PyPI
22
+ pip install rqmesh[scipy] # with SciPy: faster spatial queries and solvers
23
+ pip install git+https://github.com/sandner-art/rqmesh # from source
24
+ ```
25
+
26
+ Requires Python 3.11+ and NumPy.
27
+
28
+ ## Quick start
29
+
30
+ ```python
31
+ from rqmesh.meshio_min import read_obj_uv, write_obj_uv
32
+ from rqmesh import transitions, topofix
33
+
34
+ V, F, UV, FUV = read_obj_uv("model.obj")
35
+ V2, F2, FUV2, UV2, info = transitions.adaptive_simplify(
36
+ V, F, target=len(F) // 3, UV=UV, FUV=FUV,
37
+ feature_deg=35, local="adaptive", cost_mode="qem", transitions="auto")
38
+
39
+ pf = topofix.PoleFixer(V2, F2, 30.0)
40
+ pf.guard_isolation(2) # keep the innermost 2 rings around every opening
41
+ pf.improve(); pf.refill_poles(); pf.improve(); pf.relax(10)
42
+ V3, F3 = pf.result()
43
+ write_obj_uv("model_simplified.obj", V3, F3, None, None)
44
+ ```
45
+
46
+ More in [`examples/`](examples/). Most modules also work as command-line tools, for example
47
+ `python -m rqmesh.transitions --help` and `python -m rqmesh.isolation model.obj`.
48
+
49
+ ## Modules
50
+
51
+ | Module | Purpose |
52
+ |---|---|
53
+ | `structsimp`, `transitions` | Ring collapse, strip transitions, the error ladder (`adaptive_simplify`) |
54
+ | `topofix` | Pole fixing, refills, isolation-ring guard |
55
+ | `isolation` | Openings, isolating rings, protected loops, reports |
56
+ | `subdiv`, `subdiv_tri` | Base-cage recovery for quad and triangle subdivision schemes |
57
+ | `features`, `crease_split`, `symmetry` | Sharp features, crease splitting, mirror planes |
58
+ | `analyze` | Structure report and recommendation |
59
+ | `scalefield`, `defofield` | Cross fields (scale-matched for sculpts; deformation) |
60
+ | `repair` | Welding, small holes, degenerate faces |
61
+ | `qw_driver`, `strip_bounds` | Driver for the optional QuadWild-BiMDF back-end package |
62
+ | `meshio_min`, `compat`, `rosy` | I/O and NumPy-only stand-ins |
63
+
64
+ ## Development
65
+
66
+ ```
67
+ pip install -e .[test,scipy]
68
+ pytest
69
+ ```
70
+
71
+ The CI runs the tests on Linux, Windows and macOS, on Python 3.11 and 3.13, with and without SciPy.
72
+ Blender's bundled Python has NumPy but no SciPy, so the NumPy-only path has to keep working.
73
+
74
+ ## Licence
75
+
76
+ Apache-2.0 (see [LICENSE](LICENSE)). Apache-2.0 is compatible with the GPL-3.0, so the Blender extension (GPL) can
77
+ bundle this library.
78
+
79
+ ## Citing
80
+
81
+ If you use rqmesh in research, please cite it using [CITATION.cff](CITATION.cff); GitHub shows a "Cite this
82
+ repository" button.
@@ -0,0 +1,36 @@
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ """Simplify a quad mesh by edge rings, keep isolation loops around openings, then fix poles.
3
+
4
+ usage: python simplify_and_fix.py IN.obj OUT.obj [RATIO] (no input: a generated test torus)"""
5
+ import sys, time
6
+ import numpy as np
7
+ from rqmesh.meshio_min import read_obj_uv, write_obj_uv
8
+ from rqmesh import transitions, topofix, isolation
9
+
10
+
11
+ def torus(n=64, m=32, R=1.0, r=0.4):
12
+ V = np.array([[(R + r * np.cos(2 * np.pi * j / m)) * np.cos(2 * np.pi * i / n),
13
+ (R + r * np.cos(2 * np.pi * j / m)) * np.sin(2 * np.pi * i / n), r * np.sin(2 * np.pi * j / m)]
14
+ for i in range(n) for j in range(m)])
15
+ F = [[i * m + j, ((i + 1) % n) * m + j, ((i + 1) % n) * m + (j + 1) % m, i * m + (j + 1) % m]
16
+ for i in range(n) for j in range(m)]
17
+ return V, F, None, None
18
+
19
+
20
+ inp = sys.argv[1] if len(sys.argv) > 1 else None
21
+ out = sys.argv[2] if len(sys.argv) > 2 else 'simplified.obj'
22
+ ratio = float(sys.argv[3]) if len(sys.argv) > 3 else 0.35
23
+ V, F, UV, FUV = read_obj_uv(inp) if inp else torus()
24
+ V = np.asarray(V, float); target = max(4, int(len(F) * ratio))
25
+
26
+ t = time.time()
27
+ loops, linfo = isolation.isolation_loops(V, F, k=2, target_faces=target) # empty if there are no openings
28
+ V2, F2, FUV2, UV2, info = transitions.adaptive_simplify(V, F, target, UV=UV, FUV=FUV, feature_deg=35,
29
+ local='adaptive', cost_mode='qem', transitions='auto',
30
+ extra_feat=sorted(loops) or None)
31
+ pf = topofix.PoleFixer(np.asarray(V2), F2, 30.0)
32
+ pf.guard_isolation(3)
33
+ pf.improve(); pf.refill_poles(); pf.improve(); pf.relax(10)
34
+ V3, F3 = pf.result()
35
+ write_obj_uv(out, V3, F3, None, None)
36
+ print(f"{len(F)} -> {len(F3)} faces, {pf.poles()} poles, {time.time() - t:.1f} s -> {out}")
@@ -0,0 +1,44 @@
1
+ [build-system]
2
+ requires = ["hatchling>=1.27"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "rqmesh"
7
+ version = "0.1.0"
8
+ description = "Structure-aware quad remeshing, simplification and retopology (pure Python + NumPy)"
9
+ readme = "README.md"
10
+ license = "Apache-2.0"
11
+ license-files = ["LICENSE"]
12
+ authors = [{ name = "Daniel Sandner" }]
13
+ requires-python = ">=3.11"
14
+ dependencies = ["numpy>=1.24"]
15
+ keywords = ["quad mesh", "remeshing", "retopology", "geometry processing", "blender", "subdivision"]
16
+ classifiers = [
17
+ "Development Status :: 3 - Alpha",
18
+ "Intended Audience :: Science/Research",
19
+ "Intended Audience :: Developers",
20
+ "Programming Language :: Python :: 3",
21
+ "Programming Language :: Python :: 3.11",
22
+ "Programming Language :: Python :: 3.12",
23
+ "Programming Language :: Python :: 3.13",
24
+ "Topic :: Multimedia :: Graphics :: 3D Modeling",
25
+ "Topic :: Scientific/Engineering :: Mathematics",
26
+ ]
27
+
28
+ [project.optional-dependencies]
29
+ scipy = ["scipy>=1.10"]
30
+ test = ["pytest>=8"]
31
+
32
+ [project.urls]
33
+ Homepage = "https://github.com/sandner-art/rqmesh"
34
+ Issues = "https://github.com/sandner-art/rqmesh/issues"
35
+ "Blender add-on" = "https://github.com/sandner-art/rqmesh-blender"
36
+
37
+ [tool.hatch.build.targets.wheel]
38
+ packages = ["src/rqmesh"]
39
+
40
+ [tool.hatch.build.targets.sdist]
41
+ include = ["src/rqmesh", "tests", "examples", "README.md", "CHANGELOG.md", "CITATION.cff", "LICENSE"]
42
+
43
+ [tool.pytest.ini_options]
44
+ testpaths = ["tests"]
@@ -0,0 +1,20 @@
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ """rqmesh: structure-aware quad remeshing, simplification and retopology.
3
+
4
+ Pure Python + NumPy (SciPy optional, used when present). Modules:
5
+
6
+ structsimp, transitions simplify a quad mesh by removing whole edge rings; 3-1 and gentle strip transitions
7
+ topofix fix poles: rotations, collapses, loop moves and pattern refills; guarded isolation rings
8
+ isolation openings, isolating rings around eyes / mouths / bumps, protected edge loops
9
+ subdiv, subdiv_tri recover the base cage of Catmull-Clark / simple / Loop / midpoint subdivided meshes
10
+ features, crease_split sharp features and crease splitting
11
+ symmetry mirror-plane detection and symmetric operations
12
+ analyze structure report and recommended workflow for a mesh
13
+ scalefield, defofield cross fields: scale-matched curvature fields for sculpts, deformation fields
14
+ repair welds, small holes, degenerate faces
15
+ qw_driver, strip_bounds drive the optional QuadWild-BiMDF back-end (GPL, separate package)
16
+ meshio_min, compat, rosy OBJ / .rosy I/O and NumPy-only stand-ins for SciPy pieces
17
+
18
+ Most modules also run as command-line tools: python -m rqmesh.transitions --help
19
+ """
20
+ __version__ = "0.1.0"
@@ -0,0 +1,114 @@
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ """Structure introspection -> method choice (the introsort / Timsort idea applied to retopology).
3
+
4
+ Hybrid sorts look at the input first (Timsort: existing runs; introsort: recursion depth as a sign of a bad pivot
5
+ sequence) and switch to the algorithm that fits it. For simplification / retopology the "runs" are the modelling
6
+ structure: quads, regular vertices and clean edge loops. Cheap scores, measured in one pass:
7
+
8
+ quad_share fraction of faces that are quads after rebuilding quads from triangles (export order first)
9
+ regular_share fraction of interior vertices with valence 4
10
+ loop_share fraction of quad sides that lie on clean edge loops (no triangle, no self-crossing, no revisit)
11
+ loop_len median clean-loop length relative to sqrt(#faces)
12
+ block_share fraction of quads whose four corners are all regular (where 3-1 strips can work)
13
+ subdiv_levels levels of Catmull-Clark / simple subdivision the mesh carries (topology test, confirmed by fitting
14
+ one level: residual in fine edge lengths); such meshes go to Recover Base Cage first
15
+
16
+ recommend() turns them into a method, the way introsort turns a depth counter into a switch:
17
+ * edge loops (+ transitions when stuck) -- quad-modelled assets with long clean loops
18
+ * adaptive loops + transitions -- quad-modelled but loops are short/blocked (organic, partly symmetric)
19
+ * QEM decimation (triangles) or a field-aligned remesh -- little or no loop structure (scans, iso-remeshes,
20
+ meshes subdivided from triangles, remesher output with spiralling loops)
21
+
22
+ python analyze.py MESH.obj -> JSON
23
+ """
24
+ import sys, os, json, math
25
+ import numpy as np
26
+ try:
27
+ from .meshio_min import read_obj
28
+ from .structsimp import tris_to_quads, Mesh, chords
29
+ from . import subdiv as SD
30
+ from . import subdiv_tri as STRI
31
+ except ImportError:
32
+ sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
33
+ from meshio_min import read_obj
34
+ from structsimp import tris_to_quads, Mesh, chords
35
+ import subdiv as SD
36
+ import subdiv_tri as STRI
37
+
38
+
39
+ def structure_scores(V, F, order_hint=True):
40
+ V = np.asarray(V, float)
41
+ T = [f for f in F if len(f) == 3]
42
+ tri_at = {}
43
+ for f in T:
44
+ for v in f: tri_at[v] = tri_at.get(v, 0) + 1
45
+ fans = sum(1 for v, c in tri_at.items() if c >= 5)
46
+ ngons = sum(1 for f in F if len(f) > 4)
47
+ Q = (tris_to_quads(V, T, order_hint=order_hint) + [f for f in F if len(f) != 3]) if T else [list(f) for f in F]
48
+ nq = sum(1 for f in Q if len(f) == 4)
49
+ M = Mesh(V, Q); em = M.edges()
50
+ bnd = {v for e, fs in em.items() if len(fs) == 1 for v in e}
51
+ val = {}
52
+ for a, b in em: val[a] = val.get(a, 0) + 1; val[b] = val.get(b, 0) + 1
53
+ interior = [v for v in val if v not in bnd]
54
+ regular = sum(1 for v in interior if val[v] == 4)
55
+ clean_sides, lens = 0, []
56
+ for edges, faces, closed in chords(M, em):
57
+ ok = faces and all(f >= 0 for f in faces) and len(set(faces)) == len(faces)
58
+ if ok:
59
+ verts = [v for e in edges for v in e]
60
+ ok = len(set(verts)) == len(verts)
61
+ if ok: clean_sides += len(faces); lens.append(len(faces))
62
+ blocks = sum(1 for f in Q if len(f) == 4 and all(val.get(v, 0) == 4 and v not in bnd for v in f))
63
+ n = max(len(Q), 1)
64
+ sub = subdiv_scores(V, F)
65
+ return dict(sub, faces=len(Q), quad_share=round(nq / n, 4), regular_share=round(regular / max(len(interior), 1), 4),
66
+ loop_share=round(clean_sides / max(2 * nq, 1), 4),
67
+ loop_len=round(float(np.median(lens)) / math.sqrt(n), 3) if lens else 0.0,
68
+ block_share=round(blocks / max(nq, 1), 4), fans=fans, ngons=ngons)
69
+
70
+
71
+ def subdiv_scores(V, F, tol=0.05):
72
+ Q, how = SD.to_quads_if_subdivided(V, [list(f) for f in F])
73
+ if Q is None:
74
+ if F and all(len(f) == 3 for f in F): # triangle subdivision (Loop / Blender Subdivide)
75
+ r = STRI.unsubdivide_tri_once(V, [list(f) for f in F])
76
+ if r is not None and r['residual_rel'] <= tol:
77
+ return dict(subdiv_levels=1, subdiv_scheme='tri-' + r['scheme'], subdiv_residual=round(r['residual_rel'], 6))
78
+ return dict(subdiv_levels=0)
79
+ lv = SD.detect_levels(Q, len(V))
80
+ if lv == 0: return dict(subdiv_levels=0)
81
+ r = SD.unsubdivide_once(V, Q)
82
+ if r is None or r['residual_rel'] > tol:
83
+ return dict(subdiv_levels=0, subdiv_topology_levels=lv, subdiv_residual=None if r is None else round(r['residual_rel'], 5))
84
+ return dict(subdiv_levels=lv, subdiv_scheme=r['scheme'], subdiv_residual=round(r['residual_rel'], 6))
85
+
86
+
87
+ def recommend(s):
88
+ """Rules checked against every case measured in rounds 5-9 (see RESULTS-round9)."""
89
+ if s.get('subdiv_levels', 0) > 0:
90
+ return 'recover_base_first', (f"subdivided (up to {s['subdiv_levels']} level(s); first level {s.get('subdiv_scheme')}, residual "
91
+ f"{s.get('subdiv_residual')}): Recover Base Cage first - the exact cage - then "
92
+ f"re-analyze the cage")
93
+ if s.get('fans', 0) + s.get('ngons', 0) > 0 and s['faces'] < 20000:
94
+ m, why = recommend(dict(s, fans=0, ngons=0))
95
+ return 'quad_caps_first', (f"{s['fans']} triangle fan(s) and {s['ngons']} n-gon(s): run Quad Caps first, "
96
+ f"then re-analyze (now: {why})")
97
+ if s['quad_share'] < 0.9:
98
+ return 'decimate_or_remesh', "few quads: not quad-modelled (scan, triangle export, sculpt)"
99
+ if s['loop_share'] < 0.3 or s['loop_len'] < 0.15:
100
+ return 'decimate_or_remesh', "quads without usable edge loops (iso-remesh, subdivided triangles)"
101
+ if s['regular_share'] >= 0.95 and s['loop_share'] >= 0.9:
102
+ return 'edge_loops', "quad-modelled with clean edge loops: remove whole loops, 3-1 transitions only when stuck"
103
+ return 'adaptive_loops', ("quad-modelled but loops are blocked or poles are many: loops + 3-1 transitions on an "
104
+ "error ladder (expect 2-5x Decimate's geometric error, but quads, UVs and symmetry kept)")
105
+
106
+
107
+ def main():
108
+ V, F = read_obj(sys.argv[1])
109
+ s = structure_scores(V, F); m, why = recommend(s)
110
+ s.update(method=m, why=why); print(json.dumps(s))
111
+
112
+
113
+ if __name__ == '__main__':
114
+ main()