【问题标题】:Blender bevel selected edge of a default cube with PythonBlender斜面选择了默认立方体的边缘与Python
【发布时间】:2022-08-24 03:45:04
【问题描述】:

我想在 Blender 3.0 中使用 Python 对默认立方体的单边进行斜切。我需要选择边的两个顶点来选择边并对其进行斜切。事实证明这是相当困难的。

import bpy
import bmesh

obj = bpy.context.active_object  # Get selected object

epsilon = 1e-5  # Threshold to account for floating point precision

if obj:
    bpy.ops.object.mode_set(mode=\'EDIT\')  # Go into edit mode
    bpy.ops.mesh.select_mode(type=\"EDGE\")  # Switch to edge select mode

   
    bm = bmesh.from_edit_mesh(obj.data)  # Create bmesh object for easy mesh evaluation
    obj = bpy.context.active_object
    obj.data.polygons[2].select = True
    for e in bm.edges:  # Check all edges
    
        if e.index  == 0:
            print (\"abc\")
            first_pos = e.verts[0].co  # Get first vert position of this edge
            other_pos = e.verts[1].co  # Get second vert position of this edge

            e.select_set(abs(first_pos.x - other_pos.x) <= epsilon and abs(first_pos.y - other_pos.y) <= epsilon)
        
    bmesh.update_edit_mesh(obj.data)  # Update the mesh in edit mode
    bpy.ops.object.modifier_set_active(modifier=\"Bevel\")
    bpy.ops.object.modifier_add(type=\'BEVEL\')

    bpy.context.object.modifiers[\"Bevel\"].segments = 10
    bpy.context.object.modifiers[\"Bevel\"].width = 0.37

我可以选择整个立方体和所有边缘,但不能选择特定边缘。

    标签: python default blender cube modifier


    【解决方案1】:

    我认为您想选择一个边缘进行斜切,其余的保持不变。

    您可以通过在斜角修改器中选择“重量”限制方法来做到这一点。在这种方法中, 网格中的每个边缘都有一个“斜角权重”,用于乘以该边缘上的斜角大小。因此,如果边上的斜角权重为 0 - 该边上没有斜角;如果斜角重量为 1,那么您将得到一个完整的斜角。

    斜角权重通常在新网格的所有边上设置为 0。它可以改变 (在编辑模式下)通过选择要斜切的边缘,然后

     “Edge” menu -  “ Edge_Bevel_Weights” :     1
    

    这会将要斜切的边缘(或边缘)上的权重设置为 1。

    在 Python 中,应通过如下更改代码来修改脚本

     # To use this script:
     #    1)  Open Blender new file   (default cube is already loaded and selected)
     #    2)  go to "Scripting" windows arrangement
     #    3)  load this script
     #    4)  Edit mode - select "Vertex" mode
     #    5)  Deselect all vertices  <Alt>A
     #    6)  Select vertices at both ends of edge to be bevelled
     #    7)  Run script
    
    import bpy
    bpy.ops.mesh.select_mode(type="EDGE")  # Switch to edge select mode 
    
    bpy.ops.object.modifier_add(type='BEVEL')    # add a new bevel modifier 
    bpy.context.object.modifiers["Bevel"].limit_method = 'WEIGHT'     # change its limit method to "weight"
    bpy.context.object.modifiers["Bevel"].offset_type = 'WIDTH'
        
    bpy.context.object.modifiers["Bevel"].segments = 10
    bpy.context.object.modifiers["Bevel"].width = 0.37
     
    bpy.ops.transform.edge_bevelweight(value=1)
    

    最后,我发现以下关于 Blender Bevels 的文章非常有用:
    “如何在 Blender 中解决斜角问题”(Erik Selin): https://artisticrender.com/how-to-solve-bevel-problems-in-blender/#:~:text=The%20most%20common%20issue%20when,the%20tools%20or%20bad%20geometry

    【讨论】:

    • 致 Suraj Rao:非常感谢您整理我的贡献 - 现在正如我所愿!谢谢你。
    • 非常感谢你们。迫不及待想试试。只是现在不能,但我会尝试加权
    • 那么如何在脚本中选择边缘呢?倒角。我可以在 GUI 中选择,边缘是白色的。但是,当您在脚本中选择一条边时,它会变为橙色。那是选择和激活之间的区别吗?什么是取消选择?谢谢
    • # 之前的代码应该取消选择所有不被斜切的边缘,选择那些确实想要斜切的边缘,但是如何?
    • 我已经编辑了我对什么(我希望)给出了我现在认为是你的问题的更完整的答案的原始答案。另外:您对选定(橙色)和活动(白色)边缘的理解是正确的。取消选择边缘意味着使边缘“未选择”。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-03
    • 2017-11-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多