本文整理汇总了C++中UPaperSprite类的典型用法代码示例。如果您正苦于以下问题:C++ UPaperSprite类的具体用法?C++ UPaperSprite怎么用?C++ UPaperSprite使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了UPaperSprite类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GetSpriteBeingEdited
void FSpriteEditorViewportClient::EndTransaction()
{
if (bManipulationDirtiedSomething)
{
UPaperSprite* Sprite = GetSpriteBeingEdited();
if (IsInSourceRegionEditMode())
{
// Snap to pixel grid at the end of the drag
Sprite->SourceUV.X = FMath::Max(FMath::RoundToFloat(Sprite->SourceUV.X), 0.0f);
Sprite->SourceUV.Y = FMath::Max(FMath::RoundToFloat(Sprite->SourceUV.Y), 0.0f);
Sprite->SourceDimension.X = FMath::Max(FMath::RoundToFloat(Sprite->SourceDimension.X), 0.0f);
Sprite->SourceDimension.Y = FMath::Max(FMath::RoundToFloat(Sprite->SourceDimension.Y), 0.0f);
}
Sprite->PostEditChange();
}
bManipulationDirtiedSomething = false;
if (ScopedTransaction != nullptr)
{
delete ScopedTransaction;
ScopedTransaction = nullptr;
}
}
示例2: QueryPaintableTextures
void FMeshPaintSpriteAdapter::QueryPaintableTextures(int32 MaterialIndex, int32& OutDefaultIndex, TArray<struct FPaintableTexture>& InOutTextureList)
{
UPaperSprite* Sprite = SpriteComponent->GetSprite();
checkSlow(Sprite != nullptr);
// Grab the sprite texture first
int32 ForceIndex = INDEX_NONE;
if (UTexture2D* SourceTexture = Sprite->GetBakedTexture())
{
FPaintableTexture PaintableTexture(SourceTexture, 0);
ForceIndex = InOutTextureList.AddUnique(PaintableTexture);
}
// Grab the additional textures next
FAdditionalSpriteTextureArray AdditionalTextureList;
Sprite->GetBakedAdditionalSourceTextures(/*out*/ AdditionalTextureList);
for (UTexture* AdditionalTexture : AdditionalTextureList)
{
if (AdditionalTexture != nullptr)
{
FPaintableTexture PaintableTexture(AdditionalTexture, 0);
InOutTextureList.AddUnique(AdditionalTexture);
}
}
// Now ask the material
DefaultQueryPaintableTextures(MaterialIndex, SpriteComponent, OutDefaultIndex, InOutTextureList);
if (ForceIndex != INDEX_NONE)
{
OutDefaultIndex = ForceIndex;
}
}
示例3: 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;
}
示例4: FScopedTransaction
void FSpriteEditorViewportClient::BeginTransaction(const FText& SessionName)
{
if (ScopedTransaction == nullptr)
{
ScopedTransaction = new FScopedTransaction(SessionName);
UPaperSprite* Sprite = GetSpriteBeingEdited();
Sprite->Modify();
}
}
示例5: check
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;
}
示例6: operator
// Sort predicate operator
bool operator()(UPaperSprite& LHS, UPaperSprite& RHS) const
{
FString LeftString;
int32 LeftNumber;
ExtractSpriteNumber(LHS.GetName(), /*out*/ LeftString, /*out*/ LeftNumber);
FString RightString;
int32 RightNumber;
ExtractSpriteNumber(RHS.GetName(), /*out*/ RightString, /*out*/ RightNumber);
return (LeftString == RightString) ? (LeftNumber < RightNumber) : (LeftString < RightString);
}
示例7: EndTransaction
void FSpriteEditorViewportClient::NotifySpriteBeingEditedHasChanged()
{
//@TODO: Ideally we do this before switching
EndTransaction();
// Refresh the viewport in case we were not in realtime mode
Invalidate();
// Update components to know about the new sprite being edited
UPaperSprite* Sprite = GetSpriteBeingEdited();
RenderSpriteComponent->SetSprite(Sprite);
UpdateSourceTextureSpriteFromSprite(Sprite);
InternalActivateNewMode(CurrentMode);
//@TODO: Only do this if the sprite isn't visible (may consider doing a flashing pulse around the source region rect?)
RequestFocusOnSelection(/*bInstant=*/ true);
if (Sprite != nullptr)
{
// Create and display a notification about the new sprite being edited
const FText NotificationErrorText = FText::Format(LOCTEXT("SwitchingToSprite", "Editing {0}"), FText::AsCultureInvariant(Sprite->GetName()));
FNotificationInfo Info(NotificationErrorText);
Info.ExpireDuration = 2.0f;
FSlateNotificationManager::Get().AddNotification(Info);
}
}
示例8: 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;
}
示例9: 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;
}
示例10: check
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();
}
示例11: check
void FPaperSpriteSheetAssetTypeActions::ExecuteCreateFlipbooks(TArray<TWeakObjectPtr<UPaperSpriteSheet>> Objects)
{
for (int SpriteSheetIndex = 0; SpriteSheetIndex < Objects.Num(); ++SpriteSheetIndex)
{
UPaperSpriteSheet* SpriteSheet = Objects[SpriteSheetIndex].Get();
if (SpriteSheet != nullptr)
{
const FString PackagePath = FPackageName::GetLongPackagePath(SpriteSheet->GetOutermost()->GetPathName());
FAssetToolsModule& AssetToolsModule = FModuleManager::GetModuleChecked<FAssetToolsModule>("AssetTools");
FContentBrowserModule& ContentBrowserModule = FModuleManager::LoadModuleChecked<FContentBrowserModule>("ContentBrowser");
check(SpriteSheet->SpriteNames.Num() == SpriteSheet->Sprites.Num());
bool useSpriteNames = (SpriteSheet->SpriteNames.Num() == SpriteSheet->Sprites.Num());
// Create a list of sprites and sprite names to feed into paper flipbook helpers
TMap<FString, TArray<UPaperSprite*> > SpriteFlipbookMap;
{
TArray<UPaperSprite*> Sprites;
TArray<FString> SpriteNames;
for (int SpriteIndex = 0; SpriteIndex < SpriteSheet->Sprites.Num(); ++SpriteIndex)
{
auto SpriteAssetPtr = SpriteSheet->Sprites[SpriteIndex];
FStringAssetReference SpriteStringRef = SpriteAssetPtr.ToStringReference();
UPaperSprite* Sprite = nullptr;
if (!SpriteStringRef.ToString().IsEmpty())
{
Sprite = Cast<UPaperSprite>(StaticLoadObject(UPaperSprite::StaticClass(), nullptr, *SpriteStringRef.ToString(), nullptr, LOAD_None, nullptr));
}
if (Sprite != nullptr)
{
const FString SpriteName = useSpriteNames ? SpriteSheet->SpriteNames[SpriteIndex] : Sprite->GetName();
Sprites.Add(Sprite);
SpriteNames.Add(SpriteName);
}
}
FPaperFlipbookHelpers::ExtractFlipbooksFromSprites(/*out*/ SpriteFlipbookMap, Sprites, SpriteNames);
}
// Create one flipbook for every grouped flipbook name
if (SpriteFlipbookMap.Num() > 0)
{
UPaperFlipbookFactory* FlipbookFactory = NewObject<UPaperFlipbookFactory>();
GWarn->BeginSlowTask(NSLOCTEXT("Paper2D", "Paper2D_CreateFlipbooks", "Creating flipbooks from selection"), true, true);
int Progress = 0;
int TotalProgress = SpriteFlipbookMap.Num();
TArray<UObject*> ObjectsToSync;
for (auto It : SpriteFlipbookMap)
{
GWarn->UpdateProgress(Progress++, TotalProgress);
const FString& FlipbookName = It.Key;
TArray<UPaperSprite*>& Sprites = It.Value;
const FString TentativePackagePath = PackageTools::SanitizePackageName(PackagePath + TEXT("/") + FlipbookName);
FString DefaultSuffix;
FString AssetName;
FString PackageName;
AssetToolsModule.Get().CreateUniqueAssetName(TentativePackagePath, DefaultSuffix, /*out*/ PackageName, /*out*/ AssetName);
FlipbookFactory->KeyFrames.Empty();
for (int32 SpriteIndex = 0; SpriteIndex < Sprites.Num(); ++SpriteIndex)
{
FPaperFlipbookKeyFrame* KeyFrame = new (FlipbookFactory->KeyFrames) FPaperFlipbookKeyFrame();
KeyFrame->Sprite = Sprites[SpriteIndex];
KeyFrame->FrameRun = 1;
}
if (UObject* NewAsset = AssetToolsModule.Get().CreateAsset(AssetName, PackagePath, UPaperFlipbook::StaticClass(), FlipbookFactory))
{
ObjectsToSync.Add(NewAsset);
}
if (GWarn->ReceivedUserCancel())
{
break;
}
}
GWarn->EndSlowTask();
if (ObjectsToSync.Num() > 0)
{
ContentBrowserModule.Get().SyncBrowserToAssets(ObjectsToSync);
}
}
}
}
}
示例12: new
void FPaperAtlasGenerator::HandleAssetChangedEvent(UPaperSpriteAtlas* Atlas)
{
Atlas->MaxWidth = FMath::Clamp(Atlas->MaxWidth, 16, 4096);
Atlas->MaxHeight = FMath::Clamp(Atlas->MaxHeight, 16, 4096);
// Find all sprites that reference the atlas and force them loaded
FAssetRegistryModule& AssetRegistryModule = FModuleManager::LoadModuleChecked<FAssetRegistryModule>(TEXT("AssetRegistry"));
TArray<FAssetData> AssetList;
TMultiMap<FName, FString> TagsAndValues;
TagsAndValues.Add(TEXT("AtlasGroupGUID"), Atlas->AtlasGUID.ToString(EGuidFormats::Digits));
AssetRegistryModule.Get().GetAssetsByTagValues(TagsAndValues, AssetList);
TIndirectArray<FSingleTexturePaperAtlas> AtlasGenerators;
// Start off with one page
new (AtlasGenerators) FSingleTexturePaperAtlas(Atlas->MaxWidth, Atlas->MaxHeight);
for (const FAssetData& SpriteRef : AssetList)
{
if (UPaperSprite* Sprite = Cast<UPaperSprite>(SpriteRef.GetAsset()))
{
//@TODO: Use the tight bounds instead of the source bounds
const FVector2D SpriteSizeFloat = Sprite->GetSourceSize();
const FIntPoint SpriteSize(FMath::TruncToInt(SpriteSizeFloat.X), FMath::TruncToInt(SpriteSizeFloat.Y));
if (Sprite->GetSourceTexture() == nullptr)
{
UE_LOG(LogPaper2DEditor, Error, TEXT("Sprite %s has no source texture and cannot be packed"), *(Sprite->GetPathName()));
continue;
}
//@TODO: Take padding into account (push this into the generator)
if ((SpriteSize.X > Atlas->MaxWidth) || (SpriteSize.Y >= Atlas->MaxHeight))
{
// This sprite cannot ever fit into an atlas page
UE_LOG(LogPaper2DEditor, Error, TEXT("Sprite %s (%d x %d) can never fit into atlas %s (%d x %d) due to maximum page size restrictions"),
*(Sprite->GetPathName()),
SpriteSize.X,
SpriteSize.Y,
*(Atlas->GetPathName()),
Atlas->MaxWidth,
Atlas->MaxHeight);
}
else
{
const FAtlasedTextureSlot* Slot = nullptr;
// Does it fit in any existing pages?
for (auto& Generator : AtlasGenerators)
{
Slot = Generator.AddSprite(Sprite);
if (Slot != nullptr)
{
break;
}
}
if (Slot == nullptr)
{
// Doesn't fit in any current pages, make a new one
FSingleTexturePaperAtlas* NewGenerator = new (AtlasGenerators) FSingleTexturePaperAtlas(Atlas->MaxWidth, Atlas->MaxHeight);
Slot = NewGenerator->AddSprite(Sprite);
}
if (Slot != nullptr)
{
UE_LOG(LogPaper2DEditor, Warning, TEXT("Allocated %s to (%d,%d)"), *(Sprite->GetPathName()), Slot->X, Slot->Y);
}
else
{
// ERROR: Didn't fit into a brand new page, maybe padding was wrong
UE_LOG(LogPaper2DEditor, Error, TEXT("Failed to allocate %s into a brand new page"), *(Sprite->GetPathName()));
}
}
}
}
// Turn the generators back into textures
Atlas->GeneratedTextures.Empty(AtlasGenerators.Num());
for (int32 GeneratorIndex = 0; GeneratorIndex < AtlasGenerators.Num(); ++GeneratorIndex)
{
FSingleTexturePaperAtlas& AtlasPage = AtlasGenerators[GeneratorIndex];
UTexture2D* Texture = NewNamedObject<UTexture2D>(Atlas, NAME_None, RF_Public);
Atlas->GeneratedTextures.Add(Texture);
AtlasPage.CopyToTexture(Texture);
// Now update the baked data for all the sprites to point there
for (auto& SpriteToSlot : AtlasPage.SpriteToSlotMap)
{
UPaperSprite* Sprite = SpriteToSlot.Key;
Sprite->Modify();
const FAtlasedTextureSlot* Slot = SpriteToSlot.Value;
Sprite->BakedSourceTexture = Texture;
Sprite->BakedSourceUV = FVector2D(Slot->X, Slot->Y);
Sprite->RebuildRenderData();
}
//.........这里部分代码省略.........
示例13: 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;
}
}
示例14: SourceTextureSpaceToWorldSpace
FVector FSpriteEditorViewportClient::SourceTextureSpaceToWorldSpace(const FVector2D& SourcePoint) const
{
UPaperSprite* Sprite = SourceTextureViewComponent->GetSprite();
return Sprite->ConvertTextureSpaceToWorldSpace(SourcePoint);
}
示例15: NameForErrors
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;
}
}
//.........这里部分代码省略.........