Jump to content

Force Directed Graph OpenCL


Librarian

Recommended Posts

Yunus :wub:  How to ? Point me to Right Direction when you have Time ....

 If You Have Said A, You Must Also Say B ...
 

geonode = hou.node('/obj/geo') # geometry
geonode.deleteItems(geonode.children()) # 

merge = geonode.createNode("merge") # merge
merge.setPosition(hou.Vector2(1,-2)) 

# box
nodes = []
posarray = [(0,0),(0,2),(2,2),(2,0)] # 
for i in xrange(4): 
    nodes.append(geonode.createNode("box")) # box
    nodes[i].setPosition(hou.Vector2(posarray[i]))
    merge.setInput(i,nodes[i]) 

# box
# posarray 
posarray2 = posarray[:]
posarray2.append(posarray2[0])
posarray2.pop(0)

anival = [] # 
for i in xrange(4):
    # 
    anival.append(
        hou.NetworkAnimValue(
            4.0, 
            nodes[i].position(), 
            hou.Vector2(posarray2[i])))


ne.setVisibleBounds(hou.BoundingRect(-3,-3,6,3),0.5) 
ne.setAdjustments(nodes, anival, auto_remove=True) 

# 
# ref) http://www.sidefx.com/docs/houdini/hom/hou/NetworkAnimValue.html
for i in xrange(4):  
    nodes[i].setPosition(hou.Vector2(posarray2[i]))

 

Link to comment
Share on other sites

@animatrix When you Have Time Please..
I followed ...here its Code ..I download Again 16.5 Houdini...syntax error   /Don't 'see ....Don't Understand-- Nada ...Maybe Typo

IndentationError: ('unexpected indent', ('Sc', 34, 1, ' for point in wrangle.geometry().points():\n'))

 

import toolutils


#Ask user to select source geometry 
sViewer = toolutils.sceneViewer()
selected_object = sViewer.selectObjects('Select geometry to copy nodes to', allowed_types=("geo",), allow_multisel=0) 
source = selected_object[0]

#Create folder in which new animated nodes will be contained
root = hou.node('/obj')
folder = root.createNode('geo', 'Moving_Nodes') 
folder.moveToGoodPosition()

# Delete default file node from the new folder 
for nodes in folder.children():
    nodes.destroy()
    
#Find a node with Display Flag on 
for child in source.children():
     if child.isDisplayFlagSet() == 1: 
          geo = child
          
#Create a new wrangle node which sets Id and Color point attributes to source geo 
wrangle = source.createNode('attribwrangle')
wrangle.parm('snippet').set("""i@id = @ptnum;
@Cd = fit01(@P, 0.5, 1);""")
wrangle.moveToGoodPosition() 
wrangle.setInput(0, geo) 
wrangle.setDisplayFlag(1) 
wrangle.setRenderFlag(1)

# Create a new Null node on for every point and copy X and Y coordinates from P point attribute to every new Null
# Create a new Index parameter on each Null which corresponds to its "parent" point
 for point in wrangle.geometry().points():
     node_Xpos = point.attribValue('P')[0]*6 
     node_Ypos = point.attribValue('P')[1]*6 
     new_node = folder.createNode('null') 
     parms = new_node.parmTemplateGroup()
     parms.addParmTemplate(hou.IntParmTemplate("index", "Index", 1)) 
     new_node.setParmTemplateGroup(parms) 
     new_node.parm('index').set(point.attribValue('id'))
     new_node.setPosition((node_Xpos, node_Ypos))
     
     
# Create a new Python SOP in the source folder with a code which transfers a position from points to the corresponding Nulls on every frame
python = source.createNode('python')
python.parm('python').set("""node = hou.pwd()
geo = node.geometry()
root = hou.node('/obj/Moving_Nodes')

for point in geo.points():
    node_Xpos = point.attribValue('P')[0]*6
    node_Ypos = point.attribValue('P')[1]*6
    node_color= point.attribValue('Cd')
    for child in root.children():
        if child.parm('index').eval() == point.attribValue('id'): 
           child.setPosition((node_Xpos, node_Ypos)) 
           child.setColor(hou.Color(node_color))""")


python.setDisplayFlag(1)
python.setRenderFlag(1) 
python.moveToGoodPosition()
python.setInput(0, wrangle)



 

Link to comment
Share on other sites

7 hours ago, Librarian said:

@anim :rolleyes::wub::rolleyes: Thanx It works Yessssss ...OO I have Fun

Yes that happens when you copy paste code and even Sublime seems to mess up indents sometimes especially if you don't edit the code in Python syntax.

But my idea was to model your network using the OpenCL force directed graph, solve it using the OpenCL SOP in the BG, and then copy the positions in animated form :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...