Upgrading to the latest Babylon 5.2.0

Hello everyone,

Haven’t been here in a while, work keeps me busy. But glad to be back with another question.
On our Babylon project we’ve decided it’s time to upgrade to the latest version (4.2.0 => 5.2.0).

There are two breaking changes that don’t seem to be mentioned in the major updates and changes lists for the releases:

  • Property ‘textBaseline’ does not exist on type ‘ICanvasRenderingContext’. It seems to have been removed in this (old) commit. We use it in the code as follows:
const dynamicTexture = new DynamicTexture(...)
const context = dynamicTexture.getContext()
context.textBaseline = 'hanging' 
  • Properties ‘actualBoundingBoxAscent’ and ‘actualBoundingBoxDescent’ do not exist on type ‘ITextMetrics’. We use it as:
const textMetrics = dynamicTexture.getContext().measureText(text)
const textHeight = Math.abs(textMetrics.actualBoundingBoxAscent) + 
      Math.abs(textMetrics.actualBoundingBoxDescent)

What are our alternatives to using these now?

Please let me know if more info is needed.
Thank you,
Anton.

Hum , let me check with @Cedric if this was related to Babylon Native support

(in the meantime you can cast it to any)

1 Like

We can maybe restore it as Nullable?

I see, now that I cast value returned by measureText() as any actualBoundingBoxAscent and actualBoundingBoxDescent refer to the readonly properties of the TextMetrics interface in typescript’s lib.dom.d.ts.
textBaseline seems to be referring to the property textBaseline of the CanvasTextDrawingStyles interface there as well.

Yes, these are missing properties when doing refactor and abstraction for native.
I’ll do a PR to add them in the interface class.

2 Likes