Files
UnrealEngineUWP/Engine/Source/Editor/StaticMeshEditor/Private/StaticMeshEditor.cpp
Thomas Sarkanen 1102c5e12c Copying //UE4/Dev-AnimPhys to //UE4/Dev-Main (Source: //UE4/Dev-AnimPhys @ 3384744)
#lockdown Nick.Penwarden

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

Change 3294073 on 2017/02/09 by Thomas.Sarkanen

	Delete old location of FriendViewModel.h that did not get picked up correctly in the merge

Change 3354003 on 2017/03/20 by Thomas.Sarkanen

	Back out changelist 3353914

Change 3355932 on 2017/03/21 by Thomas.Sarkanen

	Back out changelist 3354003

	Reinstating merge from Main:

	Merging //UE4/Dev-Main to Dev-AnimPhys (//UE4/Dev-AnimPhys) @ CL 3353839

Change 3358776 on 2017/03/22 by Ori.Cohen

	Recreate physics when changing mobility of components - fixes debug rendering issue

	#JIRA UE-39328

Change 3360075 on 2017/03/23 by James.Golding

	Back out changelist 3358776, as it was made after smoke testing. Will re-submit after copy to main.

Change 3362695 on 2017/03/24 by Thomas.Sarkanen

	Use correct extender when building menus for AnimationEditor, SkeletalMeshEditor & SkeletonEditor

	#jira UE-41100 - Persona code calling incorrect extenders when building menus.

Change 3362696 on 2017/03/24 by Thomas.Sarkanen

	Facial animation experimental feature now pops up restart editor toast

	#jira UE-40989 - User is not prompted to restart the editor when enabling the Facial Animation Importer

Change 3362699 on 2017/03/24 by Thomas.Sarkanen

	Enable snapping for translation in animation viewports

	#jira UE-39747 - Translating sockets in Persona is not affected by Snap Options
	#jira UE-39748 - Translating bones in Persona is not affected by Snap Options

Change 3362700 on 2017/03/24 by Thomas.Sarkanen

	Curve source nodes now dont update their source title if the source is a pin

	The title of the node is not recached when the pin default changes, so we cant display it in the title

	#jira UE-40108 - When changing a Curve Source Node doesn't update source binding name when typed in

Change 3362721 on 2017/03/24 by Thomas.Sarkanen

	CVar r.SkeletalMeshLODBias no longer affects meshes in animation viewports

	#jira UE-35733 - GSkeletalMeshLODBias affects render LOD in Persona

Change 3362724 on 2017/03/24 by Thomas.Sarkanen

	Fix animation preview scene keyboard bindings

	Also moved advanced preview scene into its own module

	#jira UE-41505 - Pressing the hotkey I and O do not hide the floor and environment if the Preview Scene Settings tab isn't opened.

Change 3362783 on 2017/03/24 by Ori.Cohen

	Fix incorrect locking and check when an editor static shape is changed. Originally this code assumed it would only get called at runtime, where there is only 1 shape. In the case of the async scene and static shapes - there are two shapes and if you update the body setup in the editor this will crash.

Change 3362796 on 2017/03/24 by Ori.Cohen

	Fix welded capsules not using the right rotation

	#JIRA UE-41546

Change 3362803 on 2017/03/24 by Ori.Cohen

	Recreate physics when changing mobility of components - fixes debug rendering issue

	#JIRA UE-39328

Change 3363013 on 2017/03/24 by Thomas.Sarkanen

	Fix CIS issue

Change 3363202 on 2017/03/24 by Ori.Cohen

	Fix bad #endif

Change 3363295 on 2017/03/24 by Ori.Cohen

	Remove bWelded and use WeldParent everywhere. This fixes a bad case where a kinematic is returned as the root welded of simulated children.

	#JIRA UE-40783

Change 3363435 on 2017/03/24 by Jon.Nabozny

	Fix infinite jump on client when Jump Max Hold Time is not 0.

	#jira UE-41004

Change 3363451 on 2017/03/24 by Jon.Nabozny

	Fix USkeletalMeshComponent::PoseTickedThisFrame to use a frame counter instead of world time (which isn't changed while paused).

	#jira UE-39567

Change 3363504 on 2017/03/24 by Jon.Nabozny

	Fix SCE_NP_MATCHING2_REQUEST_EVENT_SEARCH_ROOM_A to treat result data as linked list instead of array.
	(Code originally came from SCE via UDN)

	#jira UE-41049

Change 3363532 on 2017/03/24 by Ori.Cohen

	Change default to SkipSimulatedBones.

	#JIRA UE-41404

Change 3363537 on 2017/03/24 by Ori.Cohen

	Remove the unsupported option of HideBone with DisableCollision. If we want this in the future we can add it.

	#JIRA UE-30826

Change 3363681 on 2017/03/24 by Jon.Nabozny

	Reapply 3292286 after it was clobbered by 3360002
	(Only clobbered in Ocean).

	#jira UE-37512

Change 3363722 on 2017/03/24 by mason.seay

	Updated map to improve testing

Change 3365351 on 2017/03/27 by Thomas.Sarkanen

	Fix non-PCH CIS errors

	#jira UE-43335 - CIS fail: 'FAdvancedPreviewSceneCommands is not a class name

Change 3365422 on 2017/03/27 by Thomas.Sarkanen

	Fixed skinned mesh LOD not updating in editor under various physics-related circumstances

	#jira UE-42013 - Skeletal meshes with recently generated LODs will not change LODs in viewport

Change 3365423 on 2017/03/27 by Thomas.Sarkanen

	Fix ensure when setting Spline IK Bone Axis  to 'None'

	Node is currently not in use, so I've avoided deprecating this for now. Values should be preserved.

	#jira UE-39723 - Ensure when setting Bone Axis to None in Spline IK

Change 3365424 on 2017/03/27 by Thomas.Sarkanen

	Fix control rigs being convertable to possessables

	Also prevent 'export to anim sequence' button from appearing on standard level sequences

	#jira UE-42070 - Crash converting a control rig to Possessable

Change 3365425 on 2017/03/27 by Thomas.Sarkanen

	When selecting bones that are non-required, we dont render gizmos or text labels

	#jira UE-35737 - Bone labels flicker between two locations when removing from LOD levels in Persona

Change 3365426 on 2017/03/27 by Thomas.Sarkanen

	Fixed foot placement IK doing line traces on worker threads

	Also exposed const access to required bones array (the proxy already does this, so I figure the instance should get it too).
	Note: Node is not actually used

	#jira UE-43179 - Fix FAnimNode_FootPlacementIK doing line trace on worker thread

Change 3365428 on 2017/03/27 by Thomas.Sarkanen

	Skeleton selection no does not lag behind choice made in viewport

	#jira UE-42236 - Mesh Overlay always lags behind actual selection

Change 3365429 on 2017/03/27 by Thomas.Sarkanen

	Fix anim BPs that contain state machines having blank palettes

	#jira UE-42172 - AnimBP Palette is blank on existing AnimBPs

Change 3365435 on 2017/03/27 by Jurre.deBaare

	Undoing Channel selection in Paint mode does not work
	#fix use duplicated CDO object instead of CDO directly
	#jira UE-42621

Change 3365436 on 2017/03/27 by Jurre.deBaare

	Functionless undo/redo transactions created when importing Alembic file and changing conversion settings
	#fix use duplicated CDO object instead of CDO directly
	#jira UE-40347

Change 3365437 on 2017/03/27 by Jurre.deBaare

	Ensure that HLOD cannot be set up in sub-levels
	#fix added functionality to check whether or not a level is used as a sub/streaming level in any other content, and if so show a widget similar to the checkout notice to inform the user why the hlod outliner is disabled
	#jira UE-40301

Change 3365438 on 2017/03/27 by Jurre.deBaare

	2D Blendspace breaks when aligning samples in a straight line
	#fix for some reason the number of samples to considerate was limit to 3 (old code) so removed it since it doesn't make sense
	#jira UE-42744

Change 3365439 on 2017/03/27 by Jurre.deBaare

	Color View Mode doesn't reset when closing/reopening editor
	#fix added a delegate to OnEditorClose to ensure we can reset the viewport modes while they still exist, this issue would happen if the user closes the editor with mesh paint mode open, exiting the mode would only happen after destructing most of the editor
	#jira UE-42466

Change 3365440 on 2017/03/27 by Jurre.deBaare

	LOD Model field scrubbing is very sensitive
	#fix made sure that max slider value is also driven by data
	#jira UE-42980

Change 3365441 on 2017/03/27 by Jurre.deBaare

	Replacing an asset in a sequence player node does not register in undo history
	#fix added transaction for dropping anim assets on player nodes
	#jira UE-39152

Change 3365442 on 2017/03/27 by Jurre.deBaare

	Crash on Mac importing some alembic files
	#fix disable multithread abc file reading with HDF5 backend
	#jira UE-39783

Change 3365443 on 2017/03/27 by Jurre.deBaare

	Moving over Alembic feature: "Add support for 'finding' materials according to the face-set names in abc files"

Change 3365444 on 2017/03/27 by Jurre.deBaare

	Moving over Alembic fixes:
	- Time offset issues > changed how we determine frame indices and frame steps
	- Incorrect tangent issues > enforce tangent calculation during skeletal mesh import
	- Automatically set recompute tangent flag on skeletal mesh sections

Change 3365451 on 2017/03/27 by Jurre.deBaare

	CIS: include needed for GetTransientPackage

Change 3365460 on 2017/03/27 by Jurre.deBaare

	CIS: apparently CIS wants explicit cast to UObject

Change 3365463 on 2017/03/27 by Jurre.deBaare

	CIS: final fix, was actually UPackage include missing ugh

Change 3365486 on 2017/03/27 by Thomas.Sarkanen

	Fix case error in include for Linux builds

Change 3365499 on 2017/03/27 by James.Golding

	Fix editing collision settings sometimes not 'sticking' - wait until after LoadProfileConfig (which modified Profiles array) to copy to 'SavedData'
	Fix FCollsiionProfileData typo
	#jira UE-42490

Change 3365500 on 2017/03/27 by Jurre.deBaare

	Turning on LOD Model Painting does not copy paint to other LODs on Skeletal Mesh
	#fix neede to pre edit / post edit the skeletal mesh to ensure the color buffers were re-initialised
	#jira UE-42637

Change 3365501 on 2017/03/27 by James.Golding

	Disable rather than hide anim picker when no mesh assigned
	#jira UE-35537

Change 3365505 on 2017/03/27 by James.Golding

	Fix USkinnedMeshComponent::FindClosestBone ignoring bRequirePhysicsAsset, because BodySetupIndexMap.FindRef would return 0 if bone not present
	https://udn.unrealengine.com/questions/353125/uskinnedmeshcomponentfindclosestbone-does-not-resp.html
	#jira UE-43061

Change 3365515 on 2017/03/27 by Jurre.deBaare

	Using Alt+Click to break Transition node connections cannot be undone using the Undo command
	#fix added transactions to breaking node links
	#jira UE-39068

Change 3365528 on 2017/03/27 by Jurre.deBaare

	Blendspaces don't update to reflect sync marker changes that have occurred on animations in the blend
	#fix added validation on blendspaces when removing or adding sync markers in animation editor
	#jira UE-39814

Change 3365535 on 2017/03/27 by Jurre.deBaare

	Camera moves at the same time as erasing paint when clicking Paint settings and back into Viewport
	#fix lock camera if erasing as well
	#jira UE-42474

Change 3365539 on 2017/03/27 by Jurre.deBaare

	Painting on animation sequence paints on invisible T-pose skeleton
	#fix during painting enforce bUseRefPoseOnInitAnim so you're always painting on a ref-pose skeletal mesh
	#jira UE-42484

Change 3365545 on 2017/03/27 by Jurre.deBaare

	Fill Tool does not fill the mesh with the selected Texture Weight Index when used in Weight Vertex Painting
	#fix added function to generate color according to texture weight settings and index, and fill using that color when the editor is in texture weight mode
	#jira UE-43091

Change 3365549 on 2017/03/27 by Jurre.deBaare

	CIS: include fix

Change 3365555 on 2017/03/27 by Jurre.deBaare

	Missing change from 3365545

Change 3365561 on 2017/03/27 by Jurre.deBaare

	Missing change from 3365545

Change 3365918 on 2017/03/27 by Ori.Cohen

	PR #3424: fix compile error when PHYSX_MEMORY_STATS=1 (Contributed by kayama-shift)

	#JIRA UE-43337

Change 3366234 on 2017/03/27 by Ori.Cohen

	Moved call to UpdateHasValidBodies into OnRegister. Original suggested fix came from github, but I think the bounds need to update even if OnCreatePhysics isn't called.

	#JIRA UE-43339

	#pr 3427

Change 3367252 on 2017/03/28 by Jurre.deBaare

	Vertex Weight Painting options are no longer present in MeshPaint mode
	#fix implemented singleton pattern for paint mode settings to ensure customization works correctly
	#jira UE-43357

Change 3367340 on 2017/03/28 by Jurre.deBaare

	GC fix for recent changes to painting / alembic settings

Change 3367445 on 2017/03/28 by Thomas.Sarkanen

	Fix fallout from Main merge

	OrionEditor needs to depend on the new AdvancedPreviewScene module.

Change 3367741 on 2017/03/28 by Ori.Cohen

	Remove unused physics warning when moving simulated object during physics

	#jira UE-41465

Change 3368072 on 2017/03/28 by Ori.Cohen

	Removed collision aggregates from ISMC collision. This is not a good candidate for aggregates as the bounding boxes generated could be huge (for example several trees that are very far away). This fixes perf regression from the PhysX 3.4 upgrade

	#JIRA UE-42956

Change 3368479 on 2017/03/28 by Ori.Cohen

	Fix GetClosestPoint incorrectly considering welded bodies.

	#JIRA UE-39329

Change 3368620 on 2017/03/28 by Lina.Halper

	Added code comment

	#rb:none
	#jira: UE-38836

Change 3368752 on 2017/03/28 by mason.seay

	Updated test map since UE-338836 came back as by design

Change 3369370 on 2017/03/29 by James.Golding

	Fix StaticMesh Editor drawing complex collision if 'use simple as complex' is enabled
	Add separate options for showing simple and complex collision in StaticMesh Editor
	#jira UE-42844

Change 3369438 on 2017/03/29 by Lina.Halper

	Fix issue where it updates more often when you give too high update rate - i.e. 60

	#jira: UE-38844
	#code review: Laurent.Delayen

Change 3369462 on 2017/03/29 by Thomas.Sarkanen

	Add preview mesh to animation blueprints

	Auto set preview mesh for animation assets and animation blueprints based off meshes.

	#jira UE-40032 - Creating animation assets from right-clicking skel mesh results in showing incorrect mesh in Persona

Change 3369463 on 2017/03/29 by Thomas.Sarkanen

	We now select current preview mesh in the preview mesh dropdown

Change 3369464 on 2017/03/29 by Thomas.Sarkanen

	Ticks now appear properly on anim sequence scrub bar

	#jira UE-41197 - No additional ticks appear on the timeline when you zoom in

Change 3369465 on 2017/03/29 by Thomas.Sarkanen

	Persona now depends publicly on SkeletonEditor

	GitHub PR #3431 from kayama-shift

	#jira UE-43344 - GitHub 3431 : Persona module must depend on SkeletonEditor publically

Change 3369466 on 2017/03/29 by Thomas.Sarkanen

	Blueprints are now only dirtied if edited properties are from objects in the Blueprint's package

	#jira UE-38956 - Changing Bone Transform between World and Local Location dirties Anim Blueprints

Change 3369467 on 2017/03/29 by Thomas.Sarkanen

	Tweaked combo box alignment for world/local transform

	Appearance is now closer to that of the level editor

Change 3369469 on 2017/03/29 by Thomas.Sarkanen

	Prevent switching to unsupported widget modes when editing control rigs

	#jira UE-42557 - When in Animation Mode, if you select a controller with the translation gizmo active, when you select a non animation controller the gizmo renders incorrectly

Change 3369588 on 2017/03/29 by Thomas.Sarkanen

	Make import data and thumbnail data transactional

	#jira UE-41579 - Undo not working for several Asset Details options in Skeletal Mesh editor (Persona)

Change 3369609 on 2017/03/29 by Thomas.Sarkanen

	Montages are now correctly initialized when created

	They can be used straight away without first opening them in the montage edtior.
	Moved initialization of composite sections from SMontageEditor to AnimMontageFactory.

	#jira UE-41219 - Animation montages created via Right click Create montage, that aren't opened in persona will not animate when used in an AnimBP

Change 3369610 on 2017/03/29 by Thomas.Sarkanen

	Fixed anim class being set by name, causing duplicate-named anim BPs to be incorrectly resolved

	#jira UE-39833 - SkelMesh Component > Anim Class does not handle identical AnimBP names

Change 3369647 on 2017/03/29 by Ori.Cohen

	Fix mass debug not working when moving components in the editor.

	#JIRA UE-43437

Change 3369875 on 2017/03/29 by Ori.Cohen

	Added the call into overlap instead of computePenetration when possible. There are edge cases that exist when computePenetration returns false but overlap returns true. Originally we were using computePenetration for all overlaps to make it consistent. However, computePenetration doesn't handle trimeshes correctly in certain cases. The reason for this is so that we can at least resolve a known issue with overlap events with complex collision. Nvidia may give us a flag for computePenetration to not do back-face culling which would give us a more consistent result.

	#JIRA UE-25923

Change 3370144 on 2017/03/29 by Lina.Halper

	Fix on the retargeting child anim BP

	#rb: Martin.Wilson
	#jira: UE-39928

Change 3371480 on 2017/03/30 by James.Golding

	Changes by BryanG at Nvidia required to get them up and running with plugins that override some skeletal mesh stuff.

	#jira UE-42132

Change 3371484 on 2017/03/30 by Thomas.Sarkanen

	We now propagate thread safety flags to child Animation Blueprints

Change 3371486 on 2017/03/30 by Thomas.Sarkanen

	Fixed crash and effector selection issues for two bone IK

	Crash occured when selecting the root bone as the end of the chain.
	Viewport selection was not working at all as we werent creating any selection proxy actors any more.

Change 3371497 on 2017/03/30 by Thomas.Sarkanen

	Added warning when Sequencer tries to write to properties that have changed type

	#jira UE-42098 - Sequencer writes rotation data to transform properties, causes assert

Change 3371614 on 2017/03/30 by Martin.Wilson

	Clean up deprecated property value after load so we dont get extra anim blueprint references

	#jira UE-42501

Change 3371619 on 2017/03/30 by James.Golding

	Fix CIS by removing unneeded UNREALED_API from FImportSkeletalMeshArgs

Change 3372452 on 2017/03/30 by Jon.Nabozny

	Add flag to CharacterMovementComponent to determine whether or not character should Sweep while using NavWalking, instead of relying on GenerateOverlaps flag.

	#jira UE-36546

Change 3373043 on 2017/03/30 by Lina.Halper

	- Consolidating to FastLerp to simply code
	- Added comment on FastLerp as the result is not normalized

	#rb: Michael.Noland, David.Hill

Change 3373292 on 2017/03/30 by Jeff.Farris

	Made Actor.DispatchPhysicsCollisionHit virtual.

	(Copied CL 3261103 from Robo Recall to Dev-AnimPhys)

Change 3373293 on 2017/03/30 by Jeff.Farris

	Added PhysicalAnimationComponent.GetBodyTargetTransform

	(Copied 3256175 from RoboRecall to Dev-AnimPhys)

Change 3373318 on 2017/03/30 by Jeff.Farris

	Added option for components to opt out of physics impulses on damage.

	(Copied CL 3282585 from RoboRecall to Dev-AnimPhys)

Change 3374064 on 2017/03/31 by Thomas.Sarkanen

	Renaming curves in animations is now saved properly

	Guids were not being set, so loading code obliterated the rename after an editor restart

	#jira UE-40582 - Curve name is not updated when user changes it in persona editor.

Change 3374175 on 2017/03/31 by Thomas.Sarkanen

	Two bone IK UI consistency fixes

	Completely removed all bone select actors. They have a terrible UX anyway.
	We now rely only on our custom hit proxy and use a unified path to generate effector locations to draw and manipulate.

	#jira UE-42359 - Two Bone IK modifying effector location from viewport when bone is not set

Change 3374216 on 2017/03/31 by Martin.Wilson

	Clear raw curve data during cooking + change Paragon game code so that it reads from the compressed curve data on Anim Sequences, not the raw data

	#jira UE-37897

Change 3374253 on 2017/03/31 by Thomas.Sarkanen

	Supplementary fix to CL 3371497

	Adding name exposure for property types that we support

Change 3374298 on 2017/03/31 by Jeff.Farris

	Code change from nVidia that improves physX perf (afterIntegration time).

	(Copied CL 3302239 from Robo Recall to Dev-AnimPhys)

Change 3374432 on 2017/03/31 by Lina.Halper

	Make sure AcitveBoneIndices contains parent

	#jira: UE-14597
	#rb: Martin.Wilson
	#code review: Benn.Gallagher, Alexis.Matte, James.Golding

Change 3374836 on 2017/03/31 by Jon.Nabozny

	Fixup hits returned before start of trace in raycast_capsule.

	This change is copied from CL-3297212

	#jira UE-42532

Change 3375195 on 2017/03/31 by Lina.Halper

	resave animation sequence for increasing info to warning

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

Change 3375282 on 2017/03/31 by Lina.Halper

	Fix odin content for animation : resave animation sequence for increasing info to warning

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

Change 3375288 on 2017/03/31 by Lina.Halper

	reverting code of degrading warning to info to avoid warning

	#jira: UE-40643

Change 3375865 on 2017/04/01 by Lina.Halper

	fix build error

Change 3375868 on 2017/04/01 by Lina.Halper

	fix build warning on shadow var

	#code review: Thomas.Sarkanen

Change 3376283 on 2017/04/03 by Thomas.Sarkanen

	Reworked, more generic property path handling in object change listener

	This allows all paths (auto vs manual key) to use the same code path, as well as regularizing the special-case handling of structs and arrays (and combinations thereof).
	The gist of the new implementation is to traverse the property path until we come across any property that satisfies our crirtera (exposed function, Interp flag etc.)
	Tweaked PropertyHandleToPropertyPath to correctly handle the slightly different way FPropertyNodes are arranged inside IPropertyHandle chains.
	IPropertyHandle chains contain arrays in a manner designed for display in the property editor, e.g. Container.Array.Array[ArrayIndex].StructInner. We need to collapse adjacent array properties as we are looking for Container.Array[ArrayIndex].StructInner to form a well-formed 'property path'.
	Small tweak to FPropertyChangedParams::GetPropertyValue. This is to handle property paths that end in an array (e.g. Struct.Array[0]).

	#jira UE-42271 - Pressing enter while the spine is in IK doesn't set any keys

Change 3376320 on 2017/04/03 by Benn.Gallagher

	Merging from OR39 - Fix for clothing perf regressions due to LOD switching leaving simulation enties in the clothing solver
	#jira OR-36926

Change 3376413 on 2017/04/03 by Benn.Gallagher

	Merge from OR - Fixes to stability due to component space being the simulation space, games like Paragon treat the mesh and component transforms differently and cause issues with added energy in the system.
	#jira OR-36927

Change 3376421 on 2017/04/03 by Benn.Gallagher

	Missed file from OR cloth fixes merge

Change 3376456 on 2017/04/03 by Lina.Halper

	Resave fortnite animation to remove warning

	#rb: none

Change 3376479 on 2017/04/03 by Jon.Nabozny

	Touch PhysXLibs to ensure physx links properly.
	(Needed for CL-3374836)

Change 3376610 on 2017/04/03 by Martin.Wilson

	Fix for crash when reimporting lodded mesh with virtual bones

	#jira UE-43557

Change 3376618 on 2017/04/03 by Jurre.deBaare

	Mesh Paint decrement rate is too slow when used with hotkeys
	#fix change way we increase/decrease brush value
	#jira UE-43402

Change 3376650 on 2017/04/03 by Benn.Gallagher

	Converted clothing asset editor warnings into toasts + logs so they are more discoverable by the user.
	#jira UE-41739

Change 3376771 on 2017/04/03 by Benn.Gallagher

	Fixed clothing selection dropdowns to no longer get out of sync with actual state (if the binding fails it falls back to the "None" selection correctly internally)
	#jira UE-41737

Change 3378117 on 2017/04/04 by Thomas.Sarkanen

	Prevented ensure by reverting to default unit vectors if zero-sized lookat/lookup vectors are specified

	Also added a warning to inform users of the issue.

	#jira UE-43360 - Enabling Use LookUp Axis causes handled ensure to occur

Change 3378118 on 2017/04/04 by Thomas.Sarkanen

	Fix 2-bone IK flickering

	First changed non-triangular range check to be >= instead  of >. Also removed fallback to doubled-back as this singularity also occurs at min stretch + float epsilon (which caused the flicker). We are OK to call ACos with out-of-range values as it clamps internally and the subsequent calculations work in these degenerate cases.

	#jira UE-43525 - Mesh Flicker when Two Bone IK is stretched

Change 3378192 on 2017/04/04 by Benn.Gallagher

	Trivial fix to clothing dropdowns to unbind clothing assets when switching

Change 3378206 on 2017/04/04 by Thomas.Sarkanen

	Fix IncludeTool static analysis errors

	Traced this back to the checkin that moved advanced preview scene into its own module. Further refined this to be the dependency on SharedSettingsWidgets. Simplest solution was to move the details customization back into the DetailsCustomizations module.

	#jira UE-43563 - //UE4/Dev-AnimPhys: Compile IncludeTool Static analysis Win64 completed with 1 error

Change 3378207 on 2017/04/04 by Thomas.Sarkanen

	Fix static analysis warning

Change 3378267 on 2017/04/04 by Benn.Gallagher

	Disabled "Accurate" wind mode selection for 4.16 by hiding enum option for windmode. Looks like there are some simulation issues that need resolved. Wind will act as it always has for 4.16.

Change 3378268 on 2017/04/04 by Benn.Gallagher

	Fixed bounds calculation on clothing to stop dissapearances or flickering at the edge of the screen.
	#jira UE-40407

Change 3378342 on 2017/04/04 by Jurre.deBaare

	Bone LOD preview doesn't get update if change removed bones array directly in Skeletalmesh editor
	#fix ensure that we update the skeleton tree when changes to the bones are made
	#misc made sure the reapply button its visibility is dynamic
	#misc made sure we always re-add previously removed bones when necessary
	#jira UE-40500

Change 3378374 on 2017/04/04 by Thomas.Sarkanen

	Fixed animation not working for dynamically-bound wheeled-vehicle anim instances

	Vehicle anim instance now looks for a wheeled vehicle component when it initializes.

	#jira UE-41048 - Set Anim Instance Class no longer works with Wheeled Vehicle Pawns

Change 3378518 on 2017/04/04 by Jon.Nabozny

	Fix jump height becoming frame dependent when JumpMaxHoldTime > 0.

	#jira UE-23695

Change 3378538 on 2017/04/04 by Martin.Wilson

	Speculative fix for unreproducable crash on loading animations

	#jira OR-37157

Change 3378592 on 2017/04/04 by Jurre.deBaare

	Mesh painting tools not working outside of QAGame
	#fix required a direct loadmodule call

Change 3378622 on 2017/04/04 by Jurre.deBaare

	CIS shadow variable fix

Change 3378742 on 2017/04/04 by Thomas.Sarkanen

	Fixed crash entering PIE in Orion

Change 3378907 on 2017/04/04 by Benn.Gallagher

	Re-added wind adaptiive effects to legacy wind path.
	Fixed math error in damping calculations (log2/loge).
	#jira UE-42044

Change 3379240 on 2017/04/04 by Jon.Nabozny

	Fix SkeletalMeshComponent GetWeldedBodies not returning actual Skeletal Bodies

Change 3379415 on 2017/04/04 by Jon.Nabozny

	Fix Skeletal Meshes imported with non-identity transform from reapplying transform when simulation is enabled / disabled.

	#JIRA UE-32598

Change 3379502 on 2017/04/04 by Lina.Halper

	Mirroring issue with flipping rotation due to not counting scale

	#jira: UE-33646, UE-34489
	#rb: Ori.Cohen
	#code review: Zak.Middleton

Change 3380544 on 2017/04/05 by Thomas.Sarkanen

	Fix warning spam when playing back UMG sequences animating visibility

	Reduced runtime overhead to a simple size check. This catches 90% of problem issues with much less runtime overhead. It would be well worth getting an FName-based type check working at some point, although we would need speciall case enum handling.
	Also removed message log usage in shipping/test builds.

	#jira UE-43621 - Large number of Sequencer warnings occur after opening Paragon in Pie - Property type mismatch for property 'Visibility'. Expected 'uint8', found 'ESlateVisibility'.

Change 3380605 on 2017/04/05 by Benn.Gallagher

	Fix clothing simulation to correctly index a master pose component for clothing pose data. Fixes integration blocking crash in UT when picking up the flag which sets a master pose mid-game.
	#jira UE-43624

Change 3381025 on 2017/04/05 by Jon.Nabozny

	Change ensure in UpdateKinematicBonesToAnim to ensureMsgf so we can track down potential content issues.

Change 3381475 on 2017/04/05 by Lina.Halper

	Fix crash on creating montage and setting slot node

	#jira: UE-43698
	#rb: Ori.Cohen

Change 3381558 on 2017/04/05 by Lina.Halper

	Better clean up of flipping issue of quaternion issue

	#jira: UE-33646, UE-34489
	#rb: Zak.Middleton

Change 3381789 on 2017/04/05 by Jon.Nabozny

	Revert InitAnim changes from CL-3379415 to fix cook warnings.
	(Will have proper fix for 4.17 instead).

Change 3381978 on 2017/04/05 by Aaron.McLeran

	#jira UE-43654 Fixing oculus audio SDK sample rate issue

Change 3383181 on 2017/04/06 by Lina.Halper

	Remove copy right of Dual quaternion since we no longer uses

	#code review:Leslie.Nivison

Change 3383283 on 2017/04/06 by Ori.Cohen

	Fixed missing invalidation for body setup when modifying materials

	#JIRA UE-43680

Change 3383602 on 2017/04/06 by Lina.Halper

	Fixed scroller in retargeting window

	#jira: UE-43736

Change 3384369 on 2017/04/07 by Jurre.deBaare

	Wrong bone is sometimes highlighted in skeleton editor
	#fix new behaviour caused the user to try and select a bone if we didn't find on through hit proxies
	#jira UE-43735

Change 3384744 on 2017/04/07 by Jon.Nabozny

	Fix body rotation being killed on load.

	#JIRA UE-43771

[CL 3385232 by Thomas Sarkanen in Main branch]
2017-04-07 16:51:51 -04:00

2024 lines
60 KiB
C++

// Copyright 1998-2017 Epic Games, Inc. All Rights Reserved.
#include "StaticMeshEditor.h"
#include "AssetData.h"
#include "Misc/MessageDialog.h"
#include "HAL/FileManager.h"
#include "Misc/ScopedSlowTask.h"
#include "Modules/ModuleManager.h"
#include "Framework/Application/SlateApplication.h"
#include "EditorStyleSet.h"
#include "EditorReimportHandler.h"
#include "Editor/UnrealEdEngine.h"
#include "EditorFramework/AssetImportData.h"
#include "Engine/StaticMesh.h"
#include "Editor.h"
#include "UnrealEdGlobals.h"
#include "StaticMeshEditorModule.h"
#include "SStaticMeshEditorViewport.h"
#include "PropertyEditorModule.h"
#include "IDetailsView.h"
#include "IDetailCustomization.h"
#include "StaticMeshEditorTools.h"
#include "StaticMeshEditorActions.h"
#include "StaticMeshResources.h"
#include "BusyCursor.h"
#include "Private/GeomFitUtils.h"
#include "EditorViewportCommands.h"
#include "Private/ConvexDecompTool.h"
#include "Runtime/Analytics/Analytics/Public/Interfaces/IAnalyticsProvider.h"
#include "EngineAnalytics.h"
#include "Widgets/Docking/SDockTab.h"
#include "Framework/Commands/GenericCommands.h"
#include "Widgets/Input/STextComboBox.h"
#include "PhysicsEngine/ConvexElem.h"
#include "PhysicsEngine/BoxElem.h"
#include "PhysicsEngine/SphereElem.h"
#include "PhysicsEngine/SphylElem.h"
#include "PhysicsEngine/BodySetup.h"
#include "AdvancedPreviewSceneModule.h"
#define LOCTEXT_NAMESPACE "StaticMeshEditor"
DEFINE_LOG_CATEGORY_STATIC(LogStaticMeshEditor, Log, All);
class FStaticMeshStatusMessageContext : public FScopedSlowTask
{
public:
explicit FStaticMeshStatusMessageContext(const FText& InMessage)
: FScopedSlowTask(0, InMessage)
{
UE_LOG(LogStaticMesh, Log, TEXT("%s"), *InMessage.ToString());
MakeDialog();
}
};
const FName FStaticMeshEditor::ViewportTabId( TEXT( "StaticMeshEditor_Viewport" ) );
const FName FStaticMeshEditor::PropertiesTabId( TEXT( "StaticMeshEditor_Properties" ) );
const FName FStaticMeshEditor::SocketManagerTabId( TEXT( "StaticMeshEditor_SocketManager" ) );
const FName FStaticMeshEditor::CollisionTabId( TEXT( "StaticMeshEditor_Collision" ) );
const FName FStaticMeshEditor::PreviewSceneSettingsTabId(TEXT("StaticMeshEditor_PreviewScene"));
void FStaticMeshEditor::RegisterTabSpawners(const TSharedRef<class FTabManager>& InTabManager)
{
WorkspaceMenuCategory = InTabManager->AddLocalWorkspaceMenuCategory(LOCTEXT("WorkspaceMenu_StaticMeshEditor", "Static Mesh Editor"));
auto WorkspaceMenuCategoryRef = WorkspaceMenuCategory.ToSharedRef();
FAssetEditorToolkit::RegisterTabSpawners(InTabManager);
InTabManager->RegisterTabSpawner( ViewportTabId, FOnSpawnTab::CreateSP(this, &FStaticMeshEditor::SpawnTab_Viewport) )
.SetDisplayName( LOCTEXT("ViewportTab", "Viewport") )
.SetGroup(WorkspaceMenuCategoryRef)
.SetIcon(FSlateIcon(FEditorStyle::GetStyleSetName(), "LevelEditor.Tabs.Viewports"));
InTabManager->RegisterTabSpawner( PropertiesTabId, FOnSpawnTab::CreateSP(this, &FStaticMeshEditor::SpawnTab_Properties) )
.SetDisplayName( LOCTEXT("PropertiesTab", "Details") )
.SetGroup(WorkspaceMenuCategoryRef)
.SetIcon(FSlateIcon(FEditorStyle::GetStyleSetName(), "LevelEditor.Tabs.Details"));
InTabManager->RegisterTabSpawner( SocketManagerTabId, FOnSpawnTab::CreateSP(this, &FStaticMeshEditor::SpawnTab_SocketManager) )
.SetDisplayName( LOCTEXT("SocketManagerTab", "Socket Manager") )
.SetGroup(WorkspaceMenuCategoryRef)
.SetIcon(FSlateIcon(FEditorStyle::GetStyleSetName(), "StaticMeshEditor.Tabs.SocketManager"));
InTabManager->RegisterTabSpawner( CollisionTabId, FOnSpawnTab::CreateSP(this, &FStaticMeshEditor::SpawnTab_Collision) )
.SetDisplayName( LOCTEXT("CollisionTab", "Convex Decomposition") )
.SetGroup(WorkspaceMenuCategoryRef)
.SetIcon(FSlateIcon(FEditorStyle::GetStyleSetName(), "StaticMeshEditor.Tabs.ConvexDecomposition"));
InTabManager->RegisterTabSpawner(PreviewSceneSettingsTabId, FOnSpawnTab::CreateSP(this, &FStaticMeshEditor::SpawnTab_PreviewSceneSettings))
.SetDisplayName(LOCTEXT("PreviewSceneTab", "Preview Scene Settings"))
.SetGroup(WorkspaceMenuCategoryRef)
.SetIcon(FSlateIcon(FEditorStyle::GetStyleSetName(), "LevelEditor.Tabs.Details"));
}
void FStaticMeshEditor::UnregisterTabSpawners(const TSharedRef<class FTabManager>& InTabManager)
{
FAssetEditorToolkit::UnregisterTabSpawners(InTabManager);
InTabManager->UnregisterTabSpawner( ViewportTabId );
InTabManager->UnregisterTabSpawner( PropertiesTabId );
InTabManager->UnregisterTabSpawner( SocketManagerTabId );
InTabManager->UnregisterTabSpawner( CollisionTabId );
InTabManager->UnregisterTabSpawner( PreviewSceneSettingsTabId );
}
FStaticMeshEditor::~FStaticMeshEditor()
{
FReimportManager::Instance()->OnPostReimport().RemoveAll(this);
GEditor->UnregisterForUndo( this );
GEditor->OnObjectReimported().RemoveAll(this);
}
void FStaticMeshEditor::InitStaticMeshEditor( const EToolkitMode::Type Mode, const TSharedPtr< class IToolkitHost >& InitToolkitHost, UStaticMesh* ObjectToEdit )
{
FReimportManager::Instance()->OnPostReimport().AddRaw(this, &FStaticMeshEditor::OnPostReimport);
// Support undo/redo
ObjectToEdit->SetFlags( RF_Transactional );
GEditor->RegisterForUndo( this );
// Register our commands. This will only register them if not previously registered
FStaticMeshEditorCommands::Register();
// Register to be notified when an object is reimported.
GEditor->OnObjectReimported().AddSP(this, &FStaticMeshEditor::OnObjectReimported);
BindCommands();
Viewport = SNew(SStaticMeshEditorViewport)
.StaticMeshEditor(SharedThis(this))
.ObjectToEdit(ObjectToEdit);
FPropertyEditorModule& PropertyEditorModule = FModuleManager::LoadModuleChecked<FPropertyEditorModule>(TEXT("PropertyEditor"));
FDetailsViewArgs DetailsViewArgs;
DetailsViewArgs.bAllowSearch = true;
DetailsViewArgs.bLockable = false;
DetailsViewArgs.bUpdatesFromSelection = false;
DetailsViewArgs.NameAreaSettings = FDetailsViewArgs::HideNameArea;
DetailsViewArgs.NotifyHook = this;
StaticMeshDetailsView = PropertyEditorModule.CreateDetailView( DetailsViewArgs );
FOnGetDetailCustomizationInstance LayoutCustomStaticMeshProperties = FOnGetDetailCustomizationInstance::CreateSP( this, &FStaticMeshEditor::MakeStaticMeshDetails );
StaticMeshDetailsView->RegisterInstancedCustomPropertyLayout( UStaticMesh::StaticClass(), LayoutCustomStaticMeshProperties );
SetEditorMesh(ObjectToEdit);
BuildSubTools();
const TSharedRef<FTabManager::FLayout> StandaloneDefaultLayout = FTabManager::NewLayout( "Standalone_StaticMeshEditor_Layout_v4" )
->AddArea
(
FTabManager::NewPrimaryArea() ->SetOrientation(Orient_Vertical)
->Split
(
FTabManager::NewStack()
->SetSizeCoefficient(0.1f)
->SetHideTabWell( true )
->AddTab(GetToolbarTabId(), ETabState::OpenedTab)
)
->Split
(
FTabManager::NewSplitter() ->SetOrientation(Orient_Horizontal)
->SetSizeCoefficient(0.9f)
->Split
(
FTabManager::NewStack()
->SetSizeCoefficient(0.6f)
->AddTab(ViewportTabId, ETabState::OpenedTab)
->SetHideTabWell( true )
)
->Split
(
FTabManager::NewSplitter() ->SetOrientation(Orient_Vertical)
->SetSizeCoefficient(0.2f)
->Split
(
FTabManager::NewStack()
->SetSizeCoefficient(0.7f)
->AddTab(PreviewSceneSettingsTabId, ETabState::OpenedTab)
->AddTab(PropertiesTabId, ETabState::OpenedTab)
)
->Split
(
FTabManager::NewStack()
->SetSizeCoefficient(0.3f)
->AddTab(SocketManagerTabId, ETabState::OpenedTab)
->AddTab(CollisionTabId, ETabState::ClosedTab)
)
)
)
);
const bool bCreateDefaultStandaloneMenu = true;
const bool bCreateDefaultToolbar = true;
FAssetEditorToolkit::InitAssetEditor( Mode, InitToolkitHost, StaticMeshEditorAppIdentifier, StandaloneDefaultLayout, bCreateDefaultToolbar, bCreateDefaultStandaloneMenu, ObjectToEdit );
ExtendMenu();
ExtendToolBar();
RegenerateMenusAndToolbars();
}
TSharedRef<IDetailCustomization> FStaticMeshEditor::MakeStaticMeshDetails()
{
TSharedRef<FStaticMeshDetails> NewDetails = MakeShareable( new FStaticMeshDetails( *this ) );
StaticMeshDetails = NewDetails;
return NewDetails;
}
void FStaticMeshEditor::ExtendMenu()
{
struct Local
{
static void FillEditMenu( FMenuBuilder& InMenuBuilder )
{
InMenuBuilder.BeginSection("Sockets", LOCTEXT("EditStaticMeshSockets", "Sockets"));
{
InMenuBuilder.AddMenuEntry( FGenericCommands::Get().Delete, "DeleteSocket", LOCTEXT("DeleteSocket", "Delete Socket"), LOCTEXT("DeleteSocketToolTip", "Deletes the selected socket from the mesh.") );
InMenuBuilder.AddMenuEntry( FGenericCommands::Get().Duplicate, "DuplicateSocket", LOCTEXT("DuplicateSocket", "Duplicate Socket"), LOCTEXT("DuplicateSocketToolTip", "Duplicates the selected socket.") );
}
InMenuBuilder.EndSection();
}
static void FillMeshMenu( FMenuBuilder& InMenuBuilder )
{
// @todo mainframe: These menus, and indeed all menus like them, should be updated with extension points, plus expose public module
// access to extending the menus. They may also need to extend the command list, or be able to PUSH a command list of their own.
// If we decide to only allow PUSHING, then nothing else should be needed (happens by extender automatically). But if we want to
// augment the asset editor's existing command list, then we need to think about how to expose support for that.
InMenuBuilder.BeginSection("MeshFindSource");
{
InMenuBuilder.AddMenuEntry(FStaticMeshEditorCommands::Get().FindSource);
}
InMenuBuilder.EndSection();
InMenuBuilder.BeginSection("MeshChange");
{
InMenuBuilder.AddMenuEntry(FStaticMeshEditorCommands::Get().ChangeMesh);
static auto* CVar = IConsoleManager::Get().FindTConsoleVariableDataInt(TEXT("r.StaticMesh.EnableSaveGeneratedLODsInPackage"));
if (CVar && CVar->GetValueOnGameThread() != 0)
{
InMenuBuilder.AddMenuEntry(FStaticMeshEditorCommands::Get().SaveGeneratedLODs);
}
}
InMenuBuilder.EndSection();
}
static void FillCollisionMenu( FMenuBuilder& InMenuBuilder )
{
InMenuBuilder.BeginSection("CollisionEditCollision");
{
InMenuBuilder.AddMenuEntry(FStaticMeshEditorCommands::Get().CreateSphereCollision);
InMenuBuilder.AddMenuEntry(FStaticMeshEditorCommands::Get().CreateSphylCollision);
InMenuBuilder.AddMenuEntry(FStaticMeshEditorCommands::Get().CreateBoxCollision);
InMenuBuilder.AddMenuEntry(FStaticMeshEditorCommands::Get().CreateDOP10X);
InMenuBuilder.AddMenuEntry(FStaticMeshEditorCommands::Get().CreateDOP10Y);
InMenuBuilder.AddMenuEntry(FStaticMeshEditorCommands::Get().CreateDOP10Z);
InMenuBuilder.AddMenuEntry(FStaticMeshEditorCommands::Get().CreateDOP18);
InMenuBuilder.AddMenuEntry(FStaticMeshEditorCommands::Get().CreateDOP26);
InMenuBuilder.AddMenuEntry(FStaticMeshEditorCommands::Get().ConvertBoxesToConvex);
InMenuBuilder.AddMenuEntry(FStaticMeshEditorCommands::Get().RemoveCollision);
InMenuBuilder.AddMenuEntry(FGenericCommands::Get().Delete, "DeleteCollision", LOCTEXT("DeleteCollision", "Delete Selected Collision"), LOCTEXT("DeleteCollisionToolTip", "Deletes the selected Collision from the mesh."));
InMenuBuilder.AddMenuEntry(FGenericCommands::Get().Duplicate, "DuplicateCollision", LOCTEXT("DuplicateCollision", "Duplicate Selected Collision"), LOCTEXT("DuplicateCollisionToolTip", "Duplicates the selected Collision."));
}
InMenuBuilder.EndSection();
InMenuBuilder.BeginSection("CollisionAutoConvexCollision");
{
InMenuBuilder.AddMenuEntry(FStaticMeshEditorCommands::Get().CreateAutoConvexCollision);
}
InMenuBuilder.EndSection();
InMenuBuilder.BeginSection("CollisionCopy");
{
InMenuBuilder.AddMenuEntry(FStaticMeshEditorCommands::Get().CopyCollisionFromSelectedMesh);
}
InMenuBuilder.EndSection();
}
static void GenerateMeshAndCollisionMenuBars( FMenuBarBuilder& InMenuBarBuilder)
{
InMenuBarBuilder.AddPullDownMenu(
LOCTEXT("StaticMeshEditorMeshMenu", "Mesh"),
LOCTEXT("StaticMeshEditorMeshMenu_ToolTip", "Opens a menu with commands for altering this mesh"),
FNewMenuDelegate::CreateStatic(&Local::FillMeshMenu),
"Mesh");
InMenuBarBuilder.AddPullDownMenu(
LOCTEXT("StaticMeshEditorCollisionMenu", "Collision"),
LOCTEXT("StaticMeshEditorCollisionMenu_ToolTip", "Opens a menu with commands for editing this mesh's collision"),
FNewMenuDelegate::CreateStatic(&Local::FillCollisionMenu),
"Collision");
}
};
TSharedPtr<FExtender> MenuExtender = MakeShareable(new FExtender);
MenuExtender->AddMenuExtension(
"EditHistory",
EExtensionHook::After,
GetToolkitCommands(),
FMenuExtensionDelegate::CreateStatic( &Local::FillEditMenu ) );
MenuExtender->AddMenuBarExtension(
"Asset",
EExtensionHook::After,
GetToolkitCommands(),
FMenuBarExtensionDelegate::CreateStatic( &Local::GenerateMeshAndCollisionMenuBars )
);
AddMenuExtender(MenuExtender);
IStaticMeshEditorModule* StaticMeshEditorModule = &FModuleManager::LoadModuleChecked<IStaticMeshEditorModule>( "StaticMeshEditor" );
AddMenuExtender(StaticMeshEditorModule->GetMenuExtensibilityManager()->GetAllExtenders(GetToolkitCommands(), GetEditingObjects()));
}
void FStaticMeshEditor::AddReferencedObjects( FReferenceCollector& Collector )
{
Collector.AddReferencedObject( StaticMesh );
}
TSharedRef<SDockTab> FStaticMeshEditor::SpawnTab_Viewport( const FSpawnTabArgs& Args )
{
check( Args.GetTabId() == ViewportTabId );
TSharedRef<SDockTab> SpawnedTab =
SNew(SDockTab)
.Label( LOCTEXT("StaticMeshViewport_TabTitle", "Viewport") )
[
Viewport.ToSharedRef()
];
Viewport->SetParentTab( SpawnedTab );
return SpawnedTab;
}
TSharedRef<SDockTab> FStaticMeshEditor::SpawnTab_Properties( const FSpawnTabArgs& Args )
{
check( Args.GetTabId() == PropertiesTabId );
return SNew(SDockTab)
.Icon( FEditorStyle::GetBrush("StaticMeshEditor.Tabs.Properties") )
.Label( LOCTEXT("StaticMeshProperties_TabTitle", "Details") )
[
StaticMeshDetailsView.ToSharedRef()
];
}
TSharedRef<SDockTab> FStaticMeshEditor::SpawnTab_SocketManager( const FSpawnTabArgs& Args )
{
check( Args.GetTabId() == SocketManagerTabId );
return SNew(SDockTab)
.Label( LOCTEXT("StaticMeshSocketManager_TabTitle", "Socket Manager") )
[
SocketManager.ToSharedRef()
];
}
TSharedRef<SDockTab> FStaticMeshEditor::SpawnTab_Collision( const FSpawnTabArgs& Args )
{
check( Args.GetTabId() == CollisionTabId );
return SNew(SDockTab)
.Label( LOCTEXT("StaticMeshConvexDecomp_TabTitle", "Convex Decomposition") )
[
ConvexDecomposition.ToSharedRef()
];
}
TSharedRef<SDockTab> FStaticMeshEditor::SpawnTab_PreviewSceneSettings(const FSpawnTabArgs& Args)
{
check(Args.GetTabId() == PreviewSceneSettingsTabId);
return SNew(SDockTab)
.Label(LOCTEXT("StaticMeshPreviewScene_TabTitle", "Preview Scene Settings"))
[
AdvancedPreviewSettingsWidget.ToSharedRef()
];
}
void FStaticMeshEditor::BindCommands()
{
const FStaticMeshEditorCommands& Commands = FStaticMeshEditorCommands::Get();
const TSharedRef<FUICommandList>& UICommandList = GetToolkitCommands();
UICommandList->MapAction( FGenericCommands::Get().Delete,
FExecuteAction::CreateSP( this, &FStaticMeshEditor::DeleteSelected ),
FCanExecuteAction::CreateSP(this, &FStaticMeshEditor::CanDeleteSelected));
UICommandList->MapAction( FGenericCommands::Get().Undo,
FExecuteAction::CreateSP( this, &FStaticMeshEditor::UndoAction ) );
UICommandList->MapAction( FGenericCommands::Get().Redo,
FExecuteAction::CreateSP( this, &FStaticMeshEditor::RedoAction ) );
UICommandList->MapAction(
FGenericCommands::Get().Duplicate,
FExecuteAction::CreateSP(this, &FStaticMeshEditor::DuplicateSelected),
FCanExecuteAction::CreateSP(this, &FStaticMeshEditor::CanDuplicateSelected));
UICommandList->MapAction(
FGenericCommands::Get().Rename,
FExecuteAction::CreateSP(this, &FStaticMeshEditor::RequestRenameSelectedSocket),
FCanExecuteAction::CreateSP(this, &FStaticMeshEditor::CanRenameSelected));
UICommandList->MapAction(
Commands.CreateDOP10X,
FExecuteAction::CreateSP(this, &FStaticMeshEditor::GenerateKDop, KDopDir10X, (uint32)10));
UICommandList->MapAction(
Commands.CreateDOP10Y,
FExecuteAction::CreateSP(this, &FStaticMeshEditor::GenerateKDop, KDopDir10Y, (uint32)10));
UICommandList->MapAction(
Commands.CreateDOP10Z,
FExecuteAction::CreateSP(this, &FStaticMeshEditor::GenerateKDop, KDopDir10Z, (uint32)10));
UICommandList->MapAction(
Commands.CreateDOP18,
FExecuteAction::CreateSP(this, &FStaticMeshEditor::GenerateKDop, KDopDir18, (uint32)18));
UICommandList->MapAction(
Commands.CreateDOP26,
FExecuteAction::CreateSP(this, &FStaticMeshEditor::GenerateKDop, KDopDir26, (uint32)26));
UICommandList->MapAction(
Commands.CreateBoxCollision,
FExecuteAction::CreateSP(this, &FStaticMeshEditor::OnCollisionBox));
UICommandList->MapAction(
Commands.CreateSphereCollision,
FExecuteAction::CreateSP(this, &FStaticMeshEditor::OnCollisionSphere));
UICommandList->MapAction(
Commands.CreateSphylCollision,
FExecuteAction::CreateSP(this, &FStaticMeshEditor::OnCollisionSphyl));
UICommandList->MapAction(
Commands.RemoveCollision,
FExecuteAction::CreateSP(this, &FStaticMeshEditor::OnRemoveCollision),
FCanExecuteAction::CreateSP(this, &FStaticMeshEditor::CanRemoveCollision));
UICommandList->MapAction(
Commands.ConvertBoxesToConvex,
FExecuteAction::CreateSP(this, &FStaticMeshEditor::OnConvertBoxToConvexCollision));
UICommandList->MapAction(
Commands.CopyCollisionFromSelectedMesh,
FExecuteAction::CreateSP(this, &FStaticMeshEditor::OnCopyCollisionFromSelectedStaticMesh),
FCanExecuteAction::CreateSP(this, &FStaticMeshEditor::CanCopyCollisionFromSelectedStaticMesh));
// Mesh menu
UICommandList->MapAction(
Commands.FindSource,
FExecuteAction::CreateSP(this, &FStaticMeshEditor::ExecuteFindInExplorer),
FCanExecuteAction::CreateSP(this, &FStaticMeshEditor::CanExecuteSourceCommands));
UICommandList->MapAction(
Commands.ChangeMesh,
FExecuteAction::CreateSP(this, &FStaticMeshEditor::OnChangeMesh),
FCanExecuteAction::CreateSP(this, &FStaticMeshEditor::CanChangeMesh));
UICommandList->MapAction(
Commands.SaveGeneratedLODs,
FExecuteAction::CreateSP(this, &FStaticMeshEditor::OnSaveGeneratedLODs));
// Collision Menu
UICommandList->MapAction(
Commands.CreateAutoConvexCollision,
FExecuteAction::CreateSP(this, &FStaticMeshEditor::OnConvexDecomposition));
}
static TSharedRef< SWidget > GenerateCollisionMenuContent(TSharedPtr<const FUICommandList> InCommandList)
{
FMenuBuilder MenuBuilder(true, InCommandList);
MenuBuilder.BeginSection("ShowCollision", LOCTEXT("ShowCollision", "Show Collision"));
{
MenuBuilder.AddMenuEntry(FStaticMeshEditorCommands::Get().SetShowSimpleCollision);
MenuBuilder.AddMenuEntry(FStaticMeshEditorCommands::Get().SetShowComplexCollision);
}
MenuBuilder.EndSection();
return MenuBuilder.MakeWidget();
}
void FStaticMeshEditor::ExtendToolBar()
{
struct Local
{
static void FillToolbar(FToolBarBuilder& ToolbarBuilder, TSharedPtr< class STextComboBox > UVChannelCombo, TSharedPtr< class STextComboBox > LODLevelCombo)
{
ToolbarBuilder.BeginSection("Realtime");
{
ToolbarBuilder.AddToolBarButton(FEditorViewportCommands::Get().ToggleRealTime);
}
ToolbarBuilder.EndSection();
ToolbarBuilder.BeginSection("Command");
{
ToolbarBuilder.AddToolBarButton(FStaticMeshEditorCommands::Get().SetShowSockets);
ToolbarBuilder.AddToolBarButton(FStaticMeshEditorCommands::Get().SetShowWireframe);
ToolbarBuilder.AddToolBarButton(FStaticMeshEditorCommands::Get().SetShowVertexColor);
ToolbarBuilder.AddToolBarButton(FStaticMeshEditorCommands::Get().SetShowGrid);
ToolbarBuilder.AddToolBarButton(FStaticMeshEditorCommands::Get().SetShowBounds);
TSharedPtr<const FUICommandList> CommandList = ToolbarBuilder.GetTopCommandList();
ToolbarBuilder.AddComboButton(
FUIAction(),
FOnGetContent::CreateStatic(&GenerateCollisionMenuContent, CommandList),
LOCTEXT("Collision_Label", "Collision"),
LOCTEXT("Collision_Tooltip", "Collision drawing options"),
FSlateIcon(FEditorStyle::GetStyleSetName(), "StaticMeshEditor.SetShowCollision")
);
ToolbarBuilder.AddToolBarButton(FStaticMeshEditorCommands::Get().SetShowPivot);
ToolbarBuilder.AddToolBarButton(FStaticMeshEditorCommands::Get().SetShowNormals);
ToolbarBuilder.AddToolBarButton(FStaticMeshEditorCommands::Get().SetShowTangents);
ToolbarBuilder.AddToolBarButton(FStaticMeshEditorCommands::Get().SetShowBinormals);
ToolbarBuilder.AddToolBarButton(FStaticMeshEditorCommands::Get().SetShowVertices);
ToolbarBuilder.AddToolBarButton(FStaticMeshEditorCommands::Get().SetDrawUVs);
ToolbarBuilder.AddToolBarButton(FStaticMeshEditorCommands::Get().SetDrawAdditionalData);
}
ToolbarBuilder.EndSection();
ToolbarBuilder.BeginSection("UV");
{
ToolbarBuilder.AddWidget(UVChannelCombo.ToSharedRef());
}
ToolbarBuilder.EndSection();
ToolbarBuilder.BeginSection("Camera");
{
ToolbarBuilder.AddToolBarButton(FStaticMeshEditorCommands::Get().ResetCamera);
}
ToolbarBuilder.EndSection();
ToolbarBuilder.BeginSection("LOD");
{
ToolbarBuilder.AddWidget(LODLevelCombo.ToSharedRef());
}
ToolbarBuilder.EndSection();
}
};
TSharedPtr<FExtender> ToolbarExtender = MakeShareable(new FExtender);
ToolbarExtender->AddToolBarExtension(
"Asset",
EExtensionHook::After,
Viewport->GetCommandList(),
FToolBarExtensionDelegate::CreateStatic( &Local::FillToolbar, UVChannelCombo, LODLevelCombo )
);
AddToolbarExtender(ToolbarExtender);
IStaticMeshEditorModule* StaticMeshEditorModule = &FModuleManager::LoadModuleChecked<IStaticMeshEditorModule>( "StaticMeshEditor" );
AddToolbarExtender(StaticMeshEditorModule->GetToolBarExtensibilityManager()->GetAllExtenders(GetToolkitCommands(), GetEditingObjects()));
}
void FStaticMeshEditor::BuildSubTools()
{
FSimpleDelegate OnSocketSelectionChanged = FSimpleDelegate::CreateSP( SharedThis(this), &FStaticMeshEditor::OnSocketSelectionChanged );
SocketManager = ISocketManager::CreateSocketManager( SharedThis(this) , OnSocketSelectionChanged );
SAssignNew( ConvexDecomposition, SConvexDecomposition )
.StaticMeshEditorPtr(SharedThis(this));
// Build toolbar widgets
UVChannelCombo = SNew(STextComboBox)
.OptionsSource(&UVChannels)
.OnSelectionChanged(this, &FStaticMeshEditor::ComboBoxSelectionChanged)
.IsEnabled( FSlateApplication::Get().GetNormalExecutionAttribute() );
if(UVChannels.IsValidIndex(0))
{
UVChannelCombo->SetSelectedItem(UVChannels[0]);
}
LODLevelCombo = SNew(STextComboBox)
.OptionsSource(&LODLevels)
.OnSelectionChanged(this, &FStaticMeshEditor::LODLevelsSelectionChanged)
.IsEnabled( FSlateApplication::Get().GetNormalExecutionAttribute() );
if(LODLevels.IsValidIndex(0))
{
LODLevelCombo->SetSelectedItem(LODLevels[0]);
}
FAdvancedPreviewSceneModule& AdvancedPreviewSceneModule = FModuleManager::LoadModuleChecked<FAdvancedPreviewSceneModule>("AdvancedPreviewScene");
AdvancedPreviewSettingsWidget = AdvancedPreviewSceneModule.CreateAdvancedPreviewSceneSettingsWidget(Viewport->GetPreviewScene());
}
FName FStaticMeshEditor::GetToolkitFName() const
{
return FName("StaticMeshEditor");
}
FText FStaticMeshEditor::GetBaseToolkitName() const
{
return LOCTEXT("AppLabel", "StaticMesh Editor");
}
FString FStaticMeshEditor::GetWorldCentricTabPrefix() const
{
return LOCTEXT("WorldCentricTabPrefix", "StaticMesh ").ToString();
}
FLinearColor FStaticMeshEditor::GetWorldCentricTabColorScale() const
{
return FLinearColor( 0.3f, 0.2f, 0.5f, 0.5f );
}
UStaticMeshComponent* FStaticMeshEditor::GetStaticMeshComponent() const
{
return Viewport->GetStaticMeshComponent();
}
void FStaticMeshEditor::SetSelectedSocket(UStaticMeshSocket* InSelectedSocket)
{
SocketManager->SetSelectedSocket(InSelectedSocket);
}
UStaticMeshSocket* FStaticMeshEditor::GetSelectedSocket() const
{
check(SocketManager.IsValid());
return SocketManager->GetSelectedSocket();
}
void FStaticMeshEditor::DuplicateSelectedSocket()
{
SocketManager->DuplicateSelectedSocket();
}
void FStaticMeshEditor::RequestRenameSelectedSocket()
{
SocketManager->RequestRenameSelectedSocket();
}
bool FStaticMeshEditor::IsPrimValid(const FPrimData& InPrimData) const
{
if (StaticMesh->BodySetup)
{
const FKAggregateGeom* AggGeom = &StaticMesh->BodySetup->AggGeom;
switch (InPrimData.PrimType)
{
case KPT_Sphere:
return AggGeom->SphereElems.IsValidIndex(InPrimData.PrimIndex);
case KPT_Box:
return AggGeom->BoxElems.IsValidIndex(InPrimData.PrimIndex);
case KPT_Sphyl:
return AggGeom->SphylElems.IsValidIndex(InPrimData.PrimIndex);
case KPT_Convex:
return AggGeom->ConvexElems.IsValidIndex(InPrimData.PrimIndex);
}
}
return false;
}
bool FStaticMeshEditor::HasSelectedPrims() const
{
return (SelectedPrims.Num() > 0 ? true : false);
}
void FStaticMeshEditor::AddSelectedPrim(const FPrimData& InPrimData, bool bClearSelection)
{
check(IsPrimValid(InPrimData));
// Enable collision, if not already
if( !Viewport->GetViewportClient().IsSetShowSimpleCollisionChecked() )
{
Viewport->GetViewportClient().SetShowSimpleCollision();
}
if( bClearSelection )
{
ClearSelectedPrims();
}
SelectedPrims.Add(InPrimData);
}
void FStaticMeshEditor::RemoveSelectedPrim(const FPrimData& InPrimData)
{
SelectedPrims.Remove(InPrimData);
}
void FStaticMeshEditor::RemoveInvalidPrims()
{
for (int32 PrimIdx = SelectedPrims.Num() - 1; PrimIdx >= 0; PrimIdx--)
{
FPrimData& PrimData = SelectedPrims[PrimIdx];
if (!IsPrimValid(PrimData))
{
SelectedPrims.RemoveAt(PrimIdx);
}
}
}
bool FStaticMeshEditor::IsSelectedPrim(const FPrimData& InPrimData) const
{
return SelectedPrims.Contains(InPrimData);
}
void FStaticMeshEditor::ClearSelectedPrims()
{
SelectedPrims.Empty();
}
void FStaticMeshEditor::DuplicateSelectedPrims(const FVector* InOffset)
{
if (SelectedPrims.Num() > 0)
{
check(StaticMesh->BodySetup);
FKAggregateGeom* AggGeom = &StaticMesh->BodySetup->AggGeom;
GEditor->BeginTransaction(LOCTEXT("FStaticMeshEditor_DuplicateSelectedPrims", "Duplicate Collision"));
StaticMesh->BodySetup->Modify();
//Clear the cache (PIE may have created some data), create new GUID
StaticMesh->BodySetup->InvalidatePhysicsData();
for (int32 PrimIdx = 0; PrimIdx < SelectedPrims.Num(); PrimIdx++)
{
FPrimData& PrimData = SelectedPrims[PrimIdx];
check(IsPrimValid(PrimData));
switch (PrimData.PrimType)
{
case KPT_Sphere:
{
const FKSphereElem SphereElem = AggGeom->SphereElems[PrimData.PrimIndex];
PrimData.PrimIndex = AggGeom->SphereElems.Add(SphereElem);
}
break;
case KPT_Box:
{
const FKBoxElem BoxElem = AggGeom->BoxElems[PrimData.PrimIndex];
PrimData.PrimIndex = AggGeom->BoxElems.Add(BoxElem);
}
break;
case KPT_Sphyl:
{
const FKSphylElem SphylElem = AggGeom->SphylElems[PrimData.PrimIndex];
PrimData.PrimIndex = AggGeom->SphylElems.Add(SphylElem);
}
break;
case KPT_Convex:
{
const FKConvexElem ConvexElem = AggGeom->ConvexElems[PrimData.PrimIndex];
PrimData.PrimIndex = AggGeom->ConvexElems.Add(ConvexElem);
}
break;
}
// If specified, offset the duplicate by a specific amount
if (InOffset)
{
FTransform PrimTransform = GetPrimTransform(PrimData);
FVector PrimLocation = PrimTransform.GetLocation();
PrimLocation += *InOffset;
PrimTransform.SetLocation(PrimLocation);
SetPrimTransform(PrimData, PrimTransform);
}
}
// refresh collision change back to staticmesh components
RefreshCollisionChange(*StaticMesh);
GEditor->EndTransaction();
// Mark staticmesh as dirty, to help make sure it gets saved.
StaticMesh->MarkPackageDirty();
// Update views/property windows
Viewport->RefreshViewport();
StaticMesh->bCustomizedCollision = true; //mark the static mesh for collision customization
}
}
void FStaticMeshEditor::TranslateSelectedPrims(const FVector& InDrag)
{
check(StaticMesh->BodySetup);
StaticMesh->BodySetup->InvalidatePhysicsData();
for (int32 PrimIdx = 0; PrimIdx < SelectedPrims.Num(); PrimIdx++)
{
const FPrimData& PrimData = SelectedPrims[PrimIdx];
FTransform PrimTransform = GetPrimTransform(PrimData);
FVector PrimLocation = PrimTransform.GetLocation();
PrimLocation += InDrag;
PrimTransform.SetLocation(PrimLocation);
SetPrimTransform(PrimData, PrimTransform);
}
// refresh collision change back to staticmesh components
RefreshCollisionChange(*StaticMesh);
}
void FStaticMeshEditor::RotateSelectedPrims(const FRotator& InRot)
{
check(StaticMesh->BodySetup);
StaticMesh->BodySetup->InvalidatePhysicsData();
const FQuat DeltaQ = InRot.Quaternion();
for (int32 PrimIdx = 0; PrimIdx < SelectedPrims.Num(); PrimIdx++)
{
const FPrimData& PrimData = SelectedPrims[PrimIdx];
FTransform PrimTransform = GetPrimTransform(PrimData);
FRotator ActorRotWind, ActorRotRem;
PrimTransform.Rotator().GetWindingAndRemainder(ActorRotWind, ActorRotRem);
const FQuat ActorQ = ActorRotRem.Quaternion();
FRotator NewActorRotRem = FRotator(DeltaQ * ActorQ);
NewActorRotRem.Normalize();
PrimTransform.SetRotation(NewActorRotRem.Quaternion());
SetPrimTransform(PrimData, PrimTransform);
}
// refresh collision change back to staticmesh components
RefreshCollisionChange(*StaticMesh);
}
void FStaticMeshEditor::ScaleSelectedPrims(const FVector& InScale)
{
check(StaticMesh->BodySetup);
StaticMesh->BodySetup->InvalidatePhysicsData();
FKAggregateGeom* AggGeom = &StaticMesh->BodySetup->AggGeom;
FVector ModifiedScale = InScale;
if (GEditor->UsePercentageBasedScaling())
{
ModifiedScale = InScale * ((GEditor->GetScaleGridSize() / 100.0f) / GEditor->GetGridSize());
}
//Multiply in estimated size of the mesh so scaling of sphere, box and sphyl is similar speed to other scaling
float SimplePrimitiveScaleSpeedFactor = StaticMesh->GetBounds().SphereRadius;
for (int32 PrimIdx = 0; PrimIdx < SelectedPrims.Num(); PrimIdx++)
{
const FPrimData& PrimData = SelectedPrims[PrimIdx];
check(IsPrimValid(PrimData));
switch (PrimData.PrimType)
{
case KPT_Sphere:
AggGeom->SphereElems[PrimData.PrimIndex].ScaleElem(SimplePrimitiveScaleSpeedFactor * ModifiedScale, MinPrimSize);
break;
case KPT_Box:
AggGeom->BoxElems[PrimData.PrimIndex].ScaleElem(SimplePrimitiveScaleSpeedFactor * ModifiedScale, MinPrimSize);
break;
case KPT_Sphyl:
AggGeom->SphylElems[PrimData.PrimIndex].ScaleElem(SimplePrimitiveScaleSpeedFactor * ModifiedScale, MinPrimSize);
break;
case KPT_Convex:
AggGeom->ConvexElems[PrimData.PrimIndex].ScaleElem(ModifiedScale, MinPrimSize);
break;
}
StaticMesh->bCustomizedCollision = true; //mark the static mesh for collision customization
}
// refresh collision change back to staticmesh components
RefreshCollisionChange(*StaticMesh);
}
bool FStaticMeshEditor::CalcSelectedPrimsAABB(FBox &OutBox) const
{
check(StaticMesh->BodySetup);
FKAggregateGeom* AggGeom = &StaticMesh->BodySetup->AggGeom;
for (int32 PrimIdx = 0; PrimIdx < SelectedPrims.Num(); PrimIdx++)
{
const FPrimData& PrimData = SelectedPrims[PrimIdx];
check(IsPrimValid(PrimData));
switch (PrimData.PrimType)
{
case KPT_Sphere:
OutBox += AggGeom->SphereElems[PrimData.PrimIndex].CalcAABB(FTransform::Identity, 1.f);
break;
case KPT_Box:
OutBox += AggGeom->BoxElems[PrimData.PrimIndex].CalcAABB(FTransform::Identity, 1.f);
break;
case KPT_Sphyl:
OutBox += AggGeom->SphylElems[PrimData.PrimIndex].CalcAABB(FTransform::Identity, 1.f);
break;
case KPT_Convex:
OutBox += AggGeom->ConvexElems[PrimData.PrimIndex].CalcAABB(FTransform::Identity, FVector(1.f));
break;
}
}
return HasSelectedPrims();
}
bool FStaticMeshEditor::GetLastSelectedPrimTransform(FTransform& OutTransform) const
{
if (SelectedPrims.Num() > 0)
{
check(StaticMesh->BodySetup);
const FKAggregateGeom* AggGeom = &StaticMesh->BodySetup->AggGeom;
const FPrimData& PrimData = SelectedPrims.Last();
check(IsPrimValid(PrimData));
switch (PrimData.PrimType)
{
case KPT_Sphere:
OutTransform = AggGeom->SphereElems[PrimData.PrimIndex].GetTransform();
break;
case KPT_Box:
OutTransform = AggGeom->BoxElems[PrimData.PrimIndex].GetTransform();
break;
case KPT_Sphyl:
OutTransform = AggGeom->SphylElems[PrimData.PrimIndex].GetTransform();
break;
case KPT_Convex:
OutTransform = AggGeom->ConvexElems[PrimData.PrimIndex].GetTransform();
break;
}
}
return HasSelectedPrims();
}
FTransform FStaticMeshEditor::GetPrimTransform(const FPrimData& InPrimData) const
{
check(StaticMesh->BodySetup);
const FKAggregateGeom* AggGeom = &StaticMesh->BodySetup->AggGeom;
check(IsPrimValid(InPrimData));
switch (InPrimData.PrimType)
{
case KPT_Sphere:
return AggGeom->SphereElems[InPrimData.PrimIndex].GetTransform();
case KPT_Box:
return AggGeom->BoxElems[InPrimData.PrimIndex].GetTransform();
case KPT_Sphyl:
return AggGeom->SphylElems[InPrimData.PrimIndex].GetTransform();
case KPT_Convex:
return AggGeom->ConvexElems[InPrimData.PrimIndex].GetTransform();
}
return FTransform::Identity;
}
void FStaticMeshEditor::SetPrimTransform(const FPrimData& InPrimData, const FTransform& InPrimTransform) const
{
check(StaticMesh->BodySetup);
FKAggregateGeom* AggGeom = &StaticMesh->BodySetup->AggGeom;
check(IsPrimValid(InPrimData));
switch (InPrimData.PrimType)
{
case KPT_Sphere:
AggGeom->SphereElems[InPrimData.PrimIndex].SetTransform(InPrimTransform);
break;
case KPT_Box:
AggGeom->BoxElems[InPrimData.PrimIndex].SetTransform(InPrimTransform);
break;
case KPT_Sphyl:
AggGeom->SphylElems[InPrimData.PrimIndex].SetTransform(InPrimTransform);
break;
case KPT_Convex:
AggGeom->ConvexElems[InPrimData.PrimIndex].SetTransform(InPrimTransform);
break;
}
StaticMesh->bCustomizedCollision = true; //mark the static mesh for collision customization
}
bool FStaticMeshEditor::OverlapsExistingPrim(const FPrimData& InPrimData) const
{
check(StaticMesh->BodySetup);
const FKAggregateGeom* AggGeom = &StaticMesh->BodySetup->AggGeom;
// Assume that if the transform of the prim is the same, then it overlaps (FKConvexElem doesn't have an operator==, and no shape takes tolerances into account)
check(IsPrimValid(InPrimData));
switch (InPrimData.PrimType)
{
case KPT_Sphere:
{
const FKSphereElem InSphereElem = AggGeom->SphereElems[InPrimData.PrimIndex];
const FTransform InElemTM = InSphereElem.GetTransform();
for (int32 i = 0; i < AggGeom->SphereElems.Num(); ++i)
{
if( i == InPrimData.PrimIndex )
{
continue;
}
const FKSphereElem& SphereElem = AggGeom->SphereElems[i];
const FTransform ElemTM = SphereElem.GetTransform();
if( InElemTM.Equals(ElemTM) )
{
return true;
}
}
}
break;
case KPT_Box:
{
const FKBoxElem InBoxElem = AggGeom->BoxElems[InPrimData.PrimIndex];
const FTransform InElemTM = InBoxElem.GetTransform();
for (int32 i = 0; i < AggGeom->BoxElems.Num(); ++i)
{
if( i == InPrimData.PrimIndex )
{
continue;
}
const FKBoxElem& BoxElem = AggGeom->BoxElems[i];
const FTransform ElemTM = BoxElem.GetTransform();
if( InElemTM.Equals(ElemTM) )
{
return true;
}
}
}
break;
case KPT_Sphyl:
{
const FKSphylElem InSphylElem = AggGeom->SphylElems[InPrimData.PrimIndex];
const FTransform InElemTM = InSphylElem.GetTransform();
for (int32 i = 0; i < AggGeom->SphylElems.Num(); ++i)
{
if( i == InPrimData.PrimIndex )
{
continue;
}
const FKSphylElem& SphylElem = AggGeom->SphylElems[i];
const FTransform ElemTM = SphylElem.GetTransform();
if( InElemTM.Equals(ElemTM) )
{
return true;
}
}
}
break;
case KPT_Convex:
{
const FKConvexElem InConvexElem = AggGeom->ConvexElems[InPrimData.PrimIndex];
const FTransform InElemTM = InConvexElem.GetTransform();
for (int32 i = 0; i < AggGeom->ConvexElems.Num(); ++i)
{
if( i == InPrimData.PrimIndex )
{
continue;
}
const FKConvexElem& ConvexElem = AggGeom->ConvexElems[i];
const FTransform ElemTM = ConvexElem.GetTransform();
if( InElemTM.Equals(ElemTM) )
{
return true;
}
}
}
break;
}
return false;
}
void FStaticMeshEditor::RefreshTool()
{
int32 NumLODs = StaticMesh->GetNumLODs();
for (int32 LODIndex = 0; LODIndex < NumLODs; ++LODIndex)
{
UpdateLODStats(LODIndex);
}
bool bForceRefresh = true;
StaticMeshDetailsView->SetObject( StaticMesh, bForceRefresh );
RegenerateLODComboList();
RegenerateUVChannelComboList();
RefreshViewport();
}
void FStaticMeshEditor::RefreshViewport()
{
Viewport->RefreshViewport();
}
void FStaticMeshEditor::RegenerateLODComboList()
{
if( StaticMesh->RenderData )
{
int32 OldLOD = GetCurrentLODLevel();
NumLODLevels = StaticMesh->RenderData->LODResources.Num();
// Fill out the LOD level combo.
LODLevels.Empty();
LODLevels.Add( MakeShareable( new FString( LOCTEXT("AutoLOD", "Auto LOD").ToString() ) ) );
LODLevels.Add( MakeShareable( new FString( LOCTEXT("BaseLOD", "Base LOD").ToString() ) ) );
for(int32 LODLevelID = 1; LODLevelID < NumLODLevels; ++LODLevelID)
{
LODLevels.Add( MakeShareable( new FString( FString::Printf(*LOCTEXT("LODLevel_ID", "LOD Level %d").ToString(), LODLevelID ) ) ) );
}
if( LODLevelCombo.IsValid() )
{
LODLevelCombo->RefreshOptions();
if( OldLOD < LODLevels.Num() )
{
LODLevelCombo->SetSelectedItem(LODLevels[OldLOD]);
}
else
{
LODLevelCombo->SetSelectedItem(LODLevels[0]);
}
}
}
else
{
NumLODLevels = 0;
LODLevels.Empty();
LODLevels.Add( MakeShareable( new FString( LOCTEXT("AutoLOD", "Auto LOD").ToString() ) ) );
}
}
void FStaticMeshEditor::RegenerateUVChannelComboList()
{
int32 OldUVChannel = GetCurrentUVChannel();
// Fill out the UV channels combo.
UVChannels.Empty();
int32 MaxUVChannels = FMath::Max<int32>(GetNumUVChannels(),1);
for(int32 UVChannelID = 0; UVChannelID < MaxUVChannels; ++UVChannelID)
{
UVChannels.Add( MakeShareable( new FString( FText::Format( LOCTEXT("UVChannel_ID", "UV Channel {0}"), FText::AsNumber( UVChannelID ) ).ToString() ) ) );
}
if(UVChannelCombo.IsValid())
{
UVChannelCombo->RefreshOptions();
if( OldUVChannel >= 0 && OldUVChannel < GetNumUVChannels() )
{
UVChannelCombo->SetSelectedItem(UVChannels[OldUVChannel]);
}
else
{
UVChannelCombo->SetSelectedItem(UVChannels[0]);
}
}
}
void FStaticMeshEditor::UpdateLODStats(int32 CurrentLOD)
{
NumTriangles[CurrentLOD] = 0;
NumVertices[CurrentLOD] = 0;
NumUVChannels[CurrentLOD] = 0;
NumLODLevels = 0;
if( StaticMesh->RenderData )
{
NumLODLevels = StaticMesh->RenderData->LODResources.Num();
if (CurrentLOD >= 0 && CurrentLOD < NumLODLevels)
{
FStaticMeshLODResources& LODModel = StaticMesh->RenderData->LODResources[CurrentLOD];
NumTriangles[CurrentLOD] = LODModel.GetNumTriangles();
NumVertices[CurrentLOD] = LODModel.GetNumVertices();
NumUVChannels[CurrentLOD] = LODModel.VertexBuffer.GetNumTexCoords();
}
}
}
void FStaticMeshEditor::ComboBoxSelectionChanged( TSharedPtr<FString> NewSelection, ESelectInfo::Type /*SelectInfo*/ )
{
Viewport->RefreshViewport();
}
void FStaticMeshEditor::LODLevelsSelectionChanged( TSharedPtr<FString> NewSelection, ESelectInfo::Type /*SelectInfo*/ )
{
int32 CurrentLOD = GetCurrentLODLevel();
UpdateLODStats( CurrentLOD > 0? CurrentLOD - 1 : 0 );
Viewport->ForceLODLevel(CurrentLOD);
}
int32 FStaticMeshEditor::GetCurrentUVChannel()
{
int32 Index = 0;
UVChannels.Find(UVChannelCombo->GetSelectedItem(), Index);
return Index;
}
int32 FStaticMeshEditor::GetCurrentLODLevel()
{
int32 Index = 0;
LODLevels.Find(LODLevelCombo->GetSelectedItem(), Index);
return Index;
}
int32 FStaticMeshEditor::GetCurrentLODIndex()
{
int32 Index = LODLevels.Find(LODLevelCombo->GetSelectedItem());
return Index == 0? 0 : Index - 1;
}
void FStaticMeshEditor::GenerateKDop(const FVector* Directions, uint32 NumDirections)
{
TArray<FVector> DirArray;
for(uint32 DirectionIndex = 0;DirectionIndex < NumDirections;DirectionIndex++)
{
DirArray.Add(Directions[DirectionIndex]);
}
GEditor->BeginTransaction(LOCTEXT("FStaticMeshEditor_GenerateKDop", "Create Convex Collision"));
const int32 PrimIndex = GenerateKDopAsSimpleCollision(StaticMesh, DirArray);
GEditor->EndTransaction();
if (PrimIndex != INDEX_NONE)
{
if (FEngineAnalytics::IsAvailable())
{
FEngineAnalytics::GetProvider().RecordEvent(TEXT("Editor.Usage.StaticMesh.Collision"), TEXT("Type"), TEXT("KDop Collision"));
}
const FPrimData PrimData = FPrimData(KPT_Convex, PrimIndex);
ClearSelectedPrims();
AddSelectedPrim(PrimData, true);
// Don't 'nudge' KDop prims, as they are fitted specifically around the geometry
}
Viewport->RefreshViewport();
}
void FStaticMeshEditor::OnCollisionBox()
{
GEditor->BeginTransaction(LOCTEXT("FStaticMeshEditor_OnCollisionBox", "Create Box Collision"));
const int32 PrimIndex = GenerateBoxAsSimpleCollision(StaticMesh);
GEditor->EndTransaction();
if (PrimIndex != INDEX_NONE)
{
if (FEngineAnalytics::IsAvailable())
{
FEngineAnalytics::GetProvider().RecordEvent(TEXT("Editor.Usage.StaticMesh.Collision"), TEXT("Type"), TEXT("Box Collision"));
}
const FPrimData PrimData = FPrimData(KPT_Box, PrimIndex);
ClearSelectedPrims();
AddSelectedPrim(PrimData, true);
while( OverlapsExistingPrim(PrimData) )
{
TranslateSelectedPrims(OverlapNudge);
}
}
Viewport->RefreshViewport();
}
void FStaticMeshEditor::OnCollisionSphere()
{
GEditor->BeginTransaction(LOCTEXT("FStaticMeshEditor_OnCollisionSphere", "Create Sphere Collision"));
const int32 PrimIndex = GenerateSphereAsSimpleCollision(StaticMesh);
GEditor->EndTransaction();
if (PrimIndex != INDEX_NONE)
{
if (FEngineAnalytics::IsAvailable())
{
FEngineAnalytics::GetProvider().RecordEvent(TEXT("Editor.Usage.StaticMesh.Collision"), TEXT("Type"), TEXT("Sphere Collision"));
}
const FPrimData PrimData = FPrimData(KPT_Sphere, PrimIndex);
ClearSelectedPrims();
AddSelectedPrim(PrimData, true);
while( OverlapsExistingPrim(PrimData) )
{
TranslateSelectedPrims(OverlapNudge);
}
}
Viewport->RefreshViewport();
}
void FStaticMeshEditor::OnCollisionSphyl()
{
GEditor->BeginTransaction(LOCTEXT("FStaticMeshEditor_OnCollisionSphyl", "Create Capsule Collision"));
const int32 PrimIndex = GenerateSphylAsSimpleCollision(StaticMesh);
GEditor->EndTransaction();
if (PrimIndex != INDEX_NONE)
{
if (FEngineAnalytics::IsAvailable())
{
FEngineAnalytics::GetProvider().RecordEvent(TEXT("Editor.Usage.StaticMesh.Collision"), TEXT("Type"), TEXT("Capsule Collision"));
}
const FPrimData PrimData = FPrimData(KPT_Sphyl, PrimIndex);
ClearSelectedPrims();
AddSelectedPrim(PrimData, true);
while( OverlapsExistingPrim(PrimData) )
{
TranslateSelectedPrims(OverlapNudge);
}
}
Viewport->RefreshViewport();
}
void FStaticMeshEditor::OnRemoveCollision(void)
{
UBodySetup* BS = StaticMesh->BodySetup;
check(BS != NULL && BS->AggGeom.GetElementCount() > 0);
ClearSelectedPrims();
// Make sure rendering is done - so we are not changing data being used by collision drawing.
FlushRenderingCommands();
GEditor->BeginTransaction(LOCTEXT("FStaticMeshEditor_RemoveCollision", "Remove Collision"));
StaticMesh->BodySetup->Modify();
StaticMesh->BodySetup->RemoveSimpleCollision();
GEditor->EndTransaction();
// refresh collision change back to staticmesh components
RefreshCollisionChange(*StaticMesh);
// Mark staticmesh as dirty, to help make sure it gets saved.
StaticMesh->MarkPackageDirty();
// Update views/property windows
Viewport->RefreshViewport();
StaticMesh->bCustomizedCollision = true; //mark the static mesh for collision customization
}
bool FStaticMeshEditor::CanRemoveCollision()
{
UBodySetup* BS = StaticMesh->BodySetup;
return (BS != NULL && BS->AggGeom.GetElementCount() > 0);
}
/** Util for adding vertex to an array if it is not already present. */
static void AddVertexIfNotPresent(TArray<FVector>& Vertices, const FVector& NewVertex)
{
bool bIsPresent = false;
for(int32 i=0; i<Vertices.Num(); i++)
{
float diffSqr = (NewVertex - Vertices[i]).SizeSquared();
if(diffSqr < 0.01f * 0.01f)
{
bIsPresent = 1;
break;
}
}
if(!bIsPresent)
{
Vertices.Add(NewVertex);
}
}
void FStaticMeshEditor::OnConvertBoxToConvexCollision()
{
// If we have a collision model for this staticmesh, ask if we want to replace it.
if (StaticMesh->BodySetup != NULL)
{
int32 ShouldReplace = FMessageDialog::Open( EAppMsgType::YesNo, LOCTEXT("ConvertBoxCollisionPrompt", "Are you sure you want to convert all box collision?") );
if (ShouldReplace == EAppReturnType::Yes)
{
UBodySetup* BodySetup = StaticMesh->BodySetup;
int32 NumBoxElems = BodySetup->AggGeom.BoxElems.Num();
if (NumBoxElems > 0)
{
ClearSelectedPrims();
// Make sure rendering is done - so we are not changing data being used by collision drawing.
FlushRenderingCommands();
FKConvexElem* NewConvexColl = NULL;
//For each box elem, calculate the new convex collision representation
//Stored in a temp array so we can undo on failure.
TArray<FKConvexElem> TempArray;
for (int32 i=0; i<NumBoxElems; i++)
{
const FKBoxElem& BoxColl = BodySetup->AggGeom.BoxElems[i];
//Create a new convex collision element
NewConvexColl = new(TempArray) FKConvexElem();
NewConvexColl->ConvexFromBoxElem(BoxColl);
}
//Clear the cache (PIE may have created some data), create new GUID
BodySetup->InvalidatePhysicsData();
//Copy the new data into the static mesh
BodySetup->AggGeom.ConvexElems.Append(TempArray);
//Clear out what we just replaced
BodySetup->AggGeom.BoxElems.Empty();
BodySetup->CreatePhysicsMeshes();
// Select the new prims
FKAggregateGeom* AggGeom = &StaticMesh->BodySetup->AggGeom;
for (int32 i = 0; i < NumBoxElems; ++i)
{
AddSelectedPrim(FPrimData(KPT_Convex, (AggGeom->ConvexElems.Num() - (i+1))), false);
}
RefreshCollisionChange(*StaticMesh);
// Mark static mesh as dirty, to help make sure it gets saved.
StaticMesh->MarkPackageDirty();
// Update views/property windows
Viewport->RefreshViewport();
StaticMesh->bCustomizedCollision = true; //mark the static mesh for collision customization
}
}
}
}
void FStaticMeshEditor::OnCopyCollisionFromSelectedStaticMesh()
{
UStaticMesh* SelectedMesh = GetFirstSelectedStaticMeshInContentBrowser();
check(SelectedMesh && SelectedMesh != StaticMesh && SelectedMesh->BodySetup != NULL);
UBodySetup* BodySetup = StaticMesh->BodySetup;
ClearSelectedPrims();
// Make sure rendering is done - so we are not changing data being used by collision drawing.
FlushRenderingCommands();
GEditor->BeginTransaction(LOCTEXT("FStaticMeshEditor_CopyCollisionFromSelectedStaticMesh", "Copy Collision from Selected Static Mesh"));
BodySetup->Modify();
// Copy body properties from
BodySetup->CopyBodyPropertiesFrom(SelectedMesh->BodySetup);
// Enable collision, if not already
if( !Viewport->GetViewportClient().IsSetShowSimpleCollisionChecked() )
{
Viewport->GetViewportClient().SetShowSimpleCollision();
}
// Invalidate physics data and create new meshes
BodySetup->InvalidatePhysicsData();
BodySetup->CreatePhysicsMeshes();
GEditor->EndTransaction();
RefreshCollisionChange(*StaticMesh);
// Mark static mesh as dirty, to help make sure it gets saved.
StaticMesh->MarkPackageDirty();
// Redraw level editor viewports, in case the asset's collision is visible in a viewport and the viewport isn't set to realtime.
// Note: This could be more intelligent and only trigger a redraw if the asset is referenced in the world.
GUnrealEd->RedrawLevelEditingViewports();
// Update views/property windows
Viewport->RefreshViewport();
StaticMesh->bCustomizedCollision = true; //mark the static mesh for collision customization
}
bool FStaticMeshEditor::CanCopyCollisionFromSelectedStaticMesh() const
{
bool CanCopy = false;
TArray<FAssetData> SelectedAssets;
GEditor->GetContentBrowserSelections(SelectedAssets);
if(SelectedAssets.Num() == 1)
{
FAssetData& Asset = SelectedAssets[0];
if(Asset.GetClass() == UStaticMesh::StaticClass())
{
UStaticMesh* SelectedMesh = Cast<UStaticMesh>(Asset.GetAsset());
if(SelectedMesh && SelectedMesh != StaticMesh && SelectedMesh->BodySetup != NULL)
{
CanCopy = true;
}
}
}
return CanCopy;
}
UStaticMesh* FStaticMeshEditor::GetFirstSelectedStaticMeshInContentBrowser() const
{
TArray<FAssetData> SelectedAssets;
GEditor->GetContentBrowserSelections(SelectedAssets);
for(auto& Asset : SelectedAssets)
{
UStaticMesh* SelectedMesh = Cast<UStaticMesh>(Asset.GetAsset());
if(SelectedMesh)
{
return SelectedMesh;
}
}
return NULL;
}
void FStaticMeshEditor::SetEditorMesh(UStaticMesh* InStaticMesh, bool bResetCamera/*=true*/)
{
ClearSelectedPrims();
StaticMesh = InStaticMesh;
//Init stat arrays.
const int32 ArraySize = MAX_STATIC_MESH_LODS;
NumVertices.Empty(ArraySize);
NumVertices.AddZeroed(ArraySize);
NumTriangles.Empty(ArraySize);
NumTriangles.AddZeroed(ArraySize);
NumUVChannels.Empty(ArraySize);
NumUVChannels.AddZeroed(ArraySize);
// Always default the LOD to 0 when setting the mesh.
UpdateLODStats(0);
// Fill out the LOD level combo.
LODLevels.Empty();
LODLevels.Add( MakeShareable( new FString( LOCTEXT("AutoLOD", "Auto LOD").ToString() ) ) );
LODLevels.Add( MakeShareable( new FString( LOCTEXT("BaseLOD", "Base LOD").ToString() ) ) );
for(int32 LODLevelID = 1; LODLevelID < NumLODLevels; ++LODLevelID)
{
LODLevels.Add( MakeShareable( new FString( FString::Printf(*LOCTEXT("LODLevel_ID", "LOD Level %d").ToString(), LODLevelID ) ) ) );
//Update LOD stats for each level
UpdateLODStats(LODLevelID);
}
// Fill out the UV channels combo.
UVChannels.Empty();
for(int32 UVChannelID = 0; UVChannelID < GetNumUVChannels(0); ++UVChannelID)
{
UVChannels.Add( MakeShareable( new FString( FText::Format( LOCTEXT("UVChannel_ID", "UV Channel {0}"), FText::AsNumber( UVChannelID ) ).ToString() ) ) );
}
if( UVChannelCombo.IsValid() )
{
UVChannelCombo->RefreshOptions();
if(UVChannels.Num())
{
UVChannelCombo->SetSelectedItem(UVChannels[0]);
}
}
if( LODLevelCombo.IsValid() )
{
LODLevelCombo->RefreshOptions();
if(LODLevels.Num())
{
LODLevelCombo->SetSelectedItem(LODLevels[0]);
}
}
// Set the details view.
StaticMeshDetailsView->SetObject(StaticMesh);
Viewport->UpdatePreviewMesh(StaticMesh, bResetCamera);
Viewport->RefreshViewport();
}
void FStaticMeshEditor::OnChangeMesh()
{
UStaticMesh* SelectedMesh = GetFirstSelectedStaticMeshInContentBrowser();
check(SelectedMesh != NULL && SelectedMesh != StaticMesh);
RemoveEditingObject(StaticMesh);
AddEditingObject(SelectedMesh);
SetEditorMesh(SelectedMesh);
// Clear selections made on previous mesh
ClearSelectedPrims();
GetSelectedEdges().Empty();
if(SocketManager.IsValid())
{
SocketManager->UpdateStaticMesh();
}
}
bool FStaticMeshEditor::CanChangeMesh() const
{
bool CanChange = false;
TArray<FAssetData> SelectedAssets;
GEditor->GetContentBrowserSelections(SelectedAssets);
if(SelectedAssets.Num() == 1)
{
FAssetData& Asset = SelectedAssets[0];
if(Asset.GetClass() == UStaticMesh::StaticClass())
{
UStaticMesh* SelectedMesh = Cast<UStaticMesh>(Asset.GetAsset());
if(SelectedMesh && SelectedMesh != StaticMesh)
{
CanChange = true;
}
}
}
return CanChange;
}
void FStaticMeshEditor::OnSaveGeneratedLODs()
{
if (StaticMesh)
{
StaticMesh->GenerateLodsInPackage();
// Update editor UI as we modified LOD groups
auto Selected = StaticMeshDetailsView->GetSelectedObjects();
StaticMeshDetailsView->SetObjects(Selected, true);
// Update screen
Viewport->RefreshViewport();
}
}
void FStaticMeshEditor::DoDecomp(float InAccuracy, int32 InMaxHullVerts)
{
// Check we have a selected StaticMesh
if(StaticMesh && StaticMesh->RenderData)
{
FStaticMeshLODResources& LODModel = StaticMesh->RenderData->LODResources[0];
// Start a busy cursor so the user has feedback while waiting
const FScopedBusyCursor BusyCursor;
// Make vertex buffer
int32 NumVerts = LODModel.VertexBuffer.GetNumVertices();
TArray<FVector> Verts;
for(int32 i=0; i<NumVerts; i++)
{
FVector Vert = LODModel.PositionVertexBuffer.VertexPosition(i);
Verts.Add(Vert);
}
// Grab all indices
TArray<uint32> AllIndices;
LODModel.IndexBuffer.GetCopy(AllIndices);
// Only copy indices that have collision enabled
TArray<uint32> CollidingIndices;
for(const FStaticMeshSection& Section : LODModel.Sections)
{
if(Section.bEnableCollision)
{
for (uint32 IndexIdx = Section.FirstIndex; IndexIdx < Section.FirstIndex + (Section.NumTriangles * 3); IndexIdx++)
{
CollidingIndices.Add(AllIndices[IndexIdx]);
}
}
}
ClearSelectedPrims();
// Make sure rendering is done - so we are not changing data being used by collision drawing.
FlushRenderingCommands();
// Get the BodySetup we are going to put the collision into
UBodySetup* bs = StaticMesh->BodySetup;
if(bs)
{
bs->RemoveSimpleCollision();
}
else
{
// Otherwise, create one here.
StaticMesh->CreateBodySetup();
bs = StaticMesh->BodySetup;
}
// Run actual util to do the work (if we have some valid input)
if(Verts.Num() >= 3 && CollidingIndices.Num() >= 3)
{
DecomposeMeshToHulls(bs, Verts, CollidingIndices, InAccuracy, InMaxHullVerts);
}
// Enable collision, if not already
if( !Viewport->GetViewportClient().IsSetShowSimpleCollisionChecked() )
{
Viewport->GetViewportClient().SetShowSimpleCollision();
}
// refresh collision change back to staticmesh components
RefreshCollisionChange(*StaticMesh);
// Mark mesh as dirty
StaticMesh->MarkPackageDirty();
// Update screen.
Viewport->RefreshViewport();
StaticMesh->bCustomizedCollision = true; //mark the static mesh for collision customization
}
}
TSet< int32 >& FStaticMeshEditor::GetSelectedEdges()
{
return Viewport->GetSelectedEdges();
}
int32 FStaticMeshEditor::GetNumTriangles( int32 LODLevel ) const
{
return NumTriangles.IsValidIndex(LODLevel) ? NumTriangles[LODLevel] : 0;
}
int32 FStaticMeshEditor::GetNumVertices( int32 LODLevel ) const
{
return NumVertices.IsValidIndex(LODLevel) ? NumVertices[LODLevel] : 0;
}
int32 FStaticMeshEditor::GetNumUVChannels( int32 LODLevel ) const
{
return NumUVChannels.IsValidIndex(LODLevel) ? NumUVChannels[LODLevel] : 0;
}
void FStaticMeshEditor::DeleteSelected()
{
if (GetSelectedSocket())
{
DeleteSelectedSockets();
}
if (HasSelectedPrims())
{
DeleteSelectedPrims();
}
}
bool FStaticMeshEditor::CanDeleteSelected() const
{
return (GetSelectedSocket() != NULL || HasSelectedPrims());
}
void FStaticMeshEditor::DeleteSelectedSockets()
{
check(SocketManager.IsValid());
SocketManager->DeleteSelectedSocket();
}
void FStaticMeshEditor::DeleteSelectedPrims()
{
if (SelectedPrims.Num() > 0)
{
// Sort the selected prims by PrimIndex so when we're deleting them we don't mess up other prims indicies
struct FCompareFPrimDataPrimIndex
{
FORCEINLINE bool operator()(const FPrimData& A, const FPrimData& B) const
{
return A.PrimIndex < B.PrimIndex;
}
};
SelectedPrims.Sort(FCompareFPrimDataPrimIndex());
check(StaticMesh->BodySetup);
FKAggregateGeom* AggGeom = &StaticMesh->BodySetup->AggGeom;
GEditor->BeginTransaction(LOCTEXT("FStaticMeshEditor_DeleteSelectedPrims", "Delete Collision"));
StaticMesh->BodySetup->Modify();
for (int32 PrimIdx = SelectedPrims.Num() - 1; PrimIdx >= 0; PrimIdx--)
{
const FPrimData& PrimData = SelectedPrims[PrimIdx];
check(IsPrimValid(PrimData));
switch (PrimData.PrimType)
{
case KPT_Sphere:
AggGeom->SphereElems.RemoveAt(PrimData.PrimIndex);
break;
case KPT_Box:
AggGeom->BoxElems.RemoveAt(PrimData.PrimIndex);
break;
case KPT_Sphyl:
AggGeom->SphylElems.RemoveAt(PrimData.PrimIndex);
break;
case KPT_Convex:
AggGeom->ConvexElems.RemoveAt(PrimData.PrimIndex);
break;
}
}
GEditor->EndTransaction();
ClearSelectedPrims();
// Make sure rendering is done - so we are not changing data being used by collision drawing.
FlushRenderingCommands();
// Make sure to invalidate cooked data
StaticMesh->BodySetup->InvalidatePhysicsData();
// refresh collision change back to staticmesh components
RefreshCollisionChange(*StaticMesh);
// Mark staticmesh as dirty, to help make sure it gets saved.
StaticMesh->MarkPackageDirty();
// Update views/property windows
Viewport->RefreshViewport();
StaticMesh->bCustomizedCollision = true; //mark the static mesh for collision customization
}
}
void FStaticMeshEditor::DuplicateSelected()
{
DuplicateSelectedSocket();
const FVector InitialOffset(20.f);
DuplicateSelectedPrims(&InitialOffset);
}
bool FStaticMeshEditor::CanDuplicateSelected() const
{
return (GetSelectedSocket() != NULL || HasSelectedPrims());
}
bool FStaticMeshEditor::CanRenameSelected() const
{
return (GetSelectedSocket() != NULL);
}
void FStaticMeshEditor::ExecuteFindInExplorer()
{
if ( ensure(StaticMesh->AssetImportData) )
{
const FString SourceFilePath = StaticMesh->AssetImportData->GetFirstFilename();
if ( SourceFilePath.Len() && IFileManager::Get().FileSize( *SourceFilePath ) != INDEX_NONE )
{
FPlatformProcess::ExploreFolder( *FPaths::GetPath(SourceFilePath) );
}
}
}
bool FStaticMeshEditor::CanExecuteSourceCommands() const
{
if ( !StaticMesh->AssetImportData )
{
return false;
}
const FString& SourceFilePath = StaticMesh->AssetImportData->GetFirstFilename();
return SourceFilePath.Len() && IFileManager::Get().FileSize(*SourceFilePath) != INDEX_NONE;
}
void FStaticMeshEditor::OnObjectReimported(UObject* InObject)
{
// Make sure we are using the object that is being reimported, otherwise a lot of needless work could occur.
if(StaticMesh == InObject)
{
//When we re-import we want to avoid moving the camera in the staticmesh editor
bool bResetCamera = false;
SetEditorMesh(Cast<UStaticMesh>(InObject), bResetCamera);
if (SocketManager.IsValid())
{
SocketManager->UpdateStaticMesh();
}
}
}
EViewModeIndex FStaticMeshEditor::GetViewMode() const
{
if (Viewport.IsValid())
{
const FStaticMeshEditorViewportClient& ViewportClient = Viewport->GetViewportClient();
return ViewportClient.GetViewMode();
}
else
{
return VMI_Unknown;
}
}
void FStaticMeshEditor::OnConvexDecomposition()
{
TabManager->InvokeTab(CollisionTabId);
}
bool FStaticMeshEditor::OnRequestClose()
{
bool bAllowClose = true;
if (StaticMeshDetails.IsValid() && StaticMeshDetails.Pin()->IsApplyNeeded())
{
// find out the user wants to do with this dirty material
EAppReturnType::Type YesNoCancelReply = FMessageDialog::Open(
EAppMsgType::YesNoCancel,
FText::Format( LOCTEXT("ShouldApplyLODChanges", "Would you like to apply level of detail changes to {0}?\n\n(No will lose all changes!)"), FText::FromString( StaticMesh->GetName() ) )
);
switch (YesNoCancelReply)
{
case EAppReturnType::Yes:
StaticMeshDetails.Pin()->ApplyChanges();
bAllowClose = true;
break;
case EAppReturnType::No:
// Do nothing, changes will be abandoned.
bAllowClose = true;
break;
case EAppReturnType::Cancel:
// Don't exit.
bAllowClose = false;
break;
}
}
return bAllowClose;
}
void FStaticMeshEditor::RegisterOnPostUndo( const FOnPostUndo& Delegate )
{
OnPostUndo.Add( Delegate );
}
void FStaticMeshEditor::UnregisterOnPostUndo( SWidget* Widget )
{
OnPostUndo.RemoveAll( Widget );
}
void FStaticMeshEditor::NotifyPostChange( const FPropertyChangedEvent& PropertyChangedEvent, UProperty* PropertyThatChanged )
{
if(StaticMesh && StaticMesh->BodySetup)
{
StaticMesh->BodySetup->CreatePhysicsMeshes();
}
}
void FStaticMeshEditor::UndoAction()
{
GEditor->UndoTransaction();
}
void FStaticMeshEditor::RedoAction()
{
GEditor->RedoTransaction();
}
void FStaticMeshEditor::PostUndo( bool bSuccess )
{
RemoveInvalidPrims();
RefreshTool();
OnPostUndo.Broadcast();
}
void FStaticMeshEditor::PostRedo( bool bSuccess )
{
RemoveInvalidPrims();
RefreshTool();
OnPostUndo.Broadcast();
}
void FStaticMeshEditor::OnSocketSelectionChanged()
{
UStaticMeshSocket* SelectedSocket = GetSelectedSocket();
if (SelectedSocket)
{
ClearSelectedPrims();
}
Viewport->GetViewportClient().OnSocketSelectionChanged( SelectedSocket );
}
void FStaticMeshEditor::OnPostReimport(UObject* InObject, bool bSuccess)
{
// Ignore if this is regarding a different object
if ( InObject != StaticMesh )
{
return;
}
if (bSuccess)
{
RefreshTool();
}
}
#undef LOCTEXT_NAMESPACE