1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How to work with Bmesh correctly?

Discussion in 'Technology' started by cronk, Oct 8, 2018.

  1. cronk

    cronk Guest

    I'm writing a window generator script.

    Here is a current version of my script: https://gist.github.com/romanvolodin/3bfd349795443118a2298819349a0b3c

    Windows config: https://gist.github.com/romanvolodin/60055b1593a3c4c6d52e017cfd9696be

    Script's algorithm looks like this (in short):

    • Read json config
    • Build a wall object
    • Build window's inner part
    • Get vertex normals on the edge of a window
    • For every window build window's decoration

    In my scene I have a mesh object ('profile') which is define the decor profile. [​IMG]

    To build a window decor, I copy given profile several times to window vertex position and orient it in vertex normal direction.

    [​IMG]

    And then I bridge them together. Kind of 'profile along path'.

    I have a super weird bug - the most of the time I get distorted geometry. Something corrupt my normal's data. But sometimes the script works correctly (at 0:07, 1:06, 1:28, 1:37, 1:45, 2:12): https://www.youtube.com/watch?v=I6wysGzIQfU

    Also, only 4 windows at the beginning are distorted, 5th and next look just nice. (These crumpled objects at the origin are four first windows.)

    [​IMG]

    [​IMG]

    [​IMG]

    Here is more.

    In my script I print normal's positions. Then I add a new Bmesh object. And then I print normal's positions again.

    # ...
    windows_edge_normals = get_windows_edge_normals(windows_vertex_positions)

    for i, window_normals in enumerate(windows_edge_normals, start=1):
    print("before", i)
    for num, normal in enumerate(window_normals):
    vert_co, vert_normal = normal
    print(
    " co: {}\n"
    "normal {}".format(vert_co, vert_normal)
    )

    for i, window_normals in enumerate(windows_edge_normals, start=1):
    print("after", i)
    bm = bmesh.new()
    last_profile = None
    for num, normal in enumerate(window_normals):
    vert_co, vert_normal = normal
    print(
    " co: {}\n"
    "normal {}".format(vert_co, vert_normal)
    )
    # ...


    And the result is completely different! (Note: 'before' is green and on the right, 'after' red on the left, see link) https://www.diffchecker.com/9YEV3moY

    Why?! I've just added a new Bmesh!

    So the question is - what I'm doing wrong? Should I delete previous bmeshes explicitly (the wall and inner parts)? Or it's a bug in Blender? Any help will be appreciated.

    Login To add answer/comment
     

Share This Page