UPreviewMesh

[UPreviewMesh](API\Plugins\ModelingComponents\UPreviewMesh) is a utility object that spawns and owns a transient mesh object in the World.

Choose your operating system:

Windows

macOS

Linux

Inheritance Hierarchy

References

Module

ModelingComponents

Header

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

Include

#include "PreviewMesh.h"

Syntax

UCLASS(Transient)
class UPreviewMesh :
    public UObject,
    public IMeshVertexCommandChangeTarget,
    public IMeshCommandChangeTarget,
    public IMeshReplacementCommandChangeTarget

Remarks

UPreviewMesh is a utility object that spawns and owns a transient mesh object in the World. This can be used to show live preview geometry during modeling operations. Call CreateInWorld() to set it up, and Disconnect() to shut it down.

Currently implemented via an internal Actor that has a UDynamicMeshComponent root component, with an AABBTree created/updated if FProperty bBuildSpatialDataStructure=true. The Actor is destroyed on Disconnect().

The intention with UPreviewMesh is to provide a higher-level interface than the Component. In future the internal Component may be replaced with another class (eg OctreeDynamicMeshComponent), or automatically swap between the two, etc.

As a result direct access to the Actor/Component, or a non-const FDynamicMesh3, is intentionally not provided. Wrapper functions are provided (or should be added) for necessary Actor/Component parameters. To edit the mesh either a copy is done, or EditMesh()/ApplyChange() must be used. These functions automatically update necessary internal data structures.

Variables

Name Description

Public variable UProperty

bool

 

bBuildSpatialDataStructure

If true, we build a spatial data structure internally for the preview mesh, which allows for hit-testing

Protected variable

bool

 

bDecompositionEnabled

If true, mesh will be chunked into multiple render buffers inside the DynamicMeshComponent

Protected variable UProperty

TObjectPtr< UDy...

 

DynamicMeshComponent

This component is set as the root component of TemporaryParentActor

Protected variable

UE::Geometry::F...

 

MeshAABBTree

Spatial data structure that is initialized if bBuildSpatialDataStructure = true when UpdatePreview() is called

Protected variable

APreviewMeshAct...

 

TemporaryParentActor

The temporary actor we create internally to own the preview mesh component

Constructors

Name Description

Public function

UPreviewMesh()

Destructors

Name Description

Public function Virtual

~UPreviewMesh()

Functions

Name Description

Public function

bool

 

CalculateTangents()

Calculate tangents for the underlying component.

Public function

void

 

ClearOverrideRenderMaterial()

Clear the override material for the preview mesh.

Public function

void

 

ClearPreview()

Read access to internal mesh Clear the preview mesh

Public function

void

 

ClearSecondaryRenderMaterial()

Clear the secondary material for the preview mesh.

Public function

void

 

ClearTriangleColorFunction

(
    ERenderUpdateMode UpdateMode
)

Clear the triangle color function for rendering / render data construction

Public function

void

 

CreateInWorld

(
    UWorld* World,
    const FTransform& WithTransform
)

Construction / destruction Create preview mesh in the World with the given transform

Public function

void

 

DeferredEditMesh

(
    TFunctionRef< void&)...,
    bool bRebuildSpatial
)

Apply EditFunc to the internal mesh, and update spatial data structure if requested, but do not update/rebuild rendering data structures.

Public function

void

 

DisableSecondaryTriangleBuffers()

Disable secondary triangle buffers

Public function

void

 

Disconnect()

Remove and destroy preview mesh

Public function

void

 

EditMesh

(
    TFunctionRef< void&)...
)

Apply EditFunc to the internal mesh and update internal data structures as necessary

Public function

void

 

EnableSecondaryTriangleBuffers

(
    TUniqueFunction< bool...
)

Enable secondary triangle buffers.

Public function

void

 

EnableWireframe

(
    bool bEnable
)

Visualization parameters Enable/disable wireframe overlay rendering

Public function Const

TUniquePtr< ...

 

ExtractPreviewMesh()

Public function

void

 

FastNotifySecondaryTrianglesChanged()

Call this after updating the secondary triangle sorting.

Public function

FVector3d

 

FindNearestPoint

(
    const FVector3d& WorldPoint,
    bool bLinearSearch
)

Find nearest point on current mesh to given WorldPoint Requires that bBuildSpatialDataStructure = true unless bLinearSearch = true

Public function

bool

 

FindRayIntersection

(
    const FRay3d& WorldRay,
    FHitResult& HitOut
)

Find ray intersection with the preview mesh.

Public function

void

 

ForceRebuildSpatial()

Force rebuild of internal spatial data structure.

Public function Const

UMaterialInt...

 

GetActiveMaterial

(
    int MaterialIndex
)

Public function Const

AActor *

 

GetActor()

Public function Const

bool

 

GetIsRenderMeshDecompositionEnabled()

Public function Const

UMaterialInt...

 

GetMaterial

(
    int MaterialIndex
)

Get material from the preview mesh

Public function Const

void

 

GetMaterials

(
    TArray< UMaterialInterface* > ...
)

Get the entire materials array from the preview mesh. Appends to OutMaterials without clearing it.

Public function Const

const FDynam...

 

GetMesh()

Read access to the internal mesh.

Public function Const

int32

 

GetNumMaterials()

Get number of materials in the preview mesh (base materials, i.e., not including override material)

Public function

FSimpleMulti...

 

GetOnMeshChanged()

Public function Const

const FDynam...

 

GetPreviewDynamicMesh()

Public function

UPrimitiveCo...

 

GetRootComponent()

Public function

UE::Geometry...

 

GetSpatial()

This has to return non-const because of current FDynamicMeshAABBTree3 API, but you should not modify this!

Public function Const

FTransform

 

GetTransform()

Get the current transform on the preview mesh

Public function Const

bool

 

IsVisible()

Public function

void

 

NotifyDeferredEditCompleted

(
    ERenderUpdateMode UpdateMode,
    EMeshRenderAttributeFlags ModifiedA...,
    bool bRebuildSpatial
)

Notify that a DeferredEditMesh sequence is complete and cause update of rendering data structures.

Public function

void

 

NotifyRegionDeferredEditCompleted

(
    const TArray< int32 >& Triangles,
    EMeshRenderAttributeFlags ModifiedA...
)

Notify that a deferred edit is completed and cause update of rendering data structures for modified Triangles.

Public function

void

 

NotifyRegionDeferredEditCompleted

(
    const TSet< int32 >& Triangles,
    EMeshRenderAttributeFlags ModifiedA...
)

Notify that a deferred edit is completed and cause update of rendering data structures for modified Triangles.

Protected function

void

 

NotifyWorldPathTracedOutputInvalidated()

This function is called internally on some changes, to let the path tracer know that this mesha/actor has been modified in a way that will require invalidating the current path tracing result

Public function Virtual Const

void

 

ProcessMesh

(
    TFunctionRef< void...
)

Give external code direct read access to the internal FDynamicMesh3.

Public function

void

 

ReplaceMesh

(
    FDynamicMesh3&& NewMesh
)

Replace mesh with new mesh

Public function

void

 

ReplaceMesh

(
    const FDynamicMesh3& NewMesh
)

Edit access to internal mesh, and change-tracking/notification Replace mesh with new mesh

Public function Virtual

void

 

SetEnableRenderMeshDecomposition

(
    bool bEnable
)

Enable automatically-computed decomposition of internal mesh into subregions when rendering (ie inside the Component).

Public function

void

 

SetMaterial

(
    int MaterialIndex,
    UMaterialInterface* Material
)

Set material on the preview mesh

Public function

void

 

SetMaterial

(
    UMaterialInterface* Material
)

Set material on the preview mesh

Public function

void

 

SetMaterials

(
    const TArray< UMaterialInterface&#...
)

Set the entire material set on the preview mesh

Public function

void

 

SetOverrideRenderMaterial

(
    UMaterialInterface* Material
)

Set an override material for the preview mesh. This material will override all the given materials.

Public function

void

 

SetSecondaryBuffersVisibility

(
    bool bSecondaryVisibility
)

Show/Hide the secondary triangle buffers.

Public function

void

 

SetSecondaryRenderMaterial

(
    UMaterialInterface* Material
)

Set an secondary material for the preview mesh.

Public function

void

 

SetShadowsEnabled

(
    bool bEnable
)

Enable/disable shadow rendering

Public function

void

 

SetTangentsMode

Set the tangents mode for the underlying component, if available.

Public function

void

 

SetTransform

(
    const FTransform& UseTransform
)

Set the transform on the preview mesh

Public function

void

 

SetTriangleColorFunction

(
    TFunction< FColor...,
    ERenderUpdateMode UpdateMode
)

Set the triangle color function for rendering / render data construction

Public function

void

 

SetVisible

(
    bool bVisible
)

Set visibility state of the preview mesh

Public function

bool

 

TestRayIntersection

(
    const FRay3d& WorldRay
)

Queries Test for ray intersection with the preview mesh.

Public function

TUniquePtr< ...

 

TrackedEditMesh

(
    TFunctionRef< void&,...
)

Apply EditFunc to the internal mesh and update internal data structures as necessary.

Public function

void

 

UpdatePreview

(
    const FDynamicMesh3* Mesh,
    ERenderUpdateMode UpdateMode,
    EMeshRenderAttributeFlags ModifiedA...
)

Update the internal mesh by copying the given Mesh

Public function

void

 

UpdatePreview

(
    FDynamicMesh3&& Mesh,
    ERenderUpdateMode UpdateMode,
    EMeshRenderAttributeFlags ModifiedA...
)

Update the internal mesh by moving in the given Mesh

Protected function

void

 

UpdateRenderMeshDecomposition()

Update chunk decomposition

Overridden from IMeshVertexCommandChangeTarget

Name Description

Public function Virtual

void

 

ApplyChange

(
    const FMeshVertexChange* Chang...,
    bool bRevert
)

Apply/Revert a vertex deformation change to the internal mesh (implements IMeshVertexCommandChangeTarget)

Overridden from IMeshCommandChangeTarget

Name Description

Public function Virtual

void

 

ApplyChange

(
    const FMeshChange* Change,
    bool bRevert
)

Apply/Revert a general mesh change to the internal mesh (implements IMeshCommandChangeTarget)

Overridden from IMeshReplacementCommandChangeTarget

Name Description

Public function Virtual

void

 

ApplyChange

(
    const FMeshReplacementChange* ...,
    bool bRevert
)

Apply/Revert a general mesh change to the internal mesh (implements IMeshReplacementCommandChangeTarget)

Enums

Name

Description

Public enum

ERenderUpdateMode

Render data update hint (values mirror EDynamicMeshComponentRenderUpdateMode)