当前位置: 首页 > 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;这样可以规避因频繁创建对象而导致的内存飙升情况。 单例模式有三个要点 私有化…...

突破不可导策略的训练难题:零阶优化与强化学习的深度嵌合

强化学习&#xff08;Reinforcement Learning, RL&#xff09;是工业领域智能控制的重要方法。它的基本原理是将最优控制问题建模为马尔可夫决策过程&#xff0c;然后使用强化学习的Actor-Critic机制&#xff08;中文译作“知行互动”机制&#xff09;&#xff0c;逐步迭代求解…...

【JavaEE】-- HTTP

1. HTTP是什么&#xff1f; HTTP&#xff08;全称为"超文本传输协议"&#xff09;是一种应用非常广泛的应用层协议&#xff0c;HTTP是基于TCP协议的一种应用层协议。 应用层协议&#xff1a;是计算机网络协议栈中最高层的协议&#xff0c;它定义了运行在不同主机上…...

黑马Mybatis

Mybatis 表现层&#xff1a;页面展示 业务层&#xff1a;逻辑处理 持久层&#xff1a;持久数据化保存 在这里插入图片描述 Mybatis快速入门 ![在这里插入图片描述](https://i-blog.csdnimg.cn/direct/6501c2109c4442118ceb6014725e48e4.png //logback.xml <?xml ver…...

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

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

P3 QT项目----记事本(3.8)

3.8 记事本项目总结 项目源码 1.main.cpp #include "widget.h" #include <QApplication> int main(int argc, char *argv[]) {QApplication a(argc, argv);Widget w;w.show();return a.exec(); } 2.widget.cpp #include "widget.h" #include &q…...

DBAPI如何优雅的获取单条数据

API如何优雅的获取单条数据 案例一 对于查询类API&#xff0c;查询的是单条数据&#xff0c;比如根据主键ID查询用户信息&#xff0c;sql如下&#xff1a; select id, name, age from user where id #{id}API默认返回的数据格式是多条的&#xff0c;如下&#xff1a; {&qu…...

多模态大语言模型arxiv论文略读(108)

CROME: Cross-Modal Adapters for Efficient Multimodal LLM ➡️ 论文标题&#xff1a;CROME: Cross-Modal Adapters for Efficient Multimodal LLM ➡️ 论文作者&#xff1a;Sayna Ebrahimi, Sercan O. Arik, Tejas Nama, Tomas Pfister ➡️ 研究机构: Google Cloud AI Re…...

Java数值运算常见陷阱与规避方法

整数除法中的舍入问题 问题现象 当开发者预期进行浮点除法却误用整数除法时,会出现小数部分被截断的情况。典型错误模式如下: void process(int value) {double half = value / 2; // 整数除法导致截断// 使用half变量 }此时...

云原生安全实战:API网关Kong的鉴权与限流详解

&#x1f525;「炎码工坊」技术弹药已装填&#xff01; 点击关注 → 解锁工业级干货【工具实测|项目避坑|源码燃烧指南】 一、基础概念 1. API网关&#xff08;API Gateway&#xff09; API网关是微服务架构中的核心组件&#xff0c;负责统一管理所有API的流量入口。它像一座…...

Linux nano命令的基本使用

参考资料 GNU nanoを使いこなすnano基础 目录 一. 简介二. 文件打开2.1 普通方式打开文件2.2 只读方式打开文件 三. 文件查看3.1 打开文件时&#xff0c;显示行号3.2 翻页查看 四. 文件编辑4.1 Ctrl K 复制 和 Ctrl U 粘贴4.2 Alt/Esc U 撤回 五. 文件保存与退出5.1 Ctrl …...