利用Blender进行点云渲染的代码

利用Blender进行点云渲染的代码,第1张

利用Blender进行点云渲染的代码 一、导入点云文件并显示

教程:【CG黑科技】如何在Blender中可视化点云数据?https://www.bilibili.com/video/av93751683/

1. 安装点云显示插件

下载链接:GitHub - uhlik/bpy: blender python scripts

2. 根据b站视频教程安装插件、导入点云 二、利用python脚本自动渲染代码
import bpy
import numpy as np
import math
import os
import sys

ROOT_DIR = "C://Users//11580//Desktop//bpy//"
sys.path.insert(1, ROOT_DIR)

from space_view3d_point_cloud_visualizer import *

tx = 0.0
ty = 2.0
tz = 0.0

rx = 90.0
ry = 0.0
rz = 180.0

fov = 50.0
pi = 3.14159265

scene = bpy.data.scenes["Scene"]

# Set render resolution
scene.render.resolution_x = 480
scene.render.resolution_y = 359

# Set camera fov in degrees
scene.camera.data.angle = fov*(pi/180.0)

# Set camera rotation in euler angles
scene.camera.rotation_mode = 'XYZ'
scene.camera.rotation_euler[0] = rx*(pi/180.0)
scene.camera.rotation_euler[1] = ry*(pi/180.0)
scene.camera.rotation_euler[2] = rz*(pi/180.0)

scene.camera.location.x = tx
scene.camera.location.y = ty
scene.camera.location.z = tz

#创建一个空物体
bpy.ops.object.add(radius=1.0, type='EMPTY', enter_editmode=False, align='WORLD')
#bpy.ops.object.add_named(linked=False, name='kong', drop_x=0, drop_y=0)
active_object = bpy.context.active_object
filepath = "C://Users//11580//Desktop//bunny.ply"
controller = PCVControl(active_object)

# Load data from ply file
pcv = active_object.point_cloud_visualizer
pcv.filepath = filepath
PCVManager.load_ply_to_cache(None, bpy.context)

#edit point cloud
#bpy.ops.object.select_all(action='SELECT')
bpy.data.objects['Empty'].scale = (1.0, 1.0, 1.0)


# Draw point cloud
bpy.app.debug_value = 1
c = PCVManager.cache[pcv.uuid]
c['draw'] = True
controller._redraw()

#Render
PCV_OT_render.execute(None, bpy.context)


#PCV_OT_convert.execute(None, bpy.context)
#bpy.ops.object.delete()

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/4655184.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-06
下一篇 2022-11-06

发表评论

登录后才能评论

评论列表(0条)

保存