-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
UV projection of pointerValues
for FX is wrong
#84
Comments
@nhtoby311 If so, please refer to the following! const updatePointer = usePointer();
const raycaster = useMemo(() => new THREE.Raycaster(), []);
const rayCursor = useRef<THREE.Vector2 | null>(null);
useFrame((props) => {
updateFluid(props);
raycaster.setFromCamera(props.pointer, camera); // This camera must be the same scene camera as the object you want to target the raycaster
const intersects = raycaster.intersectObject(mesh); // Here the target object 3D
if (intersects.length > 0) {
const uv = intersects[0]?.uv as THREE.Vector2; //
if (!uv) return;
rayCursor.current = uv.multiplyScalar(2).subScalar(1); // Depending on how you set the uv value of attribute, the default uv of THREE is 0 to 1.
}
if (rayCursor.current) {
mesh.material.uniforms.uFx.value = updateFluid(props, {
pointerValues: updatePointer(rayCursor.current), // pointer requires vec2 normalized to -1~1
});
}
}); |
Yes, I use I see, so const refPointer = useRef(new Vector2(0, 0));
const handlePointerMove = (e: any) => {
//This value returns the correct current UV at pointer position.
refPointer.current = e.uv;
};
useFrame((props) => {
const actualValue = refPointer.current.multiplyScalar(2).subScalar(1);
const fluid = updateFluid(props, {
pointerValues: updatePointer(actualValue),
});
const fx = updateBlending(props, {
map: fluid,
alphaMap: false,
});
materialRef.current!.material.uniforms.u_fx.value = fx;
});
...
<primitive
onPointerMove={handlePointerMove}
rotation-x={-Math.PI / 2}
position={[0, -5, 0]}
/> broken-pointerValues.mp4 |
It seems const handlePointerMove = (e: any) => {
refPointer.current = e.uv.multiplyScalar(2).subScalar(1);
};
useFrame((props) => {
const fluid = updateFluid(props, {
pointerValues: updatePointer(refPointer.current),
});
const fx = updateBlending(props, {
map: fluid,
alphaMap: false,
});
materialRef.current!.material.uniforms.u_fx.value = fx;
}); |
@nhtoby311 |
Following this setup to assign custom pointer values to FX hooks (Ex:
useFluid
) results in a wrong UV projection, as while pointer value goes from 0 -> 1, the effects display from 0.5 -> 1 on the UV instead.2024-03-04.20-52-56.mp4
If I use my custom code for
useFluid
that I created in this PR #65, it works well like below:2024-03-04.20-58-43.mp4
The text was updated successfully, but these errors were encountered: