Ejemplo n.º 1
0
    def apply(self, obj, morphFactor, update=True, calcNormals=True, faceGroupToUpdateName=None, scale=(1.0,1.0,1.0), animatedMesh=None):
        self.morphFactor = morphFactor

        if len(self.verts):

            if morphFactor or calcNormals or update:

                if faceGroupToUpdateName:
                    # if a facegroup is provided, apply it ONLY to the verts used
                    # by the specified facegroup.
                    vmask, fmask = obj.getVertexAndFaceMasksForGroups([faceGroupToUpdateName])

                    srcVerts = np.argwhere(vmask[self.verts])[...,0]
                    facesToRecalculate = self.faces[fmask[self.faces]]
                else:
                    # if a vertgroup is not provided, all verts affected by
                    # the targets will be modified

                    facesToRecalculate = self.faces
                    srcVerts = np.s_[...]

                dstVerts = self.verts[srcVerts]

            if morphFactor:
                # Adding the translation vector

                scale = np.array(scale) * morphFactor
                if animatedMesh is not None:
                    # Pose the direction in which the target is applied, for fast
                    # approximate modeling of a posed model
                    import animation
                    vertBoneMapping = animatedMesh.getBoundMesh(obj.name)[1]
                    if not vertBoneMapping.isCompiled(4):
                        vertBoneMapping.compileData(animatedMesh.getBaseSkeleton(), 4)
                    animationTrack = animatedMesh.getActiveAnimation()
                    if not animationTrack.isBaked():
                        animationTrack.bake(animatedMesh.getBaseSkeleton())
                    poseData = animatedMesh.getPoseState()
                    obj.coord[dstVerts] += animation.skinMesh( \
                                  self.data[srcVerts] * scale[None,:], 
                                  vertBoneMapping.compiled(4)[dstVerts], poseData )
                else:
                    obj.coord[dstVerts] += self.data[srcVerts] * scale[None,:]
                obj.markCoords(dstVerts, coor=True)

            if calcNormals:
                obj.calcNormals(1, 1, dstVerts, facesToRecalculate)
            if update:
                obj.update()

            return True

        return False
Ejemplo n.º 2
0
    def apply(self, obj, morphFactor, update=True, calcNormals=True, faceGroupToUpdateName=None, scale=(1.0,1.0,1.0), animatedMesh=None):
        self.morphFactor = morphFactor

        if len(self.verts):

            if morphFactor or calcNormals or update:

                if faceGroupToUpdateName:
                    # if a facegroup is provided, apply it ONLY to the verts used
                    # by the specified facegroup.
                    vmask, fmask = obj.getVertexAndFaceMasksForGroups([faceGroupToUpdateName])

                    srcVerts = np.argwhere(vmask[self.verts])[...,0]
                    facesToRecalculate = self.faces[fmask[self.faces]]
                else:
                    # if a vertgroup is not provided, all verts affected by
                    # the targets will be modified

                    facesToRecalculate = self.faces
                    srcVerts = np.s_[...]

                dstVerts = self.verts[srcVerts]

            if morphFactor:
                # Adding the translation vector

                scale = np.array(scale) * morphFactor
                if animatedMesh is not None:
                    # Pose the direction in which the target is applied, for fast
                    # approximate modeling of a posed model
                    import animation
                    vertBoneMapping = animatedMesh.getBoundMesh(obj.name)[1]
                    if not vertBoneMapping.isCompiled(4):
                        vertBoneMapping.compileData(animatedMesh.getSkeleton(), 4)
                    animationTrack = animatedMesh.getActiveAnimation()
                    if not animationTrack.isBaked():
                        animationTrack.bake(animatedMesh.getSkeleton())
                    poseData = animatedMesh.getPoseState()
                    obj.coord[dstVerts] += animation.skinMesh( \
                                  self.data[srcVerts] * scale[None,:], 
                                  vertBoneMapping.compiled(4)[dstVerts], poseData )
                else:
                    obj.coord[dstVerts] += self.data[srcVerts] * scale[None,:]
                obj.markCoords(dstVerts, coor=True)

            if calcNormals:
                obj.calcNormals(1, 1, dstVerts, facesToRecalculate)
            if update:
                obj.update()

            return True

        return False