nglviewer / ngl

WebGL protein viewer
http://nglviewer.org/ngl/
MIT License
665 stars 169 forks source link

setParameters on shape component #376

Open giagitom opened 7 years ago

giagitom commented 7 years ago

Hi, I have two questions about shape components.

I have a shape component with a cylinder and a label. Is it possible to alter the color and the size of both objects in the shape component without disposing and rebuilding entirely (like using a setParameter method)?

And is it possible to keep the label in front of the cylinder like a distance representation?

arose commented 7 years ago

I have a shape component with a cylinder and a label. Is it possible to alter the color and the size of both objects in the shape component without disposing and rebuilding entirely (like using a setParameter method)?

No, not possible. If you have a large number of cylinders and labels it is good to create CylinderBuffer and TextBuffer objects instead of shape.addCylinder and shape.addLabel, plus you can change the color and size of the buffer objects without disposing and rebuilding. See this example https://codepen.io/arose/pen/qXgxap?editors=0010.

And is it possible to keep the label in front of the cylinder like a distance representation?

Yes, using the zOffset parameter http://nglviewer.org/ngldev/api/typedef/index.html#static-typedef-TextBufferParameters, for shape.addLabel set it when instantiating new Shape({labelParams: {zOffset: 5}})

giagitom commented 7 years ago

Great solution, only one thing. In my example hear I tried to alter the length of a cylinder created before and at the same time tried to add two other cylinders. I noticed that the dimension of the first cylinder was changed but the other cylinders did not appeared. Is it possible that the new buffers length is not updated?

arose commented 7 years ago

At the moment it is not possible to alter the size of buffers, you will need to re-create them. There is some exception for mesh-buffer (which makes changing the isosurface threshold so fast) but I haven't generalized that. Eventually it will be possible.

lenhsherr commented 7 years ago

Is there anyway to alter the opacity of a buffer?

arose commented 7 years ago

keep a reference to the buffer and then do buffer.setParameters({opacity: 0.5})

garboit commented 2 years ago

Is it possible to add a tooltip/hover text to buffers the way it is done with shapes?