Example #1
0
def blenderCurves2MHData():
    global hairsClass
    #Note the coords are saved in global (absolute) coords.
    hairsClass.resetHairs()
    hairCounter = 0
    groups = Group.Get()
    for group in groups:
        print "GROUP",group
        g = hairsClass.addGuideGroup(group.name)
        for obj in list(group.objects):
            data = obj.getData()
            name = obj.getName()
            if type(data) == Types.CurveType:
                matr = obj.getMatrix()
                controlPoints = []
                for curnurb in data:
                    for p in curnurb:
                        p1 = [p[0],p[1],p[2]]
                        worldP = local2World(p1,matr) #convert the point in absolute coords
                        p2 = [worldP[0],worldP[1],worldP[2]] #convert from Blender coord to Renderman coords
                        controlPoints.append(p2)
                    hairsClass.addHairGuide(controlPoints, name, g)
                    hairCounter += 1
Example #2
0
def bevent(evt):
    global tipMagnet,hairDiameterClump,hairDiameterMultiStrand
    global numberOfHairsClump,numberOfHairsMultiStrand,randomFactClump
    global randomFactMultiStrand,randomPercentage,sizeClump,sizeMultiStrand
    global blendDistance,sizeMultiStrand,rootCOlor,tipCOlor, humanMesh
    global noGuides, noCPoints, gLength, gFactor

    if   (evt== 1): Exit()

    elif (evt== 2):
        saveRib("hair-test.rib")

    elif (evt== 3):

        hairsClass.tipMagnet = tipMagnet.val
        hairsClass.hairDiameterClump = hairDiameterClump.val
        hairsClass.hairDiameterMultiStrand = hairDiameterMultiStrand.val
        hairsClass.numberOfHairsClump= numberOfHairsClump.val
        hairsClass.numberOfHairsMultiStrand= numberOfHairsMultiStrand.val
        hairsClass.randomFactClump= randomFactClump.val
        hairsClass.randomFactMultiStrand= randomFactMultiStrand.val
        hairsClass.randomPercentage= randomPercentage.val
        hairsClass.sizeClump= sizeClump.val
        hairsClass.sizeMultiStrand= sizeMultiStrand.val
        hairsClass.blendDistance= blendDistance.val
        hairsClass.tipColor= tipColor.val
        hairsClass.rootColor= rootColor.val
        hairsClass.noGuides = noGuides.val
        hairsClass.noCPoints = noCPoints.val
        hairsClass.gLength = gLength.val
        hairsClass.gFactor = gFactor.val

    elif (evt== 4):
        Window.FileSelector (saveHairsFile, "Save hair data")
    elif (evt== 5):
        Window.FileSelector (loadHairsFile, "Load hair data")
    elif (evt==8):
        scn = Scene.GetCurrent() #get current scene
        mesh = humanMesh.getData()
        mat = humanMesh.getMatrix()
        verts=[]
        for v in mesh.verts: #reduces vertices for simplifying octree, improves performance
            if v.co[0]<=2 and v.co[0]>=-2 and v.co[1]<=8.6 and v.co[1]>=3.6: #2D bounding box between head and chest
                verts.append(local2World(v.co,mat)) #localspace to worldspace
        octree = simpleoctree.SimpleOctree(verts,0.09)
        for obj in scn.objects:
            if obj.type == "Curve":
                data = obj.getData()
                if data[0].isNurb():
                    mat = obj.getMatrix()
                    curve=[]
                    for p in data[0]:
                        curve.append(local2World([p[0],p[1],p[2]],mat))
                    collision(curve,humanMesh,octree.minsize,9,True) #collision will after 9th controlPoint!!!
                    N=data.getNumPoints(0)
                    if N<len(curve):
                        #Window.SetCursorPos(curve[len(curve)-1])
                        for i in range(0,len(curve)):
                            temp = world2Local(curve[i],mat)
                            if i < N: 
                                data.setControlPoint(0,i,[temp[0],temp[1],temp[2],1])
                            else: 
                                data.appendPoint(0,[temp[0],temp[1],temp[2],1])
                        #data[0].recalc()
                        data.update()
        Blender.Redraw()
    elif (evt==9):
        #noCPoints=15
        mesh = humanMesh.getData()
        #scalp = 269 vertices!
        vertIndices = mesh.getVertsFromGroup("part_head-back-skull")
        vertIndices.extend(mesh.getVertsFromGroup("part_head-upper-skull"))
        vertIndices.extend(mesh.getVertsFromGroup("part_l-head-temple"))
        vertIndices.extend(mesh.getVertsFromGroup("part_r-head-temple"))
        scalpVerts = len(vertIndices) #Collects all vertices that are part of the head where hair grows!
        interval = int(scalpVerts/noGuides.val) #variable used to randomly distribute scalp-vertices
        cPInterval = gLength.val/float(noCPoints.val) #Length between c.P. for hairs being generated
        #print "cPInterval is : ", cPInterval
        scn = Scene.GetCurrent() #get current scene
        for i in range(0,noGuides.val):
            if i==noGuides.val-1:
                r= random.randint(interval*i,scalpVerts-1)
            else:    
                r = random.randint(interval*i,interval*(i+1))
            v= mesh.verts[vertIndices[r]].co
            normal = mesh.verts[vertIndices[r]].no
            point2 = vadd(v,vmul(normal,gLength.val))
            curve=[vadd(v,vmul(normal,-0.5))]
            w,normal2,point22,curve2 =[],[],[],[]
            for j in range(0,scalpVerts):
                w=mesh.verts[vertIndices[j]].co
                dist = vdist(v,w)
                if dist>=0.05 and dist<=0.3:
                    normal2=mesh.verts[vertIndices[j]].no
                    point22 = vadd(w,vmul(normal2,gLength.val))
                    curve2=[vadd(w,vmul(normal2,-0.5))]
                    break
            curve.append(vadd(v,vmul(normal,-0.2)))
            curve2.append(vadd(w,vmul(normal2,-0.2)))
            for j in range(1,noCPoints.val-1):
                curve.append(vadd(v,vmul(normal,cPInterval*j)))
                curve2.append(vadd(w,vmul(normal2,cPInterval*j)))
            curve.append(point2)
            curve2.append(point22)
            drawGuidePair(scn,curve[:],curve2[:])
        #r= random.randint(interval*(noGuides.val-1),scalpVerts-1)
        Blender.Redraw()
    elif (evt==10):
        selected = Blender.Object.GetSelected()
        start=1 #starting c.P. to use gravity!
        for obj in selected:
            if obj.type == "Curve": #we use virtual Young's modulus
                data= obj.getData()
                if data[0].isNurb():
                    mat = obj.getMatrix()
                    curve=[]
                    for p in data[0]:
                        curve.append(local2World([p[0],p[1],p[2]],mat))
                    gravitize(curve,start,mat,gFactor.val)
                    for i in range(start,len(curve)):
                        temp = world2Local(curve[i],mat)
                        data.setControlPoint(0,i,[temp[0],temp[1],temp[2],1])
                    data.update()
        Blender.Redraw()
    elif (evt==11):
        groups = Group.Get()
        for grp in groups:
            obj1, obj2 = grp.objects[0], grp.objects[1]
            if obj1.type == "Curve" and obj2.type == "Curve":
                data1, data2 = obj1.getData(), obj2.getData()
                if data1[0].isNurb() and data2[0].isNurb():
                    mat1, mat2 = obj1.getMatrix(), obj2.getMatrix()
                    curve1,curve2=[],[]
                    l1,l2 = list(data1[0]), list(data2[0])
                    for i in range(0,len(l1)):
                        curve1.append(local2World([l1[i][0],l1[i][1],l1[i][2]],mat1))
                        curve2.append(local2World([l2[i][0],l2[i][1],l2[i][2]],mat2))
                    clamp(curve1,curve2)
                    for i in range(0, len(curve1)):
                        temp = world2Local(curve1[i],mat1)
                        data1.setControlPoint(0,i,[temp[0],temp[1],temp[2],1])
                        temp = world2Local(curve2[i],mat2)
                        data2.setControlPoint(0,i,[temp[0],temp[1],temp[2],1])
                    data1.update()
                    data2.update()
        Blender.Redraw()