mvc架构
m —- 数据块 bpy.types.Property bpy.data
v —- 界面层 界面层 UI 面板(Panels):
c —– 控制层 控件 Operator
python版本与Cython
使用与Blender相同版本的Python
cython
pip instance cython
给要加密的文件增加装饰器
def log_class_methods(cls):
"""仅包装类方法的装饰器"""
for name, method in vars(cls).items():
if isinstance(method, classmethod):
original = method.__func__
def wrapper(*args, _name=name, _original=original, **kwargs):
print(f"调用类方法: {_name}")
return _original(*args, **kwargs)
setattr(cls, name, classmethod(wrapper))
return cls
@log_class_methods
class stCore():
@classmethod
def getTest(cls):
return 'test'
# 正确的调用方式
print(stCore.getTest()) # 通过类调用
print(stCore().getTest()) # 通过实例调用也可以
return cls
@log_class_methods
class stCore():
xxxx
setup.py
import sys
from setuptools import setup, Extension
from Cython.Build import cythonize
blender_python_libs = r"C:\Program Files\Blender Foundation\Blender 4.2\4.2\python\lib"
sys.path.append(blender_python_libs)
extensions = [
Extension(
"st_core", # 模块名
["st_core.py"], # Cython 源文件
library_dirs=[blender_python_libs], # 库路径
libraries=["python311"], # 链接的库(Python 版本可能不同)
define_macros=[("PYTHON_H", None)], # 可选:定义宏
)
]
setup(
name="st_core",
ext_modules=cythonize(extensions),
)
环境变量

编译
# cd到 python工程下
python setup.py build_ext --inplace