This commit is contained in:
2025-08-02 12:09:34 +08:00
commit e70b01cdca
2785 changed files with 575579 additions and 0 deletions

View File

@@ -0,0 +1,156 @@
# 使用Pyside6以及非基础模块
安装Pyside6
```
pip install PySide6
```
默认情况下需要添加路径才能调用下载的库,执行以下代码即可:
```python
import sys
import pathlib
my_python_path = "C:\Python311\Lib\site-packages"
sys.path.insert(0, my_python_path)
```
## 其他模块
对于一些非基础模块比如PySide6.QtWebSockets需要执行以下命令进行安装
```bash
pip install PySide6-Addons
```
# WebSocketServer for Blender
https://github.com/KoltesDigital/websocket-server-for-blender
## Pyside6实现
TODO:添加多线程,防止退出。
```python
server = QWebSocketServer()
thread = QtCore.QThread()
server.moveTOThread(thread)
server.finished.connect(thread.quit)
thread.started.connect(model.func_to_run)
thread.finished.connect(fun_to_run_after_thread_finished)
thread.start()
thread.start()
```
```python
# blender --background test.blend --python mytest.py -- example args 123
import sys
import pathlib
# import pyside6
my_python_path = "C:\Python311\Lib\site-packages"
sys.path.insert(0, my_python_path)
import bpy
from PySide6.QtNetwork import QHostAddress
from PySide6.QtWebSockets import QWebSocket
from PySide6.QtWebSockets import QWebSocketServer
class QRetargetWebsocketServer(QWebSocketServer):
def __init__(self):
super(QRetargetWebsocketServer, self).__init__("RetargetWebsocketServer", QWebSocketServer.NonSecureMode)
self.closed.connect(self.onClosed)
self.newConnection.connect(self.onNewConnection)
def onClosed():
print('connect closed!')
def onNewConnection(self, context, event):
client: QWebSocket = self.nextPendingConnection()
client.textMessageReceived.connect(self.onTextReceived)
def onTextReceived(self, text: str):
client: QWebSocket = self.sender()
if text == "Retarget":
print("Retarget")
client.sendTextMessage("Retarget")
else:
print("text:", text)
# 提取输出的命
argv = sys.argv
print(argv)
# argv = argv[argv.index("--") + 1:] # get all args after "--"
# print(argv) # --> ['example', 'args', '123']
WebSocketServer = QRetargetWebsocketServer()
WebSocketServer.listen(QHostAddress.LocalHost,9091)
```
# Http Server
```python
bl_info = {
"name": "My Awesome Server",
"blender": (2, 80, 0),
"category": "Object",
}
from http.server import BaseHTTPRequestHandler, HTTPServer
import threading
import bpy
class MyServer(BaseHTTPRequestHandler):
def do_GET(self):
if self.path == '/test':
self.send_response(200)
self.send_header('Content-type','text/html')
self.end_headers()
message = "This is a test page2."
self.wfile.write(bytes(message, "utf8"))
else:
self.send_response(404)
self.send_header('Content-type','text/html')
self.end_headers()
message = "404 Not Found."
self.wfile.write(bytes(message, "utf8"))
return
httpd = None
thread = None
thread2 = None
def start_server():
global httpd
server_address = ('localhost', 8080)
# Server is not running, start it
httpd = HTTPServer(server_address, MyServer)
print("Server started")
httpd.serve_forever()
def stop_server():
global httpd
global thread
httpd.shutdown()
thread.join()
print("Server stopped")
def stop_server_thread():
global thread2
thread2 = threading.Thread(target=stop_server)
thread2.start()
def register():
global thread
print("Hello World")
# Start the server on a new thread
thread = threading.Thread(target=start_server)
thread.daemon = True
thread.start()
def unregister():
print("Goodbye World")
stop_server_thread()
global thread2
thread2.join()
```
# Blender CMD 启用插件
>./blender -b --addons animation_nodes,meshlint [file] --python [myscript.py]
这样就可以指定启用某某插件

View File

@@ -0,0 +1,43 @@
```python
import bpy
#import os
import sys
argv = sys.argv
argv = argv[argv.index("--") + 1:] # get all args after "--"
# print(argv) # --> ['example', 'args', '123']
SourceFBXPath = argv[0]
ExportFBXPath = argv[1]
RemoveWeightBoneNames = argv[2]
RemoveWeightBoneNameList = RemoveWeightBoneNames.split(',')
#RemoveWeightBoneNameList = ['calf_twist_01_l','calf_twist_01_r','calf_twist_02_l','calf_twist_02_r','lowerarm_twist_01_l','lowerarm_twist_01_r']
bpy.ops.scene.new(type='EMPTY')
bpy.ops.object.select_all(action='SELECT')
bpy.ops.object.delete()
bpy.ops.import_scene.fbx(filepath=SourceFBXPath)
for obj in bpy.data.objects:
if obj.type == 'MESH':
for BoneName in RemoveWeightBoneNameList:
vg = obj.vertex_groups.get(BoneName)
if vg is not None:
obj.vertex_groups.remove(vg)
bpy.ops.export_scene.fbx(filepath=ExportFBXPath,add_leaf_bones=False)
# ob = bpy.context.object
# if ob.type == 'ARMATURE':
# armature = ob.data
# bpy.ops.object.mode_set(mode='EDIT')
# for bone in armature.bones:
# if fnmatch.fnmatchcase(bone.name, "something"):
# armature.delete(bone)
# for bone in armature.edit_bones:
# if fnmatch.fnmatchcase(bone.name, "something"):
# armature.edit_bones.remove(bone)
```

View File

@@ -0,0 +1,100 @@
# 插件
- Blender Animation Retargeting:https://github.com/Mwni/blender-animation-retargeting
- Rokoko Plugin:https://support.rokoko.com/hc/en-us/articles/12644862322321-Release-Notes-Blender-Plugin-1-4-1
- https://www.youtube.com/watch?v=HitTDDCfhJg&t=1s
- https://www.bilibili.com/video/BV1ex4y1g7DX/?spm_id_from=333.337.search-card.all.click&vd_source=d47c0bb42f9c72fd7d74562185cee290
- (收费)Blender Retargeting Tools 1.2:https://blendermarket.com/products/blender-retargeting-tools-1
# 调用
使用Rokoko与BetterFbx插件。这里因为需要规避Rokoko插件名带有“-”的问题所以还需要安装Importlib库
```python
import bpy
import os
import sys
import importlib
rokoko = importlib.import_module("rokoko-studio-live-blender-master")
from better_fbx import *
# 启动命令参数
'''
# blender --background test.blend --python mytest.py -- example args 123
cd /d D:/Program Files/Blender Foundation/Blender 3.3/
blender.exe --python C:/Users/BlueRose/Desktop/Retareting/Blender_AnimationRetarget.py -- C:/Users/BlueRose/Desktop/Retareting/Animations/MF_Run_Fwd.fbx C:/Users/BlueRose/Desktop/Retareting/Characters/SKM_Quinn.fbx C:/Users/BlueRose/Desktop/Retareting/Animations/ExportAnimation.fbx 0
# Blender后台启动并且执行Python
blender.exe --python C:/Users/BlueRose/Desktop/Retareting/Blender_AnimationRetarget.py --background --python-text -- C:/Users/BlueRose/Desktop/Retareting/Animations/MF_Run_Fwd.fbx C:/Users/BlueRose/Desktop/Retareting/Characters/SKM_Quinn.fbx C:/Users/BlueRose/Desktop/Retareting/Animations/ExportAnimation.fbx 0
# Python CMD 交互方式
blender.exe --python-console --background -- C:/Users/BlueRose/Desktop/Retareting/Animations/MF_Run_Fwd.fbx C:/Users/BlueRose/Desktop/Retareting/Characters/SKM_Quinn.fbx C:/Users/BlueRose/Desktop/Retareting/Animations/ExportAnimation.fbx 0
'''
# 读取输入路径
argv = sys.argv
argv = argv[argv.index("--") + 1:] # get all args after "--"
print(argv) # --> ['example', 'args', '123']
SourceAnimation = argv[0]
TargetSkeletalMesh = argv[1]
ExportAnimtion = argv[2]
bExportPreviewMesh = bool(int(argv[3]))
# SourceAnimation = "C:/Users/BlueRose/Desktop/Retareting/Animations/MM_Run_Fwd.fbx"
# TargetSkeletalMesh = "C:/Users/BlueRose/Desktop/Retareting/Characters/SKM_Quinn.fbx"
# ExportAnimtion = "C:/Users/BlueRose/Desktop/Retareting/Animations/ExportAnimation.fbx"
# bExportPreviewMesh = bool(int("0"))
# 清空场景
# bpy.ops.wm.read_factory_settings(use_empty=True)
bpy.ops.scene.new(type='EMPTY')
# for block in bpy.data.meshes:
# if block.users == 0:
# bpy.data.meshes.remove(block)
# for block in bpy.data.materials:
# if block.users == 0:
# bpy.data.materials.remove(block)
# for block in bpy.data.textures:
# if block.users == 0:
# bpy.data.textures.remove(block)
# for block in bpy.data.images:
# if block.users == 0:
# bpy.data.images.remove(block)
# 导入相关资产
bpy.ops.better_import.fbx(filepath=TargetSkeletalMesh,use_auto_bone_orientation=False,use_reset_mesh_origin=False,use_animation=False,use_detect_deform_bone=False,use_import_materials=False)
#bpy.ops.import_scene.fbx(filepath=TargetSkeletalMesh,use_anim=False)
TargetSeletctObjects = bpy.context.selected_objects
bpy.ops.object.select_all(action='DESELECT')
bpy.ops.better_import.fbx(filepath=SourceAnimation,use_auto_bone_orientation=False,use_reset_mesh_origin=False,use_animation=True,use_detect_deform_bone=False,use_import_materials=False)
#bpy.ops.import_scene.fbx(filepath=SourceAnimation,use_anim=True)
SourceSeletctObjects = bpy.context.selected_objects
# 使用插件重定向
for Object in SourceSeletctObjects:
if Object.type == "ARMATURE":
bpy.context.scene.rsl_retargeting_armature_source=Object
for Object in TargetSeletctObjects:
if Object.type == "ARMATURE":
bpy.context.scene.rsl_retargeting_armature_target=Object
# 构建Bone映射表 & 填充缺少的BoneName(假设使用相同的骨骼结构) & 移除root的映射
bpy.ops.rsl.build_bone_list()
for BoneItem in bpy.context.scene.rsl_retargeting_bone_list:
if BoneItem.bone_name_target == "":
BoneItem.bone_name_target = BoneItem.bone_name_source
continue
if BoneItem.bone_name_target == "root":
BoneItem.bone_name_target = ""
# 动画重定向
bpy.ops.rsl.retarget_animation()
# 输出
bpy.ops.object.select_all(action='DESELECT')
for Object in TargetSeletctObjects:
if bExportPreviewMesh or Object.type == "ARMATURE":
Object.select_set(True)
bpy.ops.better_export.fbx(filepath=ExportAnimtion,my_fbx_format="binary",use_selection=True,use_visible=True,use_only_root_empty_node=False)
# bpy.ops.export_scene.fbx(filepath=ExportAnimtion,use_selection=True,add_leaf_bones=False,object_types={"ARMATURE","MESH"},bake_anim_use_nla_strips=False,bake_anim_use_all_actions=False)
```

View File

@@ -0,0 +1,133 @@
---
title: Blender材质节点笔记
date: 2022-08-12 16:55:20
tags: Blender
rating: ⭐️
---
# Blender材质节点笔记
[Blender Shader文档](https://docs.blender.org/manual/en/latest/render/shader_nodes/index.html)
节点的GLSL源码位于`source\blender\gpu\shaders\material`
## InputNode
- Attribute一个测试节点允许你输入各种类型的数据。就是通过字符串来获取对应的数据。
- UVMap 比较适合于多UVMap的模型。
- Value一个float数值。
- Wirframe网格渲染模式。
- AmbientOcciusion产生AO效果EEVEE需要开启AO选项后才有效果。
- CameraData获取相机数据。
- ViewZDepth线性渐变越近越黑。
- ViewDistance径向渐变。
- Fresnel菲尼尔效果。
- Geometry模型多边形数据。
- Position像素世界坐标。
- Normal世界法线。
- TrueNormal世界面法线。
- HairInfo毛发信息。
- ObjectInfo物体信息。
- Location物体世界坐标。
- Color物体颜色?
- ObjectIndex物体 Relations-PassIndex。
- MaterialIndex材质 Settings-PassIndex。
- Random随机值。
- ParticleInfo粒子信息。
- RGBRGB颜色。
- Tangent生成模型的切线法线。适合用于各向异性BSDF。 可选多种生成方式与投射方向。
- Radial
- UVMap
- TextureCoordinate
- Generated当模型没有UV时基于物体形状快速生成。
- NormalLocalNormal
- Object可以指定一个坐标并且进行旋转缩放来进行映射。
- Window观察坐标UV投射。
- Reflection模拟折射效果的投射坐标
## Output
- MaterialOuput输出材质结果。
- AOVOutput输出用于合成的多通道结果。
## Shader
- [Add Shader](https://docs.blender.org/manual/en/latest/render/shader_nodes/shader/add.html)将2个Shader类型节点结果相加。比如DiffuseBSDF+GlossyBSDF。
- [Anisotropic BSDF](https://docs.blender.org/manual/en/latest/render/shader_nodes/shader/anisotropic.html)
- [Background](https://docs.blender.org/manual/en/latest/render/shader_nodes/shader/background.html)
- [Diffuse BSDF](https://docs.blender.org/manual/en/latest/render/shader_nodes/shader/diffuse.html)
- [Emission](https://docs.blender.org/manual/en/latest/render/shader_nodes/shader/emission.html)
- [Glass BSDF](https://docs.blender.org/manual/en/latest/render/shader_nodes/shader/glass.html)模拟玻璃用的BSDF。
- [Glossy BSDF](https://docs.blender.org/manual/en/latest/render/shader_nodes/shader/glossy.html)
- [Hair BSDF](https://docs.blender.org/manual/en/latest/render/shader_nodes/shader/hair.html)
- [Holdout](https://docs.blender.org/manual/en/latest/render/shader_nodes/shader/holdout.html):合成用节点,让指定区域不渲染。
- [Mix Shader](https://docs.blender.org/manual/en/latest/render/shader_nodes/shader/mix.html)将2个Shader类型节点结果相乘。
- [Principled BSDF](https://docs.blender.org/manual/en/latest/render/shader_nodes/shader/principled.html)多个层组合成一个易于使用的节点的Principled BSDF ,它基于迪士尼模型。
- [Principled Hair BSDF](https://docs.blender.org/manual/en/latest/render/shader_nodes/shader/hair_principled.html)和Hair BSDF差不多。
- [Principled Volume](https://docs.blender.org/manual/en/latest/render/shader_nodes/shader/volume_principled.html):可以给模型或者烟雾材质,以渲染体积效果。
- [Refraction BSDF](https://docs.blender.org/manual/en/latest/render/shader_nodes/shader/refraction.html)
- [Specular BSDF](https://docs.blender.org/manual/en/latest/render/shader_nodes/shader/specular_bsdf.html)
- [Subsurface Scattering](https://docs.blender.org/manual/en/latest/render/shader_nodes/shader/sss.html)模拟次表面散射的BSSDF
- [Toon BSDF](https://docs.blender.org/manual/en/latest/render/shader_nodes/shader/toon.html)
- [Translucent BSDF](https://docs.blender.org/manual/en/latest/render/shader_nodes/shader/translucent.html)
- [Transparent BSDF](https://docs.blender.org/manual/en/latest/render/shader_nodes/shader/transparent.html)
- [Velvet BSDF](https://docs.blender.org/manual/en/latest/render/shader_nodes/shader/velvet.html)丝绸类表面物体的BSDF。
- [Volume Absorption](https://docs.blender.org/manual/en/latest/render/shader_nodes/shader/volume_absorption.html)体积吸收Shader。
- [Volume Scatter](https://docs.blender.org/manual/en/latest/render/shader_nodes/shader/volume_scatter.html)体积散射Shader。
## Texture
- [Brick Texture Node](https://docs.blender.org/manual/en/latest/render/shader_nodes/textures/brick.html):砖墙程序贴图节点。
- [Checker Texture Node](https://docs.blender.org/manual/en/latest/render/shader_nodes/textures/checker.html):棋盘格程序贴图节点。
- [Environment Texture Node](https://docs.blender.org/manual/en/latest/render/shader_nodes/textures/environment.html)HDRI节点。
- [Gradient Texture Node](https://docs.blender.org/manual/en/latest/render/shader_nodes/textures/gradient.html):渐变贴图节点。
- [IES Texture Node](https://docs.blender.org/manual/en/latest/render/shader_nodes/textures/ies.html)IES节点。
- [Image Texture Node](https://docs.blender.org/manual/en/latest/render/shader_nodes/textures/image.html):图片贴图节点。
- [Magic Texture Node](https://docs.blender.org/manual/en/latest/render/shader_nodes/textures/magic.html):魔幻贴图节点,可以用来制作一些油膜干涉效果。
- [Musgrave Texture Node](https://docs.blender.org/manual/en/latest/render/shader_nodes/textures/musgrave.html):马氏分形节点,可以拿来制作一些地形以及黏土表面效果。
- [Noise Texture Node](https://docs.blender.org/manual/en/latest/render/shader_nodes/textures/noise.html)Perlin澡波节点。
- [Point Density Node](https://docs.blender.org/manual/en/latest/render/shader_nodes/textures/point_density.html):获取粒子密度数据节点。
- [Sky Texture Node](https://docs.blender.org/manual/en/latest/render/shader_nodes/textures/sky.html)天光Texture节点。
- [Voronoi Texture Node](https://docs.blender.org/manual/en/latest/render/shader_nodes/textures/voronoi.html):Voronoi澡波节点。
- [Wave Texture Node](https://docs.blender.org/manual/en/latest/render/shader_nodes/textures/wave.html):用于添加环带状失真效果,(摩尔纹子类的)或者等高线效果。
- [White Noise Texture Node](https://docs.blender.org/manual/en/latest/render/shader_nodes/textures/white_noise.html)
## Color
- [Bright/Contrast Node](https://docs.blender.org/manual/en/latest/render/shader_nodes/color/bright_contrast.html):调整亮度。
- [Gamma Node](https://docs.blender.org/manual/en/latest/render/shader_nodes/color/gamma.html)调整Gamma。
- [Hue Saturation Value Node](https://docs.blender.org/manual/en/latest/render/shader_nodes/color/hue_saturation.html):调整色相饱和度。
- [Invert Node](https://docs.blender.org/manual/en/latest/render/shader_nodes/color/invert.html):颜色反转。
- [Light Falloff Node](https://docs.blender.org/manual/en/latest/render/shader_nodes/color/light_falloff.html):灯光衰减效果节点,需要用灯光一起使用,来获取到灯光衰减数据(一个渐变贴图)。
- [Mix Node](https://docs.blender.org/manual/en/latest/render/shader_nodes/color/mix.html):混合颜色与贴图节点。
- [RGB Curves Node](https://docs.blender.org/manual/en/latest/render/shader_nodes/color/rgb_curves.html):颜色曲线节点。
## Vector
- [Bump Node](https://docs.blender.org/manual/en/latest/render/shader_nodes/vector/bump.html)凹凸节点基于Height计算出法线。
- [Displacement Node](https://docs.blender.org/manual/en/latest/render/shader_nodes/vector/displacement.html):置换节点。
- [Mapping Node](https://docs.blender.org/manual/en/latest/render/shader_nodes/vector/mapping.html):映射节点。
- [Normal Node](https://docs.blender.org/manual/en/latest/render/shader_nodes/vector/normal.html)
- [Normal Map Node](https://docs.blender.org/manual/en/latest/render/shader_nodes/vector/normal_map.html)
- [Vector Curves Node](https://docs.blender.org/manual/en/latest/render/shader_nodes/vector/curves.html):矢量曲线节点。
- [Vector Displacement Node](https://docs.blender.org/manual/en/latest/render/shader_nodes/vector/vector_displacement.html)
- [Vector Rotate Node](https://docs.blender.org/manual/en/latest/render/shader_nodes/vector/vector_rotate.html)
- [Vector Transform Node](https://docs.blender.org/manual/en/latest/render/shader_nodes/vector/transform.html)
## Converter
- [Blackbody Node](https://docs.blender.org/manual/en/latest/render/shader_nodes/converter/blackbody.html):黑体温度节点。
- [Clamp Node](https://docs.blender.org/manual/en/latest/render/shader_nodes/converter/clamp.html)
- [Color Ramp Node](https://docs.blender.org/manual/en/latest/render/shader_nodes/converter/color_ramp.html):渐变节点。
- [Combine/Separate Nodes](https://docs.blender.org/manual/en/latest/render/shader_nodes/converter/combine_separate.html):矢量通道合并/分离节点Vector、RGB、HSV
- [Float Curve](https://docs.blender.org/manual/en/latest/render/shader_nodes/converter/float_curve.html)
- [Map Range Node](https://docs.blender.org/manual/en/latest/render/shader_nodes/converter/map_range.html):范围重新映射节点。
- [Math Node](https://docs.blender.org/manual/en/latest/render/shader_nodes/converter/math.html)
- [RGB to BW Node](https://docs.blender.org/manual/en/latest/render/shader_nodes/converter/rgb_to_bw.html)
- [Shader To RGB](https://docs.blender.org/manual/en/latest/render/shader_nodes/converter/shader_to_rgb.html):EEVEE独有使用Shader计算出颜色数据。
- [Vector Math Node](https://docs.blender.org/manual/en/latest/render/shader_nodes/converter/vector_math.html):各种常用数学计算系列节点。
- [Wavelength Node](https://docs.blender.org/manual/en/latest/render/shader_nodes/converter/wavelength.html):可以根据波长转换成不同的颜色。
## Group
- Ctrl+G打组
- N重命名
- Tab退出
- Shift+A新建组
- Ctrl+J背框节点
## 快捷操作
- Ctrl+右键划过:切断材质连线。
- Shift+右键划过:添加转折点。
## OpenShaderingLanguage

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,81 @@
使用方法使用Blender打开NinjaRipper截取的文件并保存成blend文件后执行该脚本。注意运行完之后需要手动导出fbx。
```python
import bpy
def convert_image_tga(sourceImagePath):
    image = bpy.data.images.load(sourceImagePath)
    image.file_format = "TARGA"
    image.save_render(sourceImagePath.replace(".dds",".tga"))
# Unpack
blendPath=bpy.data.filepath
fbxPath=blendPath.replace(".blend",".fbx")
print(fbxPath)
bpy.ops.file.unpack_all()
bpy.ops.wm.save_as_mainfile()
for i in bpy.data.images:
    if i.filepath == '':
        continue
    currentFilePath=bpy.path.abspath(i.filepath)
    print(currentFilePath)
    convert_image_tga(currentFilePath)
    i.filepath = i.filepath.replace('.dds', '.tga')
# Save Blender Project
bpy.ops.wm.save_as_mainfile()
# Export FBX
# bpy.ops.export_scene.fbx(fbxPath)
```
## 贴图格式转换
```python
#dds 转 jpg ------
import bpy
for i in bpy.data.images:
i.filepath = i.filepath.replace('.dds', '.jpg')
#dds 转 png ------
import bpy
for i in bpy.data.images:
i.filepath = i.filepath.replace('.dds', '.png')
#dds 自动转 tga 并关联 fbx
import bpy
def convert_image_tga(sourceImagePath):
image = bpy.data.images.load(sourceImagePath)
image.file_format = "TARGA"
image.save_render(sourceImagePath.replace(".dds",".tga"))
# Pack
bpy.ops.file.pack_all()
# Unpack
blendPath=bpy.data.filepath
fbxPath=blendPath.replace(".blend",".fbx")
print(fbxPath)
bpy.ops.file.unpack_all()
bpy.ops.wm.save_as_mainfile()
for i in bpy.data.images:
if i.filepath == '':
continue
currentFilePath=bpy.path.abspath(i.filepath)
print(currentFilePath)
convert_image_tga(currentFilePath)
i.filepath = i.filepath.replace('.dds', '.tga')
# Save Blender Project
bpy.ops.wm.save_as_mainfile()
# Export FBX
# bpy.ops.export_scene.fbx(fbxPath)
```