python绘制三维网格图_使用python将三维网格渲染为图像

我刚刚遇到了一个类似的问题,并用pyrender及其屏幕外渲染器解决了这个问题。在

看看这里的最小工作示例PyrenderOSMesaSample.ipynb。

构建自己的网格并获得场景的渲染RGB非常简单。在

这是我的MWEimport os

# switch to "osmesa" or "egl" before loading pyrender

os.environ["PYOPENGL_PLATFORM"] = "osmesa"

import numpy as np

import pyrender

import trimesh

import matplotlib.pyplot as plt

# generate mesh

sphere = trimesh.creation.icosphere(subdivisions=4, radius=0.8)

sphere.vertices+=1e-2*np.random.randn(*sphere.vertices.shape)

mesh = pyrender.Mesh.from_trimesh(sphere, smooth=False)

# compose scene

scene = pyrender.Scene(ambient_light=[.1, .1, .3], bg_color=[0, 0, 0])

camera = pyrender.PerspectiveCamera( yfov=np.pi / 3.0)

light = pyrender.DirectionalLight(color=[1,1,1], intensity=2e3)

scene.add(mesh, pose= np.eye(4))

scene.add(light, pose= np.eye(4))

c = 2**-0.5

scene.add(camera, pose=[[ 1, 0, 0, 0],

[ 0, c, -c, -2],

[ 0, c, c, 2],

[ 0, 0, 0, 1]])

# render scene

r = pyrender.OffscreenRenderer(512, 512)

color, _ = r.render(scene)

plt.figure(figsize=(8,8)), plt.imshow(color);

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值