OK, I have a texture which shows a circle given a uv co-ordinate (see code below) but I cannot figure out how to change this on mouse click (also see below). Any ideas there would be fantastic.
Thanks!
N
Sorry, but I can’t get this to work on jsfiddle or similar. Anyone got a good template for that?
So, here’s an image of what it looks like:
Here’s what I have for mouse click change. This basically does nothing. Doesn’t kill the scene but doesn’t change it either…
const handleClick =(e) =>
{
const intersects = e.intersections
const myCircledNode = Fn(() => {
const iSect = intersects[ 0 ]
const circleCentre = iSect.uv
const currentColors = pRef.current.material.colorNode;
console.log("CC:", currentColors)
const colorD = color("#1a9815");
const newCols = mix( colorD , mix('#005500','#FF0011', (positionLocal.z)).mul(0.06), step(0.05, distance(uv(),circleCentre)) )
return newCols;
})();
if ( intersects.length > 0 ) {
const newPos = intersects[ 0 ].point
newPos.y += 2.5
coneRef.current.position.copy( newPos);
pRef.current.material.colorNode = myCircledNode
}
}
And here’s the shader:
export const MyCircleNodeMaterial = (colorz, hitPos=vec2(0.4,0.4), circleSize=0.15) => {
const circleCentre = hitPos;
const insideCircle = distance(positionLocal.xy, circleCentre)
const { nodes } = useMemo( () => {
const colorA = uniform(color(colorz.colors[0]));
const colorB = uniform(color(colorz.colors[1]));
const colorD = uniform(color("#1a9815"));
const tDis = uniform( 0.9 );
const tAmb = uniform( 0.1 );
const tAtt = uniform( 0.1 );
const tPow = uniform( 1.0 );
const tSca = uniform( 2.0 );
console.log("canda", colorA)
console.log("Inside:", insideCircle)
return {
nodes: {
colorNode: mix( colorD , mix(colorA, colorB, (positionLocal.z)).mul(0.06), step(circleSize, distance(uv(),circleCentre)) ),
thicknessColorNode: vec3( 0.5, 0.3, 0.0 ) ,
thicknessDistortionNode: tDis,
thicknessAmbientNode: tAmb,
thicknessAttenuationNode:tAtt,
thicknessPowerNode:tPow,
thicknessScaleNode:tSca,
},
};
}, []);
return <meshSSSNodeMaterial {...nodes}
side={THREE.DoubleSide}
//vertexColors={true}
roughness ={ 0.3}
/>
};