Graphics

 View Only
  • 1.  Change Material Color through scripting

    Posted 03-30-2023 15:48

    This was set out to be such an easy thing, but something is stumping me.  I have a material.  I want to be able to change that material's color on sequence side across multiple take items at once.

    So I want to either have a text box that is setting a HEX code, and multiple text boxes that are setting HSL on the material.

    What I am attempting to do is that, I am trying to set a base layer, then I have a overlay playing.  That base layer needs to be a dynamic color that can shift, but since this is a tessera system, I have 11 take items to update.  I am trying to prevent any potential issues, and be able to assign a material "Sponsor Color 1", then on sequence side change that material's color.

    Then if there is a 2nd take item group that is needed, obviously would have to create a second material if I wanted a different color.

    I do not want to make an image that is a swatch that I link to.  I do not want to do texture position and move an item around to color pick something. - I simply want a material that I can dynamically update its color from sequence side, based on a text box.  If not a text box, then a control scene that uses the color picker to set a color and then that updates across.



    ------------------------------
    Garrett Hall
    Overtime Elite
    ------------------------------


  • 2.  RE: Change Material Color through scripting

    Posted 03-30-2023 17:19

    I just did a test and in VisLogic a string can be assigned to a material's Layer->Colors->some_attribute.
    This captured example is green.
    I have to admit the color updating as I typed it in is confusing, but if you made 3 separate text fields,
    one for RED then GREEN then BLUE, you can do a simple hex spell check and put them together with visual logic.
    Trying to spell check the full string might not be that easy.

    From what I can tell you can not do it with VB scripting because the properties are read only, at least according
    to documentation.

    I hope that is the bridge you needed to cross.



    ------------------------------
    Azathoth
    Son of Cthulhu
    ------------------------------



  • 3.  RE: Change Material Color through scripting

    Posted 03-31-2023 02:13

    Here is a script I found that is labeled as "Setting Color Diffuse Materials Using RGB". 
    It is setting RGB and not HSL. I did not write this script or test it. Maybe this will help get you started..



    dim team, path, pri, sec, lite, dark as xpTextObject

    dim priColorMat, secColorMat, txtLiteMat, txtDarkMat, logoLiteMat, logoDarkMat, priBgrdMat, secBgrdMat as xpMaterial

    dim priColorShad, secColorShad, txtLiteShad, txtDarkShad, logoLiteShad, logoDarkShad, priBgrdShad, secBgrdShad as xpBaseShader

    dim priColor, secColor, liteColor, darkColor as xpColor

    dim value as integer = 0

    dim priStr(), secStr(), liteStr(), darkStr() as string

    scene.GetObjectByName("TEAM", team)

    scene.GetObjectByName("PATH", path)

    scene.GetObjectByName("PRIMARY_COLOR", pri)

    scene.GetObjectByName("SECONDARY_COLOR", sec)

    scene.GetObjectByName("4LITE_COLOR", lite)

    scene.GetObjectByName("4DARK_COLOR", dark)

    priStr = split(pri.text, ",")

    secStr = split(sec.text, ",")

    liteStr = split(lite.text, ",")

    darkStr = split(dark.text, ",")

    engine.GetMaterialByName(ucase(team.text & "_COLOR_PRI"), priColorMat)

    engine.GetMaterialByName(ucase(team.text & "_COLOR_SEC"), secColorMat)

    engine.GetMaterialByName(ucase(team.text & "_COLOR_4LITE"), txtLiteMat)

    engine.GetMaterialByName(ucase(team.text & "_COLOR_4DARK"), txtDarkMat)

    engine.GetMaterialByName(ucase(team.text & "_LOGO_4LITE"), logoLiteMat)

    engine.GetMaterialByName(ucase(team.text & "_LOGO_4DARK"), logoDarkMat)

    engine.GetMaterialByName(ucase(team.text & "_BGRD_PRI"), priBgrdMat)

    engine.GetMaterialByName(ucase(team.text & "_BGRD_SEC"), secBgrdMat)

    'SET COLORS

    priColor = priColorMat.ColorDiffuse

    secColor = secColorMat.ColorDiffuse

    liteColor = txtLiteMat.ColorDiffuse

    darkColor = txtDarkMat.ColorDiffuse

    priColor.R = priStr(0)

    priColor.G = priStr(1)

    priColor.B = priStr(2)

    secColor.R = secStr(0)

    secColor.G = secStr(1)

    secColor.B = secStr(2)

    liteColor.R = liteStr(0)

    liteColor.G = liteStr(1)

    liteColor.B = liteStr(2)

    darkColor.R = darkStr(0)

    darkColor.G = darkStr(1)

    darkColor.B = darkStr(2)

    'SET LOGOS

    engine.debugMessage(logoLiteMat.ShaderCount, 0)

    'LOGO FOR LIGHT BGRD

    'DELETE EXISTING SHADERS

    if logoLiteMat.ShaderCount > 0

    for i as integer = 0 to (logoLiteMat.ShaderCount - 1)

    logoLiteMat.DeleteShaderByIndex(i)

    next

    end if

    logoLiteMat.AddShader("Texture2D", 0, logoLiteShad)

    logoLiteShad.SetFileName(path.text & "\" & team.text & "_4LITE_LOGO.TGA")

    'LOGO FOR DARK BGRD

    if logoDarkMat.ShaderCount > 0

    for i as integer = 0 to (logoDarkMat.ShaderCount - 1)

    logoDarkMat.DeleteShaderByIndex(i)

    next

    end if

    logoDarkMat.AddShader("Texture2D", 0, logoDarkShad)

    logoDarkShad.SetFileName(path.text & "\" & team.text & "_4DARK_LOGO.TGA")

    'PRIMARY PATTERNS

    if priBgrdMat.ShaderCount > 0

    for i as integer = 0 to (priBgrdMat.ShaderCount - 1)

    priBgrdMat.DeleteShaderByIndex(i)

    next

    end if

    priBgrdMat.AddShader("Texture2D", 0, priBgrdShad)

    priBgrdShad.SetFileName(path.text & "\" & team.text & "_PRIMARY_PATTERN.TGA")

    'SECONDARY PATTERNS

    if secBgrdMat.ShaderCount > 0

    for i as integer = 0 to (secBgrdMat.ShaderCount - 1)

    secBgrdMat.DeleteShaderByIndex(i)

    next

    end if

    secBgrdMat.AddShader("Texture2D", 0, secBgrdShad)

    secBgrdShad.SetFileName(path.text & "\" & team.text & "_SECONDARY_PATTERN.TGA")






  • 4.  RE: Change Material Color through scripting

    Posted 03-31-2023 11:31

    Thank you both for responses.  Both of you kind of moved my thinking around a little bit. - I ended up being able to get what I wanted to get.  Garner, I think that your script that you sent over is still having a lot to do with files that exist to create the colors and select which color.

    While ideally with the partner colors, it would be nice to be able to affect the HEX Code to the material, that is okay as most everyone provides an RGB.  So I switched from HSL to RGB to accomplish.

    dim mat as xpMatieral
    dim r, g, b as xpTextObject
    
    'Get text boxes in the scene
    self.GetObjectByName("Set R", r)
    self.GetObjectByName("Set G", g)
    self.GetObjectByName("Set B", b)
    
    'Get the Material in the Project
    engine.GetMaterialByName("Change This Material", mat)
    
    'Set RGB Value
    mat.ColorDiffuse.R = (cInt(r.Text))
    mat.ColorDiffuse.G = (cInt(g.Text))
    mat.ColorDiffuse.B = (cInt(b.Text))

    So the weird step to most might be the cInt part.  That is converting text to an integer so that you can use it as a number.  Shout out Amber Barnett for giving me that little jewel years ago.

    This works in Xpression, now I have to see if it works in Tessera or not.  I have my doubts solely because we are blue boxes, and if you make a change to a material, in theory you need to republish your project for all of the boxes to see the change to that material.  But I can dream can't I. - Plus like, make the material, publish, and then you are good to go, until you need to change it again.



    ------------------------------
    Garrett Hall
    Overtime Elite
    ------------------------------



  • 5.  RE: Change Material Color through scripting

    Posted 03-31-2023 11:36

    I also want to reply and say that I got HSL working before I got RGB working, so for those that need to work in HSL world, very similar script as what is above.

    'Script if using RGB
    mat.ColorDiffuse.R = (cInt(r.Text))
    
    'Script if using HSL
    mat.ColorDiffuse.SetHSL = (cInt(h.Text),cInt(s.Text),cInt(l.Text))


    ------------------------------
    Garrett Hall
    Overtime Elite
    ------------------------------



  • 6.  RE: Change Material Color through scripting

    Posted 04-03-2023 16:54

    You need to create a "Setup" or "Skinning" scene - a dummy/blank scene that plays out from all Tessera Nodes. That scene needs to do the material modifications, and that way the material will be modified in the project that is loaded on all nodes.