当前位置: 首页 > news >正文

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")

相关文章:

blender scripting 编写

blender scripting 编写 一、查看ui按钮对应的代码二、查看或修改对象名称三、案例:渲染多张图片并导出对应的相机参数 一、查看ui按钮对应的代码 二、查看或修改对象名称 三、案例:渲染多张图片并导出对应的相机参数 注:通过ui交互都设置好…...

使用 Elasticsearch 检测抄袭 (二)

我在在之前的文章 “使用 Elasticsearch 检测抄袭 (一)” 介绍了如何检文章抄袭。这个在许多的实际使用中非常有意义。我在 CSDN 上的文章也经常被人引用或者抄袭。有的人甚至也不用指明出处。这对文章的作者来说是很不公平的。文章介绍的内容针对很多的…...

WPF DataGrid

文章目录 SelectionModeHeaderVisibilityBorderBrush SelectionMode DataGrid 控件的 SelectionMode 属性定义了用户可以如何选择 DataGrid 中的行。它是一个枚举类型的属性,有以下几个选项: Single(默认值):只能选择…...

【cesium-5】鼠标交互与数据查询

scene.pick返回的是包含给定窗口位置基元的对象 scene.drillpack返回的是给定窗口位置所有对象的列表 Globe.pick返回的是给光线和地形的交点 Cesium.ScreenSpaceEventType.MIDDLE_CLICK 鼠标中间点击事件 Cesium.ScreenSpaceEventType.MOUSE_MOVE 鼠标移入事件 Cesium.ScreenS…...

Xcode 编译速度慢是什么原因?如何提高编译速度?

作为一个开发者,我们都希望能够高效地开发应用程序,而编译速度是影响开发效率的重要因素之一。然而,有时候我们会发现在使用 Xcode 进行开发时,译速度非常慢,这给我们带来了不少困扰。那么,为什么 Xcode 的…...

Best Arm Identification in Batched Multi-armed Bandit Problems

Q: 这篇论文试图解决什么问题? A: 这篇论文试图解决在批量多臂老虎机问题中进行最佳臂识别(BAI)的挑战,其中必须成批地对臂进行抽样,因为代理等待反馈的时间有限。这种场景出现在许多现实世界的应用中,例如…...

Unity编辑器紫色

紫色原因是因为编辑器内跑了其他平台的shader兼容性导致的,需要动态的去修改shader,主要用到Unity的api : Shader.Find(shaderName); 具体的工具代码如下: using System.Collections; using System.Collections.Generic; using UnityEngine…...

冒泡排序(C语言)

void BubbleSort(int arr[], int len) {int i, j, temp;for (i 0; i < len; i){for (j len - 1; j > i; j--){if (arr[j] > arr[j 1]){temp arr[j];arr[j] arr[j 1];arr[j 1] temp;}}} } 优化&#xff1a; 设置标志位flag&#xff0c;如果发生了交换flag设置…...

Unity中Shader观察空间推导(在Shader中实现)

文章目录 前言一、观察空间矩阵推导1、求观察空间基向量2、求观察空间的基向量在世界空间中的矩阵 的 逆矩阵2、求平移变换矩阵3、相乘得出 观察空间转化矩阵4、得到顶点的世界空间坐标&#xff0c;然后转化到观察空间5、把观察空间坐标转化为齐次裁剪坐标输出到屏幕 二、最终效…...

Hive04_DDL操作

Hive DDL操作 1 DDL 数据定义 1.1 创建数据库 CREATE DATABASE [IF NOT EXISTS] database_name [COMMENT database_comment] [LOCATION hdfs_path] [WITH DBPROPERTIES (property_nameproperty_value, ...)];[IF NOT EXISTS] &#xff1a;判断是否存在 [COMMENT database_c…...

odoo17核心概念view4——view.js

这是view系列的第四篇文章&#xff0c;专门介绍View组件。 作为一个Component&#xff0c;它总共包含js、css、xml三个标准文件&#xff0c;当然最重要的是view.js 首先在setup函数中对传入的参数props做了各种校验&#xff0c;然后扩展了subenv useSubEnv({keepLast: new Kee…...

Centos7 openSSL

阅读时长&#xff1a;10分钟 本文内容&#xff1a; 在阿里云Centos7上部署python3.10.6项目时遇到openSSL协议不支持&#xff0c;导致无法下载第三方包 本文目的&#xff1a; 通过手动编译&#xff0c;升级openssl版本centos7 重编译 python3.10.6github下载缓慢解决镜像源记录…...

Web 安全之文件下载漏洞详解

目录 引言 文件下载漏洞原理 文件下载漏洞的危害 文件下载漏洞类型 文件下载漏洞的利用方法 文件下载漏洞示例 文件下载漏洞的防护措施 漏洞检测与测试 小结 引言 在数字化时代&#xff0c;文件下载是网络应用程序的重要的功能之一&#xff0c;用户可以通过这一功能获…...

搬运机器人RFID传感器CNS-RFID-01|1S的RS485(MODBUS|HS协议)通讯连接方法

搬运机器人RFID传感器CNS-RFID-01|1S支持RS485通信&#xff0c;可支持RS485&#xff08;MODBUS RTU&#xff09;协议、RS485-HS协议&#xff0c;广泛应用于物流仓储&#xff0c;立库 AGV|无人叉车|搬送机器人等领域&#xff0c;常用定位、驻车等&#xff0c;本篇重点介绍CNS-RF…...

使用ZMQ.proxy实现ZMQ PUB消息转发

MQ.proxy 是 ZeroMQ 库中的一个功能&#xff0c;用于创建一个简单的代理服务器。它可以将消息从一个套接字传递到另一个套接字&#xff0c;实现消息的转发和路由。 要使用 ZMQ.proxy&#xff0c;需要按照以下步骤进行操作&#xff1a; 创建两个 ZMQ.Socket 对象&#xff1a;一个…...

若依SQL Server开发使用教程

1. sys_menu表中的将菜单ID修改为自动ID,解决不能增加菜单的问题&#xff0c;操作流程如下&#xff1a; 解决方案如下 菜单栏->工具->选项 点击设计器&#xff0c;去掉阻止保存要求更新创建表的更改选项&#xff0c;点确认既可以保存了 2 自动生成代码找不表的解决方案…...

Mysql5.7服务器选项、系统变量和状态变量参考

官网地址&#xff1a;MySQL :: MySQL 5.7 Reference Manual :: 5.1.3 Server Option, System Variable, and Status Variable Reference 欢迎关注留言&#xff0c;我是收集整理小能手&#xff0c;工具翻译&#xff0c;仅供参考&#xff0c;笔芯笔芯. MySQL 5.7 参考手册 / ..…...

【Qt-Qss-Style】

Qt编程指南 ■ Qss■ Style■ setStyleSheet ■ style.qss■ border■ 去除弹框背景圆角■ QProgressBar样式表 ■ Qss Qt 支持很多种常见 符号 “>”代表直属子部件&#xff0c;说明两个控件之间是父子关系。 “#”代表后面的字段是前面控件类型的名称&#xff0c;当然也可…...

基于yolov8,制作停车位计数器(附源码)

大家好&#xff0c;YOLO(You Only Look Once) 是由Joseph Redmon和Ali开发的一种对象检测和图像分割模型。 YOLO的第一个版本于2015年发布&#xff0c;由于其高速度和准确性&#xff0c;瞬间得到了广大AI爱好者的喜爱。 Ultralytics YOLOv8则是一款前沿、最先进(SOTA)的模型&a…...

C++设计模式:单例模式(饿汉式、懒汉式)

单例模式是什么&#xff1f; 单例模式是一种创建型的软件设计模式。通过单例模式的设计&#xff0c;使得创建的类在当前进程中只有唯一一个实例&#xff0c;并提供一个全局性的访问点&#xff0c;这样可以规避因频繁创建对象而导致的内存飙升情况。 单例模式有三个要点 私有化…...

css实现圆环展示百分比,根据值动态展示所占比例

代码如下 <view class""><view class"circle-chart"><view v-if"!!num" class"pie-item" :style"{background: conic-gradient(var(--one-color) 0%,#E9E6F1 ${num}%),}"></view><view v-else …...

R语言AI模型部署方案:精准离线运行详解

R语言AI模型部署方案:精准离线运行详解 一、项目概述 本文将构建一个完整的R语言AI部署解决方案,实现鸢尾花分类模型的训练、保存、离线部署和预测功能。核心特点: 100%离线运行能力自包含环境依赖生产级错误处理跨平台兼容性模型版本管理# 文件结构说明 Iris_AI_Deployme…...

蓝桥杯 2024 15届国赛 A组 儿童节快乐

P10576 [蓝桥杯 2024 国 A] 儿童节快乐 题目描述 五彩斑斓的气球在蓝天下悠然飘荡&#xff0c;轻快的音乐在耳边持续回荡&#xff0c;小朋友们手牵着手一同畅快欢笑。在这样一片安乐祥和的氛围下&#xff0c;六一来了。 今天是六一儿童节&#xff0c;小蓝老师为了让大家在节…...

系统设计 --- MongoDB亿级数据查询优化策略

系统设计 --- MongoDB亿级数据查询分表策略 背景Solution --- 分表 背景 使用audit log实现Audi Trail功能 Audit Trail范围: 六个月数据量: 每秒5-7条audi log&#xff0c;共计7千万 – 1亿条数据需要实现全文检索按照时间倒序因为license问题&#xff0c;不能使用ELK只能使用…...

视频字幕质量评估的大规模细粒度基准

大家读完觉得有帮助记得关注和点赞&#xff01;&#xff01;&#xff01; 摘要 视频字幕在文本到视频生成任务中起着至关重要的作用&#xff0c;因为它们的质量直接影响所生成视频的语义连贯性和视觉保真度。尽管大型视觉-语言模型&#xff08;VLMs&#xff09;在字幕生成方面…...

sqlserver 根据指定字符 解析拼接字符串

DECLARE LotNo NVARCHAR(50)A,B,C DECLARE xml XML ( SELECT <x> REPLACE(LotNo, ,, </x><x>) </x> ) DECLARE ErrorCode NVARCHAR(50) -- 提取 XML 中的值 SELECT value x.value(., VARCHAR(MAX))…...

【Web 进阶篇】优雅的接口设计:统一响应、全局异常处理与参数校验

系列回顾&#xff1a; 在上一篇中&#xff0c;我们成功地为应用集成了数据库&#xff0c;并使用 Spring Data JPA 实现了基本的 CRUD API。我们的应用现在能“记忆”数据了&#xff01;但是&#xff0c;如果你仔细审视那些 API&#xff0c;会发现它们还很“粗糙”&#xff1a;有…...

04-初识css

一、css样式引入 1.1.内部样式 <div style"width: 100px;"></div>1.2.外部样式 1.2.1.外部样式1 <style>.aa {width: 100px;} </style> <div class"aa"></div>1.2.2.外部样式2 <!-- rel内表面引入的是style样…...

uniapp微信小程序视频实时流+pc端预览方案

方案类型技术实现是否免费优点缺点适用场景延迟范围开发复杂度​WebSocket图片帧​定时拍照Base64传输✅ 完全免费无需服务器 纯前端实现高延迟高流量 帧率极低个人demo测试 超低频监控500ms-2s⭐⭐​RTMP推流​TRTC/即构SDK推流❌ 付费方案 &#xff08;部分有免费额度&#x…...

C++.OpenGL (10/64)基础光照(Basic Lighting)

基础光照(Basic Lighting) 冯氏光照模型(Phong Lighting Model) #mermaid-svg-GLdskXwWINxNGHso {font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}#mermaid-svg-GLdskXwWINxNGHso .error-icon{fill:#552222;}#mermaid-svg-GLd…...