Skip to content

Camera FBX importer example #554

@cghub-io

Description

@cghub-io

Hi there,

just here an example of an working camera FBX importer for people to use as reference.

I have two questions though:

  1. how can i pull in the focalLength from the fbx. Right now I am doing a workaround by exporting into a textfile from Maya

  2. How to adjust the WorkingRange and ViewRange in the Sequencer. I have camera animations start at Frame 1001. Its a nightmare to adjust the viewing timeline to it each time.
    I found that the DataEditor is the variable which holds the property. But somehow I am not able to set it properly.

This here doesn't work.

from unreal_engine.structs import FloatRange, FloatRangeBound


# [u'ExpansionStates', u'ViewStart', u'ViewEnd', u'WorkStart', u'WorkEnd', u'WorkingRange', u'ViewRange']
seq.MovieScene.EditorData.WorkingRange = FloatRange(LowerBound=FloatRangeBound(Value=1001), UpperBound=FloatRangeBound(Value=1100))
seq.MovieScene.EditorData.ViewRange = FloatRange(LowerBound=FloatRangeBound(Value=1001), UpperBound=FloatRangeBound(Value=1100))
seq.sequencer_changed(True)

Cheers,

frame_start = 1001
frame_end = 1100
fps = 25
focal = 21
camera_fbx_name= 'C:/inf_010_v006_scale1.fbx'

tokens = camera_fbx_name.split('_')
# ['inf', '010', 'v006', 'scale1']


# Unreal stuff here
world = ue.get_editor_world()

exist = ue.find_asset('/Game/Cameras/{0}/{1}/{2}/{0}_{1}_{2}'.format(tokens[0],tokens[1],tokens[2]))

if exist:

    DialogException('Yo mate!\n\nCamera already exist in the scene.\n\n{0}_{1}_{2}'.format(tokens[0],tokens[1],tokens[2]))


else:
    factory = LevelSequenceFactoryNew()
    seq = factory.factory_create_new('/Game/Cameras/{0}/{1}/{2}/{0}_{1}_{2}'.format(tokens[0],tokens[1],tokens[2]))

    seq.MovieScene.FixedFrameInterval = 1.0/float(fps)
    seq.sequencer_changed(True)

    seq.sequencer_set_playback_range(float(frame_start)/float(fps), float(frame_end)/float(fps))
    cine_camera = world.actor_spawn(CineCameraActor)
    cine_camera.set_actor_label('{0}_{1}_{2}'.format(tokens[0],tokens[1],tokens[2]))

    # adjust focal length as sequencer_import_fbx_transform() doesn't do it. Maybe I am missing something..??
    cine_camera.CameraComponent.CurrentFocalLength = float(focal)
    cine_camera.CameraComponent.CurrentAperture = 21
    cine_camera.CameraComponent.post_edit_change()

    # add camera cut track (can be only one)
    camera_cut_track = seq.sequencer_add_camera_cut_track()
    seq.sequencer_changed(True)

    # add camera view
    camera = camera_cut_track.sequencer_track_add_section()
    camera_guid = seq.sequencer_add_actor(cine_camera)

    # # assign the two cameras to the camera cut sections (via binding id)
    camera.CameraBindingID = MovieSceneObjectBindingID( Guid=ue.string_to_guid( camera_guid ), Space=EMovieSceneObjectBindingSpace.Local )
    camera.sequencer_set_section_range(float(frame_start)/float(fps), float(frame_end)/float(fps))
    seq.sequencer_changed(True)

    # remove the Transform track as it pulls in fbx weirdly
    seq.sequencer_remove_track(seq.sequencer_possessable_tracks(camera_guid)[0])
    seq.sequencer_changed(True)

    # create new transform track and assign fbx to it
    transform_track = seq.sequencer_add_track(MovieScene3DTransformTrack, camera_guid)
    transform_section = transform_track.sequencer_track_add_section()

    # set frame range for playback
    transform_section.sequencer_set_section_range(float(frame_start)/float(fps), float(frame_end)/float(fps))
    transform_section.sequencer_import_fbx_transform(fbx_file, camera_fbx_name)

    # set frame rate of sequencer
    seq.MovieScene.DisplayRate.Numerator = float(fps)
    seq.sequencer_changed(True)

    seq.save_package()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions