replicator-workshop 0.1.0__py3-none-any.whl

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.
Files changed (118) hide show
  1. replicator/__init__.py +6 -0
  2. replicator/app.py +204 -0
  3. replicator/config.py +48 -0
  4. replicator/core/__init__.py +0 -0
  5. replicator/core/assembly.py +117 -0
  6. replicator/core/blender_link.py +161 -0
  7. replicator/core/critique.py +594 -0
  8. replicator/core/drawing.py +389 -0
  9. replicator/core/dxf.py +120 -0
  10. replicator/core/evaluate.py +439 -0
  11. replicator/core/explain.py +139 -0
  12. replicator/core/export.py +96 -0
  13. replicator/core/fit.py +170 -0
  14. replicator/core/importers.py +185 -0
  15. replicator/core/materials.py +104 -0
  16. replicator/core/ops_advanced.py +496 -0
  17. replicator/core/ops_engineering.py +223 -0
  18. replicator/core/physics.py +147 -0
  19. replicator/core/printers.py +100 -0
  20. replicator/core/program.py +298 -0
  21. replicator/core/render.py +145 -0
  22. replicator/core/reverse.py +350 -0
  23. replicator/core/robot.py +153 -0
  24. replicator/core/step.py +245 -0
  25. replicator/fixtures/gaming_pc_liquid.json +2259 -0
  26. replicator/fixtures/gas_generator_rocket.json +876 -0
  27. replicator/fixtures/gas_generator_rocket_aero.json +861 -0
  28. replicator/fixtures/house_two_bed.json +979 -0
  29. replicator/fixtures/quadcopter_drone.json +687 -0
  30. replicator/fixtures/raspberry_pi_5.json +884 -0
  31. replicator/fixtures/rocket_engine.json +652 -0
  32. replicator/fixtures/turbofan.json +931 -0
  33. replicator/fixtures/vector_engine.json +314 -0
  34. replicator/gpu.py +81 -0
  35. replicator/image3d/__init__.py +0 -0
  36. replicator/image3d/comfy.py +181 -0
  37. replicator/image3d/pipeline.py +208 -0
  38. replicator/image3d/sheet.py +154 -0
  39. replicator/knowledge/__init__.py +61 -0
  40. replicator/knowledge/car_wheel_corner.md +21 -0
  41. replicator/knowledge/desk_lamp.md +21 -0
  42. replicator/knowledge/desktop_pc.md +20 -0
  43. replicator/knowledge/electronics_board.md +21 -0
  44. replicator/knowledge/exoskeleton.md +21 -0
  45. replicator/knowledge/house.md +22 -0
  46. replicator/knowledge/light_aircraft.md +22 -0
  47. replicator/knowledge/multirotor_drone.md +25 -0
  48. replicator/knowledge/print_replica.md +13 -0
  49. replicator/knowledge/rocket_engine.md +27 -0
  50. replicator/knowledge/turbofan.md +23 -0
  51. replicator/llm/__init__.py +0 -0
  52. replicator/llm/client.py +424 -0
  53. replicator/llm/prompts/blueprint.md +28 -0
  54. replicator/llm/prompts/edit.md +15 -0
  55. replicator/llm/prompts/explain.md +37 -0
  56. replicator/llm/prompts/name_parts.md +13 -0
  57. replicator/llm/prompts/program.md +72 -0
  58. replicator/llm/prompts/research_queries.md +8 -0
  59. replicator/mcp_server.py +307 -0
  60. replicator/qml/Main.qml +874 -0
  61. replicator/qml/Replicator/UI/Chip.qml +17 -0
  62. replicator/qml/Replicator/UI/DockHeader.qml +27 -0
  63. replicator/qml/Replicator/UI/Icon.qml +118 -0
  64. replicator/qml/Replicator/UI/IconButton.qml +31 -0
  65. replicator/qml/Replicator/UI/Kbd.qml +18 -0
  66. replicator/qml/Replicator/UI/NumField.qml +69 -0
  67. replicator/qml/Replicator/UI/Pill.qml +28 -0
  68. replicator/qml/Replicator/UI/RCombo.qml +51 -0
  69. replicator/qml/Replicator/UI/RMenu.qml +42 -0
  70. replicator/qml/Replicator/UI/RSlider.qml +23 -0
  71. replicator/qml/Replicator/UI/Segmented.qml +63 -0
  72. replicator/qml/Replicator/UI/Swatch.qml +47 -0
  73. replicator/qml/Replicator/UI/Theme.qml +149 -0
  74. replicator/qml/Replicator/UI/qmldir +14 -0
  75. replicator/qml/panels/AgentPrompt.qml +53 -0
  76. replicator/qml/panels/AttributeManager.qml +171 -0
  77. replicator/qml/panels/Commander.qml +136 -0
  78. replicator/qml/panels/HolodeckPanel.qml +117 -0
  79. replicator/qml/panels/IssuesCard.qml +78 -0
  80. replicator/qml/panels/LedgerPanel.qml +110 -0
  81. replicator/qml/panels/MaterialShelf.qml +97 -0
  82. replicator/qml/panels/ObjectManager.qml +107 -0
  83. replicator/qml/panels/Preferences.qml +211 -0
  84. replicator/qml/panels/Presenter.qml +316 -0
  85. replicator/qml/panels/StatusBar.qml +77 -0
  86. replicator/qml/panels/Timeline.qml +149 -0
  87. replicator/qml/panels/Welcome.qml +126 -0
  88. replicator/qml/viewport/Callouts.qml +87 -0
  89. replicator/qml/viewport/EdgeMaterial.qml +16 -0
  90. replicator/qml/viewport/GridMaterial.qml +16 -0
  91. replicator/qml/viewport/HoloMaterial.qml +23 -0
  92. replicator/qml/viewport/NavGizmo.qml +72 -0
  93. replicator/qml/viewport/ReferenceMaterial.qml +17 -0
  94. replicator/qml/viewport/Viewport.qml +583 -0
  95. replicator/qt/__init__.py +0 -0
  96. replicator/qt/bridge.py +1427 -0
  97. replicator/qt/drawing_sheet.py +33 -0
  98. replicator/qt/envmap.py +40 -0
  99. replicator/qt/library.py +68 -0
  100. replicator/qt/mesh_geometry.py +167 -0
  101. replicator/qt/svg.py +41 -0
  102. replicator/research/__init__.py +0 -0
  103. replicator/research/lane.py +281 -0
  104. replicator/shaders/edge.frag +9 -0
  105. replicator/shaders/edge.vert +7 -0
  106. replicator/shaders/grid.frag +52 -0
  107. replicator/shaders/grid.vert +6 -0
  108. replicator/shaders/holo.frag +41 -0
  109. replicator/shaders/reference.frag +15 -0
  110. replicator/shaders/reference.vert +6 -0
  111. replicator/voice.py +120 -0
  112. replicator_workshop-0.1.0.dist-info/METADATA +410 -0
  113. replicator_workshop-0.1.0.dist-info/RECORD +118 -0
  114. replicator_workshop-0.1.0.dist-info/WHEEL +5 -0
  115. replicator_workshop-0.1.0.dist-info/entry_points.txt +3 -0
  116. replicator_workshop-0.1.0.dist-info/licenses/LICENSE +21 -0
  117. replicator_workshop-0.1.0.dist-info/licenses/vendor/mcp-for-blender/LICENSE +21 -0
  118. replicator_workshop-0.1.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,245 @@
1
+ """STEP (ISO 10303-21, AP214) out of exact Manifold solids, as faceted B-rep.
2
+
3
+ Every connected lump of a part becomes one MANIFOLD_SOLID_BREP (BREP_WITH_VOIDS when it encloses a cavity). Adjacent coplanar triangles merge into one planar face (a box is six faces,
4
+ not twelve triangles), with holes kept as inner bounds; edges and vertices are shared across faces, so a CAD reader
5
+ gets a closed shell, not a soup. Surfaces are planes: a cylinder arrives as a ring of flat faces, exactly the facets
6
+ Manifold built, so volumes and mass match the workshop to the last facet. Analytic surfaces need an OCCT layer.
7
+
8
+ Written Z-up in the program's units (mm by default), the CAD convention; Replicator itself is Y-up.
9
+ """
10
+ from __future__ import annotations
11
+
12
+ import datetime as _dt
13
+ from pathlib import Path
14
+
15
+ import numpy as np
16
+
17
+ from .evaluate import Shape
18
+
19
+ _UNITS = {"mm": ".MILLI.", "m": None, "cm": ".CENTI."}
20
+ _INCH = 25.4
21
+
22
+
23
+ class _Writer:
24
+ def __init__(self):
25
+ self.lines: list[str] = []
26
+
27
+ def add(self, entity: str) -> int:
28
+ self.lines.append(entity)
29
+ return len(self.lines)
30
+
31
+ def point(self, p) -> int:
32
+ return self.add(f"CARTESIAN_POINT('',({_f(p[0])},{_f(p[1])},{_f(p[2])}))")
33
+
34
+ def direction(self, d) -> int:
35
+ return self.add(f"DIRECTION('',({_f(d[0])},{_f(d[1])},{_f(d[2])}))")
36
+
37
+
38
+ def _f(x: float) -> str:
39
+ s = f"{float(x):.10G}"
40
+ if "E" in s:
41
+ m, e = s.split("E")
42
+ return (m if "." in m else m + ".") + "E" + e
43
+ return s if "." in s else s + "."
44
+
45
+
46
+ def _s(text: str) -> str:
47
+ return "'" + text.encode("ascii", "replace").decode().replace("'", "''").replace("\\", "\\\\") + "'"
48
+
49
+
50
+ def _planar_groups(v: np.ndarray, f: np.ndarray, tol: float) -> list[np.ndarray]:
51
+ """Edge-connected triangles that lie in one plane, as lists of triangle indices."""
52
+ n = np.cross(v[f[:, 1]] - v[f[:, 0]], v[f[:, 2]] - v[f[:, 0]])
53
+ ln = np.linalg.norm(n, axis=1)
54
+ ok = ln > 0
55
+ n[ok] /= ln[ok, None]
56
+ d = np.einsum("ij,ij->i", n, v[f[:, 0]])
57
+ # A zero-area sliver (three collinear vertices) cannot be a face of its own, and leaving it out opens the shell.
58
+ # It joins the neighbour across its longest edge; its middle vertex becomes one more point on that face's boundary.
59
+ corner = np.stack([np.linalg.norm(v[f[:, (k + 1) % 3]] - v[f[:, k]], axis=1) for k in range(3)], 1).argmax(1)
60
+ longest = {t: (int(f[t, k]), int(f[t, (k + 1) % 3])) for t, k in enumerate(corner) if not ok[t]}
61
+ parent = np.arange(len(f))
62
+
63
+ def find(i):
64
+ while parent[i] != i:
65
+ parent[i] = parent[parent[i]]
66
+ i = parent[i]
67
+ return i
68
+
69
+ edges: dict[tuple[int, int], int] = {}
70
+ for t, tri in enumerate(f):
71
+ for a, b in ((tri[0], tri[1]), (tri[1], tri[2]), (tri[2], tri[0])):
72
+ o = edges.pop((b, a), None) # the neighbour across this edge walks it the other way
73
+ if o is None:
74
+ edges[(a, b)] = t
75
+ elif (ok[t] and ok[o] and n[t] @ n[o] > 1 - 1e-9 and abs(d[t] - d[o]) < tol) or \
76
+ longest.get(t) == (a, b) or longest.get(o) == (b, a):
77
+ ra, rb = find(t), find(o)
78
+ if ra != rb:
79
+ parent[ra] = rb
80
+ roots = np.array([find(i) for i in range(len(f))])
81
+ order = np.argsort(roots, kind="stable")
82
+ cuts = np.flatnonzero(np.diff(roots[order])) + 1
83
+ return np.split(order, cuts)
84
+
85
+
86
+ def _loops(f: np.ndarray, tris: np.ndarray) -> list[list[int]]:
87
+ """Boundary loops of a planar triangle group, each walked in the triangles' winding (outer CCW, holes CW)."""
88
+ half: dict[tuple[int, int], None] = {}
89
+ for tri in f[tris]:
90
+ for a, b in ((tri[0], tri[1]), (tri[1], tri[2]), (tri[2], tri[0])):
91
+ if (b, a) in half:
92
+ del half[(b, a)]
93
+ else:
94
+ half[(a, b)] = None
95
+ nxt: dict[int, list[int]] = {}
96
+ for a, b in half:
97
+ nxt.setdefault(int(a), []).append(int(b))
98
+ loops = []
99
+ while nxt:
100
+ start = next(iter(nxt))
101
+ loop, cur = [start], start
102
+ while True:
103
+ outs = nxt[cur]
104
+ b = outs.pop()
105
+ if not outs:
106
+ del nxt[cur]
107
+ if b == start:
108
+ break
109
+ loop.append(b)
110
+ cur = b
111
+ if cur not in nxt: # a broken boundary; never happens on a manifold, guard against a hang
112
+ break
113
+ if len(loop) >= 3:
114
+ loops.append(loop)
115
+ return loops
116
+
117
+
118
+ def _shell(w: _Writer, v: np.ndarray, f: np.ndarray, tol: float) -> int:
119
+ vert_ids: dict[int, int] = {}
120
+ edge_ids: dict[tuple[int, int], int] = {}
121
+
122
+ def vertex(i: int) -> int:
123
+ if i not in vert_ids:
124
+ vert_ids[i] = w.add(f"VERTEX_POINT('',#{w.point(v[i])})")
125
+ return vert_ids[i]
126
+
127
+ def oriented_edge(a: int, b: int) -> str:
128
+ key = (min(a, b), max(a, b))
129
+ if key not in edge_ids:
130
+ p, q = v[key[0]], v[key[1]]
131
+ d = q - p
132
+ ln = float(np.linalg.norm(d))
133
+ vec = w.add(f"VECTOR('',#{w.direction(d / ln)},{_f(ln)})")
134
+ line = w.add(f"LINE('',#{w.point(p)},#{vec})")
135
+ edge_ids[key] = w.add(f"EDGE_CURVE('',#{vertex(key[0])},#{vertex(key[1])},#{line},.T.)")
136
+ return f"ORIENTED_EDGE('',*,*,#{edge_ids[key]},{'.T.' if a == key[0] else '.F.'})"
137
+
138
+ faces = []
139
+ for tris in _planar_groups(v, f, tol):
140
+ loops = _loops(f, tris)
141
+ if not loops:
142
+ continue
143
+ g = f[tris]
144
+ nrm = np.cross(v[g[:, 1]] - v[g[:, 0]], v[g[:, 2]] - v[g[:, 0]]).sum(0) # area-weighted: sliver-proof
145
+ ln = float(np.linalg.norm(nrm))
146
+ if ln == 0: # zero-area group (Manifold drops these; guard anyway)
147
+ continue
148
+ nrm = nrm / ln
149
+
150
+ def area(loop):
151
+ p = v[loop]
152
+ return float(np.cross(p, np.roll(p, -1, 0)).sum(0) @ nrm) / 2
153
+
154
+ outer = max(range(len(loops)), key=lambda k: area(loops[k]))
155
+ bounds = []
156
+ for k, loop in enumerate(loops):
157
+ es = ",".join(f"#{w.add(oriented_edge(a, b))}" for a, b in zip(loop, loop[1:] + loop[:1]))
158
+ el = w.add(f"EDGE_LOOP('',({es}))")
159
+ bounds.append(w.add(f"{'FACE_OUTER_BOUND' if k == outer else 'FACE_BOUND'}('',#{el},.T.)"))
160
+ p0 = v[loops[outer][0]]
161
+ ref = v[loops[outer][1]] - p0
162
+ ref = ref - (ref @ nrm) * nrm
163
+ if np.linalg.norm(ref) < 1e-12:
164
+ ref = np.cross(nrm, [1.0, 0, 0] if abs(nrm[0]) < 0.9 else [0, 1.0, 0])
165
+ ref = ref / np.linalg.norm(ref)
166
+ ax = w.add(f"AXIS2_PLACEMENT_3D('',#{w.point(p0)},#{w.direction(nrm)},#{w.direction(ref)})")
167
+ plane = w.add(f"PLANE('',#{ax})")
168
+ faces.append(w.add(f"ADVANCED_FACE('',({','.join(f'#{b}' for b in bounds)}),#{plane},.T.)"))
169
+ return w.add(f"CLOSED_SHELL('',({','.join(f'#{x}' for x in faces)}))")
170
+
171
+
172
+ def _arrays(m, scale: float) -> tuple[np.ndarray, np.ndarray]:
173
+ mesh = m.to_mesh()
174
+ v = np.asarray(mesh.vert_properties[:, :3], np.float64) * scale
175
+ return np.column_stack([v[:, 0], -v[:, 2], v[:, 1]]), np.asarray(mesh.tri_verts, np.int64) # Y-up to Z-up
176
+
177
+
178
+ def _solids(w: _Writer, manifold, name: str, scale: float) -> list[int]:
179
+ """One B-rep solid per connected lump; an internal cavity (a negative lump) becomes a void of the smallest lump
180
+ whose box holds it, so a hollow part keeps its real volume in CAD."""
181
+ lumps = manifold.decompose()
182
+ pos = [m for m in lumps if m.volume() > 0]
183
+ neg = [m for m in lumps if m.volume() < 0]
184
+ box = lambda m: (np.asarray(m.bounding_box()[:3]), np.asarray(m.bounding_box()[3:]))
185
+ voids: dict[int, list] = {i: [] for i in range(len(pos))}
186
+ for c in neg:
187
+ clo, chi = box(c)
188
+ inside = [i for i, m in enumerate(pos) if np.all(box(m)[0] <= clo) and np.all(chi <= box(m)[1])]
189
+ if inside:
190
+ voids[min(inside, key=lambda i: pos[i].volume())].append(c)
191
+ out = []
192
+ for i, m in enumerate(pos):
193
+ v, f = _arrays(m, scale)
194
+ tol = max(float(np.ptp(v, axis=0).max()), 1.0) * 1e-7
195
+ label = name if len(pos) == 1 else f"{name} {i + 1}"
196
+ outer = _shell(w, v, f, tol)
197
+ if not voids[i]:
198
+ out.append(w.add(f"MANIFOLD_SOLID_BREP({_s(label)},#{outer})"))
199
+ continue
200
+ inner = []
201
+ for c in voids[i]: # cavity faces point into the hole; STEP wants the shell reversed
202
+ cv, cf = _arrays(c, scale)
203
+ inner.append(w.add(f"ORIENTED_CLOSED_SHELL('',*,#{_shell(w, cv, cf[:, ::-1], tol)},.F.)"))
204
+ out.append(w.add(f"BREP_WITH_VOIDS({_s(label)},#{outer},({','.join(f'#{x}' for x in inner)}))"))
205
+ return out
206
+
207
+
208
+ def write(shapes: list[Shape], path: str | Path, name: str = "Replicator part", units: str = "mm") -> Path:
209
+ """Write the solids to a STEP file. Raises on open surfaces: STEP solids must be closed."""
210
+ path = Path(path)
211
+ bad = [s.id for s in shapes if not hasattr(s.manifold, "status") or s.manifold.status().name != "NoError"
212
+ or s.manifold.is_empty()]
213
+ if bad:
214
+ raise ValueError(f"STEP needs closed solids; these parts are open or broken: {bad}. Export GLB instead")
215
+ scale, unit = (_INCH, ".MILLI.") if units == "in" else (1.0, _UNITS.get(units, ".MILLI."))
216
+ w = _Writer()
217
+ ctx_len = w.add(f"(LENGTH_UNIT() NAMED_UNIT(*) SI_UNIT({unit or '$'},.METRE.))")
218
+ ctx_ang = w.add("(NAMED_UNIT(*) PLANE_ANGLE_UNIT() SI_UNIT($,.RADIAN.))")
219
+ ctx_sol = w.add("(NAMED_UNIT(*) SI_UNIT($,.STERADIAN.) SOLID_ANGLE_UNIT())")
220
+ unc = w.add(f"UNCERTAINTY_MEASURE_WITH_UNIT(LENGTH_MEASURE(1.E-06),#{ctx_len},'distance_accuracy_value','')")
221
+ ctx = w.add(f"(GEOMETRIC_REPRESENTATION_CONTEXT(3) GLOBAL_UNCERTAINTY_ASSIGNED_CONTEXT((#{unc})) "
222
+ f"GLOBAL_UNIT_ASSIGNED_CONTEXT((#{ctx_len},#{ctx_ang},#{ctx_sol})) "
223
+ f"REPRESENTATION_CONTEXT('Context #1','3D Context with UNIT and UNCERTAINTY'))")
224
+ origin = w.add(f"AXIS2_PLACEMENT_3D('',#{w.point((0, 0, 0))},#{w.direction((0, 0, 1))},#{w.direction((1, 0, 0))})")
225
+ solids = []
226
+ for s in shapes:
227
+ solids += _solids(w, s.manifold, s.label or s.id, scale)
228
+ rep = w.add(f"ADVANCED_BREP_SHAPE_REPRESENTATION({_s(name)},(#{origin},{','.join(f'#{x}' for x in solids)}),#{ctx})")
229
+ app = w.add("APPLICATION_CONTEXT('automotive_design')")
230
+ w.add(f"APPLICATION_PROTOCOL_DEFINITION('international standard','automotive_design',2000,#{app})")
231
+ mctx = w.add(f"PRODUCT_CONTEXT('',#{app},'mechanical')")
232
+ prod = w.add(f"PRODUCT({_s(name)},{_s(name)},'',(#{mctx}))")
233
+ w.add(f"PRODUCT_RELATED_PRODUCT_CATEGORY('part',$,(#{prod}))")
234
+ form = w.add(f"PRODUCT_DEFINITION_FORMATION('','',#{prod})")
235
+ dctx = w.add(f"PRODUCT_DEFINITION_CONTEXT('part definition',#{app},'design')")
236
+ pdef = w.add(f"PRODUCT_DEFINITION('design','',#{form},#{dctx})")
237
+ pds = w.add(f"PRODUCT_DEFINITION_SHAPE('','',#{pdef})")
238
+ w.add(f"SHAPE_DEFINITION_REPRESENTATION(#{pds},#{rep})")
239
+ stamp = _dt.datetime.now().replace(microsecond=0).isoformat()
240
+ head = ["ISO-10303-21;", "HEADER;", "FILE_DESCRIPTION(('Replicator faceted B-rep'),'2;1');",
241
+ f"FILE_NAME({_s(path.name)},'{stamp}',(''),(''),'Replicator','Replicator','');",
242
+ "FILE_SCHEMA(('AUTOMOTIVE_DESIGN { 1 0 10303 214 1 1 1 1 }'));", "ENDSEC;", "DATA;"]
243
+ body = [f"#{i}={e};" for i, e in enumerate(w.lines, 1)]
244
+ path.write_text("\n".join(head + body + ["ENDSEC;", "END-ISO-10303-21;", ""]))
245
+ return path