Johann Woelper пре 10 година
родитељ
комит
5e574033ef
4 измењених фајлова са 34 додато и 31 уклоњено
  1. BIN
      grow.hda
  2. 34 23
      grow.py
  3. BIN
      stag/rigtest.hiplc
  4. 0 8
      stag/stag.mtl

+ 34 - 23
grow.py

@@ -14,7 +14,8 @@ GENERATIONS = hou.ch('generations')
 TROPISM = hou.Vector3(hou.parmTuple("tropDir").eval())
 TROPISMFACTOR = hou.ch('tropStrength')
 GRAVITYFACTOR = hou.ch('gFactor')
-SEED = 1233
+SEED = hou.ch('seed')
+
 #hou.ch("falloff")
 
 # the "seed"
@@ -36,7 +37,7 @@ geo.addAttrib(hou.attribType.Point, 'Diameter', 1.0)
 #defaultGrp.add(point)
 
 
-def duplicatePoint(p):
+def duplicate_point(p):
     # hmm. maybe there is sth like this already, but i missed it...
     # this duplicates a point and all it's attributes.
     dupe=geo.createPoint()
@@ -48,7 +49,8 @@ def duplicatePoint(p):
         dupe.setAttribValue(i, holder)
     return dupe
 
-def tropism(pt,vector,factor):
+
+def tropism(pt, vector, factor):
     '''Move point towards another point, as in growing towards a light source (sun)
        or a food source (roots)
     '''
@@ -56,14 +58,16 @@ def tropism(pt,vector,factor):
     vector = vector.normalized()
     pt.setPosition(P + (1*factor) * vector)
 
-def moveAlongNormal(pt, factor):
+
+def move_along_normal(pt, factor):
     P = pt.position()
     #P = hou.Vector3(P)
     # be careful - this returns a value you cant simply add to P, must convert it to a hou.Vector3
     N = pt.attribValue("N")
     N = hou.Vector3(N)
     pt.setPosition(P + (1*factor) * N)
-   
+
+
 def gravity(pt, factor):
     '''Convenience function to move down a point, multiplied by diameter.'''
     P = pt.position()
@@ -73,13 +77,14 @@ def gravity(pt, factor):
     pt.setPosition(P - G)
 
 
-def createRandomVector():
+def create_random_vector():
     rx = (random.random()-0.5)*2
     ry = (random.random()-0.5)*2
     rz = (random.random()-0.5)*2
     return hou.Vector3([rx, ry, rz])
 
-def addNoiseToNormal(pt, factor):
+
+def add_noise_to_normal(pt, factor):
     N = pt.attribValue("N")
     N = hou.Vector3(N)
     rx = (random.random()-0.5)*2
@@ -91,7 +96,7 @@ def addNoiseToNormal(pt, factor):
     return pt
 
 
-def rotateNormal(pt, factor, seed):
+def rotate_normal(pt, factor, seed):
     N = pt.attribValue("N")
     N = hou.Vector3(N)
     
@@ -110,14 +115,16 @@ def rotateNormal(pt, factor, seed):
     pt.setAttribValue("N", newN)
     return pt
 
-def getPointsByAttribValue(attr, val):
+
+def get_points_by_attrib_value(attr, val):
     plist = []
     for p in geo.iterPoints():
         if p.attribValue(attr) == val:
             plist.append(p)
     return plist
 
-def getHighestNumericAttrVal(points, attr):
+
+def get_highest_numeric_attr_val(points, attr):
     val = 0.0
     for p in points:
         v = float(p.attribValue(attr))
@@ -129,27 +136,31 @@ def getHighestNumericAttrVal(points, attr):
 
 branchNum = 0
 
-def step(pointers,stepseed):
-    ''' step through all head pointers (aka growing branches)'''
+
+def step(pointers, stepseed):
+    """
+    step through all head pointers (aka growing branches)
+    """
     updatedPointers=[]
-    for p in pointers:
+    for pointer in pointers:
         #print 'pointer is point w/ # ' + str(p.number())
-        newP = duplicatePoint(p)
+        newP = duplicate_point(pointer)
         #print 'copy is point w/ # ' + str(newP.number())
         updatedPointers.append(newP)
         newP.setAttribValue('BranchPoint', newP.attribValue('BranchPoint')+1)
         # Should we branch?
         # TODO allow multiple branches at once
         rnd = random.random()
-        rnd = hou.hmath.rand(stepseed+11)
-        if rnd > 0.7:
+        rnd = hou.hmath.rand(stepseed + 11)
+        # BRANCH OFF
+        if rnd > 0.8:
             # Dirty, find a better way soon!
             global branchNum
             branchNum += 1
             global treeInfo
             #treeInfo['totalbranches']+=1
             #print 'branch'
-            branchP = duplicatePoint(p)
+            branchP = duplicate_point(pointer)
             branchP.setAttribValue('BranchPoint', 0)
             b = branchP.attribValue('Branch')
             branchP.setAttribValue('Branch', branchNum)
@@ -158,9 +169,9 @@ def step(pointers,stepseed):
             branchP.setAttribValue('Generation', g + 1)
             updatedPointers.append(branchP)
             stepseed += 1
-        newP = rotateNormal(newP, 0.4, stepseed)
+        newP = rotate_normal(newP, 1.7, stepseed)
         # now move along normal
-        moveAlongNormal(newP, 1)
+        move_along_normal(newP, 1)
         v = hou.Vector3(0, 1, 1)
         tropism(newP, TROPISM, TROPISMFACTOR)
         gravity(newP, GRAVITYFACTOR)
@@ -172,7 +183,7 @@ def step(pointers,stepseed):
     
 x = step(pointers, 1)
 
-seed = 2
+seed = SEED
 for arsch in range(GENERATIONS):
     #seed=1
     x = step(x, seed)
@@ -199,16 +210,16 @@ def postprocess():
 
 
 print '[[[[[[[[[[***]]]]]]]]]]'
-totalBranches = int(getHighestNumericAttrVal(geo.iterPoints(), 'Branch'))
+totalBranches = int(get_highest_numeric_attr_val(geo.iterPoints(), 'Branch'))
 
 for i in range(0,totalBranches):
     # go through all branches
     max = 0
-    for p in getPointsByAttribValue('Branch',i):
+    for p in get_points_by_attrib_value('Branch', i):
         v = p.attribValue('BranchPoint')
         if v > max:
             max = v
-    for p in getPointsByAttribValue('Branch',i):
+    for p in get_points_by_attrib_value('Branch', i):
         bp = p.attribValue('BranchPoint')
         #print max
         #print bp

BIN
stag/rigtest.hiplc


+ 0 - 8
stag/stag.mtl

@@ -1,8 +0,0 @@
-newmtl VoxMtl
-Ns 100.000
-d 1.00000
-illum 2
-Kd 1.00000 1.00000 1.00000
-Ka 0.00000 0.00000 0.00000
-Ks 1.00000 1.00000 1.00000
-Ke 0.00000e+0 0.00000e+0 0.00000e+0