3dmol / 3Dmol.js

WebGL accelerated JavaScript molecular graphics library
Other
770 stars 190 forks source link

setSurfaceMaterialStyle also for isoSurfaces #600

Closed duerrsimon closed 2 years ago

duerrsimon commented 2 years ago

I want to dynamically change an isosurface but it seems that there is no equivalent of setSurfaceMaterialStyle(surf, style) for isosurfaces.

I currently delete and readd the isosurface using the following command

let voldata = null;
let shape = null;
voldata = new $3Dmol.VolumeData(cubefile, "cube");
shape = viewer.addIsosurface(voldata, { isoval: 0.5 , color: "blue", alpha: 0.85, smoothness: 1 });

I modify the isovalue using:

$("#rangeslider").rangeslider().on("change", function (el) {
                isoval = parseFloat(el.target.value);
                $("#isovalue").text(el.target.value)
                viewer.removeShape(shape)
                shape=viewer.addIsosurface(voldata, { isoval: parseFloat(el.target.value), color: "blue", alpha: 0.85, smoothness: 1 });
                viewer.render();
            });
dkoes commented 2 years ago

Shapes have an updateStyle method: https://3dmol.org/doc/$3Dmol.GLShape.html#updateStyle You can use this to change the color etc, but any change to the actual geometry requires creating a new surface. Example: https://3dmol.org/tests/auto/generate_test.cgi?test=updateiso