accessing color in scripts question

Discussions concerning programming of SOFTIMAGE©
Post Reply
User avatar
rray
Moderator
Posts: 1774
Joined: 26 Sep 2009, 15:51
Location: Bonn, Germany
Contact:

accessing color in scripts question

Post by rray » 04 Dec 2017, 20:17

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
softimage resources section updated Jan 5th 2024

User avatar
myara
Posts: 403
Joined: 28 Sep 2011, 10:33

Re: accessing color in scripts question

Post by myara » 06 Dec 2017, 08:22

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.
M.Yara
Character Modeler | Softimage Generalist (sort of)

User avatar
rray
Moderator
Posts: 1774
Joined: 26 Sep 2009, 15:51
Location: Bonn, Germany
Contact:

Re: accessing color in scripts question

Post by rray » 06 Dec 2017, 11:40

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.
softimage resources section updated Jan 5th 2024

User avatar
Daniel Brassard
Posts: 878
Joined: 18 Mar 2010, 23:38
Location: St. Thomas, Ontario
Contact:

Re: accessing color in scripts question

Post by Daniel Brassard » 06 Dec 2017, 15:11

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)
$ifndef "Softimage"
set "Softimage" "true"
$endif

User avatar
myara
Posts: 403
Joined: 28 Sep 2011, 10:33

Re: accessing color in scripts question

Post by myara » 06 Dec 2017, 15:16

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
M.Yara
Character Modeler | Softimage Generalist (sort of)

User avatar
Daniel Brassard
Posts: 878
Joined: 18 Mar 2010, 23:38
Location: St. Thomas, Ontario
Contact:

Re: accessing color in scripts question

Post by Daniel Brassard » 06 Dec 2017, 16:35

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
$ifndef "Softimage"
set "Softimage" "true"
$endif

User avatar
rray
Moderator
Posts: 1774
Joined: 26 Sep 2009, 15:51
Location: Bonn, Germany
Contact:

Re: accessing color in scripts question

Post by rray » 06 Dec 2017, 17:27

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 :)
softimage resources section updated Jan 5th 2024

Post Reply

Who is online

Users browsing this forum: No registered users and 20 guests