Jump to content
Ultimaker Community of 3D Printing Experts

SceneNode mesh created from scratch has no color/gray color


Recommended Posts

Posted (edited) · SceneNode mesh created from scratch has no color/gray color

Hello guys. Some time ago I made a little Python application to visualize the results of a FEM study, and now I'm integrating it into a Cura plugin. However, the resulting SceneNode's mesh looks completely gray/colorless:

 

cube.jpg.b1f6abb363be8c01d6bd0cb50b89bf2d.jpgcubecura.thumb.PNG.7636d2966b9a57f31ad980c5328e5763.PNG

 

The steps followed to prepare the mesh are:

1) Calculate the coordinates and color of every square. The algorithm is pretty much the same as in the old application so I didn't change much.

2) Create a SceneNode object. Make it a child of the Root SceneNode.

3) Use addQuad() to actually build the mesh by drawing each little square. More or less like this:

class ResultsNode(SceneNode):
  
  [...]
  
  def buildMesh(self, geometryData):

      self.mb = MeshBuilder()
      self.resultsMeshBuilder(geometryData)
      mesh = self.mb.build()
      self.setMeshData(mesh)

  def resultsMeshBuilder(self, geometryData):

      [...] #Code to find coordinates P1, P2, P3, P4 and color of each square

      color = Color(1.0, 0, 0, 1.0)	#For now, just paint all squares RED
      for face in ListOfFaces:
          self.mb.addQuad(face.P1, face.P2, face.P3, face.P4, color)

 

Geometrically, the mesh is built correctly (I've successfully tested other shapes). It's just the color that fails.

If the code above is not the culprit, I suspect it might be the View. Is there somewhere I can learn about views, rendering and shaders (something more in depth than the Uranium docs)? Thanks.

 

  

Edited by Tyronnosaurus
  • Link to post
    Share on other sites
    • Tyronnosaurus changed the title to SceneNode mesh created from scratch has no color/gray color
    Posted (edited) · SceneNode mesh created from scratch has no color/gray color

    Thanks, ahoeben. It works now with this change:

     

    def buildMesh(self, geometryData):
    
      self.mb = MeshBuilder()
      self.resultsMeshBuilder(geometryData)
      self.mb.calculateNormals()	#Added this line
      mesh = self.mb.build()
      self.setMeshData(mesh)
    
      

     

    femresult.thumb.PNG.8497dc7077ee240cddd0c701eb20101f.PNG

    Edited by Tyronnosaurus
    Added screenshot
    • Like 1
    Link to post
    Share on other sites
    Posted (edited) · SceneNode mesh created from scratch has no color/gray color

    One additional related question if you don't mind: how would you approach drawing the edges (black lines delimiting each square) like in my first screenshot?

    1) With addLine(): I've tried but for some reason the resulting mesh is not drawn correctly when combining addQuad & addLine.

    2) Option 1 but putting the lines in a child sceneNode's mesh

    3) Some shader or rendering option, if it exists

    4) Implementing a custom shader, akin to how the Platform is a single quad but draws a 1x1cm mesh

    5) Something else

     

     

    Edited by Tyronnosaurus
  • Link to post
    Share on other sites
    Posted · SceneNode mesh created from scratch has no color/gray color

    I think applying a custom shader is the best option. Adding lines might work too, but you will end up with LOTs of them for larger organic meshes. You could look at how grid.shader draws lines.

    • Like 1
    Link to post
    Share on other sites
    Posted (edited) · SceneNode mesh created from scratch has no color/gray color

    [Hey ahoeben, I was just writing a solution I've found, which uses addLine(). Since I've got it almost written I'll just leave it here for anyone curious, but I'll try using a shader as you say]

     

    I've discovered that I can simply create a second mesh inside a single SceneNode, and then render each mesh separately. I discovered this by looking into Cura's BuildVolume class. More or less my code is this:

     

    1) Create a _grid_mesh and build the wireframe with AddLine()

    2) Override the SceneNode.render() method:

        def render(self, renderer):
    
            if (self.isVisible()):
                #To draw the colored faces -> The most simple rendering
                renderer.queueNode(self)    
    
                #To draw the edges -> A Lines AKA wireframe rendering
                renderer.queueNode(self, mesh=self._grid_mesh,
                                         mode=RenderBatch.RenderMode.Lines) 
            
            return True

    3) Make sure the active view runs this render()

     

    I still can't control the lines' color though (always white).

    meshWireframe.PNG.2024bf443782789d1635b8e35ab1c9f3.PNG

    Edited by Tyronnosaurus
  • 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

      • Startups, apply for the Forward AM Innovation Award!
        Are you a startup using 3D printing? Perhaps you should continue reading... 
         
        Together with BASF we are launching the Forward AM Innovation Award - the very first global contest for startups developing new applications with 3D printing!
         
        Why apply?
        The winning startup will receive €100,000 in goods and services*, along with coaching and marketing exposure from top-notch leaders in the industry.
         

         
        Who can apply?
        Your startup creates products using Additive Manufacturing, is less than 5 years old, and has less than 50 employees. We are looking for 3D printing applications with a strong focus on innovation, sustainability and scalability.
         
        Dental aligners, shoes, tools, automotive parts, music instruments, industrial tooling and molding, medical implants, sports equipment, toys, architecture, fashion, construction... all are welcome to join!
         
        Do you have an innovative, sustainable and scalable idea that leverages the unique possibilities of 3D printing? Then it is time to apply!
        More information can be found here.
         
        Applications close on March 28th, 2021
        * What does "in goods and services" mean?
        The winner will be able to pick any item from the overall product and service portfolio of the sponsors, e.g. printers, materials, consulting, software... Choose whatever you need to accelerate your startup.
         
          • Like
        • 0 replies
      • New here? Register your Ultimaker for free 3D printer 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
        • 0 replies
    ×
    ×
    • Create New...