Page 1 of 1

accessing color in scripts question

Posted: 04 Dec 2017, 20:17
by rray
Hi,

Can't figure this out. When accessing a color parameter in shader, I get strangely repeating values:

e.g. my shader has red diffuse and grey ambient, so for example myPhong.diffuse red=1.0 and myPhong.ambient.red=0.5

and now..
LogMessage(myPhong.diffuse red+","+myPhong.ambient.red)

will log 1.0, 1.0 instead of 1.0, 0.5

which is weird.

When I use GetValue with the string names of the parameter apparently it works correctly but I still wonder what I'm doing wrong

Cheers

Re: accessing color in scripts question

Posted: 06 Dec 2017, 08:22
by myara
I think I've always used NestedObjects or Parameters : myPhong.ambient.parameters('red') So I've never run into this problem but I've just tried what you said and effectively, it seems that the variable gets overwritten to whatever you got first.

If I do :

- Diffuse First
LogMessage (myPhong.diffuse.red)
LogMessage (myPhong.ambient.red)

Will log both diffuse.red.
If I do the opposite:

- Ambient First
LogMessage (myPhong.ambient.red)
LogMessage (myPhong.diffuse.red)

Will log both ambient.

- NestedObjects parameters
LogMessage (myPhong.diffuse.parameters('red'))
LogMessage (myPhong.ambient.parameters('red'))
LogMessage (myPhong.diffuse.NestedObjects('red'))
LogMessage (myPhong.ambient.NestedObjects('red'))

This works fine.

Curiously, if you change one of them to capital letters, it will also work

LogMessage (myPhong.ambient.red)
LogMessage (myPhong.diffuse.Red)

RED, or reD would also work.

Re: accessing color in scripts question

Posted: 06 Dec 2017, 11:40
by rray
Thanks for your inquiries. Didn't even know about the parameters("name") syntax, I'll use that from now on. The other syntax looks like it has a bug, maybe an optimization that went wrong.

Re: accessing color in scripts question

Posted: 06 Dec 2017, 15:11
by Daniel Brassard
Properties and Parameters using the object model as explained here

http://download.autodesk.com/global/doc ... forNovices

set oAmbientRed = myPhong.Properties("ambient").Parameters("Red")
logmessage (oAmbientRed.Value)

Your original problem does not work because your are not asking the value of the parameter "Red"

Try this:

LogMessage(myPhong.Diffuse.Red.Value+","+myPhong.Ambient.Red.Value)

Re: accessing color in scripts question

Posted: 06 Dec 2017, 15:16
by myara
That's the bug, that doesn't work, it only gives you the value of the first one. Try it

It does work with parameters or nestedobjects, but not directly

Re: accessing color in scripts question

Posted: 06 Dec 2017, 16:35
by Daniel Brassard
VBScript is case insensitive so red, Red and reD are the same variable in vbscript

JScript and C# in the other hand are case sensitive so red, Red and reD would be three different variables. This is also true for Python, C and C++.

When you use GetValue your are actually asking the current "Value" of the parameter

So the question is what XSI returning when asking for

LogMessage (myPhong.diffuse.red)
LogMessage (myPhong.ambient.red)

Is it returning the default value, index of the parameter, true/false or a value set elsewhere?

http://download.autodesk.com/global/doc ... r.Red.html

Re: accessing color in scripts question

Posted: 06 Dec 2017, 17:27
by rray
myPhong.diffuse.red is the parameter object, not the value. I meant to add the .value in the orig question but typed too quickly :)

When you log a parameter object, the parameter name is printed which is "myPhong.diffuse.red". The bug happens when you do the second log message with ambient. This prints "myPhong.diffuse.red" instead of what it should print ("myPhong.ambient.red")

Similarly when ".value" is added then "logmessage(myPhong.ambient.red.value)" prints the value of myPhong.diffuse.red instead if you accessed ...diffuse.red before. Some caching bug probably where xsi looks at "red" only.

So as Martin found you can work around by using a different case for some letters (it doesn't seem to matter in Jscript even, probably it's accessing the parameter through some kind of COM wrapper)

Am using the ...diffuse.parameter("green") syntax now because it's much less confusing than ...diffuse.gReEn :)