Jump to content

Support for rendering color gradients on mesh and/or slice preview


odd08

Recommended Posts

Posted · Support for rendering color gradients on mesh and/or slice preview

I noticed that Cura supports different colors for mesh and slice views, but I don't see any instance of rendering with color gradient. This is typically achieved by specifying color (or some value) at the vertices and the render interpolates the color inside the triangle (in mesh view) or the gcode line (in the slice view). Is anyone aware that Cura supports this or if it's in the cards. Thanks!

  • Link to post
    Share on other sites

    • 2 months later...
    Posted (edited) · Support for rendering color gradients on mesh and/or slice preview

    Hey, late reply but good news. What you want to do is exactly how Cura works behind the scenes. When adding a triangle (or quad, or line...), Cura uses setVertexColor() on each of its 3 vertices, but uses the same color so there's no gradient.

     

    What you can do is first create your mesh with your primitives, and afterwards go vertex by vertex changing the color.

     

    For example, I tested it on this cube I built for a project of mine. It's made up of 10x10x10 quads. Mind you, quads are actually just a pair of triangles:

    femCube.thumb.png.c318ab053d97ab07d8466ea2a33f4525.png

     

    Then I used this code to randomize the color of every vertex:

    def PrepareMeshBuilder(self):
        ...
        [Here goes code to add primitives (tris, quads...), calculate normals, etc.]
        ...
        
        import random
        for vIndex,_ in enumerate(self.mb.getVertices()):
            r = random.randint(0, 255)
            g = random.randint(0, 255)
            b = random.randint(0, 255)
            self.mb.setVertexColor(vIndex, Color(r, g, b, 255))

     

    And got this:

    gradientTriangles.thumb.PNG.d0ae019080c51f90c1ff4a3720971200.PNG

     

    Edit:

    If I were you, I would override or create a custom addFace() method that took 3 colors instead of 1 and applied them directly. This way you could create your triangles and paint them at the same time.

     

    Edited by Tyronnosaurus
    • Like 1
    Link to post
    Share on other sites

    • 3 months later...

    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

      • UltiMaker Cura 5.8 Stable released 🎉
        In the Cura 5.8 stable release, everyone can now tune their Z seams to look better than ever. Method series users get access to new material profiles, and the base Method model now has a printer profile, meaning the whole Method series is now supported in Cura!
        • 5 replies
      • Introducing the UltiMaker Factor 4
        We are happy to announce the next evolution in the UltiMaker 3D printer lineup: the UltiMaker Factor 4 industrial-grade 3D printer, designed to take manufacturing to new levels of efficiency and reliability. Factor 4 is an end-to-end 3D printing solution for light industrial applications
          • Thanks
          • Like
        • 3 replies
    ×
    ×
    • Create New...