PDA

View Full Version : Help with text in viewport is needed


Phaeton
05-13-2008, 02:11 PM
Hello, respective community.. Recently i started to learn maxscript and encountered following problem: i made script which switches (on/off) state of the lights depending on "ambient only" checkbox i.e. we have few lights in the scene, some are ambient and some aren`t. I need to switch ones off while others are on. My script is working just well but i wanted to implement it with displaying which lights are currently on, "ambient" or "normal". The problem itself is in not displaying text with such code :



gw.setTransform (Matrix3 1)
gw.Text [10,10,0] "some text" color:green
strRect = (Box2 50 50 50 50)
gw.enlargeUpdateRect strRect
gw.updateScreen()



Also I very appreciate if you place some critics and advices for the whole code


macroScript SwitchLights
category:"myScripts"
toolTip:""

(
local LightningState = ""
for l in lights do
(
if l.baseobject.ambientOnly == true then
(
if l.baseobject.Enabled == true then
(
for n in lights do
(
if n.baseobject.ambientOnly == false and n.baseobject.Enabled == false then
n.baseobject.Enabled = true; l.baseObject.Enabled = false
)
)
else if l.baseobject.Enabled == false do
(
for n in lights do
(
if n.baseobject.ambientOnly == false and n.baseobject.Enabled == true then
n.baseobject.Enabled = false; l.baseObject.Enabled = true
if l.baseobject.Enabled == true then LightningState = "ambient lightning"
if n.baseObject.Enabled == true then LightningState = "normal lightning"
)
)

)
)
gw.setTransform (Matrix3 1)
gw.Text [10,10,0] LightningState color:green
strRect = (Box2 50 50 50 50)
gw.enlargeUpdateRect strRect
gw.updateScreen()


)



P.S. Sorry for my English - it`s not my native language.
P.P.S. Oh, yes, I`ve read other threads relative to my problem, but didn`t understood, why my text isn`t working...

Bobo
05-13-2008, 02:59 PM
In recent versions of Max (well, in the last 4, at least), viewport text display in world space has severe issues in DirectX mode. It might work in SZB and OpenGL mode, but we all want to use DirectX after all, it is the fastest mode.

It looks like text display in screen coordinates does not have the same issues, so a possible workaround would be to convert the world space position into screen space (see the "How To ... Develop a Vertex Renderer" tutorial in MAXScript Help for the actual code) and then draw the text in 2D screen coordinates instead.

EricDLegare
05-13-2008, 04:40 PM
(see the "How To ... Develop a Vertex Renderer" tutorial in MAXScript Help for the actual code)

Woah, thats cool :cool:

Phaeton
05-13-2008, 04:48 PM
Wow!! Borislav Petrov himself answered me, I`m very very pleased. Man i decided to try scripting after watching your tutorials of CG Acadamy, you are the best hellish scripter ever :bowdown: :buttrock:
About my script.. In search of solution i`ve tried this (http://forums.cgsociety.org/showthread.php?f=98&t=628614) script and it worked sometimes.. But when i used part of the code where text is creating itself it does nothing in my case ((..
And I`ll surely follow you advice and see what i can do. Thank you!

edited..
Just in case.. i used max 9

Bobo
05-13-2008, 05:07 PM
Woah, thats cool :cool:

Well, it is not Krakatoa, but with a couple of objects, it tends to run in real time!

Bobo
05-13-2008, 05:35 PM
Wow!! Borislav Petrov himself answered me, I`m very very pleased. Man i decided to try scripting after watching your tutorials of CG Acadamy, you are the best

edited..
Just in case.. i used max 9

Thanks for the flowers!

(
fn mapWorldToScreen thePoint =
(
local thePos = thePoint * viewport.getTM()
local screenSize = getViewSize()
local screen_origin = mapScreenToView [0,0] (thePos.z) screenSize
local end_screen = mapScreenToView screenSize (thePos.z) screenSize
local world_size = screen_origin-end_screen
local x_aspect = screenSize.x/(abs world_size.x)
local y_aspect = screenSize.y/(abs world_size.y)
point3 (x_aspect*(thePos.x-screen_origin.x)) (-(y_aspect*(thePos.y-screen_origin.y))) 0
)

for theObj in selection do
(
gw.setTransform (matrix3 1)
gw.wText (mapWorldToScreen theObj.pos) theObj.name color:green
)
gw.enlargeUpdateRect #whole
gw.updateScreen()
)

This works with Max 9.
Select a couple of objects and evaluate to see if it works for you too...

Phaeton
05-13-2008, 05:54 PM
it works well for max 9 and 2008 too.
Thank you very much

Phaeton
05-13-2008, 06:47 PM
It seems like problem was not in the drawing methods, but somewhere else in my code. When I run Bobo`s script it works perfectly, but if i paste it into my, it becomes dead ond do nothing at all. Please somebody explain to stupid me where i have to paste working code and why there

Sigmao
05-14-2008, 12:53 PM
Hi Phaeton, try using:
Gw.EnlargeUpdateRect #whole

Phaeton
05-15-2008, 06:43 AM
this string already in the code but it doesn`t work in my script.. Please check my first post and tell me, where i have to paste Bobo`s code for it to work properly. It seems like i missed right place or something else

Bobo
05-15-2008, 04:42 PM
this string already in the code but it doesn`t work in my script.. Please check my first post and tell me, where i have to paste Bobo`s code for it to work properly. It seems like i missed right place or something else

Keep in mind that the viewport can update after the drawing and your update and clear all the text you wrote. So it is not very persistent, and it is possible that calling it in a macroScript is doing just that - drawing and redrawing after it. Will have to take a closer look.

You can put the code into a function and register it as a redraw callback so it gets updated constantly. (but will be flashing a bit)

CGTalk Moderation
05-15-2008, 04:42 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.