Пример #1
0
def create_enter_carry_posture(sim, posture_state, carry_target, track):
    from postures.posture_state import PostureState
    var_map = {
        PostureSpecVariable.CARRY_TARGET:
        carry_target,
        PostureSpecVariable.HAND:
        PostureState.track_to_hand(track),
        PostureSpecVariable.POSTURE_TYPE_CARRY_OBJECT:
        CarryPostureStaticTuning.POSTURE_CARRY_OBJECT
    }
    pick_up_operation = PostureOperation.PickUpObject(
        PostureSpecVariable.POSTURE_TYPE_CARRY_OBJECT,
        PostureSpecVariable.CARRY_TARGET)
    new_source_aop = pick_up_operation.associated_aop(sim, var_map)
    new_posture_spec = pick_up_operation.apply(
        posture_state.get_posture_spec(var_map),
        enter_carry_while_holding=True)
    if new_posture_spec is None:
        raise RuntimeError(
            '[jpollak] Failed to create new_posture_spec in enter_carry_while_holding!'
        )
    new_posture_state = PostureState(sim, posture_state, new_posture_spec,
                                     var_map)
    new_posture = new_posture_state.get_aspect(track)
    from carry.carry_postures import CarryingNothing
    if new_posture is None or isinstance(new_posture, CarryingNothing):
        raise RuntimeError(
            '[jpollak] Failed to create a valid new_posture ({}) from new_posture_state ({}) in enter_carry_while_holding!'
            .format(new_posture, new_posture_state))
    new_posture.external_transition = True
    return (new_posture_state, new_posture, new_source_aop, var_map)
Пример #2
0
def create_exit_carry_posture(sim, target, interaction, use_posture_animations):
    from postures.posture_state import PostureState
    failure_result = (None, None, None, None, None)
    slot_manifest = interaction.slot_manifest
    old_carry_posture = sim.posture_state.get_carry_posture(target)
    if old_carry_posture is None:
        return failure_result
    spec_surface = sim.posture_state.spec[SURFACE_INDEX]
    if spec_surface is not None and spec_surface[SURFACE_SLOT_TYPE_INDEX] is not None:
        put_down_operation = PostureOperation.PutDownObjectOnSurface(PostureSpecVariable.POSTURE_TYPE_CARRY_NOTHING, spec_surface[SURFACE_TARGET_INDEX], spec_surface[SURFACE_SLOT_TYPE_INDEX], PostureSpecVariable.CARRY_TARGET)
    else:
        put_down_operation = PostureOperation.PutDownObject(PostureSpecVariable.POSTURE_TYPE_CARRY_NOTHING, PostureSpecVariable.CARRY_TARGET)
    var_map = {PostureSpecVariable.CARRY_TARGET: target, PostureSpecVariable.HAND: PostureState.track_to_hand(old_carry_posture.track), PostureSpecVariable.POSTURE_TYPE_CARRY_NOTHING: CarryPostureStaticTuning.POSTURE_CARRY_NOTHING, PostureSpecVariable.SLOT: slot_manifest, PostureSpecVariable.SLOT_TEST_DEFINITION: interaction.create_target}
    current_spec = sim.posture_state.get_posture_spec(var_map)
    if current_spec is None:
        logger.warn('Failed to get posture spec for var_map: {} for {}', sim.posture_state, var_map)
        return failure_result
    new_posture_spec = put_down_operation.apply(current_spec)
    if new_posture_spec is None:
        logger.warn('Failed to apply put_down_operation: {}', put_down_operation)
        return failure_result
    if not new_posture_spec.validate_destination((new_posture_spec,), var_map, interaction.affordance):
        logger.warn('Failed to validate put down spec {}  with var map {}', new_posture_spec, var_map)
        return failure_result
    new_posture_state = PostureState(sim, sim.posture_state, new_posture_spec, var_map)
    new_posture = new_posture_state.get_aspect(old_carry_posture.track)
    new_posture.source_interaction = interaction.super_interaction
    new_posture.external_transition = not use_posture_animations
    posture_context = postures.context.PostureContext(interaction.context.source, interaction.priority, None)
    transition = postures.transition.PostureTransition(new_posture, new_posture_state, posture_context, var_map)
    transition.must_run = True
    return (old_carry_posture, new_posture, new_posture_state, transition, var_map)
Пример #3
0
def create_exit_carry_posture(sim, target, interaction,
                              use_posture_animations):
    from postures.posture_state import PostureState
    failure_result = (None, None, None, None, None)
    slot_manifest = interaction.slot_manifest
    old_carry_posture = sim.posture_state.get_carry_posture(target)
    if old_carry_posture is None:
        return failure_result
    spec_surface = sim.posture_state.spec[SURFACE_INDEX]
    if spec_surface is not None and spec_surface[
            SURFACE_SLOT_TYPE_INDEX] is not None:
        put_down_operation = PostureOperation.PutDownObjectOnSurface(
            PostureSpecVariable.POSTURE_TYPE_CARRY_NOTHING,
            spec_surface[SURFACE_TARGET_INDEX],
            spec_surface[SURFACE_SLOT_TYPE_INDEX],
            PostureSpecVariable.CARRY_TARGET)
    else:
        put_down_operation = PostureOperation.PutDownObject(
            PostureSpecVariable.POSTURE_TYPE_CARRY_NOTHING,
            PostureSpecVariable.CARRY_TARGET)
    var_map = {
        PostureSpecVariable.CARRY_TARGET:
        target,
        PostureSpecVariable.HAND:
        PostureState.track_to_hand(old_carry_posture.track),
        PostureSpecVariable.POSTURE_TYPE_CARRY_NOTHING:
        CarryPostureStaticTuning.POSTURE_CARRY_NOTHING,
        PostureSpecVariable.SLOT:
        slot_manifest,
        PostureSpecVariable.SLOT_TEST_DEFINITION:
        interaction.create_target
    }
    current_spec = sim.posture_state.get_posture_spec(var_map)
    if current_spec is None:
        logger.warn('Failed to get posture spec for var_map: {} for {}',
                    sim.posture_state, var_map)
        return failure_result
    new_posture_spec = put_down_operation.apply(current_spec)
    if new_posture_spec is None:
        logger.warn('Failed to apply put_down_operation: {}',
                    put_down_operation)
        return failure_result
    if not new_posture_spec.validate_destination(
        (new_posture_spec, ), var_map, interaction.affordance):
        logger.warn('Failed to validate put down spec {}  with var map {}',
                    new_posture_spec, var_map)
        return failure_result
    new_posture_state = PostureState(sim, sim.posture_state, new_posture_spec,
                                     var_map)
    new_posture = new_posture_state.get_aspect(old_carry_posture.track)
    new_posture.source_interaction = interaction.super_interaction
    new_posture.external_transition = not use_posture_animations
    posture_context = postures.context.PostureContext(
        interaction.context.source, interaction.priority, None)
    transition = postures.transition.PostureTransition(new_posture,
                                                       new_posture_state,
                                                       posture_context,
                                                       var_map)
    transition.must_run = True
    return (old_carry_posture, new_posture, new_posture_state, transition,
            var_map)
Пример #4
0
def create_enter_carry_posture(sim, posture_state, carry_target, track):
    from postures.posture_state import PostureState
    var_map = {PostureSpecVariable.CARRY_TARGET: carry_target, PostureSpecVariable.HAND: PostureState.track_to_hand(track), PostureSpecVariable.POSTURE_TYPE_CARRY_OBJECT: CarryPostureStaticTuning.POSTURE_CARRY_OBJECT}
    pick_up_operation = PostureOperation.PickUpObject(PostureSpecVariable.POSTURE_TYPE_CARRY_OBJECT, PostureSpecVariable.CARRY_TARGET)
    new_source_aop = pick_up_operation.associated_aop(sim, var_map)
    new_posture_spec = pick_up_operation.apply(posture_state.get_posture_spec(var_map), enter_carry_while_holding=True)
    if new_posture_spec is None:
        raise RuntimeError('[jpollak] Failed to create new_posture_spec in enter_carry_while_holding!')
    new_posture_state = PostureState(sim, posture_state, new_posture_spec, var_map)
    new_posture = new_posture_state.get_aspect(track)
    from carry.carry_postures import CarryingNothing
    if new_posture is None or isinstance(new_posture, CarryingNothing):
        raise RuntimeError('[jpollak] Failed to create a valid new_posture ({}) from new_posture_state ({}) in enter_carry_while_holding!'.format(new_posture, new_posture_state))
    new_posture.external_transition = True
    return (new_posture_state, new_posture, new_source_aop, var_map)