[Closed] ScriptedManipulator – addGizmoText
Hi
I would like use scripted manipulators in my script but i have got problem with display test text in viewport and i don’t have idea what i do wrong or if i missing some part of code which is necessary for make my text visible. I just would like print some text in center of a box. Can anybody give me a help with this. Thanks.
plugin simpleManipulator TestManip
name:"TestManip"
invisible:false
(
local g = [0, 1, 0], r = [1, 0, 0]
on canManipulate target return classOf target == box
on updateGizmos do
(
this.clearGizmos()
this.addGizmoText "TestText" [0,0,0] 1 g r
)
)
manipulatemode=true
Hi, the problem is the optional flag you set to 1.
change
this.addGizmoText "TestText" [0,0,0] 1 g r
with
this.addGizmoText "TestText" [0,0,0] 0 g r
It will work. You can use and compose flags like this:
this.addGizmoText "TestText" [100,100,0] (gizmoUseScreenSpace + gizmoActiveViewportOnly) g r
- Enrico
Thanks Enrico for your reply and help. I tried change flags before just like number constant but without success. But your second trick work little better so i try find way how i can transfer this to 3d because i think it is just now count in 2d screen. So if anybody else wants show me another trick i will be thankful.
Hi, if you want text in 3D space, relative to local object coordinate system, just put a 0 (zero) in place of flags. If you put 1 it doesn’t work. First solution was what you want.
- Enrico
You need to assign the text to the “target” and not to “this”.
on updateGizmos do
(
this.clearGizmos()
if isValidObj target do
(
target.addGizmoText “TestText” [0,0,0] 1 g r
)
A manipulator needs to know what it’s going to be manipulating, that’s why you assign to target.
-Johan
Johan, that is not needed, as “this” in a simple manipulator plugin points to “target”, they’re the same. His code works fine on my machine setting 0 as flag value. I read somewhere manipulators text in 3D can have issues on some video cards, and is better to use it always in screen space because is more safe. If that’s his case, he needs to use gw.transPoint to get 3D coords to 2D screen space.
Take into account text in manipulators is clipped by viewport too. It must be entirely visible or is not displayed at all.
- Enrico
Thanks guys. Unfortunately it is how Enrico wrote. My problem is hardware not in script. I just try swap from direct to opengl and it works:\ It is really annoying find problem like this. I spent 2 days with looking what is wrong with my script, but once again thanks for solution. Funny is every others scripted manipulators work OK just GizmoText doesn’t work. So i will try trick with gw but i afraid that will be for me another challenge.
I was wrong. “this” points to the simple manipulator, while “target” seems to point to the class of the node. Anyway “this” is correct for addGizmoText.
Here is a sample of the workaround for the text in screen space. It’s not perfect because the gizmo doesn’t update by itself when the viewport is modified, like by pan or zoom. To make it happen it is forced by setting “node.transform = node.transform”. I’t not perfect, but works.
simpleManipulator TestManip
name:"TestManip"
invisible:true
(
local g = [0, 1, 0], r = [1, 0, 0]
on canManipulate target return ((classOf target) == Box)
on updateGizmos do
(
this.clearGizmos()
gw.setTransform (Matrix3 1)
local p3TargetScreenPos = gw.transPoint node.position
this.addGizmoText "TestText" p3TargetScreenPos (gizmoUseScreenSpace + gizmoActiveViewportOnly) g r
-- hack to force the gizmo update
node.transform = node.transform
)
)
manipulatemode = true
- Enrico
Yes works fine . I think i can live with this and try use it like tutorial for my next work or i can buy new graphic card Cheer guys
I thought it was the other way around, I could be wrong, have to check it when I’m behind max next time.
-Johan
GizmoText is BROKEN in World Space, at least in DirectX, but should work in Screen Space on all hardware. Thus, I suggest using screen space for all cases and simply perform the world-to-screen calculation yourself.
See my 2008 Master Class for the function.