Jump to content
Ultimaker Community of 3D Printing Experts

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


odd08
 Share

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
     Share

    • Our picks

      • New here? Get ahead with a free onboarding course
        Hi,
         
        Often getting started is the most difficult part of any process. A good start sets you up for success and saves you time and energy that could be spent elsewhere. That is why we have a onboarding course ready for
        Ultimaker S5 Pro Bundle, Ultimaker S5, Ultimaker S3 Ultimaker 2+ Connect.   
        They're ready for you on the Ultimaker Academy platform. All you need to do to gain access is to register your product to gain free access. 
        Ready? Register your product here in just 60 seconds.
          • Like
        • 11 replies
    ×
    ×
    • Create New...