def __updatePrism(self, mesh, o, e, index, p):
            
        dir = aljabr.vsub(e, o) # direction vector from o to e
        len = aljabr.vlen(dir) # distance from o to e
        scale = 0.5 # the thickness is 10% of the length
        i = aljabr.vadd(o, aljabr.vmul(dir, 0.25)) # the thickest part is 25% from o
        n = aljabr.vmul(dir, 1.0 / len) # the normalized direction
        q = aljabr.axisAngleToQuaternion(n, pi / 2.0) # a quaternion to rotate the point p1 to obtain the other points
        p1 = p # a random point in the plane defined by 0,0,0 and n
        p1 = aljabr.vmul(aljabr.vnorm(p1), scale) # the point scaled to the thickness
        p2 = aljabr.quaternionVectorTransform(q, p1) # the other points
        p3 = aljabr.quaternionVectorTransform(q, p2)
        p4 = aljabr.quaternionVectorTransform(q, p3)
        
        p1 = aljabr.vadd(i, p1) # translate by i since we were working in the origin
        p2 = aljabr.vadd(i, p2)
        p3 = aljabr.vadd(i, p3)
        p4 = aljabr.vadd(i, p4)

        # The 6 vertices
        mesh.verts[index].co = o
        mesh.verts[index+1].co = p1
        mesh.verts[index+2].co = p2
        mesh.verts[index+3].co = p3
        mesh.verts[index+4].co = p4
        mesh.verts[index+5].co = e
Пример #2
0
def addPrism(mesh, o=[0.0, 0.0, 0.0], e=[0.0, 1.0, 0.0], name='prism'):
    fg = mesh.createFaceGroup(name)

    dir = aljabr.vsub(e, o)  # direction vector from o to e
    if dir == [0.0, 0.0, 0.0]:
        dir = [0.0, 1.0, 0.0]
    len = aljabr.vlen(dir)  # distance from o to e
    if len == 0:
        len = 1
    scale = 0.5  # the thickness is 10% of the length
    i = aljabr.vadd(o, aljabr.vmul(dir,
                                   0.25))  # the thickest part is 25% from o
    n = aljabr.vmul(dir, 1.0 / len)  # the normalized direction
    q = aljabr.axisAngleToQuaternion(
        n, pi /
        2.0)  # a quaternion to rotate the point p1 to obtain the other points
    p = p1 = aljabr.randomPointFromNormal(
        n)  # a random point in the plane defined by 0,0,0 and n
    p1 = aljabr.vmul(aljabr.vnorm(p1),
                     scale)  # the point scaled to the thickness
    p2 = aljabr.quaternionVectorTransform(q, p1)  # the other points
    p3 = aljabr.quaternionVectorTransform(q, p2)
    p4 = aljabr.quaternionVectorTransform(q, p3)

    p1 = aljabr.vadd(i,
                     p1)  # translate by i since we were working in the origin
    p2 = aljabr.vadd(i, p2)
    p3 = aljabr.vadd(i, p3)
    p4 = aljabr.vadd(i, p4)

    # The 6 vertices
    v = []
    v.append(mesh.createVertex(o))  # 0             0
    v.append(mesh.createVertex(p1))  # 1            /|\
    v.append(mesh.createVertex(p2))  # 2           /.2.\
    v.append(mesh.createVertex(p3))  # 3          1` | `3
    v.append(mesh.createVertex(p4))  # 4          \`.4.`/
    v.append(mesh.createVertex(e))  # 5           \ | /
    #              \|/
    #               5

    # The 8 faces
    fg.createFace((v[0], v[1], v[4], v[0]))
    fg.createFace((v[0], v[4], v[3], v[0]))
    fg.createFace((v[0], v[3], v[2], v[0]))
    fg.createFace((v[0], v[2], v[1], v[0]))
    fg.createFace((v[5], v[4], v[1], v[5]))
    fg.createFace((v[5], v[1], v[2], v[5]))
    fg.createFace((v[5], v[2], v[3], v[5]))
    fg.createFace((v[5], v[3], v[4], v[5]))

    return p
Пример #3
0
def addPrism(mesh, o=[0.0, 0.0, 0.0], e=[0.0, 1.0, 0.0], name='prism'):
    fg = mesh.createFaceGroup(name)

    dir = aljabr.vsub(e, o) # direction vector from o to e
    if dir == [0.0, 0.0, 0.0]:
        dir = [0.0, 1.0, 0.0]
    len = aljabr.vlen(dir) # distance from o to e
    if len == 0:
        len = 1
    scale = 0.5 # the thickness is 10% of the length
    i = aljabr.vadd(o, aljabr.vmul(dir, 0.25)) # the thickest part is 25% from o
    n = aljabr.vmul(dir, 1.0 / len) # the normalized direction
    q = aljabr.axisAngleToQuaternion(n, pi / 2.0) # a quaternion to rotate the point p1 to obtain the other points
    p = p1 = aljabr.randomPointFromNormal(n) # a random point in the plane defined by 0,0,0 and n
    p1 = aljabr.vmul(aljabr.vnorm(p1), scale) # the point scaled to the thickness
    p2 = aljabr.quaternionVectorTransform(q, p1) # the other points
    p3 = aljabr.quaternionVectorTransform(q, p2)
    p4 = aljabr.quaternionVectorTransform(q, p3)
    
    p1 = aljabr.vadd(i, p1) # translate by i since we were working in the origin
    p2 = aljabr.vadd(i, p2)
    p3 = aljabr.vadd(i, p3)
    p4 = aljabr.vadd(i, p4)

    # The 6 vertices
    v = []
    v.append(mesh.createVertex(o))      # 0             0
    v.append(mesh.createVertex(p1))     # 1            /|\
    v.append(mesh.createVertex(p2))     # 2           /.2.\
    v.append(mesh.createVertex(p3))     # 3          1` | `3
    v.append(mesh.createVertex(p4))     # 4          \`.4.`/ 
    v.append(mesh.createVertex(e))      # 5           \ | /
                                        #              \|/
                                        #               5
    
    # The 8 faces
    fg.createFace((v[0], v[1], v[4], v[0]))
    fg.createFace((v[0], v[4], v[3], v[0]))
    fg.createFace((v[0], v[3], v[2], v[0]))
    fg.createFace((v[0], v[2], v[1], v[0]))
    fg.createFace((v[5], v[4], v[1], v[5]))
    fg.createFace((v[5], v[1], v[2], v[5]))
    fg.createFace((v[5], v[2], v[3], v[5]))
    fg.createFace((v[5], v[3], v[4], v[5]))
    
    return p
Пример #4
0
    def scale(self, scale):
        #self.position = vmul(self.position, scale)
        #self.tail = vmul(self.tail, scale)
        self.length = self.length * scale
        self.offset = vmul(self.offset, scale)
        self.calcTransform()

        for child in self.children:
            child.scale(scale)
Пример #5
0
    def scale(self, scale):
        #self.position = vmul(self.position, scale)
        #self.tail = vmul(self.tail, scale)
        self.length = self.length * scale
        self.offset = vmul(self.offset, scale)
        self.calcTransform()

        for child in self.children:
            child.scale(scale)
def hairWidthUpdate(scn, obj,res=0.04, widthFactor=1.0): #luckily both normal and vertex index of object remains the same!
  N=len(obj.verts)
  origWidth = vdist(obj.verts[1].co,obj.verts[0].co)/res
  diff= (widthFactor-origWidth)*res/2
  for i in xrange(0,N/2):
      vec=vmul(vnorm(vsub(obj.verts[i*2+1].co,obj.verts[i*2].co)), diff) 
      obj.verts[i*2].co=vsub(obj.verts[i*2].co,vec)
      obj.verts[i*2+1].co=vadd(obj.verts[i*2+1].co,vec)
      obj.verts[i*2].update(updateNor=0)
      obj.verts[i*2+1].update(updateNor=0)
Пример #7
0
def setupRigJoint(words, obj, verts, locations):
    key = words[0]
    typ = words[1]
    if typ == 'joint':
        loc = mh2proxy.calcJointPos(obj, words[2])
        locations[key] = loc
    elif typ == 'vertex':
        v = int(words[2])
        locations[key] = verts[v].co
    elif typ == 'position':
        x = locations[words[2]]
        y = locations[words[3]]
        z = locations[words[4]]
        locations[key] = [x[0], y[1], z[2]]
    elif typ == 'line':
        k1 = float(words[2])
        k2 = float(words[4])
        locations[key] = vadd(vmul(locations[words[3]], k1),
                              vmul(locations[words[5]], k2))
    elif typ == 'offset':
        x = float(words[3])
        y = float(words[4])
        z = float(words[5])
        locations[key] = vadd(locations[words[2]], [x, y, z])
    elif typ == 'voffset':
        v = int(words[2])
        x = float(words[3])
        y = float(words[4])
        z = float(words[5])
        try:
            loc = verts[v].co
        except:
            loc = verts[v]
        locations[key] = vadd(loc, [x, y, z])
    elif typ == 'front':
        raw = locations[words[2]]
        head = locations[words[3]]
        tail = locations[words[4]]
        offs = map(float, words[5].strip().lstrip('[').rstrip(']').split(','))
        vec = aljabr.vsub(tail, head)
        vec2 = aljabr.vdot(vec, vec)
        vraw = aljabr.vsub(raw, head)
        x = aljabr.vdot(vec, vraw) / vec2
        rvec = aljabr.vmul(vec, x)
        nloc = aljabr.vadd(head, rvec, offs)
        locations[key] = nloc
    else:
        raise NameError("Unknown %s" % typ)
Пример #8
0
def setupRigJoint (words, obj, verts, locations):
    key = words[0]
    typ = words[1]
    if typ == 'joint':
        loc = mh2proxy.calcJointPos(obj, words[2])
        locations[key] = loc
    elif typ == 'vertex':
        v = int(words[2])
        locations[key] = verts[v].co
    elif typ == 'position':
        x = locations[words[2]]
        y = locations[words[3]]
        z = locations[words[4]]
        locations[key] = [x[0],y[1],z[2]]
    elif typ == 'line':
        k1 = float(words[2])
        k2 = float(words[4])
        locations[key] = vadd(vmul(locations[words[3]], k1), vmul(locations[words[5]], k2))
    elif typ == 'offset':
        x = float(words[3])
        y = float(words[4])
        z = float(words[5])
        locations[key] = vadd(locations[words[2]], [x,y,z])
    elif typ == 'voffset':
        v = int(words[2])
        x = float(words[3])
        y = float(words[4])
        z = float(words[5])
        try:
            loc = verts[v].co
        except:
            loc = verts[v]         
        locations[key] = vadd(loc, [x,y,z])
    elif typ == 'front':
        raw = locations[words[2]]
        head = locations[words[3]]
        tail = locations[words[4]]
        offs = map(float, words[5].strip().lstrip('[').rstrip(']').split(','))
        vec = aljabr.vsub(tail, head)
        vec2 = aljabr.vdot(vec, vec)
        vraw = aljabr.vsub(raw, head)
        x = aljabr.vdot(vec, vraw) / vec2
        rvec = aljabr.vmul(vec, x)
        nloc = aljabr.vadd(head, rvec, offs)
        locations[key] = nloc
    else:
        raise NameError("Unknown %s" % typ)
Пример #9
0
def readProxyFile(obj, file, evalOnLoad):
    if not file:
        return CProxy(None, 'Proxy', 2)
    elif type(file) == str or type(file) == unicode:
        pfile = export_config.CProxyFile()
        pfile.file = file
    else:
        pfile = file
    #print "Loading", pfile
    folder = os.path.dirname(pfile.file)
    objfile = None
    
    try:
        tmpl = open(pfile.file, "rU")
    except:
        tmpl = None
    if tmpl == None:
        print ("*** Cannot open", pfile.file)
        return None
        return CProxy(None, pfile.type, pfile.layer)

    verts = obj.verts
    locations = {}
    tails = {}
    proxy = CProxy(pfile.file, pfile.type, pfile.layer)
    proxy.name = "MyProxy"

    useProjection = True
    ignoreOffset = False
    xScale = 1.0
    yScale = 1.0
    zScale = 1.0
    
    status = 0

    vn = 0
    for line in tmpl:
        words= line.split()
        if len(words) == 0:
            pass
        elif words[0] == '#':
            theGroup = None
            if len(words) == 1:
                continue
            key = words[1]
            if key == 'verts':
                if evalOnLoad:
                    status = doVerts
                else:
                    status = doRefVerts
            elif key == 'faces':
                status = doFaces
            elif key == 'weights':
                status = doWeights
                if proxy.weights == None:
                    proxy.weights = {}
                weights = []
                proxy.weights[words[2]] = weights
            elif key == 'material':
                status = doMaterial
                proxy.material.name = stringFromWords(words[2:])
            elif key == 'useBaseMaterials':
                proxy.useBaseMaterials = True
            elif key == 'faceNumbers':
                status = doFaceNumbers
            elif key == 'texVerts':
                status = doTexVerts
                if len(words) > 2:
                    layer = int(words[2])
                else:
                    layer = 0
                proxy.texVerts = []
                proxy.texVertsLayers[layer] = proxy.texVerts
            elif key == 'texFaces':
                status = doTexFaces
                if len(words) > 2:
                    layer = int(words[2])
                else:
                    layer = 0
                proxy.texFaces = []
                proxy.texFacesLayers[layer] = proxy.texFaces
            elif key == 'obj_data':
                status = doObjData
                proxy.texVerts = []
                proxy.texFaces = []
                proxy.texVertsLayers[0] = proxy.texVerts
                proxy.texFacesLayers[0] = proxy.texFaces                
            elif key == 'name':
                proxy.name = stringFromWords(words[2:])
            elif key == 'uuid':
                proxy.uuid = stringFromWords(words[2:])
            elif key == 'tag':
                proxy.tags.append( stringFromWords(words[2:]) )
            elif key == 'z_depth':
                proxy.z_depth = int(words[2])
            elif key == 'wire':
                proxy.wire = True
            elif key == 'cage':
                proxy.cage = True
            elif key == 'x_scale':
                proxy.xScaleData = getScaleData(words)
                xScale = getScale(proxy.xScaleData, verts, 0)
            elif key == 'y_scale':
                proxy.yScaleData = getScaleData(words)
                yScale = getScale(proxy.yScaleData, verts, 1)
            elif key == 'z_scale':
                proxy.zScaleData = getScaleData(words)
                zScale = getScale(proxy.zScaleData, verts, 2)
            elif key == 'use_projection':
                useProjection = int(words[2])
            elif key == 'ignoreOffset':
                ignoreOffset = int(words[2])
            elif key == 'delete':
                proxy.deleteGroups.append(words[2])
            elif key == 'delete_connected':
                selectConnected(proxy, obj, int(words[2]))
            elif key == 'rig':
                proxy.rig = getFileName(folder, words[2], ".rig")
            elif key == 'mask':
                proxy.mask = getFileName(folder, words[2], ".png")
                if len(words) > 3:
                    proxy.maskLayer = int(words[3])
            elif key == 'bump':
                proxy.bump = getFileName(folder, words[2], ".tif")
                if len(words) > 4:
                    proxy.bumpStrength = float(words[4])
            elif key == 'normal':
                proxy.normal = getFileName(folder, words[2], ".tif")
                if len(words) > 4:
                    proxy.normalStrength = float(words[4])
            elif key == 'transparency':
                proxy.transparency = getFileName(folder, words[2], ".tif")
            elif key == 'displacement':
                proxy.displacement = getFileName(folder, words[2], ".tif")
                if len(words) > 4:
                    proxy.dispStrength = float(words[4])
            elif key == 'texture':
                proxy.texture = getFileName(folder, words[2], ".tif")
                if len(words) > 3:
                    proxy.textureLayer = int(words[3])
            elif key == 'objfile_layer':
                proxy.objFileLayer = int(words[2])
            elif key == 'uvtex_layer':
                proxy.uvtexLayerName[int(words[2])] = words[3]
            elif key == 'material_file':
                proxy.material_file = getFileName(folder, words[2], ".mhx")
            elif key == 'obj_file':
                proxy.obj_file = getFileName(folder, words[2], ".obj")
            elif key == 'clothing':
                proxy.clothings.append(words[2])
            elif key == 'subsurf':
                levels = int(words[2])
                if len(words) > 3:
                    render = int(words[3])
                else:
                    render = levels+1
                proxy.modifiers.append( ['subsurf', levels, render] )
            elif key == 'shrinkwrap':
                offset = float(words[2])
                proxy.modifiers.append( ['shrinkwrap', offset] )
            elif key == 'solidify':
                thickness = float(words[2])
                offset = float(words[3])
                proxy.modifiers.append( ['solidify', thickness, offset] )
            elif key == 'shapekey':
                proxy.shapekeys.append( words[2] )
            elif key == 'basemesh':
                proxy.basemesh = words[2]
            else:
                pass
                #print "Ignored proxy keyword", key
        elif status == doObjData:
            if words[0] == 'vt':
                newTexVert(1, words, proxy)
            elif words[0] == 'f':
                newFace(1, words, theGroup, proxy)
            elif words[0] == 'g':
                theGroup = words[1]
        elif status == doFaceNumbers:
            proxy.faceNumbers.append(line)
        elif status == doRefVerts:
            if len(words) == 1:
                v = int(words[0])
                proxy.refVerts.append(v)
            else:                
                v0 = int(words[0])
                v1 = int(words[1])
                v2 = int(words[2])
                w0 = float(words[3])
                w1 = float(words[4])
                w2 = float(words[5])            
                if len(words) > 6:
                    d0 = float(words[6])
                    d1 = float(words[7])
                    d2 = float(words[8])
                else:
                    (d0,d1,d2) = (0,0,0)
                proxy.refVerts.append( (v0,v1,v2,w0,w1,w2,d0,d1,d2) )
        elif status == doVerts:
            if len(words) == 1:
                v = int(words[0])
                proxy.realVerts.append(verts[v])
                addProxyVert(v, vn, 1, proxy)
            else:                
                v0 = int(words[0])
                v1 = int(words[1])
                v2 = int(words[2])
                w0 = float(words[3])
                w1 = float(words[4])
                w2 = float(words[5])            

                if len(words) < 7 or ignoreOffset:
                    (d0, d1, d2) = (0, 0, 0)
                elif useProjection:
                    proj = float(words[6])
                    n0 = aljabr.vmul(verts[v0].no, w0)
                    n1 = aljabr.vmul(verts[v1].no, w1)
                    n2 = aljabr.vmul(verts[v2].no, w2)
                    norm = aljabr.vadd(n0, n1)
                    norm = aljabr.vadd(norm, n2)
                    d0 = proj * norm[0] * xScale
                    d1 = proj * norm[1] * yScale
                    d2 = proj * norm[2] * zScale
                else:
                    d0 = float(words[6]) * xScale
                    d1 = float(words[7]) * yScale
                    d2 = float(words[8]) * zScale

                proxy.realVerts.append((verts[v0], verts[v1], verts[v2], w0, w1, w2, d0, d1, d2))
                addProxyVert(v0, vn, w0, proxy)
                addProxyVert(v1, vn, w1, proxy)
                addProxyVert(v2, vn, w2, proxy)
            vn += 1
        elif status == doFaces:
            newFace(0, words, theGroup, proxy)
        elif status == doTexVerts:
            newTexVert(0, words, proxy)
        elif status == doTexFaces:
            newTexFace(words, proxy)
        elif status == doMaterial:
            readMaterial(line, proxy.material, proxy, False)
        elif status == doWeights:
            v = int(words[0])
            w = float(words[1])
            weights.append((v,w))
            
    if evalOnLoad and proxy.obj_file:
        if not copyObjFile(proxy):
            return None

    if pfile.name:
        proxy.name = pfile.name
    return proxy
Пример #10
0
    def generateHairInterpolation2(self,guide1,guide2,humanMesh,isCollision,startIndex=9,gravity=True):
        if isCollision: octree = simpleoctree.SimpleOctree(humanMesh.getData().verts,0.08)
        hairName = "strand%s-%s"%(guide1.name,guide2.name)
        hSet = HairGroup(hairName)

        if len(guide1.controlPoints)>= len(guide2.controlPoints):
            longerGuide = guide1
            shorterGuide = guide2
        else:
            longerGuide = guide2
            shorterGuide = guide1

        nVerts = min([len(guide1.controlPoints),len(guide2.controlPoints)])
        interpFactor = 0
        vertsListToModify1 = []
        vertsListToModify2 = []

        for n in range (self.numberOfHairsMultiStrand):
            h = Hair()
            interpFactor += 1.0/self.numberOfHairsMultiStrand
            for i in range(len(longerGuide.controlPoints)):
                if random.random() < self.randomPercentage:
                    xRand = self.sizeMultiStrand*random.random()*self.randomFactMultiStrand
                    yRand = self.sizeMultiStrand*random.random()*self.randomFactMultiStrand
                    zRand = self.sizeMultiStrand*random.random()*self.randomFactMultiStrand
                    randomVect = [xRand,yRand,zRand]
                else:
                    randomVect = [0,0,0]

                if i == 0:
                    i2 = 0
                if i == len(longerGuide.controlPoints)-1:
                    i2 = len(shorterGuide.controlPoints)-1
                else:
                    i2 = int(round(i*len(shorterGuide.controlPoints)/len(longerGuide.controlPoints)))

                vert1 = longerGuide.controlPoints[i]
                vert2 = shorterGuide.controlPoints[i2]

                #Slerp
                dotProd = aljabr.vdot(aljabr.vnorm(vert1),aljabr.vnorm(vert2))
                #Python has a very very bad numerical accuracy.. we need to do this for very small angle between guides 
                #this occurs when we do collision detection
                if dotProd>1: 
                    angleBetweenGuides = 0.0
                else:
                    angleBetweenGuides = math.acos(aljabr.vdot(aljabr.vnorm(vert1),aljabr.vnorm(vert2)))
                denom = math.sin(angleBetweenGuides)
                if denom == 0.0: #controlpoints of some guides coincide
                    vert1[0] = self.randomPercentage*self.sizeMultiStrand*random.random()*self.randomFactMultiStrand+vert1[0]
                    vert1[1] = self.randomPercentage*self.sizeMultiStrand*random.random()*self.randomFactMultiStrand+vert1[1]
                    vert1[2] = self.randomPercentage*self.sizeMultiStrand*random.random()*self.randomFactMultiStrand+vert1[2]
                    vert1= aljabr.vadd(vert1,randomVect)
                    angleBetweenGuides = math.acos(aljabr.vdot(aljabr.vnorm(vert1),aljabr.vnorm(vert2)))
                    denom = math.sin(angleBetweenGuides)
                f1 = math.sin((1-interpFactor)*angleBetweenGuides)/denom
                f2 = math.sin(interpFactor*angleBetweenGuides)/denom
                newVert = aljabr.vadd(aljabr.vmul(vert1,f1),aljabr.vmul(vert2,f2))

                #Uncomment the following line we use lerp instead slerp
                #newVert = aljabr.vadd(aljabr.vmul(vert1,(1-interpFactor)),aljabr.vmul(vert2,interpFactor))
                h.controlPoints.append([newVert[0]+randomVect[0],\
                                                newVert[1]+randomVect[1],\
                                                newVert[2]+randomVect[2]])
            if isCollision:
                print "h is: ", h.controlPoints
                for j in (0,len(h.controlPoints)):
                    #print "h.controlPts is : ", h.controlPoints[i]
                    #print "h.controlPts[i] length is: ", len(h.controlPoints[i])
                    h.controlPoints[i][2] = -h.controlPoints[i][2] #Renderman to Blender coordinates!
                collision(h.controlPoints,humanMesh,octree.minsize,startIndex,gravity)
                for j in (0,len(h.controlPoints)):
                    h.controlPoints[i][2] = -h.controlPoints[i][2] #Blender to Renderman coordinates!
            hSet.hairs.append(h)
        self.hairStyle.append(hSet)
Пример #11
0
def readProxyFile(obj, file, evalOnLoad):
    if not file:
        return CProxy(None, 'Proxy', 2)
    elif type(file) == str or type(file) == unicode:
        pfile = export_config.CProxyFile()
        pfile.file = file
    else:
        pfile = file
    #print "Loading", pfile
    folder = os.path.dirname(pfile.file)
    objfile = None
    
    try:
        tmpl = open(pfile.file, "rU")
    except:
        tmpl = None
    if tmpl == None:
        log.error("*** Cannot open %s", pfile.file)
        return None
        return CProxy(None, pfile.type, pfile.layer)

    verts = obj.verts
    locations = {}
    tails = {}
    proxy = CProxy(pfile.file, pfile.type, pfile.layer)
    proxy.deleteVerts = np.zeros(len(verts), bool)
    proxy.name = "MyProxy"

    useProjection = True
    ignoreOffset = False
    xScale = 1.0
    yScale = 1.0
    zScale = 1.0
    
    status = 0

    vn = 0
    for line in tmpl:
        words= line.split()
        if len(words) == 0:
            pass
        elif words[0] == '#':
            theGroup = None
            if len(words) == 1:
                continue
            key = words[1]
            if key == 'verts':
                if evalOnLoad:
                    status = doVerts
                else:
                    status = doRefVerts
            elif key == 'faces':
                status = doFaces
            elif key == 'weights':
                status = doWeights
                if proxy.weights == None:
                    proxy.weights = {}
                weights = []
                proxy.weights[words[2]] = weights
            elif key == 'material':
                status = doMaterial
                proxy.material.name = stringFromWords(words[2:])
            elif key == 'useBaseMaterials':
                proxy.useBaseMaterials = True
            elif key == 'faceNumbers':
                status = doFaceNumbers
            elif key == 'texVerts':
                status = doTexVerts
                if len(words) > 2:
                    layer = int(words[2])
                else:
                    layer = 0
                proxy.texVerts = []
                proxy.texVertsLayers[layer] = proxy.texVerts
            elif key == 'texFaces':
                status = doTexFaces
                if len(words) > 2:
                    layer = int(words[2])
                else:
                    layer = 0
                proxy.texFaces = []
                proxy.texFacesLayers[layer] = proxy.texFaces
            elif key == 'obj_data':
                status = doObjData
                proxy.texVerts = []
                proxy.texFaces = []
                proxy.texVertsLayers[0] = proxy.texVerts
                proxy.texFacesLayers[0] = proxy.texFaces     
            elif key == 'name':
                proxy.name = stringFromWords(words[2:])
            elif key == 'uuid':
                proxy.uuid = stringFromWords(words[2:])
            elif key == 'tag':
                proxy.tags.append( stringFromWords(words[2:]) )
            elif key == 'z_depth':
                proxy.z_depth = int(words[2])
            elif key == 'wire':
                proxy.wire = True
            elif key == 'cage':
                proxy.cage = True
            elif key == 'x_scale':
                proxy.xScaleData = getScaleData(words)
                xScale = getScale(proxy.xScaleData, verts, 0)
            elif key == 'y_scale':
                proxy.yScaleData = getScaleData(words)
                yScale = getScale(proxy.yScaleData, verts, 1)
            elif key == 'z_scale':
                proxy.zScaleData = getScaleData(words)
                zScale = getScale(proxy.zScaleData, verts, 2)
            elif key == 'use_projection':
                useProjection = int(words[2])
            elif key == 'ignoreOffset':
                ignoreOffset = int(words[2])
            elif key == 'delete':
                proxy.deleteGroups.append(words[2])
            elif key == 'delete_connected':
                selectConnected(proxy, obj, int(words[2]))
            elif key == "delete_verts":
                status = doDeleteVerts
            elif key == 'rig':
                proxy.rig = getFileName(folder, words[2], ".rig")
            elif key == 'mask':
                proxy.mask = getFileName(folder, words[2], ".png")
                if len(words) > 3:
                    proxy.maskLayer = int(words[3])
            elif key == 'specular':
                proxy.specular = getFileName(folder, words[2], ".png")
                if len(words) > 4:
                    proxy.specularStrength = float(words[4])
            elif key == 'bump':
                proxy.bump = getFileName(folder, words[2], ".png")
                if len(words) > 4:
                    proxy.bumpStrength = float(words[4])
            elif key == 'normal':
                proxy.normal = getFileName(folder, words[2], ".png")
                if len(words) > 4:
                    proxy.normalStrength = float(words[4])
            elif key == 'transparency':
                proxy.transparency = getFileName(folder, words[2], ".png")
            elif key == 'displacement':
                proxy.displacement = getFileName(folder, words[2], ".png")
                if len(words) > 4:
                    proxy.dispStrength = float(words[4])
            elif key == 'texture':
                proxy.texture = getFileName(folder, words[2], ".png")
                if len(words) > 3:
                    proxy.textureLayer = int(words[3])
            elif key == 'objfile_layer':
                proxy.objFileLayer = int(words[2])
            elif key == 'uvtex_layer':
                proxy.uvtexLayerName[int(words[2])] = words[3]
            elif key == 'material_file':
                pass
                #proxy.material_file = getFileName(folder, words[2], ".mhx")
            elif key == 'obj_file':
                proxy.obj_file = getFileName(folder, words[2], ".obj")
            elif key == 'backface_culling':
                proxy.cull = words[2].lower() in ["1", "yes", "true", "enable", "enabled"]
            elif key == 'transparent':
                proxy.transparent = words[2].lower() in ["1", "yes", "true", "enable", "enabled"]
            elif key == 'clothing':
                if len(words) > 3:
                    clothingPiece = (words[2], words[3])
                else:
                    clothingPiece = (words[2], None)
                proxy.clothings.append(clothingPiece)
            elif key == 'transparencies':
                uuid = words[2]
                proxy.transparencies[uuid] = words[3].lower() in ["1", "yes", "true", "enable", "enabled"]
            elif key == 'textures':
                proxy.textures.append( (words[2], words[3]) )
            elif key == 'subsurf':
                levels = int(words[2])
                if len(words) > 3:
                    render = int(words[3])
                else:
                    render = levels+1
                proxy.modifiers.append( ['subsurf', levels, render] )
            elif key == 'shrinkwrap':
                offset = float(words[2])
                proxy.modifiers.append( ['shrinkwrap', offset] )
            elif key == 'solidify':
                thickness = float(words[2])
                offset = float(words[3])
                proxy.modifiers.append( ['solidify', thickness, offset] )
            elif key == 'shapekey':
                proxy.shapekeys.append( words[2] )
            elif key == 'basemesh':
                proxy.basemesh = words[2]
            else:
                pass
                #print "Ignored proxy keyword", key
        elif status == doObjData:
            if words[0] == 'vt':
                newTexVert(1, words, proxy)
            elif words[0] == 'f':
                newFace(1, words, theGroup, proxy)
            elif words[0] == 'g':
                theGroup = words[1]
        elif status == doFaceNumbers:
            proxy.faceNumbers.append(line)
        elif status == doRefVerts:
            if len(words) == 1:
                v = int(words[0])
                proxy.refVerts.append(v)
            else:                
                v0 = int(words[0])
                v1 = int(words[1])
                v2 = int(words[2])
                w0 = float(words[3])
                w1 = float(words[4])
                w2 = float(words[5])            
                if len(words) > 6:
                    d0 = float(words[6])
                    d1 = float(words[7])
                    d2 = float(words[8])
                else:
                    (d0,d1,d2) = (0,0,0)
                proxy.refVerts.append( (v0,v1,v2,w0,w1,w2,d0,d1,d2) )
        elif status == doVerts:
            if len(words) == 1:
                v = int(words[0])
                proxy.realVerts.append(verts[v])
                addProxyVert(v, vn, 1, proxy)
            else:                
                v0 = int(words[0])
                v1 = int(words[1])
                v2 = int(words[2])
                w0 = float(words[3])
                w1 = float(words[4])
                w2 = float(words[5])            

                if len(words) < 7 or ignoreOffset:
                    (d0, d1, d2) = (0, 0, 0)
                elif useProjection:
                    proj = float(words[6])
                    n0 = aljabr.vmul(verts[v0].no, w0)
                    n1 = aljabr.vmul(verts[v1].no, w1)
                    n2 = aljabr.vmul(verts[v2].no, w2)
                    norm = aljabr.vadd(n0, n1)
                    norm = aljabr.vadd(norm, n2)
                    d0 = proj * norm[0] * xScale
                    d1 = proj * norm[1] * yScale
                    d2 = proj * norm[2] * zScale
                else:
                    d0 = float(words[6]) * xScale
                    d1 = float(words[7]) * yScale
                    d2 = float(words[8]) * zScale

                proxy.realVerts.append((verts[v0], verts[v1], verts[v2], w0, w1, w2, d0, d1, d2))
                addProxyVert(v0, vn, w0, proxy)
                addProxyVert(v1, vn, w1, proxy)
                addProxyVert(v2, vn, w2, proxy)
            vn += 1
        elif status == doFaces:
            newFace(0, words, theGroup, proxy)
        elif status == doTexVerts:
            newTexVert(0, words, proxy)
        elif status == doTexFaces:
            newTexFace(words, proxy)
        elif status == doMaterial:
            readMaterial(line, proxy.material, proxy, False)
        elif status == doWeights:
            v = int(words[0])
            w = float(words[1])
            weights.append((v,w))
        elif status == doDeleteVerts:
            sequence = False
            for v in words:            
                if v == "-":
                    sequence = True
                else:
                    v1 = int(v)
                    if sequence:
                        for vn in range(v0,v1+1):
                            proxy.deleteVerts[vn] = True
                        sequence = False                            
                    else:
                        proxy.deleteVerts[v1] = True
                    v0 = v1
                        
            
    if evalOnLoad and proxy.obj_file:
        if not copyObjFile(proxy):
            return None

    if pfile.name:
        proxy.name = pfile.name
    return proxy
Пример #12
0
def newSetupJoints(obj, joints):
    the.Locations = {}
    for (key, typ, data) in joints:
        #print(key)
        if typ == 'j':
            loc = mh2proxy.calcJointPos(obj, data)
            the.Locations[key] = loc
            the.Locations[data] = loc
        elif typ == 'v':
            v = int(data)
            the.Locations[key] = obj.verts[v].co
        elif typ == 'x':
            the.Locations[key] = [
                float(data[0]),
                float(data[2]), -float(data[1])
            ]
        elif typ == 'vo':
            v = int(data[0])
            loc = obj.verts[v].co
            the.Locations[key] = [
                loc[0] + float(data[1]), loc[1] + float(data[3]),
                loc[2] - float(data[2])
            ]
        elif typ == 'vl':
            ((k1, v1), (k2, v2)) = data
            loc1 = obj.verts[int(v1)].co
            loc2 = obj.verts[int(v2)].co
            the.Locations[key] = vadd(vmul(loc1, k1), vmul(loc2, k2))
        elif typ == 'f':
            (raw, head, tail, offs) = data
            rloc = the.Locations[raw]
            hloc = the.Locations[head]
            tloc = the.Locations[tail]
            #print(raw, rloc)
            vec = aljabr.vsub(tloc, hloc)
            vec2 = aljabr.vdot(vec, vec)
            vraw = aljabr.vsub(rloc, hloc)
            x = aljabr.vdot(vec, vraw) / vec2
            rvec = aljabr.vmul(vec, x)
            nloc = aljabr.vadd(hloc, rvec, offs)
            #print(key, nloc)
            the.Locations[key] = nloc
        elif typ == 'b':
            the.Locations[key] = the.Locations[data]
        elif typ == 'p':
            x = the.Locations[data[0]]
            y = the.Locations[data[1]]
            z = the.Locations[data[2]]
            the.Locations[key] = [x[0], y[1], z[2]]
        elif typ == 'vz':
            v = int(data[0])
            z = obj.verts[v].co[2]
            loc = the.Locations[data[1]]
            the.Locations[key] = [loc[0], loc[1], z]
        elif typ == 'X':
            r = the.Locations[data[0]]
            (x, y, z) = data[1]
            r1 = [float(x), float(y), float(z)]
            the.Locations[key] = aljabr.vcross(r, r1)
        elif typ == 'l':
            ((k1, joint1), (k2, joint2)) = data
            the.Locations[key] = vadd(vmul(the.Locations[joint1], k1),
                                      vmul(the.Locations[joint2], k2))
        elif typ == 'o':
            (joint, offsSym) = data
            if type(offsSym) == str:
                offs = the.Locations[offsSym]
            else:
                offs = offsSym
            the.Locations[key] = vadd(the.Locations[joint], offs)
        else:
            raise NameError("Unknown %s" % typ)
    return
Пример #13
0
def newSetupJoints (obj, joints):
    the.Locations = {}
    for (key, typ, data) in joints:
        #print(key)
        if typ == 'j':
            loc = mh2proxy.calcJointPos(obj, data)
            the.Locations[key] = loc
            the.Locations[data] = loc
        elif typ == 'v':
            v = int(data)
            the.Locations[key] = obj.verts[v].co
        elif typ == 'x':
            the.Locations[key] = [float(data[0]), float(data[2]), -float(data[1])]
        elif typ == 'vo':
            v = int(data[0])
            loc = obj.verts[v].co
            the.Locations[key] = [loc[0]+float(data[1]), loc[1]+float(data[3]), loc[2]-float(data[2])]
        elif typ == 'vl':
            ((k1, v1), (k2, v2)) = data
            loc1 = obj.verts[int(v1)].co
            loc2 = obj.verts[int(v2)].co
            the.Locations[key] = vadd(vmul(loc1, k1), vmul(loc2, k2))
        elif typ == 'f':
            (raw, head, tail, offs) = data
            rloc = the.Locations[raw]
            hloc = the.Locations[head]
            tloc = the.Locations[tail]
            #print(raw, rloc)
            vec = aljabr.vsub(tloc, hloc)
            vec2 = aljabr.vdot(vec, vec)
            vraw = aljabr.vsub(rloc, hloc)
            x = aljabr.vdot(vec, vraw) / vec2
            rvec = aljabr.vmul(vec, x)
            nloc = aljabr.vadd(hloc, rvec, offs)
            #print(key, nloc)
            the.Locations[key] = nloc
        elif typ == 'b':
            the.Locations[key] = the.Locations[data]
        elif typ == 'p':
            x = the.Locations[data[0]]
            y = the.Locations[data[1]]
            z = the.Locations[data[2]]
            the.Locations[key] = [x[0],y[1],z[2]]
        elif typ == 'vz':
            v = int(data[0])
            z = obj.verts[v].co[2]
            loc = the.Locations[data[1]]
            the.Locations[key] = [loc[0],loc[1],z]
        elif typ == 'X':
            r = the.Locations[data[0]]
            (x,y,z) = data[1]
            r1 = [float(x), float(y), float(z)]
            the.Locations[key] = aljabr.vcross(r, r1)
        elif typ == 'l':
            ((k1, joint1), (k2, joint2)) = data
            the.Locations[key] = vadd(vmul(the.Locations[joint1], k1), vmul(the.Locations[joint2], k2))
        elif typ == 'o':
            (joint, offsSym) = data
            if type(offsSym) == str:
                offs = the.Locations[offsSym]
            else:
                offs = offsSym
            the.Locations[key] = vadd(the.Locations[joint], offs)
        else:
            raise NameError("Unknown %s" % typ)
    return