felixmariotto / three-mesh-ui

⏹ Make VR user interfaces for Three.js
https://felixmariotto.github.io/three-mesh-ui/#basic_setup
MIT License
1.31k stars 138 forks source link

Text change #202

Open Yeisonlop10 opened 2 years ago

Yeisonlop10 commented 2 years ago

Hi, thank you for the amazing work with this library. I would like to ask if there is any way to update the text that has been rendered inside a block. I'm trying to add a new text object and deleting the old one, but I'm getting specific error in the oculus quest 2 and sometimes in the regular browser while using the WebXR extension to simulate the oculus. It seems like at some point it loses a reference to the initial text that was rendered.

Ideally at some point in the code execution the user performs an action and I would like to change the already rendered text.For example:

swingingtom commented 2 years ago

Hello @Yeisonlop10, thanks for reporting. The behaviour you describe seems odd. Does this also happen to you on examples such as this one or keyboard?

Yeisonlop10 commented 2 years ago

Hi @swingingtom , for now I'm only experimenting with the regular text. I will try again by setting the text with: text.set( { content: 'new text' } ); Thanks for the hint with the provided example. 👍

swingingtom commented 2 years ago

You are welcome How did you changed the text content previously? Feel free to share your setup on codesandbox if you succeed to reproduce it.

Yeisonlop10 commented 2 years ago

Hi. It's for a bigger project that uses react. I see that in children components where we use threemesh ui, we have to call again the renderer.setAnimationLoop to update ThreeMeshUI.update even if in the parent component we are already running it. I see this error the second time I want a component to mount: Screen Shot 2022-05-12 at 12 27 24 PM

This error in VR session automatically causes crashing.

swingingtom commented 2 years ago

Im not fluent at all in react, but I managed to get some experiences with Vue.

The error, as you may already know, comes from the fact that a Text doesn't have a fontFamily attached. Text must be added to a parent Block. And usually this is the parent Block that have the fontFamily attached. Allowing other Text children to use the same fontFamily without the need to explicitely setting it.

Can you check that nothing "happend" to your font before mounting a second Text component ?

When you say:

the second time I want a component to mount:

Are we okay that you want to mount a second instance of that component? Or is a the same instance that you mount, dismount, mount ?

if you can provide a minimum reproduction setup codesandbox, I might be able to help you further. They are some starter template for three-mesh-ui and react (react-three-fiber) such as this one

swingingtom commented 2 years ago

@Yeisonlop10 Did you succeed some progress on this task ?