带Python的默认立方体的搅拌器斜角选定的边缘

发布于 2025-01-23 13:31:25 字数 1425 浏览 0 评论 0原文

我想在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

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

I'd like to bevel a single edge of a default cube with Python in Blender 3.0. I need to select two vertices of an edge to select the edge and bevel it. This is proving quite difficult.

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

enter image description here

I can select the whole cube and all the edges but not a specific edge.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

过度放纵 2025-01-30 13:31:25

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

您可以通过在斜角修饰符中选择“重量”极限方法来做到这一点。在这种方法中,
网格中的每个边缘都有一个“斜角重量”,用于将斜角在该边缘的大小倍增。因此,如果边缘上的斜角重量为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)


“如何解决搅拌机中的斜面问题”(Erik Selin):
https://artistisrender.com/how-to-solve-bevel-bevel-problems-in-blender/#:~: text = the%20mast%20common%20common%20issue%20When, %20工具%20or%20BAD%20分

I think you want to select one edge to bevel and leave the rest unchanged.

You can do this by selecting the “Weight” limit method in the bevel modifier. In this method,
each edge in your mesh has a “Bevel Weight” which is used to multiply the size of your bevel on that edge. So if the Bevel Weight on an edge is 0 – no bevel on that edge; if Bevel Weight is 1, then you get a full bevel.

The Bevel Weight is normally set to 0 on all edges in a new mesh. It can be changed
(in Edit mode) by selecting the edges you want to bevel, then

 “Edge” menu -  “ Edge_Bevel_Weights” :     1

This sets the weight to 1 on the edge (or edges) you want to bevel.

In Python, your script should be modified by changing your code as follows

 # 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)

enter image description here

Finally, I found the following article on Blender Bevels to be very useful:
“How to solve bevel problems in Blender” (Erik Selin):
https://artisticrender.com/how-to-solve-bevel-problems-in-blender/#:~:text=The%20most%20common%20issue%20when,the%20tools%20or%20bad%20geometry.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文