mirror of
https://github.com/redoules/redoules.github.io.git
synced 2025-12-12 15:59:34 +00:00
visualisation de mesh dans plotly #1
Owner
```python
import numpy as np
from stl import mesh # pip install numpy-stl
import plotly.graph_objects as go
def stl2mesh3d(path):
stl_mesh = mesh.Mesh.from_file(path)
# stl file from: https://github.com/stephenyeargin/stl-files/blob/master/AT%26T%20Building.stl
stl_mesh.vectors.shape
# stl_mesh is read by nympy-stl from a stl file; it is an array of faces/triangles (i.e. three 3d points)
# this function extracts the unique vertices and the lists I, J, K to define a Plotly mesh3d
p, q, r = stl_mesh.vectors.shape #(p, 3, 3)
# the array stl_mesh.vectors.reshape(p*q, r) can contain multiple copies of the same vertex;
# extract unique vertices from all mesh triangles
vertices, ixr = np.unique(stl_mesh.vectors.reshape(p*q, r), return_inverse=True, axis=0)
I = np.take(ixr, [3*k for k in range(p)])
J = np.take(ixr, [3*k+1 for k in range(p)])
K = np.take(ixr, [3*k+2 for k in range(p)])
x, y, z = vertices.T
colorscale= [[0, '#e5dee5'], [1, '#e5dee5']]
mesh3D = go.Mesh3d(
x=x,
y=y,
z=z,
i=I,
j=J,
k=K,
flatshading=False,
colorscale=colorscale,
intensity=z,
#name='AT&T',
showscale=False)
return mesh3D
fig = go.Figure(data=[stl2mesh3d("CAO.stl")])
fig.write_html("visu.html")
```
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?