Replies: 2 comments 4 replies
-
Few things are going awry here. The primary issue is that you have a pipeline. The glyph's you are tying to update are computed from the I recommend avoiding the HTH |
Beta Was this translation helpful? Give feedback.
-
Agree with @banesullivan's assessment. Here's the code to do this: sample.mp4from tqdm import tqdm
import pyvista as pv
import numpy as np
import random
import time
pv.set_plot_theme('document')
# Initialize particle data
num_particles = 100
positions = np.random.rand(num_particles, 3)
# Create a PyVista mesh for the particles
poly = pv.PolyData(positions)
poly['velocities'] = (np.random.rand(num_particles, 3) - 0.5) * 0.001
poly['size'] = np.random.rand(num_particles) * 0.05 + 0.05
sphere = pv.Sphere(radius=0.3)
# Create a PyVista plotter
pl = pv.Plotter(off_screen=True)
# Set up a callback function for updating particle positions
def gen_glyphs():
"""Update point positions and return glyphs of those particles."""
poly.points += poly['velocities']
# Update velocities based on particle interactions (insert logic here...)
poly['velocities'] += (np.random.rand(num_particles, 3) - 0.5) * 0.01
poly['size'] += np.random.rand(num_particles) * 0.05 - 0.025
return poly.glyph(geom=sphere, scale='size', factor=1, rng=(0.05, 0.1), orient=False)
# add the mesh, open the movie, and write the first frame
pl.add_mesh(gen_glyphs(), smooth_shading=True, name='points', show_scalar_bar=False)
pl.enable_anti_aliasing('ssaa')
pl.open_movie('/tmp/sample.mp4', quality=10)
pl.write_frame()
# write the remaining frames
for n in tqdm(range(260)):
pl.remove_actor('points') # Remove the previous actor
pl.add_mesh(gen_glyphs(), smooth_shading=True, name='points', show_scalar_bar=False)
pl.write_frame()
pl.close() |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Describe the bug, what's wrong, and what you expect:
I am trying to animate a point cloud of points that move over time. Trying to use the plotter with points rendered as spheres in a window. I do not want to do this off-screen as a gif or mov.
I am trying to use the plotter update_coordinates with interactive_update=True. As I understand it I should be able to change the points and have the changes rendered on screen with this approach.
plotter.show(window_size=(1024, 1024), interactive_update=True)
then
plotter.update_coordinates(points, mesh=glyphs, render=True)
and
plotter.update()
The script crashes on the call to update_coordinates.
I would like help to get this working, or if there is a preferred way to animate a pyvista plotter render on screen can you advise how to achieve this.
** To Reproduce **
** Result **
** System Information **
Date: Sun Apr 23 13:59:15 2023 BST
Python 3.9.13 | packaged by conda-forge | (main, May 27 2022, 17:00:33)
[Clang 13.0.1 ]
Beta Was this translation helpful? Give feedback.
All reactions