- Sketch projection partly works again :)
This commit is contained in:
69
main.py
69
main.py
@@ -49,7 +49,6 @@ class ExtrudeDialog(QDialog):
|
||||
self.rounded_checkbox = QCheckBox('Round Edges')
|
||||
self.seperator = create_hline()
|
||||
|
||||
|
||||
# OK and Cancel buttons
|
||||
button_layout = QHBoxLayout()
|
||||
ok_button = QPushButton('OK')
|
||||
@@ -263,14 +262,12 @@ class MainWindow(QMainWindow):
|
||||
sketch = Sketch()
|
||||
sketch.id = name
|
||||
sketch.origin = [0,0,0]
|
||||
sketch.slv_points = []
|
||||
sketch.slv_lines = []
|
||||
sketch.proj_points = []
|
||||
sketch.proj_lines = []
|
||||
|
||||
self.sketchWidget.reset_buffers()
|
||||
self.sketchWidget.set_sketch(sketch)
|
||||
self.sketchWidget.create_sketch(sketch)
|
||||
|
||||
def add_new_sketch_wp(self):
|
||||
## Sketch projected from 3d view into 2d
|
||||
name = f"sketches-{str(names.get_first_name())}"
|
||||
sketch = Sketch()
|
||||
sketch.id = name
|
||||
@@ -280,11 +277,13 @@ class MainWindow(QMainWindow):
|
||||
sketch.slv_lines = []
|
||||
sketch.proj_points = self.custom_3D_Widget.project_tosketch_points
|
||||
sketch.proj_lines = self.custom_3D_Widget.project_tosketch_lines
|
||||
|
||||
self.sketchWidget.reset_buffers()
|
||||
self.sketchWidget.set_sketch(sketch)
|
||||
self.sketchWidget.create_sketch(sketch)
|
||||
self.sketchWidget.create_workplane_projected()
|
||||
self.sketchWidget.convert_proj_points()
|
||||
self.sketchWidget.convert_proj_lines()
|
||||
if not sketch.proj_lines:
|
||||
self.sketchWidget.convert_proj_points(sketch.proj_points)
|
||||
self.sketchWidget.convert_proj_lines(sketch.proj_lines)
|
||||
self.sketchWidget.update()
|
||||
|
||||
# CLear all selections after it has been projected
|
||||
@@ -295,15 +294,24 @@ class MainWindow(QMainWindow):
|
||||
|
||||
def add_sketch(self):
|
||||
"""
|
||||
|
||||
:return:
|
||||
"""
|
||||
sketch = self.sketchWidget.get_sketch()
|
||||
sketch.convert_points_for_sdf()
|
||||
sketch = Sketch()
|
||||
sketch_from_widget = self.sketchWidget.get_sketch()
|
||||
points = sketch_from_widget.points
|
||||
|
||||
sketch.convert_points_for_sdf(points)
|
||||
sketch.id = sketch_from_widget.id
|
||||
|
||||
sketch.filter_lines_for_interactor(sketch_from_widget.lines)
|
||||
|
||||
# Register sketch to timeline
|
||||
self.project.timeline[-1].sketches[sketch.id] = sketch
|
||||
|
||||
# Add Item to slection menu
|
||||
self.ui.sketch_list.addItem(sketch.id)
|
||||
|
||||
# Deactivate drawing
|
||||
self.ui.pb_linetool.setChecked(False)
|
||||
self.sketchWidget.line_mode = False
|
||||
|
||||
@@ -387,7 +395,9 @@ class MainWindow(QMainWindow):
|
||||
name = selected.text()
|
||||
# TODO: add selected element from timeline
|
||||
sel_compo = self.project.timeline[-1]
|
||||
print(sel_compo)
|
||||
sketch = sel_compo.sketches[name]
|
||||
print(sketch)
|
||||
points = sketch.sdf_points
|
||||
|
||||
if points[-1] == points[0]:
|
||||
@@ -428,7 +438,7 @@ class MainWindow(QMainWindow):
|
||||
|
||||
### Interactor
|
||||
interactor = Interactor()
|
||||
interactor.add_lines_for_interactor(sketch.slv_lines)
|
||||
interactor.add_lines_for_interactor(sketch.interactor_lines)
|
||||
|
||||
if not invert:
|
||||
edges = interactor_mesh.generate_mesh(interactor.lines, 0, length)
|
||||
@@ -564,6 +574,8 @@ class Sketch:
|
||||
|
||||
sdf_points: list = None
|
||||
|
||||
interactor_lines: list = None
|
||||
|
||||
# Points coming back from the 3D-Widget as projection to draw on
|
||||
proj_points: list = None
|
||||
proj_lines: list = None
|
||||
@@ -623,13 +635,24 @@ class Sketch:
|
||||
print("p2", p2)
|
||||
return math.sqrt((p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2)
|
||||
|
||||
def convert_points_for_sdf(self):
|
||||
def convert_points_for_sdf(self, points):
|
||||
points_for_sdf = []
|
||||
for point_to_poly in self.slv_points:
|
||||
points_for_sdf.append(self.translate_points_tup(point_to_poly['ui_point']))
|
||||
for point in points:
|
||||
if point.is_helper is False:
|
||||
print("point", point)
|
||||
points_for_sdf.append(self.translate_points_tup(point.ui_point))
|
||||
|
||||
self.sdf_points = points_for_sdf
|
||||
|
||||
def filter_lines_for_interactor(self, lines):
|
||||
### Filter lines that are not meant to be drawn for the interactor like contruction lines
|
||||
filtered_lines = []
|
||||
for line in lines:
|
||||
if not line.is_helper:
|
||||
filtered_lines.append(line)
|
||||
|
||||
self.interactor_lines = filtered_lines
|
||||
|
||||
def extrude(self, height: float, symet: bool = True, invert: bool = False, offset_length: float = None):
|
||||
"""
|
||||
Extrude a 2D shape into 3D, orient it along the normal, and position it relative to the centroid.
|
||||
@@ -677,7 +700,6 @@ class Sketch:
|
||||
|
||||
return f
|
||||
|
||||
|
||||
@dataclass
|
||||
class Interactor:
|
||||
"""Helper mesh consisting of edges for selection"""
|
||||
@@ -708,12 +730,13 @@ class Interactor:
|
||||
return translation_along_normal
|
||||
|
||||
def add_lines_for_interactor(self, input_lines: list):
|
||||
"""Expects slvs_lines main list"""
|
||||
"""Takes Line2D objects from the sketch widget and preparesit for interactor mesh.
|
||||
Translates coordinates."""
|
||||
|
||||
points_for_interact = []
|
||||
for point_to_poly in input_lines:
|
||||
start, end = point_to_poly['ui_points']
|
||||
from_coord_start = window.sketchWidget.from_quadrant_coords_no_center(start)
|
||||
from_coord_end = window.sketchWidget.from_quadrant_coords_no_center(end)
|
||||
from_coord_start = window.sketchWidget.from_quadrant_coords_no_center(point_to_poly.crd1.ui_point)
|
||||
from_coord_end = window.sketchWidget.from_quadrant_coords_no_center(point_to_poly.crd2.ui_point)
|
||||
start_draw = self.translate_points_tup(from_coord_start)
|
||||
end_draw = self.translate_points_tup(from_coord_end)
|
||||
line = start_draw, end_draw
|
||||
@@ -723,7 +746,6 @@ class Interactor:
|
||||
|
||||
self.lines = points_for_interact
|
||||
|
||||
|
||||
@dataclass
|
||||
class Body:
|
||||
"""The actual body as sdf3 object"""
|
||||
@@ -743,7 +765,6 @@ class Body:
|
||||
|
||||
return f
|
||||
|
||||
|
||||
class Output:
|
||||
def export_mesh(self, sdf_object):
|
||||
"""FINAL EXPORT"""
|
||||
@@ -763,13 +784,11 @@ class Output:
|
||||
except Exception as e:
|
||||
print("Error executing code:", e)
|
||||
|
||||
|
||||
class Project:
|
||||
"""Project -> Timeline -> Component -> Sketch -> Body / Interactor -> Connector -> Assembly -> PB Render"""
|
||||
timeline: Timeline = None
|
||||
assembly: Assembly = None
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app = QApplication([])
|
||||
window = MainWindow()
|
||||
|
||||
Reference in New Issue
Block a user