Graphics

 View Only
  • 1.  Using Visual Logic to load images based on DataLinq

    Posted 07-01-2022 13:24
    We pull all of our elections data through DataLinq from an xml generated by our data provider. One of the pieces of data is an picture identifier, which is four letters long (typically from the beginning of the candidate's last name). That system uses that info to find the associated .png file to use on other platforms (web and app), but we'd like to use that to load images into XPression, as well.

    The four letter code comes in and is assigned via visual logic to that candidate's "Pic Tag" text file, named "Pic Tag 1", "Pic Tag 2", and "Pic Tag 3".

    I currently have a template with three different objects assigned to three different materials.The materials are "Pic_1", "Pic_2," and "Pic_3", which are all .png files that are transparent. Here's what I've come up with in the script editor, but it is assigning the image to not just the first, but all three shaders:
    dim pictag as xpTextObject
    dim pic as xpBaseObject
    dim picmat as xpMaterial
    dim picshad as xpBaseShader
    dim filepath as String
    dim i as Integer
    
    for i = 1 to 3
    Self.GetObjectByName("Pic Tag " & i, pictag)
    filepath="X:\!Election\Pictures\FINAL\" & pictag.Text & ".png"
    Self.GetObjectByName("Pic " & i, pic)
    pic.GetMaterial(0, picmat)
    picmat.GetShader(0, picshad)
    picshad.SetFileName(filepath)
    next i​

    Is there a better way to do this via Visual Logic where the rest of the scene's logic lives and works?



    ------------------------------
    Dan Jensen
    Operations Director
    WREX-TV
    ------------------------------


  • 2.  RE: Using Visual Logic to load images based on DataLinq

    Ross Staff
    Posted 07-04-2022 06:09
    What you have written should just address the first shader. 

    I was just checking the SDK and there is another option.

    You could name the shaders and then get them by name instead. 

    I think something like;

    dim pictag as xpTextObject
    dim pic as xpBaseObject
    dim picmat as xpMaterial
    dim picshad as xpBaseShader
    dim filepath as String
    dim i as Integer

    for i = 1 to 3
    Self.GetObjectByName("Pic Tag " & i, pictag)
    filepath="X:\!Election\Pictures\FINAL\" & pictag.Text & ".png"
    Self.GetObjectByName("Pic " & i, pic)
    pic.GetMaterial(0, picmat)
    picmat.GetShaderByName("Texture", picshad)
    picshad.SetFileName(filepath)
    next i​


    Should work although I wouldn't just use the default name like Texture, I would edit the shader and give it a specific name.

    ------------------------------
    Simon Redmile
    Senior Graphic Programmer & Designer
    Ross Video
    Bristol United Kingdom
    ------------------------------



  • 3.  RE: Using Visual Logic to load images based on DataLinq

    Posted 08-19-2022 15:07
    I've got with a non-looping version of this as I couldn't get it to work while looping through integers, but now it still does not work. The output is the same image being applied to both material shaders.

    dim ida as xpTextObject
    dim filea as String
    dim pica as xpBaseObject
    dim mata as xpMaterial
    dim shada as xpBaseShader
    dim idb as xpTextObject
    dim fileb as String
    dim picb as xpBaseObject
    dim matb as xpMaterial
    dim shadb as xpBaseShader
    
    Self.GetObjectByName("ID 1", ida)
    Self.GetObjectByName("ID 2", idb)
    filea="C:\Users\djensen\Documents\XPression Projects\Test Graphics Holder\" & ida.Text & ".png"
    fileb="C:\Users\djensen\Documents\XPression Projects\Test Graphics Holder\" & idb.Text & ".png"
    Self.GetObjectByName("Pic 1", pica)
    Self.GetObjectByName("Pic 2", picb)
    pica.GetMaterial(0, mata)
    picb.GetMaterial(0, matb)
    mata.GetShaderByName("holder1", shada)
    matb.GetShaderByName("holder2", shadb)
    shada.SetFileName(filea)
    shadb.SetFileName(fileb)​


    ------------------------------
    Dan Jensen
    Operations Director
    WREX-TV
    ------------------------------



  • 4.  RE: Using Visual Logic to load images based on DataLinq

    Posted 08-20-2022 15:09
    Hi Dan.
    Try to use this script
    dim pictag as xpTextObject
    dim picmat as xpMaterial
    dim picshad as xpBaseShader
    dim filepath as String
    
    for i as  Integer = 1 to 3
    	self.GetObjectByName("Pic Tag " + Cstr(i), pictag)
    	filepath="X:\!Election\Pictures\FINAL\" + pictag.Text + ".png"
    	engine.GetMaterialByName("Pic_" + CStr(i), picmat)
    	picmat.GetShader(0, picshad)
    	picshad.SetFileName(filepath)
    next​

    or try updating the image using DataLink. In the line DataLink select your xml



    ------------------------------
    Roman Yaroshenko
    chief specialist
    RBC-TV
    Moscow Russian Federation
    ------------------------------



  • 5.  RE: Using Visual Logic to load images based on DataLinq

    Ross Staff
    Posted 08-22-2022 11:55
    Alternatively you can use the volatile texture face of an object to apply a file as a texture temporarily to an object. Volatile textures only exist when rendered. Volatile textures take on the properties of the material on the face of the object they are replacing. 

    quad as xpBaseObject

    scene.GetObjectByName("Headshot1", quad)

    quad.SetVolatileTextureFile(0,"D:\In-Game Fascia\Images\Elements" & text & "\Bullpen.png")


    If you're on XPression v10.5, you could also use Dynamic Materials + Datalinq to entirely avoid any scripting: https://www.youtube.com/watch?v=nJ26YiJ9RUI