Community
Bifrost Forum
Welcome to the Bifrost Forum. This is the place for artists using Bifrost to ask and answer questions, browse popular topics, and share knowledge about creating effects procedurally using Bifrost. You can also visit the Bifrost Community on AREA to download an array of ready-to-use graphs, read Bifrost news and updates, and find the latest tutorials.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Create text in bifrost graph.

9 REPLIES 9
Reply
Message 1 of 10
Aslan.Jafari
1566 Views, 9 Replies

Create text in bifrost graph.

 

This compound can generate mesh and strand text inside bifrost graph from a given string.

 

image.png

 

Face and vertex information from a Maya Type has been stored in value nodes through a python script, generating the necessary data to reconstruct the geometry/strand inside the graph.

 

image.png

image.png

 

You will need delete_mesh_faces.json from the Rebel Pack for this compound to work properly.

I've included a copy of this compound in the attached zip file. It is best to download the latest Rebel Pack from https://area.autodesk.com/downloads/all/compounds/


Aslan Jafari
Sr QA Analyst
Tags (3)
9 REPLIES 9
Message 2 of 10
mjcg91
in reply to: Aslan.Jafari

Brillant! 

Maxime Jeanmougin - Technical Artist
https://maximejeanmougin.com

Join the Bifrost Addicts community on Discord:
https://discord.gg/bifrost-addicts
Message 3 of 10
adminY93DK
in reply to: Aslan.Jafari

Would love to hear about your approach to storing the data from a Maya type via python!

Any experiences you could share about this approach?

Message 4 of 10
Aslanjafari
in reply to: adminY93DK

You can use a similar script to the one posted here, to create value nodes in the board and store some data in them.

 

C:\Program Files\Autodesk\Maya2020\scripts\others\convertTypeCapsToCurves.mel might help in converting Type to curves for you.

 

Note: for ease of use and saving space I've decided to store my data (X,Y,Z) X 1000 as string separated by " | " symbol. 

Inside the board you will need to split the string by " | " symbol, convert to float, divide by 1000 and slice the new array back into float3 array.image.png

 

 

import maya.cmds as cmds

#------------ variables
board = "bifrostGraphShape1" #Bifrost board name

Dictionary = {
"build_array":"BifrostBoard,Core::Array,build_array",
"value_float":"BifrostBoard,Core::Constants,float",
"array_float":"BifrostBoard,Core::Constants,array<float>",
"value_float3":"BifrostBoard,Core::Constants,Math::float3",
"value_float3Array":"BifrostBoard,Core::Constants,array<Math::float3>",
"string":"BifrostBoard,Core::Constants,string",
"array_string":"BifrostBoard,Core::Constants,array<string>",
}

def CreateNode(NodeName):
    return cmds.vnnCompound(board, ".", addNode=Dictionary[NodeName])[0]

Curves = cmds.ls(sl=True)
for Curve in Curves:
    cmds.select(Curve)
    curveShape = cmds.listRelatives(Curve,s=True)[0] #selected curve shape
    curveInfoNode = cmds.createNode("curveInfo") #create a curveInfo node
    cmds.connectAttr(curveShape + ".worldSpace", curveInfoNode + ".inputCurve") #connect the curve to the curveInfo node
    CVs = cmds.getAttr( curveInfoNode + ".cp[*]")
    
    separator = "|" #separator, to be used in the board to get data
    stringList = [] 
    
    for i in range (0,len(CVs)):
        stringList.append(str(int(float(str(CVs[i][0])[:4])*1000))) #float accuracy, divide by 1000 in the board
        stringList.append(str(int(float(str(CVs[i][1])[:4])*1000)))#float accuracy, divide by 1000 in the board
        stringList.append(str(int(float(str(CVs[i][2])[:4])*1000)))#float accuracy, divide by 1000 in the board
            
    stringData = separator.join(stringList) #joint string
    valueNode = CreateNode("string") #create value node of type string
    cmds.vnnNode(board, "." + valueNode, setPortDefaultValues = ( "value", str(stringData)))  #set string value in the node

 

 

Message 5 of 10
Aslanjafari
in reply to: adminY93DK

You can use a similar script to the one posted here to create value nodes inside the graph and set values in them.

 

C:\Program Files\Autodesk\Maya2020\scripts\others\convertTypeCapsToCurves.mel Might be of some help converting the Types to curves for you.

 

Note: For ease of use and saving space I decided to store my (X,Y,Z) X 1000 data as string separated by | (pipesymbol.

In the board you will have to do the reverse. Replace with comma in the string then split by comma and convert to float. Slice the new array into Array<Math::float3>

image.png

 

import maya.cmds as cmds

#------------ variables
board = "bifrostGraphShape1" #Bifrost board name

Dictionary = {
"build_array":"BifrostBoard,Core::Array,build_array",
"value_float":"BifrostBoard,Core::Constants,float",
"array_float":"BifrostBoard,Core::Constants,array<float>",
"value_float3":"BifrostBoard,Core::Constants,Math::float3",
"value_float3Array":"BifrostBoard,Core::Constants,array<Math::float3>",
"string":"BifrostBoard,Core::Constants,string",
"array_string":"BifrostBoard,Core::Constants,array<string>",
}

def CreateNode(NodeName):
    return cmds.vnnCompound(board, ".", addNode=Dictionary[NodeName])[0]

Curves = cmds.ls(sl=True)
for Curve in Curves:
    cmds.select(Curve)
    curveShape = cmds.listRelatives(Curve,s=True)[0] #selected curve shape
    curveInfoNode = cmds.createNode("curveInfo") #create a curveInfo node
    cmds.connectAttr(curveShape + ".worldSpace", curveInfoNode + ".inputCurve") #connect the curve to the curveInfo node
    CVs = cmds.getAttr( curveInfoNode + ".cp[*]")
    
    separator = "|" #separator, to be used in the board to get data
    stringList = [] 
    
    for i in range (0,len(CVs)):
        stringList.append(str(int(float(str(CVs[i][0])[:4])*1000))) #float accuracy, divide by 1000 in the board
        stringList.append(str(int(float(str(CVs[i][1])[:4])*1000)))#float accuracy, divide by 1000 in the board
        stringList.append(str(int(float(str(CVs[i][2])[:4])*1000)))#float accuracy, divide by 1000 in the board
            
    stringData = separator.join(stringList) #joint string
    valueNode = CreateNode("string") #create value node of type string
    cmds.vnnNode(board, "." + valueNode, setPortDefaultValues = ( "value", str(stringData)))  #set string value in the node

 

 

 

Message 6 of 10
sklauss
in reply to: Aslan.Jafari

This is really cool! However adding just one text element takes my scene fps from 30 down to about 10 fps.

Is there a more efficient way to create text?

Message 7 of 10
Aslan.Jafari
in reply to: sklauss

Generating the text per frame might not be the best way, you may need to use feedback port and a simple logic to make it faster.

Here is an example:text_feedback.JPG

In this graph I am generating the text on frame one and using the feedback port to store and reuse the text after that.

 

I hope this helps.

 

 

 

 


Aslan Jafari
Sr QA Analyst
Message 8 of 10
valhallen
in reply to: Aslan.Jafari

Just used this to bring in colours from a texture ... ~300k points * 3 values, just wanted to say a big fat THANK YOU!

valhallen_0-1613580901253.png

 

Message 9 of 10
valhallen
in reply to: Aslan.Jafari

So here's my stripped-down python for getting cpv data in as a string array of floats if it's of use to anyone ... heavily based on what @Aslan.Jafari has posted earlier, just wrapped up in a def.

 

def cpvToBifrost(board,object,theFile,dp):
    
    '''
    Variables:
    board: the bifrost board name, example: "bifrostGraphShape3"        | String
    object:  the name of the object you are pulling the cpv data from   | String
    theFile:  the texture file                                          | String
    dp:  numver of decimal places to round the colour values to         | Int
    
    Note:
        the object should be mapped to your satisfaction, and the texture UV adjusted for same.  The script pulls the colour from
        the file at each UV and builds an array of colours for Bifrost reading. The array is sent to a string node as a big fat
        list of floats.  The more points in the object, the slower it is.
    
    Example Usage:
        cpvToBifrost("bifrostGraphShape3", "ground_base_hi", "file2", 2)
    '''

    colorArray = []

    Dictionary = {
    "build_array":"BifrostBoard,Core::Array,build_array",
    "value_float":"BifrostBoard,Core::Constants,float",
    "array_float":"BifrostBoard,Core::Constants,array<float>",
    "value_float3":"BifrostBoard,Core::Constants,Math::float3",
    "value_float3Array":"BifrostBoard,Core::Constants,array<Math::float3>",
    "string":"BifrostBoard,Core::Constants,string",
    "array_string":"BifrostBoard,Core::Constants,array<string>",
    }    
    
    verts = cmds.ls(object+".vtx[*]", fl=True)
    uvs = cmds.polyListComponentConversion(verts, tuv = True)
    uvs = cmds.ls(uvs, fl=True)

    for e in range(len(verts)):
        pnt_UV = cmds.polyEditUV(uvs[e], q=True)
        col = cmds.colorAtPoint(theFile, u=pnt_UV[0], v=pnt_UV[1], o="RGB")
        col = [round(each,dp) for each in col]
        
        colorArray.append(str(col[0]))
        colorArray.append(str(col[1]))
        colorArray.append(str(col[2]))
        
    stringData = "|".join(colorArray)

    valueNode = cmds.vnnCompound(board, ".", addNode=Dictionary["string"])[0]
    cmds.vnnNode(board, "." + valueNode, setPortDefaultValues = ( "value", str(stringData)))  #set string value in the node

 

As with most of my python, it's not pretty, but it works

When it's in the graph it's a big string of floats, separated by the "|" character, as above.  You will still need to do all the string separation, comma insertion and splitting into float arrays for colour.

valhallen_0-1613997802015.png

Hope this is useful, sing out if anyone wants me to post the graph.

Message 10 of 10
Aslan.Jafari
in reply to: valhallen

This is amazing, Thank you for sharing.


Aslan Jafari
Sr QA Analyst

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums