|
@@ -2,17 +2,11 @@
|
|
|
# This code is called when instances of this SOP cook.
|
|
# This code is called when instances of this SOP cook.
|
|
|
#scaleFactor = node.parm("scaleFactor").eval()
|
|
#scaleFactor = node.parm("scaleFactor").eval()
|
|
|
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
import random
|
|
import random
|
|
|
import os
|
|
import os
|
|
|
import sys
|
|
import sys
|
|
|
from os import path
|
|
from os import path
|
|
|
|
|
|
|
|
-#homedir=os.path.expanduser('~')
|
|
|
|
|
-#modDir=sys.path.append(os.path.join(homedir, 'Documents/lab'))
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
node = hou.pwd()
|
|
node = hou.pwd()
|
|
|
geo = node.geometry()
|
|
geo = node.geometry()
|
|
|
|
|
|
|
@@ -28,7 +22,7 @@ BAttr = geo.addAttrib(hou.attribType.Point, "Branch", 0)
|
|
|
GAttr = geo.addAttrib(hou.attribType.Point, "Generation", 0)
|
|
GAttr = geo.addAttrib(hou.attribType.Point, "Generation", 0)
|
|
|
BNAttr = geo.addAttrib(hou.attribType.Point, "BranchPoint", 0)
|
|
BNAttr = geo.addAttrib(hou.attribType.Point, "BranchPoint", 0)
|
|
|
BTNAttr = geo.addAttrib(hou.attribType.Point, 'NormalizedPosition', 0.0)
|
|
BTNAttr = geo.addAttrib(hou.attribType.Point, 'NormalizedPosition', 0.0)
|
|
|
-
|
|
|
|
|
|
|
+DAttr = geo.addAttrib(hou.attribType.Point, 'Diameter', 1.0)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -39,8 +33,6 @@ point.setAttribValue('NormalizedPosition', 0.5)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
defaultGrp=geo.createPointGroup('name')
|
|
defaultGrp=geo.createPointGroup('name')
|
|
|
defaultGrp.add(point)
|
|
defaultGrp.add(point)
|
|
|
|
|
|
|
@@ -62,44 +54,49 @@ def duplicatePoint(p):
|
|
|
#dupe=duplicatePoint(point)
|
|
#dupe=duplicatePoint(point)
|
|
|
|
|
|
|
|
|
|
|
|
|
-def moveAlongNormal(pt):
|
|
|
|
|
|
|
+def tropism(pt,vector,factor):
|
|
|
|
|
+ '''Move point towards another point, as in growing towards a light source (sun)
|
|
|
|
|
+ or a food source (roots)
|
|
|
|
|
+ '''
|
|
|
|
|
+ P = pt.position()
|
|
|
|
|
+ pt.setPosition( P + 1 * vector)
|
|
|
|
|
+
|
|
|
|
|
+def moveAlongNormal(pt,factor):
|
|
|
P = pt.position()
|
|
P = pt.position()
|
|
|
#P = hou.Vector3(P)
|
|
#P = hou.Vector3(P)
|
|
|
# be careful - this returns a value you cant simply add to P, must convert it to a hou.Vector3
|
|
# be careful - this returns a value you cant simply add to P, must convert it to a hou.Vector3
|
|
|
N = pt.attribValue("N")
|
|
N = pt.attribValue("N")
|
|
|
N = hou.Vector3(N)
|
|
N = hou.Vector3(N)
|
|
|
- pt.setPosition( P + 1 * N )
|
|
|
|
|
-
|
|
|
|
|
|
|
+ pt.setPosition( P + (1*factor) * N )
|
|
|
|
|
|
|
|
def createRandomVector():
|
|
def createRandomVector():
|
|
|
- rx=(random.random()-0.5)*2
|
|
|
|
|
- ry=(random.random()-0.5)*2
|
|
|
|
|
- rz=(random.random()-0.5)*2
|
|
|
|
|
|
|
+ rx = (random.random()-0.5)*2
|
|
|
|
|
+ ry = (random.random()-0.5)*2
|
|
|
|
|
+ rz = (random.random()-0.5)*2
|
|
|
return hou.Vector3([rx,ry,rz])
|
|
return hou.Vector3([rx,ry,rz])
|
|
|
|
|
|
|
|
def addNoiseToNormal(pt,factor):
|
|
def addNoiseToNormal(pt,factor):
|
|
|
N = pt.attribValue("N")
|
|
N = pt.attribValue("N")
|
|
|
N = hou.Vector3(N)
|
|
N = hou.Vector3(N)
|
|
|
- rx=(random.random()-0.5)*2
|
|
|
|
|
- ry=(random.random()-0.5)*2
|
|
|
|
|
- rz=(random.random()-0.5)*2
|
|
|
|
|
- rvec=hou.Vector3([rx*factor,ry*factor,rz*factor])
|
|
|
|
|
- newN= rvec + 1 * N
|
|
|
|
|
|
|
+ rx = (random.random()-0.5)*2
|
|
|
|
|
+ ry = (random.random()-0.5)*2
|
|
|
|
|
+ rz = (random.random()-0.5)*2
|
|
|
|
|
+ rvec = hou.Vector3([rx*factor,ry*factor,rz*factor])
|
|
|
|
|
+ newN = rvec + 1 * N
|
|
|
pt.setAttribValue("N", newN)
|
|
pt.setAttribValue("N", newN)
|
|
|
return pt
|
|
return pt
|
|
|
-
|
|
|
|
|
|
|
|
|
|
def rotateNormal(pt,factor):
|
|
def rotateNormal(pt,factor):
|
|
|
N = pt.attribValue("N")
|
|
N = pt.attribValue("N")
|
|
|
N = hou.Vector3(N)
|
|
N = hou.Vector3(N)
|
|
|
- rx=(random.random()-0.5)*2
|
|
|
|
|
- ry=(random.random()-0.5)*2
|
|
|
|
|
- rz=(random.random()-0.5)*2
|
|
|
|
|
- rvec=hou.Vector3([rx*factor,ry*factor,rz*factor])
|
|
|
|
|
- newN= rvec + 1 * N
|
|
|
|
|
|
|
+ rx = (random.random()-0.5)*2
|
|
|
|
|
+ ry = (random.random()-0.5)*2
|
|
|
|
|
+ rz = (random.random()-0.5)*2
|
|
|
|
|
+ rvec = hou.Vector3([rx*factor,ry*factor,rz*factor])
|
|
|
|
|
+ newN = rvec + 1 * N
|
|
|
pt.setAttribValue("N", newN)
|
|
pt.setAttribValue("N", newN)
|
|
|
return pt
|
|
return pt
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
def getPointsByAttribValue(attr,val):
|
|
def getPointsByAttribValue(attr,val):
|
|
|
plist=[]
|
|
plist=[]
|
|
|
for p in geo.iterPoints():
|
|
for p in geo.iterPoints():
|
|
@@ -121,7 +118,6 @@ branchgroups=[]
|
|
|
branchNum=0
|
|
branchNum=0
|
|
|
|
|
|
|
|
def step(pointers):
|
|
def step(pointers):
|
|
|
- inc=hou.Vector3([0,1,0])
|
|
|
|
|
updatedPointers=[]
|
|
updatedPointers=[]
|
|
|
for p in pointers:
|
|
for p in pointers:
|
|
|
n=p.attribValue("N")
|
|
n=p.attribValue("N")
|
|
@@ -161,13 +157,14 @@ def step(pointers):
|
|
|
branchP.setAttribValue('Generation',g+1)
|
|
branchP.setAttribValue('Generation',g+1)
|
|
|
updatedPointers.append(branchP)
|
|
updatedPointers.append(branchP)
|
|
|
|
|
|
|
|
- newP=rotateNormal(newP,0.1)
|
|
|
|
|
|
|
+ newP=rotateNormal(newP,0.4)
|
|
|
# now move along normal
|
|
# now move along normal
|
|
|
- moveAlongNormal(newP)
|
|
|
|
|
|
|
+ moveAlongNormal(newP,1)
|
|
|
|
|
+ v=hou.Vector3(0,1,1)
|
|
|
|
|
+ tropism(newP,v,1)
|
|
|
|
|
+ newP.setAttribValue('Diameter',newP.attribValue('Diameter')*0.9 )
|
|
|
return updatedPointers
|
|
return updatedPointers
|
|
|
-
|
|
|
|
|
|
|
|
|
|
-#moveAlongNormal(point)
|
|
|
|
|
|
|
|
|
|
x=step(pointers)
|
|
x=step(pointers)
|
|
|
|
|
|
|
@@ -194,7 +191,7 @@ def postprocess():
|
|
|
tInfo['branch']=curBranch
|
|
tInfo['branch']=curBranch
|
|
|
|
|
|
|
|
|
|
|
|
|
-print '[[[[[[[[[[]]]]]]]]]]'
|
|
|
|
|
|
|
+print '[[[[[[[[[[***]]]]]]]]]]'
|
|
|
totalBranches=int(getHighestNumericAttrVal(geo.iterPoints(),'Branch'))
|
|
totalBranches=int(getHighestNumericAttrVal(geo.iterPoints(),'Branch'))
|
|
|
#print geo.points()
|
|
#print geo.points()
|
|
|
|
|
|
|
@@ -227,7 +224,7 @@ for i in range(0,totalBranches):
|
|
|
# TODO and thoughts
|
|
# TODO and thoughts
|
|
|
# in addition to the branch 'id' we need a distance of each point of a branch towards it's parent.
|
|
# in addition to the branch 'id' we need a distance of each point of a branch towards it's parent.
|
|
|
# useful: how many 'levels' are we away from the main parent? > point needs to have parent id, increment on branch
|
|
# useful: how many 'levels' are we away from the main parent? > point needs to have parent id, increment on branch
|
|
|
-
|
|
|
|
|
|
|
+# roots
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|