How 2 Align script created text to a view programmatically

2.49b: I found a couple of scripts which when combined make and position a text object; what I’d like also is to programmatically orient the text to the view (camera). I did try setting “Edit Methods” (top hidden menu), to “Align to View”, but that didn’t have any effect with regard to the action of the script.

You can switch on billboard or halo for the faces of the mesh. Keep in mind the face must face along -Y.

Thanks Monster, but I’ll be adding elements of this script idea to a .stl import script, so I’d think setting operations outside the script might make problems for those items that are imported? (by orienting them differently than the importing would?)

That’s why I was wondering if I could do the aligning in the script itself.

(edit) Actually, now that I read a little about billboard, it sounds perfect, but I haven’t yet messed with properties, how might I set such a property as billboard in a script? (I’ll be googling it, but it’s quick to ask, may be easy to answer too?)

Yeah, you could. Here’s an example:


from bge import logic

import math

cont = logic.getCurrentController()
obj = cont.owner
sce = logic.getCurrentScene()
cam = sce.active_camera

ori = obj.orientation.to_euler()
ori.z = cam.orientation.to_euler().z + math.pi
obj.orientation = ori

That should work.

That sounds interesting, what’s euler, sounds like I should recognize it from math; it also sound like your method is also general enough to apply to any desired view, too? Though billboard, when I figure out how to set a propery, sounds easier, maybe?

It’s probably relevant to indicate that I won’t actually be moving the camera, other than perhaps zooming it in/out, as what I’m doing is a model viewer; the model itself will be rotated etc, unless that’s not a good way to proceed.

(edit) ahh, I find: get & setOrientation(), they’ll probably work, will give it a try.

Billboard method is easier, but if your camera never moves, then just put the text in an overlay scene, or parent the text to the camera in the game scene.

As for Eulers, a Euler is basically another way to express a 3D rotation - rather than using matrices, you can use a Euler. A Euler looks like this:

[x, y, z]

and each component is that much rotation (in radians, I believe) on the specified axis. By converting the text object’s orientation to a Euler and then setting its Z-component to the camera’s Z-component + pi (to do a complete 180), the text object would always rotate around to face the active camera (but not on the other axes).

That’s done in the game engine, right? How would I do that as a Blender script?

This is super late, but you would put that in a script and execute it with a Python controller.