本文整理汇总了C++中UPaperSprite::SetPivotMode方法的典型用法代码示例。如果您正苦于以下问题:C++ UPaperSprite::SetPivotMode方法的具体用法?C++ UPaperSprite::SetPivotMode怎么用?C++ UPaperSprite::SetPivotMode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UPaperSprite
的用法示例。
在下文中一共展示了UPaperSprite::SetPivotMode方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: UpdateSourceTextureSpriteFromSprite
void FSpriteEditorViewportClient::UpdateSourceTextureSpriteFromSprite(UPaperSprite* SourceSprite)
{
UPaperSprite* TargetSprite = SourceTextureViewComponent->GetSprite();
check(TargetSprite);
if (SourceSprite != nullptr)
{
if ((SourceSprite->GetSourceTexture() != TargetSprite->GetSourceTexture()) || (TargetSprite->PixelsPerUnrealUnit != SourceSprite->PixelsPerUnrealUnit))
{
FComponentReregisterContext ReregisterSprite(SourceTextureViewComponent);
FSpriteAssetInitParameters SpriteReinitParams;
SpriteReinitParams.SetTextureAndFill(SourceSprite->SourceTexture);
SpriteReinitParams.DefaultMaterialOverride = SourceSprite->DefaultMaterial;
SpriteReinitParams.AlternateMaterialOverride = SourceSprite->AlternateMaterial;
SpriteReinitParams.SetPixelsPerUnrealUnit(SourceSprite->PixelsPerUnrealUnit);
TargetSprite->InitializeSprite(SpriteReinitParams);
RequestFocusOnSelection(/*bInstant=*/ true);
}
// Position the sprite for the mode its meant to be in
FVector2D CurrentPivotPosition;
ESpritePivotMode::Type CurrentPivotMode = TargetSprite->GetPivotMode(/*out*/CurrentPivotPosition);
FVector Translation(1.0f * PaperAxisZ);
if (IsInSourceRegionEditMode())
{
if (CurrentPivotMode != ESpritePivotMode::Bottom_Left)
{
TargetSprite->SetPivotMode(ESpritePivotMode::Bottom_Left, FVector2D::ZeroVector);
TargetSprite->PostEditChange();
}
SourceTextureViewComponent->SetSpriteColor(FLinearColor::White);
SourceTextureViewComponent->SetWorldTransform(FTransform(Translation));
}
else
{
const FVector2D PivotPosition = SourceSprite->GetPivotPosition();
if (CurrentPivotMode != ESpritePivotMode::Custom || CurrentPivotPosition != PivotPosition)
{
TargetSprite->SetPivotMode(ESpritePivotMode::Custom, PivotPosition);
TargetSprite->PostEditChange();
}
// Tint the source texture darker to help distinguish the two
SourceTextureViewComponent->SetSpriteColor(SpriteEditingConstants::SourceTextureDarkTintColor);
const bool bRotated = SourceSprite->IsRotatedInSourceImage();
if (bRotated)
{
FQuat Rotation(PaperAxisZ, FMath::DegreesToRadians(90.0f));
SourceTextureViewComponent->SetWorldTransform(FTransform(Rotation, Translation));
}
else
{
SourceTextureViewComponent->SetWorldTransform(FTransform(Translation));
}
}
}
else
{
// No source sprite, so don't draw the target either
TargetSprite->SourceTexture = nullptr;
}
}
示例2: PerformImport
bool FPaperJsonSpriteSheetImporter::PerformImport(const FString& LongPackagePath, EObjectFlags Flags, UPaperSpriteSheet* SpriteSheet)
{
FAssetToolsModule& AssetToolsModule = FModuleManager::GetModuleChecked<FAssetToolsModule>("AssetTools");
GWarn->BeginSlowTask(NSLOCTEXT("Paper2D", "PaperJsonImporterFactory_ImportingSprites", "Importing Sprite Frame"), true, true);
for (int32 FrameIndex = 0; FrameIndex < Frames.Num(); ++FrameIndex)
{
GWarn->StatusUpdate(FrameIndex, Frames.Num(), NSLOCTEXT("Paper2D", "PaperJsonImporterFactory_ImportingSprites", "Importing Sprite Frames"));
// Check for user canceling the import
if (GWarn->ReceivedUserCancel())
{
break;
}
const FSpriteFrame& Frame = Frames[FrameIndex];
// Create a package for the frame
const FString TargetSubPath = LongPackagePath + TEXT("/Frames");
UObject* OuterForFrame = nullptr; // @TODO: Use this if we don't want them to be individual assets - Flipbook;
// Create a frame in the package
UPaperSprite* TargetSprite = nullptr;
if (bIsReimporting)
{
TargetSprite = FindExistingSprite(Frame.FrameName.ToString());
}
if (TargetSprite == nullptr)
{
const FString SanitizedFrameName = ObjectTools::SanitizeObjectName(Frame.FrameName.ToString());
const FString TentativePackagePath = PackageTools::SanitizePackageName(TargetSubPath + TEXT("/") + SanitizedFrameName);
FString DefaultSuffix;
FString AssetName;
FString PackageName;
AssetToolsModule.Get().CreateUniqueAssetName(TentativePackagePath, DefaultSuffix, /*out*/ PackageName, /*out*/ AssetName);
// Create a unique package name and asset name for the frame
if (OuterForFrame == nullptr)
{
// Create a package for the frame
OuterForFrame = CreatePackage(nullptr, *PackageName);
}
// Create the asset
TargetSprite = NewObject<UPaperSprite>(OuterForFrame, *AssetName, Flags);
FAssetRegistryModule::AssetCreated(TargetSprite);
}
TargetSprite->Modify();
FSpriteAssetInitParameters SpriteInitParams;
SpriteInitParams.Texture = ImageTexture;
if (NormalMapTexture != nullptr)
{
// Put the normal map into the additional textures array and ask for a lit material instead of unlit
SpriteInitParams.AdditionalTextures.Add(NormalMapTexture);
}
SpriteInitParams.Offset = Frame.SpritePosInSheet;
SpriteInitParams.Dimension = Frame.SpriteSizeInSheet;
GetDefault<UPaperImporterSettings>()->ApplySettingsForSpriteInit(/*inout*/ SpriteInitParams, (NormalMapTexture != nullptr) ? ESpriteInitMaterialLightingMode::ForceLit : ESpriteInitMaterialLightingMode::Automatic);
TargetSprite->InitializeSprite(SpriteInitParams);
if (Frame.bRotated)
{
TargetSprite->SetRotated(true);
}
if (Frame.bTrimmed)
{
TargetSprite->SetTrim(Frame.bTrimmed, Frame.SpriteSourcePos, Frame.ImageSourceSize);
}
// Set up pivot on object based on Texture Packer json
ESpritePivotMode::Type PivotType = GetBestPivotType(Frame.Pivot);
FVector2D TextureSpacePivotPoint = FVector2D::ZeroVector;
if (PivotType == ESpritePivotMode::Custom)
{
TextureSpacePivotPoint.X = Frame.SpritePosInSheet.X - Frame.SpriteSourcePos.X + Frame.ImageSourceSize.X * Frame.Pivot.X;
TextureSpacePivotPoint.Y = Frame.SpritePosInSheet.Y - Frame.SpriteSourcePos.Y + Frame.ImageSourceSize.Y * Frame.Pivot.Y;
}
TargetSprite->SetPivotMode(PivotType, TextureSpacePivotPoint);
// Create the entry in the animation
SpriteSheet->SpriteNames.Add(Frame.FrameName.ToString());
SpriteSheet->Sprites.Add(TargetSprite);
TargetSprite->PostEditChange();
}
SpriteSheet->TextureName = ImageName;
SpriteSheet->Texture = ImageTexture;
SpriteSheet->NormalMapTextureName = ComputedNormalMapName;
SpriteSheet->NormalMapTexture = NormalMapTexture;
//.........这里部分代码省略.........
示例3: FactoryCreateText
UObject* USpriterImporterFactory::FactoryCreateText(UClass* InClass, UObject* InParent, FName InName, EObjectFlags Flags, UObject* Context, const TCHAR* Type, const TCHAR*& Buffer, const TCHAR* BufferEnd, FFeedbackContext* Warn)
{
Flags |= RF_Transactional;
FEditorDelegates::OnAssetPreImport.Broadcast(this, InClass, InParent, InName, Type);
FAssetToolsModule& AssetToolsModule = FModuleManager::GetModuleChecked<FAssetToolsModule>("AssetTools");
bool bLoadedSuccessfully = true;
const FString CurrentFilename = UFactory::GetCurrentFilename();
FString CurrentSourcePath;
FString FilenameNoExtension;
FString UnusedExtension;
FPaths::Split(CurrentFilename, CurrentSourcePath, FilenameNoExtension, UnusedExtension);
const FString LongPackagePath = FPackageName::GetLongPackagePath(InParent->GetOutermost()->GetPathName());
const FString NameForErrors(InName.ToString());
const FString FileContent(BufferEnd - Buffer, Buffer);
TSharedPtr<FJsonObject> DescriptorObject = ParseJSON(FileContent, NameForErrors);
UPaperSpriterImportData* Result = nullptr;
// Parse the file
FSpriterSCON DataModel;
if (DescriptorObject.IsValid())
{
DataModel.ParseFromJSON(DescriptorObject, NameForErrors, /*bSilent=*/ false, /*bPreParseOnly=*/ false);
}
// Create the new 'hub' asset and convert the data model over
if (DataModel.IsValid())
{
const bool bSilent = false;
Result = NewObject<UPaperSpriterImportData>(InParent, InName, Flags);
Result->Modify();
//@TODO: Do some things here maybe?
Result->ImportedData = DataModel;
// Import the assets in the folders
for (const FSpriterFolder& Folder : DataModel.Folders)
{
for (const FSpriterFile& File : Folder.Files)
{
const FString RelativeFilename = File.Name.Replace(TEXT("\\"), TEXT("/"), ESearchCase::CaseSensitive);
const FString SourceSpriterFilePath = FPaths::Combine(*CurrentSourcePath, *RelativeFilename);
FString RelativeDestPath;
FString JustFilename;
FString JustExtension;
FPaths::Split(RelativeFilename, /*out*/ RelativeDestPath, /*out*/ JustFilename, /*out*/ JustExtension);
if (File.FileType == ESpriterFileType::Sprite)
{
const FString TargetTexturePath = LongPackagePath / TEXT("Textures") / RelativeDestPath;
const FString TargetSpritePath = LongPackagePath / TEXT("Sprites") / RelativeDestPath;
// Import the texture
UTexture2D* ImportedTexture = ImportTexture(SourceSpriterFilePath, TargetTexturePath);
if (ImportTexture == nullptr)
{
SPRITER_IMPORT_ERROR(TEXT("Failed to import texture '%s' while importing '%s'"), *SourceSpriterFilePath, *CurrentFilename);
}
// Create a sprite from it
UPaperSprite* ImportedSprite = CastChecked<UPaperSprite>(CreateNewAsset(UPaperSprite::StaticClass(), TargetSpritePath, JustFilename, Flags));
const ESpritePivotMode::Type PivotMode = ConvertNormalizedPivotPointToPivotMode(File.PivotX, File.PivotY);
const double PivotInPixelsX = File.Width * File.PivotX;
const double PivotInPixelsY = File.Height * File.PivotY;
ImportedSprite->SetPivotMode(PivotMode, FVector2D((float)PivotInPixelsX, (float)PivotInPixelsY));
FSpriteAssetInitParameters SpriteInitParams;
SpriteInitParams.SetTextureAndFill(ImportedTexture);
GetDefault<UPaperImporterSettings>()->ApplySettingsForSpriteInit(SpriteInitParams);
SpriteInitParams.SetPixelsPerUnrealUnit(1.0f);
ImportedSprite->InitializeSprite(SpriteInitParams);
}
else if (File.FileType == ESpriterFileType::Sound)
{
// Import the sound
const FString TargetAssetPath = LongPackagePath / RelativeDestPath;
UObject* ImportedSound = ImportAsset(SourceSpriterFilePath, TargetAssetPath);
}
else if (File.FileType != ESpriterFileType::INVALID)
{
ensureMsgf(false, TEXT("Importer was not updated when a new entry was added to ESpriterFileType"));
}
// TMap<FString, class UTexture2D*> ImportedTextures;
// TMap<FString, class UPaperSprite> ImportedSprites;
}
}
//.........这里部分代码省略.........