def updateOriginalVert(v):
    
    if not v.data[1] or not v.data[2]: # Joint vertex
        return
      
    n = len(v.data[1])
    if n == len(v.data[2]): # Inner vertex
        faceVertAvg = centroid([fv.co for fv in v.data[1]])
        edgeVertAvg = centroid([ev.co for ev in v.data[2]])
        v.co = vmul3d(vadd3d(vadd3d(faceVertAvg, vmul3d(edgeVertAvg, 2.0)), vmul3d(v.data[0].co, n - 3.0)), 1.0/n)
    else: # Outer vertex
        v.co = centroid([ev.co for ev in v.data[2] if len(ev.data) == 3]+[v.data[0].co])
Beispiel #2
0
    def setCameraGroupsViewDistance(self, groupNames, view='front', distance=10):

        human = self.selectedHuman
        vertices = human.meshData.getCoords(human.meshData.getVerticesForGroups(groupNames))
        center = centroid(vertices)

        self.setCameraCenterViewDistance(center, view, distance)
Beispiel #3
0
    def setCameraGroupsViewDistance(self, groupNames, view='front', distance=10):

        human = self.selectedHuman
        vertices = human.meshData.getCoords(human.meshData.getVerticesForGroups(groupNames))
        center = centroid(vertices)

        self.setCameraCenterViewDistance(center, view, distance)
Beispiel #4
0
def calcJointPos(obj, joint):
    g = obj.getFaceGroup("joint-"+joint)
    verts = []
    for f in g.faces:
        for v in f.verts:
            verts.append(v.co)
    return aljabr.centroid(verts)
Beispiel #5
0
def closerVert(diamondIndices):
    """

    """

    activeObjs = Blender.Object.GetSelected()
    obj = activeObjs[0].getData(mesh=True)

    centroidVerts = [[
        obj.verts[i].co[0], obj.verts[i].co[1], obj.verts[i].co[2]
    ] for i in diamondIndices]
    center = aljabr.centroid(centroidVerts)

    vertsList = []
    vertsListIndices = []
    vertsToUse = getSkinVerts()
    for i in vertsToUse:
        v = obj.verts[i]
        vertsList.append([v.co[0], v.co[1], v.co[2]])
        vertsListIndices.append(v.index)

    kd = KDTree(vertsList)
    dist, indx = kd.query([center])
    i = vertsListIndices[indx]

    return i
Beispiel #6
0
def getHumanJointPosition(mesh, jointName):
    """
    Get the position of a joint from the human mesh.
    This position is determined by the center of the joint helper with the
    specified name.
    """
    fg = mesh.getFaceGroup(jointName)
    verts = mesh.getCoords(mesh.getVerticesForGroups([fg.name]))
    return aljabr.centroid(verts)
Beispiel #7
0
def getHumanJointPosition(mesh, jointName):
    """
    Get the position of a joint from the human mesh.
    This position is determined by the center of the joint helper with the
    specified name.
    """
    fg = mesh.getFaceGroup(jointName)
    verts = mesh.getCoords(mesh.getVerticesForGroups([fg.name]))
    return aljabr.centroid(verts)
    def __calcJointOffsets(self, mesh, joint, parent=None):
        """
        This function calculates the position and offset for a joint and calls itself for 
        each 'child' joint in the hierarchical joint structure. 
        
        Parameters
        ----------
        
        mesh:     
          *Object3D*.  The object whose information is to be used for the calculation.
        joint:     
          *Joint Object*.  The joint object to be processed by this function call.
        parent:     
          *Joint Object*.  The parent joint object or 'None' if not specified.
        """

        # Calculate joint positions
        g = mesh.getFaceGroup(joint.name)
        verts = []
        for f in g.faces:
            for v in f.verts:
                verts.append(v.co)
        joint.position = centroid(verts)
        joint.transform[3], joint.transform[7], joint.transform[11] = joint.position

        # Calculate offset
        if parent:
            joint.offset = vsub(joint.position, parent.position)
        else:
            joint.offset = joint.position[:]

        """
        # Calculate direction
        direction = vnorm(joint.offset)
        axis = vnorm(vcross([0.0, 0.0, 1.0], direction))
        angle = acos(vdot([0.0, 0.0, 1.0], direction))
        joint.direction = axisAngleToQuaternion(axis, angle)
        
        # Calculate rotation
        if parent:
            v1 = vmul(vnorm(parent.offset), -1.0)
            v2 = vnorm(joint.offset)
            axis = vnorm(vcross(v1, v2))
            angle = acos(vdot(v1, v2))
            joint.rotation = axisAngleToQuaternion(axis, angle)   
        """

        # Update counters and set index
        joint.index = self.joints
        self.joints += 1
        if not joint.children:
            self.endEffectors += 1

        # Calculate child offsets
        for child in joint.children:
            self.__calcJointOffsets(mesh, child, joint)
Beispiel #9
0
    def __calcJointOffsets(self, mesh, joint, parent=None):
        """
        This function calculates the position and offset for a joint and calls itself for 
        each 'child' joint in the hierarchical joint structure. 
        
        Parameters
        ----------
        
        mesh:     
          *Object3D*.  The object whose information is to be used for the calculation.
        joint:     
          *Joint Object*.  The joint object to be processed by this function call.
        parent:     
          *Joint Object*.  The parent joint object or 'None' if not specified.
        """
        # Calculate joint positions
        g = mesh.getFaceGroup(joint.name)
        verts = []
        for f in g.faces:
            for v in f.verts:
                verts.append(v.co)
        joint.position = centroid(verts)
        joint.transform[3], joint.transform[7], joint.transform[
            11] = joint.position

        # Calculate offset
        if parent:
            joint.offset = vsub(joint.position, parent.position)
        else:
            joint.offset = joint.position[:]
        """
        # Calculate direction
        direction = vnorm(joint.offset)
        axis = vnorm(vcross([0.0, 0.0, 1.0], direction))
        angle = acos(vdot([0.0, 0.0, 1.0], direction))
        joint.direction = axisAngleToQuaternion(axis, angle)
        
        # Calculate rotation
        if parent:
            v1 = vmul(vnorm(parent.offset), -1.0)
            v2 = vnorm(joint.offset)
            axis = vnorm(vcross(v1, v2))
            angle = acos(vdot(v1, v2))
            joint.rotation = axisAngleToQuaternion(axis, angle)   
        """
        # Update counters and set index
        joint.index = self.joints
        self.joints += 1
        if not joint.children:
            self.endEffectors += 1

        # Calculate child offsets
        for child in joint.children:
            self.__calcJointOffsets(mesh, child, joint)
def closerVert(diamondIndices):
    """

    """

    activeObjs = Blender.Object.GetSelected()
    obj = activeObjs[0].getData(mesh=True)

    centroidVerts = [[obj.verts[i].co[0],obj.verts[i].co[1],obj.verts[i].co[2]] for i in diamondIndices]
    center = aljabr.centroid(centroidVerts)

    vertsList = []
    vertsListIndices = []
    vertsToUse = getSkinVerts()
    for i in vertsToUse:
        v = obj.verts[i]
        vertsList.append([v.co[0],v.co[1],v.co[2]])
        vertsListIndices.append(v.index)          
    
    kd = KDTree(vertsList)
    dist,indx = kd.query([center])
    i = vertsListIndices[indx]

    return i
Beispiel #11
0
def loadRotationTarget(obj, targetPath, morphFactor):  
    """
    This function loads a rotation target file and applies the rotations to 
    specific vertices on the mesh object by rotating them around a common axis 
    (which is specified in a separate 'info' file using two of 
    the vertices on the mesh object). 
    
    Each line in the rotation target file contains a pair of numbers. The first
    is an index to a particular vertex in the array of vertices in the mesh object. 
    The second is a rotation angle.
    
    This function requires an 'info' file with a name that corresponds to the name of
    the rotation target file. This file contains a pair of 
    indices that point to two of the vertices in the mesh object. The coordinates of
    those two vertices are used as the axis around which the vertices listed in the 
    rotation target file will be rotated. 
    
    The rotation angles for each of the points listed in the rotation target file are
    multiplied by a factor (morphFactor) before being applied to the vertex coordinates.

    Parameters
    ----------

    obj:
        *3d object*. The target object to which the rotations are to be applied.

    targetPath:
        *string*. The file system path to the file containing the rotation targets.
        **Note.** This path is also used to find an accompanying path with the '.info'
        extension appended to targetPath. This 'info' file must be present and must 
        contain the element numbers of a pair 
        of vertices around which the rotation is to be performed.

    morphFactor:
        *float*. A factor between 0 and 1 controlling the proportion of the specified 
        rotations to apply. If 0 then the object remains unmodified. If 1 the full rotations
        are applied. This parameter would normally be in the range 0-1 but can be greater 
        than 1 or less than 0 when used to produce extreme deformations (deformations 
        that extend beyond those modelled by the original artist).

    calcNorm:
        *int flag*. A flag to indicate whether the normals are to be recalculated (1/true) 
        or not (0/false).    

    """

    a = time.time()  

    try:
        f = open(targetPath)
        fileDescriptor = f.readlines()
        f.close()
    except:
        print "Error opening target file: %s"%(targetPath)
        return 0


    #Get info of axis from the first line of file
    rotAxeInfo = fileDescriptor[0].split()

    #Calculate the rotation axis vector
    axisP1  = obj.verts[int(rotAxeInfo[0])]
    axisP2  = obj.verts[int(rotAxeInfo[1])]
    axis = rotAxeInfo[2]
    #rotAxis = [axisP2.co[0]-axisP1.co[0],axisP2.co[1]-axisP1.co[1],axisP2.co[2]-axisP1.co[2]]
    #rotAxis = vunit(rotAxis)
    #axis = axisID(rotAxis)

    indicesToUpdate = []

    v1= [axisP1.co[0],axisP1.co[1],axisP1.co[2]]
    v2= [axisP2.co[0],axisP2.co[1],axisP2.co[2]]
    actualRotCenter = aljabr.centroid([v1,v2])

    for stringData in fileDescriptor[1:]:
        listData = stringData.split()
        theta = float(listData[0])
        theta = theta*morphFactor
        #Rmtx = makeRotMatrix(-theta, rotAxis)
        if axis == "X":
            Rmtx = aljabr.makeRotEulerMtx3D(theta,0,0)
        elif axis == "Y":
            Rmtx = aljabr.makeRotEulerMtx3D(0,theta,0)
        elif axis == "Z":
            Rmtx = aljabr.makeRotEulerMtx3D(0,0,theta)

        for pIndex in listData[1:]:
            pointIndex = int(pIndex)
            indicesToUpdate.append(pointIndex)
            pointRotated = aljabr.rotatePoint(actualRotCenter, obj.verts[pointIndex].co, Rmtx)

            obj.verts[pointIndex].co = list(pointRotated)
    
    verticesToUpdate = [obj.verts[i] for i in set(indicesToUpdate)]
    obj.update(verticesToUpdate)
    print "ROTATION TIME", time.time()-a

    return 1