Files
UnrealEngineUWP/Engine/Source/Runtime/InteractiveToolsFramework/Public/ComponentSourceInterfaces.h
ryan schmidt 27ba71e214 ModelingTools: Add support for reading and writing to a specific LOD via IMeshDescriptionProvider/Committer. Refactor various other aspects of MeshDescription access. Update MeshTransferTool to be able to transfer from and to specific LODs.
Add new MeshTargetInterfaceTypes.h file, move EStaticMeshEditingLOD there and rename to EMeshLODIdentifier. Add FGetMeshParameters and FCommitMeshParameters types.

IMeshDescriptionProvider::GetMeshDescription() now takes FGetMeshParameters to optionally specify LOD.
Added IMeshDescriptionProvider::GetMeshDescriptionCopy() function, to handle copy-case.
removed IMeshDescriptionProvider::CalculateAutoGeneratedAttributes(). This was only being used to force Tangents computation, which can now be done via GetMeshDescriptionCopy() and FGetMeshParameters.bWantMeshTangents option

IMeshDescriptionCommitter commit functions now take a FCommitMeshParameters to optionally specify target LOD.

StaticMeshComponentToolTarget::GetMeshDescriptionCopy() added, optionally computes auto-generated MeshDescription attributes on the copy

StaticMesh(Component)ToolTarget updated to support FCommitMeshParameters target-LOD.

SkeletalMesh, Volume, and DynamicMesh ToolTargets updated for new APIs but do not currently support any of the new LOD parameters. These should never be called w/ LOD parameters in the current codebase, ensures added to catch any errors (they would be non-fatal).

UE::ToolTarget::GetMeshDescription() and GetMeshDescriptionCopy() in now take FGetMeshParameters argument.
Removed bWantMeshTangents param to GetMeshDescriptionCopy(), now done via FGetMeshParameters. Updated call sites.

TransferMeshesTool now supports specifying read and write LOD (numbered or HiRes) for StaticMeshComponent source/target, via above functions.
TransferMeshesTool can now also target a new LOD in a StaticMeshComponent, index is 1 larger than current maximum source LOD.

#rb lonnie.li, rinat.abdrashitov
#rnx
#jira none
#preflight 61b8d56b2e65a1df046aa5e1

#ROBOMERGE-AUTHOR: ryan.schmidt
#ROBOMERGE-SOURCE: CL 18461686 in //UE5/Release-5.0/... via CL 18461725
#ROBOMERGE-BOT: STARSHIP (Release-Engine-Staging -> Release-Engine-Test) (v899-18417669)

[CL 18461778 by ryan schmidt in ue5-release-engine-test branch]
2021-12-14 18:40:01 -05:00

170 lines
5.9 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "Math/UnrealMath.h"
#include "Misc/Optional.h"
#include "Templates/Function.h"
#include "TargetInterfaces/MaterialProvider.h" // FComponentMaterialSet
#include "Engine/EngineTypes.h" // FHitResult
// predeclarations
class AActor;
class UActorComponent;
class UPrimitiveComponent;
struct FMeshDescription;
class UMaterialInterface;
/**
* @deprecated Use tool targets instead, such as UPrimitiveComponentToolTarget
*
* Wrapper around a UObject Component that can provide a MeshDescription, and
* (optionally) bake a modified MeshDescription back to this Component.
* An example of a Source might be a StaticMeshComponent. How a modified
* MeshDescription is committed back is context-dependent (in Editor vs PIE vs Runtime, etc).
*
* (Conceivably this doesn't have to be backed by a Component, but most usage will assume there is an Actor)
*/
class INTERACTIVETOOLSFRAMEWORK_API FPrimitiveComponentTarget
{
public:
virtual ~FPrimitiveComponentTarget(){}
/** Constructor UPrimitivecomponent*
* @param Component the UPrimitiveComponent* to target
*/
FPrimitiveComponentTarget( UPrimitiveComponent* Component ): Component( Component ){}
/** @return true if component target is still valid. May become invalid for various reasons (eg Component was deleted out from under us) */
virtual bool IsValid() const;
/** @return the Actor that owns this Component */
AActor* GetOwnerActor() const;
/** @return the Component this is a Source for */
UPrimitiveComponent* GetOwnerComponent() const;
/** @return number of material indices in use by this Component */
int32 GetNumMaterials() const;
/**
* Get pointer to a Material provided by this Source
* @param MaterialIndex index of the material
* @return MaterialInterface pointer, or null if MaterialIndex is invalid
*/
UMaterialInterface* GetMaterial(int32 MaterialIndex) const;
/**
* Get material set provided by this source
* @param MaterialSetOut returned material set
* @param bAssetMaterials if an underlying asset exists, return the Asset-level material assignment instead of the component materials
*/
virtual void GetMaterialSet(FComponentMaterialSet& MaterialSetOut, bool bAssetMaterials = false) const;
/**
* @return the transform on this component
* @todo Do we need to return a list of transforms here?
*/
FTransform GetWorldTransform() const;
/**
* Compute ray intersection with the MeshDescription this Source is providing
* @param WorldRay ray in world space
* @param OutHit hit test data
* @return true if ray intersected Component
*/
bool HitTest(const FRay& WorldRay, FHitResult& OutHit) const;
/**
* Set the visibility of the Component associated with this Source (ie to hide during Tool usage)
* @param bVisible desired visibility
*/
void SetOwnerVisibility(bool bVisible) const;
/**
* Checks if the underlying asset that would be edited by CommitMesh() is the same for two ComponentTargets
* @param OtherTarget Another component target to compare against
* @return true if both component targets are known to share the same source asset
*/
virtual bool HasSameSourceData(const FPrimitiveComponentTarget& OtherTarget) const = 0;
/**
* Commit an update to the material set. This may generate a transaction.
* @param MaterialSet new list of materials
* @param bApplyToAsset if true, materials of Asset are updated (if Asset exists), rather than Component
*/
virtual void CommitMaterialSetUpdate(const FComponentMaterialSet& MaterialSet, bool bApplyToAsset);
struct FCommitParams
{
FMeshDescription* MeshDescription{ nullptr };
};
using FCommitter = TFunction< void( const FCommitParams& ) >;
virtual FMeshDescription* GetMesh() = 0;
virtual void CommitMesh( const FCommitter& ) = 0;
UPrimitiveComponent* Component{};
};
/** @deprecated Use tool target factories instead. */
class INTERACTIVETOOLSFRAMEWORK_API FComponentTargetFactory
{
public:
virtual ~FComponentTargetFactory(){}
virtual bool CanBuild( UActorComponent* Candidate ) = 0;
virtual TUniquePtr<FPrimitiveComponentTarget> Build( UPrimitiveComponent* PrimitiveComponent ) = 0;
};
/**
* @deprecated Add tool target factories to the tool target manager instead.
*
* Add a factory method to make ComponentTarget from UPrimitiveComponent*
* @param Factory The ComponentTargetFactory
* @return integer indentifier that identifies this Factory
*/
INTERACTIVETOOLSFRAMEWORK_API int32 AddComponentTargetFactory( TUniquePtr<FComponentTargetFactory> Factory );
/**
* @return ComponentTargetFactory associated with the given Key, or nullptr if not found
*/
INTERACTIVETOOLSFRAMEWORK_API FComponentTargetFactory* FindComponentTargetFactoryByKey(int32 Key);
/**
* @return true if ComponentTargetFactory associated with the given Key was found and removed
*/
INTERACTIVETOOLSFRAMEWORK_API bool RemoveComponentTargetFactoryByKey(int32 Key);
/**
* remove all registered ComponentTargetFactory objects
*/
INTERACTIVETOOLSFRAMEWORK_API void RemoveAllComponentTargetFactoryies();
/**
* @deprecated Ask your tool target manager to build a target for you instead.
*
* Create a TargetComponent for the given Component
* @param Component A UObject that we would like to use as tool target. This must presently descend from
* UPrimitiveComponent
* @return An FComponentTarget instance. Must not return null, though the MeshSource and MeshSink in it's MeshBridge may
* be
*/
INTERACTIVETOOLSFRAMEWORK_API TUniquePtr<FPrimitiveComponentTarget> MakeComponentTarget(UPrimitiveComponent* Component);
/**
* @deprecated Ask your tool target manager instead.
*
* Determine whether a TargetComponent can be created for the given Component
* @param Component A UObject that we would like to use as tool target.
* @return bool signifying whether or not a ComponentTarget can be built
*/
INTERACTIVETOOLSFRAMEWORK_API bool CanMakeComponentTarget(UActorComponent* Component);