AnalyseMorphologique/utils/3d/mpl_render.py

16 lines
539 B
Python

from mpl_toolkits.mplot3d.art3d import Poly3DCollection
import matplotlib.pyplot as plt
import numpy as np
def render3D(data:dict):
"""
Render a 3D model using matplotlib poly3dcollection
:param data: A dict with the vertices and faces
"""
fig = plt.figure()
ax = fig.add_subplot(projection='3d')
faces = np.array(data['faces'])
verts = np.array(list(zip(data['x'], data['y'], data['z'])))
mesh = Poly3DCollection(verts[faces], alpha=0.25, edgecolor='none')
ax.add_collection3d(mesh)
plt.show()