Jump to content
Ultimaker Community of 3D Printing Experts

Cura Plugin - getPickedPosition


Recommended Posts

Posted · Cura Plugin - getPickedPosition

Hello,

 

Still working on my plugins, I'm wondering if it's possible to get the normal orientation on a picked position ?

 

Best regards,

 

Cuq 

  • Link to post
    Share on other sites
    Posted · Cura Plugin - getPickedPosition

    Yeah, that should be possible. It's not entirely there already, but you can have a look at the lay flat in the rotation tool. That allows you to pick faces already.

    • Thanks 1
    Link to post
    Share on other sites
    Posted · Cura Plugin - getPickedPosition

    Ok I will investigate this code ...

     

        def _onSelectedFaceChanged(self):
            if not self._select_face_mode:
                return
    
            self._handle.setEnabled(not Selection.getFaceSelectMode())
    
            selected_face = Selection.getSelectedFace()
            if not Selection.getSelectedFace() or not (Selection.hasSelection() and Selection.getFaceSelectMode()):
                return
    
            original_node, face_id = selected_face
            meshdata = original_node.getMeshDataTransformed()
            if not meshdata or face_id < 0:
                return
            if face_id > (meshdata.getVertexCount() / 3 if not meshdata.hasIndices() else meshdata.getFaceCount()):
                return
    
            face_mid, face_normal = meshdata.getFacePlane(face_id)
            object_mid = original_node.getBoundingBox().center
            rotation_point_vector = Vector(object_mid.x, object_mid.y, face_mid[2])
            face_normal_vector = Vector(face_normal[0], face_normal[1], face_normal[2])
            rotation_quaternion = Quaternion.rotationTo(face_normal_vector.normalized(), Vector(0.0, -1.0, 0.0))
    
            operation = GroupedOperation()
            current_node = None  # type: Optional[SceneNode]
            for node in Selection.getAllSelectedObjects():
                current_node = node
                parent_node = current_node.getParent()
                while parent_node and parent_node.callDecoration("isGroup"):
                    current_node = parent_node
                    parent_node = current_node.getParent()
            if current_node is None:
                return
    
            rotate_operation = RotateOperation(current_node, rotation_quaternion, rotation_point_vector)
            operation.addOperation(rotate_operation)
            operation.push()

     

    • Like 1
    Link to post
    Share on other sites
    Posted · Cura Plugin - getPickedPosition

    I'm still avaing some problem to implement this code .  I can get the facette center point and the normal with 

     

    face_mid, face_normal = meshdata.getFacePlane(face_id)

     

    But I'm still fighting with the possibility to have in the same time the subroutine _onSelectedFaceChanged and def event(self, event)  . An idea or a suggestion to move forward on this point ?

     

  • Link to post
    Share on other sites

    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now
    ×
    ×
    • Create New...