Graphics

 View Only
  • 1.  Red State, Blue State

    Posted 10-21-2016 19:48
    I need help.

    I have a 3D map of the US, with each state as an individual model. I need to assign the color of each through the Xpression plugin in ENPS. I have .3ds models named by state name (with a few that are shortened) and so far one text field AlabamaColor as a Radio Buttons with RedState, BlueState, PurpleState, WhiteState as the choices. The only thing I could find in the SDK help that might apply to 3D models was xpTexturedObject.

    I explored the possibility of making this happen through Visual Logic, but didn't think I could make it work.

    Am I even close to success?

    I have the following in OnOnline:

    dim matRedState as xpMaterial
    dim matBlueState as xpMaterial
    dim matWhiteState as xpMaterial
    dim matPurpleState as xpMaterial

    dim AlabamaColor as xpTextObject
    dim Alabama as xpTexturedObject

    Engine.getMaterialByName("RedState", matRedState)
    Engine.getMaterialByName("BlueState", matBlueState)
    Engine.getMaterialByName("PurpleState", matPurpleState)
    Engine.getMaterialByName("WhiteState", matWhiteState)

    Self.getObjectByName("AlabamaColor", AlabamaColor)

    Alabama.setMaterial(0,matRedState)


  • 2.  RE: Red State, Blue State

    Posted 10-22-2016 01:57
    Update: The script below sets Alabama to red. Now, how do I extract the text from TextObject and include it in SetMaterial?

    ...and what short-cut is there to save me from declaring 49 more models & text fields and all the self.get and set?

    dim RedState as xpMaterial
    dim BlueState as xpMaterial
    dim PurpleState as xpMaterial
    dim WhiteState as xpMaterial

    '.3ds file model
    dim Alabama as xpTexturedObject

    'radio button RedState, BlueState, PurpleState, WhiteState
    dim AlabamaColor as xpTextObject
    self.getobjectbyname ("AlabamaColor",AlabamaColor)

    Engine.getMaterialByName("RedState", RedState)
    Engine.getMaterialByName("BlueState", BlueState)
    Engine.getMaterialByName("PurpleState", PurpleState)
    Engine.getMaterialByName("WhiteState", WhiteState)

    self.getobjectbyname ("Alabama", Alabama)

    Alabama.SetMaterial(0, RedState)



    #XPression


  • 3.  RE: Red State, Blue State

    Posted 10-24-2016 09:16
    Do you have a white model for each states and you want to set a color to them, or do you have for each states 4 models (white, red, etc....) ?
    #XPression


  • 4.  RE: Red State, Blue State

    Posted 10-24-2016 18:30
    I have fifty models that are white by default. I am wary of using multiple versions of the same model because of strange behavior when two models overlap or occupy the same space. I think I could design Visual Logic capable of controlling the visibility of the correct color....except that it would require hundreds of blocks. Scripting it is probably a better choice.
    #XPression


  • 5.  RE: Red State, Blue State

    Posted 10-24-2016 18:54
    This code into OnSetText of Alabama TextObject

    Dim MyXpTextObject as xpTextObject = nothing
    Dim MyMaterial as xpMaterial = nothing
    Dim MyColor as xpColor
    Dim MyColorToApply as xpColor
    Dim MyLayer as xpMaterialLayer

    Engine.GetMaterialByName("Material_Alabama", MyMaterial)
    MyMaterial.GetLayer(0,MyLayer)
    MyColorToApply = MyLayer.ColorDiffuse

    Select Case Text
    Case "WhiteState"
    MyColorToApply.R = 255
    MyColorToApply.G = 255
    MyColorToApply.B = 255

    Case "RedState"
    MyColorToApply.R = 255
    MyColorToApply.G = 0
    MyColorToApply.B = 0

    Case "BlueState"
    MyColorToApply.R = 0
    MyColorToApply.G = 0
    MyColorToApply.B = 255

    Case "PurpleState"
    MyColorToApply.R = 255
    MyColorToApply.G = 0
    MyColorToApply.B = 255
    End Select

    #XPression


  • 6.  RE: Red State, Blue State

    Posted 10-24-2016 21:58
    Vinz!

    Got the chance to test it out with one state and it works like magic. Made the extra forty-nine materials, the individual state text objects, and tailored the scripts to match the models, but won't get to test out the complete map until after our evening newscasts.

    I believe I need to think more like a programmer---do you have any tips/resources toward that goal?

    Thanks,
    James.
    #XPression


  • 7.  RE: Red State, Blue State

    Posted 10-25-2016 09:25
    One tip : be logic... ;)
    #XPression


  • 8.  RE: Red State, Blue State

    Posted 10-27-2016 00:50
    Vinz,

    In testing a sequence of these graphic where I build up to assigning colors to all the states, I assigned one state a color, duplicated that, assigned another state a color and so on. As I'm doing this, (I had already put the first map online) each state I assigned a color updated online. Then I moved the cursor through the sequence of the graphics and the map online updated as I set the focus to the next....even though I hadn't played it to air. It seems like OnSetText scripts behave like OnPreviewRender scripts. I haven't published my project yet, so I don't know that it will behave similarly when playing scenes through the Remote Sequencer, but I suspect that it will. Any suggestions?

    Thanks,
    James.
    #XPression


  • 9.  RE: Red State, Blue State

    Posted 10-27-2016 09:01
    Yes it's normal. In fact, you modify each material OnSetText, but when you focus another element, all the textobjects in this scene are modify to have your data in it; and the script modify all material.
    What you can do is to add a condition like : if a map is on air, don't refresh materials.
    Or you can create 50 materials, one for each state.

    Last possiblity, the best one, but you have to think your scene differently You use SetVolatileTextureFile, then retrieve material dynamically created and colorize it.
    But you have to set up a loop routine in online...
    #XPression