def create_constraint(self, actor, target, **kwargs): if target is None: return Nowhere( '{} is creating a RoutingSlotConstraint for a None Target.', actor) slot_constraints = [] asm_key = self.animation_element.asm_key actor_name = self.animation_element.actor_name target_name = self.animation_element.target_name state_name = self.animation_element.begin_states[0] asm = create_asm(asm_key, context=get_throwaway_animation_context()) asm.set_actor(actor_name, actor) asm.add_potentially_virtual_actor(actor_name, actor, target_name, target) asm.dirty_boundary_conditions() if actor.is_sim: age = actor.age.age_for_animation_cache else: age = None boundary_conditions = asm.get_boundary_conditions_list( actor, state_name) for (_, slots_to_params_entry) in boundary_conditions: if not slots_to_params_entry: continue slots_to_params_entry_absolute = [] for (boundary_condition_entry, param_sequences_entry) in slots_to_params_entry: (routing_transform_entry, containment_transform, _, reference_joint_exit ) = boundary_condition_entry.get_transforms(asm, target) slots_to_params_entry_absolute.append( (routing_transform_entry, reference_joint_exit, param_sequences_entry)) slot_constraint = RequiredSlotSingle( actor, target, asm, asm_key, None, actor_name, target_name, state_name, containment_transform, None, tuple(slots_to_params_entry_absolute), None, asm_name=asm.name, age=age) slot_constraints.append(slot_constraint) return create_constraint_set(slot_constraints)
def setup_asm_interaction(self, asm, sim, target, actor_name, target_name, carry_target=None, carry_target_name=None, create_target_name=None, surface_target=DEFAULT, carry_track=DEFAULT, actor_participant=AnimationParticipant.ACTOR, invalid_expected=False): if target_name is not None and (target_name == self._target_name and (target is not None and self.target is not None)) and target.id != self.target.id: if not invalid_expected: logger.error('Animation targets a different object than its posture, but both use the same actor name for the object. This is impossible to resolve. Actor name: {}, posture target: {}, interaction target: {}', target_name, target, self.target) return False if not asm.set_actor(actor_name, sim, actor_participant=actor_participant): logger.error('Failed to set actor: {0} on asm {1}', actor_name, asm) return False if sim.asm_auto_exit.apply_carry_interaction_mask: asm._set_actor_trackmask_override(actor_name, 50000, 'Trackmask_CarryInteraction') if target is not None and target_name is not None: from sims.sim import Sim if isinstance(target, Sim): if not target.posture.setup_asm_interaction(asm, target, None, target_name, None, actor_participant=AnimationParticipant.TARGET): return False else: asm.add_potentially_virtual_actor(actor_name, sim, target_name, target, target_participant=AnimationParticipant.TARGET) anim_overrides = target.get_anim_overrides(target_name) if anim_overrides is not None and anim_overrides.params: virtual_actor_map = {self._target_name: self.target} asm.update_locked_params(anim_overrides.params, virtual_actor_map) if not self._setup_custom_posture_target_name(asm, target): logger.error('Unable to setup custom posture target name for {} on {}', target, asm) _carry_target_name = carry_target_name or create_target_name if carry_target is not None and _carry_target_name is not None: asm.add_potentially_virtual_actor(actor_name, sim, _carry_target_name, carry_target, target_participant=AnimationParticipant.CARRY_TARGET) if not self._setup_asm_interaction_add_posture_info(asm, sim, target, actor_name, target_name, carry_target, carry_target_name, surface_target, carry_track): return False return True
def setup_asm_posture(self, asm, sim, target, locked_params=frozendict(), actor_param_name=DEFAULT): if actor_param_name is DEFAULT: actor_param_name = self._actor_param_name if asm is None: logger.error('Attempt to setup an asm whose value is None.') return False if sim is None: logger.error('Attempt to setup an asm {0} on a sim whose value is None.', asm) return False if not asm.set_actor(actor_param_name, sim, actor_participant=AnimationParticipant.ACTOR): logger.error('Failed to set actor sim: {0} on asm {1}', actor_param_name, asm) return False sim.set_mood_asm_parameter(asm, actor_param_name) sim.set_trait_asm_parameters(asm, actor_param_name) if target.is_part: is_mirrored = target.is_mirrored() if is_mirrored is not None: locked_params += {'isMirrored': is_mirrored} part_suffix = self.get_part_suffix() if not (target is not None and self._target_name is not None and self._setup_asm_container_parameter(asm, target, actor_param_name, part_suffix)): logger.error('Failed to set actor target: {0} on asm {1}', self._target_name, asm) return False if not PostureTrack.is_body(self.track): self._update_non_body_posture_asm() sim.on_posture_event.append(self._update_on_posture_event) if locked_params: virtual_actor_map = {self._target_name: self.target} asm.update_locked_params(locked_params, virtual_actor_map) self._setup_asm_carry_parameter(asm, target) return True
def _setup_custom_posture_target_name(self, asm, target): _custom_target_name = target.custom_posture_target_name if _custom_target_name in asm.actors: (_custom_target_actor, _) = asm.get_actor_and_suffix(_custom_target_name) if _custom_target_actor is None: return asm.set_actor(target.custom_posture_target_name, target, suffix=None, actor_participant=AnimationParticipant.CONTAINER) return True
def get_asm(self, asm_key, actor_name, setup_asm_func=None, use_cache=True, cache_key=DEFAULT, **kwargs): if use_cache: asm_dict = self._asm_registry.setdefault(self._animation_context, {}) asm = None if asm_key in asm_dict: asm = asm_dict[asm_key] if asm.current_state == 'exit': asm = None if asm is None: asm = animation.asm.Asm(asm_key, context=self._animation_context) asm_dict[asm_key] = asm else: asm = animation.asm.Asm(asm_key, context=self._animation_context) asm.set_actor(actor_name, self.owner) if not (setup_asm_func is not None and setup_asm_func(asm)): return return asm
def get_asm(self, asm_key, actor_name, setup_asm_func=None, use_cache=True, animation_context=DEFAULT, cache_key=DEFAULT, **kwargs): if animation_context is DEFAULT: animation_context = self._animation_context if use_cache: asm_dict = self._asm_registry.setdefault(animation_context, {}) asm = None if asm_key in asm_dict: asm = asm_dict[asm_key] if asm.current_state == 'exit': asm = None if asm is None: asm = animation.asm.create_asm(asm_key, context=animation_context) asm_dict[asm_key] = asm else: asm = animation.asm.create_asm(asm_key, context=animation_context) asm.set_actor(actor_name, self.owner) if self.parent_name is not None: parent = self.owner.parent if parent is not None: asm.add_potentially_virtual_actor(actor_name, self.owner, self.parent_name, parent) if setup_asm_func is not None: result = setup_asm_func(asm) if not result: logger.warn("Couldn't setup idle asm {} for {}. {}", asm, self.owner, result) return return asm
def setup_asm_additional(asm): if not asm.set_actor( best_carry_actor_and_object[0], best_carry_actor_and_object[1], actor_participant=AnimationParticipant.CREATE_TARGET): return TestResult( False, 'Failed to set actor {} for actor name {} on asm {}'. format(best_carry_actor_and_object[0], best_carry_actor_and_object[1], asm)) else: from carry.carry_utils import set_carry_track_param_if_needed set_carry_track_param_if_needed( asm, sim, best_carry_actor_and_object[0], best_carry_actor_and_object[1]) if setup_asm_additional_override is not None: return setup_asm_additional_override(asm) return True