Jump to content

SceneNode mesh created from scratch has no color/gray color


Tyronnosaurus

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

      • UltiMaker Cura 5.7 stable released
        Cura 5.7 is here and it brings a handy new workflow improvement when using Thingiverse and Cura together, as well as additional capabilities for Method series printers, and a powerful way of sharing print settings using new printer-agnostic project files! Read on to find out about all of these improvements and more. 
         
          • Like
        • 18 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...