// ------------------------------------------------------------------------------------------------ // ___ __ ___ ___ ® // Copyright © 2009-2010, All rights reserved __)| /\ \__|| / \ / | / // Playlogic games factory, Breda | |___/__\ __||___\__/ \__| | \___ // // ------------------------------------------------------------------------------------------------ #include "PLBase.h" IMPLEMENT_CLASS( APLTextMesh ); void APLTextMesh::InitTextTexture() { // Ensure we have a texture if ( TextTexture == NULL ) { TextTexture = ConstructObject< UPLTextTexture >( UPLTextTexture::StaticClass(), this ); } // Ensure that this class is in the interfaces list new( TextTexture->TextActors ) TScriptInterface( this ); // Initialize the texture TextTexture->UpdateText(); } void APLTextMesh::PostLoad() { Super::PostLoad(); // Ensure we have a properly initialized texture if ( GIsEditor && TextTexture == NULL ) { InitTextTexture(); } if ( GIsEditor && StaticMeshComponent != NULL ) { // Ensure we have our own MIC, non-recurring UMaterialInstanceConstant* Material = Cast< UMaterialInstanceConstant >( StaticMeshComponent->GetMaterial( 0 ) ); if ( Material != NULL && Material->IsIn( this ) && Material->Parent != NULL && Material->Parent->IsInA( StaticClass() ) ) { UMaterialInterface* Parent = Material->Parent; while ( Parent != NULL && Parent->IsA( UMaterialInstanceConstant::StaticClass() ) && Parent->IsInA( StaticClass() ) ) { UMaterialInstanceConstant* Current = CastChecked< UMaterialInstanceConstant >( Parent ); Parent = Current->Parent; } Material->SetParent( Parent ); } } } void APLTextMesh::PostEditImport() { Super::PostEditImport(); // Ensure we have our own MIC UMaterialInstanceConstant* Material = Cast< UMaterialInstanceConstant >( StaticMeshComponent->GetMaterial( 0 ) ); if ( Material != NULL && Material->GetOuter() != NULL && Material->IsInA( StaticClass() ) ) { StaticMeshComponent->SetMaterial( 0, Material->Parent ); } TextTexture->TextActors.Reset(); InitTextTexture(); } void APLTextMesh::Spawned() { Super::Spawned(); // Just spawned, initialize texture InitTextTexture(); } void APLTextMesh::TextSizeChanged( UObject* Sender, FVector2D const & NewTextSize, FVector2D const & NewUVs ) { FComponentReattachContext ReattachContext( StaticMeshComponent ); // Update mesh width and height if ( StaticMeshComponent->StaticMesh != NULL ) { StaticMeshComponent->Scale3D = FVector( 1.0f, NewTextSize.X / Max< FLOAT >( SMALL_NUMBER, StaticMeshComponent->StaticMesh->Bounds.BoxExtent.Y ), NewTextSize.Y / Max< FLOAT >( SMALL_NUMBER, StaticMeshComponent->StaticMesh->Bounds.BoxExtent.Z ) ); } else { StaticMeshComponent->Scale3D = FVector( NewTextSize.X, 0.0f, NewTextSize.Y ); } // Ensure we have our own MIC UMaterialInstanceConstant* Material = Cast< UMaterialInstanceConstant >( StaticMeshComponent->GetMaterial( 0 ) ); if ( Material == NULL || !Material->IsIn( this ) ) { Material = ConstructObject< UMaterialInstanceConstant >( UMaterialInstanceConstant::StaticClass(), this ); check( Material ); UMaterialInterface* ParentMat = StaticMeshComponent->GetMaterial( 0 ); Material->SetParent( ParentMat ); StaticMeshComponent->SetMaterial( 0, Material ); } // Update parameters Material->SetTextureParameterValue( TextureParameterName, TextTexture ); Material->SetVectorParameterValue( UVParameterName, FLinearColor( NewUVs.X, NewUVs.Y, 0.0, 0.0 ) ); } void APLTextMesh::CheckForErrors() { Super::CheckForErrors(); // Ensure we have our own MIC UMaterialInstanceConstant* Material = Cast< UMaterialInstanceConstant >( StaticMeshComponent->GetMaterial( 0 ) ); if ( Material != NULL && Material->IsIn( this ) && Material->Parent != NULL ) { if ( Material->Parent->IsIn( this ) ) { GWarn->MapCheck_Add( MCTYPE_ERROR, this, *FString::Printf( TEXT( "%s: Multiple Recursive Material, please recreate!" ), *GetName() ), MCACTION_DELETE ); } else if ( Material->Parent->IsInA( StaticClass() ) ) { GWarn->MapCheck_Add( MCTYPE_ERROR, this, *FString::Printf( TEXT( "%s: Cross-actor material reference, please recreate!" ), *GetName() ), MCACTION_DELETE ); } } }