Graphics

 View Only
  • 1.  material assignement to an object

    Posted 07-26-2013 18:39
    Hi, I have the following script

    dim indiceGeneral, indiceSelectivo, indiceNY, indiceSP, indiceST, indiceBT as xptextObject

    dim iconoGeneral, iconoSelectivo, iconoNY, iconoSP, iconoST, iconoBT as xpQuadObject

    dim matGeneral, matSelectivo, matNY, matSP, matST, matBT as xpMaterial

    dim shaderGeneral, shaderSelectivo, shaderNY, shaderSP, shaderST, shaderBT as xpBaseShader

    Self.GetObjectbyName("indiceGeneral", indiceGeneral)

    Self.GetObjectbyName("indiceSelectivo", indiceSelectivo)

    Self.GetObjectbyName("indiceNY", indiceNY)

    Self.GetObjectbyName("indiceSP", indiceSP)

    Self.GetObjectbyName("indiceST", indiceST)

    Self.GetObjectbyName("indiceBT", indiceBT)

    Self.GetObjectbyName("iconoGeneral", iconoGeneral)

    Self.GetObjectbyName("iconoSelectivo", iconoSelectivo)

    Self.GetObjectbyName("iconoNY", iconoNY)

    Self.GetObjectbyName("iconoSP", iconoSP)

    Self.GetObjectbyName("iconoST", iconoST)

    Self.GetObjectbyName("iconoBT", iconoBT)

    '#################################### Indice General #################################################

    if inStr(indiceGeneral.text, "+") = 1 then

    Engine.getMaterialByName ("matGeneral", MatGeneral)

    MatGeneral.getShaderByName ("shaderGeneral", ShaderGeneral)

    ShaderGeneral.setFileName (Engine.ProjectPath &"Imagesindicadoresflecha arriba.png")

    ShaderGeneral.reloadfile

    elseIf inStr(indiceGeneral.text, "-" ) = 1 then

    Engine.getMaterialByName ("matGeneral", MatGeneral)

    MatGeneral.getShaderByName ("shaderGeneral", ShaderGeneral)

    ShaderGeneral.setFileName (Engine.ProjectPath &"Imagesindicadoresflecha abajo.png")

    ShaderGeneral.reloadfile

    Else

    iconoGeneral.visible ="false"

    end if

    '#################################### Indice Selectivo #################################################

    if inStr(indiceSelectivo.text, "+") = 1 then

    Engine.getMaterialByName ("matSelectivo", MatSelectivo)

    MatGeneral.getShaderByName ("shaderSelectivo", ShaderSelectivo)

    ShaderSelectivo.setFileName (Engine.ProjectPath &"Imagesindicadoresflecha arriba.png")

    ShaderSelectivo.reloadfile

    elseIf inStr(indiceSelectivo.text, "-" ) = 1 then

    Engine.getMaterialByName ("matSelectivo", MatSelectivo)

    MatSelectivo.getShaderByName ("shaderSelectivo", ShaderSelectivo)

    ShaderSelectivo.setFileName (Engine.ProjectPath &"Imagesindicadoresflecha abajo.png")

    ShaderSelectivo.reloadfile

    Else

    iconoSelectivo.visible ="false"

    end if

    '#################################### Nueva York #################################################

    if inStr(indiceNY.text, "+") = 1 then

    Engine.getMaterialByName ("matNY", MatNY)

    MatNY.getShaderByName ("shaderNY", ShaderNY)

    ShaderNY.setFileName (Engine.ProjectPath &"Imagesindicadoresflecha arriba.png")

    ShaderNY.reloadfile

    elseIf inStr(indiceNY.text, "-" ) = 1 then

    Engine.getMaterialByName ("matNY", MatNY)

    MatNY.getShaderByName ("shaderNY", ShaderNY)

    ShaderNY.setFileName (Engine.ProjectPath &"Imagesindicadoresflecha abajo.png")

    ShaderNY.reloadfile

    Else

    iconoNY.visible ="false"

    end if

    '#################################### Sao Paulo #################################################

    if inStr(indiceSP.text, "+") = 1 then

    Engine.getMaterialByName ("matSP", MatSP)

    MatSP.getShaderByName ("shaderSP", ShaderSP)

    ShaderSP.setFileName (Engine.ProjectPath &"Imagesindicadoresflecha arriba.png")

    ShaderSP.reloadfile

    elseIf inStr(indiceSP.text, "-" ) = 1 then

    Engine.getMaterialByName ("matSP", MatBT)

    MatSP.getShaderByName ("shaderSP", ShaderBT)

    ShaderSP.setFileName (Engine.ProjectPath &"Imagesindicadoresflecha abajo.png")

    ShaderSP.reloadfile

    Else

    iconoSP.visible ="false"

    end if

    '#################################### Santiago #################################################

    if inStr(indiceST.text, "+") = 1 then

    Engine.getMaterialByName ("matST", MatST)

    MatST.getShaderByName ("shaderST", ShaderST)

    ShaderST.setFileName (Engine.ProjectPath &"Imagesindicadoresflecha arriba.png")

    ShaderST.reloadfile

    elseIf inStr(indiceST.text, "-" ) = 1 then

    Engine.getMaterialByName ("matST", MatST)

    MatST.getShaderByName ("shaderST", ShaderST)

    ShaderST.setFileName (Engine.ProjectPath &"Imagesindicadoresflecha abajo.png")

    ShaderST.reloadfile

    Else

    iconoST.visible ="false"

    end if

    '#################################### Bogota #################################################

    if inStr(indiceBT.text, "+") = 1 then

    Engine.getMaterialByName ("matBT", MatBT)

    MatBT.getShaderByName ("shaderBT", ShaderBT)

    ShaderBT.setFileName (Engine.ProjectPath &"Imagesindicadoresflecha arriba.png")

    ShaderBT.reloadfile

    elseIf inStr(indiceBT.text, "-" ) = 1 then

    Engine.getMaterialByName ("matBT", MatBT)

    MatBT.getShaderByName ("shaderBT", ShaderBT)

    ShaderBT.setFileName (Engine.ProjectPath &"Imagesindicadoresflecha abajo.png")

    ShaderBT.reloadfile

    Else

    iconoBT.visible ="false"

    end if

    +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

    I think is a long script because I have six items, with six different materials and the script is assigning an up or down arrow for each material (is for stocks), What I want is to have only two materials (one for up and one for down), and then assign the materials to my items when certain conditions are true.

    Is there a way to make the script smaller with what I want?

    thank you in advance.


  • 2.  RE: material assignement to an object

    Posted 07-26-2013 19:10
    Hi Luis,

    try to make re-usable functions in order to save code size.

    With the following example you need 2 materials (Up & Down images) matup & matdn.

    2 shaders shaderup & shaderdn

    Public Function SETMATERIAL(matname As String, shader As String, filename As String) As Boolean

    xEngine.GetMaterialByName "mat" & matname, xMaterial

    xMaterial.GetShaderByName "shader" & shader, xShader

    xShader.SetFileName filename

    End Function

    Public Function SETQUAD(quad As String, matname As String) As Boolean

    Dim tmpQuadObj As xpQuadObject

    xScene.GetObjectByName "quad" & quad, tmpQuadObj

    xEngine.GetMaterialByName "mat" & matname, xMaterial

    tmpQuadObj.SetMaterial 0, xMaterial

    End Function

    Public Function SETTHIS(item As String) As Boolean

    Dim tmpTextObj as xpTextObject

    xScene.GetObjectByName "indice" & item, tmpTextObj

    if inst(tmpTextObj.text,"+")=1 then

    SETQUAD "indice" & item,"up"

    else

    SETQUAD "indice" & item,"dn"

    end if

    End Function

    '#################################

    SETMATERIAL "up","up","C:imagesup.png"

    SETMATERIAL "dn","dn","C:imagesdn.png"

    '#################################

    SETTHIS("General")

    SETTHIS("Selectivo")

    SETTHIS("NY")

    SETTHIS("SP")

    SETTHIS("ST")

    SETTHIS("BT")

    Hope that helps

    #XPression


  • 3.  RE: material assignement to an object

    Posted 07-26-2013 19:13
    The correct part of code

    Public Function SETTHIS(item As String) As Boolean

    Dim tmpTextObj as xpTextObject

    xScene.GetObjectByName "indice" & item, tmpTextObj

    if inst(tmpTextObj.text,"+")=1 then

    SETQUAD "quad" & item,"up"

    else

    SETQUAD "quad" & item,"dn"

    end if

    End Function

    #XPression