UTexture2D* UTensorFlowBlueprintLibrary::Conv_RenderTargetTextureToTexture2D(UTextureRenderTarget2D* PassedTexture)
{
	int TextureLength = PassedTexture->SizeX * PassedTexture->SizeY;
	UTexture2D* Pointer = UTexture2D::CreateTransient(PassedTexture->SizeX, PassedTexture->SizeY, PF_R8G8B8A8);
	
	TArray<FColor> SurfData;
	FRenderTarget *RenderTarget = PassedTexture->GameThread_GetRenderTargetResource();
	RenderTarget->ReadPixels(SurfData);

	uint8* MipData = static_cast<uint8*>(Pointer->PlatformData->Mips[0].BulkData.Lock(LOCK_READ_WRITE));

	//Copy Data
	for (int i = 0; i < TextureLength; i++)
	{
		int MipPointer = i * 4;
		const FColor& Color = SurfData[i];
		uint8 AdjustedColor = (Color.R + Color.G + Color.B) / 3;
		MipData[MipPointer] = AdjustedColor;
		MipData[MipPointer + 1] = AdjustedColor;
		MipData[MipPointer + 2] = AdjustedColor;
		MipData[MipPointer + 3] = 255;	//Alpha
	}

	//Unlock and Return data
	Pointer->PlatformData->Mips[0].BulkData.Unlock();
	Pointer->UpdateResource();
	PassedTexture->Source.UnlockMip(0);
	return Pointer;
}
void FLightmapCustomNodeBuilder::RefreshLightmapItems()
{
	LightmapItems.Empty();

	FWorldContext& Context = GEditor->GetEditorWorldContext();
	UWorld* World = Context.World();
	if ( World )
	{
		TArray<UTexture2D*> LightMapsAndShadowMaps;
		World->GetLightMapsAndShadowMaps(World->GetCurrentLevel(), LightMapsAndShadowMaps);

		for ( auto ObjIt = LightMapsAndShadowMaps.CreateConstIterator(); ObjIt; ++ObjIt )
		{
			UTexture2D* CurrentObject = *ObjIt;
			if (CurrentObject)
			{
				FAssetData AssetData = FAssetData(CurrentObject);
				const uint32 ThumbnailResolution = 64;
				TSharedPtr<FAssetThumbnail> LightMapThumbnail = MakeShareable( new FAssetThumbnail( AssetData, ThumbnailResolution, ThumbnailResolution, ThumbnailPool ) );
				TSharedPtr<FLightmapItem> NewItem = MakeShareable( new FLightmapItem(CurrentObject->GetPathName(), LightMapThumbnail) );
				LightmapItems.Add(NewItem);
			}
		}
	}

	if ( LightmapListView.IsValid() )
	{
		LightmapListView->RequestListRefresh();
	}
}
	void CreateTileSetsFromTextures(TArray<UTexture2D*>& Textures)
	{
		const FString DefaultSuffix = TEXT("_TileSet");

		FAssetToolsModule& AssetToolsModule = FModuleManager::Get().LoadModuleChecked<FAssetToolsModule>("AssetTools");
		FContentBrowserModule& ContentBrowserModule = FModuleManager::LoadModuleChecked<FContentBrowserModule>("ContentBrowser");

		TArray<UObject*> ObjectsToSync;

		for (auto TextureIt = Textures.CreateConstIterator(); TextureIt; ++TextureIt)
		{
			UTexture2D* Texture = *TextureIt;

			// Create the factory used to generate the tile set
			UPaperTileSetFactory* TileSetFactory = NewObject<UPaperTileSetFactory>();
			TileSetFactory->InitialTexture = Texture;

			// Get a unique name for the tile set
			FString Name;
			FString PackageName;
			AssetToolsModule.Get().CreateUniqueAssetName(Texture->GetOutermost()->GetName(), DefaultSuffix, /*out*/ PackageName, /*out*/ Name);
			const FString PackagePath = FPackageName::GetLongPackagePath(PackageName);

			if (UObject* NewAsset = AssetToolsModule.Get().CreateAsset(Name, PackagePath, UPaperTileSet::StaticClass(), TileSetFactory))
			{
				ObjectsToSync.Add(NewAsset);
			}
		}

		if (ObjectsToSync.Num() > 0)
		{
			ContentBrowserModule.Get().SyncBrowserToAssets(ObjectsToSync);
		}
	}
UTexture2D* UTensorFlowBlueprintLibrary::Conv_FloatArrayToTexture2D(const TArray<float>& InFloatArray)
{
	//Create square image and lock for writing
	int32 Size = FMath::Pow(InFloatArray.Num(), 0.5);
	if (Size * Size != InFloatArray.Num())
	{
		UE_LOG(LogTemp, Warning, TEXT("Invalid float array, needs to be square."));
		return nullptr;
	}
	UTexture2D* Pointer = UTexture2D::CreateTransient(Size, Size, PF_R8G8B8A8);
	uint8* MipData = static_cast<uint8*>(Pointer->PlatformData->Mips[0].BulkData.Lock(LOCK_READ_WRITE));

	//Copy Data
	for (int i = 0; i < InFloatArray.Num(); i++)
	{
		int MipPointer = i * 4;
		int InverseValue = (1 - InFloatArray[i]) * 255.f;
		MipData[MipPointer] = InverseValue;
		MipData[MipPointer + 1] = InverseValue;
		MipData[MipPointer + 2] = InverseValue;
		MipData[MipPointer + 3] = 255;	//Alpha
	}

	//Unlock and Return data
	Pointer->PlatformData->Mips[0].BulkData.Unlock();
	Pointer->UpdateResource();
	return Pointer;
}
Exemplo n.º 5
1
void UFont::PostLoad()
{
	Super::PostLoad();

	// Cache the character count and the maximum character height for this font
	CacheCharacterCountAndMaxCharHeight();

	for( int32 TextureIndex = 0 ; TextureIndex < Textures.Num() ; ++TextureIndex )
	{
		UTexture2D* Texture = Textures[TextureIndex];
		if( Texture )
		{	
			Texture->SetFlags(RF_Public);
			Texture->LODGroup = TEXTUREGROUP_UI;

			// Fix up compression type for distance field fonts.
			if (Texture->CompressionSettings == TC_Displacementmap && !Texture->SRGB)
			{
				Texture->ConditionalPostLoad();
				Texture->CompressionSettings = TC_DistanceFieldFont;
				Texture->UpdateResource();
			}
		}
	}
}
Exemplo n.º 6
1
void UMaterialInterface::SetForceMipLevelsToBeResident( bool OverrideForceMiplevelsToBeResident, bool bForceMiplevelsToBeResidentValue, float ForceDuration, int32 CinematicTextureGroups )
{
	TArray<UTexture*> Textures;
	
	GetUsedTextures(Textures, EMaterialQualityLevel::Num, false, ERHIFeatureLevel::Num, true);
	for ( int32 TextureIndex=0; TextureIndex < Textures.Num(); ++TextureIndex )
	{
		UTexture2D* Texture = Cast<UTexture2D>(Textures[TextureIndex]);
		if ( Texture )
		{
			Texture->SetForceMipLevelsToBeResident( ForceDuration, CinematicTextureGroups );
			if (OverrideForceMiplevelsToBeResident)
			{
				Texture->bForceMiplevelsToBeResident = bForceMiplevelsToBeResidentValue;
			}
		}
	}
}
Exemplo n.º 7
1
UTexture2D* ULRRTextureManager::GetTexture(FString path, bool alpha) {
	TArray<uint8> RawFileData;
	FFileHelper::LoadFileToArray(RawFileData, *path, 0);
	if (RawFileData.Num() != 0)
	{
		IImageWrapperModule& ImageWrapperModule = FModuleManager::LoadModuleChecked<IImageWrapperModule>(FName(TEXT("ImageWrapper")));
		// Note: PNG format.  Other formats are supported
		IImageWrapperPtr ImageWrapper = ImageWrapperModule.CreateImageWrapper(EImageFormat::BMP);
		if (ImageWrapper.IsValid() && ImageWrapper->SetCompressed(RawFileData.GetData(), RawFileData.Num()))
		{
			const TArray<uint8>* UncompressedBGRA = nullptr;
			TArray<uint8> UncompressedRGBA;
			if (ImageWrapper->GetRaw(ERGBFormat::BGRA, 8, UncompressedBGRA))
			{
				// Create the UTexture for rendering
				UncompressedRGBA.AddZeroed(UncompressedBGRA->Num());
				for (int i = 0; UncompressedBGRA->Num() > i; i += 4) {
					UncompressedRGBA[i] = (*UncompressedBGRA)[i + 2];
					UncompressedRGBA[i + 1] = (*UncompressedBGRA)[i + 1];
					UncompressedRGBA[i + 2] = (*UncompressedBGRA)[i];
					UncompressedRGBA[i + 3] = (*UncompressedBGRA)[i + 3];
					if (alpha) {
						if ((UncompressedRGBA[i] + UncompressedRGBA[i + 1] + UncompressedRGBA[i + 2]) < 3) {
							UncompressedRGBA[i + 3] = 0;
						}
					}
				}

				UTexture2D* MyTexture = UTexture2D::CreateTransient(ImageWrapper->GetWidth(), ImageWrapper->GetHeight(), PF_R8G8B8A8);

				// Fill in the source data from the file
				uint8* TextureData = (uint8*)MyTexture->PlatformData->Mips[0].BulkData.Lock(LOCK_READ_WRITE);
				FMemory::Memcpy(TextureData, UncompressedRGBA.GetData(), UncompressedRGBA.Num());
				MyTexture->PlatformData->Mips[0].BulkData.Unlock();

				// Update the rendering resource from data.
				MyTexture->UpdateResource();
				return MyTexture;
			}
		}
	}
	return nullptr;
}
Exemplo n.º 8
0
void UFont::PostLoad()
{
	Super::PostLoad();


	// Cache the character count and the maximum character height for this font
	CacheCharacterCountAndMaxCharHeight();


	for( int32 TextureIndex = 0 ; TextureIndex < Textures.Num() ; ++TextureIndex )
	{
		UTexture2D* Texture = Textures[TextureIndex];
		if( Texture )
		{	
			Texture->SetFlags(RF_Public);
			Texture->LODGroup = TEXTUREGROUP_UI;	
		}
	}
}
void FPaperExtractSpritesViewportClient::Draw(FViewport* Viewport, FCanvas* Canvas)
{
	// Super will clear the viewport 
	FPaperEditorViewportClient::Draw(Viewport, Canvas);

	UTexture2D* Texture = TextureBeingExtracted.Get();

	if (Texture != nullptr)
	{
		const bool bUseTranslucentBlend = Texture->HasAlphaChannel();

		// Fully stream in the texture before drawing it.
		Texture->SetForceMipLevelsToBeResident(30.0f);
		Texture->WaitForStreaming();

		FLinearColor TextureDrawColor = Settings->TextureTint;
		//FLinearColor RectOutlineColor = FLinearColor::Yellow;
		const FLinearColor RectOutlineColor = Settings->OutlineColor;

		const float XPos = -ZoomPos.X * ZoomAmount;
		const float YPos = -ZoomPos.Y * ZoomAmount;
		const float Width = Texture->GetSurfaceWidth() * ZoomAmount;
		const float Height = Texture->GetSurfaceHeight() * ZoomAmount;

		Canvas->DrawTile(XPos, YPos, Width, Height, 0.0f, 0.0f, 1.0f, 1.0f, TextureDrawColor, Texture->Resource, bUseTranslucentBlend);

		for (FPaperExtractedSprite Sprite : ExtractedSprites)
		{
			DrawRectangle(Canvas, RectOutlineColor, Sprite.Rect);
		}
	}
}
Exemplo n.º 10
0
void FCanvasTextItem::DrawStringInternal( class FCanvas* InCanvas, const FVector2D& DrawPos, const FLinearColor& InColour )
{		
	DrawnSize.X = 0.0f;
	FHitProxyId HitProxyId = InCanvas->GetHitProxyId();
	FTexture* LastTexture = NULL;
	UTexture2D* Tex = NULL;
	FVector2D InvTextureSize(1.0f,1.0f);
	const TArray< TCHAR >& Chars = Text.ToString().GetCharArray();
	// Draw all characters in string.
	for( int32 i=0; i < TextLen; i++ )
	{
		int32 Ch = (int32)Font->RemapChar(Chars[i]);

		// Process character if it's valid.
		if( Font->Characters.IsValidIndex(Ch) )
		{
			FFontCharacter& Char = Font->Characters[Ch];
			if( Font->Textures.IsValidIndex(Char.TextureIndex) && 
				(Tex=Font->Textures[Char.TextureIndex])!=NULL && 
				Tex->Resource != NULL )
			{
				if( LastTexture != Tex->Resource || BatchedElements == NULL )
				{
					FBatchedElementParameters* BatchedElementParameters = NULL;
					BatchedElements = InCanvas->GetBatchedElements(FCanvas::ET_Triangle, BatchedElementParameters, Tex->Resource, BlendMode, FontRenderInfo.GlowInfo);
					check(BatchedElements != NULL);
					// trade-off between memory and performance by pre-allocating more reserved space 
					// for the triangles/vertices of the batched elements used to render the text tiles
					//BatchedElements->AddReserveTriangles(TextLen*2,Tex->Resource,BlendMode);
					//BatchedElements->AddReserveVertices(TextLen*4);

					FIntPoint ImportedTextureSize = Tex->GetImportedSize();
					InvTextureSize.X = 1.0f / (float)ImportedTextureSize.X;
					InvTextureSize.Y = 1.0f / (float)ImportedTextureSize.Y;
				}
				LastTexture = Tex->Resource;

				const float X		= DrawnSize.X + DrawPos.X;
				const float Y		= DrawPos.Y + + Char.VerticalOffset * YScale;
				float SizeX			= Char.USize * XScale;
				const float SizeY	= Char.VSize * YScale;
				const float U		= Char.StartU * InvTextureSize.X;
				const float V		= Char.StartV * InvTextureSize.Y;
				const float SizeU	= Char.USize * InvTextureSize.X;
				const float SizeV	= Char.VSize * InvTextureSize.Y;				

				float Left, Top, Right, Bottom;
				Left = X * Depth;
				Top = Y * Depth;
				Right = (X + SizeX) * Depth;
				Bottom = (Y + SizeY) * Depth;

				int32 V00 = BatchedElements->AddVertex(
					FVector4( Left, Top, 0.f, Depth ),
					FVector2D( U, V ),
					InColour,
					HitProxyId );
				int32 V10 = BatchedElements->AddVertex(
					FVector4( Right, Top, 0.0f, Depth ),
					FVector2D( U + SizeU, V ),			
					InColour,
					HitProxyId );
				int32 V01 = BatchedElements->AddVertex(
					FVector4( Left, Bottom, 0.0f, Depth ),
					FVector2D( U, V + SizeV ),	
					InColour,
					HitProxyId);
				int32 V11 = BatchedElements->AddVertex(
					FVector4( Right, Bottom, 0.0f, Depth ),
					FVector2D( U + SizeU, V + SizeV ),
					InColour,
					HitProxyId);

				BatchedElements->AddTriangle(V00, V10, V11, Tex->Resource, BlendMode, FontRenderInfo.GlowInfo);
				BatchedElements->AddTriangle(V00, V11, V01, Tex->Resource, BlendMode, FontRenderInfo.GlowInfo);

				// if we have another non-whitespace character to render, add the font's kerning.
				if ( Chars[i+1] && !FChar::IsWhitespace(Chars[i+1]) )
				{
					SizeX += CharIncrement;
				}

				// Update the current rendering position
				DrawnSize.X += SizeX;
			}
		}
	}
}
Exemplo n.º 11
0
UTexture2D * UAdvancedFriendsLibrary::GetSteamFriendAvatar(APlayerController *PlayerController, const FBPUniqueNetId UniqueNetId, SteamAvatarSize AvatarSize)
{
	if (!PlayerController)
	{
		UE_LOG(AdvancedFriendsLog, Warning, TEXT("IsAFriend Had a bad Player Controller!"));
		return nullptr;
	}

	if (!UniqueNetId.IsValid() || !UniqueNetId.UniqueNetId->IsValid())
	{
		UE_LOG(AdvancedFriendsLog, Warning, TEXT("IsAFriend Had a bad UniqueNetId!"));
		return nullptr;
	}

	uint32 Width = 0;
	uint32 Height = 0;

	if (SteamAPI_Init())
	{
		//Getting the PictureID from the SteamAPI and getting the Size with the ID
		//virtual bool RequestUserInformation( CSteamID steamIDUser, bool bRequireNameOnly ) = 0;

		
		uint64 id = *((uint64*)UniqueNetId.UniqueNetId->GetBytes());
		int Picture = 0;
		
		switch(AvatarSize)
		{
		case SteamAvatarSize::SteamAvatar_Small: Picture = SteamFriends()->GetSmallFriendAvatar(id); break;
		case SteamAvatarSize::SteamAvatar_Medium: Picture = SteamFriends()->GetMediumFriendAvatar(id); break;
		case SteamAvatarSize::SteamAvatar_Large: Picture = SteamFriends()->GetLargeFriendAvatar(id); break;
		default: break;
		}

		if (Picture == -1)
			return NULL;

		SteamUtils()->GetImageSize(Picture, &Width, &Height);

		// STOLEN FROM ANSWERHUB :p

		if (Width > 0 && Height > 0)
		{
			//Creating the buffer "oAvatarRGBA" and then filling it with the RGBA Stream from the Steam Avatar
			uint8 *oAvatarRGBA = new uint8[Width * Height * 4];


			//Filling the buffer with the RGBA Stream from the Steam Avatar and creating a UTextur2D to parse the RGBA Steam in
			SteamUtils()->GetImageRGBA(Picture, (uint8*)oAvatarRGBA, 4 * Height * Width * sizeof(char));


			// Removed as I changed the image bit code to be RGB
			/*
			//Swap R and B channels because for some reason the games whack
			for (uint32 i = 0; i < (Width * Height * 4); i += 4)
			{
				uint8 Temp = oAvatarRGBA[i + 0];
				oAvatarRGBA[i + 0] = oAvatarRGBA[i + 2];
				oAvatarRGBA[i + 2] = Temp;
			}*/

			UTexture2D* Avatar = UTexture2D::CreateTransient(Width, Height, PF_R8G8B8A8);

			uint8* MipData = (uint8*)Avatar->PlatformData->Mips[0].BulkData.Lock(LOCK_READ_WRITE);
			FMemory::Memcpy(MipData, (void*)oAvatarRGBA, Height * Width * 4);
			Avatar->PlatformData->Mips[0].BulkData.Unlock();

			// Original implementation was missing this!!
			// the hell man......
			delete[] oAvatarRGBA;

			//Setting some Parameters for the Texture and finally returning it
			Avatar->PlatformData->NumSlices = 1;
			Avatar->NeverStream = true;
			//Avatar->CompressionSettings = TC_EditorIcon;

			Avatar->UpdateResource();

			return Avatar;
		}
		else
		{
			UE_LOG(AdvancedFriendsLog, Warning, TEXT("Bad Height / Width with steam avatar!"));
		}

		return nullptr;
	}

	UE_LOG(AdvancedFriendsLog, Warning, TEXT("STEAM Couldn't be verified as initialized"));
	return nullptr;
}
	void CreateSpritesFromTextures(TArray<UTexture2D*>& Textures)
	{
		const FString DefaultSuffix = TEXT("_Sprite");

		FAssetToolsModule& AssetToolsModule = FModuleManager::Get().LoadModuleChecked<FAssetToolsModule>("AssetTools");
		FContentBrowserModule& ContentBrowserModule = FModuleManager::LoadModuleChecked<FContentBrowserModule>("ContentBrowser");

		TArray<UObject*> ObjectsToSync;

		for (auto TextureIt = Textures.CreateConstIterator(); TextureIt; ++TextureIt)
		{
			UTexture2D* Texture = *TextureIt;

			// Create the factory used to generate the sprite
			UPaperSpriteFactory* SpriteFactory = ConstructObject<UPaperSpriteFactory>(UPaperSpriteFactory::StaticClass());
			SpriteFactory->InitialTexture = Texture;

			// Create the sprite
			FString Name;
			FString PackageName;

			if (!bExtractSprites)
			{
				// Get a unique name for the sprite
				AssetToolsModule.Get().CreateUniqueAssetName(Texture->GetOutermost()->GetName(), DefaultSuffix, /*out*/ PackageName, /*out*/ Name);
				const FString PackagePath = FPackageName::GetLongPackagePath(PackageName);

				if (UObject* NewAsset = AssetToolsModule.Get().CreateAsset(Name, PackagePath, UPaperSprite::StaticClass(), SpriteFactory))
				{
					ObjectsToSync.Add(NewAsset);
				}
			}
			else
			{
				FScopedSlowTask Feedback(1, NSLOCTEXT("Paper2D", "Paper2D_ExtractSpritesFromTexture", "Extracting Sprites From Texture"));
				Feedback.MakeDialog(true);

				// First extract the rects from the texture
				TArray<FIntRect> ExtractedRects;
				UPaperSprite::ExtractRectsFromTexture(Texture, /*out*/ ExtractedRects);

				// Sort the rectangles by approximate row
				struct FRectangleSortHelper
				{
					FRectangleSortHelper(TArray<FIntRect>& InOutSprites)
					{
						// Sort by Y, then by X (top left corner), descending order (so we can use it as a stack from the top row down)
						TArray<FIntRect> SpritesLeft = InOutSprites;
						SpritesLeft.Sort([](const FIntRect& A, const FIntRect& B) { return (A.Min.Y == B.Min.Y) ? (A.Min.X > B.Min.X) : (A.Min.Y > B.Min.Y); });
						InOutSprites.Reset();

						// Start pulling sprites out, the first one in each row will dominate remaining ones and cause them to get labeled
						TArray<FIntRect> DominatedSprites;
						DominatedSprites.Empty(SpritesLeft.Num());
 						while (SpritesLeft.Num())
 						{
							FIntRect DominatingSprite = SpritesLeft.Pop();
							DominatedSprites.Add(DominatingSprite);

							// Find the sprites that are dominated (intersect the infinite horizontal band described by the dominating sprite)
							for (int32 Index = 0; Index < SpritesLeft.Num();)
							{
								const FIntRect& CurElement = SpritesLeft[Index];
								if ((CurElement.Min.Y <= DominatingSprite.Max.Y) && (CurElement.Max.Y >= DominatingSprite.Min.Y))
								{
									DominatedSprites.Add(CurElement);
									SpritesLeft.RemoveAt(Index, /*Count=*/ 1, /*bAllowShrinking=*/ false);
								}
								else
								{
									++Index;
								}
							}

							// Sort the sprites in the band by X and add them to the result
							DominatedSprites.Sort([](const FIntRect& A, const FIntRect& B) { return (A.Min.X < B.Min.X); });
							InOutSprites.Append(DominatedSprites);
							DominatedSprites.Reset();
 						}
					}
				};
				FRectangleSortHelper RectSorter(ExtractedRects);

				Feedback.TotalAmountOfWork = ExtractedRects.Num();

				for (int ExtractedRectIndex = 0; ExtractedRectIndex < ExtractedRects.Num(); ++ExtractedRectIndex)
				{
					Feedback.EnterProgressFrame(1, NSLOCTEXT("Paper2D", "Paper2D_ExtractSpritesFromTexture", "Extracting Sprites From Texture"));

					FIntRect& ExtractedRect = ExtractedRects[ExtractedRectIndex];
					SpriteFactory->bUseSourceRegion = true;
					SpriteFactory->InitialSourceUV = FVector2D(ExtractedRect.Min.X, ExtractedRect.Min.Y);
					SpriteFactory->InitialSourceDimension = FVector2D(ExtractedRect.Width(), ExtractedRect.Height());

					// Get a unique name for the sprite
					const FString Suffix = FString::Printf(TEXT("%s_%d"), *DefaultSuffix, ExtractedRectIndex);
					AssetToolsModule.Get().CreateUniqueAssetName(Texture->GetOutermost()->GetName(), Suffix, /*out*/ PackageName, /*out*/ Name);
					const FString PackagePath = FPackageName::GetLongPackagePath(PackageName);

					if (UObject* NewAsset = AssetToolsModule.Get().CreateAsset(Name, PackagePath, UPaperSprite::StaticClass(), SpriteFactory))
					{
						ObjectsToSync.Add(NewAsset);
					}

					if (GWarn->ReceivedUserCancel()) 
					{
						break;
					}
				}
			}
		}

		if (ObjectsToSync.Num() > 0)
		{
			ContentBrowserModule.Get().SyncBrowserToAssets(ObjectsToSync);
		}
	}
Exemplo n.º 13
0
void FEdMode::DrawHUD(FEditorViewportClient* ViewportClient,FViewport* Viewport,const FSceneView* View,FCanvas* Canvas)
{
    // Render the drag tool.
    ViewportClient->RenderDragTool( View, Canvas );

    // Let the current mode tool draw a HUD if it wants to
    FModeTool* tool = GetCurrentTool();
    if( tool )
    {
        tool->DrawHUD( ViewportClient, Viewport, View, Canvas );
    }

    if (ViewportClient->IsPerspective() && GetDefault<ULevelEditorViewportSettings>()->bHighlightWithBrackets)
    {
        DrawBrackets( ViewportClient, Viewport, View, Canvas );
    }

    // If this viewport doesn't show mode widgets or the mode itself doesn't want them, leave.
    if( !(ViewportClient->EngineShowFlags.ModeWidgets) || !ShowModeWidgets() )
    {
        return;
    }

    // Clear Hit proxies
    const bool bIsHitTesting = Canvas->IsHitTesting();
    if ( !bIsHitTesting )
    {
        Canvas->SetHitProxy(NULL);
    }

    // Draw vertices for selected BSP brushes and static meshes if the large vertices show flag is set.
    if ( !ViewportClient->bDrawVertices )
    {
        return;
    }

    const bool bLargeVertices		= View->Family->EngineShowFlags.LargeVertices;
    const bool bShowBrushes			= View->Family->EngineShowFlags.Brushes;
    const bool bShowBSP				= View->Family->EngineShowFlags.BSP;
    const bool bShowBuilderBrush	= View->Family->EngineShowFlags.BuilderBrush != 0;

    UTexture2D* VertexTexture = GetVertexTexture();
    const float TextureSizeX		= VertexTexture->GetSizeX() * ( bLargeVertices ? 1.0f : 0.5f );
    const float TextureSizeY		= VertexTexture->GetSizeY() * ( bLargeVertices ? 1.0f : 0.5f );

    // Temporaries.
    TArray<FVector> Vertices;

    for ( FSelectionIterator It( *Owner->GetSelectedActors() ) ; It ; ++It )
    {
        AActor* SelectedActor = static_cast<AActor*>( *It );
        checkSlow( SelectedActor->IsA(AActor::StaticClass()) );

        if( bLargeVertices )
        {
            FCanvasItemTestbed::bTestState = !FCanvasItemTestbed::bTestState;

            // Static mesh vertices
            AStaticMeshActor* Actor = Cast<AStaticMeshActor>( SelectedActor );
            if( Actor && Actor->GetStaticMeshComponent() && Actor->GetStaticMeshComponent()->StaticMesh
                    && Actor->GetStaticMeshComponent()->StaticMesh->RenderData )
            {
                FTransform ActorToWorld = Actor->ActorToWorld();
                Vertices.Empty();
                const FPositionVertexBuffer& VertexBuffer = Actor->GetStaticMeshComponent()->StaticMesh->RenderData->LODResources[0].PositionVertexBuffer;
                for( uint32 i = 0 ; i < VertexBuffer.GetNumVertices() ; i++ )
                {
                    Vertices.AddUnique( ActorToWorld.TransformPosition( VertexBuffer.VertexPosition(i) ) );
                }

                FCanvasTileItem TileItem( FVector2D( 0.0f, 0.0f ), FVector2D( 0.0f, 0.0f ), FLinearColor::White );
                TileItem.BlendMode = SE_BLEND_Translucent;
                for( int32 VertexIndex = 0 ; VertexIndex < Vertices.Num() ; ++VertexIndex )
                {
                    const FVector& Vertex = Vertices[VertexIndex];
                    FVector2D PixelLocation;
                    if(View->ScreenToPixel(View->WorldToScreen(Vertex),PixelLocation))
                    {
                        const bool bOutside =
                            PixelLocation.X < 0.0f || PixelLocation.X > View->ViewRect.Width() ||
                            PixelLocation.Y < 0.0f || PixelLocation.Y > View->ViewRect.Height();
                        if( !bOutside )
                        {
                            const float X = PixelLocation.X - (TextureSizeX/2);
                            const float Y = PixelLocation.Y - (TextureSizeY/2);
                            if( bIsHitTesting )
                            {
                                Canvas->SetHitProxy( new HStaticMeshVert(Actor,Vertex) );
                            }
                            TileItem.Texture = VertexTexture->Resource;

                            TileItem.Size = FVector2D( TextureSizeX, TextureSizeY );
                            Canvas->DrawItem( TileItem, FVector2D( X, Y ) );
                            if( bIsHitTesting )
                            {
                                Canvas->SetHitProxy( NULL );
                            }
                        }
                    }
                }
            }
        }
    }

    if(UsesPropertyWidgets())
    {
        AActor* SelectedActor = GetFirstSelectedActorInstance();
        if (SelectedActor != NULL)
        {
            FEditorScriptExecutionGuard ScriptGuard;

            const int32 HalfX = 0.5f * Viewport->GetSizeXY().X;
            const int32 HalfY = 0.5f * Viewport->GetSizeXY().Y;

            UClass* Class = SelectedActor->GetClass();
            TArray<FPropertyWidgetInfo> WidgetInfos;
            GetPropertyWidgetInfos(Class, SelectedActor, WidgetInfos);
            for(int32 i=0; i<WidgetInfos.Num(); i++)
            {
                FString WidgetName = WidgetInfos[i].PropertyName;
                FName WidgetValidator = WidgetInfos[i].PropertyValidationName;
                int32 WidgetIndex = WidgetInfos[i].PropertyIndex;
                bool bIsTransform = WidgetInfos[i].bIsTransform;

                FVector LocalPos = FVector::ZeroVector;
                if(bIsTransform)
                {
                    FTransform LocalTM = GetPropertyValueByName<FTransform>(SelectedActor, WidgetName, WidgetIndex);
                    LocalPos = LocalTM.GetLocation();
                }
                else
                {
                    LocalPos = GetPropertyValueByName<FVector>(SelectedActor, WidgetName, WidgetIndex);
                }

                FTransform ActorToWorld = SelectedActor->ActorToWorld();
                FVector WorldPos = ActorToWorld.TransformPosition(LocalPos);

                UFunction* ValidateFunc = NULL;
                FString FinalString;
                if(WidgetValidator != NAME_None &&
                        (ValidateFunc = SelectedActor->FindFunction(WidgetValidator)) != NULL)
                {
                    SelectedActor->ProcessEvent(ValidateFunc, &FinalString);
                }

                const FPlane Proj = View->Project( WorldPos );

                //do some string fixing
                const uint32 VectorIndex = WidgetInfos[i].PropertyIndex;
                const FString WidgetDisplayName = WidgetInfos[i].DisplayName + ((VectorIndex != INDEX_NONE) ? FString::Printf(TEXT("[%d]"), VectorIndex) : TEXT(""));
                FinalString = FinalString.IsEmpty() ? WidgetDisplayName : FinalString;

                if(Proj.W > 0.f)
                {
                    const int32 XPos = HalfX + ( HalfX * Proj.X );
                    const int32 YPos = HalfY + ( HalfY * (Proj.Y * -1.f) );
                    FCanvasTextItem TextItem( FVector2D( XPos + 5, YPos), FText::FromString( FinalString ), GEngine->GetSmallFont(), FLinearColor::White );
                    Canvas->DrawItem( TextItem );
                }
            }
        }
    }
}
Exemplo n.º 14
0
void UJanusExporterTool::Export()
{
	TArray<UObject*> ObjectsToExport;

	FString Root = FString(ExportPath); // copy so we dont mess with the original reference
	FString Index = "<html>\n\t<head>\n\t\t<title>Unreal Export</title>\n\t</head>\n\t<body>\n\t\t<FireBoxRoom>\n\t\t\t<Assets>";

	TArray<AActor*> ActorsExported;
	TArray<UStaticMesh*> StaticMeshesExp;
	TArray<FString> TexturesExp;
	TArray<FString> MaterialsExported;

	for (TObjectIterator<AActor> Itr; Itr; ++Itr)
	{
		AActor *Actor = *Itr;

		FString Name = Actor->GetName();
		/*if (!Name.StartsWith("SM_Floor_R"))
		{
			continue;
		}*/

		if (Actor->IsHiddenEd())
		{
			continue;
		}

		ActorsExported.Add(Actor);

		TArray<UStaticMeshComponent*> StaticMeshes;
		Actor->GetComponents<UStaticMeshComponent>(StaticMeshes);
		for (int32 i = 0; i < StaticMeshes.Num(); i++)
		{
			UStaticMeshComponent* Component = StaticMeshes[i];
			UStaticMesh *Mesh = Component->StaticMesh;
			if (!Mesh)
			{
				continue;
			}

			if (Component->LODData.Num() > 0)
				//if (false)
			{
				FStaticMeshComponentLODInfo* LODInfo = &Component->LODData[0];
				FLightMap* LightMap = LODInfo->LightMap;
				FShadowMap* ShadowMap = LODInfo->ShadowMap;
				if (LightMap != NULL)
				{
					FLightMap2D* LightMap2D = LightMap->GetLightMap2D();
					UTexture2D* Texture = LightMap2D->GetTexture(0); // 0 = HQ LightMap
					FString TexName = Texture->GetName();
					if (TexturesExp.Contains(TexName))
					{
						continue;
					}

					TexturesExp.Add(TexName);
					ExportPNG(Texture, Root);
				}
				if (ShadowMap != NULL)
				{
					FShadowMap2D* ShadowMap2D = ShadowMap->GetShadowMap2D();
					UShadowMapTexture2D* ShadowTex = ShadowMap2D->GetTexture();
					FString TexName = ShadowTex->GetName();
					if (TexturesExp.Contains(TexName))
					{
						continue;
					}

					TexturesExp.Add(TexName);
					ExportPNG(ShadowTex, Root);
				}
			}

			if (!StaticMeshesExp.Contains(Mesh))
			{
				StaticMeshesExp.Add(Mesh);
				ExportFBX(Mesh, Root);
			}

			TArray<UMaterialInterface*> Materials = Component->GetMaterials();
			for (int32 j = 0; j < Materials.Num(); j++)
			{
				UMaterialInterface* Material = Materials[j];
				if (!Material)
				{
					continue;
				}

				FString MatName = Material->GetName();

				if (MaterialsExported.Contains(MatName))
				{
					continue;
				}

				MaterialsExported.Add(MatName);
				ExportMaterial(Root, Material, &TexturesExp);
			}
		}
	}

	// Models before textures so we can start showing the scene faster (textures take too long to load)
	for (int32 i = 0; i < StaticMeshesExp.Num(); i++)
	{
		UStaticMesh *mesh = StaticMeshesExp[i];

		Index.Append("\n\t\t\t\t<AssetObject id=\"" + mesh->GetName() + "\" src=\"" + mesh->GetName() + ".fbx\" />");
	}

	for (int32 i = 0; i < TexturesExp.Num(); i++)
	{
		FString Path = TexturesExp[i];

		Index.Append("\n\t\t\t\t<AssetImage id=\"" + Path + "\" src=\"" + Path + ".png\" />");
	}

	Index.Append("\n\t\t\t</Assets>\n\t\t\t<Room>");

	for (int32 i = 0; i < ActorsExported.Num(); i++)
	{
		AActor *Actor = ActorsExported[i];

		TArray<UStaticMeshComponent*> StaticMeshes;
		Actor->GetComponents<UStaticMeshComponent>(StaticMeshes);
		for (int32 i = 0; i < StaticMeshes.Num(); i++)
		{
			UStaticMeshComponent* Component = StaticMeshes[i];
			UStaticMesh *Mesh = Component->StaticMesh;
			if (!Mesh)
			{
				continue;
			}

			FString ImageID = "";

			TArray<UMaterialInterface*> Materials = Component->GetMaterials();
			for (int32 j = 0; j < Materials.Num(); j++)
			{
				UMaterialInterface* Material = Materials[j];
				if (!Material)
				{
					continue;
				}
				ImageID = Material->GetName() + "_BaseColor";
				break;
			}

			if (ImageID == "")
			{
				Index.Append("\n\t\t\t\t<Object collision_id=\"" + Mesh->GetName() + "\" id=\"" + Mesh->GetName() + "\" lighting=\"true\" pos=\"");
			}
			else
			{
				Index.Append("\n\t\t\t\t<Object collision_id=\"" + Mesh->GetName() + "\" id=\"" + Mesh->GetName() + "\" image_id=\"" + ImageID + "\" lighting=\"true\" pos=\"");
			}

			FRotator Rot = Actor->GetActorRotation();
			FVector XDir = Rot.RotateVector(FVector::RightVector);
			FVector YDir = Rot.RotateVector(FVector::UpVector);
			FVector ZDir = Rot.RotateVector(FVector::ForwardVector);

			FVector Pos = Actor->GetActorLocation() * UniformScale;
			FVector Sca = Actor->GetActorScale();

			Pos = ChangeSpace(Pos);
			Sca = ChangeSpaceScalar(Sca) * UniformScale;

			XDir = ChangeSpace(XDir);
			YDir = ChangeSpace(YDir);
			ZDir = ChangeSpace(ZDir);
			FVector Sign = GetSignVector(Sca);

			Index.Append(FString::SanitizeFloat(Pos.X) + " " + FString::SanitizeFloat(Pos.Y) + " " + FString::SanitizeFloat(Pos.Z));
			if (Sca.X < 0 || Sca.Y < 0 || Sca.Z < 0)
			{
				Index.Append("\" cull_face=\"front");
			}

			Index.Append("\" scale=\"");
			Index.Append(FString::SanitizeFloat(Sca.X) + " " + FString::SanitizeFloat(Sca.Y) + " " + FString::SanitizeFloat(Sca.Z));

			Index.Append("\" xdir=\"");
			Index.Append(FString::SanitizeFloat(XDir.X) + " " + FString::SanitizeFloat(XDir.Y) + " " + FString::SanitizeFloat(XDir.Z));

			Index.Append("\" ydir=\"");
			Index.Append(FString::SanitizeFloat(YDir.X) + " " + FString::SanitizeFloat(YDir.Y) + " " + FString::SanitizeFloat(YDir.Z));

			Index.Append("\" zdir=\"");
			Index.Append(FString::SanitizeFloat(ZDir.X) + " " + FString::SanitizeFloat(ZDir.Y) + " " + FString::SanitizeFloat(ZDir.Z));

			Index.Append("\" />");
		}
	}

	Index.Append("\n\t\t\t</Room>\n\t\t</FireBoxRoom>\n\t</body>\n</html>");

	FString IndexPath = FString(ExportPath).Append("index.html");
	FFileHelper::SaveStringToFile(Index, *IndexPath);
}
Exemplo n.º 15
0
void UPaperTileMapComponent::RebuildRenderData(FPaperTileMapRenderSceneProxy* Proxy)
{
	TArray<FSpriteDrawCallRecord> BatchedSprites;
	
	if (TileMap == nullptr)
	{
		return;
	}

	FVector CornerOffset;
	FVector OffsetYFactor;
	FVector StepPerTileX;
	FVector StepPerTileY;
	TileMap->GetTileToLocalParameters(/*out*/ CornerOffset, /*out*/ StepPerTileX, /*out*/ StepPerTileY, /*out*/ OffsetYFactor);
	
	UTexture2D* LastSourceTexture = nullptr;
	FVector TileSetOffset = FVector::ZeroVector;
	FVector2D InverseTextureSize(1.0f, 1.0f);
	FVector2D SourceDimensionsUV(1.0f, 1.0f);
	FVector2D TileSizeXY(0.0f, 0.0f);

	for (int32 Z = 0; Z < TileMap->TileLayers.Num(); ++Z)
	{
		UPaperTileLayer* Layer = TileMap->TileLayers[Z];

		if (Layer == nullptr)
		{
			continue;
		}

		FLinearColor DrawColor = FLinearColor::White;
#if WITH_EDITORONLY_DATA
		if (Layer->bHiddenInEditor)
		{
			continue;
		}

		DrawColor.A = Layer->LayerOpacity;
#endif

		FSpriteDrawCallRecord* CurrentBatch = nullptr;

		for (int32 Y = 0; Y < TileMap->MapHeight; ++Y)
		{
			// In pixels
			FVector EffectiveTopLeftCorner;

			switch (TileMap->ProjectionMode)
			{
			case ETileMapProjectionMode::Orthogonal:
			default:
				EffectiveTopLeftCorner = CornerOffset;
				break;
			case ETileMapProjectionMode::IsometricDiamond:
				EffectiveTopLeftCorner = CornerOffset - StepPerTileX;
				break;
			case ETileMapProjectionMode::IsometricStaggered:
			case ETileMapProjectionMode::HexagonalStaggered:
				EffectiveTopLeftCorner = CornerOffset + (Y & 1) * OffsetYFactor;
				break;
			}

			for (int32 X = 0; X < TileMap->MapWidth; ++X)
			{
				const FPaperTileInfo TileInfo = Layer->GetCell(X, Y);

				// do stuff
				const float TotalSeparation = (TileMap->SeparationPerLayer * Z) + (TileMap->SeparationPerTileX * X) + (TileMap->SeparationPerTileY * Y);
				FVector TopLeftCornerOfTile = (StepPerTileX * X) + (StepPerTileY * Y) + EffectiveTopLeftCorner;
				TopLeftCornerOfTile += TotalSeparation * PaperAxisZ;

				const int32 TileWidth = TileMap->TileWidth;
				const int32 TileHeight = TileMap->TileHeight;


				{
					UTexture2D* SourceTexture = nullptr;

					FVector2D SourceUV = FVector2D::ZeroVector;
					if (Layer->bCollisionLayer)
					{
						if (TileInfo.PackedTileIndex == 0)
						{
							continue;
						}
						SourceTexture = UCanvas::StaticClass()->GetDefaultObject<UCanvas>()->DefaultTexture;
					}
					else
					{
						if (TileInfo.TileSet == nullptr)
						{
							continue;
						}

						if (!TileInfo.TileSet->GetTileUV(TileInfo.PackedTileIndex, /*out*/ SourceUV))
						{
							continue;
						}

						SourceTexture = TileInfo.TileSet->TileSheet;
						if (SourceTexture == nullptr)
						{
							continue;
						}
					}

					if ((SourceTexture != LastSourceTexture) || (CurrentBatch == nullptr))
					{
						CurrentBatch = (new (BatchedSprites) FSpriteDrawCallRecord());
						CurrentBatch->Texture = SourceTexture;
						CurrentBatch->Color = DrawColor;
						CurrentBatch->Destination = TopLeftCornerOfTile.ProjectOnTo(PaperAxisZ);
					}

					if (SourceTexture != LastSourceTexture)
					{
						InverseTextureSize = FVector2D(1.0f / SourceTexture->GetSizeX(), 1.0f / SourceTexture->GetSizeY());

						if (TileInfo.TileSet != nullptr)
						{
							SourceDimensionsUV = FVector2D(TileInfo.TileSet->TileWidth * InverseTextureSize.X, TileInfo.TileSet->TileHeight * InverseTextureSize.Y);
							TileSizeXY = FVector2D(TileInfo.TileSet->TileWidth, TileInfo.TileSet->TileHeight);
							TileSetOffset = (TileInfo.TileSet->DrawingOffset.X * PaperAxisX) + (TileInfo.TileSet->DrawingOffset.Y * PaperAxisY);
						}
						else
						{
							SourceDimensionsUV = FVector2D(TileWidth * InverseTextureSize.X, TileHeight * InverseTextureSize.Y);
							TileSizeXY = FVector2D(TileWidth, TileHeight);
							TileSetOffset = FVector::ZeroVector;
						}
						LastSourceTexture = SourceTexture;
					}
					TopLeftCornerOfTile += TileSetOffset;

					SourceUV.X *= InverseTextureSize.X;
					SourceUV.Y *= InverseTextureSize.Y;

					FSpriteDrawCallRecord& NewTile = *CurrentBatch;

					const float WX0 = FVector::DotProduct(TopLeftCornerOfTile, PaperAxisX);
					const float WY0 = FVector::DotProduct(TopLeftCornerOfTile, PaperAxisY);

					const FVector4 BottomLeft(WX0, WY0 - TileSizeXY.Y, SourceUV.X, SourceUV.Y + SourceDimensionsUV.Y);
					const FVector4 BottomRight(WX0 + TileSizeXY.X, WY0 - TileSizeXY.Y, SourceUV.X + SourceDimensionsUV.X, SourceUV.Y + SourceDimensionsUV.Y);
					const FVector4 TopRight(WX0 + TileSizeXY.X, WY0, SourceUV.X + SourceDimensionsUV.X, SourceUV.Y);
					const FVector4 TopLeft(WX0, WY0, SourceUV.X, SourceUV.Y);

					new (NewTile.RenderVerts) FVector4(BottomLeft);
					new (NewTile.RenderVerts) FVector4(TopRight);
					new (NewTile.RenderVerts) FVector4(BottomRight);

					new (NewTile.RenderVerts) FVector4(BottomLeft);
					new (NewTile.RenderVerts) FVector4(TopLeft);
					new (NewTile.RenderVerts) FVector4(TopRight);
				}
			}
		}
	}

	Proxy->SetBatchesHack(BatchedSprites);
}
UObject* USspjFactory::FactoryCreateBinary(UClass* InClass, UObject* InParent, FName InName, EObjectFlags Flags, UObject* Context, const TCHAR* Type, const uint8*& Buffer, const uint8* InBufferEnd, FFeedbackContext* Warn)
{
	bool bReimport = this->IsA(UReimportSspjFactory::StaticClass());
	TMap<FString, UTexture*>* ExistImages = NULL;
	if(bReimport)
	{
		ExistImages = &(Cast<UReimportSspjFactory>(this)->ExistImages);
	}

	FAssetToolsModule& AssetToolsModule = FModuleManager::LoadModuleChecked<FAssetToolsModule>("AssetTools");

	FString ProjectNameStr = InName.ToString();
	FName ProjectName = InName;

	UPackage* InParentPackage = Cast<UPackage>(InParent);
	if(InParentPackage && !bReimport)
	{
		FString ProjectPackageName;
		FString BasePackageName = FPackageName::GetLongPackagePath(InParent->GetOutermost()->GetName()) / ProjectNameStr;
		AssetToolsModule.Get().CreateUniqueAssetName(BasePackageName, TEXT(""), ProjectPackageName, ProjectNameStr);
		InParentPackage->Rename(*ProjectPackageName);
	}

	// インポート設定の取得 
	const USsImportSettings* ImportSettings = GetDefault<USsImportSettings>();

	// インポート開始 
	FEditorDelegates::OnAssetPreImport.Broadcast(this, InClass, InParent, ProjectName, Type);

	// sspj
	USsProject* NewProject = FSsLoader::LoadSsProject(InParent, ProjectName, Flags, Buffer, (InBufferEnd - Buffer) + 1);
	NewProject->SetFilepath( GetCurrentFilename() );
	if(NewProject)
	{
		if(NewProject->AssetImportData == nullptr)
		{
			NewProject->AssetImportData = NewObject<UAssetImportData>(NewProject);
		}
		NewProject->AssetImportData->Update(CurrentFilename);

		FString CurPath = FPaths::GetPath(GetCurrentFilename());

		TArray<FString> ImagePaths;
		TArray<SsTexWrapMode::Type> ImageWrapModes;
		TArray<SsTexFilterMode::Type> ImageFilterModes;

		// ssce
		NewProject->CellmapList.Empty();
		NewProject->CellmapList.AddZeroed(NewProject->CellmapNames.Num());
		for(int i = 0; i < NewProject->CellmapNames.Num(); ++i)
		{
			FString FileName = GetFilePath(CurPath, NewProject->Settings.CellMapBaseDirectory, NewProject->CellmapNames[i].ToString());

			TArray<uint8> Data;
			if(FFileHelper::LoadFileToArray(Data, *FileName))
			{
				const uint8* BufferBegin = Data.GetData();
				const uint8* BufferEnd = BufferBegin + Data.Num() - 1;
				if(FSsLoader::LoadSsCellMap(&(NewProject->CellmapList[i]), BufferBegin, (BufferEnd - BufferBegin) + 1))
				{
					NewProject->CellmapList[i].FileName = NewProject->CellmapNames[i];
					if(0 < NewProject->CellmapList[i].ImagePath.Len())
					{
						if(INDEX_NONE == ImagePaths.Find(NewProject->CellmapList[i].ImagePath))
						{
							ImagePaths.Add(NewProject->CellmapList[i].ImagePath);
							if(NewProject->CellmapList[i].OverrideTexSettings)
							{
								ImageWrapModes.Add(NewProject->CellmapList[i].WrapMode);
								ImageFilterModes.Add(NewProject->CellmapList[i].FilterMode);
							}
							else
							{
								ImageWrapModes.Add(NewProject->Settings.WrapMode);
								ImageFilterModes.Add(NewProject->Settings.FilterMode);
							}
						}
					}
				}
			}
		}

		// ssae
		NewProject->AnimeList.Empty();
		NewProject->AnimeList.AddZeroed(NewProject->AnimepackNames.Num());
		for(int i = 0; i < NewProject->AnimepackNames.Num(); ++i)
		{
			FString FileName = GetFilePath(CurPath, NewProject->Settings.AnimeBaseDirectory, NewProject->AnimepackNames[i].ToString());

			TArray<uint8> Data;
			if(FFileHelper::LoadFileToArray(Data, *FileName))
			{
				const uint8* BufferBegin = Data.GetData();
				const uint8* BufferEnd = BufferBegin + Data.Num() - 1;
				FSsLoader::LoadSsAnimePack(&(NewProject->AnimeList[i]), BufferBegin, (BufferEnd - BufferBegin) + 1);
			}
		}

		// texture
		for(int i = 0; i < ImagePaths.Num(); ++i)
		{
			FString FileName = GetFilePath(CurPath, NewProject->Settings.ImageBaseDirectory, ImagePaths[i]);

			UTexture* ImportedTexture = NULL;
			if(ExistImages && ExistImages->Contains(ImagePaths[i]))
			{
				ImportedTexture = ExistImages->FindChecked(ImagePaths[i]);
			}

			TArray<uint8> Data;
			if(FFileHelper::LoadFileToArray(Data, *FileName))
			{

				UTextureFactory* TextureFact = NewObject<UTextureFactory>();
				TextureFact->AddToRoot();

				FString TextureName = FPaths::GetBaseFilename(ImagePaths[i]);

				UPackage* TexturePackage = NULL;
				if(ImportedTexture)
				{
					TexturePackage = ImportedTexture->GetOutermost();
				}
				else
				{
					FString TexturePackageName;
					FString BasePackageName = FPackageName::GetLongPackagePath(InParent->GetOutermost()->GetName()) / TextureName;
					AssetToolsModule.Get().CreateUniqueAssetName(BasePackageName, TEXT(""), TexturePackageName, TextureName);
					TexturePackage = CreatePackage(NULL, *TexturePackageName);
				}

				const uint8* BufferBegin = Data.GetData();
				const uint8* BufferEnd = BufferBegin + Data.Num();
				UTexture2D* NewTexture = (UTexture2D*)TextureFact->FactoryCreateBinary(
					UTexture2D::StaticClass(),
					TexturePackage,
					FName(*TextureName),
					Flags,
					NULL,
					*FPaths::GetExtension(ImagePaths[i]),
					BufferBegin, BufferEnd,
					Warn
					);
				if(NewTexture)
				{
					if(ImportSettings->bOverwriteMipGenSettings)
					{
						NewTexture->MipGenSettings = TMGS_NoMipmaps;
					}
					if(ImportSettings->bOverwriteTextureGroup)
					{
						NewTexture->LODGroup = ImportSettings->TextureGroup;
					}
					if(ImportSettings->bOverwriteCompressionSettings)
					{
						NewTexture->CompressionSettings = TextureCompressionSettings::TC_EditorIcon;
					}
					if(ImportSettings->bOverwriteTilingMethodFromSspj)
					{
						switch(ImageWrapModes[i])
						{
							case SsTexWrapMode::Clamp:
								{
									NewTexture->AddressX = NewTexture->AddressY = TA_Clamp;
								} break;
							case SsTexWrapMode::Repeat:
								{
									NewTexture->AddressX = NewTexture->AddressY = TA_Wrap;
								} break;
							case SsTexWrapMode::Mirror:
								{
									NewTexture->AddressX = NewTexture->AddressY = TA_Mirror;
								} break;
						}
					}
					if(ImportSettings->bOverwriteNeverStream)
					{
						NewTexture->NeverStream = true;
					}
					if(ImportSettings->bOverwriteFilterFromSspj)
					{
						switch(ImageFilterModes[i])
						{
							case SsTexFilterMode::Nearest:
								{
									NewTexture->Filter = TF_Nearest;
								} break;
							case SsTexFilterMode::Linear:
								{
									NewTexture->Filter = TF_Bilinear;
								} break;
						}
					}

					NewTexture->UpdateResource();

					FAssetRegistryModule::AssetCreated(NewTexture);
					TexturePackage->SetDirtyFlag(true);

					TextureFact->RemoveFromRoot();

					ImportedTexture = NewTexture;
				}
			}

			if(ImportedTexture)
			{
				for(int ii = 0; ii < NewProject->CellmapList.Num(); ++ii)
				{
					if(NewProject->CellmapList[ii].ImagePath == ImagePaths[i])
					{
						NewProject->CellmapList[ii].Texture = ImportedTexture;
					}
				}
			}
		}
	}

	// インポート終了
	FEditorDelegates::OnAssetPostImport.Broadcast(this, NewProject);
	return NewProject;
}
/**
* For the given text, constructs a mesh to be used by the vertex factory for rendering.
*/
bool  FTextRenderSceneProxy::BuildStringMesh( TArray<FDynamicMeshVertex>& OutVertices, TArray<uint16>& OutIndices )
{
	if(!Font || Text.IsEmpty())
	{
		return false;
	}

	float FirstLineHeight = -1; // Only kept around for legacy positioning support
	float StartY = 0;

	const float CharIncrement = ( (float)Font->Kerning + HorizSpacingAdjust ) * XScale;

	float LineX = 0;

	const int32 PageIndex = 0;

	FTextIterator It(*Text.ToString());
	while (It.NextLine())
	{
		FVector2D LineSize = ComputeTextSize(It, Font, XScale, YScale, HorizSpacingAdjust);
		float StartX = ComputeHorizontalAlignmentOffset(LineSize, HorizontalAlignment);

		if (FirstLineHeight < 0)
		{
			FirstLineHeight = LineSize.Y;
		}

		LineX = 0;
		int32 Ch;

		while (It.NextCharacterInLine(Ch))
		{
			Ch = (int32)Font->RemapChar(Ch);

			if(!Font->Characters.IsValidIndex(Ch + PageIndex))
			{
				continue;
			}

			FFontCharacter& Char = Font->Characters[Ch + PageIndex];

			if(!Font->Textures.IsValidIndex(Char.TextureIndex))
			{
				continue;
			}

			UTexture2D* Tex = Font->Textures[Char.TextureIndex];

			if(Tex)
			{
				FIntPoint ImportedTextureSize = Tex->GetImportedSize();
				FVector2D InvTextureSize(1.0f / (float)ImportedTextureSize.X, 1.0f / (float)ImportedTextureSize.Y);

				const float X      = LineX + StartX;
				const float Y      = StartY + Char.VerticalOffset * YScale;
				float SizeX = Char.USize * XScale;
				const float SizeY = Char.VSize * YScale;
				const float U		= Char.StartU * InvTextureSize.X;
				const float V		= Char.StartV * InvTextureSize.Y;
				const float SizeU	= Char.USize * InvTextureSize.X;
				const float SizeV	= Char.VSize * InvTextureSize.Y;			

				float Left = X;
				float Top = Y;
				float Right = X + SizeX;
				float Bottom = Y + SizeY;

				// axis choice and sign to get good alignment when placed on surface
				FVector4 V0 = FVector4(0, -Left, -Top, 0);
				FVector4 V1 = FVector4(0, -Right, -Top, 0);
				FVector4 V2 = FVector4(0, -Left, -Bottom, 0);
				FVector4 V3 = FVector4(0, -Right, -Bottom, 0);

				FVector TangentX(0, -1, 0);
				FVector TangentY(0, 0, -1);
				FVector TangentZ(1, 0, 0);

				int32 V00 = OutVertices.Add(FDynamicMeshVertex(V0, TangentX, TangentZ, FVector2D(U, V), TextRenderColor));
				int32 V10 = OutVertices.Add(FDynamicMeshVertex(V1, TangentX, TangentZ, FVector2D(U + SizeU, V), TextRenderColor));
				int32 V01 = OutVertices.Add(FDynamicMeshVertex(V2, TangentX, TangentZ, FVector2D(U, V + SizeV), TextRenderColor));
				int32 V11 = OutVertices.Add(FDynamicMeshVertex(V3, TangentX, TangentZ, FVector2D(U + SizeU, V + SizeV), TextRenderColor));

				check(V00 < 65536);
				check(V10 < 65536);
				check(V01 < 65536);
				check(V11 < 65536);

				OutIndices.Add(V00);
				OutIndices.Add(V11);
				OutIndices.Add(V10);

				OutIndices.Add(V00);
				OutIndices.Add(V01);
				OutIndices.Add(V11);

				// if we have another non-whitespace character to render, add the font's kerning.
				int32 NextChar;
				if( It.Peek(NextChar) && !FChar::IsWhitespace(NextChar) )
				{
					SizeX += CharIncrement;
				}

				LineX += SizeX;
			}
		}

		// Move Y position down to next line. If the current line is empty, move by max char height in font
		StartY += LineSize.Y > 0 ? LineSize.Y : Font->GetMaxCharHeight();
	}

	// Avoid initializing RHI resources when no vertices are generated.
	return (OutVertices.Num() > 0);
}
void USlateBrushThumbnailRenderer::Draw(UObject* Object, int32 X, int32 Y, uint32 Width, uint32 Height, FRenderTarget* RenderTarget, FCanvas* Canvas)
{
	USlateBrushAsset* SlateBrushAsset = Cast<USlateBrushAsset>(Object);
	if (SlateBrushAsset)
	{
		FSlateBrush Brush = SlateBrushAsset->Brush;
		UTexture2D* Texture = Cast<UTexture2D>( Brush.GetResourceObject() );

		// Draw the background checkboard pattern
		const int32 CheckerDensity = 8;
		auto* Checker = UThumbnailManager::Get().CheckerboardTexture;
		Canvas->DrawTile(
			0.0f, 0.0f, Width, Height,							// Dimensions
			0.0f, 0.0f, CheckerDensity, CheckerDensity,			// UVs
			FLinearColor::White, Checker->Resource);			// Tint & Texture

		if (Texture)
		{
			switch(Brush.DrawAs)
			{
			case ESlateBrushDrawType::Image:
				{
					FCanvasTileItem CanvasTile( FVector2D( X, Y ), Texture->Resource, FVector2D( Width,Height ), Brush.TintColor.GetSpecifiedColor() );
					CanvasTile.BlendMode = SE_BLEND_Translucent;
					CanvasTile.Draw( Canvas );
				}
				break;
			case ESlateBrushDrawType::Border:
				{
					FCanvasTileItem CanvasTile( FVector2D( X, Y ), Texture->Resource, FVector2D( Width,Height ), Brush.TintColor.GetSpecifiedColor() );
					CanvasTile.BlendMode = SE_BLEND_Translucent;
					CanvasTile.Draw( Canvas );
				}
				break;
			case ESlateBrushDrawType::Box:
				{
					float NaturalWidth = Texture->GetSurfaceWidth();
					float NaturalHeight = Texture->GetSurfaceHeight();

					float TopPx = FMath::Clamp<float>(NaturalHeight * Brush.Margin.Top, 0, Height);
					float BottomPx = FMath::Clamp<float>(NaturalHeight * Brush.Margin.Bottom, 0, Height);
					float VerticalCenterPx = FMath::Clamp<float>(Height - TopPx - BottomPx, 0, Height);
					float LeftPx = FMath::Clamp<float>(NaturalWidth * Brush.Margin.Left, 0, Width);
					float RightPx = FMath::Clamp<float>(NaturalWidth * Brush.Margin.Right, 0, Width);
					float HorizontalCenterPx = FMath::Clamp<float>(Width - LeftPx - RightPx, 0, Width);

					// Top-Left
					FVector2D TopLeftSize( LeftPx, TopPx );
					{
						FVector2D UV0( 0, 0 );
						FVector2D UV1( Brush.Margin.Left, Brush.Margin.Top );

						FCanvasTileItem CanvasTile( FVector2D( X, Y ), Texture->Resource, TopLeftSize, UV0, UV1, Brush.TintColor.GetSpecifiedColor() );
						CanvasTile.BlendMode = SE_BLEND_Translucent;
						CanvasTile.Draw( Canvas );
					}

					// Bottom-Left
					FVector2D BottomLeftSize( LeftPx, BottomPx );
					{
						FVector2D UV0( 0, 1 - Brush.Margin.Bottom );
						FVector2D UV1( Brush.Margin.Left, 1 );

						FCanvasTileItem CanvasTile( FVector2D( X, Y + Height - BottomPx ), Texture->Resource, BottomLeftSize, UV0, UV1, Brush.TintColor.GetSpecifiedColor() );
						CanvasTile.BlendMode = SE_BLEND_Translucent;
						CanvasTile.Draw( Canvas );
					}

					// Top-Right
					FVector2D TopRightSize( RightPx, TopPx );
					{
						FVector2D UV0( 1 - Brush.Margin.Right, 0 );
						FVector2D UV1( 1, Brush.Margin.Top );

						FCanvasTileItem CanvasTile( FVector2D( X + Width - RightPx, Y ), Texture->Resource, TopRightSize, UV0, UV1, Brush.TintColor.GetSpecifiedColor() );
						CanvasTile.BlendMode = SE_BLEND_Translucent;
						CanvasTile.Draw( Canvas );
					}

					// Bottom-Right
					FVector2D BottomRightSize( RightPx, BottomPx );
					{
						FVector2D UV0( 1 - Brush.Margin.Right, 1 - Brush.Margin.Bottom );
						FVector2D UV1( 1, 1 );

						FCanvasTileItem CanvasTile( FVector2D( X + Width - RightPx, Y + Height - BottomPx ), Texture->Resource, BottomRightSize, UV0, UV1, Brush.TintColor.GetSpecifiedColor() );
						CanvasTile.BlendMode = SE_BLEND_Translucent;
						CanvasTile.Draw( Canvas );
					}

					//-----------------------------------------------------------------------

					// Center-Vertical-Left
					FVector2D CenterVerticalLeftSize( LeftPx, VerticalCenterPx );
					{
						FVector2D UV0( 0, Brush.Margin.Top );
						FVector2D UV1( Brush.Margin.Left, 1 - Brush.Margin.Bottom );

						FCanvasTileItem CanvasTile( FVector2D( X, Y + TopPx), Texture->Resource, CenterVerticalLeftSize, UV0, UV1, Brush.TintColor.GetSpecifiedColor() );
						CanvasTile.BlendMode = SE_BLEND_Translucent;
						CanvasTile.Draw( Canvas );
					}

					// Center-Vertical-Right
					FVector2D CenterVerticalRightSize( RightPx, VerticalCenterPx );
					{
						FVector2D UV0( 1 - Brush.Margin.Right, Brush.Margin.Top );
						FVector2D UV1( 1, 1 - Brush.Margin.Bottom );

						FCanvasTileItem CanvasTile( FVector2D( X + Width - RightPx, Y + TopPx), Texture->Resource, CenterVerticalRightSize, UV0, UV1, Brush.TintColor.GetSpecifiedColor() );
						CanvasTile.BlendMode = SE_BLEND_Translucent;
						CanvasTile.Draw( Canvas );
					}

					//-----------------------------------------------------------------------

					// Center-Horizontal-Top
					FVector2D CenterHorizontalTopSize( HorizontalCenterPx, TopPx );
					{
						FVector2D UV0( Brush.Margin.Left, 0 );
						FVector2D UV1( 1 - Brush.Margin.Right, Brush.Margin.Top );

						FCanvasTileItem CanvasTile( FVector2D( X + LeftPx, Y), Texture->Resource, CenterHorizontalTopSize, UV0, UV1, Brush.TintColor.GetSpecifiedColor() );
						CanvasTile.BlendMode = SE_BLEND_Translucent;
						CanvasTile.Draw( Canvas );
					}

					// Center-Horizontal-Bottom
					FVector2D CenterHorizontalBottomSize( HorizontalCenterPx, BottomPx );
					{
						FVector2D UV0( Brush.Margin.Left, 1 - Brush.Margin.Bottom );
						FVector2D UV1( 1 - Brush.Margin.Right, 1 );

						FCanvasTileItem CanvasTile( FVector2D( X + LeftPx, Y + Height - BottomPx ), Texture->Resource, CenterHorizontalBottomSize, UV0, UV1, Brush.TintColor.GetSpecifiedColor() );
						CanvasTile.BlendMode = SE_BLEND_Translucent;
						CanvasTile.Draw( Canvas );
					}

					//-----------------------------------------------------------------------

					// Center
					FVector2D CenterSize( HorizontalCenterPx, VerticalCenterPx );
					{
						FVector2D UV0( Brush.Margin.Left, Brush.Margin.Top );
						FVector2D UV1( 1 - Brush.Margin.Right, 1 - Brush.Margin.Bottom );

						FCanvasTileItem CanvasTile( FVector2D( X + LeftPx, Y + TopPx), Texture->Resource, CenterSize, UV0, UV1, Brush.TintColor.GetSpecifiedColor() );
						CanvasTile.BlendMode = SE_BLEND_Translucent;
						CanvasTile.Draw( Canvas );
					}
				}
				break;
			case ESlateBrushDrawType::NoDrawType:
				{
					FCanvasTileItem CanvasTile( FVector2D( X, Y ), Texture->Resource, FVector2D( Width,Height ), Brush.TintColor.GetSpecifiedColor() );
					CanvasTile.BlendMode = SE_BLEND_Translucent;
					CanvasTile.Draw( Canvas );
				}
				break;
			default:

				check(false);
			}
		}
	}
}
// @param It must be a valid initialized text iterator
// @param Font 0 is silently ignored
FVector2D ComputeTextSize(FTextIterator It, class UFont* Font,
	float XScale, float YScale, float HorizSpacingAdjust)
{
	FVector2D Ret(0, 0);

	if(!Font)
	{
		return Ret;
	}

	const float CharIncrement = ( (float)Font->Kerning + HorizSpacingAdjust ) * XScale;

	float LineX = 0;

	const int32 PageIndex = 0;

	int32 Ch;
	while (It.NextCharacterInLine(Ch))
	{
		Ch = (int32)Font->RemapChar(Ch);

		if(!Font->Characters.IsValidIndex(Ch + PageIndex))
		{
			continue;
		}

		FFontCharacter& Char = Font->Characters[Ch + PageIndex];

		if(!Font->Textures.IsValidIndex(Char.TextureIndex))
		{
			continue;
		}

		UTexture2D* Tex = Font->Textures[Char.TextureIndex];

		if(Tex)
		{
			FIntPoint ImportedTextureSize = Tex->GetImportedSize();
			FVector2D InvTextureSize(1.0f / (float)ImportedTextureSize.X, 1.0f / (float)ImportedTextureSize.Y);

			const float X		= LineX;
			const float Y		= Char.VerticalOffset * YScale;
			float SizeX			= Char.USize * XScale;
			const float SizeY	= Char.VSize * YScale;
			const float U		= Char.StartU * InvTextureSize.X;
			const float V		= Char.StartV * InvTextureSize.Y;
			const float SizeU	= Char.USize * InvTextureSize.X;
			const float SizeV	= Char.VSize * InvTextureSize.Y;

			float Right = X + SizeX;
			float Bottom = Y + SizeY;

			Ret.X = FMath::Max(Ret.X, Right);
			Ret.Y = FMath::Max(Ret.Y, Bottom);

			// if we have another non-whitespace character to render, add the font's kerning.
			int32 NextCh;
			if( It.Peek(NextCh) && !FChar::IsWhitespace(NextCh) )
			{
				SizeX += CharIncrement;
			}

			LineX += SizeX;
		}
	}

	return Ret;
}
void FEditorLiveStreaming::BroadcastStatusCallback( const FLiveStreamingStatus& Status )
{
	TSharedPtr< SNotificationItem > Notification( NotificationWeakPtr.Pin() );
	if( Notification.IsValid() )
	{
		// Don't bother clobbering existing message with text about web cam starting/stopping, unless we're already broadcasting.
		// We want to make sure people see the persistent text about login state.
		if( SubmittedVideoFrameCount > 0 ||
			( Status.StatusType != FLiveStreamingStatus::EStatusType::WebCamStarted &&
			  Status.StatusType != FLiveStreamingStatus::EStatusType::WebCamStopped &&
			  Status.StatusType != FLiveStreamingStatus::EStatusType::WebCamTextureNotReady &&
			  Status.StatusType != FLiveStreamingStatus::EStatusType::WebCamTextureReady &&
			  Status.StatusType != FLiveStreamingStatus::EStatusType::ChatConnected &&
			  Status.StatusType != FLiveStreamingStatus::EStatusType::ChatDisconnected ) )
		{
			Notification->SetText( Status.CustomStatusDescription );
		}
	}
	else
	{
		// Only spawn a notification if we're actually still trying to broadcast, not if we're stopping broadcasting.  We don't want
		// to revive our notification that we intentionally expired.
		if( bIsBroadcasting )
		{
			FNotificationInfo Info( Status.CustomStatusDescription );
			Info.FadeInDuration = 0.1f;
			Info.FadeOutDuration = 0.5f;
			Info.ExpireDuration = 1.5f;
			Info.bUseThrobber = false;
			Info.bUseSuccessFailIcons = true;
			Info.bUseLargeFont = true;
			Info.bFireAndForget = false;
			Info.bAllowThrottleWhenFrameRateIsLow = false;
			NotificationWeakPtr = FSlateNotificationManager::Get().AddNotification( Info );
		}
	}

	Notification = NotificationWeakPtr.Pin();
	if( Notification.IsValid() )
	{
		SNotificationItem::ECompletionState State = SNotificationItem::CS_Pending;
		if( Status.StatusType == FLiveStreamingStatus::EStatusType::Failure )
		{
			State = SNotificationItem::CS_Fail;
		}
		else if( Status.StatusType == FLiveStreamingStatus::EStatusType::BroadcastStarted ||
				 Status.StatusType == FLiveStreamingStatus::EStatusType::WebCamStarted ||
				 Status.StatusType == FLiveStreamingStatus::EStatusType::ChatConnected )
		{
			State = SNotificationItem::CS_Success;
		}

		Notification->SetCompletionState( State );
	}

	// If the web cam just turned on, then we'll go ahead and show it
	if( Status.StatusType == FLiveStreamingStatus::EStatusType::WebCamTextureReady )
	{	
		bool bIsImageFlippedHorizontally = false;
		bool bIsImageFlippedVertically = false;
		UTexture2D* WebCamTexture = LiveStreamer->GetWebCamTexture( bIsImageFlippedHorizontally, bIsImageFlippedVertically );
		if( ensure( WebCamTexture != nullptr ) )
		{
			IMainFrameModule& MainFrameModule = FModuleManager::LoadModuleChecked<IMainFrameModule>( TEXT( "MainFrame" ) );
			check( MainFrameModule.IsWindowInitialized() );
			auto RootWindow = MainFrameModule.GetParentWindow();
			check( RootWindow.IsValid() );

			// Allow the user to customize the image mirroring, too!
			const auto& Settings = *GetDefault< UEditorLiveStreamingSettings >();
			if( Settings.bMirrorWebCamImage )
			{
				bIsImageFlippedHorizontally = !bIsImageFlippedHorizontally;
			}

			// How many pixels from the edge of the main frame window to where the broadcast status window appears
			const int WindowBorderPadding = 50;

			// @todo livestream: Currently this window is not created as "topmost".  We don't really want it to be OS-topmost, but we do want it to be the most
			// topmost "regular" window in our application (not on top of tooltips, etc.)

			// Create a window that will show the web cam video feed
			BroadcastStatusWindow = SNew( SWindow )
				.Title( LOCTEXT( "StreamingWindowTitle", "Web Camera" ) )
				.ClientSize( FVector2D( WebCamTexture->GetSizeX(), WebCamTexture->GetSizeY() ) )
				.ScreenPosition( FVector2D( 
					RootWindow->GetRectInScreen().Right - WebCamTexture->GetSizeX() - WindowBorderPadding, 
					RootWindow->GetRectInScreen().Top +  WindowBorderPadding ) )

				// @todo livestream: Ideally the user could freely resize the window, but it gets a bit tricky to preserve the web cam aspect.  Plus, we don't really like how letterboxing/columnboxing looks with this.
				.SizingRule( ESizingRule::FixedSize )

				.AutoCenter( EAutoCenter::None )
				.bDragAnywhere( true )
				.SupportsMaximize( true )
				.SupportsMinimize( true )
				.FocusWhenFirstShown( false )
				.ActivateWhenFirstShown( false )
				.SaneWindowPlacement( false );

			WebCamDynamicImageBrush = MakeShareable( new FSlateDynamicImageBrush( 
				WebCamTexture,
				FVector2D( WebCamTexture->GetSizeX(), WebCamTexture->GetSizeY() ),
				WebCamTexture->GetFName() ) );

			// If the web cam image is coming in flipped, we'll apply mirroring to the Slate brush
			if( bIsImageFlippedHorizontally && bIsImageFlippedVertically )
			{
				WebCamDynamicImageBrush->Mirroring = ESlateBrushMirrorType::Both;
			}
			else if( bIsImageFlippedHorizontally )
			{ 
				WebCamDynamicImageBrush->Mirroring = ESlateBrushMirrorType::Horizontal;
			}
			else if( bIsImageFlippedVertically )
			{ 
				WebCamDynamicImageBrush->Mirroring = ESlateBrushMirrorType::Vertical;
			}

			// @todo livestream: Currently if the user closes the window, the camera is deactivated and it doesn't turn back on unless the broadcast is restarted.  We could allow the camera to be reactivated though.
			BroadcastStatusWindow->SetOnWindowClosed( 
				FOnWindowClosed::CreateStatic( []( const TSharedRef<SWindow>& Window, FEditorLiveStreaming* This ) 
				{
					// User closed the broadcast status window, so go ahead and shut down the web cam
					This->LiveStreamer->StopWebCam();
					This->BroadcastStatusWindow.Reset();
					This->WebCamDynamicImageBrush.Reset();
				}, 
				this ) );

			BroadcastStatusWindow->SetContent( 
				SNew( SImage )
					.Image( WebCamDynamicImageBrush.Get() )
			);

			FSlateApplication::Get().AddWindowAsNativeChild(
				BroadcastStatusWindow.ToSharedRef(), 
				RootWindow.ToSharedRef() );
		}

	}
	else if( Status.StatusType == FLiveStreamingStatus::EStatusType::WebCamTextureNotReady )
	{
		CloseBroadcastStatusWindow();
	}
}
Exemplo n.º 21
-2
UTexture2D* PrivateLeapImage::Texture32FromLeapDistortion(int32 SrcWidth, int32 SrcHeight, float* imageBuffer)
{
	// Lock the texture so it can be modified
	if (distortionPointer == NULL)
		return NULL;

	int32 DestWidth = SrcWidth /2; // Put 2 floats in the R and G channels
	int32 DestHeight = SrcHeight;

	// Lock the texture so it can be modified
	uint8* MipData = static_cast<uint8*>(distortionPointer->PlatformData->Mips[0].BulkData.Lock(LOCK_READ_WRITE));

	// Create base mip.
	uint8* DestPtr = NULL;
	const float* SrcPtr = NULL;
	for (int32 y = 0; y<SrcHeight; y++)
	{
		DestPtr = &MipData[(DestHeight - 1 - y) * DestWidth * sizeof(FColor)];
		SrcPtr = const_cast<float*>(&imageBuffer[(SrcHeight - 1 - y) * SrcWidth]);
		for (int32 x = 0; x<SrcWidth; x++)
		{

			*DestPtr++ = (uint8)(*SrcPtr++ * 0xFF);	//Scale floats
			*DestPtr++ = (uint8)(*SrcPtr++ * 0xFF);
			*DestPtr++ = (uint8)0x00;						//Black
			*DestPtr++ = (uint8)0xFF;						//Full 255 alpha
		}
	}

	// Unlock the texture
	distortionPointer->PlatformData->Mips[0].BulkData.Unlock();
	distortionPointer->UpdateResource();

	return distortionPointer;
}
void UFontThumbnailRenderer::GetThumbnailSize(UObject* Object, float Zoom,uint32& OutWidth,uint32& OutHeight) const
{
    UFont* Font = Cast<UFont>(Object);
    if (Font != nullptr &&
            Font->Textures.Num() > 0 &&
            Font->Textures[0] != nullptr)
    {
        // Get the texture interface for the font text
        UTexture2D* Tex = Font->Textures[0];
        OutWidth = FMath::TruncToInt(Zoom * (float)Tex->GetSurfaceWidth());
        OutHeight = FMath::TruncToInt(Zoom * (float)Tex->GetSurfaceHeight());
    }
    else
    {
        OutWidth = OutHeight = 0;
    }
}
Exemplo n.º 23
-3
//Grayscale average texture
UTexture2D* PrivateLeapImage::Texture32FromLeapImage(int32 SrcWidth, int32 SrcHeight, uint8* imageBuffer)
{
	// Lock the texture so it can be modified
	if (imagePointer == NULL)
		return NULL;

	uint8* MipData = static_cast<uint8*>(imagePointer->PlatformData->Mips[0].BulkData.Lock(LOCK_READ_WRITE));
	
	// Create base mip.
	uint8* DestPtr = NULL;
	const uint8* SrcPtr = NULL;

	for (int32 y = 0; y<SrcHeight; y++)
	{
		DestPtr = &MipData[(SrcHeight - 1 - y) * SrcWidth * sizeof(FColor)];
		SrcPtr = const_cast<uint8*>(&imageBuffer[(SrcHeight - 1 - y) * SrcWidth]);
		for (int32 x = 0; x<SrcWidth; x++)
		{
			//Grayscale, copy to all channels
			*DestPtr++ = *SrcPtr;
			*DestPtr++ = *SrcPtr;
			*DestPtr++ = *SrcPtr;
			*DestPtr++ = 0xFF;
			SrcPtr++;
		}
	}

	// Unlock the texture
	imagePointer->PlatformData->Mips[0].BulkData.Unlock();
	imagePointer->UpdateResource();

	return imagePointer;
}
Exemplo n.º 24
-4
static bool UpdateSelectedTexel(
	UPrimitiveComponent* Component, 
	int32 NodeIndex, 
	FLightMapRef& Lightmap, 
	const FVector& Position, 
	FVector2D InterpolatedUV, 
	int32 LocalX, int32 LocalY,
	int32 LightmapSizeX, int32 LightmapSizeY)
{
	if (Component == GCurrentSelectedLightmapSample.Component
		&& NodeIndex == GCurrentSelectedLightmapSample.NodeIndex
		&& LocalX == GCurrentSelectedLightmapSample.LocalX
		&& LocalY == GCurrentSelectedLightmapSample.LocalY)
	{
		return false;
	}
	else
	{
		// Store information about the selected texel
		FSelectedLightmapSample NewSelectedTexel(Component, NodeIndex, Lightmap, Position, LocalX, LocalY, LightmapSizeX, LightmapSizeY);

		if (IsValidRef(Lightmap))
		{
			FLightMap2D* Lightmap2D = Lightmap->GetLightMap2D();
			check(Lightmap2D);
			const FVector2D CoordinateScale = Lightmap2D->GetCoordinateScale();
			const FVector2D CoordinateBias = Lightmap2D->GetCoordinateBias();
			// Calculate lightmap atlas UV's for the selected point
			FVector2D LightmapUV = InterpolatedUV * CoordinateScale + CoordinateBias;

			int32 LightmapIndex = Lightmap2D->AllowsHighQualityLightmaps() ? 0 : 1;
			UTexture2D* CurrentLightmap = Lightmap2D->GetTexture( LightmapIndex );
			// UV's in the lightmap atlas
			NewSelectedTexel.LightmapX = FMath::TruncToInt(LightmapUV.X * CurrentLightmap->GetSizeX());
			NewSelectedTexel.LightmapY = FMath::TruncToInt(LightmapUV.Y * CurrentLightmap->GetSizeY());
			// Write the selection color to the selected lightmap texel
			WriteTexel(CurrentLightmap, NewSelectedTexel.LightmapX, NewSelectedTexel.LightmapY, GTexelSelectionColor, NewSelectedTexel.OriginalColor);

			GCurrentSelectedLightmapSample = NewSelectedTexel;
			return true;
		}
		else
		{
			UE_LOG(LogStaticLightingSystem, Log, TEXT("Texel selection failed because the lightmap is an invalid reference!"));
			return false;
		}
	}
}
bool FSpriteEditorViewportClient::ConvertMarqueeToSourceTextureSpace(/*out*/ FIntPoint& OutStartPos, /*out*/ FIntPoint& OutDimension)
{
	FSpriteGeometryEditMode* GeometryEditMode = ModeTools->GetActiveModeTyped<FSpriteGeometryEditMode>(FSpriteGeometryEditMode::EM_SpriteGeometry);
	check(GeometryEditMode);
	const FVector2D MarqueeStartPos = GeometryEditMode->GetMarqueeStartPos();
	const FVector2D MarqueeEndPos = GeometryEditMode->GetMarqueeEndPos();

	bool bSuccessful = false;
	UPaperSprite* Sprite = SourceTextureViewComponent->GetSprite();
	UTexture2D* SpriteSourceTexture = Sprite->GetSourceTexture();
	if (SpriteSourceTexture != nullptr)
	{
		// Calculate world space positions
		FSceneViewFamilyContext ViewFamily(FSceneViewFamily::ConstructionValues(Viewport, GetScene(), EngineShowFlags));
		FSceneView* View = CalcSceneView(&ViewFamily);
		const FVector StartPos = View->PixelToWorld(MarqueeStartPos.X, MarqueeStartPos.Y, 0);
		const FVector EndPos = View->PixelToWorld(MarqueeEndPos.X, MarqueeEndPos.Y, 0);

		// Convert to source texture space to work out the pixels dragged
		FVector2D TextureSpaceStartPos = Sprite->ConvertWorldSpaceToTextureSpace(StartPos);
		FVector2D TextureSpaceEndPos = Sprite->ConvertWorldSpaceToTextureSpace(EndPos);

		if (TextureSpaceStartPos.X > TextureSpaceEndPos.X)
		{
			Swap(TextureSpaceStartPos.X, TextureSpaceEndPos.X);
		}
		if (TextureSpaceStartPos.Y > TextureSpaceEndPos.Y)
		{
			Swap(TextureSpaceStartPos.Y, TextureSpaceEndPos.Y);
		}

		const FIntPoint SourceTextureSize(SpriteSourceTexture->GetImportedSize());
		const int32 SourceTextureWidth = SourceTextureSize.X;
		const int32 SourceTextureHeight = SourceTextureSize.Y;
		
		FIntPoint TSStartPos;
		TSStartPos.X = FMath::Clamp<int32>((int32)TextureSpaceStartPos.X, 0, SourceTextureWidth - 1);
		TSStartPos.Y = FMath::Clamp<int32>((int32)TextureSpaceStartPos.Y, 0, SourceTextureHeight - 1);

		FIntPoint TSEndPos;
		TSEndPos.X = FMath::Clamp<int32>((int32)TextureSpaceEndPos.X, 0, SourceTextureWidth - 1);
		TSEndPos.Y = FMath::Clamp<int32>((int32)TextureSpaceEndPos.Y, 0, SourceTextureHeight - 1);

		const FIntPoint TextureSpaceDimensions = TSEndPos - TSStartPos;
		if ((TextureSpaceDimensions.X > 0) || (TextureSpaceDimensions.Y > 0))
		{
			OutStartPos = TSStartPos;
			OutDimension = TextureSpaceDimensions;
			bSuccessful = true;
		}
	}

	return bSuccessful;
}
UTexture2D* ULeapMotionImageComponent::BuildDistortionTextures( const Leap::Image& Image )
{
	UTexture2D* DistortionTexture = UTexture2D::CreateTransient(Image.distortionWidth() / 2, Image.distortionHeight(), PF_B8G8R8A8);
	DistortionTexture->SRGB = 0;
	DistortionTexture->UpdateResource();

	UpdateDistortionTextures(Image, DistortionTexture);

	return DistortionTexture;
}
void FAssetTypeActions_Texture::ExecuteCreateSubUVAnimation(TArray<TWeakObjectPtr<UTexture>> Objects)
{
	const FString DefaultSuffix = TEXT("_SubUV");

	if ( Objects.Num() == 1 )
	{
		UTexture2D* Object = Cast<UTexture2D>(Objects[0].Get());

		if ( Object )
		{
			// Determine an appropriate name
			FString Name;
			FString PackagePath;
			CreateUniqueAssetName(Object->GetOutermost()->GetName(), DefaultSuffix, PackagePath, Name);

			// Create the factory used to generate the asset
			USubUVAnimationFactory* Factory = NewObject<USubUVAnimationFactory>();
			Factory->InitialTexture = Object;

			FContentBrowserModule& ContentBrowserModule = FModuleManager::LoadModuleChecked<FContentBrowserModule>("ContentBrowser");
			ContentBrowserModule.Get().CreateNewAsset(Name, FPackageName::GetLongPackagePath(PackagePath), USubUVAnimation::StaticClass(), Factory);
		}
	}
	else
	{
		TArray<UObject*> ObjectsToSync;

		for (auto ObjIt = Objects.CreateConstIterator(); ObjIt; ++ObjIt)
		{
			UTexture2D* Object = Cast<UTexture2D>((*ObjIt).Get());

			if ( Object )
			{
				FString Name;
				FString PackageName;
				CreateUniqueAssetName(Object->GetOutermost()->GetName(), DefaultSuffix, PackageName, Name);

				// Create the factory used to generate the asset
				USubUVAnimationFactory* Factory = NewObject<USubUVAnimationFactory>();
				Factory->InitialTexture = Object;

				FAssetToolsModule& AssetToolsModule = FModuleManager::GetModuleChecked<FAssetToolsModule>("AssetTools");
				UObject* NewAsset = AssetToolsModule.Get().CreateAsset(Name, FPackageName::GetLongPackagePath(PackageName), USubUVAnimation::StaticClass(), Factory);

				if ( NewAsset )
				{
					ObjectsToSync.Add(NewAsset);
				}
			}
		}

		if ( ObjectsToSync.Num() > 0 )
		{
			FAssetTools::Get().SyncBrowserToAssets(ObjectsToSync);
		}
	}
}