Unreal Engine4 使用c++创建贴图

一般我们将贴图资源导入引擎的时候,引擎会自己抽取贴图文件的数据然后创建一个UTexture的Object合一个Uasset。但是有时候我们想自己写工具的话需要自己实现这套创建机制。

可以在引擎的UTextureFactory找到我们导入引擎时的逻辑代码。可以看到不同的图片格式,不同的像素深度创建的像素格式合贴图格式都不一样。

要使用代码创建贴图资源我们第一部是先指定一个创建贴图的地方

// Build a package name to use for mesh
	FString MeshName;
	FString PackageName;

	if (InPackageName.IsEmpty())
	{
		FString NewNameSuggestion = FString(TEXT("StaticMesh"));
		FString PackageNameSuggestion = FString(TEXT("/Game/Meshes/")) + NewNameSuggestion;
		FString Name;
		FAssetToolsModule& AssetToolsModule = FModuleManager::LoadModuleChecked<FAssetToolsModule>("AssetTools");
		AssetToolsModule.Get().CreateUniqueAssetName(PackageNameSuggestion, TEXT(""), PackageNameSuggestion, Name);

		TSharedPtr<SDlgPickAssetPath> PickAssetPathWidget =
			SNew(SDlgPickAssetPath)
			.Title(LOCTEXT("ConvertToStaticMeshPickName", "Choose New StaticMesh Location"))
			.DefaultAssetPath(FText::FromString(PackageNameSuggestion));

		if (PickAssetPathWidget->ShowModal() == EAppReturnType::Ok)
		{
			// Get the full name of where we want to create the mesh asset.
			PackageName = PickAssetPathWidget->GetFullAssetPath().ToString();
			MeshName = FPackageName::GetLongPackageAssetName(PackageName);

			// Check if the user inputed a valid asset name, if they did not, give it the generated default name
			if (MeshName.IsEmpty())
			{
				// Use the defaults that were already generated.
				PackageName = PackageNameSuggestion;
				MeshName = *Name;
			}
		}
	}
	else
	{
		PackageName = InPackageName;
		MeshName = *FPackageName::GetLongPackageAssetName(PackageName);
	}

	// Build a package name to use for material
	FString NewMergeOneMaterialName = MeshName + TEXT("_MergeMat");
	FString NewMergeOneMaterialPackageName = PackageName + TEXT("_MergeMat");

	//Build a package name to use for texture
	FString NewMergedTextureName = MeshName + TEXT("_MergeTex");
	FString NewMergedTexturePackageName = PackageName + TEXT("_MergeTex");

有了这个路径之后我们New一个Package

UPackage* TexturePackage = CreatePackage(NULL, *NewMergedTexturePackageName);

然后New一个Object,与此同时把刚才New的哪个Texture Object塞到这个Package里

UTexture2D* MergedTexture = NewObject<UTexture2D>(TexturePackage, *NewMergedTextureName, RF_Public | RF_Standalone);

接下来需要初始化这个Texture

使用

Source.Init(DestTextureSizeX, DestTextureSizeY, 1, 1, TSF_BGRA8);

Texture的Source中的Init方法初始化它即可,注意格式。

Unreal Engine 4 for Beginners, as its name implies, is specifically written with the beginner in mind. It is meant for those who wish to learn how to make video games with no prior game development, game design, or game programming experience. It concentrates on the fundamentals, in order to build a rock solid foundation upon which the reader can use to confidently explore more intermediate and advanced topics. It provides a thorough examination of the basics, covering each subject in fine detail. Great care has been taken to ad vance through the subject matter in an order that best ensures that everything needed to understand one piece of information has already been covered in the information prior. It makes a great textbook for an Intro to Unreal Engine, or Unreal Engine 101 course. In addition, the book has been formatted specifically for ease of use with tablets and other mobile devices. The book concentrates heavily on four key areas: Environments - Construct beautiful environments with moving objects and sounds Inputs - Enter and explore the worlds you construct by creating a Character and specifying how it can move and how to control those movements Menus & Displays - Learn how to create the user interfaces and on-screen displays that will enhance your game and bring it to the next level Logic - Learn how to construct logic and take full control over the first three subject areas. How should objects in your world move? What should cause a certain sound to play? How does the player win the game? You decide! No need to wait for shipping! Get started learning the fundamentals of game development right now with this specially formatted ebook textbook! Table of Contents Chapter 1 Getting Started Chapter 2 Basic Concepts Chapter 3 The Level Editor Chapter 4 Actors Chapter 5 Blueprints Chapter 6 Players & Input Chapter 7 Collisions Chapter 8 User Interfaces Chapter 9 Audio Chapter 10 Additional Topics Book Details QR code for Unreal Engine 4 for Beginners Title: Unreal Engine 4 for Beginners 收缩
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值