How can I draw text in 3D within the draw method of a tool/overlay?

How can I draw text in 3D within the draw method of a tool/overlay?

The View #draw_text method is used to draw text on the screen, but only accepts Point3d object representing a 2D coordinate in view space as parameter. This text is always shown on “top” of other objects and always horizontal relative to screen. I haven’t found any way to move, rotate, twist …(transform) it into 3D space.

So I would like to draw a text such a way as e.g. you add dimension where the dimension’s text is aligned to the dimension, so this text it is located in 3D space. Like this:

entities = Sketchup.active_model.entities
dim = entities.add_dimension_linear([0, 0, 0], [50, 0, 0], [0, 20, 0])
dim.has_aligned_text = true
Click to see animation

3d_aligned text

Of course, I don’t want to create (add) a Drawingelement to the model, “just” an overlay text in 3D space specified point.

It’s would be possible, I guess, because in Curic Scale++ he can do it somehow.

I’m talking about the texts that the green arrows point to:

I’m curious, @curic4su, how? Did you make your own library that draws the text by lines/points using the View #draw method, or is there other method I missed? Or perhaps, do you draw a temporary dimension that you then delete?

Does anyone else have any ideas?

This is a different context - not a label as you are showing. But this ‘broken’ gizmo appears ‘detached’ at the origin, or centered on a selection. The testing labels are just x, y, z. They act like ‘face me’. Are you looking for something like this (but modified to your purpose)?

Broken axes with label

Just create a temporary 3D text at a given scale in flat mode. Then get all edges and faces. These gives you the plane points to draw lines in 2D at any given scale and position.

Not really. I would like to draw temporary text in overlay similar than the dimension text aligned to the dimension into a given 3D point and plane, so if it is rotated it looks skewed and the existing Drawing elements covers it and you don’t see it.

The issue is that I cant perform model changes from Overlay events, so I cant create temporary entities…
I like the idea, by the way. :slight_smile:
I had a similar idea, creating letters and numbers (characters) as png files and loading them as textures next to each other…in the right order, position and scale…But I feel this is too intensive “graphic activity” and String operation. Would be much better if the View #draw_text could handle “real” 3D points and not only screen coordinates…

Then, you can create all letters and digits (and extra signs) offline to build a library of their coordinates (possibly in various fonts / styles). Then, you assemble the text as a view.draw2d compatible directives at runtime.

The benefit of this approach is that you can draw your text in any direction, or even in perspective (for instance, as if it sticks to a face, using view.draw in 3D).

2 Likes

:+1:
Well, yes, that sounds good. It needs some effort, but it doesn’t sound like a terrible amount of work and can be “automated”… :slight_smile:

Hi Dezmo,

In Curic Scale++, I use a custom tool to draw 3D text within the draw method. I first convert a font file into geometric path data - either polylines or filled outlines. Then, a custom Ruby module handles text layout (spacing, alignment, transforms) and places each glyph in 3D space. Finally, I show the text using view.draw. This gives full control over position, rotation, and scale.

1 Like

view.draw_text is quick and handy, but drawing true 3D text like dimensions is way more fun! :grinning_face_with_smiling_eyes: Hope we get native API support for it someday.

1 Like

Thank you very much, Fredo and I came to a similar conclusion above. I’m slowly starting to get ideas developing my own “3Dtext overlay” methods…until:

:slight_smile: