Jump to content

[Plugin] Scaling cube from point down to Z=0


SmithsOfUrth

Recommended Posts

Posted · [Plugin] Scaling cube from point down to Z=0

Hey guys!

 

I'm working on a plugin (for Cura 3.6+) to enable manual supports, and one of the features I want to add is to show some kind of "preview" of what area the support is going to be taking.

Right now, I'm creating a cube and adding it to a X,Y position using this code:
 

active_camera = self._controller.getScene().getActiveCamera()
picking_pass = PickingPass(active_camera.getViewportWidth(), active_camera.getViewportHeight())
picking_pass.render()

picked_position = picking_pass.getPickedPosition(event.x, event.y)

After that, the script creates a cube kinda manually (I'm basing myself on the SupportEraser plugin) with a value entered by the user. Thus, the cube has the same width, height and depth.
What I want to do is to make it as big in the Z axis as necessary so that it touches the build plate , and the user can see what it'd look like once it's processed.

Is there a way to scale it enough?

 

Thanks!

  • Link to post
    Share on other sites

    Posted · [Plugin] Scaling cube from point down to Z=0

    There are two things you can do; You can either create longer squares with the MeshBuilder and move them down a bit (since they are places based on their center) or you can scale the model (check the setScale function of the SceneNode that contains the meshdata)

  • Link to post
    Share on other sites

    Posted · [Plugin] Scaling cube from point down to Z=0

    Thanks for answering, nallath.

    I ended up doing this to create a cube that touches the buildplate:

    s = size / 2
    dtb = distance_to_buildplate
    verts = [ # 6 faces with 4 corners each
      [-s, -dtb,  s], [-s,  s,  s], [ s,  s,  s], [ s, -dtb,  s], # a = x-yz
      [-s,  s, -s], [-s, -dtb, -s], [ s, -dtb, -s], [ s,  s, -s], # b = x+yz
      [ s, -dtb, -s], [-s, -dtb, -s], [-s, -dtb,  s], [ s, -dtb,  s], # c = xy-z
      [-s,  s, -s], [ s,  s, -s], [ s,  s,  s], [-s,  s,  s], # d = xy+z 
      [-s, -dtb,  s], [-s, -dtb, -s], [-s,  s, -s], [-s,  s,  s], # e = +xyz
      [ s, -dtb, -s], [ s, -dtb,  s], [ s,  s,  s], [ s,  s, -s] # f = -xyz
    ]

    where "distance_to_buildplate" is the position in the Y axis of the cube when you click on the model, which is the same thing as the distance from the cube the ground.

  • 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
    • Our picks

      • Introducing Universal Cura Projects in the UltiMaker Cura 5.7 beta
        Strap in for the first Cura release of 2024! This 5.7 beta release brings new material profiles as well as cloud printing for Method series printers, and introduces a powerful new way of sharing print settings using printer-agnostic project files! Also, if you want to download the cute dinosaur card holder featured below, it was specially designed for this release and can be found on Thingiverse! 
          • Like
        • 10 replies
      • S-Line Firmware 8.3.0 was released Nov. 20th on the "Latest" firmware branch.
        (Sorry, was out of office when this released)

        This update is for...
        All UltiMaker S series  
        New features
         
        Temperature status. During print preparation, the temperatures of the print cores and build plate will be shown on the display. This gives a better indication of the progress and remaining wait time. Save log files in paused state. It is now possible to save the printer's log files to USB if the currently active print job is paused. Previously, the Dump logs to USB option was only enabled if the printer was in idle state. Confirm print removal via Digital Factory. If the printer is connected to the Digital Factory, it is now possible to confirm the removal of a previous print job via the Digital Factory interface. This is useful in situations where the build plate is clear, but the operator forgot to select Confirm removal on the printer’s display. Visit this page for more information about this feature.
          • Like
        • 0 replies
    ×
    ×
    • Create New...