Skip to content

Commit

Permalink
Add freeform support
Browse files Browse the repository at this point in the history
  • Loading branch information
5axes committed Mar 8, 2021
1 parent c1476c3 commit 5407fc8
Show file tree
Hide file tree
Showing 12 changed files with 11,571 additions and 7 deletions.
22 changes: 20 additions & 2 deletions CustomSupport.qml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// "AAngle" : Support Angle in °
// "YDirection" : Support Y direction (Abutment)
// "EHeights" : Equalize heights (Abutment)
// "SType" : Support Type ( Cylinder/Tube/Cube/Abutment/Custom )
// "SType" : Support Type ( Cylinder/Tube/Cube/Abutment/Freeform/Custom )
//-----------------------------------------------------------------------------

import QtQuick 2.2
Expand All @@ -35,6 +35,7 @@ Item
cubeButton.checked = type === 'cube';
abutmentButton.checked = type === 'abutment';
customButton.checked = type === 'custom';
freeformButton.checked = type === 'freeform';
UM.ActiveTool.setProperty("SType", type);
}

Expand Down Expand Up @@ -86,7 +87,7 @@ Item
onClicked: setSType('cube');
style: UM.Theme.styles.tool_button;
checked: UM.ActiveTool.properties.getValue("SType") === 'cube';
z: 3; // Profondeur
z: 4; // Profondeur
}

Button
Expand All @@ -99,6 +100,19 @@ Item
onClicked: setSType('abutment');
style: UM.Theme.styles.tool_button;
checked: UM.ActiveTool.properties.getValue("SType") === 'abutment';
z: 3; // Profondeur
}

Button
{
id: freeformButton;
text: catalog.i18nc("@label", "Freeform");
iconSource: "type_freeform.svg";
property bool needBorder: true;
checkable:true;
onClicked: setSType('freeform');
style: UM.Theme.styles.tool_button;
checked: UM.ActiveTool.properties.getValue("SType") === 'freeform';
z: 2; // Profondeur
}

Expand Down Expand Up @@ -145,6 +159,7 @@ Item
font: UM.Theme.getFont("default");
color: UM.Theme.getColor("text");
verticalAlignment: Text.AlignVCenter;
visible: !freeformButton.checked;
renderType: Text.NativeRendering
width: Math.ceil(contentWidth) //Make sure that the grid cells have an integer width.
}
Expand All @@ -168,6 +183,7 @@ Item
font: UM.Theme.getFont("default");
color: UM.Theme.getColor("text");
verticalAlignment: Text.AlignVCenter;
visible: !freeformButton.checked;
renderType: Text.NativeRendering
width: Math.ceil(contentWidth) //Make sure that the grid cells have an integer width.
}
Expand Down Expand Up @@ -201,6 +217,7 @@ Item
height: UM.Theme.getSize("setting_control").height;
property string unit: "mm";
style: UM.Theme.styles.text_field;
visible: !freeformButton.checked;
text: UM.ActiveTool.properties.getValue("MSize")
validator: DoubleValidator
{
Expand Down Expand Up @@ -251,6 +268,7 @@ Item
height: UM.Theme.getSize("setting_control").height;
property string unit: "°";
style: UM.Theme.styles.text_field;
visible: !freeformButton.checked;
text: UM.ActiveTool.properties.getValue("AAngle")
validator: DoubleValidator
{
Expand Down
61 changes: 58 additions & 3 deletions CustomSupportsCylinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,16 @@
# V2.3.0 10-18-2020 Add Y direction and Equalize heights for Abutment support type
# V2.4.0 01-21-2021 New option Max size to limit the size of the base
# V2.4.1 01-24-2021 By default support are not define with the property support_mesh_drop_down = True
# V2.5.0 03-07-2021 freeform
#--------------------------------------------------------------------------------------------

from PyQt5.QtCore import Qt, QTimer
from PyQt5.QtWidgets import QApplication

from cura.CuraApplication import CuraApplication

from UM.Mesh.MeshData import MeshData, calculateNormalsFromIndexedVertices

from UM.Logger import Logger
from UM.Message import Message
from UM.Math.Matrix import Matrix
Expand Down Expand Up @@ -61,6 +64,8 @@

import math
import numpy
import os
import trimesh


class CustomSupportsCylinder(Tool):
Expand Down Expand Up @@ -201,6 +206,7 @@ def event(self, event):
picked_position = picking_pass.getPickedPosition(event.x, event.y)
picked_position_b = picking_pass.getPickedPosition(event.x, event.y)
self._Svg_Position = picked_position_b

# Add the support_mesh cube at the picked location
self._createSupportMesh(picked_node, picked_position,picked_position_b)

Expand All @@ -216,6 +222,8 @@ def _createSupportMesh(self, parent: CuraSceneNode, position: Vector , position2
node.setName("CustomSupportCube")
elif self._SType == 'abutment':
node.setName("CustomSupportAbutment")
elif self._SType == 'freeform':
node.setName("CustomSupportFreeForm")
else:
node.setName("CustomSupportCustom")

Expand All @@ -234,6 +242,21 @@ def _createSupportMesh(self, parent: CuraSceneNode, position: Vector , position2
elif self._SType == 'cube':
# Cube creation Size , length
mesh = self._createCube(self._UseSize,self._MaxSize,long,self._UseAngle)
elif self._SType == 'freeform':
# Cube creation Size , length
mesh = MeshBuilder()
model_definition_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "models", "support.stl")
# Logger.log('d', 'Model_definition_path : ' + str(model_definition_path))
load_mesh = trimesh.load(model_definition_path)
origin = [0, 0, 0]
DirX = [1, 0, 0]
DirY = [0, 1, 0]
DirZ = [0, 0, 1]
load_mesh.apply_transform(trimesh.transformations.scale_matrix(self._UseSize, origin, DirX))
load_mesh.apply_transform(trimesh.transformations.scale_matrix(self._UseSize, origin, DirY))
load_mesh.apply_transform(trimesh.transformations.scale_matrix(long, origin, DirZ))
mesh = self._toMeshData(load_mesh)

elif self._SType == 'abutment':
# Abutement creation Size , length , top
if self._EqualizeHeights == True :
Expand All @@ -255,7 +278,10 @@ def _createSupportMesh(self, parent: CuraSceneNode, position: Vector , position2
extra_top=extruder_stack.getProperty("support_interface_height", "value")
mesh = self._createCustom(self._UseSize,self._MaxSize,position,position2,self._UseAngle,extra_top)

node.setMeshData(mesh.build())
if self._SType != 'freeform':
node.setMeshData(mesh.build())
else:
node.setMeshData(mesh)

# test for init position
node_transform = Matrix()
Expand Down Expand Up @@ -345,7 +371,36 @@ def _selectionChangeDelay(self):
self._skip_press = False

self._had_selection = has_selection


# Initial Source code from fieldOfView
def _toMeshData(self, tri_node: trimesh.base.Trimesh) -> MeshData:
# Rotate the part to laydown on the build plate
tri_node.apply_transform(trimesh.transformations.rotation_matrix(math.radians(90), [-1, 0, 0]))
tri_faces = tri_node.faces
tri_vertices = tri_node.vertices

indices = []
vertices = []

index_count = 0
face_count = 0
for tri_face in tri_faces:
face = []
for tri_index in tri_face:
vertices.append(tri_vertices[tri_index])
face.append(index_count)
index_count += 1
indices.append(face)
face_count += 1

vertices = numpy.asarray(vertices, dtype=numpy.float32)
indices = numpy.asarray(indices, dtype=numpy.int32)
normals = calculateNormalsFromIndexedVertices(vertices, indices, face_count)

mesh_data = MeshData(vertices=vertices, indices=indices, normals=normals)

return mesh_data

# Cube Creation
def _createCube(self, size, maxs, height, dep):
mesh = MeshBuilder()
Expand Down Expand Up @@ -398,7 +453,7 @@ def _createCube(self, size, maxs, height, dep):

mesh.calculateNormals()
return mesh

# Abutment Creation
def _createAbutment(self, size, maxs, height, top, dep, ydir):

Expand Down
Binary file modified images/button.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/conical_support.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/custom_support.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/freeform_support.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/option_n.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/support.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions models/support.scad
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//----------------------------------------------
// Custom Support size must be 1x1x1
//----------------------------------------------
$fn=30;

translate([-0.5,-0.5,-1.0])
union() {
translate([0.2,0.5,0.0]) cylinder ( h = 0.01, r = 0.3, center = false);
translate([0.5,0.5,0.96]) sphere ( r = 0.05);
translate([0.13,0.5,0.01]) cylinder ( h = 0.7, r1 = 0.2, r2 = 0.14, center = false);
translate([0.13,0.5,0.7]) sphere ( r = 0.14);
translate([0.5,0.5,0.96]) rotate(-125,[0,1,0]) cylinder ( h = 0.4, r1 = 0.05, r2 = 0.12, center = false);
}
Loading

0 comments on commit 5407fc8

Please sign in to comment.