We currently have support for creating, manipulating, and fetching various attributes of 2D text elements in our application, but there is a need to further extend this functionality. Specifically, we need to enable users to:
Set and get the 3D position of a text element in the world space.
Attach a text element to an ObjectReference, optionally specifying a node (e.g., head node) and a 3D offset from the specified node.
This API, when will be used, will help our client survive in case of 100-1000 objects/players with nicknmaes without significant performance loss. The main thing is that we move texts draw logic from JavaScript to C++
Implementation Details:
This requires the addition of the following methods:
There are several considerations and potential corner cases that should be kept in mind:
For attaching a text to a node, we need to handle cases where the specified node doesn't exist or is not valid. A graceful error message should be provided in such cases.
The 3D offset should default to [0,0,0] if not provided.
We need to handle the situation where the ObjectReference does not exist or is no longer valid: text should become invisible but still being in "attached" state, still not destroyed (??) (I'm not sure, we can discuss that later).(The object is no longer valid if LookupFormById(refrId) != refr. So it's now nullptr OR changed.)
If a text element is attached to an ObjectReference and the object moves, the text should update its position accordingly.
If a text is attached to an object and the text's position is manually set afterward, the attachment should be broken to avoid inconsistencies.
The text with 3D pos set should be visible only if Z-coordinate on the screen is >= 0
The text attached to ObjectReference should be visible only Z-coordinate on the screen is >= 0 AND HasLos(objectReference) == true
If (localPlayerPos - text pos).Length() > drawDistance, text should not be visible
Documentation:
All new functions should be fully documented. Also, usage examples should be provided. + changelog
Description:
We currently have support for creating, manipulating, and fetching various attributes of 2D text elements in our application, but there is a need to further extend this functionality. Specifically, we need to enable users to:
Set and get the 3D position of a text element in the world space. Attach a text element to an ObjectReference, optionally specifying a node (e.g., head node) and a 3D offset from the specified node.
This API, when will be used, will help our client survive in case of 100-1000 objects/players with nicknmaes without significant performance loss. The main thing is that we move texts draw logic from JavaScript to C++
Implementation Details:
This requires the addition of the following methods:
Corner Cases:
There are several considerations and potential corner cases that should be kept in mind:
For attaching a text to a node, we need to handle cases where the specified node doesn't exist or is not valid. A graceful error message should be provided in such cases.
The 3D offset should default to [0,0,0] if not provided.
We need to handle the situation where the ObjectReference does not exist or is no longer valid: text should become invisible but still being in "attached" state, still not destroyed (??) (I'm not sure, we can discuss that later). (The object is no longer valid if LookupFormById(refrId) != refr. So it's now nullptr OR changed.)
If a text element is attached to an ObjectReference and the object moves, the text should update its position accordingly.
If a text is attached to an object and the text's position is manually set afterward, the attachment should be broken to avoid inconsistencies.
The text with 3D pos set should be visible only if Z-coordinate on the screen is >= 0
The text attached to ObjectReference should be visible only Z-coordinate on the screen is >= 0 AND HasLos(objectReference) == true
If (localPlayerPos - text pos).Length() > drawDistance, text should not be visible
Documentation:
All new functions should be fully documented. Also, usage examples should be provided. + changelog
depends on #1503
See also
https://github.com/skyrim-multiplayer/skymp/blob/82e4d2fc5c4d3601036bd7686f56932260a0cd1a/skymp5-client/src/view/formView.ts#L390C56-L390C56