I made a copy and got it to work. I haven’t published it, so not sure if you can see it (probably not?) but the link is here (let me know if you need me to publish it).
https://beta.observablehq.com/d/ddc5ea52009214da
Here are the changes:
In the main ‘create’ cell I created a function which receives the thickness change as a parameter. You will call this function when the thickness changes, and this avoids reevaluating the whole cell - in general you want to avoid relying on dynamic values that are going to change in the main body of code in that cell, as it will cause the cell to reexecute - so instead we use a callback function to handle it.
function changeThickness(t) {
mesh.material.uniforms.thickness.value = t;
}
I also modified the return from this cell to return a dictionary instead of just the dom element (I borrowed this trick from John Bannister’s “planets” demo, so you can get a reference to the callback function.
return {'element':renderer.domElement, 'changeThickness':changeThickness};
This means you have to add a separate block to display the actual element, since you’re returning a dictionary instead of a dom element.
create.element
Then I added a slider (using the slider import at the bottom)
// import
import {slider} from "@jashkenas/inputs"
// slider
viewof thickness = slider({min: 0.01, max: .3, value: .1, description: "Thickness"})
And I added a cell to call the callback function when the slider is moved (would be cool if this were a parameter to the slider, hmmm…)
create.changeThickness(thickness)
Note that this shows up as ‘undefined’. To make it look a little nicer, you can have it redisplay the thickness, like so:
{ create.changeThickenss(thickness); return thickness; }
Also note that I’m using identical shenanigans to get the slider to work on my sphere demo, here:
https://beta.observablehq.com/@jbum/covering-a-sphere-with-near-equidistant-dots\
I suspect there is a more elegant way to do this, perhaps by breaking up the cell with most of the code into separate cells. I’ll play around with it…