Files
UnrealEngineUWP/Engine/Plugins/Runtime/MeshModelingToolset/Source/ModelingComponents/Public/Components/OctreeDynamicMeshComponent.h

162 lines
5.1 KiB
C
Raw Normal View History

// Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#include "Components/BaseDynamicMeshComponent.h"
#include "UDynamicMesh.h"
#include "DynamicMesh/DynamicMeshOctree3.h"
#include "Util/IndexSetDecompositions.h"
#include "OctreeDynamicMeshComponent.generated.h"
// predecl
struct FMeshDescription;
/** internal FPrimitiveSceneProxy defined in OctreeDynamicMeshSceneProxy.h */
class FOctreeDynamicMeshSceneProxy;
class FBaseDynamicMeshSceneProxy;
/**
* UOctreeDynamicMeshComponent is a mesh component similar to UProceduralMeshComponent,
* except it bases the renderable geometry off an internal FDynamicMesh3 instance.
* The class generally has the same capabilities as UDynamicMeshComponent.
*
* A FDynamicMeshOctree3 is available to dynamically track the triangles of the mesh
* (however the client is responsible for updating this octree).
* Based on the Octree, the mesh is partitioned into chunks that are stored in separate
* RenderBuffers in the FOctreeDynamicMeshSceneProxy.
* Calling NotifyMeshUpdated() will result in only the "dirty" chunks being updated,
* rather than the entire mesh.
*
* (So, if you don't need this capability, and don't want to update an Octree, use UDynamicMeshComponent!)
*/
UCLASS(hidecategories = (LOD, Physics, Collision), editinlinenew, ClassGroup = Rendering)
class MODELINGCOMPONENTS_API UOctreeDynamicMeshComponent : public UBaseDynamicMeshComponent
{
GENERATED_UCLASS_BODY()
public:
/**
ModelingComponents: Clean up DynamicMeshComponent API. Update Component and Proxy handling of Tangents to use Attribute Overlay if available. Update affected Tools and also convert most of the affected Tools to use UE::ToolTarget helper functions. - Add UE::ToolTarget::CommitMaterialSetUpdate() and ::CommitDynamicMeshUpdate(). ::GetDynamicMeshCopy() can now return tangents if requested. - Add IMeshDescriptionProvider::CalculateAutoGeneratedAttributes(). Default implementation does nothing, UStaticMeshComponentToolTarget implementation initializes auto-generated MeshDescription attributes. Used in ::GetDynamicMeshCopy() to get tangents (but requires a MeshDescription copy). - Clean up handling of Tangents in Simple/OctreeDynamicMeshComponent. Add local MakeTangentsFunc() to generate the Tangents lambda, handle different cases and no-tangents fallbacks consistently. - UDynamicMesh: add optional info arguments to EditMesh() and ChangeInfo struct. Add support for deferring change events from Edit funcs. - Remove UBaseDynamicMeshComponent::InitializeMesh(), ::Bake() APIs, and add ::SetMesh(). Implement in Simple/Octree implementations, update all Tools that used those APIs. - Add USimpleDynamicMeshComponent::ProcessMesh(), EditMesh(). These are now the preferred ways to read/write mesh. - Update USimpleDynamicMeshComponent tangents handling. Externally-computed tangents are now taken directly from the FDynamicMesh3 attribute set. Autogenerated tangents are still computed and stored in an internal FMeshTangentsf, but this is no longer exposed for external updates. - Remove UPreviewMesh pass-through functions for Tangents access, InitializeMesh() and Bake(). Add ProcessMesh() - Update all affected Tools. In most cases these Tools have also been converted to use ModelingToolTargetUtil functions, instead of direct ToolTarget interface casting. #rb none #rnx #jira none #preflight 60c3e71d3e1b3c00015668af #ROBOMERGE-SOURCE: CL 16650666 in //UE5/Main/... #ROBOMERGE-BOT: STARSHIP (Main -> Release-Engine-Test) (v833-16641396) [CL 16650707 by ryan schmidt in ue5-release-engine-test branch]
2021-06-11 22:42:32 -04:00
* initialize the internal mesh from a DynamicMesh
*/
ModelingComponents: Clean up DynamicMeshComponent API. Update Component and Proxy handling of Tangents to use Attribute Overlay if available. Update affected Tools and also convert most of the affected Tools to use UE::ToolTarget helper functions. - Add UE::ToolTarget::CommitMaterialSetUpdate() and ::CommitDynamicMeshUpdate(). ::GetDynamicMeshCopy() can now return tangents if requested. - Add IMeshDescriptionProvider::CalculateAutoGeneratedAttributes(). Default implementation does nothing, UStaticMeshComponentToolTarget implementation initializes auto-generated MeshDescription attributes. Used in ::GetDynamicMeshCopy() to get tangents (but requires a MeshDescription copy). - Clean up handling of Tangents in Simple/OctreeDynamicMeshComponent. Add local MakeTangentsFunc() to generate the Tangents lambda, handle different cases and no-tangents fallbacks consistently. - UDynamicMesh: add optional info arguments to EditMesh() and ChangeInfo struct. Add support for deferring change events from Edit funcs. - Remove UBaseDynamicMeshComponent::InitializeMesh(), ::Bake() APIs, and add ::SetMesh(). Implement in Simple/Octree implementations, update all Tools that used those APIs. - Add USimpleDynamicMeshComponent::ProcessMesh(), EditMesh(). These are now the preferred ways to read/write mesh. - Update USimpleDynamicMeshComponent tangents handling. Externally-computed tangents are now taken directly from the FDynamicMesh3 attribute set. Autogenerated tangents are still computed and stored in an internal FMeshTangentsf, but this is no longer exposed for external updates. - Remove UPreviewMesh pass-through functions for Tangents access, InitializeMesh() and Bake(). Add ProcessMesh() - Update all affected Tools. In most cases these Tools have also been converted to use ModelingToolTargetUtil functions, instead of direct ToolTarget interface casting. #rb none #rnx #jira none #preflight 60c3e71d3e1b3c00015668af #ROBOMERGE-SOURCE: CL 16650666 in //UE5/Main/... #ROBOMERGE-BOT: STARSHIP (Main -> Release-Engine-Test) (v833-16641396) [CL 16650707 by ryan schmidt in ue5-release-engine-test branch]
2021-06-11 22:42:32 -04:00
virtual void SetMesh(UE::Geometry::FDynamicMesh3&& MoveMesh) override;
/**
* @return pointer to internal mesh
*/
virtual FDynamicMesh3* GetMesh() override { return MeshObject->GetMeshPtr(); }
/**
* @return pointer to internal mesh
*/
virtual const FDynamicMesh3* GetMesh() const override { return MeshObject->GetMeshPtr(); }
ModelingComponents: Clean up DynamicMeshComponent API. Update Component and Proxy handling of Tangents to use Attribute Overlay if available. Update affected Tools and also convert most of the affected Tools to use UE::ToolTarget helper functions. - Add UE::ToolTarget::CommitMaterialSetUpdate() and ::CommitDynamicMeshUpdate(). ::GetDynamicMeshCopy() can now return tangents if requested. - Add IMeshDescriptionProvider::CalculateAutoGeneratedAttributes(). Default implementation does nothing, UStaticMeshComponentToolTarget implementation initializes auto-generated MeshDescription attributes. Used in ::GetDynamicMeshCopy() to get tangents (but requires a MeshDescription copy). - Clean up handling of Tangents in Simple/OctreeDynamicMeshComponent. Add local MakeTangentsFunc() to generate the Tangents lambda, handle different cases and no-tangents fallbacks consistently. - UDynamicMesh: add optional info arguments to EditMesh() and ChangeInfo struct. Add support for deferring change events from Edit funcs. - Remove UBaseDynamicMeshComponent::InitializeMesh(), ::Bake() APIs, and add ::SetMesh(). Implement in Simple/Octree implementations, update all Tools that used those APIs. - Add USimpleDynamicMeshComponent::ProcessMesh(), EditMesh(). These are now the preferred ways to read/write mesh. - Update USimpleDynamicMeshComponent tangents handling. Externally-computed tangents are now taken directly from the FDynamicMesh3 attribute set. Autogenerated tangents are still computed and stored in an internal FMeshTangentsf, but this is no longer exposed for external updates. - Remove UPreviewMesh pass-through functions for Tangents access, InitializeMesh() and Bake(). Add ProcessMesh() - Update all affected Tools. In most cases these Tools have also been converted to use ModelingToolTargetUtil functions, instead of direct ToolTarget interface casting. #rb none #rnx #jira none #preflight 60c3e71d3e1b3c00015668af #ROBOMERGE-SOURCE: CL 16650666 in //UE5/Main/... #ROBOMERGE-BOT: STARSHIP (Main -> Release-Engine-Test) (v833-16641396) [CL 16650707 by ryan schmidt in ue5-release-engine-test branch]
2021-06-11 22:42:32 -04:00
virtual void ProcessMesh(TFunctionRef<void(const UE::Geometry::FDynamicMesh3&)> ProcessFunc) const
{
MeshObject->ProcessMesh(ProcessFunc);
}
UE::Geometry::FDynamicMeshOctree3* GetOctree() { return Octree.Get(); }
/**
* Apply transform to internal mesh. Invalidates RenderProxy.
* @param bInvert if true, inverse tranform is applied instead of forward transform
*/
virtual void ApplyTransform(const FTransform3d& Transform, bool bInvert) override;
//
// change tracking/etc
//
/**
* Call this if you update the mesh via GetMesh()
* @todo should provide a function that calls a lambda to modify the mesh, and only return const mesh pointer
*/
virtual void NotifyMeshUpdated() override;
/**
* Apply a vertex deformation change to the internal mesh
*/
virtual void ApplyChange(const FMeshVertexChange* Change, bool bRevert) override;
/**
* Apply a general mesh change to the internal mesh
*/
virtual void ApplyChange(const FMeshChange* Change, bool bRevert) override;
/**
* Apply a general mesh replacement change to the internal mesh
*/
virtual void ApplyChange(const FMeshReplacementChange* Change, bool bRevert) override;
/**
* This delegate fires when a FCommandChange is applied to this component, so that
* parent objects know the mesh has changed.
*/
FSimpleMulticastDelegate OnMeshChanged;
/**
* If this function is set, we will use these colors instead of vertex colors
*/
TFunction<FColor(const FDynamicMesh3*, int)> TriangleColorFunc = nullptr;
protected:
/**
* This is called to tell our RenderProxy about modifications to the material set.
* We need to pass this on for things like material validation in the Editor.
*/
virtual void NotifyMaterialSetUpdated();
private:
virtual FBaseDynamicMeshSceneProxy* GetBaseSceneProxy() override { return (FBaseDynamicMeshSceneProxy*)GetCurrentSceneProxy(); }
FOctreeDynamicMeshSceneProxy* GetCurrentSceneProxy() { return (FOctreeDynamicMeshSceneProxy*)SceneProxy; }
//~ Begin UPrimitiveComponent Interface.
virtual FPrimitiveSceneProxy* CreateSceneProxy() override;
//~ End UPrimitiveComponent Interface.
//~ Begin USceneComponent Interface.
virtual FBoxSphereBounds CalcBounds(const FTransform& LocalToWorld) const override;
//~ Begin USceneComponent Interface.
UPROPERTY()
TObjectPtr<UDynamicMesh> MeshObject;
FDelegateHandle MeshObjectChangedHandle;
void OnMeshObjectChanged(UDynamicMesh* ChangedMeshObject, FDynamicMeshChangeInfo ChangeInfo);
FDelegateHandle PreMeshChangeHandle;
void OnPreMeshObjectChanged(UDynamicMesh* ChangedMeshObject, FDynamicMeshChangeInfo ChangeInfo);
TUniquePtr<UE::Geometry::FDynamicMeshOctree3> Octree;
TUniquePtr<UE::Geometry::FDynamicMeshOctree3::FTreeCutSet> OctreeCut;
UE::Geometry::FArrayIndexSetsDecomposition TriangleDecomposition;
struct FCutCellIndexSet
{
UE::Geometry::FDynamicMeshOctree3::FCellReference CellRef;
int32 DecompSetID;
};
TArray<FCutCellIndexSet> CutCellSetMap;
int32 SpillDecompSetID;
FColor GetTriangleColor(int TriangleID);
//friend class FCustomMeshSceneProxy;
public:
//UFUNCTION(BlueprintCallable, Category = "DynamicMesh")
virtual UDynamicMesh* GetDynamicMesh() override { return MeshObject; }
UFUNCTION(BlueprintCallable, Category = "DynamicMesh")
void SetDynamicMesh(UDynamicMesh* NewMesh);
};