def _get_arb(self, actor, portal_instance, *, is_mirrored): arb = Arb() asm = create_asm(self.animation_element.asm_key, context=get_throwaway_animation_context()) asm.set_actor(self.animation_element.actor_name, actor) slide_end_location = self.slide_end_location(portal_instance.obj) if is_mirrored: entry_location = slide_end_location exit_location = portal_instance.back_exit else: entry_location = portal_instance.there_entry exit_location = slide_end_location initial_translation = sims4.math.Vector3(exit_location.position.x, entry_location.position.y, exit_location.position.z) asm.set_actor_parameter(self.animation_element.actor_name, actor, animation_constants.ASM_INITIAL_TRANSLATION, initial_translation) asm.set_actor_parameter(self.animation_element.actor_name, actor, animation_constants.ASM_INITIAL_ORIENTATION, entry_location.orientation) asm.set_actor_parameter(self.animation_element.actor_name, actor, animation_constants.ASM_TARGET_TRANSLATION, exit_location.position) asm.set_actor_parameter(self.animation_element.actor_name, actor, animation_constants.ASM_TARGET_ORIENTATION, exit_location.orientation) asm.set_actor_parameter( self.animation_element.actor_name, actor, animation_constants.ASM_LADDER_PORTAL_ALIGNMENT, PortalAlignment.get_asm_parameter_string(self.portal_alignment)) self.animation_element.append_to_arb(asm, arb) return arb
def _get_arb(self, actor, portal_instance, *, is_mirrored): arb = Arb() asm = create_asm(self.animation_element.asm_key, context=get_throwaway_animation_context()) asm.set_actor(self.animation_element.actor_name, actor) if is_mirrored: entry_location = portal_instance.back_entry exit_location = portal_instance.back_exit else: entry_location = portal_instance.there_entry exit_location = portal_instance.there_exit asm.set_actor_parameter(self.animation_element.actor_name, actor, animation_constants.ASM_INITIAL_TRANSLATION, entry_location.position) asm.set_actor_parameter(self.animation_element.actor_name, actor, animation_constants.ASM_INITIAL_ORIENTATION, entry_location.orientation) asm.set_actor_parameter(self.animation_element.actor_name, actor, animation_constants.ASM_TARGET_TRANSLATION, exit_location.position) asm.set_actor_parameter(self.animation_element.actor_name, actor, animation_constants.ASM_TARGET_ORIENTATION, entry_location.orientation) self.animation_element.append_to_arb(asm, arb) return arb
def get_supported_postures_gen(self): for (species, animation_data) in self._actor_species_mapping.items(): asm = create_asm(animation_data._asm_key, get_throwaway_animation_context()) supported_postures = asm.get_supported_postures_for_actor( animation_data._actor_param_name) yield (species, supported_postures, asm)
def _tuning_loaded_callback(cls): for posture_data in cls._supported_postures: transition_data = cls.PostureTransitionData(posture_data.preconditions, posture_data.transition_cost) if posture_data.entry: cls._add_posture_transition(posture_data.posture_type, cls, transition_data) while posture_data.exit: cls._add_posture_transition(cls, posture_data.posture_type, transition_data) asm = animation.asm.Asm(cls._asm_key, get_throwaway_animation_context()) provided_postures = asm.provided_postures if not provided_postures: return specific_name = None family_name = None for entry in provided_postures: entry_specific_name = entry.specific if not entry_specific_name: raise ValueError('{} must provide a specific posture for all posture definition rows.'.format(asm.name)) if specific_name is None: specific_name = entry_specific_name elif entry_specific_name != specific_name: raise ValueError('{}: {} provides multiple specific postures: {}'.format(cls, asm.name, [specific_name, entry_specific_name])) entry_family_name = entry.family while entry_family_name: if family_name is None: family_name = entry_family_name elif entry_family_name != family_name: raise ValueError('{}: {} provides multiple family postures: {}'.format(cls, asm.name, [family_name, entry_family_name])) cls._provided_postures = provided_postures cls._posture_name = specific_name cls.family_name = family_name if cls.idle_animation is None: logger.error('{} has no idle_animation tuned. Every posture must have an idle animation suite!', cls)
def callback(cls, fields, source, *, factory, overrides, actor_participant_type=ParticipantType.Actor, target_participant_type=ParticipantType.TargetSim, **kwargs): if cls is None: return participant_constraint_lists = {} run_in_sequence = factory.run_in_sequence for animation_element_factory in factory.animation_element_gen(): animation_element = animation_element_factory() asm_key = animation_element.asm_key actor_name = animation_element.actor_name target_name = animation_element.target_name carry_target_name = animation_element.carry_target_name create_target_name = animation_element.create_target_name initial_state = animation_element.initial_state begin_states = animation_element.begin_states instance_overrides = overrides() total_overrides = animation_element.overrides(overrides=instance_overrides) cls.register_tuned_animation(interaction_asm_type, asm_key, actor_name, target_name, carry_target_name, create_target_name, total_overrides, actor_participant_type, target_participant_type) if animation_element_factory._child_animations: for child_args in animation_element_factory._child_animations: cls.register_tuned_animation(*child_args) if should_use_animation_constaint_cache(): return if animation_element_factory._child_constraints: for child_args in animation_element_factory._child_constraints: cls.add_auto_constraint(*child_args) from interactions.utils.animation import InteractionAsmType while interaction_asm_type == InteractionAsmType.Interaction or (interaction_asm_type == InteractionAsmType.Canonical or interaction_asm_type == InteractionAsmType.Outcome) or interaction_asm_type == InteractionAsmType.Response: from interactions.constraints import create_animation_constraint def add_participant_constraint(participant_type, animation_constraint): if animation_constraint is not None: if interaction_asm_type == InteractionAsmType.Canonical: is_canonical = True else: is_canonical = False if run_in_sequence: cls.add_auto_constraint(participant_type, animation_constraint, is_canonical=is_canonical) else: if participant_type not in participant_constraint_lists: participant_constraint_lists[participant_type] = [] participant_constraint_lists[participant_type].append(animation_constraint) animation_constraint_actor = None try: animation_constraint_actor = create_animation_constraint(asm_key, actor_name, target_name, carry_target_name, create_target_name, initial_state, begin_states, total_overrides) except: if interaction_asm_type != InteractionAsmType.Outcome: logger.exception('Exception while processing tuning for {}', cls) add_participant_constraint(actor_participant_type, animation_constraint_actor) if target_name is not None: animation_context = get_throwaway_animation_context() asm = animation.asm.Asm(asm_key, animation_context, posture_manifest_overrides=total_overrides.manifests) target_actor_definition = asm.get_actor_definition(target_name) if target_actor_definition.actor_type == ASM_ACTORTYPE_SIM: animation_constraint_target = create_animation_constraint(asm_key, target_name, actor_name, carry_target_name, create_target_name, initial_state, begin_states, total_overrides) add_participant_constraint(target_participant_type, animation_constraint_target) if not run_in_sequence and participant_constraint_lists is not None: from interactions.constraints import create_constraint_set for (participant_type, constraints_list) in participant_constraint_lists.items(): cls.add_auto_constraint(participant_type, create_constraint_set(constraints_list))
def get_provided_postures_gen(self): for (species, animation_data) in self._actor_species_mapping.items(): asm = create_asm(animation_data._asm_key, get_throwaway_animation_context()) provided_postures = asm.provided_postures if not provided_postures: continue yield (species, provided_postures, asm)
def _get_arb(self, actor, obj, *, is_mirrored): arb = Arb() asm = create_asm(self.animation_element.asm_key, context=get_throwaway_animation_context()) asm.set_actor(self.animation_element.actor_name, actor) asm.set_actor(self.animation_element.target_name, obj) asm.set_parameter('isMirrored', is_mirrored) self.animation_element.append_to_arb(asm, arb) return arb
def get_supported_postures_gen(self): asm = create_asm(self._animation_data._asm_key, get_throwaway_animation_context()) supported_postures = asm.get_supported_postures_for_actor( self._animation_data._actor_param_name) for species in Species: if species == Species.INVALID: continue yield (species, supported_postures, asm)
def get_provided_postures_gen(self): asm = create_asm(self._animation_data._asm_key, get_throwaway_animation_context()) provided_postures = asm.provided_postures if provided_postures: for species in Species: if species == Species.INVALID: continue yield (species, provided_postures, asm)
def get_asm_supported_posture(asm_key, actor_name, overrides): context = get_throwaway_animation_context() posture_manifest_overrides = None if overrides is not None: posture_manifest_overrides = overrides.manifests asm = animation.asm.create_asm( asm_key, context, posture_manifest_overrides=posture_manifest_overrides) return asm.get_supported_postures_for_actor(actor_name)
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 try_set_current_outfit(self, outfit_category_and_index, do_spin=False, arb=None, interaction=None): sim = self.get_sim_instance() if sim is None: do_spin = False if arb is None: logger.error('Must pass in a valid ARB for the clothing spin.') do_spin = False if self.can_switch_to_outfit(outfit_category_and_index): if do_spin: did_change = False def set_ending(*_, **__): nonlocal did_change if not did_change: laundry_service = services.get_laundry_service() if laundry_service is not None: laundry_service.on_spin_outfit_change( sim, outfit_category_and_index, interaction) if self.set_current_outfit(outfit_category_and_index): self._apply_on_outfit_changed_loot() did_change = True arb.register_event_handler(set_ending, handler_id=100) if sim is not None: animation_element_tuning = OutfitTuning.OUTFIT_CHANGE_ANIMATION clothing_context = get_throwaway_animation_context() clothing_change_asm = create_asm( animation_element_tuning.asm_key, context=clothing_context) clothing_change_asm.update_locked_params( sim.get_transition_asm_params()) result = sim.posture.setup_asm_interaction( clothing_change_asm, sim, None, animation_element_tuning.actor_name, None) sim.set_trait_asm_parameters( clothing_change_asm, animation_element_tuning.actor_name) if not result: logger.error( 'Could not setup asm for Clothing Change. {}', result) clothing_change_asm.request( animation_element_tuning.begin_states[0], arb) elif self.set_current_outfit(outfit_category_and_index): self._apply_on_outfit_changed_loot()
def _try_set_current_outfit(self, outfit_category_and_index, do_spin=False, arb=None): if self._sim_info_ref().can_switch_to_outfit(outfit_category_and_index): if do_spin: sim = self._sim did_change = False def set_ending(*_, **__): nonlocal did_change if not did_change: self._sim_info_ref().set_current_outfit(outfit_category_and_index) did_change = True arb.register_event_handler(set_ending, handler_id=100) clothing_context = animation.get_throwaway_animation_context() clothing_change_asm = animation.asm.Asm(ClothingChangeTunables.clothing_change_asm, context=clothing_context) sim.posture.setup_asm_interaction(clothing_change_asm, sim, None, ClothingChangeTunables.DEFAULT_ACTOR, None) clothing_change_asm.request(ClothingChangeTunables.clothing_change_state, arb) else: self._sim_info_ref().set_current_outfit(outfit_category_and_index)
def request(self, state_name, arb, *args, context=None, debug_context=None, **kwargs): context = context or self.context if context is None: logger.error('Invalid call to Asm.request() to state_name {} with no animation context on {}. Actors {}', state_name, self, self._actors, owner='rmccord') context = get_throwaway_animation_context() self.context = context current_state = self.current_state self._on_state_changed_events(self, state_name) context._pre_request(self, arb, state_name) result = super().request(state_name, arb, *args, request_id=context.request_id, **kwargs) context._post_request(self, arb, state_name) if result == native.animation.ASM_REQUESTRESULT_SUCCESS: return True if result == native.animation.ASM_REQUESTRESULT_TARGET_JUMPED_TO_TARGET_STATE: raise RuntimeError('{}: Attempt to traverse between two states ({} -> {}) where no valid path exists! Actors {}{}'.format(self, current_state, state_name, self._actors, _format_debug_context(debug_context))) else: if result == native.animation.ASM_REQUESTRESULT_TARGET_STATE_NOT_FOUND: logger.error("{}: Attempt to request state that doesn't exist - {}.{}", self, state_name, _format_debug_context(debug_context)) return False logger.error('{}: Unknown result code when requesting state - {}.{}', self, state_name, _format_debug_context(debug_context))
def on_tunable_loaded_callback(instance_class, tunable_name, source, value): animation_element = value.canonical_animation asm_key = animation_element.asm_key actor_name = animation_element.actor_name target_name = animation_element.target_name state_name = animation_element.begin_states[0] actor = StubActor(1) target = StubActor(2) animation_context = get_throwaway_animation_context() asm = create_asm(asm_key, context=animation_context) asm.set_actor(actor_name, actor) asm.set_actor(target_name, target) for posture_manifest_entry in asm.get_supported_postures_for_actor( actor_name).get_constraint_version(): for posture_type in posture_manifest_entry.posture_types: if posture_type.mobile: break break else: posture_type = None available_transforms = [] if posture_type is not None: posture = posture_type(actor, None, PostureTrack.BODY, animation_context=animation_context) boundary_conditions = asm.get_boundary_conditions_list( actor, state_name, posture=posture, target=target) for (_, slots_to_params_entry) in boundary_conditions: if not slots_to_params_entry: continue for (boundary_condition_entry, param_sequences_entry) in slots_to_params_entry: (relative_transform, _, _, _) = boundary_condition_entry.get_transforms(asm, target) available_transforms.append( (param_sequences_entry, relative_transform)) setattr(value, 'available_transforms', available_transforms)
def callback(cls, fields, source, *, factory, overrides, actor_participant_type=ParticipantType.Actor, target_participant_type=ParticipantType.TargetSim, **kwargs): if cls is None: return participant_constraint_lists = {} run_in_sequence = factory.run_in_sequence for animation_element_factory in factory.animation_element_gen(): animation_element = animation_element_factory() asm_key = animation_element.asm_key actor_name = animation_element.actor_name target_name = animation_element.target_name carry_target_name = animation_element.carry_target_name create_target_name = animation_element.create_target_name initial_state = animation_element.initial_state begin_states = animation_element.begin_states end_states = animation_element.end_states base_object_name = animation_element.base_object_name instance_overrides = overrides() total_overrides = animation_element.overrides( overrides=instance_overrides) cls.register_tuned_animation( interaction_asm_type, asm_key, actor_name, target_name, carry_target_name, create_target_name, total_overrides, actor_participant_type, target_participant_type) if animation_element_factory._child_animations: for child_args in animation_element_factory._child_animations: cls.register_tuned_animation(*child_args) if not interactions.interaction_instance_manager.BUILD_AC_CACHE and ( cls.resource_key not in sims4.resources.localwork_no_groupid and asm_key not in sims4.resources.localwork_no_groupid ) and caches.USE_ACC_AND_BCC & caches.AccBccUsage.ACC: return if animation_element_factory._child_constraints: for child_args in animation_element_factory._child_constraints: cls.add_auto_constraint(*child_args) from animation.animation_constants import InteractionAsmType if not interaction_asm_type == InteractionAsmType.Interaction: if not interaction_asm_type == InteractionAsmType.Canonical: if not interaction_asm_type == InteractionAsmType.Outcome: if interaction_asm_type == InteractionAsmType.Response: from interactions.constraints import create_animation_constraint def add_participant_constraint( participant_type, animation_constraint): if animation_constraint is not None: if interaction_asm_type == InteractionAsmType.Canonical: is_canonical = True else: is_canonical = False if run_in_sequence: cls.add_auto_constraint( participant_type, animation_constraint, is_canonical=is_canonical) else: if participant_type not in participant_constraint_lists: participant_constraint_lists[ participant_type] = [] participant_constraint_lists[ participant_type].append( animation_constraint) animation_constraint_actor = None try: animation_constraint_actor = create_animation_constraint( asm_key, actor_name, target_name, carry_target_name, create_target_name, initial_state, begin_states, end_states, total_overrides, base_object_name=base_object_name) except: if interaction_asm_type != InteractionAsmType.Outcome: logger.exception( 'Exception while processing tuning for {}', cls) add_participant_constraint( actor_participant_type, animation_constraint_actor) if target_name is not None: animation_context = get_throwaway_animation_context( ) asm = animation.asm.create_asm( asm_key, animation_context, posture_manifest_overrides= total_overrides.manifests) target_actor_definition = asm.get_actor_definition( target_name) if target_actor_definition.actor_type == ASM_ACTORTYPE_SIM: if not target_actor_definition.is_virtual: animation_constraint_target = create_animation_constraint( asm_key, target_name, actor_name, carry_target_name, create_target_name, initial_state, begin_states, end_states, total_overrides, base_object_name= base_object_name) add_participant_constraint( target_participant_type, animation_constraint_target) from interactions.constraints import create_animation_constraint def add_participant_constraint(participant_type, animation_constraint): if animation_constraint is not None: if interaction_asm_type == InteractionAsmType.Canonical: is_canonical = True else: is_canonical = False if run_in_sequence: cls.add_auto_constraint(participant_type, animation_constraint, is_canonical=is_canonical) else: if participant_type not in participant_constraint_lists: participant_constraint_lists[ participant_type] = [] participant_constraint_lists[ participant_type].append(animation_constraint) animation_constraint_actor = None try: animation_constraint_actor = create_animation_constraint( asm_key, actor_name, target_name, carry_target_name, create_target_name, initial_state, begin_states, end_states, total_overrides, base_object_name=base_object_name) except: if interaction_asm_type != InteractionAsmType.Outcome: logger.exception( 'Exception while processing tuning for {}', cls) add_participant_constraint(actor_participant_type, animation_constraint_actor) if target_name is not None: animation_context = get_throwaway_animation_context() asm = animation.asm.create_asm( asm_key, animation_context, posture_manifest_overrides=total_overrides.manifests) target_actor_definition = asm.get_actor_definition( target_name) if target_actor_definition.actor_type == ASM_ACTORTYPE_SIM: if not target_actor_definition.is_virtual: animation_constraint_target = create_animation_constraint( asm_key, target_name, actor_name, carry_target_name, create_target_name, initial_state, begin_states, end_states, total_overrides, base_object_name=base_object_name) add_participant_constraint( target_participant_type, animation_constraint_target) if not run_in_sequence: if participant_constraint_lists is not None: for (participant_type, constraints_list ) in participant_constraint_lists.items(): cls.add_auto_constraint( participant_type, create_constraint_set(constraints_list))
def _tuning_loaded_callback(cls): asm = animation.asm.Asm(cls._asm_key, get_throwaway_animation_context()) provided_postures = asm.get_supported_postures_for_actor('x') cls._provided_postures = provided_postures cls.get_provided_postures = lambda *_, **__: provided_postures