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
    ×
    ×
    • Create New...