您的位置:首页 > 财经 > 金融 > 女子医院网站优化公司_怎么开外贸网店_google本地搜索_长春网站seo

女子医院网站优化公司_怎么开外贸网店_google本地搜索_长春网站seo

2025/3/19 4:29:13 来源:https://blog.csdn.net/2301_77717148/article/details/146281657  浏览:    关键词:女子医院网站优化公司_怎么开外贸网店_google本地搜索_长春网站seo
女子医院网站优化公司_怎么开外贸网店_google本地搜索_长春网站seo

Blender-MCP服务源码4-初始化项目解读

上篇文章针对Blender开发框架完成了一个基础模板的搭建,并在Blender中成功进行了运行,那这个初始化项目中是如何进行页面效果呈现的,尝试手动进行功能精简来拆解项目代码


1-核心知识点

  • 1)如何绘制Blender的插件UI->如何编写自己的UI界面
  • 2)了解如何快速使用Blender的开发框架->知道在哪里添加自己的核心业务

2-思路整理

  • 1)Blender开发框架-如何快速的搭建项目
    • 1)main.py修改项目配置
    • 2)create.py创建项目
    • 3)test.py进行blender调试
  • 2)只需要在AddonPanels.py修改业务逻辑即可
    • 1)因为当前项目依赖test.py进行调试->框架中使用了国际化不能随便移除
    • 2)尝试了多次,如果是尝试核心业务就不要删除代码的逻辑和目录结构
    • 3)代码的调试和发布都是编排好的脚本->不要乱动

3-参考网址

  • Blender-MCP-Github地址:https://github.com/ahujasid/blender-mcp
  • B站大佬开源Blender开发框架:https://github.com/xzhuah/BlenderAddonPackageTool
  • B站大佬开源Blender开发框架教程

4-上手实操

1-定位代码
  • 右侧:示例插件
  • 左侧:示例功能
  • 文字定位

定义在一个字典中,针对左右的英文再进行代码定位

  • 代码定位

貌似核心的代码都在这个文件中[AddonPanels.py](Blender-MCP在进行插件安装时候-也只有一个blender插件addon.py)-> 貌似我们已经快要接触到代码的本质了

import bpyfrom ..config import __addon_name__  # 导入插件名称常量
from ..operators.AddonOperators import ExampleOperator  # 导入自定义操作符类
from ....common.i18n.i18n import i18n  # 导入国际化函数
from ....common.types.framework import reg_order  # 导入注册顺序装饰器# 基础面板类
class BasePanel(object):bl_space_type = "VIEW_3D"  # 面板所在的空间类型为 3D 视图bl_region_type = "UI"  # 面板所在的区域类型为 UI 区域bl_category = "ExampleAddon"  # 面板的分类名称@classmethoddef poll(cls, context: bpy.types.Context):return True  # 始终显示面板# 使用注册顺序装饰器,值为 0,优先级较高
@reg_order(0)
class ExampleAddonPanel(BasePanel, bpy.types.Panel):bl_label = "Example Addon Side Bar Panel"  # 面板标签名称bl_idname = "SCENE_PT_sample"  # 面板的唯一标识符def draw(self, context: bpy.types.Context):addon_prefs = context.preferences.addons[__addon_name__].preferences  # 获取插件偏好设置layout = self.layout  # 获取布局对象# 显示国际化文本和偏好设置中的数字layout.label(text=i18n("Example Functions") + ": " + str(addon_prefs.number))# 显示并允许编辑文件路径属性layout.prop(addon_prefs, "filepath")layout.separator()  # 添加分隔线row = layout.row()  # 创建一行布局# 在同一行显示并允许编辑数字和布尔属性row.prop(addon_prefs, "number")row.prop(addon_prefs, "boolean")# 添加操作符按钮layout.operator(ExampleOperator.bl_idname)@classmethoddef poll(cls, context: bpy.types.Context):return True  # 始终显示面板# 这个面板将在 ExampleAddonPanel 之后绘制,因为其注册顺序值更高
@reg_order(1)
class ExampleAddonPanel2(BasePanel, bpy.types.Panel):bl_label = "Example Addon Side Bar Panel"  # 面板标签名称bl_idname = "SCENE_PT_sample2"  # 面板的唯一标识符def draw(self, context: bpy.types.Context):layout = self.layout  # 获取布局对象layout.label(text="Second Panel")  # 显示标签文本layout.operator(ExampleOperator.bl_idname)  # 添加操作符按钮

2-待完善

通过对上面代码的阅读,去除代码中高阶的国际化等功能,我们只保留一个【按钮】点击之后将窗口的物体放大2倍!

后续会尝试在Blender中部署一个socket和MCP本地的服务器进行通讯

  • 1)文字定义,否则页面展示不出来
  • 2)定义的操作

比如页面上要定义的点击事件,示例:点击按钮让图形缩小0.8倍(3步骤)

  • 1)先定义Operator->直接拷贝示例后修改
  • 2)再配置你的Operator->在国际化配置中配置
  • 3)更换你自己的事件
import bpyfrom ..config import __addon_name__
from ..preference.AddonPreferences import ExampleAddonPreferences# 自己定义的Operator
class BlenderMCPServer(bpy.types.Operator):'''ExampleAddon'''bl_idname = "object.blender_mcp_server"bl_label = "BlenderMCPServer"# 确保在操作之前备份数据,用户撤销操作时可以恢复bl_options = {'REGISTER', 'UNDO'}@classmethoddef poll(cls, context: bpy.types.Context):return context.active_object is not Nonedef execute(self, context: bpy.types.Context):addon_prefs = bpy.context.preferences.addons[__addon_name__].preferencesassert isinstance(addon_prefs, ExampleAddonPreferences)# manipulate the scale directlycontext.active_object.scale *= 0.8return {'FINISHED'}



版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com