nbe*_*ben 5 python mesh three.js jupyter-notebook
我一直在尝试使用pythreejs在jupyter笔记本中渲染3D对象。对于第一个测试,我使用四面体做了以下简单示例:
# Plot a mesh with pythreejs
import pythreejs as p3js
from IPython.display import display
vertices = [[0.3,0,0],[0,0.5,0.4],[-0.2,0.3,-0.1],[0.9,0,-0.3]]
faces = [[0,1,2],[1,2,3],[2,0,3],[0,1,3]]
colors = ['#ff0000','#00ff00','#0000ff','#ffffff']
faces = [f + [None, [colors[i] for i in f]] for f in faces]
geo = p3js.Geometry(vertices=vertices, faces=faces, colors=colors)
geo.exec_three_obj_method('computeFaceNormals')
mesh = p3js.Mesh(
geometry=geo,
material=p3js.MeshBasicMaterial(vertexColors='VertexColors',
side='DoubleSide'),
position=list(-np.mean(vertices, axis=0)))
cam = p3js.PerspectiveCamera(position=[4,0,0], up=[0,0,1], fov=10)
scene = p3js.Scene(
children=[mesh, cam, p3js.AmbientLight(color=u'0x777777')],
background='black')
renderer = p3js.Renderer(camera=cam, scene=scene,
controls=[p3js.OrbitControls(controlling=cam)])
display(renderer)
Run Code Online (Sandbox Code Playgroud)
当我在jupyter笔记本(Python 3.6.6,pythreejs版本1.1.0)中对上述内容进行评估时,我得到的期望值或多或少:黑色背景带有看起来很滑稽的四面体,其顶点具有不同的颜色。大!所以我尝试了一个更复杂的网格。我已经将这个网格的数据以gzipped-hdf5格式上传到文件放置器中,此处;您可以下载它,将其压缩,然后使用以下代码阅读:
# load the mesh
import h5py
with h5py.File(downloaded_filename, 'r') as f:
vertices = [list(xyz) for xyz in f['vertices']]
faces = [list(ijk) for ijk in f['faces']]
colors = [s.decode('utf-8') for s in f['colors']]
Run Code Online (Sandbox Code Playgroud)
我已经使用许多其他软件验证了网格数据,因此我不认为网格本身就是问题所在(尽管网格可能有一些小缺陷-例如,两个顶点实际上位于同一位置)。当我使用h5py加载代码替换vertices = ...
,faces = ...
和colors = ...
线我以前的代码块,我反而得到了一个空白的黑盒子。还要注意mesh
,当单独评估时,也会显示一个空白框(尽管在四面体的情况下,它会显示网格的渲染)。我没有在文档中看到任何暗示大网格无法正常工作的信息。还有其他问题吗?
提前致谢。
编辑:原始文件太大,无法放入文件删除器,因此我上传了一个新文件(相同文件,现在只是压缩)。
归档时间: |
|
查看次数: |
264 次 |
最近记录: |