Skip to content
Discussion options

You must be logged in to vote

You wouldn't post a message 60 times a second in a useFrame. The onmessage handler would likely be in a useEffect. Neither postMessage or onmessage should ever be in a useFrame.

Think about it this way. useFrame fires are 60 fps. Do I need to assign a new handler every frame? No. I just need to assign a handler once and then wait for the result.

useEffect(() => {
  calculateWorker.postMessage("calculatePlease");
  calculateWorker.onmessage = ([x, y, z]) => {
    meshRef.current.position.set(x, y, z);
    meshRef.geometry.attributes.position.needsUpdate = true; // some variation of this
  };
}, [])

I believe that should work without useFrame at all. However, you should look into useUpdate.…

Replies: 3 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@antran22
Comment options

Comment options

You must be logged in to vote
1 reply
@drcmda
Comment options

Answer selected by antran22
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants