Exemple #1
0
def set_curve_data(fcurve, key_data_list, frame_offset=0):
    """
    Sets curve data

    :param fcurve: fcurve to set data on
    :type fcurve: pyfbsdk.FBFCurve

    :param key_data_list: key data ordered in time as list
    :type key_data_list: list of dict

    :param frame_offset: frame offset value
    :type frame_offset: int
    """
    # clear curve first
    fcurve.EditClear()

    # grab offset in frames
    fb_offset = pyfbsdk.FBTime(0, 0, 0, frame_offset, 0)

    # set keys
    for key_data in key_data_list:

        # add key
        key_index = fcurve.KeyAdd(
            pyfbsdk.FBTime(key_data['time']) + fb_offset,
            key_data['value'])
        key = fcurve.Keys[key_index]

        # set interp
        key.Interpolation = pyfbsdk.FBInterpolation.values[
            key_data['interpolation']]

        # set tangent
        key.TangentMode = pyfbsdk.FBTangentMode.values[
            key_data['tangent-mode']]

        # not using TCB mode just set to break
        if key.TangentMode == pyfbsdk.FBTangentMode.kFBTangentModeTCB:
            key.TangentMode = pyfbsdk.FBTangentMode.kFBTangentModeBreak

        # set tangent constant
        key.TangentConstantMode = pyfbsdk.FBTangentConstantMode.values[
            key_data['constant-mode']]

    # set tangents
    for i, key_data in enumerate(key_data_list):
        key = fcurve.Keys[i]

        key.LeftDerivative = key_data['left-derivative']
        key.RightDerivative = key_data['right-derivative']

        # set tangent if needed to keep tangents from being unlocked
        if not tangent_is_default_weight(key_data['left-weight']):
            key.LeftTangentWeight = key_data['left-weight']

        if not tangent_is_default_weight(key_data['right-weight']):
            key.RightTangentWeight = key_data['right-weight']
Exemple #2
0
def plotSelectedDecision(pPlotWhere):
    # Defining our Characater as the currnetly selected one
    lCharacter = fb.FBApplication().CurrentCharacter
    # Defining the Plot option that will be used
    PlotCtrlRigTakeOptions = fb.FBPlotOptions()
    # To use Constant Key Reduction on the plot (True or False)
    PlotCtrlRigTakeOptions.ConstantKeyReducerKeepOneKey = False
    # To go through all takes in the scene and plot the data (True or False)
    PlotCtrlRigTakeOptions.PlotAllTakes = False
    # Do you wish to plot onto frames (True or False)
    PlotCtrlRigTakeOptions.PlotOnFrame = True
    # Set the plot period
    PlotCtrlRigTakeOptions.PlotPeriod = fb.FBTime(0, 0, 0, 1)
    PlotCtrlRigTakeOptions.PlotTranslationOnRootOnly = False
    PlotCtrlRigTakeOptions.PreciseTimeDiscontinuities = False
    # What filter to use on the plot (Unroll, GimabalKill or None)
    PlotCtrlRigTakeOptions.RotationFilterToApply = fb.FBRotationFilter.kFBRotationFilterUnroll
    # Use Constant Kye Reduction (True or False)
    PlotCtrlRigTakeOptions.UseConstantKeyReducer = False
    if pPlotWhere == "skeleton":
        lCharacter.PlotAnimation(
            fb.FBCharacterPlotWhere.kFBCharacterPlotOnControlRig,
            PlotCtrlRigTakeOptions)
    elif pPlotWhere == "ctrlrig":
        lCharacter.PlotAnimation(
            fb.FBCharacterPlotWhere.kFBCharacterPlotOnSkeleton,
            PlotCtrlRigTakeOptions)
Exemple #3
0
def _saveBuffer(savePath, tmpImgExtension="tif"):

    app = fb.FBApplication()
    take = fb.FBSystem().CurrentTake
    current = fb.FBTime(fb.FBPlayerControl().GetEditCurrentTime())
    next = fb.FBTime(fb.FBPlayerControl().GetEditCurrentTime() + 1)

    opts = fb.FBVideoGrabber().GetOptions()
    videoManager = fb.FBVideoCodecManager()
    videoManager.VideoCodecMode = fb.FBVideoCodecMode.FBVideoCodecUncompressed

    opts.OutputFileName = savePath
    opts.RenderAudio = False
    opts.BitsPerPixel = fb.FBVideoRenderDepth.FBVideoRender32Bits
    opts.TimeSpan = fb.FBTimeSpan(current, next)
    opts.TimeStep = fb.FBTime(0, 0, 0, 1, 0)

    app.FileRender( opts )
Exemple #4
0
def SaveScreenShot(outPath, tmpImgExtension="tif"):
    util.CheckDirectory(outPath)
    tmp_file = util.GetTempImgPath(extension=tmpImgExtension)

    _saveBuffer(tmp_file)
    current = fb.FBTime(fb.FBPlayerControl().GetEditCurrentTime())
    tmp_file = "{0}{1:04d}.tif".format(tmp_file.split(".")[0], current.GetFrame())
    tmp_bmp = tmp_file.replace(".tif", ".bmp")
    tiff2bitmap.execute(tmp_file, tmp_bmp)


    result = cropImage.CropImage.RunCropImage(tmp_bmp, outPath, parent=None)

    os.remove(tmp_file)
    os.remove(tmp_bmp)

    return (result is 1)
Exemple #5
0
def SendAllCharactersToStory():
    charIndex = 1
    lClipList = []
    lMyStartTime = 0
    # Find all characters in the scene. Add them to story track
    for lChar in fb.FBSystem().Scene.Characters:
        # Create Track for one character
        lTrack = fb.FBStoryTrack(fb.FBStoryTrackType.kFBStoryTrackCharacter)
        # Specify the index of the character which is one
        lTrack.CharacterIndex = charIndex
        # Creating the track names based on character names and adding a 'Track' behind.
        lTrack.LongName = lChar.LongName + " Track"
        #lTrack.Ghost = self.ui.RBEnableGhost.isChecked()
        # Insert current take
        lClip = lTrack.CopyTakeIntoTrack(
            fb.FBSystem().CurrentTake.LocalTimeSpan,
            fb.FBSystem().CurrentTake)
        # Shift clip to start time at 0
        lClip.Start = fb.FBTime(0, 0, 0, lMyStartTime)
        # adding one to the index so that it will repeat for the next character in the scene.
        charIndex = charIndex + 1
        # insert current take.
        lClipList.append(lClip)
Exemple #6
0
    def create_story(self, clip_data=None):
        """Creates a video story video_track

        :param clip_data:
        :return:
        """
        import os

        if clip_data is None:
            clip_data = []

        # find the default Shot Track
        track_container = pyfbsdk.FBStory().RootEditFolder.Tracks
        shot_track = None
        character_track = None
        for track in track_container:
            if track.Label == "Shot Track":
                shot_track = track
            elif track.Label == "Character Track":
                character_track = track

        if not shot_track:
            # Create a Shot Track
            shot_track = pyfbsdk.FBStoryTrack(
                pyfbsdk.FBStoryTrackType.kFBStoryTrackShot
            )

        if not character_track:
            character_track = pyfbsdk.FBStoryTrack(
                pyfbsdk.FBStoryTrackType.kFBStoryTrackCharacter
            )

        # create clips
        for clip_info in clip_data:
            assert isinstance(clip_info, ClipData)
            # create a new camera
            clip_camera = pyfbsdk.FBCamera(
                'Camera_Shot_%s' % str(clip_info.shot_name)
            )

            # Create a Shot clip
            cut_in_fbtime = pyfbsdk.FBTime(0, 0, 0, clip_info.cut_in)
            cut_out_fbtime = pyfbsdk.FBTime(0, 0, 0, clip_info.cut_out)

            shot_clip = pyfbsdk.FBStoryClip(
                clip_camera,
                shot_track,
                cut_in_fbtime
            )
            shot_clip.Stop = cut_out_fbtime
            shot_clip.Offset = cut_in_fbtime

            shot_clip.SetTime(
                None,
                None,
                cut_in_fbtime,
                cut_out_fbtime,
                False
            )
            if clip_info.fps:
                shot_clip.UseSystemFrameRate = False
                shot_clip.FrameRate = clip_info.fps

            # shot_clip.ClipAnimationPath = str(clip_info.fbx_path)
            character_clip = pyfbsdk.FBStoryClip(
                str(clip_info.fbx_path),
                character_track,
                cut_in_fbtime
            )
            character_clip.Stop = cut_out_fbtime
            character_clip.Offset = cut_in_fbtime

            # set the camera back plate to the video
            back_plate = pyfbsdk.FBTexture(str(clip_info.movie_path))

            # set the back plate as the shot_clip back plate
            clip_camera.BackGroundTexture = back_plate

            # set the video offset
            back_plate.Video.TimeOffset = cut_in_fbtime