hifi: #21323 Fixes and extensions for text entities, text3d overlays and text overlays

Text entities are missing some features of text3d overlays and text overlays.

It would be good to bring the two API's and JSON property specs into alignment, so it's easy to switch between them without changing code, and the implementations share as much code as possible.

Most importantly, there is not a way to measure the size of a text entity, like Overlays.textSize(overlayID, "text").

Also text entities don't have explicit left/right/top/bottom margins like overlay text3d's.

Additionally some of the key names (and their behaviors) are needlessly different (text3d overlay isFacingAvatar, text entity faceCamera).

Billboarding works differently between text3d overlays and text entities, and it could be more flexible (supporting both different behaviors and more).

Summary of differences:

text entity:
No margins (actually margins are fixed to 0.1 * lineHeight).
No way to measure text.
Has faceCamera flag to rotate around the y-axis (yaw) to face the camera, but does not pitch or roll.
Breaks text (split on space) and wraps words to width of entity dimensions.
Uses TextRenderer3D and Font to render text in 3D world.

text3d overlay:
Has leftMargin, rightMargin, topMargin, bottomMargin, but not margin.
Measures text with Overlays.textSize.
Does not wrap words, but supports multiple lines with newlines.
Uses TextRenderer3D and Font to render text in 3D world.
Has drawInFront flag to behave like overlay.

text overlay:
Has margin, leftMargin, topMargin, but not rightMargin, bottomMargin
Measures text with Overlays.textSize, but assumed text pixel size and line height is 18 points.
Does not wrap words, but supports multiple lines with newlines.
Uses qml text component from TextOverlay.qml to render text in the HUD.
Takes font parameter that is dictionary containing only size key to set point size.

Suggested changes:

Implement leftMargin, rightMargin, topMargin, bottomMargin on all types of text. Also maybe a shortcut margin to set all of them.

Implement a uniform way of measuring text for both entities and overlays, either wrapped to the width (and clipped to the height) of the container, or passing an explicit width to wrap it against (so you don't have to size it wide, measure, then size it again correctly.

Add an additional optional parameter to Overlay.textSize to specify the width, defaulting to zero, which means use the container's width.

Overlays.textSize(entityID, "text", width=0)

Entities.textSize(entityID, "text", width=0)

Make billboarding more consistent and flexible.
Text entities only rotate around the Y axis. text3d overlays rotate around the X and Z axis.
It would be useful in VR to even rotate the text around the Z axis (matching the camera orientation), so text would tilt when you tilted your head, so you could still read it.

We need a way to specify which axes to rotate around to face the camera.

We should think through and work out what the correct order of rotations should be, to cover the practical use cases.

The billboarding configuration could use an enumerated type (which could support any combinations and orderings of axes):
enum RotateAround: None, X, Y, Z, XY, YX, XZ, ZX, YZ, ZY, XYZ, XZY, YZX, YXZ, ZXY, XYZ

Or three boolean flags one for each axis (in which the order of the axes is implicit):
flags: bool rotateAroundX, bool rotateAroundY, bool rotateAroundZ

Also note that raycasting should take billboarding rotation into account. I don't know if that works correctly right now.

Comments & Activity

Labels Saved!


Login to bid
Who Amount Done in ...
*name hidden*$ ***8 hrs