// Copyright Epic Games, Inc. All Rights Reserved. #include "MuT/ASTOpMeshClipWithMesh.h" #include "MuT/ASTOpMeshAddMetadata.h" #include "HAL/PlatformMath.h" #include "MuR/ModelPrivate.h" #include "MuR/RefCounted.h" #include "MuR/Types.h" namespace mu { ASTOpMeshClipWithMesh::ASTOpMeshClipWithMesh() : Source(this) , ClipMesh(this) { } ASTOpMeshClipWithMesh::~ASTOpMeshClipWithMesh() { // Explicit call needed to avoid recursive destruction ASTOp::RemoveChildren(); } bool ASTOpMeshClipWithMesh::IsEqual(const ASTOp& OtherUntyped) const { if (OtherUntyped.GetOpType()==GetOpType()) { const ASTOpMeshClipWithMesh* Other = static_cast(&OtherUntyped); return Source == Other->Source && ClipMesh == Other->ClipMesh; } return false; } uint64 ASTOpMeshClipWithMesh::Hash() const { uint64 Result = std::hash()(Source.child().get()); hash_combine(Result, ClipMesh.child().get()); return Result; } Ptr ASTOpMeshClipWithMesh::Clone(MapChildFuncRef MapChild) const { Ptr New = new ASTOpMeshClipWithMesh(); New->Source = MapChild(Source.child()); New->ClipMesh = MapChild(ClipMesh.child()); return New; } void ASTOpMeshClipWithMesh::ForEachChild(const TFunctionRef Func) { Func(Source); Func(ClipMesh); } void ASTOpMeshClipWithMesh::Link(FProgram& Program, FLinkerOptions*) { // Already linked? if (!linkedAddress) { OP::MeshApplyPoseArgs Args; FMemory::Memzero(Args); if (Source) Args.base = Source->linkedAddress; if (ClipMesh) Args.pose = ClipMesh->linkedAddress; linkedAddress = (OP::ADDRESS)Program.OpAddress.Num(); Program.OpAddress.Add(Program.ByteCode.Num()); AppendCode(Program.ByteCode, GetOpType()); AppendCode(Program.ByteCode, Args); } } Ptr ASTOpMeshClipWithMesh::OptimiseSink(const FModelOptimizationOptions&, FOptimizeSinkContext&) const { Ptr NewOp; Ptr MeshAt = Source.child(); if (!MeshAt) { return nullptr; } EOpType MeshType = MeshAt->GetOpType(); switch (MeshType) { case EOpType::ME_ADDMETADATA: { Ptr New = mu::Clone(MeshAt); if (New->Source) { Ptr NewApplyPose = mu::Clone(this); NewApplyPose->Source = New->Source.child(); New->Source = NewApplyPose; } NewOp = New; break; } default: break; } return NewOp; } FSourceDataDescriptor ASTOpMeshClipWithMesh::GetSourceDataDescriptor(FGetSourceDataDescriptorContext* Context) const { if (Source) { return Source->GetSourceDataDescriptor(Context); } return {}; } }