Closed slecleach closed 1 day ago
Hi @slecleach!
Yeah, unfortunately the spline API just doesn't scale well. The reasons are unfortunately pretty fundamental.
I do have a faster API for rendering general line segments, which I just pushed to a branch in #315. Perhaps you could try it? It expects numpy arrays of shape (N, 2, 3)
, where we have N
line segments which each have separate start + end points.
import time
import numpy as np
import viser
server = viser.ViserServer()
# Line segments.
#
# This will be much faster than creating separate scene objects for
# individual line segments or splines.
N = 5_000
points = np.random.normal(size=(N, 2, 3)) * 3.0
colors = np.random.randint(0, 255, size=(N, 2, 3), dtype=np.uint8)
line_segments = server.scene.add_line_segments(
f"/line_segments",
points=points,
colors=colors,
line_width=3.0,
)
counter = server.scene.add_label("/counter", text="0")
while True:
line_segments.points = np.random.normal(size=(N, 2, 3)) * 3.0
line_segments.colors = np.random.randint(0, 255, size=(N, 2, 3), dtype=np.uint8)
counter.text = str(int(counter.text) + 1)
time.sleep(1.0 / 25.0)
Hi Brent,
Ah amazing! thanks so much for putting this together. This is perfect, I just needed to visualize segments and I didn't need the spline smoothing and interpolation from catmull
. I tried the code you sent and it should work perfectly for my use case.
I took a look at the PR #315 and left one minor comment. Thanks again for the help! Best, Simon
Hi Brent, first of all thanks a lot for building this tool, it's a truly amazing work!
I wanted to get your advice on a somewhat niche use case. I want to draw multiple splines in Viser and update them at a moderately fast rate. To give you some concrete numbers, I am trying to visualize 100 splines composed of 50 segments each and updated at ~25Hz. I am having trouble visualizing this in Viser with the current method I am using.
This is how I update the spline positions:
I wonder if you would know how we could update the splines more efficiently assuming we keep the same number of splines and the same number of segments but we just want to update the spline positions.