计算机图形学流体模拟 blender 渲染脚本

做流体模拟的时候,想要复现别人的成果,但是别人的代码都是每帧输出 ply 格式的文件,渲染部分需要自己完成

看了一下,似乎用 blender 是最简单的,于是记录一下过程中用到的代码

Blender 版本 4.0

批量导入 ply

假设所有 ply 文件都和 blend 文件位于同一目录

ply 文件的文件名格式是 00001.ply, 00002.ply, 000123.ply 之类,编号表示帧数

希望导入所有 ply 文件,都放在一个 collection 里面,并且只连接到这个 collection

import bpy 
import os

in_dir = bpy.path.abspath("//")
filters = []  # files to ignore
files_number = 0

def only_link_to_one_collection(obj, collection):
    for other_col in obj.users_collection:
        other_col.objects.unlink(obj)
    if obj.name not in collection.objects:
        collection.objects.link(obj)
        
def import_ply(path, filters):
    need_file_items = []
    need_file_names = []

    filterDict = {
   }
    for item in filters:
        filterDict[item] = True;

    file_lst = os.listdir(path)
    
    for item in file_lst:
        fileName, fileExtension = os.path.splitext(item)
        if fileExtension == ".ply" and (not item in filterDict):
            need_file_items.append(item)
            need_file_names.append(fileName)
    
    fluid_mesh_collection = bpy.data.collections.new(name='FluidMesh')
    bpy.context.scene.collection.children.link(fluid_mesh_collection)
    
    files_number = len(need_file_items)
    for i in range(files_number):
        item = need_file_items
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值