Skip to content
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

Add ability to have custom pointer for useFluid #65

Closed
wants to merge 2 commits into from

Conversation

nhtoby311
Copy link

This PR adds the ability to have custom pointer coordinates to useFluid. Ideally, this could be used to have pointer position relative to the mesh UV coordinate, make it possible to apply useFluid effect to mesh material in the scene.

This is planned to solve this issue: #62

Copy link

vercel bot commented Jan 23, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
use-shader-fx ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 3, 2024 3:25pm
use-shader-fx-stories ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 3, 2024 3:25pm

@roku-ft
Copy link
Member

roku-ft commented Jan 24, 2024

Thank you for PR!
We'll review it. please wait for a while

@nhtoby311
Copy link
Author

After trying it out, I realize that I should send the custom pointer to the updateFx function instead, and also transform pointer value from UV coordinate [0,1] range to [-1,1] range to fit the initial viewport pointer approach.

However, I think this should be the default to use pointer position relative to UV coordinate of the mesh, instead of viewport coordinate, as it is more correct this way, even in default case of using the Fx as fullscreen quad shader.

Here is how it is use:

const refPointer = useRef(new Vector2(0, 0));
function handlePointerMove(e){
  refPointer.current = e.uv;
}

...
<mesh onPointerMove={handlePointerMove}>
...

useFrame((props) => {
  const fluid = updateFluid(props, undefined, refPointer.current);
});

@takuma-hmng8
Copy link
Member

@nhtoby311
Sorry for the late response: !!!!
I've been busy with my main project, so I haven't had a lot of time to work on it.

Now that my main work has settled down, I took the time to make some changes and made a minor update.
The repo and npm package URLs have also changed since this version.

It also reflects @nhtoby311's PR, so give it a try!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants