本文整理汇总了C++中UPaperSprite::InitializeSprite方法的典型用法代码示例。如果您正苦于以下问题:C++ UPaperSprite::InitializeSprite方法的具体用法?C++ UPaperSprite::InitializeSprite怎么用?C++ UPaperSprite::InitializeSprite使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UPaperSprite
的用法示例。
在下文中一共展示了UPaperSprite::InitializeSprite方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: FactoryCreateNew
UObject* UPaperSpriteFactory::FactoryCreateNew(UClass* Class, UObject* InParent, FName Name, EObjectFlags Flags, UObject* Context, FFeedbackContext* Warn)
{
UPaperSprite* NewSprite = ConstructObject<UPaperSprite>(Class, InParent, Name, Flags);
NewSprite->InitializeSprite(InitialTexture);
return NewSprite;
}
示例2: CreateNewSprite
UPaperSprite* UHGGifFactory::CreateNewSprite(UTexture2D* InitialTexture, UClass* Class, UObject* InParent, FName Name, EObjectFlags Flags, UObject* Context, FFeedbackContext* Warn)
{
UPaperSprite* NewSprite = NewObject<UPaperSprite>(InParent, Class, Name, Flags | RF_Transactional);
if (NewSprite && InitialTexture)
{
FSpriteAssetInitParameters SpriteInitParams;
SpriteInitParams.SetTextureAndFill(InitialTexture);
const UPaperImporterSettings* ImporterSettings = GetDefault<UPaperImporterSettings>();
ImporterSettings->ApplySettingsForSpriteInit(SpriteInitParams, ESpriteInitMaterialLightingMode::Automatic);
NewSprite->InitializeSprite(SpriteInitParams);
}
return NewSprite;
}
示例3: FactoryCreateNew
UObject* UPaperSpriteFactory::FactoryCreateNew(UClass* Class, UObject* InParent, FName Name, EObjectFlags Flags, UObject* Context, FFeedbackContext* Warn)
{
UPaperSprite* NewSprite = NewObject<UPaperSprite>(InParent, Class, Name, Flags | RF_Transactional);
FSpriteAssetInitParameters SpriteInitParams;
SpriteInitParams.bNewlyCreated = true;
if (bUseSourceRegion)
{
SpriteInitParams.Texture = InitialTexture;
SpriteInitParams.Offset = InitialSourceUV;
SpriteInitParams.Dimension = InitialSourceDimension;
}
else
{
SpriteInitParams.SetTextureAndFill(InitialTexture);
}
NewSprite->InitializeSprite(SpriteInitParams);
return NewSprite;
}
示例4: 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;
//.........这里部分代码省略.........
示例5: SetTileIndex
void FSingleTileEditorViewportClient::SetTileIndex(int32 InTileIndex)
{
const int32 OldTileIndex = TileBeingEditedIndex;
const bool bNewIndexValid = (InTileIndex >= 0) && (InTileIndex < TileSet->GetTileCount());
TileBeingEditedIndex = bNewIndexValid ? InTileIndex : INDEX_NONE;
FSpriteGeometryEditMode* GeometryEditMode = ModeTools->GetActiveModeTyped<FSpriteGeometryEditMode>(FSpriteGeometryEditMode::EM_SpriteGeometry);
check(GeometryEditMode);
FSpriteGeometryCollection* GeomToEdit = nullptr;
if (TileBeingEditedIndex != INDEX_NONE)
{
if (FPaperTileMetadata* Metadata = TileSet->GetMutableTileMetadata(InTileIndex))
{
GeomToEdit = &(Metadata->CollisionData);
}
}
// Tell the geometry editor about the new tile (if it exists)
GeometryEditMode->SetGeometryBeingEdited(GeomToEdit, /*bAllowCircles=*/ true, /*bAllowSubtractivePolygons=*/ false);
// Update the visual representation
UPaperSprite* DummySprite = nullptr;
if (TileBeingEditedIndex != INDEX_NONE)
{
DummySprite = NewObject<UPaperSprite>();
DummySprite->SpriteCollisionDomain = ESpriteCollisionMode::None;
DummySprite->PivotMode = ESpritePivotMode::Center_Center;
DummySprite->CollisionGeometry.GeometryType = ESpritePolygonMode::SourceBoundingBox;
DummySprite->RenderGeometry.GeometryType = ESpritePolygonMode::SourceBoundingBox;
FSpriteAssetInitParameters SpriteReinitParams;
SpriteReinitParams.Texture = TileSet->GetTileSheetTexture();
//@TODO: Should analyze the texture (*at a higher level, not per tile click!*) to pick the correct material
FVector2D UV;
TileSet->GetTileUV(TileBeingEditedIndex, /*out*/ UV);
SpriteReinitParams.Offset = FIntPoint((int32)UV.X, (int32)(UV.Y));
SpriteReinitParams.Dimension = TileSet->GetTileSize();
SpriteReinitParams.SetPixelsPerUnrealUnit(1.0f);
DummySprite->InitializeSprite(SpriteReinitParams);
}
PreviewTileSpriteComponent->SetSprite(DummySprite);
// Update the default geometry bounds
const FVector2D HalfTileSize(TileSet->GetTileSize().X * 0.5f, TileSet->GetTileSize().Y * 0.5f);
FBox2D DesiredBounds(ForceInitToZero);
DesiredBounds.Min = -HalfTileSize;
DesiredBounds.Max = HalfTileSize;
GeometryEditMode->SetNewGeometryPreferredBounds(DesiredBounds);
// Zoom to fit when we start editing a tile and weren't before, but leave it alone if we just changed tiles, in case they zoomed in or out further
if ((TileBeingEditedIndex != INDEX_NONE) && (OldTileIndex == INDEX_NONE))
{
RequestFocusOnSelection(/*bInstant=*/ true);
}
// Trigger a details panel customization rebuild
OnSingleTileIndexChanged.Broadcast(TileBeingEditedIndex, OldTileIndex);
// Redraw the viewport
Invalidate();
}
示例6: 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;
}
}
示例7: 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;
}
}
//.........这里部分代码省略.........