Beispiel #1
0
def calculateWeight(vertex, a, b, bendyLength=0.75):
    minWeight = 0.0
    maxWeight = 0.1

    distance = geometry.pointDistance(vertex, a.bone.pivot)
    boneLength = geometry.pointDistance(a.bone.pivot,
                                        b.bone.pivot) * bendyLength
    if boneLength == 0:
        return 0
    vertexDistance = min(distance / boneLength, 1.0)
    return utils.clamp(1 - vertexDistance, minWeight, maxWeight)
Beispiel #2
0
 def pickPoint(self, pos):
     closest = None
     closestDistance = None
     for bone in self.getBones().values():
         for i, point in enumerate(self.getPolyPoints(bone)):
             distance = geometry.pointDistance(pos, point)
             if distance < PICK_DISTANCE_PIVOT:
                 if not closest or distance < closestDistance:
                     closest = (bone, bone.points[i], i)
                     closestDistance = distance
     return closest
Beispiel #3
0
    def fixTJunctions(self):
        tris = self.getTriangleIndices()
        indexAdj = self.getIndexAdjacency(tris)

        split = {}
        for i, (a, b, c) in enumerate(tris):
            for edge in ((a, b), (b, c), (c, a)):
                start = self.getVertex(edge[0])
                end = self.getVertex(edge[1])
                if geometry.pointDistance(start, end) > 0.0:
                    for tri, index in indexAdj.get(edge[0], []):
                        for n in tri:
                            v2 = self.getVertex(n)
                            if geometry.pointDistance(
                                    start,
                                    v2) > 1.0 and geometry.pointDistance(
                                        end, v2) > 1.0:
                                edgeDist = geometry.pointToLineDistance(
                                    v2, start, end)
                                if edgeDist < 1.0:
                                    #Vertex is overlapping this edge
                                    splitting = split.get(i, set())
                                    splitting.add(edge)
                                    split[i] = splitting

        verts = self.vertices[:]
        indices = self.indices[:]
        for index, edges in split.items():
            edges = list(edges)
            tri = tris[index]
            if len(edges) == 1:
                self.splitEdge(edges[0][0], edges[0][1], tri, verts, indices,
                               index)
            elif len(edges) > 1:
                #TODO This can create new edges to be splitted...
                self.subdivideTriangle(tri[0], tri[1], tri[2], verts, indices,
                                       index)

        self.setGeometry(verts, [x for x in indices if x is not None])
Beispiel #4
0
    def visualizeBones(self):
        context = self.context
        canvas = context.overlayCanvas
        mouse = self.mouse
        black = (0, 0, 0)
        shadow = 1
        activeBone = self.getActiveBone()

        hoverPoint = None
        hoverPivotBone = None
        hoverCropBone = None
        if mouse:
            hoverPoint = self.pickPoint(mouse)
            hoverPivotBone = self.pickPivot(mouse)
            hoverCropBone = self.pickCrop(mouse)

        cached = []

        for trans in reversed(self.transforms):
            bone = trans.bone
            bone.wireFrame = self.settings["wireframe"]
            pivot = self.getBonePivotTransformed(bone)
            cached.append((trans, pivot))

            if self.settings["imageAreas"] and bone.image and bone.visible:
                areaColor = (255, 255, 0)
                lines = self.getImageLines(bone)
                if not hoverPivotBone and hoverCropBone and bone.name == hoverCropBone.name:
                    self.drawText(hoverCropBone.name, "#fff", (mouse[0] + 20, mouse[1]))
                    areaColor = ACTIVE_COLOR
                canvas.lines(areaColor, False, lines, LINE_WIDTH)

                #triangles = self.getTriangles(bone)
                #for i in range(0, len(triangles), 3):
                #    tri = (triangles[i], triangles[i + 1], triangles[i + 2])
                #    context.overlayCanvas.lines("#0f0", True, tri)

            if self.settings["edgePoints"] and bone.visible:
                polyPoints = self.getPolyPoints(bone)
                if polyPoints:
                    self.drawLinesSafe("#ff0", True, polyPoints)
                    for i, p in enumerate(polyPoints):
                        #color = (0, int(float(i) / len(polyPoints) * 255), 0)
                        color = (0, 128, 0)
                        if hoverPoint and hoverPoint[0].name == bone.name and hoverPoint[2] == i:
                            color = (255, 255, 0)
                        canvas.circle(color, p, 3)

            if self.settings["pivots"] and bone.parent:
                parentTrans = self.transformsMap[bone.parent]
                parentBone = parentTrans.bone
                parentPos = self.getBonePivotTransformed(parentBone)
                color = PIVOT_COLOR
                if parentBone.damping > 0.0:
                    color = (0, 255, 255)
                if geometry.pointDistance((pivot.x, pivot.y), (parentPos.x, parentPos.y)) > 1:
                    #TODO Line drawing hangs if passed same start and end?
                    canvas.line(color, (pivot.x, pivot.y), (parentPos.x, parentPos.y), LINE_WIDTH)


        if self.settings["pivots"]:
            for trans, pivot in cached:
                bone = trans.bone

                x = pivot.x
                y = pivot.y
                color = PIVOT_COLOR
                if bone.mesh:
                    color = MESH_COLOR
                if hoverPivotBone and bone.name == hoverPivotBone.name:
                    color = HOVER_COLOR
                if activeBone and bone.name == activeBone.name:
                    color = ACTIVE_COLOR

                if bone.blocker:
                    s = PIVOT_SIZE + 1
                    canvas.rect(black, (x - s - shadow, y - s - shadow, (s + shadow) * 2 , (s + shadow) * 2))
                    canvas.rect(color, (x - s, y - s, s * 2, s * 2))
                elif bone.tessellate:
                    s = PIVOT_SIZE + 3
                    ty = y - 2
                    canvas.polygon(black, [(x - s, ty + s), (x, ty - s), (x + s, ty + s)])
                    s -= 2
                    canvas.polygon(color, [(x - s, ty + s), (x, ty - s), (x + s, ty + s)])
                else:
                    canvas.circle(black, (x, y), PIVOT_SIZE + shadow)
                    canvas.circle(color, (x, y), PIVOT_SIZE)

                textColor = "#fff"
                if activeBone and bone.name == activeBone.name:
                    textColor = ACTIVE_COLOR

                if self.settings["names"]:
                    self.drawText(bone.name, textColor, (x + 15, y - 10))

            propBone = activeBone or hoverPivotBone
            if propBone:
                self.visualizeBoneProperties(propBone, mouse)

        self.mode.draw()
Beispiel #5
0
 def update(self, editor):
     extra = -20
     currentDistance = geometry.pointDistance(self.pivot, editor.mouse) + extra
     delta = (currentDistance / max(self.startDistance + extra, 0.1)) - 1.0
     self.bone.transparency = utils.clamp(self.original - delta, 0.0, 1.0)
Beispiel #6
0
 def start(self, editor):
     self.pivot = editor.getBonePivotTransformed(self.bone)
     self.original = self.bone.transparency
     self.startDistance = geometry.pointDistance(self.pivot, editor.mouse)