Esempio n. 1
0
def _query_selection_state():
    """
    Query the current selection state.

    Get the active point group, selected camera and connected lens.

    :returns: A tuple of Point Group ID, Camera ID and Lens ID. Any of
             the tuple members may be None if it could not be found.
    :rtype: (str or None, str or None, str or None)
    """
    cam_id = None
    lens_id = None
    msg = None
    pgroup_id = tde4.getCurrentPGroup()
    if not pgroup_id:
        msg = 'Error: Could not get active Point Group for camera.'
    else:
        with_selection = 1
        cam_ids = tde4.getCameraList(with_selection)
        if len(cam_ids) == 1:
            cam_id = cam_ids[0]
            lens_id = tde4.getCameraLens(cam_id)
            if not lens_id:
                msg = 'Error: Selected camera does not have a connected lens.'
        else:
            if len(cam_ids) == 0:
                msg = 'Error: Please select a camera.'
            elif len(cam_ids) > 1:
                msg = 'Error: Please select only one camera.'
            tde4.postQuestionRequester(TITLE, msg, 'Ok')
        if msg is not None:
            tde4.postQuestionRequester(TITLE, msg, 'Ok')
    return pgroup_id, cam_id, lens_id
def main():
    camera = tde4.getCurrentCamera()
    point_group = tde4.getCurrentPGroup()
    if camera is None or point_group is None:
        msg = 'There is no current Point Group or Camera.'
        tde4.postQuestionRequester(TITLE, msg, 'Ok')
        return

    # check if context menu has been used, and retrieve point...
    point = tde4.getContextMenuObject()
    if point is not None:
        # retrieve point's parent pgroup (not necessarily being the current one!)...
        point_group = tde4.getContextMenuParentObject()
        points = tde4.getPointList(point_group, 1)
    else:
        # otherwise use regular selection...
        points = tde4.getPointList(point_group, 1)
    if len(points) == 0:
        msg = 'There are no selected points.'
        tde4.postQuestionRequester(TITLE, msg, 'Ok')
        return

    # widget default values
    start_frame = 1
    # Backwards compatibility with 3DE4 Release 2.
    if uvtrack_format.SUPPORT_CAMERA_FRAME_OFFSET is True:
        start_frame = tde4.getCameraFrameOffset(camera)
    pattern = '*' + EXT

    # GUI
    req = tde4.createCustomRequester()
    tde4.addFileWidget(req, 'file_browser_widget', 'Filename...', pattern)
    tde4.addTextFieldWidget(req, 'start_frame_widget', 'Start Frame', str(start_frame))
    ret = tde4.postCustomRequester(req, TITLE, 500, 0, 'Ok', 'Cancel')
    if ret == 1:
        # Query GUI Widgets
        path = tde4.getWidgetValue(req, 'file_browser_widget')
        start_frame = tde4.getWidgetValue(req, 'start_frame_widget')
        start_frame = int(start_frame)

        # Generate file contents
        data_str = uvtrack_format.generate(
            point_group, camera, points,
            start_frame=start_frame,
            fmt=uvtrack_format.UV_TRACK_FORMAT_VERSION_PREFERRED,
        )

        # Write file.
        if path.find(EXT, len(path)-3) == -1:
            # Ensure the file path ends with the extension, if not add it.
            path += EXT
        f = open(path, 'w')
        if f.closed:
            msg = "Error, couldn't open file.\n"
            msg += repr(path)
            tde4.postQuestionRequester(TITLE, msg, 'Ok')
            return
        f.write(data_str)
        f.close()
    return
    def _import_obj(self, path, sg_publish_data):
        if os.path.exists(path):
            point_group_id = tde4.getCurrentPGroup()
            if not point_group_id:
                point_group_id = tde4.createPGroup("OBJECT")
            model_id = tde4.create3DModel(point_group_id, 10000)
            imported = tde4.importOBJ3DModel(point_group_id, model_id, path)

            if not imported:
                raise Exception(
                    "Unable to import OBJ from {}. "
                    "Something went wrong in 3dequalizer.".format(path))
            else:
                # set model properties
                model_name, _ = os.path.splitext(os.path.basename(path))
                tde4.set3DModelName(point_group_id, model_id, model_name)
                tde4.set3DModelReferenceFlag(point_group_id, model_id, True)
                tde4.set3DModelSurveyFlag(point_group_id, model_id, True)
                # set3DModelRenderingFlags(<pgroup_id>, <model_id>, <show_points>, <show_lines>, <show_polygons>)
                tde4.set3DModelRenderingFlags(point_group_id, model_id, False,
                                              True, False)

        else:
            # TODO: either obj sequence or something wrong
            pass
Esempio n. 4
0
def main():
    camera = tde4.getCurrentCamera()
    point_group = tde4.getCurrentPGroup()
    if camera is None or point_group is None:
        msg = 'There is no current Point Group or Camera.'
        tde4.postQuestionRequester(TITLE, msg, 'Ok')
        return

    # check if context menu has been used, and retrieve point...
    point = tde4.getContextMenuObject()
    if point is not None:
        # retrieve point's parent pgroup (not necessarily being the current one!)...
        point_group = tde4.getContextMenuParentObject()
        points = tde4.getPointList(point_group, 1)
    else:
        # otherwise use regular selection...
        points = tde4.getPointList(point_group, 1)
    if len(points) == 0:
        msg = 'There are no selected points.'
        tde4.postQuestionRequester(TITLE, msg, 'Ok')
        return

    # Generate file contents
    undistort = True
    start_frame = 1
    # Backwards compatibility with 3DE4 Release 2.
    if uvtrack_format.SUPPORT_CAMERA_FRAME_OFFSET is True:
        start_frame = tde4.getCameraFrameOffset(camera)
    data_str = uvtrack_format.generate(
        point_group, camera, points,
        start_frame=start_frame,
        undistort=undistort
    )

    # Write file.
    file_ext = EXT
    f = tempfile.NamedTemporaryFile(
        mode='w+b',
        bufsize=-1,
        suffix=file_ext,
        delete=False
    )
    if f.closed:
        msg = "Error: Couldn't open file.\n%r"
        msg = msg % f.name
        tde4.postQuestionRequester(TITLE, msg, 'Ok')
        return
    f.write(data_str)
    f.close()

    # Override the user's clipboard with the temporary file path.
    if uvtrack_format.SUPPORT_CLIPBOARD is True:
        tde4.setClipboardString(f.name)
    else:
        # Cannot set the clipboard, so we'll print to the Python Console
        # and the user can copy it. Pretty bad workaround.
        print f.name
    return
Esempio n. 5
0
def main():
    camera = tde4.getCurrentCamera()
    point_group = tde4.getCurrentPGroup()
    if camera is None or point_group is None:
        msg = 'There is no current Point Group or Camera.'
        tde4.postQuestionRequester(TITLE, msg, 'Ok')
        return

    # check if context menu has been used, and retrieve point...
    point = tde4.getContextMenuObject()
    if point is not None:
        # retrieve point's parent pgroup (not necessarily being the current
        # one!)...
        point_group = tde4.getContextMenuParentObject()
        points = tde4.getPointList(point_group, 1)
    else:
        # otherwise use regular selection...
        points = tde4.getPointList(point_group, 1)
    if len(points) == 0:
        msg = 'There are no selected points.'
        tde4.postQuestionRequester(TITLE, msg, 'Ok')
        return

    start, end, step = tde4.getCameraSequenceAttr(camera)
    start_frame = start
    # Backwards compatibility with 3DE4 Release 2.
    if SUPPORT_CAMERA_FRAME_OFFSET is True:
        start_frame = tde4.getCameraFrameOffset(camera)

    rs_enabled = False
    rs_distance = None
    # Backwards compatibility with 3DE4 Release 1.
    if SUPPORT_RS_ENABLED is True:
        rs_enabled = bool(tde4.getCameraRollingShutterEnabledFlag(camera))
    if rs_enabled is True:
        rs_distance = get_rs_distance(camera)
        if (SUPPORT_PROJECT_NOTES is True
                and SUPPORT_RS_DISTANCE is False):
            set_rs_distance_into_project_notes(rs_distance)

    # Generate file contents
    data_str = generate(
        point_group, camera, points,
        start_frame=start_frame,
        rs_distance=rs_distance,
        fmt=UV_TRACK_FORMAT_VERSION_PREFERRED
    )

    # Write file.
    file_ext = EXT
    # Prefix with the current time 'YYYY-MM-DD_HH_MM', for example
    # '2020-12-04_14_26'.
    now_str = time.strftime('%Y-%m-%d_%H_%M')
    prefix = 'tmp_{0}_'.format(now_str)
    f = tempfile.NamedTemporaryFile(
        mode='w',
        prefix=prefix,
        suffix=file_ext,
        delete=False
    )
    if f.closed:
        msg = "Error: Couldn't open file.\n%r"
        msg = msg % f.name
        tde4.postQuestionRequester(TITLE, msg, 'Ok')
        return
    f.write(data_str)
    f.close()

    # Override the user's clipboard with the temporary file path.
    if SUPPORT_CLIPBOARD is True:
        tde4.setClipboardString(f.name)
    else:
        # Cannot set the clipboard, so we'll print to the Python Console
        # and the user can copy it. Pretty bad workaround.
        print(f.name)
    return