Graphics

 View Only
  • 1.  Change material using letter code instead of number

    Posted 10-20-2020 12:40

    I need help figuring out how to change the material color for bar graphs in an election scene. The scene involves the top 2 candidates and uses bar graphs to indicate vote totals. I need the material/color of the bars to change based on candidate party affiliation (Red for Republican, Blue for Democrat, Grey for Independent).

    I know how to set up visual logic to allow for material changes when using radial buttons & numbers fed into an input selector; however, I'm not sure how to set things up to use a letter code instead of a number. Our election ticker system that will feed the info to the scene uses letters for party affiliation.

    So I need to set it up to use the letters instead of numbers to get that material assignment to happen.

    SO,

    A- can this be done?

    B- if so, is it something that is possible using visual logic, or is this a job for scripting?  If this is a script job, who out there can hold my hand in making that happen as I'm a noobie on the script side of things.

    Thanks.



  • 2.  RE: Change material using letter code instead of number

    Posted 10-20-2020 15:55

    I was in a bit of a crunch, so went ahead on doing a workaround by duplicating graphs (one for each color needed- grey, red, blue), then doing visibility logic based on a letter code for the appropriate graphs to show up.  A lot of extra objects & duplication of logic to get all the components to work; but I get the desired result.

    If anyone stumbles upon this & can inform me of how scripting can be used to change material colors of a single object (vs making several different objects as I had to do) that would be good. I have a long way to go on the scripting side.

    Thanks.


    #XPression


  • 3.  RE: Change material using letter code instead of number

    Posted 10-24-2020 12:32

    Hi Troy,

     

    There is a way to do this using Visual Logic but it might seem a bit weird. However I use this system quite often in a variety of applications.

    Like you mentioned in your original question, the input selector only uses numerical values. So to solve your issue, we need to "convert" the string value into a numerical value.

    Below you can find an example where I do exactly that.

    So basically I compare the value which is being fed into XPression with a few predefined values.

    I use the string position because it allows me to add a predefined value inside of the block. You could also use a string compare block but then you would need to feed the value using a string value-block and the value would also have to be identical.

     

    If the string is found the string position will display the position of the character. If it doesn't find the character, it will return 0.

    So next I perform a check whether or not the value is above 0 (so a matching value was found) which will return 1 or 0.

     

    To have a unique ID I add a multiplier that multiplies the 1 with a predefined value.

    Since I can only feed one single value into the Input Selector, I need to go from three values to one.

    But since we will only have one single value at any given time, only one value will return a value, the others will be 0. So by adding the three values together I will get a single value which will either be 1, 2 or 3. If there is no match, the result will be 0.

     

    This can than be fed to the Input Selector to select the correct color or material. 


    #XPression