3

I know that I can use the blf module to draw 2d text, but is there a method to draw text at certain positions in 3d space?

I want to add a text right to a specific point in 3d.

Jayanam
  • 665
  • 3
  • 18
  • Do you mean on the 2D projection of a 3D location, as in, for example, the MeasureIt addon, or in full perspective? Or.. in perspective, but always facing the viewpoint? – Robin Betts Apr 23 '19 at 07:49
  • Thx, I found an example in the MeasureIt addon – Jayanam Apr 25 '19 at 08:56
  • @RobinBetts can set blf.rotation(..) (and aspect) to rotate text on screen. I remember fiddling with this and accidentally rotated all the GUI text too. (oops meant to comment under answer comment) – batFINGER Apr 25 '19 at 11:48

2 Answers2

3

Thx, I found an example in the MeasureIt addon and here is some code from my Fast Carve addon to draw 2d text:

rv3d = self._view_context.region_3d
region = self._view_context.region
pos_text = location_3d_to_region_2d(region, rv3d, self._center)

blf.position(2, pos_text[0], pos_text[1], 0)
blf.draw(2, "r: {0:.3f}".format(self._radius))
Jayanam
  • 665
  • 3
  • 18
0

This is a script that adds text at position x,y,z and the text says "my text"

import bpy
bpy.ops.object.text_add(location=(x,y,z))
ob=bpy.context.object
ob.data.body = "my text"
avatar
  • 325
  • 2
  • 3
  • 17