Files
UnrealEngineUWP/Engine/Source/Runtime/MeshEditingRuntime/StaticMeshEditableMeshFormat.cpp
Mike Fricker c579283605 Fixed bidirectional dependency between Engine and MeshEditingRuntime modules
- Changed StaticMesh to just have a blind UObject pointer to the EditableMesh

#codereview richard.talbotwatkin
#rb none

[CL 3354704 by Mike Fricker in Dev-Geometry branch]
2017-03-20 16:07:17 -04:00

61 lines
2.0 KiB
C++

// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved.
#include "StaticMeshEditableMeshFormat.h"
#include "EditableMesh.h"
#include "Engine/StaticMesh.h"
#include "Components/StaticMeshComponent.h"
#include "StaticMeshResources.h"
#include "EditableStaticMesh.h"
void FStaticMeshEditableMeshFormat::FillMeshObjectPtr( UPrimitiveComponent& Component, FEditableMeshSubMeshAddress& SubMeshAddress )
{
SubMeshAddress.MeshObjectPtr = nullptr;
const UStaticMeshComponent* StaticMeshComponentPtr = Cast<const UStaticMeshComponent>( &Component );
if( StaticMeshComponentPtr != nullptr )
{
const UStaticMeshComponent& StaticMeshComponent = *StaticMeshComponentPtr;
UStaticMesh* ComponentStaticMesh = StaticMeshComponent.GetStaticMesh();
if( ComponentStaticMesh != nullptr && ComponentStaticMesh->HasValidRenderData() )
{
SubMeshAddress.MeshObjectPtr = ComponentStaticMesh;
}
}
}
UEditableMesh* FStaticMeshEditableMeshFormat::MakeEditableMesh( UPrimitiveComponent& Component, const FEditableMeshSubMeshAddress& SubMeshAddress )
{
// If the static mesh already has an attached UEditableStaticMesh, use that in preference to creating a new one
const UStaticMeshComponent* StaticMeshComponentPtr = Cast<const UStaticMeshComponent>( &Component );
if( StaticMeshComponentPtr != nullptr )
{
const UStaticMeshComponent& StaticMeshComponent = *StaticMeshComponentPtr;
if( StaticMeshComponent.GetStaticMesh() != nullptr )
{
UEditableMesh* EditableMesh = Cast<UEditableMesh>( StaticMeshComponent.GetStaticMesh()->EditableMesh );
if( EditableMesh )
{
EditableMesh->SetSubMeshAddress( SubMeshAddress );
return EditableMesh;
}
}
}
UEditableStaticMesh* EditableStaticMesh = NewObject<UEditableStaticMesh>();
EditableStaticMesh->InitEditableStaticMesh( Component, SubMeshAddress );
// Don't bother returning a new mesh if it has no geometry
if( EditableStaticMesh->GetVertexCount() == 0 )
{
EditableStaticMesh->MarkPendingKill();
EditableStaticMesh = nullptr;
}
return EditableStaticMesh;
}