Fixed interactor
Added proj lines selected
This commit is contained in:
87
main.py
87
main.py
@@ -133,11 +133,14 @@ class MainWindow(QMainWindow):
|
||||
def add_new_sketch_wp(self):
|
||||
self.sketchWidget.clear_sketch()
|
||||
#edges = [((-158.0, -20.0, -25.0), (286.0, -195.0, -25.0)), ((-158.0, -20.0, 25.0), (-158.0, -20.0, -25.0))]
|
||||
edges = self.custom_3D_Widget.project_tosketch_edge
|
||||
points = self.custom_3D_Widget.project_tosketch_points
|
||||
normal = self.custom_3D_Widget.selected_normal
|
||||
selected_lines = self.custom_3D_Widget.project_tosketch_lines
|
||||
print("Selected lines", selected_lines)
|
||||
|
||||
self.sketchWidget.create_workplane_projected()
|
||||
self.sketchWidget.create_proj_lines(edges)
|
||||
self.sketchWidget.create_proj_points(points)
|
||||
self.sketchWidget.create_proj_lines(selected_lines)
|
||||
|
||||
# CLear all selections after it has been projected
|
||||
#self.custom_3D_Widget.clear_edge_select()
|
||||
@@ -377,7 +380,6 @@ class MainWindow(QMainWindow):
|
||||
selected = self.ui.sketch_list.currentItem()
|
||||
name = selected.text()
|
||||
points = self.model['sketch'][name]['sketch_points']
|
||||
lines = self.convert_lines_for_interactor()
|
||||
|
||||
if points[-1] == points[0]:
|
||||
#detect loop that causes problems in mesh generation
|
||||
@@ -391,12 +393,8 @@ class MainWindow(QMainWindow):
|
||||
length = 0
|
||||
print("Extrude cancelled")
|
||||
|
||||
#Create and draw Interactor
|
||||
geo = Geometry()
|
||||
|
||||
# Rotation is done in vtk matrix trans
|
||||
angle = 0
|
||||
|
||||
normal = self.custom_3D_Widget.selected_normal
|
||||
print("Normie enter", normal)
|
||||
if normal is None:
|
||||
@@ -407,20 +405,9 @@ class MainWindow(QMainWindow):
|
||||
centroid = [0, 0, 0]
|
||||
else:
|
||||
centroid = list(centroid)
|
||||
print("THis centroid ",centroid)
|
||||
print("This centroid ", centroid)
|
||||
|
||||
f = geo.extrude_shape(points, length, angle, normal, centroid, is_symmetric, invert)
|
||||
|
||||
z_origin = centroid[2]
|
||||
if is_symmetric:
|
||||
z_origin = z_origin - length / 2
|
||||
|
||||
if invert:
|
||||
edges = interactor_mesh.generate_mesh(lines, z_origin, length, True)
|
||||
else:
|
||||
edges = interactor_mesh.generate_mesh(lines, z_origin, length, False)
|
||||
|
||||
self.custom_3D_Widget.load_interactor_mesh(edges)
|
||||
f = geo.extrude_shape(points, length, normal, centroid, is_symmetric, invert, 0)
|
||||
|
||||
name_op = f"extrd-{name}"
|
||||
element = {
|
||||
@@ -428,7 +415,18 @@ class MainWindow(QMainWindow):
|
||||
'type': 'extrude',
|
||||
'sdf_object': f,
|
||||
}
|
||||
#print(element)
|
||||
|
||||
### Interactor
|
||||
lines = self.convert_lines_for_interactor()
|
||||
|
||||
edges = interactor_mesh.generate_mesh(lines, 0, length)
|
||||
|
||||
offset_vector = geo.vector_to_centroid(None, centroid, normal)
|
||||
#print("off_ved", offset_vector)
|
||||
if len(offset_vector) == 0 :
|
||||
offset_vector = [0, 0, 0]
|
||||
|
||||
self.custom_3D_Widget.load_interactor_mesh(edges, offset_vector)
|
||||
|
||||
self.model['operation'][name_op] = element
|
||||
self.ui.body_list.addItem(name_op)
|
||||
@@ -500,7 +498,22 @@ class Geometry:
|
||||
print("p2", p2)
|
||||
return math.sqrt((p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2)
|
||||
|
||||
def extrude_shape(self, points, length: float, angle, normal, centroid, symet: bool = True, invert: bool = False):
|
||||
def vector_to_centroid(self, shape_center, centroid, normal):
|
||||
|
||||
if not shape_center:
|
||||
# Calculate the current center of the shape
|
||||
shape_center = [0, 0, 0]
|
||||
|
||||
# Calculate the vector from the shape's center to the centroid
|
||||
center_to_centroid = np.array(centroid) - np.array(shape_center)
|
||||
|
||||
# Project this vector onto the normal to get the required translation along the normal
|
||||
translation_along_normal = np.dot(center_to_centroid, normal) * normal
|
||||
|
||||
return translation_along_normal
|
||||
|
||||
def extrude_shape(self, points, length: float, normal, centroid, 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.
|
||||
"""
|
||||
@@ -520,17 +533,29 @@ class Geometry:
|
||||
# Orient the shape along the normal vector
|
||||
f = f.orient(normal)
|
||||
|
||||
# Calculate the current center of the shape
|
||||
shape_center = [0,0,0]
|
||||
offset_vector = self.vector_to_centroid(None, centroid, normal)
|
||||
# Adjust the offset vector by subtracting the inset distance along the normal direction
|
||||
adjusted_offset = offset_vector - (normal * length)
|
||||
if invert:
|
||||
# Translate the shape along the adjusted offset vector
|
||||
f = f.translate(adjusted_offset)
|
||||
else:
|
||||
f = f.translate(offset_vector)
|
||||
|
||||
# Calculate the vector from the shape's center to the centroid
|
||||
center_to_centroid = np.array(centroid) - np.array(shape_center)
|
||||
# If offset_length is provided, adjust the offset_vector
|
||||
if offset_length is not None:
|
||||
# Check if offset_vector is not a zero vector
|
||||
offset_vector_magnitude = np.linalg.norm(offset_vector)
|
||||
if offset_vector_magnitude > 1e-10: # Use a small threshold to avoid floating-point issues
|
||||
# Normalize the offset vector
|
||||
offset_vector_norm = offset_vector / offset_vector_magnitude
|
||||
# Scale the normalized vector by the desired length
|
||||
offset_vector = offset_vector_norm * offset_length
|
||||
f = f.translate(offset_vector)
|
||||
else:
|
||||
print("Warning: Offset vector has zero magnitude. Using original vector.")
|
||||
|
||||
# Project this vector onto the normal to get the required translation along the normal
|
||||
translation_along_normal = np.dot(center_to_centroid, normal) * normal
|
||||
|
||||
# Translate the shape along the normal
|
||||
f = f.translate(translation_along_normal)
|
||||
# Translate the shape along the adjusted offset vector
|
||||
|
||||
return f
|
||||
|
||||
|
||||
Reference in New Issue
Block a user