blender scripting 编写

blender scripting 编写

  • 一、查看ui按钮对应的代码
  • 二、查看或修改对象名称
  • 三、案例:渲染多张图片并导出对应的相机参数

一、查看ui按钮对应的代码

在这里插入图片描述

二、查看或修改对象名称

在这里插入图片描述

三、案例:渲染多张图片并导出对应的相机参数

注:通过ui交互都设置好,如果ui能渲染,该代码就能运行成功。

import bpy
import math
import os
from mathutils import Vector, Matrix
from math import radians
import bmesh
import datetime
import time
import numpy as np
import os
#from os import pathscenenumber='baseline_scene6_clean'#basefolder=os.path.join(os.path.expanduser('~'), 'Documents', 'Zantis', scenenumber)
scene = bpy.data.scenes["Scene"]
#scene.camera.rotation_mode='YZX'
def length():leg=0.00p1=[0.0,0.0]temp=0ob = bpy.context.object # active objectfor p in ob.data.splines.active.bezier_points:p2=p1p1=[p.co.x,p.co.y]if(temp==0):temp=1continuedistance = math.sqrt( ((p1[0]-p2[0])**2)+((p1[1]-p2[1])**2) )leg=leg+distancereturn legitem=0
multiply=40
camera = bpy.data.objects['Camera']
target=bpy.data.objects['mesh.001']
my_obj=[]#my_obj.append("019")
#my_obj.append("021")
#my_obj.append("029")
#my_obj.append("030")
#my_obj.append("031")
#my_obj.append("032")
#my_obj.append("033")
#my_obj.append("034")
my_obj.append("040")
#my_obj.append("042")t1 = time.time()#import bpy#for ob in bpy.context.selected_editable_objects:#  ob.active_material_index = 0#   for i in range(len(ob.material_slots)):
#        bpy.ops.object.material_slot_remove({'object': ob})for item in my_obj:#break# basefolder=os.path.join(os.path.expanduser('~'), 'Desktop', 'Urban_Enviroment_Texturing','Mesh_Texturing_Pipeline', 'Scenes', '005', 'images')basefolder = os.path.join('E:\\', 'chromeDownload', 'mvs_test', 'scenes', '006', 'images')t2 = time.time()for ob in bpy.context.selected_objects:ob.select_set(False)curv='Curve.'+itempath = bpy.data.objects[curv]camera.select_set(True)path.select_set(True)# bpy.context.view_layer.objects.active = path # parent# bpy.ops.object.parent_set(type='FOLLOW') # follow path# camera.location=path.matrix_world @ bpy.context.object.data.splines.active.bezier_points[0].co# target.location=path.matrix_world @ bpy.context.object.data.splines.active.bezier_points[1].co# direc=target.location-camera.locationframes=(int)(length()*multiply)	# bpy.data.scenes["Scene"].frame_end=frames# bpy.context.object.data.path_duration=framesframe_is=0frames=frames+1print(frames)count=0for frame_is in range(scene.frame_start, scene.frame_end + 1):# for frame_is in range(frames - 3):t3 = time.time()scene.frame_current=frame_is#print(scene.frame_currents
#        s=str(scene.objects['Camera'].matrix_world[0][3])+"_"+str(scene.objects['Camera'].matrix_world[1][3])+"_"+str(scene.objects['Camera'].matrix_world[2][3])+"_"
#        s=s+str(direc[0])+"_"+str(direc[1])+"_"+str(direc[2])+".jpg"s = str(scene.frame_current).zfill(5)+".jpg"image_filepath=os.path.join(basefolder,s)#print(s)bpy.data.scenes['Scene'].render.filepath = image_filepath
#        bpy.ops.render.render(write_still=True)elapsedTime = time.time() - t3print("Frame time passed {hours:d}:{minutes:d}:{seconds:d}".format(hours=int((elapsedTime / 60 ** 2) % (60 ** 2)), minutes=int((elapsedTime / 60) % (60)),seconds=int(elapsedTime % 60)))#        print('path to create: ', os.path.join(os.path.expanduser('~'), 'Desktop', 'Data','Depth_data',scenenumber+'_'+item))if not os.path.exists(os.path.join(os.path.expanduser('~'), basefolder)):os.mkdir(os.path.join(os.path.expanduser('~'), basefolder))if not os.path.exists(os.path.join(os.path.expanduser('~'), basefolder, 'RTm/')):os.mkdir(os.path.join(os.path.expanduser('~'), basefolder, 'RTm/'))# Set up rendering of depth map:bpy.context.scene.use_nodes = Truetree = bpy.context.scene.node_treelinks = tree.links# clear default nodesfor n in tree.nodes:tree.nodes.remove(n)# create input render layer noderl = tree.nodes.new('CompositorNodeRLayers')RGB2BW = tree.nodes.new(type="CompositorNodeRGBToBW")links.new(rl.outputs[0], RGB2BW.inputs[0])map = tree.nodes.new(type="CompositorNodeMapValue")# Size is chosen kind of arbitrarily, try out until you're satisfied with resulting depth map.map.size = [0.05]map.use_min = Truemap.min = [0]map.use_max = Truemap.max = [1]links.new(rl.outputs[2], map.inputs[0])mix_multi = tree.nodes.new(type="CompositorNodeMixRGB")# Size is chosen kind of arbitrarily, try out until you're satisfied with resulting depth map.mix_multi.blend_type = 'MULTIPLY'mix_multi.inputs[2].default_value[0] = 0.5mix_multi.inputs[2].default_value[1] = 0.5mix_multi.inputs[2].default_value[2] = 0.5
#        mix_multi.inputs[2].default = [0.5 , 0.5, 0.5, 1.0]links.new(rl.outputs[3], mix_multi.inputs[1])mix_multi2 = tree.nodes.new(type="CompositorNodeMixRGB")# Size is chosen kind of arbitrarily, try out until you're satisfied with resulting depth map.mix_multi2.blend_type = 'ADD'mix_multi2.inputs[2].default_value[0] = 0.5mix_multi2.inputs[2].default_value[1] = 0.5mix_multi2.inputs[2].default_value[2] = 0.5links.new(mix_multi.outputs[0], mix_multi2.inputs[1])invert = tree.nodes.new(type="CompositorNodeInvert")links.new(map.outputs[0], invert.inputs[1])# The viewer can come in handy for inspecting the results in the GUIdepthViewer = tree.nodes.new(type="CompositorNodeViewer")links.new(invert.outputs[0], depthViewer.inputs[0])# Use alpha from input.links.new(rl.outputs[1], depthViewer.inputs[1])# Normal map# The viewer can come in handy for inspecting the results in the GUIdepthViewer2 = tree.nodes.new(type="CompositorNodeViewer")links.new(rl.outputs[1], depthViewer2.inputs[1])links.new(mix_multi2.outputs[0], depthViewer2.inputs[0])#        fileOutput = tree.nodes.new(type="CompositorNodeOutputFile")
#        fileOutput.base_path = os.path.join(os.path.expanduser('~'), 'Desktop', 'Data','Depth_data',scenenumber+'_'+item, 'depth')
##        fileOutput.file_slots[0].path = str(scene.frame_current).zfill(5)
#        links.new(invert.outputs[0], fileOutput.inputs[0])
#        
#        fileOutput2 = tree.nodes.new(type="CompositorNodeOutputFile")
#        fileOutput2.base_path = os.path.join(os.path.expanduser('~'), 'Desktop', 'Data','Depth_data',scenenumber+'_'+item,'normal')
##        fileOutput2.file_slots[0].path = str(scene.frame_current).zfill(5)
#        links.new(mix_multi2.outputs[0], fileOutput2.inputs[0])
#        
#        fileOutput3 = tree.nodes.new(type="CompositorNodeOutputFile")
#        fileOutput3.base_path = os.path.join(os.path.expanduser('~'), 'Desktop', 'Data','Depth_data',scenenumber+'_'+item,'panoramas_BW')
##        fileOutput3.file_slots[0].path = str(scene.frame_current).zfill(5)
#        links.new(RGB2BW.outputs[0], fileOutput3.inputs[0])bpy.ops.render.render(write_still=True)location, rotation = scene.objects['Camera'].matrix_world.decompose()[0:2]R_world2bcam = rotation.to_matrix().transposed()T_world2bcam = -1*R_world2bcam @ locationCamera_RT_matrix =  Matrix((R_world2bcam[0][:] + (T_world2bcam[0],),R_world2bcam[1][:] + (T_world2bcam[1],),R_world2bcam[2][:] + (T_world2bcam[2],),[0,0,0,1],))np.savetxt(os.path.join(os.path.expanduser('~'), basefolder, 'RTm')+'/'+str(frame_is).zfill(6)+"_RTm.txt",np.array(Camera_RT_matrix))# breakscene.frame_current=0path.select_set(False)bpy.ops.object.parent_clear(type='CLEAR')# camera.select_set(False)
elapsedTime = time.time() - t1
print("Total time passed {hours:d}:{minutes:d}:{seconds:d}".format(hours=int((elapsedTime / 60 ** 2) % (60 ** 2)), minutes=int((elapsedTime / 60) % (60)),seconds=int(elapsedTime % 60)))
print("Finished")

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/300649.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

算法与数据结构--二叉搜索树与自平衡二叉搜索树

0.字典(即c的map) 注:字典的 "member运算" 指的是检查字典中是否存在某个特定的键的操作,即查询操作。 如果我们使用数组来实现字典/map,虽然使用二分法查询也可以达到logn,但是的话插入和删除太…

【操作系统】探究进程奥秘:显示进程列表的解密与实战

​🌈个人主页:Sarapines Programmer🔥 系列专栏:Linux专栏:《探秘Linux | 操作系统解密》⏰诗赋清音:月悬苍穹泛清辉,梦随星河徜徉辉。情牵天际云千层,志立乘风意自飞。 ​ 目录 &a…

ImageJ图像滤波基础

文章目录 滤波简单滤波器卷积滤波Unsharp MaskTop Hat ImageJ系列:安装与初步💎灰度图像处理 滤波 预设滤波器 ImageJ的Process菜单提供了诸多图像滤波器,其中大部分方法均可定制参数,但也提供了一些已经预设参数的处理方法。 …

Visual Studio2022配置ReSharper C++ 常用设置

如需安装免费的可以在下面留言,看到即回复 文章目录 Visual Studio2022配置ReSharper C 常用设置配置Visual Studio2022,使其能够按回车进行补全配置ReSharper C 设置自动弹出配置ReSharper C 的快捷键ReSharper C 去掉注释拼写使用中文注释 如何关闭新版…

2007年AMC8数学竞赛中英文真题典型考题、考点分析和答案解析

今天,我们来继续研究AMC8竞赛的真题。通过反复研究历年真题,不仅可以掌握AMC8这个竞赛的命题规律和常见考点,通过真题的详细解析可以建立自己的解题思路、举一反三,还可以通过做真题不断发现自己的薄弱点查漏补缺。 今天我们来看看…

FinGPT:金融大语言模型 | 开源日报 No.127

verdaccio/verdaccio Stars: 15.0k License: MIT Verdaccio 是一个轻量级的 Node.js 私有代理仓库。 以下是 Verdaccio 的核心优势和关键特性: 零配置:无需复杂设置即可快速启动私有 npm 注册表。本地化管理:通过内置小型数据库进行简单而…

Nature | Baker团队用AI设计出史上最高互作强度的蛋白质

蛋白质是生命的基础,是生命功能的主要执行者,其结构与功能由氨基酸序列所决定。蛋白质设计是指对新蛋白质分子进行人为的合理设计,旨在设计新的活性,行为或目的,并增进对蛋白质功能的基本了解。可以从头开始设计蛋白质…

蓝桥杯备赛 day 1 —— 递归 、递归、枚举算法(C/C++,零基础,配图)

目录 🌈前言 📁 枚举的概念 📁递归的概念 例题: 1. 递归实现指数型枚举 2. 递归实现排列型枚举 3. 递归实现组合型枚举 📁 递推的概念 例题: 斐波那契数列 📁习题 1. 带分数 2. 反硬币 3. 费解的…

12.25

led.c #include "led.h" void all_led_init() {RCC_GPIO | (0X3<<4);//时钟使能GPIOE_MODER &(~(0X3<<20));//设置PE10输出GPIOE_MODER | (0X1<<20);//设置PE10为推挽输出GPIOE_OTYPER &(~(0x1<<10));//PE10为低速输出GPIOE_OSPEED…

【深度学习目标检测】十一、基于深度学习的电网绝缘子缺陷识别(python,目标检测,yolov8)

YOLOv8是一种物体检测算法&#xff0c;是YOLO系列算法的最新版本。 YOLO&#xff08;You Only Look Once&#xff09;是一种实时物体检测算法&#xff0c;其优势在于快速且准确的检测结果。YOLOv8在之前的版本基础上进行了一系列改进和优化&#xff0c;提高了检测速度和准确性。…

C# 读取Word表格到DataSet

目录 功能需求 Office 数据源的一些映射关系 范例运行环境 配置Office DCOM 关键代码 组件库引入 ​核心代码 杀掉进程 总结 功能需求 在应用项目里&#xff0c;多数情况下我们会遇到导入 Excel 文件数据到数据库的功能需求&#xff0c;但某些情况下&#xff0c;也存…

深圳锐科达SIP矿用电话模块SV-2801VP

深圳锐科达SIP矿用电话模块SV-2801VP 一、简介 SV-2800VP系列模块是我司设计研发的一款用于井下的矿用IP音频传输模块&#xff0c;可用此模块打造一套低延迟、高效率、高灵活和多扩展的IP矿用广播对讲系统&#xff0c;亦可对传统煤矿电话系统加装此模块&#xff0c;进行智能化…