I am trying to display some text in the viewport. to do my tests I'm overriding the Draw method (objectdata plugin). Everything seems to work fine except two small things:
1- The text is not smooth : there is a slight aliasing on it.
2- The text is hidden under the bands that sourround the safe frame. for instance the default "Perspective" HUD text is visible even when you have 100% opaque bands.
def Draw(self, op, drawpass, bd, bh):
if drawpass == c4d.DRAWPASS_HIGHLIGHTS:
bd.DrawHUDText(2, 25, "Perspective")
did I forget something? Any suggestion will be helpful.
It may surprise you, but I simply used DrawHUDText(). No low-level trickery, no touching the safe frames. I draw in SCENEHOOKDRAW::HIGHLIGHT_PASS.
welcome to the forums and thank you for reaching out to us. Please make sure to read the Forum Guidlines, as your posting is missing critical information, which we require users to add in form of tags.
For your question:
def Draw(self, op, drawpass, bd, bh):
"""Draws text into the passed BaseDraw.
# If the current draw pass is not the highlight draw pass, we skip
# this call. We cannot draw over the safe frames with any of the draw
# passes as this would defeat the purpose of the safe frames of
# blocking stuff out.
if drawpass != c4d.DRAWPASS_HIGHLIGHTS:
# Drawing in screen space does not take account of the safe frames
# automatically, but we can get hold of them.
# Get the frame of the safe frame.
safeFrame = bd.GetSafeFrame()
# The left and top offsets of the safe frame.
cl, ct = safeFrame["cl"], safeFrame["ct"]
# Draw at the point (5, 5) in the safe frame.
bd.DrawHUDText(cl + 5, ct + 5, "Perspective")
First, thank you @ferdinand for your answer!
You cannot draw on top of safe frames inside NodeData.Draw....
By reading this part, should I understand that it's possible to achieve this by using a different plugin type (....a sceenhook plugin I guess) ? if so, how to do it ?
@kilou said in HUD Text issues:
This is exactly what I thought before until I saw a video of a plugin (Terraformx). The text was drawn on top of the safe frame (please check out the image below).
By reading this part, should I understand that it's possible to achieve this by using a different plugin type (....a sceenhook plugin I guess)? if so, how to do it?
First of all, the SceneHookData plugin interface has not been wrapped for Python and is only available in C++. I have not yet tried myself when a SceneHookData is executed in the drawing pipeline. But since SceneHookData is derived from NodeData, i.e., the same type ObjectData and TagData are derived from, I would doubt that its Draw method is treated much differently. I.e., I would assume it to be also drawn before the safe frames.
There are effectively two ways how I could see how Frank has done this:
PS: The author of Terraform is @fwilleke80, the author of the topic Draw HUD-like text to viewport I did reference above. For details on how he did accomplish exactly what he did, you could try to ask him.
Thank you @ferdinand! I appreciate the effort you put in your answers. very detailed and clear. Thank you again.
Thank you @fwilleke80 for your answer!
honestly, to be surprised, I'm surprised! seeing the video, I was pretty sure that DrawHUDText() method was used, but how did you manage to get this result ? (smooth text, visible above the safe frame!).. because when I used it, it was ...meh!
If I remember correctly, I decided to just not spend any more time on this issue, and rather keep the number of HUD elements low to avoid speed issues. Why the rest just works, I don’t know. Maybe it’s just the right drawpass for it.
thank you for jumping in and offering help. Good to know that SceneHookData can draw on top of everything, which makes sense, given the nature of scene hooks. For clarification for @kilou: The draw pass flags in SCENEHOOKDRAW are not available in in other implementations of Draw (ObjectData, TagData, ect.) and therefore not available in Python due to its lack of SceneHookData. If you are hellbent on doing it, I would recommend 'faking' it as lined out in my previous posting.
Oh! sorry @fwilleke80 I misread your first message.
@ferdinand, I think I got confused from the beginning. I made a copy of my code from an objectData plugin to a scenehook plugin without changing DRAWPASS to SCENEHOOKDRAW
Everything is working just fine now(... except the aliasing) but the result is acceptable.
Thanks to both of you!