1.选中物体,进入权重绘制模式
2.代码:
import bpy # 获取当前活动的物体 obj = bpy.context.object # 确保物体是网格类型 if obj.type != 'MESH': print("当前激活的对象不是网格类型。") #exit() # 检查名为“water”的顶点组是否存在 vertex_group_name = "water" if vertex_group_name not in obj.vertex_groups: print(f"未找到名为 '{vertex_group_name}' 的顶点组。") #exit() # 获取名为“water”的顶点组 vg = obj.vertex_groups[vertex_group_name] # 获取顶点组的权重列表,并打印顶点索引和权重 weights = [] for v in obj.data.vertices: weight = vg.weight(v.index) weights.append(weight) print(f"Vertex {v.index} has weight {weight}") # 创建或更新顶点颜色属性 color_attr_name = "water_colors" if color_attr_name not in obj.data.attributes: color_attr = obj.data.attributes.new( name=color_attr_name, type='BYTE_COLOR', domain='POINT' ) else: color_attr = obj.data.attributes[color_attr_name] # 设置顶点颜色属性,映射权重到灰度颜色 for i, weight in enumerate(weights): # 将权重映射到颜色上,创建从白色到黑色的灰度渐变 color_value = int(weight * 255) # 权重映射到0-255的范围内 color_attr.data[i].color = (color_value, color_value, color_value, 255) # RGB相同,Alpha为255 print(f"顶点组 '{vertex_group_name}' 的权重已成功转换为顶点颜色属性 '{color_attr_name}'。") # 确保视图更新以显示顶点颜色 bpy.context.view_layer.update()
分类:
blender
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
2020-04-27 Vue中的发布与订阅