// Copyright Epic Games, Inc. All Rights Reserved. #include "StaticMeshAttributes.h" namespace MeshAttribute { const FName VertexInstance::TextureCoordinate("TextureCoordinate"); const FName VertexInstance::Normal("Normal"); const FName VertexInstance::Tangent("Tangent"); const FName VertexInstance::BinormalSign("BinormalSign"); const FName VertexInstance::Color("Color"); const FName Edge::IsHard("IsHard"); const FName Triangle::Normal("Normal"); const FName Triangle::Tangent("Tangent"); const FName Triangle::Binormal("Binormal"); const FName Polygon::ObjectName("ObjectName"); const FName PolygonGroup::ImportedMaterialSlotName("ImportedMaterialSlotName"); } void FStaticMeshAttributes::Register(bool bKeepExistingAttribute) { // Add basic vertex attributes // Add basic vertex instance attributes if (!MeshDescription.VertexInstanceAttributes().HasAttribute(MeshAttribute::VertexInstance::TextureCoordinate) || !bKeepExistingAttribute) { const int32 NumUVChannels = MeshDescription.GetNumUVElementChannels(); MeshDescription.VertexInstanceAttributes().RegisterAttribute(MeshAttribute::VertexInstance::TextureCoordinate, NumUVChannels, FVector2f::ZeroVector, EMeshAttributeFlags::Lerpable | EMeshAttributeFlags::Mandatory); } if (!MeshDescription.VertexInstanceAttributes().HasAttribute(MeshAttribute::VertexInstance::Normal) || !bKeepExistingAttribute) { MeshDescription.VertexInstanceAttributes().RegisterAttribute(MeshAttribute::VertexInstance::Normal, 1, FVector3f::ZeroVector, EMeshAttributeFlags::AutoGenerated | EMeshAttributeFlags::Mandatory); } if (!MeshDescription.VertexInstanceAttributes().HasAttribute(MeshAttribute::VertexInstance::Tangent) || !bKeepExistingAttribute) { MeshDescription.VertexInstanceAttributes().RegisterAttribute(MeshAttribute::VertexInstance::Tangent, 1, FVector3f::ZeroVector, EMeshAttributeFlags::AutoGenerated | EMeshAttributeFlags::Mandatory); } if (!MeshDescription.VertexInstanceAttributes().HasAttribute(MeshAttribute::VertexInstance::BinormalSign) || !bKeepExistingAttribute) { MeshDescription.VertexInstanceAttributes().RegisterAttribute(MeshAttribute::VertexInstance::BinormalSign, 1, 0.0f, EMeshAttributeFlags::AutoGenerated | EMeshAttributeFlags::Mandatory); } if (!MeshDescription.VertexInstanceAttributes().HasAttribute(MeshAttribute::VertexInstance::Color) || !bKeepExistingAttribute) { MeshDescription.VertexInstanceAttributes().RegisterAttribute(MeshAttribute::VertexInstance::Color, 1, FVector4f(1.0f, 1.0f, 1.0f, 1.0f), EMeshAttributeFlags::Lerpable | EMeshAttributeFlags::Mandatory); } // Add basic edge attributes if (!MeshDescription.EdgeAttributes().HasAttribute(MeshAttribute::Edge::IsHard) || !bKeepExistingAttribute) { MeshDescription.EdgeAttributes().RegisterAttribute(MeshAttribute::Edge::IsHard, 1, false, EMeshAttributeFlags::Mandatory); } // Add basic polygon attributes // Add basic polygon group attributes if (!MeshDescription.PolygonGroupAttributes().HasAttribute(MeshAttribute::PolygonGroup::ImportedMaterialSlotName) || !bKeepExistingAttribute) { MeshDescription.PolygonGroupAttributes().RegisterAttribute(MeshAttribute::PolygonGroup::ImportedMaterialSlotName, 1, NAME_None, EMeshAttributeFlags::Mandatory); //The unique key to match the mesh material slot } // Call super class FMeshAttributes::Register(bKeepExistingAttribute); } void FStaticMeshAttributes::RegisterTriangleNormalAndTangentAttributes() { MeshDescription.TriangleAttributes().RegisterAttribute(MeshAttribute::Triangle::Normal, 1, FVector3f::ZeroVector, EMeshAttributeFlags::Transient); MeshDescription.TriangleAttributes().RegisterAttribute(MeshAttribute::Triangle::Tangent, 1, FVector3f::ZeroVector, EMeshAttributeFlags::Transient); MeshDescription.TriangleAttributes().RegisterAttribute(MeshAttribute::Triangle::Binormal, 1, FVector3f::ZeroVector, EMeshAttributeFlags::Transient); } void FStaticMeshAttributes::RegisterPolygonObjectNameAttribute() { if (!MeshDescription.PolygonAttributes().HasAttribute(MeshAttribute::Polygon::ObjectName)) { MeshDescription.PolygonAttributes().RegisterAttribute(MeshAttribute::Polygon::ObjectName, 1, NAME_None, EMeshAttributeFlags::AutoGenerated); } }