利用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()

  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值