def _create_enter_carry_posture(sim, posture_state, carry_target, track):
    var_map = {
        PostureSpecVariable.CARRY_TARGET:
        carry_target,
        PostureSpecVariable.HAND:
        track_to_hand(track),
        PostureSpecVariable.POSTURE_TYPE_CARRY_OBJECT:
        carry_target.get_carry_object_posture()
    }
    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(
            '[rmccord] 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(
            '[rmccord] 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)
Beispiel #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)
Beispiel #3
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)
def _create_exit_carry_posture(sim,
                               target,
                               interaction,
                               use_posture_animations,
                               preserve_posture=None):
    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]
    has_slot_surface = spec_surface is not None and spec_surface[
        SURFACE_SLOT_TYPE_INDEX] is not None
    if not target.transient and has_slot_surface:
        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: 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:
        if preserve_posture 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:
        if preserve_posture 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, sim):
        if preserve_posture is None:
            logger.warn('Failed to validate put down spec {}  with var map {}',
                        new_posture_spec, var_map)
        return failure_result
    carry_posture_overrides = {}
    if preserve_posture is not None:
        carry_posture_overrides[preserve_posture.track] = preserve_posture
    new_posture_state = PostureState(
        sim,
        sim.posture_state,
        new_posture_spec,
        var_map,
        carry_posture_overrides=carry_posture_overrides)
    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 = PostureContext(interaction.context.source,
                                     interaction.priority, None)
    transition = PostureTransition(new_posture,
                                   new_posture_state,
                                   posture_context,
                                   var_map,
                                   locked_params=interaction.locked_params)
    transition.must_run = True
    return (old_carry_posture, new_posture, new_posture_state, transition,
            var_map)