UMeshOpPreviewWithBackgroundCompute

[UMeshOpPreviewWithBackgroundCompute](API\Plugins\ModelingComponents\UMeshOpPreviewWithBackgroundComp-) is an infrastructure object that implements a common UI pattern in interactive 3D tools, where we want to run an expensive computation on a mesh that is based on user-specified parameters, and show a preview of the result.

Choose your operating system:

Windows

macOS

Linux

Inheritance Hierarchy

UObjectBase

UObjectBaseUtility

UObject

UMeshOpPreviewWithBackgroundCompute

References

Module

ModelingComponents

Header

/Engine/Plugins/Runtime/MeshModelingToolset/Source/ModelingComponents/Public/MeshOpPreviewHelpers.h

Include

#include "MeshOpPreviewHelpers.h"

Syntax

UCLASS(Transient)
class UMeshOpPreviewWithBackgroundCompute : public UObject

Remarks

UMeshOpPreviewWithBackgroundCompute is an infrastructure object that implements a common UI pattern in interactive 3D tools, where we want to run an expensive computation on a mesh that is based on user-specified parameters, and show a preview of the result. The expensive computation (a MeshOperator) must run in a background thread so as to not block the UI. If the user changes parameters while the Operator is running, it should be canceled and restarted. When it completes, the Preview will be updated. When the user is happy, the current Mesh is returned to the owner of this object.

The MeshOperators are provided by the owner via a IDynamicMeshOperatorFactory implementation. The owner must also Tick() this object regularly to allow the Preview to update when the background computations complete.

If an InProgress Material is set (via ConfigureMaterials) then when a background computation is active, this material will be used to draw the previous Preview result, to give the user a visual indication that work is happening.

Variables

Name Description

Protected variable

TUniquePtr< FBa...

 

BackgroundCompute

This object manages the background computes

Public variable

bool

 

bAllowDirtyResultUpdates

When true, the preview mesh is allowed to be temporarily updated using results that we know are dirty (i.e., the preview was invalidated, but a result became available before the operation was restarted, so we can at least show that while we wait for the new result).

Protected variable

bool

 

bMeshInitialized

Protected variable

bool

 

bMeshTopologyIsConstant

Used for partial/fast updates of the preview mesh render proxy.

Protected variable

bool

 

bResultValid

State flag, if true then we have valid result

Protected variable

bool

 

bVisible

Protected variable

EMeshRenderAttr...

 

ChangingAttributeFlags

Protected variable

UE::Geometry::E...

 

LastComputeStatus

Stored status of last compute, mainly so that we know when we should show the "busy" material.

Public variable

FOnMeshUpdated

 

OnMeshUpdated

This delegate is broadcast whenever the embedded preview mesh is updated

Public variable

FOnOpCompleted

 

OnOpCompleted

Public variable UProperty

TObjectPtr< UMa...

 

OverrideMaterial

Override material to forward to PreviewMesh if set

Public variable UProperty

TObjectPtr< UPr...

 

PreviewMesh

Preview of MeshOperator result

Public variable

UWorld *

 

PreviewWorld

Public variable UProperty

TObjectPtr< UMa...

 

SecondaryMaterial

Secondary render material to forward to PreviewMesh if set

Protected variable

float

 

SecondsBeforeWorkingMaterial

Public variable UProperty

TArray< TObject...

 

StandardMaterials

Input set of materials to assign to PreviewMesh

Protected variable

double

 

ValidResultComputeTimeSeconds

Public variable UProperty

TObjectPtr< UMa...

 

WorkingMaterial

If non-null, this material is swapped in when a background compute is active

Functions

Name Description

Public function

void

 

Cancel()

Terminate any active computation without returning anything. Destroys the preview mesh.

Public function

void

 

CancelCompute()

Cancel the active computation without returning anything. Doesn't destroy the mesh.

Public function

void

 

ChangeOpFactory

Stops any running computes and swaps in a different op generator.

Public function

void

 

ClearOpFactory()

Public function

void

 

ConfigureMaterials

(
    TArray< UMaterialInterface* > ...,
    UMaterialInterface* InProgress...
)

Configure the Standard and In-Progress materials

Public function

void

 

ConfigureMaterials

(
    UMaterialInterface* StandardMa...,
    UMaterialInterface* InProgress...
)

Optional configuration Configure the Standard and In-Progress materials

Public function

bool

 

GetCurrentResultCopy

(
    FDynamicMesh3& MeshOut,
    bool bOnlyIfValid
)

Read back a copy of current preview mesh.

Public function Const

double

 

GetValidResultComputeTime()

Public function Virtual Const

UWorld *

 

GetWorld()

Public function Const

bool

 

HaveEmptyResult()

Public function Const

bool

 

HaveValidNonEmptyResult()

Public function Const

bool

 

HaveValidResult()

Public function

void

 

InvalidateResult()

Control flow Request that the current computation be canceled and a new one started

Public function

bool

 

IsUsingWorkingMaterial()

Public function

bool

 

ProcessCurrentMesh

(
    TFunctionRef< void...,
    bool bOnlyIfValid
)

Allow an external function to safely access the PreviewMesh's mesh

Public function

void

 

SetIsMeshTopologyConstant

(
    bool bOn,
    EMeshRenderAttributeFlags ChangingA...
)

If set to true, then it will be assumed that the mesh topology (i.e. triangle/edge connectivity) remains constant, which will allow updates after the first one to modify existing render proxy buffers rather than creating entirely new ones.

Public function

void

 

Setup

(
    UWorld* InWorld
)

Public function

void

 

Setup

(
    UWorld* InWorld,
    UE::Geometry::IDynamicMeshOperatorF...
)

Required calls to setup/update/shutdown this object

Public function

void

 

SetVisibility

(
    bool bVisible
)

Set the visibility of the Preview mesh

Public function

void

 

SetWorkingMaterialDelay

(
    float TimeInSeconds
)

Set time that Preview will wait before showing working material

Public function

FDynamicMesh...

 

Shutdown()

Terminate any active computation and return the current Preview Mesh/Transform

Public function

void

 

Tick

(
    float DeltaTime
)

Tick the background computation and Preview update.

Protected function

void

 

UpdateResults()

Update the PreviewMesh if a new result is available from BackgroundCompute

Typedefs

Name

Description

FOnMeshUpdated

Change notification

FOnOpCompleted