Closed dan-fritchman closed 1 year ago
Sorry for the delay. This is not ideal behavior, but it is currently accepted. To elaborate:
When you instantiate Two.js with autostart: true
, what happens is that an animation loop (an interval function gets set to call multiple times a second) is initiated. This loop starts on the frame after all the code written subsequent to the initialize and in the same scope.
So, in this case the update to render hasn't fired when you call getBoundingClientRect
and certain transform values haven't been set yet. You can get around this by ensuring the application is "up-to-date" when you call certain functions:
// ...
g2.add(text);
two.update(); // This forces an update to be called and rendered
const bbox = text.getBoundingClientRect(false);
// ...
Works here, thanks!
Fiddle: https://jsfiddle.net/danfritchman/q9sdxzr8/1/
Produces this:
Uncomment the calls to
getBoundingClientRect
on either groupg
org2
andrect
shows up around the boundary oftext
.Is that the expected behavior?