Files
UnrealEngineUWP/Engine/Source/Editor/PhAT/Private/PhATSharedData.cpp
Marc Audy ef9dbd59d7 Copying //UE4/Dev-Framework to //UE4/Dev-Main (Source: //UE4/Dev-Framework @ 3198622)
#rb None
#lockdown Nick.Penwarden

==========================
MAJOR FEATURES + CHANGES
==========================

Change 3182087 on 2016/11/01 by Lina.Halper

	PR #2328: fix morph target weight application order. (Contributed by tmiv)

	- changed order of morphtarget application to be animation and THEN SetMorphTarget
	- made sure you could clear the weight also if SetMorphTarget to be 0.f

	#jira: UE-29999

Change 3182090 on 2016/11/01 by Lina.Halper

	Fix issue where import doesn't display any message when import type hasn't been detected

Change 3182123 on 2016/11/01 by Wes.Hunt

	ensure the EngineAnalytics singleton is not being held onto by someone else during engine shutdown.

Change 3182177 on 2016/11/01 by Lina.Halper

	Fix not being able to modify Joint Target Location in detail panel

	#jira: UE-30900

Change 3182181 on 2016/11/01 by Ben.Zeigler

	Add UGameplayTagsManager::AddNativeGameplayTag to allow registering tags directly from native code. This stops them from being deleteable in the editor, and will register them even if they don't exist elsewhere
	Change internal games to use this to register their native tags. The explicit call to be done adding native tags is not required, it happens on engine post init
	Some header cleanup

Change 3182876 on 2016/11/02 by Danny.Bouimad

	Moving files

Change 3182912 on 2016/11/02 by Thomas.Sarkanen

	Added access to the viewport client from IPersonaViewport

	Allows systems to hook into the state of the client.

	#jira UE-36549 - Need to access the current viewmode in FPersonaMeshDetails

Change 3182927 on 2016/11/02 by Thomas.Sarkanen

	Initially select current asset in the asset family shortcut bar dropdown

	#jira UE-35532 - Animation dropdown submenu doesn't highlight currently selected object, where as the asset browser does

Change 3182970 on 2016/11/02 by Lukasz.Furman

	CIS fix for gameplay debugger
	copy of CL# 3165005

Change 3183123 on 2016/11/02 by Mieszko.Zielinski

	Fixed changing AreaClass of NavLinkProxy point links not having any effect on navmesh generation #UE4

Change 3183310 on 2016/11/02 by Jurre.deBaare

	Blendspace changes:
	- Moved MarkerSync code from BlendSpaceBase.cpp to BlendSpaceUtilities.h/cpp
	- Re-ordered blendspace.h/cpp
	- const correctness where possible
	- Removed unused code paths
	- Wrapped non-runtime code paths in WITH_EDITOR

	Blendspace editor refactor:
	- Moved element generators into respective AnimationBlendSpaceHelpers.h/cpp
	- New Grid Widget class
	- Simplified Blendspace(1D) editors, most things are handled within SAnimationBlendSpaceBase
	- SBlendSpaceGridWidget handles visualization and UI interaction (modifying blendspace is done through parent SAnimationBlendSpaceBase)

Change 3183344 on 2016/11/02 by James.Golding

	UEFW-181 : Move PhysX vehicle support to a plugin
	- Added FPhysicsDelegates for several useful global physics delegates (OnUpdatePhysXMaterial, OnPhysicsAssetChanged, OnPhysSceneInit, OnPhysSceneTerm)
	- Added OnPhysScenePreTick and OnPhysSceneStep delegates to FPhysScene
	- TireType is now deprecated, just kept in Engine for backwards compat. TireConfig in PhysXVehicles plugin is new structure
	- Added 'ConvertTireTypes' editor console util which creates TireConfig's from TireTypes's (using asset registry) and PhysicalMaterials, and updates any VehicleWheel BPs

Change 3183351 on 2016/11/02 by Ben.Zeigler

	Add utility functions to convert from export text versions of tag and container, which is useful when reading tags out of the asset registry

Change 3183354 on 2016/11/02 by Ben.Zeigler

	Change fortnite to use new GameplayTag functions to parse tags in the asset registry to avoid bad stall while checking mission requirements. This only works once the mission infos have been resaved

Change 3183383 on 2016/11/02 by Thomas.Sarkanen

	Persona camera fixes

	Dont reset the camera all the time when setting skeletal meshes (we only do this the first time now).
	Add shortcuts to focus the camera using 'F' key from the skeleton tree (or anywhere else that wants to). Also add a menu option to the viewport to make this more discoverable.
	Shortcut is now handles by the viewport widget instead of the client (as this is how other viewports handle it).

	#jira UE-36458 - Stop camera from resetting when doing undo or redo in persona animation editor

Change 3183409 on 2016/11/02 by Jon.Nabozny

	#rn Allow MAX_ARRAY_SIZE and MAX_ARRAY_MEMORY from RepLayout to be user configurable.

	#jira UE-35660

Change 3183625 on 2016/11/02 by James.Golding

	Hopeful fix for Mac CIS issue in PhysXVehiclesEditor

Change 3183652 on 2016/11/02 by Ben.Zeigler

	Fix issue where commonly replicated tags didn't work if load from ini was turned off.
	Fix it so gameplay tag tree is always fully sorted alphabetically, instead of only the root tags being sorted.

Change 3183856 on 2016/11/02 by Richard.Hinckley

	#jira UEDOC-4006
	Editing GameMode and GameState documentation (in Framework branch).

Change 3183902 on 2016/11/02 by Mieszko.Zielinski

	Fixed EQS debug drawing not showing item labels #UE4

	Proper implementation of CL#3183899

	#jira UE-38122

Change 3183996 on 2016/11/02 by Jon.Nabozny

	Fix DefaultMaxRepArrayMemory value to be UINT16_MAX (65535). Was previously set to 64 * 1024 = 65536.

Change 3184129 on 2016/11/02 by Ben.Zeigler

	#jira UE-38022 Move GameplayAbilities to a plugin.
	Remove GameplayAbilitiesEditorEnabled ini setting, instead enable the "GameplayAbilities" plugin in your uproject if you want abilities, it's disabled by default
	#jira UE-6947 Remove GameplayAbilityBlueprintGeneratedClass as it's not needed and was only being used half the time
	#jira UE-19427 Fix incorrect usage of WorldContextObject in ability tasks to instead be OwningAbility, as it would crash if used on anything other than a gameplay ability object

Change 3184130 on 2016/11/02 by Ben.Zeigler

	Internal game fixups for moving gameplayabilities to a plugin

Change 3184469 on 2016/11/02 by Ben.Zeigler

	Change abilities plugin to be more obviously unsupported

Change 3184565 on 2016/11/02 by dan.reynolds

	AEOverview update with HRTF test map

Change 3184800 on 2016/11/03 by Thomas.Sarkanen

	Added "Show Selected and Parents" to bone display options

	Also fixed mis-named menu section.

	#jira UE-35375 - Add 'selected bone and parents' option to Persona viewport

Change 3184810 on 2016/11/03 by James.Golding

	Remove WoflPlat PhysX 3.3 and Apex 1.3 files

Change 3184817 on 2016/11/03 by Thomas.Sarkanen

	Added facial animation support

	Added curve table to sound wave (internal or external). Added UI support for manipulating these.

	Improved curve table editor.
	- Editor can now display curves as well as tables.
	- Sparse keys are now properly supported (where keys are not presnet at some times in some curves).

	Added curve source interface.
	Added external curve node. This allows any component or actor (BP or native) that implements ICurveSourceInterface to drive curves.
	Added new audio component that can also provide curves. This handles the preroll delay (approx 0.4 seconds, depending on audio) so the mouth can open before audio is played.

	Added bulk importer plugin.
	This imports audio & FBX files and builds cuirve data into SoundWave assets.
	- Adapted exisitng FBX curve import slightly to use FRichCurves rather than FFloatCurves.
	- Added new support for importing curves to a curve table.

	Added preview of audio to Persona.
	- Added display, filtering and playback of sound waves from the anim sequence browser.
	- Audio playback with curves routed to animation now works with anim blueprints and pose assets (as we need a pose asset to preview poses!)
	- Persona now uses an Actor rather than disparate components.
	- Added overrides for AddComponent and RemoveComponent to make sure actor is hooked up correctly.
	- Preview scene can now be manipulated by plugins etc. using a delegate when it is created.
	- Single anim instance has been slightly re-worked to do its update and evaluate logic inside of a local anim node. This allows derived classes to build functionality up component-wise by adding new nodes to the 'graph'.

	#jira UEFW-7 - Routing Sound Curves to AnimBP
	#jira UEFW-5 - Support importing curves
	#jira UE-37950 - Spawn preview actor in animation editor

Change 3184837 on 2016/11/03 by James.Golding

	PR #2896: Fix FVehicleAnimInstanceProxy::PreUpdate not calling FFAnimInstanceProxy's PreUpdate (Contributed by DenizPiri)
	#jira UE-37978

Change 3184847 on 2016/11/03 by Thomas.Sarkanen

	Fixed editor shutdown crash

	Dont try to save config when UObjects are all gone.

Change 3184853 on 2016/11/03 by James.Golding

	Stop Engine module linking against PhysX vehicle lib, link that into PhysXVehicles plugin instead.

Change 3184884 on 2016/11/03 by Thomas.Sarkanen

	Anim Blueprint thread safety is now checked in the compiler

	Added new metadata keys for classes and functions to describe their thread safety.
	Added extra warnings in the anim BP compiler based around these new keys to help people catch suspect thread usage.
	Expanded the compiler erorr reporting to allow for extra rich message tokens to be appended (for documentation etc.).
	Improved BP error reporting: Now we display the actual node name instead of CallFunction_0 etc.
	CVar forcing multithreaded update is now defaulted to off. Projects now by default enable it but can more easily opt-out.

	#doc Added link to new section of AnimGraph page, which may benefit from images etc.

	#jira UE-28283 - Look into expanding the system to determine what nodes we allow to run on worker threads.

Change 3184886 on 2016/11/03 by Thomas.Sarkanen

	Content fixes for anim BP thread safety warnings

	Ocean:
	Random Float node is unsafe (uses rand() unde rthe hood) so replaced with Random Stream.

	Odin:
	Flying Bot accessed the character blueprint inside some transitions. Cached the value in the event graph instead.

	Fortnite:
	Disable threaded update for a number of anim BPs as they were using unsafe calls when using CopyPoseFromMesh

Change 3184894 on 2016/11/03 by Thomas.Sarkanen

	Fix Mac CIS

Change 3184951 on 2016/11/03 by Thomas.Sarkanen

	Fix CIS warning on clang platforms

Change 3185176 on 2016/11/03 by James.Golding

	Hopeful fix for building PhysXVehicles plugin for mac

Change 3185289 on 2016/11/03 by Alex.Delesky

	#jira UE-37773 - Updating the Gameplay Tags UI to allow for the following:

	-Addition of a tag with comments and a specific INI location
	-An "Add Subtag" button that will allow the user to create a tag underneath a specified parent that autofills most of the information (parent name and location) for the new tag
	-A dropdown menu to allow for additional actions to be performed on a tag (rename, delete, search for references)
	-Comments for gameplay tags now show up in the tooltip forthe tag rather than the tag name if one had been specified
	-Shows a tree in the Project Settings window when viewing the gameplay tag list instead of an array

Change 3185331 on 2016/11/03 by Marc.Audy

	Remove duplicated condition from if

Change 3185426 on 2016/11/03 by James.Golding

	Another attempt at fixing mac builds of PhysXVehicles plugin

Change 3185487 on 2016/11/03 by James.Golding

	- Remove TireType assets from templates/sample, add TireConfigs instead
	- Make deprecated vehicle vars visible (but not editable), to help converting content
	- Change icon for PhysX vehicle plugin

Change 3185520 on 2016/11/03 by James.Golding

	Trying yet again to fix Mac CIS!

Change 3185542 on 2016/11/03 by Ben.Zeigler

	#jira UE-34086
	Commit modified version of PR #2665 to allow overriding crouch behavior in subclasses of CharacterMovementComponent

	#jira UE-35652
	Fix crouch behavior to not change capsule until after uncroach check, to avoid causing unnecessary physics side effects
	Also had to set the TeleportPhysics flag in this case, so add code to remember if a teleport was attempted during a deferred movement, and then apply that flag during EndScopedMovementUpdate

Change 3185570 on 2016/11/03 by Marc.Audy

	Protect against theoretical crash introduced in CL# 2049861 if CreatePackage returns null.
	Remove some autos

Change 3185749 on 2016/11/03 by dan.reynolds

	AEOverview test map addition: testing Virtual Voice

Change 3185946 on 2016/11/03 by dan.reynolds

	AEOverview tweaks - clarified success conditions for Streaming Spam and Streaming Priority maps

Change 3185972 on 2016/11/03 by Lina.Halper

	Fix issue with offset of attachment getting messed up because parent doesn't tick the animation correctly when opening level from Content Browser

	#jira: UE-31890
	#code review: Thomas.Sarkanen

Change 3186043 on 2016/11/03 by Alex.Delesky

	#jira UE-37773 - Fixing some of the gameplay tags UI based on feedback

	-Right-aligned input fields for the AddNewGameplayTag and RenameGameplayTag widgets
	-Added a divider to the GameplayTag widget that will appear when the AddNewGameplayTag widget is visible
	-Tags with comments will now display both their name and their comment in tooltips

Change 3186207 on 2016/11/03 by Alex.Delesky

	#jira UE-37773 - The Gameplay Tags widget in the project browser will no longer display the disabled checkboxes and disabled text for the tag names

Change 3186321 on 2016/11/03 by Dan.Reynolds

	Removed deprecated test asset (BP_ProceduralSoundWaveTest)

Change 3186740 on 2016/11/04 by Thomas.Sarkanen

	Removed FPersona and supporting classes

	Also removed UMorphTarget's asset type actions (as it was nearly empty and we dont use them as assets any more).

	#jira UEFW-222 - Remove FPersona

Change 3186741 on 2016/11/04 by Thomas.Sarkanen

	Fix non-unity builds

Change 3186755 on 2016/11/04 by Thomas.Sarkanen

	Prevent adding keys to read-only curves in curve tables

	Lock off the shift-LMB shortcut to add keys

	#jira UE-38210 - Crash trying to add a key to a curve table in curve view

Change 3186798 on 2016/11/04 by James.Golding

	UE-37503 - Add FHitResult output to K2_LineTraceComponent

Change 3186800 on 2016/11/04 by James.Golding

	- Remove deprecated collision functions in KismetSystemLibrary
	- Remove _NEW from collision function names, add redirectors
	- Add debug draw options (TraceColor, TraceHitColor, DrawTime) to shape traces, to match line traces (UE-35941)

Change 3186989 on 2016/11/04 by James.Golding

	Fix CIS fail in Fortnte

Change 3187081 on 2016/11/04 by Wes.Hunt

	EngineAnalytics::Shutdown now checks to see if the Analytics pointer is null OR unique before ensuring. #jira UE-38125

Change 3187135 on 2016/11/04 by Jurre.deBaare

	Fix for incorrect framework version in blendspace serialization code.

Change 3187682 on 2016/11/04 by Ben.Zeigler

	#jira UE-38289 Fix crash when replicated tag array is empty

Change 3188113 on 2016/11/05 by Mieszko.Zielinski

	Removed a bunch of deprecated AI module functions #UE4

	Cut-off point at v4.10

Change 3188119 on 2016/11/05 by Mieszko.Zielinski

	Deprecated AI functionality removal fallout fixes #UE4

Change 3188121 on 2016/11/05 by Mieszko.Zielinski

	PR #2883: Added a Cone EQS Generator (Contributed by orfeasel)

	Did some massaging on change.

	#jira UE-37685

Change 3188122 on 2016/11/05 by Mieszko.Zielinski

	Bumped EnvQueryGenerator_Cone.AlignedPointsDistance's default value up to 100, which makes a bit more sense #UE4

Change 3188442 on 2016/11/07 by James.Golding

	Check in trace debug draw test map

Change 3188463 on 2016/11/07 by james.cobbett

	Submitting Pose Snapshot test map and asset

Change 3188618 on 2016/11/07 by Thomas.Sarkanen

	Expanded pose snapshot system

	Allows poses to be stored in variables.
	Split FPoseSnapshot from FAnimInstanceProxy and made it a BlueprintType USTRUCT.
	Added modes to FAnimNode_PoseSnapshot so that we can either use the named pose or a FPoseSnapshot variable pin.
	Moved pose snapshot code into USkeletalMeshComponent as it doesnt need to be on the proxy any more.

	#jira UEFW-242 - Caching poses to a Blueprint variable (and an anim node to use it with)

Change 3188619 on 2016/11/07 by Thomas.Sarkanen

	Moved "NoResetToDefaults" to the correct metadata section in ObjectMacros.h

Change 3188642 on 2016/11/07 by Thomas.Sarkanen

	Added new test for pose variables

Change 3188716 on 2016/11/07 by Ben.Zeigler

	#jira UE-38294 Fix bad error message when adding new DefaultGameplayTags.ini file

Change 3189020 on 2016/11/07 by dan.reynolds

	Added a test map for Audio Volume Ambient Zone test for Play Sound at Location

	AVOverviewAZPlaySoundAtLocation

Change 3189188 on 2016/11/07 by Jon.Nabozny

	Fix edge cases / alternate IPv6 formats in IPAddressBSDIPv6::SetIp.

	#jira UE-36607

Change 3189199 on 2016/11/07 by Jon.Nabozny

	Flag UActorComponent, USceneComponent, and UPrimitiveComponent UFUNCTIONS as UnsafeDuringActorConstruction="true" if they
	modify unreplicated properties, require use of the PhysScene, or otherwise indicate poor design.

	#jira UE-33038

Change 3189271 on 2016/11/07 by Aaron.McLeran

	UEFW-224 Refectoring UnrealEd code to move all audio related editing code to a new AudioEditor module

	- Fixups for removals
	- Several bug fixes for sound classes

Change 3189450 on 2016/11/07 by Aaron.McLeran

	Fixes for facial animation playback progress

	- Creating a per-source PlaybackTime which can be used to get a fairly accurate playback percentage function for all platforms.
	- Allowing platforms to override to get a "sample accurate" playback time for platforms that are able.

Change 3189507 on 2016/11/07 by Wes.Hunt

	* Deprecated GetUniqueDeviceId. Use GetDeviceId now instead. #jira AN-820
	  * Added warnings to each implementation of GetDeviceId as to what API it uses, and what cert requirements may be placed on it.
	* Deprecated all platform independent usages of GetMacAddress and related functions.  #jira AN-820  #jira AN-802
	* Deprecated GetMachineId. Use GetLoginId now instead. #jira AN-811
	* Update usages of MachineID throughout CrashReporter code. Left MachineId and LoginId as available attributes.
	* Removed LocalPlayer requirement for setting the Analytics UserId in internal products. Removed fallbacks for seting UserId for internal products. #jira AN-814 #jira AN-808
	* Removed GetUniqueDeviceId code from LauncherInstaller.
	* Removed redundant MachineID and AccountID from Editor.ProgramStarted analytics event.
	* Removed DeviceID from SessionStart analytics event.

	#FYI: justin.sargent, Chris.Wood, Wes.Fudala
	* Justin, reminder that FPortalRpcResponderFactory::Create will need to start using GetLoginID instead of MacAddress for IPC identifiers.
	* Chris, look over CRP code to ensure that I didn't destroy some vital bit of necessary connection with the MachineId->LoginId name change. Both values are used, and for now, they both return the same thing.
	* Wes, we didn't need GetUnqiueDeviceId attribute in BeginSession, as no one ever uses it, so I just removed it.

Change 3190032 on 2016/11/08 by Wes.Hunt

	Fix a few places I forgot to deprecate regarding GetMacAddress.

Change 3190107 on 2016/11/08 by Wes.Hunt

	Another attempt to remove deprecation warning in CIS. Apparently removing the warning for a const string initialized via a consrtuctor with a deprecated function is somewhat tricky. Still not sure why it works on my machine either way.

Change 3190326 on 2016/11/08 by Aaron.McLeran

	Fixing CIS build warning

Change 3190495 on 2016/11/08 by Jon.Nabozny

	Fix OSSNull server / session filtering to better match SessionSettings and online OSS. Make MCP, Steam, and Null LAN queries more consistent.

	#jira UE-37512

Change 3190566 on 2016/11/08 by Martin.Wilson

	Remove warning on Least Destructive (was incorrectly applied to least destructive due to legacy reasons)

	#jira UE-27323

Change 3190631 on 2016/11/08 by Martin.Wilson

	Fix notify validation not triggering when using set time/set frame context menu options

	#jira UE-37857

Change 3190666 on 2016/11/08 by Martin.Wilson

	Add info about anim instance to additive warning

	#jira UE-35930

Change 3191290 on 2016/11/09 by Thomas.Sarkanen

	Fix skeleton tree selection disappearing when filtering changes

	Note: Copying //Tasks/UE4/Dev-UEFW132-PhATUpgrade to Dev-Framework (//UE4/Dev-Framework)

	Split SSkeletonTree into multiple files
	Items now derive from the common base class ISkeletonTreeItem.
	New skeleton tree item RTTI added modlled on the drag/drop RTTI.
	Filtering is now performed independently of tree building. Filtering and building are more extensible (more of this to come).
	Item selection is now preserved on filter change.
	Filtering now (optionally) keeps the hierarchy in place.

	#jira UE-31017 - Skeleton Selection is Lost When Changing Filters

Change 3191325 on 2016/11/09 by Thomas.Sarkanen

	Fix clang CIS

Change 3191344 on 2016/11/09 by Thomas.Sarkanen

	More clang CIS fixes

Change 3191345 on 2016/11/09 by Thomas.Sarkanen

	CIS fix: Missed another enum fwd declaration

Change 3191374 on 2016/11/09 by Thomas.Sarkanen

	Remove 4.11 deprecated functions from animation systems

	Also deprecate NativeUpdateAnimation_WorkerThread as users should no longer be calling this function (it is not run on worker threads anyways).

	#jira UE-35748 - Clean up 4.11 Deprecated functions

Change 3191375 on 2016/11/09 by Thomas.Sarkanen

	Fixup Orion hero instance after deprecation

Change 3191739 on 2016/11/09 by Marc.Audy

	PhysX Vehicle plugin needs to be loaded with -game as well, so it must be Developer, not Editor.

Change 3191827 on 2016/11/09 by Marc.Audy

	Raw Input plugin allowing support of steering wheels and flightsticks
	#jira UEFW-237

Change 3191828 on 2016/11/09 by Ben.Zeigler

	#jira UE-38384 Comment cleanup for gameplay tag library

Change 3191889 on 2016/11/09 by Ben.Zeigler

	#jira UE-38294 Fix issues with trying to set not-yet-written settings files as writable and add them to source control
	If a settings file does not yet exist on disk, also try adding to source control after writing it

Change 3191911 on 2016/11/09 by Marc.Audy

	Enable raw input plugin and configure for use with the Logitech G920 all vehicle templates and vehicle game.
	#jira UEFW-237

Change 3191915 on 2016/11/09 by Marc.Audy

	Provide useful tooltips for raw input setting properties
	#jira UEFW-237

Change 3192039 on 2016/11/09 by dan.reynolds

	AEOverview Update

	- Added a map for checking multi-channel file playback: AEOverviewMultichannel.umap

	- Incorporated AVOverviewAZPlaySoundAtLocation test into the AEOverviewMain submap list temporarily for testing purposes

Change 3192059 on 2016/11/09 by Martin.Wilson

	Fix montage thumbnail rendering with ref pose

	#jira UE-35578

Change 3192065 on 2016/11/09 by Martin.Wilson

	Widen bone reference widget to give a better view of the name and added full name to tooltip

	#jira UE-36264

Change 3192217 on 2016/11/09 by Martin.Wilson

	Auto selected current bone when opening bone reference tree

	#Jira UE-36264

Change 3192332 on 2016/11/09 by Marc.Audy

	Fix RawInput compiling when WITH_EDITOR is false
	#jira UE-38433

Change 3193061 on 2016/11/10 by Thomas.Sarkanen

	Marked facial animation plugin & component as experimental/beta

Change 3193072 on 2016/11/10 by Martin.Wilson

	Correct reference skeleton fix up order

Change 3193112 on 2016/11/10 by Danny.Bouimad

	Pesudo hair asset usintphat for testing

Change 3193243 on 2016/11/10 by Martin.Wilson

	Fix removal of USkeleton bone tree entries

	#Jira UE-37363

Change 3193249 on 2016/11/10 by Marc.Audy

	Raw input compile fixes:
	Fix additional not with_editor compile issues
	Fix static analysis warnings
	#jira UE-38433

Change 3193558 on 2016/11/10 by Martin.Wilson

	Move "Number of Curves" label creation to attribute so that it updates dynamically

	#jira UE-26767

Change 3193664 on 2016/11/10 by Marc.Audy

	PR #2919: Fixed Comment Typo in ActorComponent.cpp (Contributed by KumaKing)
	#jira UE-38436

Change 3193719 on 2016/11/10 by Lukasz.Furman

	fixed vertical jitter in replicated NavWalking movement
	#jira UE-33260

Change 3193802 on 2016/11/10 by Marc.Audy

	Remove some autos, fix NULL to nullptr, call GetWorld just once

Change 3193809 on 2016/11/10 by Marc.Audy

	Fix Mac CIS compile error
	#jira UE-38501

Change 3194053 on 2016/11/10 by Aaron.McLeran

	Fixed crash on shutdown when using audio mixer

	- Switching audio mixer to use a runnable thread rather than async tasks
	- Fixed issue where audio buffers weren't taking ownership of wave data

Change 3194057 on 2016/11/10 by Aaron.McLeran

	Adjusting channel mapping code to better support standard down-mixing for 2D multi-channel files.

	- Added support for 8 channel source files.

Change 3194070 on 2016/11/10 by Aaron.McLeran

	Fixing stupid compile error

Change 3194779 on 2016/11/11 by Jon.Nabozny

	Fixed UnsafeDuringActorConstruction tag on USceneComponent::GetPhysicsVolume.
	Missed the '=true' portion.

Change 3194967 on 2016/11/11 by Mieszko.Zielinski

	PR #2920: Bug Fix: fix pasting Behavior Tree nodes with decorators in wrong position (Contributed by BrettKercher)

	#jira UE-38443
	#jira UE-30906

Change 3195741 on 2016/11/11 by Ben.Zeigler

	#UE-38539 Stop Orion from reinitializing it's native tag dictionary when reloading menu, this was just slow before but now ensures

Change 3196655 on 2016/11/14 by Marc.Audy

	Remove pointless remove/adds from Odin DefaultEngine.ini.
	This also fixes the duplicate redirector of AnimNode_WheelHandler as the version in BaseEngine.ini has been changed where it points to
	#jira UE-38562

Change 3196678 on 2016/11/14 by Lukasz.Furman

	pass on gameplay debugger's EQS category
	copy of CL# 3195071, 3195152, 3196617 with local fixes

Change 3196700 on 2016/11/14 by Ben.Zeigler

	#jira UE-38539 Move where orion tags are initialized to earlier in the startup for all loading flows

Change 3196719 on 2016/11/14 by Thomas.Sarkanen

	Added extra output to anim BP compiler when a blueprint function call is used

	This allows us to give more info to users when unsafe things (like blueprint functions) are used.

Change 3196799 on 2016/11/14 by Jurre.deBaare

	Fix for blendspace tooltip crash
	#fix Check before dereferencing animation ptr on samples :)

Change 3196971 on 2016/11/14 by Lukasz.Furman

	replaced hardcoded value for pathfollowing's focal point distance with a parameter
	#ue4

Change 3196994 on 2016/11/14 by Marc.Audy

	Slightly improve performance of boolean check

Change 3197768 on 2016/11/14 by dan.reynolds

	AEOverview Stage 2 WIP

	- Added Command Line auto sub-level loading (-AELoadMap=MapName01,MapName02,etc.) or sub-level categories auto loading (-AELoadCat=AE,SC,STRM,AV,etc.)

	- Added Categorization menu to Main staging map to help sorting maps by category

	- Changed menu to be dynamically loaded from editable Data Structure Arrays, so all the menu information is loaded dynamically.

Change 3197782 on 2016/11/14 by dan.reynolds

	AEOverview Stage 2 WIP - fixed misnamed sub-level reference, cleaned up some of the BP

Change 3197801 on 2016/11/14 by dan.reynolds

	AEOverviewMain Stage 2 WIP:

	- Added Select All Buttom to select all loaded menu items

Change 3197988 on 2016/11/15 by Thomas.Sarkanen

	Add the ability to use incompatible meshes with snapshots

	We now use a name-based mapping to copy local poses to the correct bones in the hierarchy, similar to CopyPoseFromMesh.
	No access to UObjects (components or meshes) is performed on worker threads. Bone names are all cached on the game thread when needed and used on worker threads.

	#jira UE-38413 - Pose snapshot cannot be used across meshes with different hierarchies

Change 3198062 on 2016/11/15 by Thomas.Sarkanen

	Disabled threaded update on various anim blueprints to remove cook warnings

	#jira UE-38537 - Cooking FortniteGame results in warnings

Change 3198071 on 2016/11/15 by Thomas.Sarkanen

	Fix default values not being available to change post anim BP compilation

	Make sure we re-select with force refresh on so the details panel is rebuilt even if the objects are the same (as the customization relies upon it).

	#jira UE-38518 - Animation Blueprint: Default values cannot be changed after compiling if node is currently selected

Change 3198082 on 2016/11/15 by Jurre.deBaare

	CRASH If the Vertical Axis of a blendspace is set to 0 segments when an animation is on the blendspace the editor crashes
	#fix UI and ClampMin to 1
	#jira UE-38587

Change 3198138 on 2016/11/15 by Thomas.Sarkanen

	Expose montage functions to Blueprint

	Made sure to flag appropriate functions as not thread safe.
	Also const-corrected a few functions that should be.

	Github #2918: Blueprint Callable Montage Set/Get Position
	#jira UE-38391 - GitHub 2918 : Blueprint Callable Montage Set/Get Position

Change 3198141 on 2016/11/15 by Jurre.deBaare

	Crash from generated Merged Actor with no created lightmap UV
	#fix Always flag UV channel 0 to be occupied
	#jira UE-38520

Change 3198420 on 2016/11/15 by Thomas.Sarkanen

	Move thread-safety check flags to the UAnimBlueprint

	Then have the compiler propogate the flags to the CDO. Prevents issues where the old CDO wasnt propgated during compile-on-load.
	Also move blueprint usage warning flag into the UAnimBlueprint too, as these suffer from the same issues.

	#jira UE-38537 - Cooking FortniteGame results in warnings

Change 3198485 on 2016/11/15 by Thomas.Sarkanen

	Properly fix compile-on-load/cook warnings about anim blueprint thread safety

	Content only re-save.

	#jira UE-38537 - Cooking FortniteGame results in warnings

Change 3198622 on 2016/11/15 by Ben.Zeigler

	#jira UE-38632 Fix blueprint warning, was calling SetActive from construction script which is no longer allowed. This was being used for an editor-only debug feature

[CL 3198987 by Marc Audy in Main branch]
2016-11-15 15:29:41 -05:00

1646 lines
52 KiB
C++

// Copyright 1998-2016 Epic Games, Inc. All Rights Reserved.
#include "PhATPrivatePCH.h"
#include "PhATModule.h"
#include "PhysicsPublic.h"
#include "EditorSupportDelegates.h"
#include "ScopedTransaction.h"
#include "SPhATNewAssetDlg.h"
#include "PhATEdSkeletalMeshComponent.h"
#include "PhATSharedData.h"
#include "Developer/MeshUtilities/Public/MeshUtilities.h"
#include "PhysicsEngine/BodySetup.h"
#include "Engine/CollisionProfile.h"
#include "PhysicsEngine/PhysicsConstraintTemplate.h"
#include "PhysicsEngine/PhysicsHandleComponent.h"
#include "PhysicsEngine/PhysicsAsset.h"
#include "Engine/StaticMesh.h"
#define LOCTEXT_NAMESPACE "PhATShared"
FPhATSharedData::FPhATSharedData()
: PreviewScene( FPreviewScene::ConstructionValues().ShouldSimulatePhysics(true) )
, COMRenderColor(255,255,100)
, CopiedBodySetup(NULL)
, CopiedConstraintTemplate(NULL)
, bInsideSelChange(false)
{
// Editor variables
BodyEdit_MeshViewMode = PRM_Solid;
BodyEdit_CollisionViewMode = PRM_Wireframe;
BodyEdit_ConstraintViewMode = PCV_AllPositions;
ConstraintEdit_MeshViewMode = PRM_None;
ConstraintEdit_CollisionViewMode = PRM_Wireframe;
ConstraintEdit_ConstraintViewMode = PCV_AllPositions;
Sim_MeshViewMode = PRM_Solid;
Sim_CollisionViewMode = PRM_Wireframe;
Sim_ConstraintViewMode = PCV_None;
EditingMode = PEM_BodyEdit;
bShowCOM = false;
bShowHierarchy = false;
bShowInfluences = false;
bDrawGround = true;
bShowFixedStatus = true;
bShowAnimSkel = false;
bSelectionLock = false;
bRunningSimulation = false;
bNoGravitySimulation = false;
bShowInstanceProps = false;
bManipulating = false;
// Construct mouse handle
MouseHandle = NewObject<UPhysicsHandleComponent>();
// Construct sim options.
EditorSimOptions = NewObject<UPhATSimOptions>(GetTransientPackage(), TEXT("EditorSimOptions"));
check(EditorSimOptions);
EditorSimOptions->HandleLinearDamping = MouseHandle->LinearDamping;
EditorSimOptions->HandleLinearStiffness = MouseHandle->LinearStiffness;
EditorSimOptions->HandleAngularDamping = MouseHandle->AngularDamping;
EditorSimOptions->HandleAngularStiffness = MouseHandle->AngularStiffness;
EditorSimOptions->InterpolationSpeed = MouseHandle->InterpolationSpeed;
}
FPhATSharedData::~FPhATSharedData()
{
}
void FPhATSharedData::Initialize()
{
EditorSkelComp = NULL;
PhysicalAnimationComponent = nullptr;
USkeletalMesh * PreviewMesh = NULL;
FStringAssetReference PreviewMeshStringRef = PhysicsAsset->PreviewSkeletalMesh.ToStringReference();
// load it since now is the time to load
if (!PreviewMeshStringRef.ToString().IsEmpty())
{
PreviewMesh = Cast<USkeletalMesh>(StaticLoadObject(USkeletalMesh::StaticClass(), NULL, *PreviewMeshStringRef.ToString(), NULL, LOAD_None, NULL));
}
if ( PreviewMesh == NULL)
{
// Fall back to the default skeletal mesh in the EngineMeshes package.
// This is statically loaded as the package is likely not fully loaded
// (otherwise, it would have been found in the above iteration).
PreviewMesh = (USkeletalMesh*)StaticLoadObject(
USkeletalMesh::StaticClass(), NULL, TEXT("/Engine/EngineMeshes/SkeletalCube.SkeletalCube"), NULL, LOAD_None, NULL);
check(PreviewMesh);
FMessageDialog::Open(EAppMsgType::Ok, FText::Format(
NSLOCTEXT("UnrealEd", "Error_PhysicsAssetHasNoSkelMesh",
"Warning: Physics Asset has no skeletal mesh assigned! For now, a simple default skeletal mesh ({0}) will be used. You can fix this by opening PhAT, selecting the appropriate skeletal mesh in the content browser, and using (Asset -> Change Mesh) before saving this asset."),
FText::FromString(PreviewMesh->GetFullName())));
}
EditorSkelMesh = PreviewMesh;
// Create SkeletalMeshComponent for rendering skeletal mesh
EditorSkelComp = NewObject<UPhATEdSkeletalMeshComponent>();
EditorSkelComp->SharedData = this;
EditorSkelComp->SetPhysicsAsset(PhysicsAsset);
PhysicalAnimationComponent = NewObject<UPhysicalAnimationComponent>();
PhysicalAnimationComponent->SetSkeletalMeshComponent(EditorSkelComp);
// first disable collision first to avoid creating physics body
EditorSkelComp->SetCollisionProfileName(UCollisionProfile::BlockAll_ProfileName);
EditorSkelComp->SetAnimationMode(EAnimationMode::Type::AnimationSingleNode);
// Create floor component
UStaticMesh* FloorMesh = LoadObject<UStaticMesh>(NULL, TEXT("/Engine/EditorMeshes/PhAT_FloorBox.PhAT_FloorBox"), NULL, LOAD_None, NULL);
check(FloorMesh);
EditorFloorComp = NewObject<UStaticMeshComponent>();
EditorFloorComp->SetStaticMesh(FloorMesh);
EditorFloorComp->SetRelativeScale3D(FVector(4.f));
PreviewScene.AddComponent(EditorSkelComp, FTransform::Identity);
PreviewScene.AddComponent(EditorFloorComp, FTransform::Identity);
PreviewScene.AddComponent(PhysicalAnimationComponent, FTransform::Identity);
// Look for body setups with no shapes (how does this happen?).
// If we find one- just bang on a default box.
bool bFoundEmptyShape = false;
for (int32 i = 0; i <PhysicsAsset->SkeletalBodySetups.Num(); ++i)
{
UBodySetup* BodySetup = PhysicsAsset->SkeletalBodySetups[i];
if (BodySetup->AggGeom.GetElementCount() == 0)
{
FKBoxElem BoxElem;
BoxElem.SetTransform(FTransform::Identity);
BoxElem.X = 15.f;
BoxElem.Y = 15.f;
BoxElem.Z = 15.f;
BodySetup->AggGeom.BoxElems.Add(BoxElem);
check(BodySetup->AggGeom.BoxElems.Num() == 1);
bFoundEmptyShape = true;
}
}
// Pop up a warning about what we did.
if (bFoundEmptyShape)
{
FMessageDialog::Open(EAppMsgType::Ok, NSLOCTEXT("UnrealEd", "EmptyBodyFound", "Bodies was found with no primitives!\nThey have been reset to have a box."));
}
IMeshUtilities& MeshUtilities = FModuleManager::Get().LoadModuleChecked<IMeshUtilities>("MeshUtilities");
// Used for viewing bone influences, resetting bone geometry etc.
MeshUtilities.CalcBoneVertInfos(EditorSkelMesh, DominantWeightBoneInfos, true);
MeshUtilities.CalcBoneVertInfos(EditorSkelMesh, AnyWeightBoneInfos, false);
EditorSkelComp->SetSkeletalMesh(EditorSkelMesh);
EditorSkelComp->SetPhysicsAsset(PhysicsAsset);
// Ensure PhysicsAsset mass properties are up to date.
PhysicsAsset->UpdateBoundsBodiesArray();
// Check if there are any bodies in the Asset which do not have bones in the skeletal mesh.
// If so, put up a warning.
TArray<int32> MissingBodyIndices;
FString BoneNames;
for (int32 i = 0; i <PhysicsAsset->SkeletalBodySetups.Num(); ++i)
{
FName BoneName = PhysicsAsset->SkeletalBodySetups[i]->BoneName;
int32 BoneIndex = EditorSkelMesh->RefSkeleton.FindBoneIndex(BoneName);
if (BoneIndex == INDEX_NONE)
{
MissingBodyIndices.Add( i );
BoneNames += FString::Printf(TEXT("\t%s\n"), *BoneName.ToString());
}
}
const FText MissingBodyMsg = FText::Format( LOCTEXT( "MissingBones", "The following Bodies are in the PhysicsAsset, but have no corresponding bones in the SkeletalMesh.\nClick OK to delete them, or Cancel to ignore.\n\n{0}" ), FText::FromString( BoneNames ) );
if ( MissingBodyIndices.Num() )
{
if ( FMessageDialog::Open( EAppMsgType::OkCancel, MissingBodyMsg ) == EAppReturnType::Ok )
{
// Delete the bodies with no associated bones
const FScopedTransaction Transaction( LOCTEXT( "DeleteUnusedPhysicsBodies", "Delete Physics Bodies With No Bones" ) );
PhysicsAsset->SetFlags(RF_Transactional);
PhysicsAsset->Modify();
// Iterate backwards, as PhysicsAsset->SkeletalBodySetups is a TArray and UE4 containers don't support remove_if()
for ( int32 i = MissingBodyIndices.Num() - 1; i >= 0; --i )
{
DeleteBody( MissingBodyIndices[i] );
}
}
}
// Register handle component
MouseHandle->RegisterComponentWithWorld(PreviewScene.GetWorld());
// Support undo/redo
PhysicsAsset->SetFlags(RF_Transactional);
EditorSkelComp->Stop();
SetSelectedBody(NULL);
SetSelectedConstraint(INDEX_NONE);
ResetTM = EditorSkelComp->GetComponentToWorld();
EnableSimulation(false);
}
void FPhATSharedData::CopyConstraintProperties(UPhysicsConstraintTemplate * FromConstraintSetup, UPhysicsConstraintTemplate * ToConstraintSetup)
{
ToConstraintSetup->Modify();
FConstraintInstance OldInstance = ToConstraintSetup->DefaultInstance;
ToConstraintSetup->DefaultInstance.CopyConstraintParamsFrom(&FromConstraintSetup->DefaultInstance);
// recover certain data that we'd like to keep - i.e. bone indices those still should stay.
// frame position offsets taken from old, but frame orientations are taken from new source
ToConstraintSetup->DefaultInstance.ConstraintIndex = OldInstance.ConstraintIndex;
ToConstraintSetup->DefaultInstance.ConstraintData = OldInstance.ConstraintData;
ToConstraintSetup->DefaultInstance.JointName = OldInstance.JointName;
ToConstraintSetup->DefaultInstance.ConstraintBone1 = OldInstance.ConstraintBone1;
ToConstraintSetup->DefaultInstance.ConstraintBone2 = OldInstance.ConstraintBone2;
ToConstraintSetup->DefaultInstance.Pos1 = OldInstance.Pos1;
ToConstraintSetup->DefaultInstance.Pos2 = OldInstance.Pos2;
}
struct FMirrorInfo
{
FName BoneName;
int32 BoneIndex;
int32 BodyIndex;
int32 ConstraintIndex;
FMirrorInfo()
{
BoneIndex = INDEX_NONE;
BodyIndex = INDEX_NONE;
ConstraintIndex = INDEX_NONE;
BoneName = NAME_None;
}
};
void FPhATSharedData::Mirror()
{
TArray<FMirrorInfo> MirrorInfos;
if (EditingMode == PEM_BodyEdit) //grab all selected bodies
{
for (const FSelection& Selection : SelectedBodies)
{
MirrorInfos.AddUninitialized();
FMirrorInfo & MirrorInfo = MirrorInfos[MirrorInfos.Num() - 1];
MirrorInfo.BoneName = PhysicsAsset->SkeletalBodySetups[Selection.Index]->BoneName;
MirrorInfo.BodyIndex = Selection.Index;
MirrorInfo.ConstraintIndex = PhysicsAsset->FindConstraintIndex(MirrorInfo.BoneName);
}
}
else if (EditingMode == PEM_ConstraintEdit) //grab all selected constraints
{
for (const FSelection& Selection : SelectedConstraints)
{
MirrorInfos.AddUninitialized();
FMirrorInfo & MirrorInfo = MirrorInfos[MirrorInfos.Num() - 1];
MirrorInfo.BoneName = PhysicsAsset->ConstraintSetup[Selection.Index]->DefaultInstance.ConstraintBone1;
MirrorInfo.BodyIndex = PhysicsAsset->FindBodyIndex(MirrorInfo.BoneName);
MirrorInfo.ConstraintIndex = Selection.Index;
}
}
for (FMirrorInfo & MirrorInfo : MirrorInfos) //mirror all selected bodies/constraints
{
int32 BoneIndex = EditorSkelMesh->RefSkeleton.FindBoneIndex(MirrorInfo.BoneName);
int32 MirrorBoneIndex = PhysicsAsset->FindMirroredBone(EditorSkelMesh, BoneIndex);
if (MirrorBoneIndex != INDEX_NONE)
{
UBodySetup * SrcBody = PhysicsAsset->SkeletalBodySetups[MirrorInfo.BodyIndex];
const FScopedTransaction Transaction(NSLOCTEXT("PhAT", "MirrorBody", "MirrorBody"));
MakeNewBody(MirrorBoneIndex, false);
int32 MirrorBodyIndex = PhysicsAsset->FindControllingBodyIndex(EditorSkelMesh, MirrorBoneIndex);
UBodySetup * DestBody = PhysicsAsset->SkeletalBodySetups[MirrorBodyIndex];
DestBody->Modify();
DestBody->CopyBodyPropertiesFrom(SrcBody);
FQuat ArtistMirrorConvention(0,0,1,0); // how Epic Maya artists rig the right and left orientation differently. todo: perhaps move to cvar
for (FKSphylElem& Sphyl : DestBody->AggGeom.SphylElems)
{
Sphyl.Orientation = ArtistMirrorConvention*Sphyl.Orientation;
Sphyl.Center = ArtistMirrorConvention.RotateVector(Sphyl.Center);
}
for (FKBoxElem& Box : DestBody->AggGeom.BoxElems)
{
Box.Orientation = ArtistMirrorConvention*Box.Orientation;
Box.Center = ArtistMirrorConvention.RotateVector(Box.Center);
}
for (FKSphereElem& Sphere : DestBody->AggGeom.SphereElems)
{
Sphere.Center = ArtistMirrorConvention.RotateVector(Sphere.Center);
}
int32 MirrorConstraintIndex = PhysicsAsset->FindConstraintIndex(DestBody->BoneName);
UPhysicsConstraintTemplate * FromConstraint = PhysicsAsset->ConstraintSetup[MirrorInfo.ConstraintIndex];
UPhysicsConstraintTemplate * ToConstraint = PhysicsAsset->ConstraintSetup[MirrorConstraintIndex];
CopyConstraintProperties(FromConstraint, ToConstraint);
}
}
}
FPhATSharedData::EPhATRenderMode FPhATSharedData::GetCurrentMeshViewMode()
{
if (bRunningSimulation)
{
return Sim_MeshViewMode;
}
else if (EditingMode == PEM_BodyEdit)
{
return BodyEdit_MeshViewMode;
}
else
{
return ConstraintEdit_MeshViewMode;
}
}
FPhATSharedData::EPhATRenderMode FPhATSharedData::GetCurrentCollisionViewMode()
{
if (bRunningSimulation)
{
return Sim_CollisionViewMode;
}
else if (EditingMode == PEM_BodyEdit)
{
return BodyEdit_CollisionViewMode;
}
else
{
return ConstraintEdit_CollisionViewMode;
}
}
FPhATSharedData::EPhATConstraintViewMode FPhATSharedData::GetCurrentConstraintViewMode()
{
if (bRunningSimulation)
{
return Sim_ConstraintViewMode;
}
else if (EditingMode == PEM_BodyEdit)
{
return BodyEdit_ConstraintViewMode;
}
else
{
return ConstraintEdit_ConstraintViewMode;
}
}
void FPhATSharedData::HitBone(int32 BodyIndex, EKCollisionPrimitiveType PrimType, int32 PrimIndex, bool bGroupSelect /* = false*/, bool bGroupSelectRemove /* = true */)
{
if (EditingMode == FPhATSharedData::PEM_BodyEdit && !bSelectionLock && !bRunningSimulation)
{
FPhATSharedData::FSelection Selection(BodyIndex, PrimType, PrimIndex);
SetSelectedBody( &Selection, bGroupSelect, bGroupSelectRemove);
}
}
void FPhATSharedData::HitConstraint(int32 ConstraintIndex, bool bGroupSelect)
{
if (EditingMode == FPhATSharedData::PEM_ConstraintEdit && !bSelectionLock && !bRunningSimulation)
{
SetSelectedConstraint(ConstraintIndex, bGroupSelect);
}
}
void FPhATSharedData::RefreshPhysicsAssetChange(const UPhysicsAsset* InPhysAsset)
{
if (InPhysAsset)
{
for (FObjectIterator Iter(USkeletalMeshComponent::StaticClass()); Iter; ++Iter)
{
USkeletalMeshComponent* SkeletalMeshComponent = Cast<USkeletalMeshComponent>(*Iter);
if (SkeletalMeshComponent->GetPhysicsAsset() == InPhysAsset)
{
// it needs to recreate IF it already has been created
if (SkeletalMeshComponent->IsPhysicsStateCreated())
{
SkeletalMeshComponent->RecreatePhysicsState();
}
}
}
// Broadbcast delegate
FPhysicsDelegates::OnPhysicsAssetChanged.Broadcast(InPhysAsset);
FEditorSupportDelegates::RedrawAllViewports.Broadcast();
// since we recreate physicsstate, a lot of transient state data will be gone
// so have to turn simulation off again.
// ideally maybe in the future, we'll fix it by controlling tick?
EnableSimulation(false);
}
}
void FPhATSharedData::SetSelectedBodyAnyPrim(int32 BodyIndex, bool bGroupSelect /* = false */)
{
if (BodyIndex == INDEX_NONE)
{
SetSelectedBody(NULL);
return;
}
UBodySetup* BodySetup = PhysicsAsset->SkeletalBodySetups[BodyIndex];
check(BodySetup);
if (BodySetup->AggGeom.SphereElems.Num() > 0)
{
FSelection Selection(BodyIndex, KPT_Sphere, 0);
SetSelectedBody(&Selection, bGroupSelect);
}
else if (BodySetup->AggGeom.BoxElems.Num() > 0)
{
FSelection Selection(BodyIndex, KPT_Box, 0);
SetSelectedBody(&Selection, bGroupSelect);
}
else if (BodySetup->AggGeom.SphylElems.Num() > 0)
{
FSelection Selection(BodyIndex, KPT_Sphyl, 0);
SetSelectedBody(&Selection, bGroupSelect);
}
else if (BodySetup->AggGeom.ConvexElems.Num() > 0)
{
FSelection Selection(BodyIndex, KPT_Convex, 0);
SetSelectedBody(&Selection, bGroupSelect);
}
else
{
UE_LOG(LogPhAT, Fatal, TEXT("Body Setup with No Primitives!"));
}
}
void FPhATSharedData::SetSelectedBody(const FSelection* Body, bool bGroupSelect /*= false*/, bool bGroupSelectRemove /* = true */)
{
if(bInsideSelChange)
{
return;
}
if(bGroupSelect == false)
{
SelectedBodies.Empty();
}
if(Body)
{
bool bAlreadySelected = false;
//unselect if already selected
for(int32 i=0; i<SelectedBodies.Num(); ++i)
{
if(SelectedBodies[i] == *Body)
{
if(bGroupSelectRemove)
{
SelectedBodies.RemoveAt(i);
}
bAlreadySelected = true;
break;
}
}
if(bAlreadySelected == false)
{
SelectedBodies.AddUnique(*Body);
}
}
if (SelectedBodies.Num() == 0)
{
// No bone selected
SelectionChangedEvent.Broadcast(EditorSimOptions, NULL);
}
else
{
check(GetSelectedBody() && GetSelectedBody()->Index >= 0 && GetSelectedBody()->Index < PhysicsAsset->SkeletalBodySetups.Num());
// Set properties dialog to display selected bone (or bone instance) info.
TArray<UObject*> Objs;
for(int i=0; i<SelectedBodies.Num(); ++i)
{
Objs.Add(PhysicsAsset->SkeletalBodySetups[SelectedBodies[i].Index]);
}
GroupSelectionChangedEvent.Broadcast(Objs);
}
//bInsideSelChange = true;
//HierarchySelectionChangedEvent.Broadcast(); //TODO: disable for now
bInsideSelChange = false;
ControlledBones.Empty();
if(!GetSelectedBody())
{
return;
}
for (int32 i = 0; i <EditorSkelMesh->RefSkeleton.GetRawBoneNum(); ++i)
{
int32 ControllerBodyIndex = PhysicsAsset->FindControllingBodyIndex(EditorSkelMesh, i);
if (ControllerBodyIndex == GetSelectedBody()->Index)
{
ControlledBones.Add(i);
}
}
UpdateNoCollisionBodies();
PreviewChangedEvent.Broadcast();
}
void FPhATSharedData::SetSelectedBodiesFromConstraints()
{
if(SelectedConstraints.Num() == 0)
{
return;
}
SetSelectedBody(nullptr, false);
for (const FSelection& Selection : SelectedConstraints)
{
UPhysicsConstraintTemplate* ConstraintTemplate = PhysicsAsset->ConstraintSetup[Selection.Index];
FConstraintInstance & DefaultInstance = ConstraintTemplate->DefaultInstance;
for (int32 BodyIdx = 0; BodyIdx < PhysicsAsset->SkeletalBodySetups.Num(); ++BodyIdx)
{
UBodySetup* BodySetup = PhysicsAsset->SkeletalBodySetups[BodyIdx];
if (DefaultInstance.JointName == BodySetup->BoneName && BodySetup->AggGeom.GetElementCount() > 0)
{
FSelection NewSelection(BodyIdx, KPT_Unknown, 0);
int32 PrimIndex = 0;
for(int32 GeomType = 0; GeomType < KPT_Unknown; ++GeomType)
{
if(BodySetup->AggGeom.GetElementCount(GeomType) > 0)
{
NewSelection.PrimitiveType = (EKCollisionPrimitiveType)GeomType;
break;
}
}
SetSelectedBody(&NewSelection, true);
}
}
}
}
void FPhATSharedData::SetSelectedConstraintsFromBodies()
{
if (SelectedBodies.Num() == 0)
{
return;
}
TSet<int32> TmpSelectedConstraints; //We could have multiple shapes selected which would cause us to add and remove the same constraint.
SetSelectedConstraint(INDEX_NONE, false);
for (const FSelection& Selection : SelectedBodies)
{
UBodySetup* BodySetup = PhysicsAsset->SkeletalBodySetups[Selection.Index];
for(int32 ConstraintIdx = 0; ConstraintIdx < PhysicsAsset->ConstraintSetup.Num(); ++ConstraintIdx)
{
const UPhysicsConstraintTemplate* ConstraintTemplate = PhysicsAsset->ConstraintSetup[ConstraintIdx];
if(ConstraintTemplate->DefaultInstance.JointName == BodySetup->BoneName && !TmpSelectedConstraints.Contains(ConstraintIdx))
{
TmpSelectedConstraints.Add(ConstraintIdx);
SetSelectedConstraint(ConstraintIdx, true);
}
}
}
}
void FPhATSharedData::UpdateNoCollisionBodies()
{
NoCollisionBodies.Empty();
// Query disable table with selected body and every other body.
for (int32 i = 0; i <PhysicsAsset->SkeletalBodySetups.Num(); ++i)
{
// Add any bodies with bNoCollision
if (PhysicsAsset->SkeletalBodySetups[i]->DefaultInstance.GetCollisionEnabled() == ECollisionEnabled::NoCollision)
{
NoCollisionBodies.Add(i);
}
else if (GetSelectedBody() && i != GetSelectedBody()->Index)
{
// Add this body if it has disabled collision with selected.
FRigidBodyIndexPair Key(i, GetSelectedBody()->Index);
if (PhysicsAsset->SkeletalBodySetups[GetSelectedBody()->Index]->DefaultInstance.GetCollisionEnabled() == ECollisionEnabled::NoCollision ||
PhysicsAsset->CollisionDisableTable.Find(Key))
{
NoCollisionBodies.Add(i);
}
}
}
}
void FPhATSharedData::SetSelectedConstraint(int32 ConstraintIndex, bool bGroupSelect /*= false*/)
{
if(bGroupSelect == false)
{
SelectedConstraints.Empty();
}
if(ConstraintIndex != INDEX_NONE)
{
bool bAlreadySelected = false;
for(int32 i=0; i<SelectedConstraints.Num(); ++i)
{
if(SelectedConstraints[i].Index == ConstraintIndex)
{
bAlreadySelected = true;
SelectedConstraints.RemoveAt(i);
break;
}
}
if(bAlreadySelected == false)
{
FSelection Constraint(ConstraintIndex, KPT_Unknown, INDEX_NONE);
SelectedConstraints.AddUnique(Constraint);
}
}
if (!GetSelectedConstraint())
{
SelectionChangedEvent.Broadcast(EditorSimOptions, NULL);
}
else
{
check(GetSelectedConstraint()->Index >= 0 && GetSelectedConstraint()->Index < PhysicsAsset->ConstraintSetup.Num());
TArray<UObject*> Objs;
for(int i=0; i<SelectedConstraints.Num(); ++i)
{
Objs.Add(PhysicsAsset->ConstraintSetup[SelectedConstraints[i].Index]);
}
GroupSelectionChangedEvent.Broadcast(Objs);
}
PreviewChangedEvent.Broadcast();
}
void FPhATSharedData::SetCollisionBetweenSelected(bool bEnableCollision)
{
if (bRunningSimulation || SelectedBodies.Num() == 0)
{
return;
}
PhysicsAsset->Modify();
for(int32 i=0; i<SelectedBodies.Num(); ++i)
{
for(int32 j=i+1; j<SelectedBodies.Num(); ++j)
{
if(bEnableCollision)
{
PhysicsAsset->EnableCollision(SelectedBodies[i].Index, SelectedBodies[j].Index);
}else
{
PhysicsAsset->DisableCollision(SelectedBodies[i].Index, SelectedBodies[j].Index);
}
}
}
UpdateNoCollisionBodies();
PreviewChangedEvent.Broadcast();
}
void FPhATSharedData::SetCollisionBetween(int32 Body1Index, int32 Body2Index, bool bEnableCollision)
{
if (bRunningSimulation)
{
return;
}
PhysicsAsset->Modify();
if (Body1Index != INDEX_NONE && Body2Index != INDEX_NONE && Body1Index != Body2Index)
{
if (bEnableCollision)
{
PhysicsAsset->EnableCollision(Body1Index, Body2Index);
}
else
{
PhysicsAsset->DisableCollision(Body1Index, Body2Index);
}
UpdateNoCollisionBodies();
}
PreviewChangedEvent.Broadcast();
}
void FPhATSharedData::CopyBody()
{
check(SelectedBodies.Num() == 1);
CopiedBodySetup = PhysicsAsset->SkeletalBodySetups[GetSelectedBody()->Index];
}
void FPhATSharedData::PasteBodyProperties()
{
// Can't do this while simulating!
if (bRunningSimulation)
{
return;
}
// Must have two valid bodies (which are different)
if(CopiedBodySetup == NULL)
{
return;
}
const FScopedTransaction Transaction( NSLOCTEXT("PhAT", "PasteBodyProperties", "Paste Body Properties") );
for(int32 i=0; i<SelectedBodies.Num(); ++i)
{
// Copy setup/instance properties - based on what we are viewing.
if (!bShowInstanceProps)
{
UBodySetup* ToBodySetup = PhysicsAsset->SkeletalBodySetups[SelectedBodies[i].Index];
UBodySetup* FromBodySetup = CopiedBodySetup;
ToBodySetup->Modify();
ToBodySetup->CopyBodyPropertiesFrom(FromBodySetup);
}
else
{
FBodyInstance* ToBodyInstance = &PhysicsAsset->SkeletalBodySetups[SelectedBodies[i].Index]->DefaultInstance;
FBodyInstance* FromBodyInstance = &CopiedBodySetup->DefaultInstance;
ToBodyInstance->CopyBodyInstancePropertiesFrom(FromBodyInstance);
}
}
SetSelectedBody(NULL); //paste can change the primitives on our selected bodies. There's probably a way to properly update this, but for now just deselect
PreviewChangedEvent.Broadcast();
}
bool FPhATSharedData::WeldSelectedBodies(bool bWeld /* = true */)
{
bool bCanWeld = false;
if (bRunningSimulation)
{
return false;
}
if(SelectedBodies.Num() <= 1)
{
return false;
}
//we only support two body weld
int BodyIndex0 = 0;
int BodyIndex1 = INDEX_NONE;
for(int32 i=1; i<SelectedBodies.Num(); ++i)
{
if(SelectedBodies[BodyIndex0].Index == SelectedBodies[i].Index)
{
continue;
}
if(BodyIndex1== INDEX_NONE)
{
BodyIndex1 = i;
}else
{
if(SelectedBodies[BodyIndex1].Index != SelectedBodies[i].Index)
{
return false;
}
}
}
//need to weld bodies not primitives
if(BodyIndex1 == INDEX_NONE)
{
return false;
}
const FSelection& Body0 = SelectedBodies[BodyIndex0];
const FSelection& Body1 = SelectedBodies[BodyIndex1];
FName Bone0Name = PhysicsAsset->SkeletalBodySetups[Body0.Index]->BoneName;
int32 Bone0Index = EditorSkelMesh->RefSkeleton.FindBoneIndex(Bone0Name);
check(Bone0Index != INDEX_NONE);
FName Bone1Name = PhysicsAsset->SkeletalBodySetups[Body1.Index]->BoneName;
int32 Bone1Index = EditorSkelMesh->RefSkeleton.FindBoneIndex(Bone1Name);
check(Bone1Index != INDEX_NONE);
int32 Bone0ParentIndex = EditorSkelMesh->RefSkeleton.GetParentIndex(Bone0Index);
int32 Bone1ParentIndex = EditorSkelMesh->RefSkeleton.GetParentIndex(Bone1Index);
int ParentBodyIndex = INDEX_NONE;
int ChildBodyIndex = INDEX_NONE;
FName ParentBoneName;
EKCollisionPrimitiveType ParentPrimitiveType = KPT_Unknown;
EKCollisionPrimitiveType ChildPrimitiveType = KPT_Unknown;
int32 ParentPrimitiveIndex = INDEX_NONE;
int32 ChildPrimitiveIndex = INDEX_NONE;
if (PhysicsAsset->FindControllingBodyIndex(EditorSkelMesh, Bone1ParentIndex) == Body0.Index)
{
ParentBodyIndex = Body0.Index;
ParentBoneName = Bone0Name;
ChildBodyIndex = Body1.Index;
ParentPrimitiveType = Body0.PrimitiveType;
ChildPrimitiveType = Body1.PrimitiveType;
ParentPrimitiveIndex = Body0.PrimitiveIndex;
//Child geoms get appended so just add it. This is kind of a hack but this whole indexing scheme needs to be rewritten anyway
ChildPrimitiveIndex = Body1.PrimitiveIndex + PhysicsAsset->SkeletalBodySetups[Body0.Index]->AggGeom.GetElementCount(ChildPrimitiveType);
bCanWeld = true;
}else if(PhysicsAsset->FindControllingBodyIndex(EditorSkelMesh, Bone0ParentIndex) == Body1.Index)
{
ParentBodyIndex = Body1.Index;
ParentBoneName = Bone1Name;
ChildBodyIndex = Body0.Index;
ParentPrimitiveType = Body1.PrimitiveType;
ChildPrimitiveType = Body0.PrimitiveType;
ParentPrimitiveIndex = Body1.PrimitiveIndex;
//Child geoms get appended so just add it. This is kind of a hack but this whole indexing scheme needs to be rewritten anyway
ChildPrimitiveIndex = Body0.PrimitiveIndex + PhysicsAsset->SkeletalBodySetups[Body1.Index]->AggGeom.GetElementCount(ChildPrimitiveType);
bCanWeld = true;
}
//function is used for the action and the check
if(bWeld == false)
{
return bCanWeld;
}
check(ParentBodyIndex != INDEX_NONE);
check(ChildBodyIndex != INDEX_NONE);
{
const FScopedTransaction Transaction( NSLOCTEXT("UnrealEd", "WeldBodies", "Weld Bodies") );
// .. the asset itself..
PhysicsAsset->Modify();
// .. the parent and child bodies..
PhysicsAsset->SkeletalBodySetups[ParentBodyIndex]->Modify();
PhysicsAsset->SkeletalBodySetups[ChildBodyIndex]->Modify();
// .. and any constraints of the 'child' body..
TArray<int32> Constraints;
PhysicsAsset->BodyFindConstraints(ChildBodyIndex, Constraints);
for (int32 i = 0; i <Constraints.Num(); ++i)
{
int32 ConstraintIndex = Constraints[i];
PhysicsAsset->ConstraintSetup[ConstraintIndex]->Modify();
}
// Do the actual welding
FPhysicsAssetUtils::WeldBodies(PhysicsAsset, ParentBodyIndex, ChildBodyIndex, EditorSkelComp);
}
// update the tree
HierarchyChangedEvent.Broadcast();
// Body index may have changed, so we re-find it.
int32 BodyIndex = PhysicsAsset->FindBodyIndex(ParentBoneName);
FSelection SelectionParent(BodyIndex, ParentPrimitiveType, ParentPrimitiveIndex);
SetSelectedBody(&SelectionParent); // This redraws the viewport as well...
FSelection SelectionChild(BodyIndex, ChildPrimitiveType, ChildPrimitiveIndex);
SetSelectedBody(&SelectionChild, true); // This redraws the viewport as well...
// Just to be safe - deselect any selected constraints
SetSelectedConstraint(INDEX_NONE);
RefreshPhysicsAssetChange(PhysicsAsset);
return true;
}
void FPhATSharedData::InitConstraintSetup(UPhysicsConstraintTemplate* ConstraintSetup, int32 ChildBodyIndex, int32 ParentBodyIndex)
{
check(ConstraintSetup);
ConstraintSetup->Modify(false);
UBodySetup* ChildBodySetup = PhysicsAsset->SkeletalBodySetups[ ChildBodyIndex ];
UBodySetup* ParentBodySetup = PhysicsAsset->SkeletalBodySetups[ ParentBodyIndex ];
check(ChildBodySetup && ParentBodySetup);
const int32 ChildBoneIndex = EditorSkelMesh->RefSkeleton.FindBoneIndex(ChildBodySetup->BoneName);
const int32 ParentBoneIndex = EditorSkelMesh->RefSkeleton.FindBoneIndex(ParentBodySetup->BoneName);
check(ChildBoneIndex != INDEX_NONE && ParentBoneIndex != INDEX_NONE);
// Transform of child from parent is just child ref-pose entry.
FMatrix ChildBoneTM = EditorSkelComp->GetBoneMatrix(ChildBoneIndex);
ChildBoneTM.RemoveScaling();
FMatrix ParentBoneTM = EditorSkelComp->GetBoneMatrix(ParentBoneIndex);
ParentBoneTM.RemoveScaling();
FMatrix RelTM = ChildBoneTM * ParentBoneTM.Inverse();
// Place joint at origin of child
ConstraintSetup->DefaultInstance.ConstraintBone1 = ChildBodySetup->BoneName;
ConstraintSetup->DefaultInstance.Pos1 = FVector::ZeroVector;
ConstraintSetup->DefaultInstance.PriAxis1 = FVector(1.f, 0.f, 0.f);
ConstraintSetup->DefaultInstance.SecAxis1 = FVector(0.f, 1.f, 0.f);
ConstraintSetup->DefaultInstance.ConstraintBone2 = ParentBodySetup->BoneName;
ConstraintSetup->DefaultInstance.Pos2 = RelTM.GetOrigin();
ConstraintSetup->DefaultInstance.PriAxis2 = RelTM.GetUnitAxis( EAxis::X );
ConstraintSetup->DefaultInstance.SecAxis2 = RelTM.GetUnitAxis( EAxis::Y );
// Disable collision between constrained bodies by default.
SetCollisionBetween(ChildBodyIndex, ParentBodyIndex, false);
}
void FPhATSharedData::MakeNewBody(int32 NewBoneIndex, bool bAutoSelect)
{
FName NewBoneName = EditorSkelMesh->RefSkeleton.GetBoneName(NewBoneIndex);
// If this body is already physical - do nothing.
int32 NewBodyIndex = PhysicsAsset->FindBodyIndex(NewBoneName);
if (NewBodyIndex != INDEX_NONE)
{
return;
}
// Find body that currently controls this bone.
int32 ParentBodyIndex = PhysicsAsset->FindControllingBodyIndex(EditorSkelMesh, NewBoneIndex);
PhysicsAsset->Modify();
// Create the physics body.
NewBodyIndex = FPhysicsAssetUtils::CreateNewBody(PhysicsAsset, NewBoneName);
UBodySetup* BodySetup = PhysicsAsset->SkeletalBodySetups[ NewBodyIndex ];
check(BodySetup->BoneName == NewBoneName);
BodySetup->Modify();
bool bCreatedBody = false;
// Create a new physics body for this bone.
if (NewBodyData.VertWeight == EVW_DominantWeight)
{
bCreatedBody = FPhysicsAssetUtils::CreateCollisionFromBone(BodySetup, EditorSkelMesh, NewBoneIndex, NewBodyData, DominantWeightBoneInfos);
}
else
{
bCreatedBody = FPhysicsAssetUtils::CreateCollisionFromBone(BodySetup, EditorSkelMesh, NewBoneIndex, NewBodyData, AnyWeightBoneInfos);
}
if (bCreatedBody == false)
{
FPhysicsAssetUtils::DestroyBody(PhysicsAsset, NewBodyIndex);
return;
}
// Check if the bone of the new body has any physical children bones
for (int32 i = 0; i < EditorSkelMesh->RefSkeleton.GetRawBoneNum(); ++i)
{
if (EditorSkelMesh->RefSkeleton.BoneIsChildOf(i, NewBoneIndex))
{
const int32 ChildBodyIndex = PhysicsAsset->FindBodyIndex(EditorSkelMesh->RefSkeleton.GetBoneName(i));
// If the child bone is physical, it may require fixing up in regards to constraints
if (ChildBodyIndex != INDEX_NONE)
{
UBodySetup* ChildBody = PhysicsAsset->SkeletalBodySetups[ ChildBodyIndex ];
check(ChildBody);
int32 ConstraintIndex = PhysicsAsset->FindConstraintIndex(ChildBody->BoneName);
// If the child body is not constrained already, create a new constraint between
// the child body and the new body
if (ConstraintIndex == INDEX_NONE)
{
ConstraintIndex = FPhysicsAssetUtils::CreateNewConstraint(PhysicsAsset, ChildBody->BoneName);
check(ConstraintIndex != INDEX_NONE);
}
// If there's a pre-existing constraint, see if it needs to be fixed up
else
{
UPhysicsConstraintTemplate* ExistingConstraintSetup = PhysicsAsset->ConstraintSetup[ ConstraintIndex ];
check(ExistingConstraintSetup);
const int32 ExistingConstraintBoneIndex = EditorSkelMesh->RefSkeleton.FindBoneIndex(ExistingConstraintSetup->DefaultInstance.ConstraintBone2);
check(ExistingConstraintBoneIndex != INDEX_NONE);
// If the constraint exists between two child bones, then no fix up is required
if (EditorSkelMesh->RefSkeleton.BoneIsChildOf(ExistingConstraintBoneIndex, NewBoneIndex))
{
continue;
}
// If the constraint isn't between two child bones, then it is between a physical bone higher in the bone
// hierarchy than the new bone, so it needs to be fixed up by setting the constraint to point to the new bone
// instead. Additionally, collision needs to be re-enabled between the child bone and the identified "grandparent"
// bone.
const int32 ExistingConstraintBodyIndex = PhysicsAsset->FindBodyIndex(ExistingConstraintSetup->DefaultInstance.ConstraintBone2);
check(ExistingConstraintBodyIndex != INDEX_NONE);
check(ExistingConstraintBodyIndex == ParentBodyIndex);
SetCollisionBetween(ChildBodyIndex, ExistingConstraintBodyIndex, true);
}
UPhysicsConstraintTemplate* ChildConstraintSetup = PhysicsAsset->ConstraintSetup[ ConstraintIndex ];
check(ChildConstraintSetup);
InitConstraintSetup(ChildConstraintSetup, ChildBodyIndex, NewBodyIndex);
}
}
}
// If we have a physics parent, create a joint to it.
if (ParentBodyIndex != INDEX_NONE)
{
const int32 NewConstraintIndex = FPhysicsAssetUtils::CreateNewConstraint(PhysicsAsset, NewBoneName);
UPhysicsConstraintTemplate* ConstraintSetup = PhysicsAsset->ConstraintSetup[ NewConstraintIndex ];
check(ConstraintSetup);
InitConstraintSetup(ConstraintSetup, NewBodyIndex, ParentBodyIndex);
}
// update the tree
HierarchyChangedEvent.Broadcast();
if (bAutoSelect)
{
SetSelectedBodyAnyPrim(NewBodyIndex);
}
RefreshPhysicsAssetChange(PhysicsAsset);
}
void FPhATSharedData::SetConstraintRelTM(const FPhATSharedData::FSelection* Constraint, const FTransform& RelTM)
{
FTransform WParentFrame = GetConstraintWorldTM(Constraint, EConstraintFrame::Frame2);
FTransform WNewChildFrame = RelTM * WParentFrame;
UPhysicsConstraintTemplate* ConstraintSetup = PhysicsAsset->ConstraintSetup[Constraint->Index];
ConstraintSetup->Modify();
// Get child bone transform
int32 BoneIndex = EditorSkelMesh->RefSkeleton.FindBoneIndex(ConstraintSetup->DefaultInstance.ConstraintBone1);
if (BoneIndex != INDEX_NONE)
{
FTransform BoneTM = EditorSkelComp->GetBoneTransform(BoneIndex);
BoneTM.RemoveScaling();
ConstraintSetup->DefaultInstance.SetRefFrame(EConstraintFrame::Frame1, WNewChildFrame.GetRelativeTransform(BoneTM));
}
}
void FPhATSharedData::CopyConstraint()
{
check(SelectedConstraints.Num() == 1);
CopiedConstraintTemplate = PhysicsAsset->ConstraintSetup[GetSelectedConstraint()->Index];
}
void FPhATSharedData::PasteConstraintProperties()
{
if (CopiedConstraintTemplate == NULL)
{
return;
}
const FScopedTransaction Transaction( NSLOCTEXT("PhAT", "PasteConstraintProperties", "Paste Constraint Properties") );
UPhysicsConstraintTemplate* FromConstraintSetup = CopiedConstraintTemplate;
for(int32 i=0; i<SelectedConstraints.Num(); ++i)
{
// If we are showing instance properties - copy instance properties. If showing setup, just copy setup properties.
UPhysicsConstraintTemplate* ToConstraintSetup = PhysicsAsset->ConstraintSetup[SelectedConstraints[i].Index];
CopyConstraintProperties(FromConstraintSetup, ToConstraintSetup);
}
}
void CycleMatrixRows(FMatrix* TM)
{
float Tmp[3];
Tmp[0] = TM->M[0][0]; Tmp[1] = TM->M[0][1]; Tmp[2] = TM->M[0][2];
TM->M[0][0] = TM->M[1][0]; TM->M[0][1] = TM->M[1][1]; TM->M[0][2] = TM->M[1][2];
TM->M[1][0] = TM->M[2][0]; TM->M[1][1] = TM->M[2][1]; TM->M[1][2] = TM->M[2][2];
TM->M[2][0] = Tmp[0]; TM->M[2][1] = Tmp[1]; TM->M[2][2] = Tmp[2];
}
void FPhATSharedData::CycleCurrentConstraintOrientation()
{
UPhysicsConstraintTemplate* ConstraintTemplate = PhysicsAsset->ConstraintSetup[GetSelectedConstraint()->Index];
FMatrix ConstraintTransform = ConstraintTemplate->DefaultInstance.GetRefFrame(EConstraintFrame::Frame2).ToMatrixWithScale();
FTransform WParentFrame = GetConstraintWorldTM(GetSelectedConstraint(), EConstraintFrame::Frame2);
FTransform WChildFrame = GetConstraintWorldTM(GetSelectedConstraint(), EConstraintFrame::Frame1);
FTransform RelativeTransform = WChildFrame * WParentFrame.Inverse();
CycleMatrixRows(&ConstraintTransform);
ConstraintTemplate->DefaultInstance.SetRefFrame(EConstraintFrame::Frame2, FTransform(ConstraintTransform));
SetSelectedConstraintRelTM(RelativeTransform);
}
void FPhATSharedData::CycleCurrentConstraintActive()
{
for(int32 i=0; i<SelectedConstraints.Num(); ++i)
{
UPhysicsConstraintTemplate* ConstraintTemplate = PhysicsAsset->ConstraintSetup[GetSelectedConstraint()->Index];
FConstraintInstance & DefaultInstance = ConstraintTemplate->DefaultInstance;
if(DefaultInstance.GetAngularSwing1Motion() != ACM_Limited && DefaultInstance.GetAngularSwing2Motion() != ACM_Limited)
{
DefaultInstance.SetAngularSwing1Motion(ACM_Limited);
DefaultInstance.SetAngularSwing2Motion(ACM_Locked);
DefaultInstance.SetAngularTwistMotion(ACM_Locked);
}else if(DefaultInstance.GetAngularSwing2Motion() != ACM_Limited && DefaultInstance.GetAngularTwistMotion() != ACM_Limited)
{
DefaultInstance.SetAngularSwing1Motion(ACM_Locked);
DefaultInstance.SetAngularSwing2Motion(ACM_Limited);
DefaultInstance.SetAngularTwistMotion(ACM_Locked);
}else
{
DefaultInstance.SetAngularSwing1Motion(ACM_Locked);
DefaultInstance.SetAngularSwing2Motion(ACM_Locked);
DefaultInstance.SetAngularTwistMotion(ACM_Limited);
}
}
}
void FPhATSharedData::ToggleConstraint(EPhATConstraintType Constraint)
{
for(int32 i=0; i<SelectedConstraints.Num(); ++i)
{
UPhysicsConstraintTemplate* ConstraintTemplate = PhysicsAsset->ConstraintSetup[GetSelectedConstraint()->Index];
FConstraintInstance & DefaultInstance = ConstraintTemplate->DefaultInstance;
if(Constraint == PCT_Swing1)
{
DefaultInstance.SetAngularSwing1Motion(DefaultInstance.GetAngularSwing1Motion() == ACM_Limited ? ACM_Locked : ACM_Limited);
}else if(Constraint == PCT_Swing2)
{
DefaultInstance.SetAngularSwing2Motion(DefaultInstance.GetAngularSwing2Motion() == ACM_Limited ? ACM_Locked : ACM_Limited);
}else
{
DefaultInstance.SetAngularTwistMotion(DefaultInstance.GetAngularTwistMotion() == ACM_Limited ? ACM_Locked : ACM_Limited);
}
}
}
void FPhATSharedData::DeleteBody(int32 DelBodyIndex, bool bRefreshComponent)
{
const FScopedTransaction Transaction( NSLOCTEXT("UnrealEd", "DeleteBody", "Delete Body") );
// The physics asset and default instance..
PhysicsAsset->Modify();
// .. the body..
UBodySetup * BodySetup = PhysicsAsset->SkeletalBodySetups[DelBodyIndex];
BodySetup->Modify();
// .. and any constraints to the body.
TArray<int32> Constraints;
PhysicsAsset->BodyFindConstraints(DelBodyIndex, Constraints);
//we want to fixup constraints so that nearest child bodies get constraint with parent body
TArray<int32> NearestBodiesBelow;
PhysicsAsset->GetNearestBodyIndicesBelow(NearestBodiesBelow, BodySetup->BoneName, EditorSkelMesh);
int32 BoneIndex = EditorSkelMesh->RefSkeleton.FindBoneIndex(BodySetup->BoneName);
if (BoneIndex != INDEX_NONE) //it's possible to delete bodies that have no bones. In this case just ignore all of this fixup code
{
int32 ParentBodyIndex = PhysicsAsset->FindParentBodyIndex(EditorSkelMesh, BoneIndex);
UBodySetup * ParentBody = ParentBodyIndex != INDEX_NONE ? PhysicsAsset->SkeletalBodySetups[ParentBodyIndex] : NULL;
for (const int32 ConstraintIndex : Constraints)
{
UPhysicsConstraintTemplate * Constraint = PhysicsAsset->ConstraintSetup[ConstraintIndex];
Constraint->Modify();
if (ParentBody)
{
//for all constraints that contain a nearest child of this body, create a copy of the constraint between the child and parent
for (const int32 BodyBelowIndex : NearestBodiesBelow)
{
UBodySetup * BodyBelow = PhysicsAsset->SkeletalBodySetups[BodyBelowIndex];
if (Constraint->DefaultInstance.ConstraintBone1 == BodyBelow->BoneName)
{
int32 NewConstraintIndex = FPhysicsAssetUtils::CreateNewConstraint(PhysicsAsset, BodyBelow->BoneName, Constraint);
UPhysicsConstraintTemplate * NewConstraint = PhysicsAsset->ConstraintSetup[NewConstraintIndex];
InitConstraintSetup(NewConstraint, BodyBelowIndex, ParentBodyIndex);
}
}
}
}
}
// Now actually destroy body. This will destroy any constraints associated with the body as well.
FPhysicsAssetUtils::DestroyBody(PhysicsAsset, DelBodyIndex);
// Select nothing.
SetSelectedBody(NULL);
SetSelectedConstraint(INDEX_NONE);
HierarchyChangedEvent.Broadcast();
if (bRefreshComponent)
{
RefreshPhysicsAssetChange(PhysicsAsset);
}
}
void FPhATSharedData::DeleteCurrentPrim()
{
if (bRunningSimulation)
{
return;
}
if (!GetSelectedBody())
{
return;
}
// Make sure rendering is done - so we are not changing data being used by collision drawing.
FlushRenderingCommands();
//We will first get all the bodysetups we're interested in. The number of duplicates each bodysetup has tells us how many geoms are being deleted
//We need to do this first because deleting will modify our selection
TMap<UBodySetup *, TArray<FSelection>> BodySelectionMap;
TArray<UBodySetup*> BodySetups;
for(int32 i=0; i<SelectedBodies.Num(); ++i)
{
UBodySetup* BodySetup = PhysicsAsset->SkeletalBodySetups[SelectedBodies[i].Index];
BodySelectionMap.FindOrAdd(BodySetup).Add(SelectedBodies[i]);
}
const FScopedTransaction Transaction( NSLOCTEXT("UnrealEd", "DeletePrimitive", "Delete Primitive") );
for (TMap<UBodySetup*, TArray<FSelection> >::TConstIterator It(BodySelectionMap); It; ++It)
{
UBodySetup * BodySetup = It.Key();
const TArray<FSelection> & SelectedPrimitives = It.Value();
int32 SphereDeletedCount = 0;
int32 BoxDeletedCount = 0;
int32 SphylDeletedCount = 0;
int32 ConvexDeletedCount = 0;
for (int32 i = 0; i < SelectedPrimitives.Num(); ++i)
{
const FSelection& SelectedBody = SelectedPrimitives[i];
int32 BodyIndex = PhysicsAsset->FindBodyIndex(BodySetup->BoneName);
BodySetup->Modify();
if (SelectedBody.PrimitiveType == KPT_Sphere)
{
BodySetup->AggGeom.SphereElems.RemoveAt(SelectedBody.PrimitiveIndex - (SphereDeletedCount++));
}
else if (SelectedBody.PrimitiveType == KPT_Box)
{
BodySetup->AggGeom.BoxElems.RemoveAt(SelectedBody.PrimitiveIndex - (BoxDeletedCount++));
}
else if (SelectedBody.PrimitiveType == KPT_Sphyl)
{
BodySetup->AggGeom.SphylElems.RemoveAt(SelectedBody.PrimitiveIndex - (SphylDeletedCount++));
}
else if (SelectedBody.PrimitiveType == KPT_Convex)
{
BodySetup->AggGeom.ConvexElems.RemoveAt(SelectedBody.PrimitiveIndex - (ConvexDeletedCount++));
// Need to invalidate GUID in this case as cooked data must be updated
BodySetup->InvalidatePhysicsData();
}
// If this bone has no more geometry - remove it totally.
if (BodySetup->AggGeom.GetElementCount() == 0)
{
check(i == SelectedPrimitives.Num() - 1); //we should really only delete on last prim - only reason this is even in for loop is because of API needing body index
if (BodyIndex != INDEX_NONE)
{
DeleteBody(BodyIndex, false);
}
if (CopiedBodySetup == BodySetup)
{
CopiedBodySetup = NULL;
}
}
}
}
HierarchyChangedEvent.Broadcast();
SetSelectedBodyAnyPrim(INDEX_NONE); // Will call UpdateViewport
RefreshPhysicsAssetChange(PhysicsAsset);
}
FTransform FPhATSharedData::GetConstraintBodyTM(const UPhysicsConstraintTemplate* ConstraintSetup, EConstraintFrame::Type Frame) const
{
if (ConstraintSetup == NULL)
{
return FTransform::Identity;
}
int32 BoneIndex;
if (Frame == EConstraintFrame::Frame1)
{
BoneIndex = EditorSkelMesh->RefSkeleton.FindBoneIndex(ConstraintSetup->DefaultInstance.ConstraintBone1);
}
else
{
BoneIndex = EditorSkelMesh->RefSkeleton.FindBoneIndex(ConstraintSetup->DefaultInstance.ConstraintBone2);
}
// If we couldn't find the bone - fall back to identity.
if (BoneIndex == INDEX_NONE)
{
return FTransform::Identity;
}
else
{
FTransform BoneTM = EditorSkelComp->GetBoneTransform(BoneIndex);
BoneTM.RemoveScaling();
return BoneTM;
}
}
FTransform FPhATSharedData::GetConstraintWorldTM(const UPhysicsConstraintTemplate* ConstraintSetup, EConstraintFrame::Type Frame, float Scale) const
{
if (ConstraintSetup == NULL)
{
return FTransform::Identity;
}
FVector Scale3D(Scale);
int32 BoneIndex;
FTransform LFrame = ConstraintSetup->DefaultInstance.GetRefFrame(Frame);
if (Frame == EConstraintFrame::Frame1)
{
BoneIndex = EditorSkelMesh->RefSkeleton.FindBoneIndex(ConstraintSetup->DefaultInstance.ConstraintBone1);
}
else
{
BoneIndex = EditorSkelMesh->RefSkeleton.FindBoneIndex(ConstraintSetup->DefaultInstance.ConstraintBone2);
}
// If we couldn't find the bone - fall back to identity.
if (BoneIndex == INDEX_NONE)
{
return FTransform::Identity;
}
else
{
FTransform BoneTM = EditorSkelComp->GetBoneTransform(BoneIndex);
BoneTM.RemoveScaling();
LFrame.ScaleTranslation(Scale3D);
return LFrame * BoneTM;
}
}
FTransform FPhATSharedData::GetConstraintMatrix(int32 ConstraintIndex, EConstraintFrame::Type Frame, float Scale) const
{
UPhysicsConstraintTemplate* ConstraintSetup = PhysicsAsset->ConstraintSetup[ConstraintIndex];
return GetConstraintWorldTM(ConstraintSetup, Frame, Scale);
}
FTransform FPhATSharedData::GetConstraintWorldTM(const FSelection* Constraint, EConstraintFrame::Type Frame) const
{
int32 ConstraintIndex = Constraint ? Constraint->Index : INDEX_NONE;
if (ConstraintIndex == INDEX_NONE)
{
return FTransform::Identity;
}
UPhysicsConstraintTemplate* ConstraintSetup = PhysicsAsset->ConstraintSetup[ConstraintIndex];
return GetConstraintWorldTM(ConstraintSetup, Frame, 1.f);
}
void FPhATSharedData::DeleteCurrentConstraint()
{
if (EditingMode != PEM_ConstraintEdit || !GetSelectedConstraint())
{
return;
}
const FScopedTransaction Transaction( NSLOCTEXT("PhAT", "DeleteConstraint", "Delete Constraint") );
//Save indices before delete because delete modifies our Selected array
TArray<int32> Indices;
for(int32 i=0; i<SelectedConstraints.Num(); ++i)
{
Indices.Add(SelectedConstraints[i].Index);
}
Indices.Sort();
//These are indices into an array, we must remove it from greatest to smallest so that the indices don't shift
for(int32 i=Indices.Num() - 1; i>= 0; --i)
{
if(PhysicsAsset->ConstraintSetup[Indices[i]] == CopiedConstraintTemplate)
{
CopiedConstraintTemplate = NULL;
}
PhysicsAsset->Modify();
FPhysicsAssetUtils::DestroyConstraint(PhysicsAsset, Indices[i]);
}
SetSelectedConstraint(INDEX_NONE);
HierarchyChangedEvent.Broadcast();
PreviewChangedEvent.Broadcast();
}
void FPhATSharedData::ToggleInstanceProperties()
{
bShowInstanceProps = !bShowInstanceProps;
PreviewChangedEvent.Broadcast();
if (EditingMode == PEM_ConstraintEdit)
{
if (GetSelectedConstraint())
{
UPhysicsConstraintTemplate* ConSetup = PhysicsAsset->ConstraintSetup[GetSelectedConstraint()->Index];
FSelection Selection(GetSelectedConstraint()->Index, KPT_Unknown, INDEX_NONE);
SelectionChangedEvent.Broadcast(ConSetup, &Selection);
}
}
else if (EditingMode == PEM_BodyEdit)
{
if (GetSelectedBody())
{
UBodySetup* BodySetup = PhysicsAsset->SkeletalBodySetups[GetSelectedBody()->Index];
// Set properties dialog to display selected bone (or bone instance) info.
SelectionChangedEvent.Broadcast(BodySetup, GetSelectedBody());
}
}
}
void FPhATSharedData::ToggleSimulation()
{
// don't start simulation if there are no bodies or if we are manipulating a body
if (PhysicsAsset->SkeletalBodySetups.Num() == 0 || bManipulating)
{
return;
}
EnableSimulation(!bRunningSimulation);
bRunningSimulation = !bRunningSimulation;
}
void FPhATSharedData::EnableSimulation(bool bEnableSimulation)
{
if (bEnableSimulation)
{
// Flush geometry cache inside the asset (don't want to use cached version of old geometry!)
PhysicsAsset->InvalidateAllPhysicsMeshes();
// We should not already have an instance (destroyed when stopping sim).
EditorSkelComp->SetSimulatePhysics(true);
EditorSkelComp->SetPhysicsBlendWeight(EditorSimOptions->PhysicsBlend);
EditorSkelComp->InitArticulated(PreviewScene.GetWorld()->GetPhysicsScene());
PhysicalAnimationComponent->SetSkeletalMeshComponent(EditorSkelComp);
// Make it start simulating
EditorSkelComp->WakeAllRigidBodies();
// Set the properties window to point at the simulation options object.
SelectionChangedEvent.Broadcast(EditorSimOptions, NULL);
}
else
{
// Stop any animation and clear node when stopping simulation.
EditorSkelComp->SetAnimation(NULL);
PhysicalAnimationComponent->SetSkeletalMeshComponent(nullptr);
// Turn off/remove the physics instance for this thing, and move back to start location.
EditorSkelComp->TermArticulated();
EditorSkelComp->SetSimulatePhysics(false);
EditorSkelComp->SetPhysicsBlendWeight(0.f);
// Since simulation, actor location changes. Reset to identity
EditorSkelComp->SetWorldTransform(ResetTM);
// Force an update of the skeletal mesh to get it back to ref pose
EditorSkelComp->RefreshBoneTransforms();
PreviewChangedEvent.Broadcast();
// Put properties window back to selected.
if (EditingMode == FPhATSharedData::PEM_BodyEdit)
{
SetSelectedBody(NULL, true);
}
else
{
SetSelectedConstraint(INDEX_NONE, true);
}
}
}
void FPhATSharedData::OpenNewBodyDlg()
{
OpenNewBodyDlg(&NewBodyData, &NewBodyResponse);
}
void FPhATSharedData::OpenNewBodyDlg(FPhysAssetCreateParams* NewBodyData, EAppReturnType::Type* NewBodyResponse)
{
auto ModalWindow = SNew(SWindow)
.Title( NSLOCTEXT("PhAT", "NewAssetTitle", "New Asset") )
.SizingRule( ESizingRule::Autosized )
.SupportsMinimize(false) .SupportsMaximize(false);
auto MessageBox = SNew(SPhATNewAssetDlg)
.ParentWindow(ModalWindow)
.NewBodyData(NewBodyData)
.NewBodyResponse(NewBodyResponse);
ModalWindow->SetContent(MessageBox);
GEditor->EditorAddModalWindow(ModalWindow);
}
void FPhATSharedData::PostUndo()
{
if (bRunningSimulation)
{
return;
}
bool bInvalidSelection = false;
for (int32 BodyIndex = 0; BodyIndex < SelectedBodies.Num() && bInvalidSelection == false; ++BodyIndex)
{
const FSelection& Selection = SelectedBodies[BodyIndex];
if (PhysicsAsset->SkeletalBodySetups.Num() <= Selection.Index)
{
bInvalidSelection = true;
}
else
{
if (UBodySetup * BodySetup = PhysicsAsset->SkeletalBodySetups[Selection.Index])
{
switch (Selection.PrimitiveType)
{
case KPT_Box: bInvalidSelection = BodySetup->AggGeom.BoxElems.Num() <= Selection.PrimitiveIndex ? true : bInvalidSelection; break;
case KPT_Convex: bInvalidSelection = BodySetup->AggGeom.ConvexElems.Num() <= Selection.PrimitiveIndex ? true : bInvalidSelection; break;
case KPT_Sphere: bInvalidSelection = BodySetup->AggGeom.SphereElems.Num() <= Selection.PrimitiveIndex ? true : bInvalidSelection; break;
case KPT_Sphyl: bInvalidSelection = BodySetup->AggGeom.SphylElems.Num() <= Selection.PrimitiveIndex ? true : bInvalidSelection; break;
default: bInvalidSelection = true;
}
}
else
{
bInvalidSelection = true;
}
}
}
for (int32 ConstraintIndex = 0; ConstraintIndex < SelectedConstraints.Num() && bInvalidSelection == false; ++ConstraintIndex)
{
const FSelection& Selection = SelectedConstraints[ConstraintIndex];
if (PhysicsAsset->ConstraintSetup.Num() <= Selection.Index)
{
bInvalidSelection = true;
}
}
if (bInvalidSelection)
{
// Clear selection before we undo. We don't transact the editor itself - don't want to have something selected that is then removed.
SetSelectedBody(NULL);
SetSelectedConstraint(INDEX_NONE);
}
PreviewChangedEvent.Broadcast();
HierarchyChangedEvent.Broadcast();
}
void FPhATSharedData::Redo()
{
if (bRunningSimulation)
{
return;
}
SetSelectedBody(NULL);
SetSelectedConstraint(INDEX_NONE);
GEditor->RedoTransaction();
PhysicsAsset->UpdateBodySetupIndexMap();
PreviewChangedEvent.Broadcast();
HierarchyChangedEvent.Broadcast();
}
void FPhATSharedData::AddReferencedObjects(FReferenceCollector& Collector)
{
Collector.AddReferencedObject(PhysicsAsset);
Collector.AddReferencedObject(EditorSkelComp);
Collector.AddReferencedObject(PhysicalAnimationComponent);
Collector.AddReferencedObject(EditorSkelMesh);
Collector.AddReferencedObject(EditorFloorComp);
Collector.AddReferencedObject(EditorSimOptions);
Collector.AddReferencedObject(MouseHandle);
Collector.AddReferencedObject(CopiedBodySetup);
Collector.AddReferencedObject(CopiedConstraintTemplate);
PreviewScene.AddReferencedObjects(Collector);
}
#undef LOCTEXT_NAMESPACE