+ Reply to Thread
Results 1 to 3 of 3

Thread: How to get a plain shading of meshes?

  1. #1
    New Member
    Join Date
    Apr 2012
    Location
    Kamakura, Japan
    Posts
    12

    How to get a plain shading of meshes?

    Hi,

    I am experimenting with meshes using the following code:

    Code:
    import rhinoscriptsyntax as rs
    
    # size
    x, y, z = 10, 2, 4
    
    ##      7------6
    ##     /|     /|   
    ##    4-+----5 |
    ##    | |    | |
    ##    | 3----+-2
    ##    |/     |/    
    ##    0------1
    
    vertices = [
    
        # bottom rectangle
        (0, 0, 0), # 0
        (x, 0, 0), # 1
        (x, y, 0), # 2
        (0, y, 0), # 3
    
        # top rectangle
        (0, 0, z), # 4
        (x, 0, z), # 5
        (x, y, z), # 6
        (0, y, z)  # 7
    
        ]
    
    faces = [
    
        (0, 3, 2, 1), # bottom face
        (0, 1, 5, 4), # front face
        (1, 2, 6, 5), # right face
        (2, 3, 7, 6), # back face
        (3, 0, 4, 7), # left face
        (4, 5, 6, 7)  # top face
    
        ]
    
    meshObj = rs.AddMesh(vertices, faces)
    When looking at the generated mesh in the shaded or rendered view, the shading looks strange...

    I would like to have a plain shading without interpolation similar to the one used for meshes added with Rhino's AddMesh command or rhinoscriptsyntax.AddBox().

    Is there a way to set face normals, or to set the vertex normals per face, in order to get a plain shading? I only found a way to set one normal per vertex...

    Thanks, Dietrich

  2. #2
    Super Moderator Mitch's Avatar
    Join Date
    May 2010
    Location
    Switzerland
    Posts
    288
    Well, looks like when Rhino creates a mesh like that, that it automatically unwelds the edges, so you don't get the smoothing effect. You can do the same thing by running the Rhino command Unweld on your mesh with a value of 0 and ModifyNormals=Yes.

    I don't know if AddMesh can act like that, or if you need to use a RhinoCommon method to get an unwelded mesh.

    vbRhinoscript has the command UnweldMesh, but this hasn't been added to Python yet.

    I would have thought that adding: Rhino.Geometry.Mesh.Unweld(rs.coercemesh(meshObj), 0.0,True) would have worked, but it doesn't...

    You can always script the Rhino command:
    rs.SelectObject(meshObj)
    rs.Command("_Unweld 0 ModifyNormals=Yes _Enter",False)
    (but that's painful...)

    --Mitch

  3. #3
    New Member
    Join Date
    Apr 2012
    Location
    Kamakura, Japan
    Posts
    12
    Hi Mitch,

    You can always script the Rhino command:
    rs.SelectObject(meshObj)
    rs.Command("_Unweld 0 ModifyNormals=Yes _Enter",False)
    (but that's painful...)
    ...painful, but it works and is better than nothing! Thanks

    vbRhinoscript has the command UnweldMesh, but this hasn't been added to Python yet.

    I would have thought that adding: Rhino.Geometry.Mesh.Unweld(rs.coercemesh(meshObj), 0.0,True) would have worked, but it doesn't...
    Strange that it does not work. By the way and just out of curiosity, as it seems that some parts of Rhino are open projects, is it possible to read the sources of vbRhinoscript, Rhino.Python and RhinoCommon and to extend them with new functionality?

    Thanks, Dietrich

+ Reply to Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts