I have text that changes every frame. I would like to find out if the text object is within the camera title safe and if the text is outside, scale it down so it fits the title safe. How do I do this?
My first guess is to use the bounding box of the text , and shoot a ray or something from the camera to tell whether it hits or not. I do not know how to do this in Blender which is why I’m posting here.
My second guess is to create a bounding box for the text that reaches the edges of the camera, and see if the text is INSIDE the bounding box.
I made the script, it adjusts to fit the text inside the box. I’m having issues with it not updating once the text has changed, I have to run the script twice to have the script notice the text size is larger than the box after it changed. is there a window.redraw() I need to call?
# get current frame and reference name based off of it.
box_main = bpy.data.scenes.objects[‘box_main’]
text_main = bpy.data.scenes.objects[‘text_main’]
print(“text main” ,text_main.dimensions ,“box_main” ,box_main.dimensions)
print(“in box?” , text_is_in_box(text_main, box_main))
if text_is_in_box(text_main, box_main) :
# render out stuff
def text_is_in_box(text_main, box_main):
#compare each of the components to make sure box is larger or equal to text
return text_main.dimensions.x == box_main.dimensions.x and
text_main.dimensions.y == box_main.dimensions.y and
text_main.dimensions.z == box_main.dimensions.z
def text_scale_to_box(text_main, box_main):
text_main.dimensions = text_main.dimensions *
frame = bpy.context.scene.frame_current
names = [“Robert”, “Freddyyyyyyyyyy” , “George”]
text.body = names[frame]
Here is the blend - frames 0,1,2 have different length strings associated with them. change the frame , run the script twice, see it update.
script.blend (474 KB)