enthought / mayavi

3D visualization of scientific data in Python
http://docs.enthought.com/mayavi/mayavi/
Other
1.28k stars 282 forks source link

Mayavi camera clipping #1227

Open aeropung opened 1 year ago

aeropung commented 1 year ago

I'm using Mayavi in a Python script to ingest an STL CAD file. Although the CAD file renders correctly, I experience odd clipping effects when I zoom in too far on the object or when I rotate the scene when I'm zoomed in quite a bit. Although not verbatim, my current code is something like this:

from stl import mesh
from mayavi import mlab

# Create Mayavi figure
f = mlab.figure(size=(500,500),bgcolor=(0.,0.,0.))
visual.set_viewer(f)

# Ingest CAD model
sat_body = <Path to .stl file>
body_mesh = mesh.Mesh.from_file(sat_body)
bx,by,bz = body_mesh.x, body_mesh.y, body_mesh.z
s1 = mlab.mesh(bx,by,bz,colormap="Greys",representation="surface")

# Position camera
mlab.view(focalpoint=[0,0,0],distance=200)
mlab.show()

However, when I rotate the scene, a part of the CAD model disappears. Similarly, when I zoom in without rotation, the CAD model disappears. What can I do to fix this? It's severely limiting me being able to resolve small features on the CAD model. Evidence of the clipping is illustrated in the three figures below:

(left) The normally rendered scene, no zoom, no rotation (center) The same zoom, but with added scene rotation (right) No scene rotation, but with increased zoom

image

The issue seems to be similar to that of camera clipping in Blender, which is solved by changing the clip plane of the camera. It is also addressed in this issue with less detail.

prabhuramachandran commented 1 year ago

Does doing

s1.scene.reset_zoom()

help?

drocheam commented 7 months ago

What about

s1.scene.renderer.reset_camera_clipping_range()

?