lojjic / aframe-troika-text

An A-Frame component for rendering 3D text using troika-three-text
MIT License
72 stars 12 forks source link

bug report : unable to access bounding box data from an other component #38

Open arthurmougin opened 3 years ago

arthurmougin commented 3 years ago

Hi, i am trying to access bounding box for a layout script, but i can't read it (value always infinite). i made troika-text the dependency of my component without result. can you help me ?

lojjic commented 3 years ago

How are you attempting to access the bounding box?

arthurmougin commented 3 years ago

I added my component to the a-troika-text primitive. At update, the component store in a value the content of this.el.components["troika-text"]: If that value is not empty, It read the value.troikaTextMesh.geometry.bou'dingBox;

When the initial update happen, every variable when logging .min.x, .min.y.... Return infinity.

I bypassed the issue by testing on tick when they are no longer infinite before recalling update but I don't think it is a great practice.

Edit : I tried adding troika-text to the component depencies but it didnt change the problem

lojjic commented 3 years ago

Ah, I see. Text is processed asynchronously, so it's expected that the bounds are initially unknown. See "Handling Asynchronous Updates" here for more info on how to react to the layout completion: https://github.com/protectwise/troika/blob/master/packages/troika-three-text/README.md#handling-asynchronous-updates

Let me know if you have suggestions on how to make this easier to handle in the Aframe wrapper.

arthurmougin commented 3 years ago

I personally think that an event triggered when the text render would be great. For example, when the scene load, there is a "loaded" event

Edit : this would help me and other devs : we could then have a more cleaner implementation on our side then

lojjic commented 3 years ago

OK, I'll look into how AFrame does events and see if there's an appropriate common event type I can fire. "loaded" seems perhaps not quite the right event name since it would fire anytime the text is updated.

arthurmougin commented 3 years ago

Here is the reference if that can help you : https://aframe.io/docs/1.1.0/introduction/javascript-events-dom-apis.html#events-and-event-listeners