Files
UnrealEngineUWP/Engine/Source/Editor/NiagaraEditor/Private/Customizations/NiagaraComponentDetails.cpp
Marcus Wassmer 2826204161 Copying //UE4/Dev-Rendering to //UE4/Dev-Main (Source: //UE4/Dev-Rendering @ 3357411)
#lockdown Nick.Penwarden
#rb none

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

Change 3244756 on 2017/01/03 by Marcus.Wassmer

	Copying //Tasks/UE4/Dev-Niagara@3244743 to Dev-Rendering (//UE4/Dev-Rendering)

Change 3248667 on 2017/01/05 by Olaf.Piesche

	Resaving default asset because of engine verison issue; maybe unnecessary, but resaving niagara engine content to be sure

	#jira UE-40160

Change 3249324 on 2017/01/06 by Marcus.Wassmer

	Resave with an actual version to stop cook warning

Change 3249611 on 2017/01/06 by Marcus.Wassmer

	Just remove warning-causing niagara data for now.

Change 3308052 on 2017/02/16 by Rolando.Caloca

	DR - Check for Vulkan SDK, and only use it if it's newer or the same as the headers we distribute

Change 3308109 on 2017/02/16 by Rolando.Caloca

	DR - Upgrade glslang to 1.0.39.1

Change 3308111 on 2017/02/16 by Rolando.Caloca

	DR - Update Vulkan distribution to 1.0.39.1

Change 3308153 on 2017/02/16 by Rolando.Caloca

	DR - Updated glslang libs

Change 3308842 on 2017/02/17 by Rolando.Caloca

	DR - Fixed copy/paste

Change 3310007 on 2017/02/17 by Chris.Bunner

	Back out CL 3221219 - causing MIC generation issues and superseded by CL 3273971.

	#jira UE-37792

Change 3310154 on 2017/02/17 by Chris.Bunner

	Assert when attempting to add a custom material attribute already in the base attributes list.

Change 3310155 on 2017/02/17 by Chris.Bunner

	PR #3231: Validate material index before accessing (Contributed by projectgheist)

	#jira UE-41774, UE-41788

Change 3310162 on 2017/02/17 by Chris.Bunner

	PR #3252: Added MobileMaterialInterface to UsedMaterials (Contributed by projectgheist)

	#jira UE-41823, UE-41950

Change 3310176 on 2017/02/17 by Chris.Bunner

	Merging CL 3233886: AMD HDR support (requires r.AMDSupportsHDRDisplayOutput=1 in ini).
	Update to AGS 5.0.5.
	Partial code tidy up.

Change 3310187 on 2017/02/17 by Chris.Bunner

	Preserve constant expressions rather than always casting after translating a material attribute. Losing the notion of constant means we can't correctly detect used properties and falsely enable e.g. PDO. Happened because of the incorrect component masks in BreakMaterialNodes which then had to be downcast to the correct type which is done as an inline fragment rather than swizzle expression.

	#jira UE-41594

Change 3310215 on 2017/02/17 by Chris.Bunner

	Prevent SpeedTree node compiling for skeletal meshes (not supported as uses more UV sets than available).
	More descriptive error for missing Cubemap UV input on TextureSample material node .

	#jira UE-33098

Change 3310838 on 2017/02/18 by Joe.Graf

	Moved some private functions to public for a licensee

	#CodeReview: matt.kuhlenschmidt
	#rb: n/a

Change 3311876 on 2017/02/20 by Rolando.Caloca

	DR - Expose skin cache cvar r.SkinCache.AccumulationBufferSizeInKB

	#jira UE-42014

Change 3314139 on 2017/02/21 by Rolando.Caloca

	DR - Minor cleanup pass
	- Remove FVulkanPendingState
	- Renamed some classes for clarity
	- Hoist pending UAVs for flush out to pending compute state

Change 3314642 on 2017/02/21 by Rolando.Caloca

	DR - Some more renaming

Change 3315431 on 2017/02/21 by Ben.Salem

	Properly set default values for test time out and tick. We now will default to ticking once per second, and tracking the macro stats of GPU/Render/Game thread time.

	#tests Ran showdown demo several times

Change 3316710 on 2017/02/22 by Rolando.Caloca

	DR - hlslcc - Fix refract intrinsic

Change 3316718 on 2017/02/22 by Rolando.Caloca

	DR - hlslcc - Built libs to pick up change from 3316710 - refract fix

Change 3316820 on 2017/02/22 by Benjamin.Hyder

	updating Tm-TrigNodes map

Change 3317192 on 2017/02/22 by Benjamin.Hyder

	Updating QA-Decals map

Change 3317528 on 2017/02/22 by Benjamin.Hyder

	Updating QA-Decals map

Change 3317639 on 2017/02/22 by Benjamin.Hyder

	Updating Decal on Complex Mesh example in QA-Decals

Change 3317764 on 2017/02/22 by Benjamin.Hyder

	Final updates to QA-Decals

Change 3318319 on 2017/02/22 by Rolando.Caloca

	DR - minor reorg/rename

Change 3318379 on 2017/02/22 by Rolando.Caloca

	DR - more cleanup

Change 3321181 on 2017/02/24 by Rolando.Caloca

	DR - Fix GL bug

Change 3321247 on 2017/02/24 by Rolando.Caloca

	DR - Fix misc bugs

Change 3321898 on 2017/02/24 by Chris.Bunner

	Only issue clear TLV dispatch if required.

	#jira UERNDR-193

Change 3321904 on 2017/02/24 by Chris.Bunner

	Added comment for potential future optimization.

Change 3322013 on 2017/02/24 by Uriel.Doyon

	Fixed separate translucency being affected by Gaussian DOF
	#jira UE-40489

Change 3322517 on 2017/02/24 by Uriel.Doyon

	Fixed issue with InvestigateTexture command removing budget limit.
	Fixed StreamingBounds show flag not working. It nows shows the streaming bound for the currently selected textures.
	#jira UE-40485

Change 3323470 on 2017/02/27 by Chad.Garyet

	Removing DDC job from dev-rendering

Change 3323479 on 2017/02/27 by Chad.Garyet

	Removing RDU agent type

Change 3323519 on 2017/02/27 by Chad.Garyet

	removing NCL/LHR/SEA agent types to clean up space

Change 3323639 on 2017/02/27 by Benjamin.Hyder

	More updates to QA-Decals

Change 3324207 on 2017/02/27 by Uriel.Doyon

	Fixed typo ScaleTexturesByGlobalMyBias ->  ScaleTexturesByGlobalMipBias
	Removed bad merge in FStreamingTextureLevelContext::GetBuildDataIndexRef

Change 3324396 on 2017/02/27 by Uriel.Doyon

	Fixed an issue with the Streaming Bounds show flag interferring with the static level data initialization
	#jira UE-40485

Change 3325227 on 2017/02/28 by Chris.Bunner

	Fix-up AMD AGS libs.

Change 3325566 on 2017/02/28 by Uriel.Doyon

	Fixed possible out-of-bound access in GetUsedTexture() when passing ERHIFeatureLevel::Num

Change 3326009 on 2017/02/28 by Uriel.Doyon

	Better fix for 3325566, as the previous fix would ignore the material instance overrides.

Change 3327058 on 2017/03/01 by Benjamin.Hyder

	Preparing TM_Shadermodels map for automation

Change 3328222 on 2017/03/01 by Chris.Bunner

	Prevent decals from drawing in separate translucency pass. Whilst user control and material relevance were already removed, if the flag was checked before being disabled (by swapping to decal domain) this was still being read in the render loop, now explicitly ignores decals.

	#jira UE-42449, UE-42446

Change 3329848 on 2017/03/02 by Uriel.Doyon

	Added some extra logs to help track UE-42168

Change 3329977 on 2017/03/02 by Rolando.Caloca

	DR - Fix bad clear value

Change 3330008 on 2017/03/02 by Benjamin.Hyder

	More preparations for QA-Decals automation

Change 3330754 on 2017/03/02 by Daniel.Wright

	Prominent comment explaining reflection env async compute usage and why it's not overlapped with anything

Change 3331451 on 2017/03/03 by Marc.Olano

	Manually unroll simplex noise loop to avoid PSO bug on AMD/Metal

Change 3331839 on 2017/03/03 by Rolando.Caloca

	DR - hlslcc - add missing file to project

Change 3332247 on 2017/03/03 by Rolando.Caloca

	DR - Fix for integrated intel
	PR #3305
	#jira UE-42393

Change 3332259 on 2017/03/03 by Rolando.Caloca

	DR - Fix bad index into pixel formats
	PR #3237
	#jira UE-41855

Change 3332305 on 2017/03/03 by Rolando.Caloca

	DR - OpenGL SRV for index buffers
	PR #3271
	#jira UE-32618

Change 3332313 on 2017/03/03 by Rolando.Caloca

	DR - Fix for integrated intel (properly)
	PR #3305
	#jira UE-42393

Change 3332317 on 2017/03/03 by Rolando.Caloca

	DR - OpenGL SRV for index buffers (properly)
	PR #3271
	#jira UE-32618

Change 3332368 on 2017/03/03 by Rolando.Caloca

	DR - Minor fixes so -sm4 and -sm5 can be used on windows with OpenGL/Vulkan

Change 3333690 on 2017/03/06 by Daniel.Wright

	[Copy] Changing movable skylight properties no longer affects static draw lists

Change 3333693 on 2017/03/06 by Daniel.Wright

	[Copy] Added 'r.AOListMeshDistanceFields' which dumps out mesh distance fields sorted by memory size, useful for directing content optimizations

Change 3333705 on 2017/03/06 by Daniel.Wright

	[Copy] Mesh distance fields are now 8 bit fixed point by default, but can be changed back to 16 bit floating piont with a project setting.
	* 8 bit uses half memory but introduces error for thin surfaces or large meshes.

Change 3333721 on 2017/03/06 by David.Hill

	DecalProxy:
	Copy float FadeScreenSize to FDeferredDecalProxy for use in the render thread.  This avoids  pointer chasing to the UDecalComponent (game thread component).

Change 3333772 on 2017/03/06 by Daniel.Wright

	[Copy] Scene motion blur data is only updated for the main renderer frames.  Fixes scene captures and planar reflections breaking object motion blur.

Change 3333790 on 2017/03/06 by Daniel.Wright

	[Copy] Mesh distance field generation uses Embree, for a 2.5x speedup
	* Can switch back to old kDOP generation with 'r.DistanceFieldBuild.UseEmbree 0' for debugging

Change 3333822 on 2017/03/06 by Daniel.Wright

	[Copy] Moved mesh distance field code into MeshDistanceFieldUtilities.cpp
	* Moved FMeshUtilities to its own header so the 8k line MeshUtilites.cpp file can be further split up

Change 3333827 on 2017/03/06 by Daniel.Wright

	[Copy] Range compress 8bit distance fields - gets one extra bit of precision on average

Change 3333828 on 2017/03/06 by Daniel.Wright

	[Copy] Raised High ShadowQuality to 2048 as 1024 for CSM is way too low

Change 3333831 on 2017/03/06 by Daniel.Wright

	Non-editor compile fix

Change 3333836 on 2017/03/06 by Daniel.Wright

	[Copy] Workaround for gobal distance field volume textures being bloated by 4x on PS4 due to the recommended tiling modes.  They now use a 2d tiling mode which avoids the bloat, saving 96Mb.

Change 3333843 on 2017/03/06 by Daniel.Wright

	[Copy] Added OcclusionExponent to skylight component
	* Useful for brightening up indoors without losing contact shadows as MinOcclusion does

Change 3333845 on 2017/03/06 by Daniel.Wright

	[Copy] Capsule shadow BP functions

Change 3333850 on 2017/03/06 by Daniel.Wright

	[Copy] Added OcclusionCombineMode to skylight component

Change 3333854 on 2017/03/06 by Daniel.Wright

	[Copy] Gnm properly registers clears as GPU work so those events show up in profilegpu

Change 3333857 on 2017/03/06 by Daniel.Wright

	[Copy] Clear light attenuation for local lights with a quad covering their screen extents
	* Clearing the entire light attenuation buffer costs .1ms on PS4.  This optimization lowers the minimum cost of a shadow casting light from .15ms -> .03ms.
	* Shadowed lights in Fortnite with 25 lights 3.7ms -> 1.42ms on PS4

Change 3333860 on 2017/03/06 by Daniel.Wright

	[Copy] Flush deferred deletes when reallocating distance field atlas to reduce peak memory

Change 3333861 on 2017/03/06 by Daniel.Wright

	[Copy] Disable all distance field features on Intel cards as HD 4000 hangs in the RHICreateTexture3D call to allocate the large atlas

Change 3333869 on 2017/03/06 by Daniel.Wright

	[Copy] Volumetric Fog using a volume texture mapped to the camera frustum
	* Volumetric fog can be enabled on an Exponential Height Fog component with additional controls
	* Lights have a VolumetricScatteringIntensity
	* New cvars r.VolumetricFog, r.VolumetricFog.GridPixelSize, r.VolumetricFog.GridSizeZ, r.VolumetricFog.DepthDistributionScale
	* Lighting features supported:
	   * Directional light with CSM and a light function
	   * Point / spot lights without shadows / light functions / IES profiles
	   * Skylight with occlusion from distance fields
	* Analytical height fog covers the view range past where the volumetric fog ends
	* Temporal reprojection is used on the volumetric fog scattering and extinction to achieve stability
	* Translucency integrates properly into volumetric fog
	* Height fog StartDistance is not supported by volumetric fog and should be set to 0.

Change 3333894 on 2017/03/06 by Daniel.Wright

	[Copy] Initialize GDummyVolumetricFogGlobalDataUniformBuffer outside of parallel rendering

Change 3333902 on 2017/03/06 by Daniel.Wright

	[Copy] Better handling of volumetric fog enabled with distance of 0

Change 3333903 on 2017/03/06 by Daniel.Wright

	[Copy] Fixed volumetric fog trying to render light functions for a point light

Change 3333908 on 2017/03/06 by Daniel.Wright

	[Copy] Volumetric materials
	* Added new material domain Volume, which can output Scattering, Absorption and Emissive.  All properties are in world space densities.
	* Particle systems using the Volume domain are voxelized based on their ParticlePosition and ParticleRadius
	* Volumetric fog integration is now energy conservative - scattering is integrated against transmission over the depth of each slice.
	* Added bOverrideLightColorsWithFogInscatteringColors to exponential height fog, which can be enabled to make Volumetric Fog match Height fog more closely

Change 3334134 on 2017/03/06 by Daniel.Wright

	[Copy from Michael Trepka] Added Embree 2.14.0 and changed MeshUtilities to use it as this solves issues with Embree leaking TLS keys. UnrealLightmass is still using older Embree 2.7.0 until we can find time to properly test it with the new version. Also, invalidated distance field DDC to force it to rebuild with updated Embree.

Change 3334420 on 2017/03/06 by Daniel.Wright

	Fixed RTDF shadows

Change 3335467 on 2017/03/07 by Benjamin.Hyder

	Initial submission of QA-Decals map to EngineTest

Change 3335556 on 2017/03/07 by Daniel.Wright

	Changed mesh distance field default format back to R16f

Change 3338020 on 2017/03/08 by Daniel.Wright

	Disable volumetric fog in vertex shaders for feature levels which don't support it

Change 3339394 on 2017/03/09 by Chris.Bunner

	Correctly handle material texture translation error edge case.

	#jira UE-42579, UE-42670

Change 3339992 on 2017/03/09 by Daniel.Wright

	Only compile volumetric fog shaders on supporting platforms

Change 3341858 on 2017/03/10 by Arne.Schober

	Copying //UE4/Dev-Rendering-PSO to Dev-Rendering (//UE4/Dev-Rendering)

	#RB Rolando.Caloca, Marcus.Wassmer, Daniel.Wright, Nick.Penwarden, Mark.Satterthwaite

Change 3342004 on 2017/03/10 by Arne.Schober

	Copying //UE4/Dev-Rendering-PSO to Dev-Rendering (//UE4/Dev-Rendering)
	Fix unity build

	#RB Marcus.Wassmer

Change 3343307 on 2017/03/13 by Marcus.Wassmer

	Update showflags when we are guaranteed it will happen in all possible ways to spawn the scenecapture. (drag into editor, PIE, -game, etc)

Change 3343732 on 2017/03/13 by Rolando.Caloca

	DR - Vulkan compute pipeline & refactor

Change 3344846 on 2017/03/14 by Rolando.Caloca

	DR - Android compile fixes

Change 3344883 on 2017/03/14 by Rolando.Caloca

	DR - Add missing stencil load/store to PSO initializer

Change 3344985 on 2017/03/14 by Rolando.Caloca

	DR - Made load/store actions uint8

Change 3345141 on 2017/03/14 by Rolando.Caloca

	DR - vk - Rework render pass hash

Change 3345304 on 2017/03/14 by Benjamin.Hyder

	Updating TM-Distancefields map to include TemplateFloor mesh

Change 3345387 on 2017/03/14 by Rolando.Caloca

	DR - Add _RenderThread calls for Create*Shader so RHIs can choose not to stall when creating

Change 3345388 on 2017/03/14 by Rolando.Caloca

	DR - Do not stall when creating shaders on Vulkan

Change 3345722 on 2017/03/14 by Chris.Bunner

	PR #3357: MinimalAPI add to many material expressions (Contributed by DeanoC)

	#jira UE-42752

Change 3345723 on 2017/03/14 by Chris.Bunner

	Reduce log verbosity causing spamming during  landscape editing.

	#jira UE-42714

Change 3345725 on 2017/03/14 by Chris.Bunner

	[Duplicate 3341860] Fixed material translation error with multiple connections from custom interpolator nodes.

Change 3345726 on 2017/03/14 by Chris.Bunner

	Typo fixes.

Change 3345732 on 2017/03/14 by Rolando.Caloca

	DR - Decouple vertex declaration off BSS

Change 3345746 on 2017/03/14 by Chris.Bunner

	Added sign() intrinsic material graph node and delisted material function workaround.

Change 3346042 on 2017/03/14 by Chris.Bunner

	Implement missing size query interface for FRenderTargetResources.

	#jira UE-41672

Change 3346387 on 2017/03/14 by Daniel.Wright

	[Copy] Added VolumetricScatteringIntensity to particle lights

Change 3346389 on 2017/03/14 by Daniel.Wright

	[Copy] Clamp Volumetric material attributes to fp16 range to avoid INFs
	Disable volumetric fog when the fog show flag is disabled

Change 3346392 on 2017/03/14 by Daniel.Wright

	[Copy] Fixed skylight being much too bright on volumetric fog

Change 3346406 on 2017/03/14 by Daniel.Wright

	[Copy] CSM resolution is now controlled by r.Shadow.MaxCSMResolution.
	* Changed HighPC to use 1024 MaxShadowResolution (max for all non-CSM shadows), saves 60Mb in Fortnite

Change 3346412 on 2017/03/14 by Daniel.Wright

	[Copy] TexCreate_ReduceMemoryWithTilingMode for translucency lighting 3d textures, saves 13Mb

Change 3346414 on 2017/03/14 by Daniel.Wright

	[Copy] TexCreate_ReduceMemoryWithTilingMode for volumetric fog 3d textures, saves 13Mb

Change 3346415 on 2017/03/14 by Daniel.Wright

	[Copy] Missing file from cl 3338451

Change 3346421 on 2017/03/14 by Daniel.Wright

	[Copy] Fixed NaNs in volumetric fog due to rendering when height fog is disabled
	* Volumetric fog converts NaNs to black now so they don't spread

Change 3346422 on 2017/03/14 by Daniel.Wright

	[Copy] Fixed NaN in volumetric fog with low density values

Change 3346423 on 2017/03/14 by Daniel.Wright

	[Copy] Changed default VolumetricFogScatteringDistribution to .2

Change 3346430 on 2017/03/14 by Daniel.Wright

	[Copy] New translucent material option to compute fog per pixel instead of the default per vertex

Change 3346432 on 2017/03/14 by Daniel.Wright

	[Copy] Moved Volumetric Fog parameters to view uniform buffer for translucency pass
	Fixed lifetimes of temporary Volumetric Fog render targets

Change 3346526 on 2017/03/14 by Daniel.Wright

	[Copy] Volumetric Fog supports point and spot light shadows
	* These lights are injected separately so that per-light resources can be bound (shadow depth map, static shadow depth map)
	* Forward lighting of local lights can be forced with 'r.VolumetricFog.InjectShadowedLightsSeparately 0'
	* Shadowed lights come at a cost: 2.9ms for volumetric fog on 970 -> 4.2ms with shadowing

Change 3347053 on 2017/03/15 by Rolando.Caloca

	DR - android compile fix

Change 3347384 on 2017/03/15 by Rolando.Caloca

	DR - Fix merge issue

Change 3347643 on 2017/03/15 by Marcus.Wassmer

	Fix some bugs with the 'disable stationary skylight ffor the project' feature.
	Fixes lighting in Persona on Paragon.

Change 3347979 on 2017/03/15 by Rolando.Caloca

	DR - Allow to automatically apply cached rendertargets to PSO initializer

Change 3348024 on 2017/03/15 by Rolando.Caloca

	DR - Remove NullPS on Vulkan to avoid deadlock

Change 3348303 on 2017/03/15 by Rolando.Caloca

	DR - Fix for debugging SCW with material SRT

Change 3348357 on 2017/03/15 by Marcus.Wassmer

	Fix stencildither and a stencilref bug that was probably breaking decals sometimes.

Change 3348549 on 2017/03/15 by Marcus.Wassmer

	Hopefully fix static analysis for potential nullptr access.

Change 3348614 on 2017/03/15 by Marcus.Wassmer

	Duplicate some switch changes to fix crash on launch.

Change 3349369 on 2017/03/16 by Gil.Gribb

	Fixed botched merge

Change 3349947 on 2017/03/16 by Rolando.Caloca

	DR - Fix for mismatched primitive type

Change 3349956 on 2017/03/16 by Benjamin.Hyder

	initial updates to TM-DistanceFields map

Change 3350151 on 2017/03/16 by Rolando.Caloca

	DR - Fix UT compile issue

Change 3350155 on 2017/03/16 by Rolando.Caloca

	DR - Catch mismatched primitive type on PSOs on D3D11

Change 3350192 on 2017/03/16 by Daniel.Wright

	Fix for point light shadow depths rendering with wrong cull mode due to PSO refactor

Change 3350736 on 2017/03/16 by Daniel.Wright

	Fixed formatting from merge

Change 3350881 on 2017/03/16 by Rolando.Caloca

	DR - Fix texture arrays as UAVs on Metal

Change 3350927 on 2017/03/16 by Rolando.Caloca

	DR - Fix warning

Change 3350935 on 2017/03/16 by Daniel.Wright

	Fix for materials with non-Surface domains being skipped in mesh passes

Change 3351583 on 2017/03/17 by Marcus.Wassmer

	Fix clang platforms

Change 3351917 on 2017/03/17 by Marcus.Wassmer

	Fix linux compile

Change 3351973 on 2017/03/17 by Marcus.Wassmer

	Fix mismatched rendertargetformat

Change 3352038 on 2017/03/17 by Daniel.Wright

	Enabled GetAndOrCreateGraphicsPipelineState ensures in Development for testing

Change 3352110 on 2017/03/17 by Marcus.Wassmer

	Fix missing RT PSO apply

Change 3352695 on 2017/03/17 by Arne.Schober

	DR - Remove PSO Rendertarget check in DX12 Resolve with Shader.
	#RB Rolando.Caloca

Change 3352960 on 2017/03/17 by Arne.Schober

	DR - Fix some things that slipped trough the PSO merge
	#RB none

Change 3353150 on 2017/03/18 by Rolando.Caloca

	DR - compile fix

Change 3353205 on 2017/03/18 by Arne.Schober

	DR - Fix Incremental Compile and PS4 runtime error where CMASK is not allowed for ThickTile Mode

	#RB none

Change 3353207 on 2017/03/18 by Arne.Schober

	DR - Fix Confusion

	#RB none

Change 3355183 on 2017/03/20 by Nick.Bullard

	Fixed up Content orginzation for Decals automation tests in EngineTest

Change 3355627 on 2017/03/20 by Arne.Schober

	DR - [UE-43094] - removed ensure in comporiton graph as control of the clear color cannot be gurantueed.

Change 3356342 on 2017/03/21 by Marcus.Wassmer

	Fix clang errors

Change 3356591 on 2017/03/21 by Arne.Schober

	DR - Fix ensure message
	#RB none

Change 3356873 on 2017/03/21 by Arne.Schober

	DR - Fix comparission of undefined values in RendertargetApply Check

Change 3357261 on 2017/03/21 by Marcus.Wassmer

	Fix LinuxEditor compile

Change 3357294 on 2017/03/21 by Marcus.Wassmer

	Add missing SSE functions

Change 3357351 on 2017/03/21 by Frank.Fella

	Fix win32 and linux compiler errors

Change 3357370 on 2017/03/21 by Arne.Schober

	DR - disable ensure in test builds

	#RB Marcus.Wassmer

[CL 3357449 by Marcus Wassmer in Main branch]
2017-03-21 17:46:52 -04:00

1214 lines
39 KiB
C++

// Copyright 1998-2016 Epic Games, Inc. All Rights Reserved.
#include "NiagaraComponentDetails.h"
#include "PropertyHandle.h"
#include "DetailLayoutBuilder.h"
#include "DetailCategoryBuilder.h"
#include "NiagaraComponent.h"
#include "NiagaraDataInterface.h"
#include "DetailWidgetRow.h"
#include "IDetailPropertyRow.h"
#include "Widgets/SToolTip.h"
#include "PropertyCustomizationHelpers.h"
#include "Widgets/Text/STextBlock.h"
#include "Widgets/Images/SImage.h"
#include "Widgets/Layout/SBox.h"
#include "EditorStyleSet.h"
#include "NiagaraEffectInstance.h"
#include "Private/ViewModels/NiagaraParameterViewModel.h"
#include "Private/NiagaraEditorUtilities.h"
#include "INiagaraEditorTypeUtilities.h"
#include "NiagaraTypes.h"
#include "ScopedTransaction.h"
#include "SNiagaraParameterEditor.h"
#include "NiagaraEditorModule.h"
#include "PropertyEditorModule.h"
#include "ModuleManager.h"
#include "IStructureDetailsView.h"
#include "IDetailsView.h"
#include "Widgets/Input/SButton.h"
#include "Widgets/Input/SEditableText.h"
#include "Editor.h"
#include "NiagaraParameterCollectionViewModel.h"
#include "NiagaraScriptSource.h"
#include "NiagaraNodeInput.h"
#include "NiagaraGraph.h"
#include "GameDelegates.h"
#define LOCTEXT_NAMESPACE "NiagaraComponentDetails"
class FNiagaraParameterViewModelCustomDetails : public FNiagaraParameterViewModel
{
public:
FNiagaraParameterViewModelCustomDetails(UNiagaraComponent* InComponent, const FNiagaraVariable& InSourceVariable, ENiagaraParameterEditMode ParameterEditMode) : FNiagaraParameterViewModel(ParameterEditMode)
{
Component = InComponent;
Id = InSourceVariable.GetId();
DefaultValueType = INiagaraParameterViewModel::EDefaultValueType::Struct;
SynchronizeWithSourceParameter();
RefreshParameterValue();
}
FNiagaraParameterViewModelCustomDetails(UNiagaraComponent* InComponent, const FGuid& InId, const FName& InName, UNiagaraDataInterface* InDataInterface, ENiagaraParameterEditMode ParameterEditMode) : FNiagaraParameterViewModel(ParameterEditMode)
{
Component = InComponent;
Id = InId;
DefaultValueType = INiagaraParameterViewModel::EDefaultValueType::Object;
ObjectValue.Id = InId;
ObjectValue.Name = InName;
// This needs to be in the component's package because otherwise we cannot select actors from the scene.
ObjectValue.DataInterface = Cast<UNiagaraDataInterface>(StaticDuplicateObject(InDataInterface, Component->GetOutermost(), NAME_None, RF_Transient));
Component->EditorTemporaries.Add(ObjectValue.DataInterface);
SynchronizeWithSourceDataInterface();
RefreshDataInterfaceValue();
}
~FNiagaraParameterViewModelCustomDetails()
{
Reset();
}
//~ INiagaraParameterViewModel interface
virtual FGuid GetId() const override
{
return Id;
};
virtual FName GetName() const
{
if (DefaultValueType == INiagaraParameterViewModel::EDefaultValueType::Struct)
{
const FNiagaraVariable* SrcVariable = GetSourceVariable();
return SrcVariable->GetName();
}
else
{
const FNiagaraScriptDataInterfaceInfo* SrcDataInterface = GetSourceDataInterface();
return SrcDataInterface->Name;
}
}
virtual bool CanRenameParameter() const override
{
return false;
}
virtual bool CanChangeSortOrder() const override
{
return false;
}
virtual int32 GetSortOrder() const override
{
if (Component ==nullptr || Component->GetAsset() == nullptr || Component->GetAsset()->GetEffectScript() == nullptr)
{
return 0;
}
UNiagaraScript* Script = Component->GetAsset()->GetEffectScript();
UNiagaraScriptSource* Source = Cast<UNiagaraScriptSource>(Script->Source);
if (Source == nullptr || Source->NodeGraph == nullptr)
{
return 0;
}
TArray<UNiagaraNodeInput*> InputNodes;
Source->NodeGraph->FindInputNodes(InputNodes);
if (InputNodes.Num() == 0)
{
return 0;
}
for (UNiagaraNodeInput* Input : InputNodes)
{
if (Input->Usage == ENiagaraInputNodeUsage::Parameter && Input->Input.GetId() == GetId())
{
return Input->CallSortPriority;
}
}
return 0;
}
virtual void SetSortOrder(int32 SortOrder) override
{
// do nothing
}
virtual FText GetNameText() const override
{
FName Name;
if (DefaultValueType == INiagaraParameterViewModel::EDefaultValueType::Struct)
{
const FNiagaraVariable* SrcVariable = GetSourceVariable();
Name = SrcVariable->GetName();
}
else
{
const FNiagaraScriptDataInterfaceInfo* SrcDataInterface = GetSourceDataInterface();
Name = SrcDataInterface->Name;
}
return FText::FromName(Name);
}
virtual bool CanChangeParameterType() const override
{
return false;
}
virtual void NameTextComitted(const FText& Name, ETextCommit::Type CommitInfo) override
{
/*do nothing*/
}
virtual bool VerifyNodeNameTextChanged(const FText& NewText, FText& OutErrorMessage)
{
/* do nothing*/
return true;
}
virtual FText GetTypeDisplayName() const override
{
if (DefaultValueType == INiagaraParameterViewModel::EDefaultValueType::Struct)
{
const FNiagaraVariable* SrcVariable = GetSourceVariable();
return SrcVariable->GetType().GetNameText();
}
else
{
const FNiagaraScriptDataInterfaceInfo* SrcDataInterface = GetSourceDataInterface();
FNiagaraTypeDefinition TypeDef(SrcDataInterface->DataInterface->GetClass());
return TypeDef.GetNameText();
}
}
virtual TSharedPtr<FNiagaraTypeDefinition> GetType() const override
{
if (DefaultValueType == INiagaraParameterViewModel::EDefaultValueType::Struct)
{
const FNiagaraVariable* SrcVariable = GetSourceVariable();
return MakeShareable(new FNiagaraTypeDefinition(SrcVariable->GetType()));
}
else
{
const FNiagaraScriptDataInterfaceInfo* SrcDataInterface = GetSourceDataInterface();
return MakeShareable(new FNiagaraTypeDefinition(SrcDataInterface->DataInterface->GetClass()));
}
}
virtual void SelectedTypeChanged(TSharedPtr<FNiagaraTypeDefinition> Item, ESelectInfo::Type SelectionType) override
{
/*do nothing*/
}
virtual EDefaultValueType GetDefaultValueType() override
{
return DefaultValueType;
}
virtual TSharedRef<FStructOnScope> GetDefaultValueStruct() override
{
check(DefaultValueType == INiagaraParameterViewModel::EDefaultValueType::Struct);
return ParameterValue.ToSharedRef();
}
virtual UObject* GetDefaultValueObject() override
{
check(DefaultValueType == INiagaraParameterViewModel::EDefaultValueType::Object);
return ObjectValue.DataInterface;
}
virtual void NotifyDefaultValuePropertyChanged(const FPropertyChangedEvent& PropertyChangedEvent) override
{
NotifyDefaultValueChanged();
//OnDefaultValueChangedDelegate.Broadcast(&GraphVariable);
}
virtual void NotifyBeginDefaultValueChange() override
{
GEditor->BeginTransaction(LOCTEXT("BeginEditParameterValue", "Edit parameter value"));
Component->Modify();
}
virtual void NotifyEndDefaultValueChange() override
{
if (GEditor->IsTransactionActive())
{
GEditor->EndTransaction();
}
}
bool DataMatches(const uint8* DataA, const uint8* DataB, int32 LengthA, int32 LengthB)
{
if (LengthA != LengthB)
{
return false;
}
for (int32 i = 0; i < LengthA; ++i)
{
if (DataA[i] != DataB[i])
{
return false;
}
}
return true;
}
virtual void NotifyDefaultValueChanged() override
{
if (DefaultValueType == INiagaraParameterViewModel::EDefaultValueType::Struct)
{
FNiagaraVariable* ExistingVar = GetExistingParameterOverride();
const FNiagaraVariable* SrcVariable = GetSourceVariable();
if (ParameterValue.IsValid() == false)
{
return;
}
// Get the size of the struct that we are referencing...
const UStruct* Struct = ParameterValue->GetStruct();
int32 StructSize = -1;
if (Struct)
{
StructSize = Struct->GetStructureSize();
}
// Now let's see if we need to update the value because it has changed...
if (SrcVariable != nullptr)
{
// Does the new value match exactly the source variable's value?
bool bDataMatchesSrc = DataMatches(SrcVariable->GetData(), ParameterValue->GetStructMemory(), SrcVariable->GetSizeInBytes(), StructSize);
// Does the new value match exactly the override variable's value?
bool bDataMatchesOverride = ExistingVar != nullptr ? DataMatches(ExistingVar->GetData(), ParameterValue->GetStructMemory(), ExistingVar->GetSizeInBytes(), StructSize) : false;
// If we have an override, use whether or not it matches the current override value to determine if we set the variable.
bool bUpdateValue = true;
if (ExistingVar != nullptr && bDataMatchesOverride)
{
bUpdateValue = false;
}
// If we don't have an override, use whether or not it matches the source variable's value to determine if we set the variable.
else if (ExistingVar == nullptr && bDataMatchesSrc)
{
bUpdateValue = false;
}
// Actually transact the change if needed...
if (bUpdateValue)
{
FScopedTransaction ScopedTransaction(LOCTEXT("EditParameterValue", "Edit parameter value"));
Component->Modify();
FNiagaraVariable* CopyOnWriteVariable = CopyOnWriteParameter();
if (CopyOnWriteVariable != nullptr)
{
CopyOnWriteVariable->SetData(ParameterValue->GetStructMemory());
}
}
}
}
else
{
FNiagaraScriptDataInterfaceInfo* ExistingDataInterface = GetExistingDataInterfaceOverride();
const FNiagaraScriptDataInterfaceInfo* SrcDataInterface = GetSourceDataInterface();
if (ObjectValue.DataInterface == nullptr)
{
return;
}
// Now let's see if we need to update the value because it has changed...
if ( SrcDataInterface != nullptr)
{
// Does the new value match exactly the source variable's value?
bool bDataMatchesSrc = SrcDataInterface->DataInterface->Equals(ObjectValue.DataInterface);
// Does the new value match exactly the override variable's value?
bool bDataMatchesOverride = ExistingDataInterface != nullptr ? ExistingDataInterface->DataInterface->Equals(ObjectValue.DataInterface) : false;
// If we have an override, use whether or not it matches the current override value to determine if we set the variable.
bool bUpdateValue = true;
if (ExistingDataInterface != nullptr && bDataMatchesOverride)
{
bUpdateValue = false;
}
// If we don't have an override, use whether or not it matches the source variable's value to determine if we set the variable.
else if (SrcDataInterface == nullptr && bDataMatchesSrc)
{
bUpdateValue = false;
}
// Actually transact the change if needed...
if (bUpdateValue)
{
FScopedTransaction ScopedTransaction(LOCTEXT("EditParameterValue", "Edit parameter value"));
Component->Modify();
FNiagaraScriptDataInterfaceInfo* CopyOnWriteVariable = CopyOnWriteDataInterface();
if (CopyOnWriteVariable != nullptr)
{
ensure(ObjectValue.DataInterface->CopyTo(CopyOnWriteVariable->DataInterface));
// Once we've changed a data interface, it may be wired to multiple
// simulations. For instance, the mesh for mesh emission might affect
// three different simulations. We need to reinitialize the data interfaces
// as a result.
Component->GetEffectInstance()->ReinitializeDataInterfaces();
}
}
}
}
}
void RefreshParameterValue()
{
check(DefaultValueType == INiagaraParameterViewModel::EDefaultValueType::Struct);
// If the compiled variable is null or the type of the graph variable has been changed,
// then we edit the value in the graph variable so that the value is of the correct type and can be edited.
const FNiagaraVariable* SrcVariable = GetSourceVariable();
const FNiagaraVariable* CurrentOverride = GetExistingParameterOverride();
const FNiagaraVariable* ValueVariable = CurrentOverride != nullptr ? CurrentOverride : SrcVariable;
if (ValueVariable == nullptr)
{
UE_LOG(LogNiagaraEditor, Warning, TEXT("Parameter doesn't exist!"));
return;
}
if (ParameterValue.IsValid() == false)
{
ParameterValue = MakeShareable(new FStructOnScope(ValueVariable->GetType().GetStruct()));
}
const UStruct* Struct = ParameterValue->GetStruct();
int32 StructSize = -1;
if (Struct)
{
StructSize = Struct->GetStructureSize();
}
if (ValueVariable->IsDataAllocated() && ValueVariable->GetSizeInBytes() == StructSize)
{
ValueVariable->CopyTo(ParameterValue->GetStructMemory());
if (ParameterEditor.IsValid())
{
ParameterEditor->UpdateInternalValueFromStruct(ParameterValue.ToSharedRef());
}
}
else
{
UE_LOG(LogNiagaraEditor, Warning, TEXT("Parameter %s is not allocated or sizes mismatch!"), *ValueVariable->GetName().ToString());
}
}
void RefreshDataInterfaceValue()
{
check(DefaultValueType == INiagaraParameterViewModel::EDefaultValueType::Object);
// If the compiled variable is null or the type of the graph variable has been changed,
// then we edit the value in the graph variable so that the value is of the correct type and can be edited.
const FNiagaraScriptDataInterfaceInfo* SrcVariable = GetSourceDataInterface();
const FNiagaraScriptDataInterfaceInfo* CurrentOverride = GetExistingDataInterfaceOverride();
const FNiagaraScriptDataInterfaceInfo* ValueVariable = CurrentOverride != nullptr ? CurrentOverride : SrcVariable;
if (ValueVariable == nullptr)
{
UE_LOG(LogNiagaraEditor, Warning, TEXT("Data interface doesn't exist!"));
return;
}
check(ObjectValue.DataInterface != nullptr);
if (ValueVariable)
{
check(ValueVariable->DataInterface->GetClass() == ObjectValue.DataInterface->GetClass());
ensure(ValueVariable->DataInterface->CopyTo(ObjectValue.DataInterface));
if (DetailsView.IsValid())
{
DetailsView->SetObject(ObjectValue.DataInterface);
}
}
else
{
UE_LOG(LogNiagaraEditor, Warning, TEXT("Data interface %s does not exist!"), *ValueVariable->Name.ToString());
}
}
FNiagaraVariable* CopyOnWriteParameter()
{
check(DefaultValueType == INiagaraParameterViewModel::EDefaultValueType::Struct);
const FNiagaraVariable* SrcVariable = GetSourceVariable();
FNiagaraVariable* ExistingVar = GetExistingParameterOverride();
if (ExistingVar == nullptr && SrcVariable != nullptr)
{
int32 AddIndex = Component->EffectParameterLocalOverrides.Add(*SrcVariable);
ExistingVar = &Component->EffectParameterLocalOverrides[AddIndex];
TSharedRef<FNiagaraEffectInstance> Instance = Component->GetEffectInstance();
Instance->InvalidateComponentBindings();
}
if (ExistingVar != nullptr && ExistingVar->GetType() != SrcVariable->GetType())
{
ExistingVar->SetType(SrcVariable->GetType());
}
if (ExistingVar != nullptr && ExistingVar->GetName() != SrcVariable->GetName())
{
ExistingVar->SetName(SrcVariable->GetName());
}
return ExistingVar;
}
FNiagaraScriptDataInterfaceInfo* CopyOnWriteDataInterface()
{
check(DefaultValueType == INiagaraParameterViewModel::EDefaultValueType::Object);
bool bInvalidate = false;
const FNiagaraScriptDataInterfaceInfo* SrcVariable = GetSourceDataInterface();
FNiagaraScriptDataInterfaceInfo* ExistingVar = GetExistingDataInterfaceOverride();
if (ExistingVar == nullptr && SrcVariable != nullptr)
{
int32 AddIndex = Component->EffectDataInterfaceLocalOverrides.AddDefaulted();
ExistingVar = &Component->EffectDataInterfaceLocalOverrides[AddIndex];
SrcVariable->CopyTo(ExistingVar, Component);
bInvalidate = true;
}
if (ExistingVar != nullptr && ExistingVar->DataInterface->GetClass() != SrcVariable->DataInterface->GetClass())
{
SrcVariable->CopyTo(ExistingVar, Component);
}
if (ExistingVar != nullptr && ExistingVar->Name != SrcVariable->Name)
{
ExistingVar->Name = SrcVariable->Name;
}
if (bInvalidate)
{
TSharedRef<FNiagaraEffectInstance> Instance = Component->GetEffectInstance();
Instance->InvalidateComponentBindings();
}
return ExistingVar;
}
FNiagaraVariable* GetExistingParameterOverride() const
{
check(DefaultValueType == INiagaraParameterViewModel::EDefaultValueType::Struct);
const FNiagaraVariable* SrcVariable = GetSourceVariable();
if (SrcVariable == nullptr)
{
return nullptr;
}
return Component->EffectParameterLocalOverrides.FindByPredicate([&](const FNiagaraVariable& Var)
{
return Var.GetId() == SrcVariable->GetId();
});
}
FNiagaraScriptDataInterfaceInfo* GetExistingDataInterfaceOverride() const
{
check(DefaultValueType == INiagaraParameterViewModel::EDefaultValueType::Object);
const FNiagaraScriptDataInterfaceInfo* SrcVariable = GetSourceDataInterface();
if (SrcVariable == nullptr)
{
return nullptr;
}
return Component->EffectDataInterfaceLocalOverrides.FindByPredicate([&](const FNiagaraScriptDataInterfaceInfo& Var)
{
return Var.Id == SrcVariable->Id;
});
}
void SynchronizeWithSourceParameter()
{
check(DefaultValueType == INiagaraParameterViewModel::EDefaultValueType::Struct);
const FNiagaraVariable* SrcVariable = GetSourceVariable();
FNiagaraVariable* ExistingVar = GetExistingParameterOverride();
if (ExistingVar != nullptr && ExistingVar->GetType() != SrcVariable->GetType())
{
ExistingVar->SetType(SrcVariable->GetType());
}
if (ExistingVar != nullptr && ExistingVar->GetName() != SrcVariable->GetName())
{
ExistingVar->SetName(SrcVariable->GetName());
}
}
void SynchronizeWithSourceDataInterface()
{
check(DefaultValueType == INiagaraParameterViewModel::EDefaultValueType::Object);
const FNiagaraScriptDataInterfaceInfo* SrcVariable = GetSourceDataInterface();
FNiagaraScriptDataInterfaceInfo* ExistingVar = GetExistingDataInterfaceOverride();
if (ExistingVar != nullptr && ExistingVar->DataInterface->GetClass() != SrcVariable->DataInterface->GetClass())
{
SrcVariable->CopyTo(ExistingVar, Component);
}
if (ExistingVar != nullptr && ExistingVar->Name != SrcVariable->Name)
{
ExistingVar->Name = SrcVariable->Name;
}
}
bool IsOverriddenLocally() const
{
if (DefaultValueType == INiagaraParameterViewModel::EDefaultValueType::Struct)
{
return GetExistingParameterOverride() != nullptr;
}
else
{
return GetExistingDataInterfaceOverride() != nullptr;
}
}
void ResetToDefaults()
{
if (DefaultValueType == INiagaraParameterViewModel::EDefaultValueType::Struct)
{
const FNiagaraVariable* SrcVariable = GetSourceVariable();
if (SrcVariable == nullptr)
{
return;
}
int32 OverrideIndex = Component->EffectParameterLocalOverrides.IndexOfByPredicate([&](const FNiagaraVariable& Var)
{
return Var.GetId() == SrcVariable->GetId();
});
if (OverrideIndex >= 0)
{
FScopedTransaction ScopedTransaction(LOCTEXT("ResetParameterValue", "Reset parameter value to defaults."));
Component->Modify();
Component->EffectParameterLocalOverrides.RemoveAt(OverrideIndex);
TSharedRef<FNiagaraEffectInstance> Instance = Component->GetEffectInstance();
Instance->InvalidateComponentBindings();
RefreshParameterValue();
}
}
else
{
const FNiagaraScriptDataInterfaceInfo* SrcVariable = GetSourceDataInterface();
if (SrcVariable == nullptr)
{
return;
}
int32 OverrideIndex = Component->EffectDataInterfaceLocalOverrides.IndexOfByPredicate([&](const FNiagaraScriptDataInterfaceInfo& Var)
{
return Var.Id == SrcVariable->Id;
});
if (OverrideIndex >= 0)
{
FScopedTransaction ScopedTransaction(LOCTEXT("ResetParameterValue", "Reset parameter value to defaults."));
Component->Modify();
Component->EffectDataInterfaceLocalOverrides.RemoveAt(OverrideIndex);
TSharedRef<FNiagaraEffectInstance> Instance = Component->GetEffectInstance();
Instance->InvalidateComponentBindings();
RefreshDataInterfaceValue();
}
}
}
void SetParameterEditor(TSharedPtr<SNiagaraParameterEditor>& InParameterEditor)
{
ParameterEditor = InParameterEditor;
}
void SetDataInterfaceEditor (TSharedPtr<IDetailsView>& InDetailsView)
{
DetailsView = InDetailsView;
}
void Reset()
{
if (Component)
{
Component->EditorTemporaries.Remove(ObjectValue.DataInterface);
}
Component = nullptr;
Id.Invalidate();
ParameterEditor = nullptr;
ParameterValue = nullptr;
ObjectValue.DataInterface = nullptr;
ObjectValue.Id.Invalidate();
ObjectValue.Name = NAME_None;
if (DetailsView.IsValid())
{
DetailsView->SetObject(nullptr);
DetailsView = nullptr;
}
}
const FNiagaraVariable* GetSourceVariable() const
{
if (Component != nullptr)
{
UNiagaraEffect* Effect = Component->GetAsset();
const FNiagaraParameters& Params = Effect->GetEffectScript()->Parameters;
const FNiagaraVariable* SrcVariable = Params.FindParameter(Id);
return SrcVariable;
}
return nullptr;
}
const FNiagaraScriptDataInterfaceInfo* GetSourceDataInterface() const
{
if (Component != nullptr)
{
UNiagaraEffect* Effect = Component->GetAsset();
const TArray<FNiagaraScriptDataInterfaceInfo>& Params = Effect->GetEffectScript()->DataInterfaceInfo;
const FNiagaraScriptDataInterfaceInfo* SrcVariable = Params.FindByPredicate([&](const FNiagaraScriptDataInterfaceInfo& Var)
{
return Var.Id == Id;
});
return SrcVariable;
}
return nullptr;
}
//~ FNotifyHook interface
virtual void NotifyPostChange(const FPropertyChangedEvent& PropertyChangedEvent, UProperty* PropertyThatChanged)
{
NotifyDefaultValuePropertyChanged(PropertyChangedEvent);
}
protected:
UNiagaraComponent* Component;
FGuid Id;
EDefaultValueType DefaultValueType;
TSharedPtr<FStructOnScope> ParameterValue;
FNiagaraScriptDataInterfaceInfo ObjectValue;
TSharedPtr<SNiagaraParameterEditor> ParameterEditor;
TSharedPtr<IDetailsView> DetailsView;
};
TSharedRef<IDetailCustomization> FNiagaraComponentDetails::MakeInstance()
{
return MakeShareable(new FNiagaraComponentDetails);
}
FNiagaraComponentDetails::FNiagaraComponentDetails() : Builder(nullptr), bQueueForDetailsRefresh(false)
{
GEditor->RegisterForUndo(this);
}
FNiagaraComponentDetails::~FNiagaraComponentDetails()
{
GEditor->UnregisterForUndo(this);
if (GEngine)
{
GEngine->OnWorldDestroyed().RemoveAll(this);
}
FGameDelegates::Get().GetEndPlayMapDelegate().RemoveAll(this);
if (ObjectsCustomized.Num() == 1)
{
UNiagaraComponent* Component = Cast<UNiagaraComponent>(ObjectsCustomized[0].Get());
if (Component)
{
TSharedRef<FNiagaraEffectInstance> EffectInstance = Component->GetEffectInstance();
if (OnResetDelegateHandle.IsValid())
{
EffectInstance->OnReset().Remove(OnResetDelegateHandle);
}
if (OnInitDelegateHandle.IsValid())
{
EffectInstance->OnInitialized().Remove(OnInitDelegateHandle);
}
EffectInstance->OnDestroyed().RemoveAll(this);
}
}
}
bool FNiagaraComponentDetails::IsTickable() const
{
return bQueueForDetailsRefresh;
}
void FNiagaraComponentDetails::Tick(float DeltaTime)
{
if (bQueueForDetailsRefresh)
{
if (Builder)
{
Builder->ForceRefreshDetails();
bQueueForDetailsRefresh = false;
}
}
}
void FNiagaraComponentDetails::PostUndo(bool bSuccess)
{
// We may have queued up as a result of an Undo of adding the effect itself. The objects we were
// referencing may therefore have been removed. If so, we'll have to take a different path later on in the code.
int32 NumValid = 0;
for (TWeakObjectPtr<UObject> WeakPtr : ObjectsCustomized)
{
if (!WeakPtr.IsStale(true) && WeakPtr.IsValid())
{
NumValid++;
}
}
if (Builder)
{
// This is tricky. There is a high chance that if the component changed, then
// any cached FNiagaraVariable that we're holding on to may have been changed out from underneath us.
// So we essentially must tear down and start again in the UI.
// HOWEVER, a refresh will invoke a new constructor of the FNiagaraComponentDetails, which puts us
// in the queue to handle PostUndo events. This turns quickly into an infinitely loop. Therefore,
// we circumvent this by telling the editor that we need to queue up an event
// that we will handle in the subsequent frame's Tick event. Not the cleanest approach,
// but because we are doing things like CopyOnWrite, the normal Unreal property editing
// path is not available to us.
if (NumValid != 0)
{
bQueueForDetailsRefresh = true;
}
else
{
// If we no longer have any valid pointers, but previously had a builder, that means
// that the builder is probably dead or dying soon. We shouldn't trust it any more and
// we should make sure that we aren't queueing for ticks to refresh either.
Builder = nullptr;
bQueueForDetailsRefresh = false;
}
for (TSharedPtr<FNiagaraParameterViewModelCustomDetails>& ViewModel : ViewModels)
{
ViewModel->Reset();
}
}
}
TStatId FNiagaraComponentDetails::GetStatId() const
{
RETURN_QUICK_DECLARE_CYCLE_STAT(FNiagaraComponentDetails, STATGROUP_Tickables);
}
//~ FNotifyHook interface
void FNiagaraComponentDetails::NotifyPostChange(const FPropertyChangedEvent& PropertyChangedEvent, UProperty* PropertyThatChanged)
{
for (TSharedPtr<FNiagaraParameterViewModelCustomDetails> Parameter : ViewModels)
{
if (Parameter->GetDefaultValueType() == INiagaraParameterViewModel::EDefaultValueType::Object)
{
UObject* ParameterObject = Parameter->GetDefaultValueObject();
const UObject* ChangedObject = PropertyChangedEvent.GetObjectBeingEdited(0);
const UObject* CurrentObject = ChangedObject;
bool ParameterIsInObjectChain = false;
while (ParameterIsInObjectChain == false && CurrentObject != nullptr)
{
if (ParameterObject == CurrentObject)
{
ParameterIsInObjectChain = true;
}
else
{
CurrentObject = CurrentObject->GetOuter();
}
}
if (ParameterIsInObjectChain)
{
Parameter->NotifyPostChange(PropertyChangedEvent, PropertyThatChanged);
}
}
}
}
void FNiagaraComponentDetails::OnPiEEnd()
{
UE_LOG(LogNiagaraEditor, Log, TEXT("onPieEnd"));
if (ObjectsCustomized.Num() == 1)
{
UNiagaraComponent* Component = Cast<UNiagaraComponent>(ObjectsCustomized[0].Get());
if (Component)
{
if (Component->GetOutermost()->HasAnyPackageFlags(PKG_PlayInEditor))
{
UE_LOG(LogNiagaraEditor, Log, TEXT("onPieEnd - has package flags"));
UWorld* TheWorld = UWorld::FindWorldInPackage(Component->GetOutermost());
if (TheWorld)
{
OnWorldDestroyed(TheWorld);
}
}
}
}
}
void FNiagaraComponentDetails::OnWorldDestroyed(class UWorld* InWorld)
{
// We have to clear out any temp data interfaces that were bound to the component's package when the world goes away or otherwise
// we'll report GC leaks..
if (ObjectsCustomized.Num() == 1)
{
UNiagaraComponent* Component = Cast<UNiagaraComponent>(ObjectsCustomized[0].Get());
if (Component)
{
if (Component->GetWorld() == InWorld)
{
UE_LOG(LogNiagaraEditor, Log, TEXT("OnWorldDestroyed - matched up"));
ViewModels.Empty();
Builder = nullptr;
}
}
}
}
void FNiagaraComponentDetails::CustomizeDetails(IDetailLayoutBuilder& DetailBuilder)
{
Builder = &DetailBuilder;
// Create a category so this is displayed early in the properties
IDetailCategoryBuilder& NiagaraCategory = DetailBuilder.EditCategory("Niagara", FText::GetEmpty(), ECategoryPriority::Important);
// Store off the properties for analysis in later function calls.
LocalOverridesPropertyHandle = DetailBuilder.GetProperty(GET_MEMBER_NAME_CHECKED(UNiagaraComponent, EffectParameterLocalOverrides));
if (LocalOverridesPropertyHandle.IsValid())
{
LocalOverridesPropertyHandle->MarkHiddenByCustomization();
}
LocalDataInterfaceOverridesPropertyHandle = DetailBuilder.GetProperty(GET_MEMBER_NAME_CHECKED(UNiagaraComponent, EffectDataInterfaceLocalOverrides));
if (LocalDataInterfaceOverridesPropertyHandle.IsValid())
{
LocalDataInterfaceOverridesPropertyHandle->MarkHiddenByCustomization();
}
TSharedPtr<IPropertyHandle> AssetPropertyHandle = DetailBuilder.GetProperty(FName("Asset"));
if (AssetPropertyHandle.IsValid())
{
IDetailPropertyRow& AssetRow = NiagaraCategory.AddProperty(AssetPropertyHandle, EPropertyLocation::Default);
}
// Store off the objects that we are editing for analysis in later function calls.
DetailBuilder.GetObjectsBeingCustomized(ObjectsCustomized);
if (ObjectsCustomized.Num() == 1)
{
UNiagaraComponent* Component = Cast<UNiagaraComponent>(ObjectsCustomized[0].Get());
if (Component == nullptr)
{
return;
}
if (GEngine)
{
GEngine->OnWorldDestroyed().AddRaw(this, &FNiagaraComponentDetails::OnWorldDestroyed);
}
FGameDelegates::Get().GetEndPlayMapDelegate().AddRaw(this, &FNiagaraComponentDetails::OnPiEEnd);
TSharedRef<FNiagaraEffectInstance> EffectInstance = Component->GetEffectInstance();
ViewModels.Empty();
UNiagaraEffect* Effect = Component->GetAsset();
if (Effect == nullptr || Component->IsPendingKillOrUnreachable())
{
return;
}
// We'll want to monitor for any serious changes that might require a rebuild of the UI from scratch.
UE_LOG(LogNiagaraEditor, Log, TEXT("Registering with effect instance %p"), &EffectInstance.Get());
EffectInstance->OnReset().RemoveAll(this);
EffectInstance->OnInitialized().RemoveAll(this);
EffectInstance->OnDestroyed().RemoveAll(this);
OnResetDelegateHandle = EffectInstance->OnReset().AddSP(this, &FNiagaraComponentDetails::OnEffectInstanceReset);
OnInitDelegateHandle = EffectInstance->OnInitialized().AddSP(this, &FNiagaraComponentDetails::OnEffectInstanceReset);
EffectInstance->OnDestroyed().AddSP(this, &FNiagaraComponentDetails::OnEffectInstanceDestroyed);
TArray<TSharedRef<INiagaraParameterViewModel>> SortedViewModels;
for (const FNiagaraVariable& Variable :Effect->GetEffectScript()->Parameters.Parameters)
{
TSharedPtr<FNiagaraParameterViewModelCustomDetails> ViewModel = MakeShareable(new FNiagaraParameterViewModelCustomDetails(Component, Variable, ENiagaraParameterEditMode::EditValueOnly));
TSharedRef<INiagaraParameterViewModel> ViewModelRef = ViewModel.ToSharedRef();
SortedViewModels.Add(ViewModelRef);
}
for (const FNiagaraScriptDataInterfaceInfo& Info : Effect->GetEffectScript()->DataInterfaceInfo)
{
TSharedPtr<FNiagaraParameterViewModelCustomDetails> ViewModel = MakeShareable(new FNiagaraParameterViewModelCustomDetails(Component, Info.Id, Info.Name, Info.DataInterface, ENiagaraParameterEditMode::EditValueOnly));
TSharedRef<INiagaraParameterViewModel> ViewModelRef = ViewModel.ToSharedRef();
SortedViewModels.Add(ViewModelRef);
}
INiagaraParameterCollectionViewModel::SortViewModels(SortedViewModels);
// Go through each instance variable and add new GUI for it.
for (int32 i = 0; i < SortedViewModels.Num(); i++)
{
TSharedPtr<INiagaraParameterViewModel> BaseViewModel = SortedViewModels[i];
TSharedPtr<FNiagaraParameterViewModelCustomDetails> ViewModel = StaticCastSharedPtr<FNiagaraParameterViewModelCustomDetails>(BaseViewModel);
UE_LOG(LogNiagaraEditor, Log, TEXT("Param '%s' [%d]"), *ViewModel->GetName().ToString(), ViewModel->GetSortOrder());
bool bIsDataInterface = ViewModel->GetSourceDataInterface() != nullptr;
bool bIsParameter = ViewModel->GetSourceVariable() != nullptr;
if (bIsParameter)
{
TSharedPtr<SNiagaraParameterEditor> ParameterEditor;
TSharedPtr<SWidget> DetailsWidget;
if (ViewModel->GetDefaultValueType() == INiagaraParameterViewModel::EDefaultValueType::Struct)
{
FNiagaraEditorModule& NiagaraEditorModule = FModuleManager::GetModuleChecked<FNiagaraEditorModule>("NiagaraEditor");
TSharedPtr<INiagaraEditorTypeUtilities> TypeEditorUtilities = NiagaraEditorModule.GetTypeUtilities(*ViewModel->GetType().Get());
if (TypeEditorUtilities.IsValid() && TypeEditorUtilities->CanCreateParameterEditor())
{
ParameterEditor = TypeEditorUtilities->CreateParameterEditor();
ParameterEditor->UpdateInternalValueFromStruct(ViewModel->GetDefaultValueStruct());
ParameterEditor->SetOnBeginValueChange(SNiagaraParameterEditor::FOnValueChange::CreateSP(
this, &FNiagaraComponentDetails::ParameterEditorBeginValueChange, ViewModel.ToSharedRef()));
ParameterEditor->SetOnEndValueChange(SNiagaraParameterEditor::FOnValueChange::CreateSP(
this, &FNiagaraComponentDetails::ParameterEditorEndValueChange, ViewModel.ToSharedRef()));
ParameterEditor->SetOnValueChanged(SNiagaraParameterEditor::FOnValueChange::CreateSP(
this, &FNiagaraComponentDetails::ParameterEditorValueChanged, ParameterEditor.ToSharedRef(), ViewModel.ToSharedRef()));
ViewModel->SetParameterEditor(ParameterEditor);
DetailsWidget = ParameterEditor;
}
else
{
UE_LOG(LogNiagaraEditor, Warning, TEXT("Cannot create editor for type: %s"), *ViewModel->GetTypeDisplayName().ToString());
}
}
else if (ViewModel->GetDefaultValueType() == INiagaraParameterViewModel::EDefaultValueType::Object)
{
UE_LOG(LogNiagaraEditor, Warning, TEXT("Unsupported type for component editing: %s"), *ViewModel->GetTypeDisplayName().ToString());
}
else
{
UE_LOG(LogNiagaraEditor, Warning, TEXT("Unsupported type for component editing: %s"), *ViewModel->GetTypeDisplayName().ToString());
}
if (DetailsWidget.IsValid())
{
ViewModels.Add(ViewModel);
FDetailWidgetRow& OverrideRow = NiagaraCategory.AddCustomRow(FText::FromName(ViewModel->GetName()));
OverrideRow.NameContent()
.MinDesiredWidth(0)
.MaxDesiredWidth(0)
[
SNew(STextBlock)
.Text(FText::FromName(ViewModel->GetName()))
.Font(IDetailLayoutBuilder::GetDetailFont())
];
OverrideRow.ValueContent()
.MinDesiredWidth(375.0f)
.MaxDesiredWidth(375.0f)
//.HAlign(HAlign_Fill)
[
SNew(SHorizontalBox)
+ SHorizontalBox::Slot()
.HAlign(HAlign_Fill)
.Padding(4.0f)
[
// Add in the parameter editor factoried above.
DetailsWidget.ToSharedRef()
]
+ SHorizontalBox::Slot()
.VAlign(VAlign_Center)
.AutoWidth()
[
// Add in the "reset to default" buttons
SNew(SButton)
.OnClicked(this, &FNiagaraComponentDetails::OnLocationResetClicked, ViewModel.ToSharedRef())
.Visibility(this, &FNiagaraComponentDetails::GetLocationResetVisibility, ViewModel.ToSharedRef())
.ContentPadding(FMargin(5.f, 0.f))
.ToolTipText(LOCTEXT("ResetToDefaultToolTip", "Reset to Default"))
.ButtonStyle(FEditorStyle::Get(), "NoBorder")
.Content()
[
SNew(SImage)
.Image(FEditorStyle::GetBrush("PropertyWindow.DiffersFromDefault"))
]
]
];
}
}
else if (bIsDataInterface)
{
FPropertyEditorModule& PropertyEditorModule = FModuleManager::GetModuleChecked<FPropertyEditorModule>("PropertyEditor");
FDetailsViewArgs Args(false, false, false, FDetailsViewArgs::HideNameArea, true, this);
TSharedRef<IDetailsView> DetailsView = PropertyEditorModule.CreateDetailView(Args);
TSharedPtr<IDetailsView> SetDetailsView = DetailsView;
ViewModel->SetDataInterfaceEditor(SetDetailsView);
DetailsView->SetObject(ViewModel->GetDefaultValueObject());
ViewModels.Add(ViewModel);
TSharedPtr<SWidget> DetailsWidget;
DetailsWidget = DetailsView;
FDetailWidgetRow& OverrideRow = NiagaraCategory.AddCustomRow(FText::FromName(ViewModel->GetName()));
OverrideRow.NameContent()
.MinDesiredWidth(0)
.MaxDesiredWidth(0)
[
SNew(STextBlock)
.Text(FText::FromName(ViewModel->GetName()))
.Font(IDetailLayoutBuilder::GetDetailFont())
];
OverrideRow.ValueContent()
.MinDesiredWidth(375.0f)
.MaxDesiredWidth(375.0f)
//.HAlign(HAlign_Fill)
[
SNew(SHorizontalBox)
+ SHorizontalBox::Slot()
.HAlign(HAlign_Fill)
.Padding(4.0f)
[
// Add in the parameter editor factoried above.
DetailsWidget.ToSharedRef()
]
+ SHorizontalBox::Slot()
.VAlign(VAlign_Center)
.AutoWidth()
[
// Add in the "reset to default" buttons
SNew(SButton)
.OnClicked(this, &FNiagaraComponentDetails::OnLocationResetClicked, ViewModel.ToSharedRef())
.Visibility(this, &FNiagaraComponentDetails::GetLocationResetVisibility, ViewModel.ToSharedRef())
.ContentPadding(FMargin(5.f, 0.f))
.ToolTipText(LOCTEXT("ResetToDefaultToolTip", "Reset to Default"))
.ButtonStyle(FEditorStyle::Get(), "NoBorder")
.Content()
[
SNew(SImage)
.Image(FEditorStyle::GetBrush("PropertyWindow.DiffersFromDefault"))
]
]
];
}
}
// Let the user know that there is nothing to tweak if there are no editable parameters!
if (ViewModels.Num() == 0)
{
FText WarningText = LOCTEXT("NiagaraNoExposedParams", "This effect has no supported exposed parameters.\nPlease add them in the Niagara Effect Editor's Effect Script Tab.");
FDetailWidgetRow& OverrideRow = NiagaraCategory.AddCustomRow(WarningText)
.WholeRowContent()
.VAlign(VAlign_Center)
.HAlign(HAlign_Center)
[
SNew(SHorizontalBox)
+ SHorizontalBox::Slot()
.VAlign(VAlign_Center)
.HAlign(HAlign_Center)
.Padding(4.0f, 0.0f, 0.0f, 0.0f)
[
SNew(STextBlock)
.Text(WarningText)
.Font(IDetailLayoutBuilder::GetDetailFont())
]
];
}
}
else
{
FText WarningText = LOCTEXT("NiagaraMultiSelectWarning", "Multiple selection currently unsupported.");
FDetailWidgetRow& OverrideRow = NiagaraCategory.AddCustomRow(WarningText)
.WholeRowContent()
.VAlign(VAlign_Center)
.HAlign(HAlign_Center)
[
SNew(SHorizontalBox)
+ SHorizontalBox::Slot()
.VAlign(VAlign_Center)
.HAlign(HAlign_Center)
.Padding(4.0f, 0.0f, 0.0f, 0.0f)
[
SNew(STextBlock)
.Text(WarningText)
.Font(IDetailLayoutBuilder::GetDetailFont())
]
];
}
}
void FNiagaraComponentDetails::OnEffectInstanceReset()
{
UE_LOG(LogNiagaraEditor, Log, TEXT("OnEffectInstanceReset()"));
bQueueForDetailsRefresh = true;
for (TSharedPtr<FNiagaraParameterViewModelCustomDetails>& ViewModel : ViewModels)
{
ViewModel->Reset();
}
}
void FNiagaraComponentDetails::OnEffectInstanceDestroyed()
{
UE_LOG(LogNiagaraEditor, Log, TEXT("OnEffectInstanceDestroyed()"));
bQueueForDetailsRefresh = true;
for (TSharedPtr<FNiagaraParameterViewModelCustomDetails>& ViewModel : ViewModels)
{
ViewModel->Reset();
}
ViewModels.Empty();
}
void FNiagaraComponentDetails::ParameterEditorBeginValueChange(TSharedRef<FNiagaraParameterViewModelCustomDetails> Item)
{
Item->NotifyBeginDefaultValueChange();
}
void FNiagaraComponentDetails::ParameterEditorEndValueChange(TSharedRef<FNiagaraParameterViewModelCustomDetails> Item)
{
Item->NotifyEndDefaultValueChange();
}
void FNiagaraComponentDetails::ParameterEditorValueChanged(TSharedRef<SNiagaraParameterEditor> ParameterEditor, TSharedRef<FNiagaraParameterViewModelCustomDetails> Item)
{
ParameterEditor->UpdateStructFromInternalValue(Item->GetDefaultValueStruct());
Item->NotifyDefaultValueChanged();
}
FReply FNiagaraComponentDetails::OnEffectOpenRequested(UNiagaraEffect* InEffect)
{
if (InEffect)
{
FAssetEditorManager::Get().OpenEditorForAsset(InEffect);
}
return FReply::Handled();
}
FReply FNiagaraComponentDetails::OnLocationResetClicked(TSharedRef<FNiagaraParameterViewModelCustomDetails> Item)
{
Item->ResetToDefaults();
return FReply::Handled();
}
EVisibility FNiagaraComponentDetails::GetLocationResetVisibility(TSharedRef<FNiagaraParameterViewModelCustomDetails> Item) const
{
return Item->IsOverriddenLocally() ? EVisibility::Visible : EVisibility::Collapsed;
}
#undef LOCTEXT_NAMESPACE