K3D-tools / K3D-jupyter

K3D lets you create 3D plots backed by WebGL with high-level API (surfaces, isosurfaces, voxels, mesh, cloud points, vtk objects, volume renderer, colormaps, etc). The primary aim of K3D-jupyter is to be easy for use as stand alone package like matplotlib, but also to allow interoperation with existing libraries as VTK.
MIT License
942 stars 123 forks source link

Timeseries does not work for vectors? #310

Closed tfunatomi closed 3 years ago

tfunatomi commented 3 years ago

Hello, k3d is so helpful. I deeply appreciate the developers of this project.

I tried to make an animation using k3d.vectors and found an issue probably.

I understand from the below that Timeseries must be set to model_matrix in k3d.vectors https://github.com/K3D-tools/K3D-jupyter/blob/102bdbfde6058285439b589caef6a2f936e90986/k3d/factory.py#L955 and it seems correct in the below. https://github.com/K3D-tools/K3D-jupyter/blob/102bdbfde6058285439b589caef6a2f936e90986/k3d/objects.py#L1073

However, it does not show animation in my environment. The same approach worked for points, so I believe it is correct.

import k3d
import numpy as np

vertex = np.random.rand(4,3)
transforms = [np.array([
    np.cos(theta),-np.sin(theta),0,0, 
    np.sin(theta),np.cos(theta),0,0, 
    0,0,1,-theta, 0,0,0,1
]) for theta in np.linspace(0,1,100)]

plot = k3d.plot()

vectors = k3d.vectors(vertex[:2],vertex[2:]-vertex[:2])
vectors.model_matrix={'%.f'%(t/10):transforms[t] for t in range(len(transforms))}
plot += vectors

points = k3d.points(vertex,point_size=0.05) 
points.model_matrix={'%.f'%(t/10):transforms[t] for t in range(len(transforms))}
plot += points

plot.display()
plot.start_auto_play()

I appreciate it if you could help.

Best regards,

artur-trzesiok commented 3 years ago

@tfunatomi Thanks for a kind words. I see that description : "kwargs: dict. Dictionary arguments to configure transform and model_matrix." is misleading. I will refine it.

In K3D we have two groups of primitives.

Defined as absolute positions:

Defined in object space and positioned in global space via modelMatrix

So k3d.vectors dosen't support model_matrix nad thats why it isn't working. Instead of animating a model_matrix you can animatate origins and vectors attribute.

@marcinofulus @tgandor this should be a part of official documentation or we should add support to model_matrix to all kind of objects.

artur-trzesiok commented 3 years ago

I dive into topic. What I discovered:

already have support to additional transformation via model_matrix. So I added that also to:

So right now all k3d primitives has support to model_matrix.

so @tfunatomi thanks for that ovservation! Please look forward to next release of k3d

tfunatomi commented 3 years ago

@artur-trzesiok I appreciate your work!