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
react-spring animations with react-three-fiber are choppy when using frameloop="demand" #1707
Comments
|
It's a complicated issue, rs under VR needs to be ran by r3f, so when you set the frameLoop to demand, and you're not calling that invalidate function then it won't run either. We do this because of this #1518 Where r3f can run in non-brower ENVs. There's probably a solution to this that would resolve the issue, but i'd argue the docs are a little inaccurate. |
|
So, to add. Your assumption is that despite you declaring |
Yes, that's what I would expect after reading the docs, that react spring animations have the invalidate function built in. But I see your point. |
|
Those docs should probably be changed. I think to resolve this we need to understand how people use invalidate and demand in their apps. Including those using VR. Do you have an example to hand how you're using it in your app? |
|
Sure, right now I'm using it in a super basic way. I have a model that can be rotated around with OrbitControls (from So the basic setup is: And then, inside the Model component I have components like: So, in my app, unless the model is being actively rotated or hovered over, it is basically static and doesn't need to be rendering at 60 fps and firing up the fans on my computer, which is why I prefer the use I'm not so familiar with how to manually call the invalidate function as needed, so maybe that would be an easy solution in my simple scenario, but it does seem like having react spring do this behind the scenes would be convenient, at least in my case. |
|
In the docs section for frameloop="demand", it says
Which I take to mean react-three-fiber is calling invalidate for me, but from this thread I take it that's incorrect? What does that phrase in the docs mean? React-spring doesn't seem to have a way for me to manually call invalidate when it moves, so I think I'm not able to use manual frames. |
|
Those docs are incorrect, I'm not sure who wrote them. But r3f runs spring so you can use it in XR environments. It's a problem we're wanting to solve. |
|
I'm running into this issue as well. Here's a simple workaround: const { invalidate } = useThree();
const anim = useSpring({
// ...
onChange: () => invalidate(),
});
This is reasonably - to be fair I was surprised to find that react spring automatically invalidate the R3F loop. I wouldn't expect it to. However, the docs do need to be updated if this is incorrect. |
|
Thanks @looeee
I believe someone submitted a PR for this yesterday. Thanks for the pointer as well. To anyone interested i've updated this sandbox with the workaround – https://codesandbox.io/s/react-spring-animations-forked-tmnpk?file=/src/index.js I also think this might be the best solution as we ootb support XR and WebGL three.js renderers, and if someone wants to go down the manual route then they need to take it upon themselves to call the invalidate function (which can be seen either coming from |
pmndrs#1707) * Fix: ResponsiveSwarmPlotCanvas does not work with valueScale type time * Update packages/swarmplot/src/SwarmPlotCanvas.tsx Co-authored-by: therightstuff <adam@industrialcuriosity.com> * Update packages/swarmplot/src/SwarmPlotCanvas.tsx Co-authored-by: therightstuff <adam@industrialcuriosity.com> Co-authored-by: Raphaël Benitte <501642+plouc@users.noreply.github.com> Co-authored-by: therightstuff <adam@industrialcuriosity.com>
Unfortunately it seems |
|
Whilst I understand there is still an issue with three & web targets not playing nicely together, I'm going to close this issue in favour of #1586. My view still stands if you want to use |
🐛 Bug Report
Continuing from this thread in the
@react-three/fiberGH discussions. When usingreact-springanimations in a@react-three/fiberscene, adding theframeloop="demand"prop to the canvas (to boost performance with on-demand rendering) causes animations to become very choppy or sometimes not run at all. This is contrary to the expected behavior described in the r3f docs, which say thatreact-springshould automatically invalidate the frame loop at every frame of the animation, triggering the animation to render.This issue seems to have started with something that changed in version 9.2.2. Changing the dependency to v9.2.1 fixes the issue.
To Reproduce
@react-spring/three.frameloop=demandprop to the<Canvas>elementExpected behavior
Smooth animation, as described in the react three fiber docs.
Link to repro (highly encouraged)
Forked a demo from the react three fiber website and added
frameloop=demand. The demo should animate when the ball is clicked. Animation is smooth when theframeloop=demandprop is removed.Environment
react-springv9.2.4reactv17.02@react-three/fiberv7.06The text was updated successfully, but these errors were encountered: