mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-19 00:06:42 +08:00
[ue4] Fixed spaces -> tabs
This commit is contained in:
parent
a125241bcc
commit
a46839336a
@ -14,102 +14,102 @@
|
||||
#define LOCTEXT_NAMESPACE "Spine"
|
||||
|
||||
USpineAtlasAssetFactory::USpineAtlasAssetFactory (const FObjectInitializer& objectInitializer): Super(objectInitializer) {
|
||||
bCreateNew = false;
|
||||
bEditAfterNew = true;
|
||||
bEditorImport = true;
|
||||
SupportedClass = USpineAtlasAsset::StaticClass();
|
||||
|
||||
Formats.Add(TEXT("atlas;Spine atlas file"));
|
||||
bCreateNew = false;
|
||||
bEditAfterNew = true;
|
||||
bEditorImport = true;
|
||||
SupportedClass = USpineAtlasAsset::StaticClass();
|
||||
|
||||
Formats.Add(TEXT("atlas;Spine atlas file"));
|
||||
}
|
||||
|
||||
FText USpineAtlasAssetFactory::GetToolTip () const {
|
||||
return LOCTEXT("SpineAtlasAssetFactory", "Animations exported from Spine");
|
||||
return LOCTEXT("SpineAtlasAssetFactory", "Animations exported from Spine");
|
||||
}
|
||||
|
||||
bool USpineAtlasAssetFactory::FactoryCanImport (const FString& Filename) {
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
UObject* USpineAtlasAssetFactory::FactoryCreateFile (UClass * InClass, UObject * InParent, FName InName, EObjectFlags Flags, const FString & Filename, const TCHAR* Parms, FFeedbackContext * Warn, bool& bOutOperationCanceled) {
|
||||
FString rawString;
|
||||
if (!FFileHelper::LoadFileToString(rawString, *Filename)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
FString currentSourcePath, filenameNoExtension, unusedExtension;
|
||||
const FString longPackagePath = FPackageName::GetLongPackagePath(InParent->GetOutermost()->GetPathName());
|
||||
FPaths::Split(UFactory::GetCurrentFilename(), currentSourcePath, filenameNoExtension, unusedExtension);
|
||||
FString name(InName.ToString());
|
||||
name.Append("-atlas");
|
||||
|
||||
USpineAtlasAsset* asset = NewObject<USpineAtlasAsset>(InParent, InClass, FName(*name), Flags);
|
||||
asset->SetRawData(rawString);
|
||||
asset->SetAtlasFileName(FName(*Filename));
|
||||
LoadAtlas(asset, currentSourcePath, longPackagePath);
|
||||
return asset;
|
||||
FString rawString;
|
||||
if (!FFileHelper::LoadFileToString(rawString, *Filename)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
FString currentSourcePath, filenameNoExtension, unusedExtension;
|
||||
const FString longPackagePath = FPackageName::GetLongPackagePath(InParent->GetOutermost()->GetPathName());
|
||||
FPaths::Split(UFactory::GetCurrentFilename(), currentSourcePath, filenameNoExtension, unusedExtension);
|
||||
FString name(InName.ToString());
|
||||
name.Append("-atlas");
|
||||
|
||||
USpineAtlasAsset* asset = NewObject<USpineAtlasAsset>(InParent, InClass, FName(*name), Flags);
|
||||
asset->SetRawData(rawString);
|
||||
asset->SetAtlasFileName(FName(*Filename));
|
||||
LoadAtlas(asset, currentSourcePath, longPackagePath);
|
||||
return asset;
|
||||
}
|
||||
|
||||
bool USpineAtlasAssetFactory::CanReimport (UObject* Obj, TArray<FString>& OutFilenames) {
|
||||
USpineAtlasAsset* asset = Cast<USpineAtlasAsset>(Obj);
|
||||
if (!asset) return false;
|
||||
|
||||
FString filename = asset->GetAtlasFileName().ToString();
|
||||
if (!filename.IsEmpty())
|
||||
OutFilenames.Add(filename);
|
||||
|
||||
return true;
|
||||
USpineAtlasAsset* asset = Cast<USpineAtlasAsset>(Obj);
|
||||
if (!asset) return false;
|
||||
|
||||
FString filename = asset->GetAtlasFileName().ToString();
|
||||
if (!filename.IsEmpty())
|
||||
OutFilenames.Add(filename);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void USpineAtlasAssetFactory::SetReimportPaths (UObject* Obj, const TArray<FString>& NewReimportPaths) {
|
||||
USpineAtlasAsset* asset = Cast<USpineAtlasAsset>(Obj);
|
||||
|
||||
if (asset && ensure(NewReimportPaths.Num() == 1))
|
||||
asset->SetAtlasFileName(FName(*NewReimportPaths[0]));
|
||||
USpineAtlasAsset* asset = Cast<USpineAtlasAsset>(Obj);
|
||||
|
||||
if (asset && ensure(NewReimportPaths.Num() == 1))
|
||||
asset->SetAtlasFileName(FName(*NewReimportPaths[0]));
|
||||
}
|
||||
|
||||
EReimportResult::Type USpineAtlasAssetFactory::Reimport (UObject* Obj) {
|
||||
USpineAtlasAsset* asset = Cast<USpineAtlasAsset>(Obj);
|
||||
FString rawString;
|
||||
if (!FFileHelper::LoadFileToString(rawString, *asset->GetAtlasFileName().ToString())) return EReimportResult::Failed;
|
||||
asset->SetRawData(rawString);
|
||||
|
||||
FString currentSourcePath, filenameNoExtension, unusedExtension;
|
||||
const FString longPackagePath = FPackageName::GetLongPackagePath(asset->GetOutermost()->GetPathName());
|
||||
FPaths::Split(UFactory::GetCurrentFilename(), currentSourcePath, filenameNoExtension, unusedExtension);
|
||||
|
||||
LoadAtlas(asset, currentSourcePath, longPackagePath);
|
||||
|
||||
if (Obj->GetOuter()) Obj->GetOuter()->MarkPackageDirty();
|
||||
else Obj->MarkPackageDirty();
|
||||
|
||||
return EReimportResult::Succeeded;
|
||||
USpineAtlasAsset* asset = Cast<USpineAtlasAsset>(Obj);
|
||||
FString rawString;
|
||||
if (!FFileHelper::LoadFileToString(rawString, *asset->GetAtlasFileName().ToString())) return EReimportResult::Failed;
|
||||
asset->SetRawData(rawString);
|
||||
|
||||
FString currentSourcePath, filenameNoExtension, unusedExtension;
|
||||
const FString longPackagePath = FPackageName::GetLongPackagePath(asset->GetOutermost()->GetPathName());
|
||||
FPaths::Split(UFactory::GetCurrentFilename(), currentSourcePath, filenameNoExtension, unusedExtension);
|
||||
|
||||
LoadAtlas(asset, currentSourcePath, longPackagePath);
|
||||
|
||||
if (Obj->GetOuter()) Obj->GetOuter()->MarkPackageDirty();
|
||||
else Obj->MarkPackageDirty();
|
||||
|
||||
return EReimportResult::Succeeded;
|
||||
}
|
||||
|
||||
UTexture2D* resolveTexture (USpineAtlasAsset* Asset, const FString& PageFileName, const FString& TargetSubPath) {
|
||||
FAssetToolsModule& AssetToolsModule = FModuleManager::GetModuleChecked<FAssetToolsModule>("AssetTools");
|
||||
|
||||
TArray<FString> fileNames;
|
||||
fileNames.Add(PageFileName);
|
||||
|
||||
TArray<UObject*> importedAsset = AssetToolsModule.Get().ImportAssets(fileNames, TargetSubPath);
|
||||
UTexture2D* texture = (importedAsset.Num() > 0) ? Cast<UTexture2D>(importedAsset[0]) : nullptr;
|
||||
|
||||
return texture;
|
||||
FAssetToolsModule& AssetToolsModule = FModuleManager::GetModuleChecked<FAssetToolsModule>("AssetTools");
|
||||
|
||||
TArray<FString> fileNames;
|
||||
fileNames.Add(PageFileName);
|
||||
|
||||
TArray<UObject*> importedAsset = AssetToolsModule.Get().ImportAssets(fileNames, TargetSubPath);
|
||||
UTexture2D* texture = (importedAsset.Num() > 0) ? Cast<UTexture2D>(importedAsset[0]) : nullptr;
|
||||
|
||||
return texture;
|
||||
}
|
||||
|
||||
void USpineAtlasAssetFactory::LoadAtlas (USpineAtlasAsset* Asset, const FString& CurrentSourcePath, const FString& LongPackagePath) {
|
||||
spAtlas* atlas = Asset->GetAtlas(true);
|
||||
Asset->atlasPages.Empty();
|
||||
|
||||
const FString targetTexturePath = LongPackagePath / TEXT("Textures");
|
||||
|
||||
spAtlasPage* page = atlas->pages;
|
||||
while (page) {
|
||||
const FString sourceTextureFilename = FPaths::Combine(*CurrentSourcePath, UTF8_TO_TCHAR(page->name));
|
||||
UTexture2D* texture = resolveTexture(Asset, sourceTextureFilename, targetTexturePath);
|
||||
page = page->next;
|
||||
Asset->atlasPages.Add(texture);
|
||||
}
|
||||
spAtlas* atlas = Asset->GetAtlas(true);
|
||||
Asset->atlasPages.Empty();
|
||||
|
||||
const FString targetTexturePath = LongPackagePath / TEXT("Textures");
|
||||
|
||||
spAtlasPage* page = atlas->pages;
|
||||
while (page) {
|
||||
const FString sourceTextureFilename = FPaths::Combine(*CurrentSourcePath, UTF8_TO_TCHAR(page->name));
|
||||
UTexture2D* texture = resolveTexture(Asset, sourceTextureFilename, targetTexturePath);
|
||||
page = page->next;
|
||||
Asset->atlasPages.Add(texture);
|
||||
}
|
||||
}
|
||||
|
||||
#undef LOCTEXT_NAMESPACE
|
||||
|
||||
@ -14,78 +14,78 @@
|
||||
#define LOCTEXT_NAMESPACE "Spine"
|
||||
|
||||
USpineSkeletonAssetFactory::USpineSkeletonAssetFactory (const FObjectInitializer& objectInitializer): Super(objectInitializer) {
|
||||
bCreateNew = false;
|
||||
bEditAfterNew = true;
|
||||
bEditorImport = true;
|
||||
SupportedClass = USpineSkeletonDataAsset::StaticClass();
|
||||
|
||||
Formats.Add(TEXT("json;Spine skeleton file"));
|
||||
Formats.Add(TEXT("skel;Spine skeleton file"));
|
||||
bCreateNew = false;
|
||||
bEditAfterNew = true;
|
||||
bEditorImport = true;
|
||||
SupportedClass = USpineSkeletonDataAsset::StaticClass();
|
||||
|
||||
Formats.Add(TEXT("json;Spine skeleton file"));
|
||||
Formats.Add(TEXT("skel;Spine skeleton file"));
|
||||
}
|
||||
|
||||
FText USpineSkeletonAssetFactory::GetToolTip () const {
|
||||
return LOCTEXT("USpineSkeletonAssetFactory", "Animations exported from Spine");
|
||||
return LOCTEXT("USpineSkeletonAssetFactory", "Animations exported from Spine");
|
||||
}
|
||||
|
||||
bool USpineSkeletonAssetFactory::FactoryCanImport (const FString& Filename) {
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
void LoadAtlas (const FString& Filename, const FString& TargetPath) {
|
||||
FAssetToolsModule& AssetToolsModule = FModuleManager::GetModuleChecked<FAssetToolsModule>("AssetTools");
|
||||
|
||||
FString skelFile = Filename.Replace(TEXT(".skel"), TEXT(".atlas")).Replace(TEXT(".json"), TEXT(".atlas"));
|
||||
if (!FPaths::FileExists(skelFile)) return;
|
||||
|
||||
TArray<FString> fileNames;
|
||||
fileNames.Add(skelFile);
|
||||
AssetToolsModule.Get().ImportAssets(fileNames, TargetPath);
|
||||
FAssetToolsModule& AssetToolsModule = FModuleManager::GetModuleChecked<FAssetToolsModule>("AssetTools");
|
||||
|
||||
FString skelFile = Filename.Replace(TEXT(".skel"), TEXT(".atlas")).Replace(TEXT(".json"), TEXT(".atlas"));
|
||||
if (!FPaths::FileExists(skelFile)) return;
|
||||
|
||||
TArray<FString> fileNames;
|
||||
fileNames.Add(skelFile);
|
||||
AssetToolsModule.Get().ImportAssets(fileNames, TargetPath);
|
||||
}
|
||||
|
||||
UObject* USpineSkeletonAssetFactory::FactoryCreateFile (UClass * InClass, UObject * InParent, FName InName, EObjectFlags Flags, const FString & Filename, const TCHAR* Parms, FFeedbackContext * Warn, bool& bOutOperationCanceled) {
|
||||
FString name(InName.ToString());
|
||||
name.Append("-data");
|
||||
|
||||
USpineSkeletonDataAsset* asset = NewObject<USpineSkeletonDataAsset>(InParent, InClass, FName(*name), Flags);
|
||||
if (!FFileHelper::LoadFileToArray(asset->GetRawData(), *Filename, 0)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
asset->SetSkeletonDataFileName(FName(*Filename));
|
||||
const FString longPackagePath = FPackageName::GetLongPackagePath(asset->GetOutermost()->GetPathName());
|
||||
LoadAtlas(Filename, longPackagePath);
|
||||
return asset;
|
||||
FString name(InName.ToString());
|
||||
name.Append("-data");
|
||||
|
||||
USpineSkeletonDataAsset* asset = NewObject<USpineSkeletonDataAsset>(InParent, InClass, FName(*name), Flags);
|
||||
if (!FFileHelper::LoadFileToArray(asset->GetRawData(), *Filename, 0)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
asset->SetSkeletonDataFileName(FName(*Filename));
|
||||
const FString longPackagePath = FPackageName::GetLongPackagePath(asset->GetOutermost()->GetPathName());
|
||||
LoadAtlas(Filename, longPackagePath);
|
||||
return asset;
|
||||
}
|
||||
|
||||
bool USpineSkeletonAssetFactory::CanReimport (UObject* Obj, TArray<FString>& OutFilenames) {
|
||||
USpineSkeletonDataAsset* asset = Cast<USpineSkeletonDataAsset>(Obj);
|
||||
if (!asset) return false;
|
||||
|
||||
FString filename = asset->GetSkeletonDataFileName().ToString();
|
||||
if (!filename.IsEmpty())
|
||||
OutFilenames.Add(filename);
|
||||
|
||||
return true;
|
||||
USpineSkeletonDataAsset* asset = Cast<USpineSkeletonDataAsset>(Obj);
|
||||
if (!asset) return false;
|
||||
|
||||
FString filename = asset->GetSkeletonDataFileName().ToString();
|
||||
if (!filename.IsEmpty())
|
||||
OutFilenames.Add(filename);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void USpineSkeletonAssetFactory::SetReimportPaths (UObject* Obj, const TArray<FString>& NewReimportPaths) {
|
||||
USpineSkeletonDataAsset* asset = Cast<USpineSkeletonDataAsset>(Obj);
|
||||
|
||||
if (asset && ensure(NewReimportPaths.Num() == 1))
|
||||
asset->SetSkeletonDataFileName(FName(*NewReimportPaths[0]));
|
||||
USpineSkeletonDataAsset* asset = Cast<USpineSkeletonDataAsset>(Obj);
|
||||
|
||||
if (asset && ensure(NewReimportPaths.Num() == 1))
|
||||
asset->SetSkeletonDataFileName(FName(*NewReimportPaths[0]));
|
||||
}
|
||||
|
||||
EReimportResult::Type USpineSkeletonAssetFactory::Reimport (UObject* Obj) {
|
||||
USpineSkeletonDataAsset* asset = Cast<USpineSkeletonDataAsset>(Obj);
|
||||
if (!FFileHelper::LoadFileToArray(asset->GetRawData(), *asset->GetSkeletonDataFileName().ToString(), 0)) return EReimportResult::Failed;
|
||||
|
||||
const FString longPackagePath = FPackageName::GetLongPackagePath(asset->GetOutermost()->GetPathName());
|
||||
LoadAtlas(*asset->GetSkeletonDataFileName().ToString(), longPackagePath);
|
||||
|
||||
if (Obj->GetOuter()) Obj->GetOuter()->MarkPackageDirty();
|
||||
else Obj->MarkPackageDirty();
|
||||
|
||||
return EReimportResult::Succeeded;
|
||||
USpineSkeletonDataAsset* asset = Cast<USpineSkeletonDataAsset>(Obj);
|
||||
if (!FFileHelper::LoadFileToArray(asset->GetRawData(), *asset->GetSkeletonDataFileName().ToString(), 0)) return EReimportResult::Failed;
|
||||
|
||||
const FString longPackagePath = FPackageName::GetLongPackagePath(asset->GetOutermost()->GetPathName());
|
||||
LoadAtlas(*asset->GetSkeletonDataFileName().ToString(), longPackagePath);
|
||||
|
||||
if (Obj->GetOuter()) Obj->GetOuter()->MarkPackageDirty();
|
||||
else Obj->MarkPackageDirty();
|
||||
|
||||
return EReimportResult::Succeeded;
|
||||
}
|
||||
|
||||
#undef LOCTEXT_NAMESPACE
|
||||
|
||||
@ -10,13 +10,13 @@ class USpineAtlasAssetFactory: public UFactory, public FReimportHandler {
|
||||
GENERATED_UCLASS_BODY()
|
||||
|
||||
virtual FText GetToolTip() const override;
|
||||
|
||||
|
||||
virtual bool FactoryCanImport(const FString& Filename) override;
|
||||
virtual UObject* FactoryCreateFile (UClass * InClass, UObject * InParent, FName InName, EObjectFlags Flags, const FString & Filename, const TCHAR* Parms, FFeedbackContext * Warn, bool& bOutOperationCanceled) override;
|
||||
|
||||
virtual bool CanReimport(UObject* Obj, TArray<FString>& OutFilenames) override;
|
||||
virtual void SetReimportPaths(UObject* Obj, const TArray<FString>& NewReimportPaths) override;
|
||||
virtual EReimportResult::Type Reimport(UObject* Obj) override;
|
||||
virtual UObject* FactoryCreateFile (UClass * InClass, UObject * InParent, FName InName, EObjectFlags Flags, const FString & Filename, const TCHAR* Parms, FFeedbackContext * Warn, bool& bOutOperationCanceled) override;
|
||||
|
||||
virtual bool CanReimport(UObject* Obj, TArray<FString>& OutFilenames) override;
|
||||
virtual void SetReimportPaths(UObject* Obj, const TArray<FString>& NewReimportPaths) override;
|
||||
virtual EReimportResult::Type Reimport(UObject* Obj) override;
|
||||
|
||||
void LoadAtlas(USpineAtlasAsset* Asset, const FString& CurrentSourcePath, const FString& LongPackagePath);
|
||||
void LoadAtlas(USpineAtlasAsset* Asset, const FString& CurrentSourcePath, const FString& LongPackagePath);
|
||||
};
|
||||
|
||||
@ -11,9 +11,9 @@ class USpineSkeletonAssetFactory : public UFactory, public FReimportHandler {
|
||||
|
||||
virtual FText GetToolTip () const override;
|
||||
virtual bool FactoryCanImport (const FString& Filename) override;
|
||||
virtual UObject* FactoryCreateFile (UClass * InClass, UObject * InParent, FName InName, EObjectFlags Flags, const FString & Filename, const TCHAR* Parms, FFeedbackContext * Warn, bool& bOutOperationCanceled) override;
|
||||
|
||||
virtual bool CanReimport (UObject* Obj, TArray<FString>& OutFilenames) override;
|
||||
virtual void SetReimportPaths (UObject* Obj, const TArray<FString>& NewReimportPaths) override;
|
||||
virtual EReimportResult::Type Reimport (UObject* Obj) override;
|
||||
virtual UObject* FactoryCreateFile (UClass * InClass, UObject * InParent, FName InName, EObjectFlags Flags, const FString & Filename, const TCHAR* Parms, FFeedbackContext * Warn, bool& bOutOperationCanceled) override;
|
||||
|
||||
virtual bool CanReimport (UObject* Obj, TArray<FString>& OutFilenames) override;
|
||||
virtual void SetReimportPaths (UObject* Obj, const TArray<FString>& NewReimportPaths) override;
|
||||
virtual EReimportResult::Type Reimport (UObject* Obj) override;
|
||||
};
|
||||
|
||||
@ -7,17 +7,17 @@
|
||||
#define LOCTEXT_NAMESPACE "Spine"
|
||||
|
||||
FString USpineAtlasAsset::GetRawData () const {
|
||||
return rawData;
|
||||
return rawData;
|
||||
}
|
||||
|
||||
FName USpineAtlasAsset::GetAtlasFileName () const {
|
||||
#if WITH_EDITORONLY_DATA
|
||||
TArray<FString> files;
|
||||
if (importData) importData->ExtractFilenames(files);
|
||||
if (files.Num() > 0) return FName(*files[0]);
|
||||
else return atlasFileName;
|
||||
TArray<FString> files;
|
||||
if (importData) importData->ExtractFilenames(files);
|
||||
if (files.Num() > 0) return FName(*files[0]);
|
||||
else return atlasFileName;
|
||||
#else
|
||||
return atlasFileName;
|
||||
return atlasFileName;
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -28,57 +28,57 @@ void USpineAtlasAsset::SetRawData (const FString &RawData) {
|
||||
}
|
||||
|
||||
void USpineAtlasAsset::SetAtlasFileName (const FName &AtlasFileName) {
|
||||
importData->UpdateFilenameOnly(AtlasFileName.ToString());
|
||||
TArray<FString> files;
|
||||
importData->ExtractFilenames(files);
|
||||
if (files.Num() > 0) atlasFileName = FName(*files[0]);
|
||||
importData->UpdateFilenameOnly(AtlasFileName.ToString());
|
||||
TArray<FString> files;
|
||||
importData->ExtractFilenames(files);
|
||||
if (files.Num() > 0) atlasFileName = FName(*files[0]);
|
||||
}
|
||||
|
||||
void USpineAtlasAsset::PostInitProperties () {
|
||||
if (!HasAnyFlags(RF_ClassDefaultObject)) importData = NewObject<UAssetImportData>(this, TEXT("AssetImportData"));
|
||||
Super::PostInitProperties();
|
||||
if (!HasAnyFlags(RF_ClassDefaultObject)) importData = NewObject<UAssetImportData>(this, TEXT("AssetImportData"));
|
||||
Super::PostInitProperties();
|
||||
}
|
||||
|
||||
void USpineAtlasAsset::GetAssetRegistryTags (TArray<FAssetRegistryTag>& OutTags) const {
|
||||
if (importData) {
|
||||
OutTags.Add(FAssetRegistryTag(SourceFileTagName(), importData->GetSourceData().ToJson(), FAssetRegistryTag::TT_Hidden) );
|
||||
}
|
||||
|
||||
Super::GetAssetRegistryTags(OutTags);
|
||||
if (importData) {
|
||||
OutTags.Add(FAssetRegistryTag(SourceFileTagName(), importData->GetSourceData().ToJson(), FAssetRegistryTag::TT_Hidden) );
|
||||
}
|
||||
|
||||
Super::GetAssetRegistryTags(OutTags);
|
||||
}
|
||||
|
||||
void USpineAtlasAsset::Serialize (FArchive& Ar) {
|
||||
Super::Serialize(Ar);
|
||||
if (Ar.IsLoading() && Ar.UE4Ver() < VER_UE4_ASSET_IMPORT_DATA_AS_JSON && !importData)
|
||||
importData = NewObject<UAssetImportData>(this, TEXT("AssetImportData"));
|
||||
Super::Serialize(Ar);
|
||||
if (Ar.IsLoading() && Ar.UE4Ver() < VER_UE4_ASSET_IMPORT_DATA_AS_JSON && !importData)
|
||||
importData = NewObject<UAssetImportData>(this, TEXT("AssetImportData"));
|
||||
}
|
||||
|
||||
void USpineAtlasAsset::BeginDestroy () {
|
||||
if (atlas) {
|
||||
spAtlas_dispose(atlas);
|
||||
atlas = nullptr;
|
||||
}
|
||||
Super::BeginDestroy();
|
||||
if (atlas) {
|
||||
spAtlas_dispose(atlas);
|
||||
atlas = nullptr;
|
||||
}
|
||||
Super::BeginDestroy();
|
||||
}
|
||||
|
||||
spAtlas* USpineAtlasAsset::GetAtlas (bool ForceReload) {
|
||||
if (!atlas || ForceReload) {
|
||||
if (atlas) {
|
||||
spAtlas_dispose(atlas);
|
||||
atlas = nullptr;
|
||||
}
|
||||
if (!atlas || ForceReload) {
|
||||
if (atlas) {
|
||||
spAtlas_dispose(atlas);
|
||||
atlas = nullptr;
|
||||
}
|
||||
std::string t = TCHAR_TO_UTF8(*rawData);
|
||||
atlas = spAtlas_create(t.c_str(), strlen(t.c_str()), "", nullptr);
|
||||
spAtlasPage* page = atlas->pages;
|
||||
int i = 0;
|
||||
while (page) {
|
||||
int num = atlasPages.Num();
|
||||
if (atlasPages.Num() > 0 && atlasPages.Num() > i)
|
||||
page->rendererObject = atlasPages[i++];
|
||||
page = page->next;
|
||||
}
|
||||
}
|
||||
return this->atlas;
|
||||
atlas = spAtlas_create(t.c_str(), strlen(t.c_str()), "", nullptr);
|
||||
spAtlasPage* page = atlas->pages;
|
||||
int i = 0;
|
||||
while (page) {
|
||||
int num = atlasPages.Num();
|
||||
if (atlasPages.Num() > 0 && atlasPages.Num() > i)
|
||||
page->rendererObject = atlasPages[i++];
|
||||
page = page->next;
|
||||
}
|
||||
}
|
||||
return this->atlas;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@ -16,9 +16,9 @@ void FSpinePlugin::ShutdownModule() { }
|
||||
// These are not used in the Spine UE4 plugin, see SpineAtlasAsset on how atlas page textures
|
||||
// are loaded, See SpineSkeletonRendererComponent on how these textures are used for rendering.
|
||||
extern "C" {
|
||||
void _spAtlasPage_createTexture (spAtlasPage* self, const char* path) { }
|
||||
void _spAtlasPage_disposeTexture (spAtlasPage* self) { }
|
||||
char* _spUtil_readFile (const char* path, int* length) { return 0; }
|
||||
void _spAtlasPage_createTexture (spAtlasPage* self, const char* path) { }
|
||||
void _spAtlasPage_disposeTexture (spAtlasPage* self) { }
|
||||
char* _spUtil_readFile (const char* path, int* length) { return 0; }
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
#include "SpinePlugin.h"
|
||||
|
||||
// You should place include statements to your module's private header files here. You only need to
|
||||
// You should place include statements to your module's private header files here. You only need to
|
||||
// add includes for headers that are used in most of your module's source files though.
|
||||
#include "SpineSkeletonDataAsset.h"
|
||||
#include "SpineAtlasAsset.h"
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
|
||||
USpineSkeletonComponent::USpineSkeletonComponent () {
|
||||
bWantsBeginPlay = true;
|
||||
PrimaryComponentTick.bCanEverTick = true;
|
||||
PrimaryComponentTick.bCanEverTick = true;
|
||||
bTickInEditor = true;
|
||||
bAutoActivate = true;
|
||||
}
|
||||
@ -33,7 +33,7 @@ void USpineSkeletonComponent::TickComponent (float DeltaTime, ELevelTick TickTyp
|
||||
if (state) {
|
||||
spAnimationState_update(state, DeltaTime);
|
||||
spAnimationState_apply(state, skeleton);
|
||||
spSkeleton_updateWorldTransform(skeleton);
|
||||
spSkeleton_updateWorldTransform(skeleton);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -8,74 +8,74 @@
|
||||
|
||||
FName USpineSkeletonDataAsset::GetSkeletonDataFileName () const {
|
||||
#if WITH_EDITORONLY_DATA
|
||||
TArray<FString> files;
|
||||
if (importData) importData->ExtractFilenames(files);
|
||||
if (files.Num() > 0) return FName(*files[0]);
|
||||
else return skeletonDataFileName;
|
||||
TArray<FString> files;
|
||||
if (importData) importData->ExtractFilenames(files);
|
||||
if (files.Num() > 0) return FName(*files[0]);
|
||||
else return skeletonDataFileName;
|
||||
#else
|
||||
return skeletonDataFileName;
|
||||
return skeletonDataFileName;
|
||||
#endif
|
||||
}
|
||||
|
||||
TArray<uint8>& USpineSkeletonDataAsset::GetRawData () {
|
||||
return this->rawData;
|
||||
return this->rawData;
|
||||
}
|
||||
|
||||
#if WITH_EDITORONLY_DATA
|
||||
|
||||
void USpineSkeletonDataAsset::SetSkeletonDataFileName (const FName &SkeletonDataFileName) {
|
||||
importData->UpdateFilenameOnly(SkeletonDataFileName.ToString());
|
||||
TArray<FString> files;
|
||||
importData->ExtractFilenames(files);
|
||||
if (files.Num() > 0) this->skeletonDataFileName = FName(*files[0]);
|
||||
importData->UpdateFilenameOnly(SkeletonDataFileName.ToString());
|
||||
TArray<FString> files;
|
||||
importData->ExtractFilenames(files);
|
||||
if (files.Num() > 0) this->skeletonDataFileName = FName(*files[0]);
|
||||
}
|
||||
|
||||
void USpineSkeletonDataAsset::PostInitProperties () {
|
||||
if (!HasAnyFlags(RF_ClassDefaultObject)) importData = NewObject<UAssetImportData>(this, TEXT("AssetImportData"));
|
||||
Super::PostInitProperties();
|
||||
if (!HasAnyFlags(RF_ClassDefaultObject)) importData = NewObject<UAssetImportData>(this, TEXT("AssetImportData"));
|
||||
Super::PostInitProperties();
|
||||
}
|
||||
|
||||
void USpineSkeletonDataAsset::GetAssetRegistryTags (TArray<FAssetRegistryTag>& OutTags) const {
|
||||
if (importData) {
|
||||
OutTags.Add(FAssetRegistryTag(SourceFileTagName(), importData->GetSourceData().ToJson(), FAssetRegistryTag::TT_Hidden) );
|
||||
}
|
||||
|
||||
Super::GetAssetRegistryTags(OutTags);
|
||||
if (importData) {
|
||||
OutTags.Add(FAssetRegistryTag(SourceFileTagName(), importData->GetSourceData().ToJson(), FAssetRegistryTag::TT_Hidden) );
|
||||
}
|
||||
|
||||
Super::GetAssetRegistryTags(OutTags);
|
||||
}
|
||||
|
||||
void USpineSkeletonDataAsset::Serialize (FArchive& Ar) {
|
||||
Super::Serialize(Ar);
|
||||
if (Ar.IsLoading() && Ar.UE4Ver() < VER_UE4_ASSET_IMPORT_DATA_AS_JSON && !importData)
|
||||
importData = NewObject<UAssetImportData>(this, TEXT("AssetImportData"));
|
||||
Super::Serialize(Ar);
|
||||
if (Ar.IsLoading() && Ar.UE4Ver() < VER_UE4_ASSET_IMPORT_DATA_AS_JSON && !importData)
|
||||
importData = NewObject<UAssetImportData>(this, TEXT("AssetImportData"));
|
||||
}
|
||||
|
||||
void USpineSkeletonDataAsset::BeginDestroy () {
|
||||
if (this->skeletonData) {
|
||||
spSkeletonData_dispose(this->skeletonData);
|
||||
this->skeletonData = nullptr;
|
||||
}
|
||||
Super::BeginDestroy();
|
||||
if (this->skeletonData) {
|
||||
spSkeletonData_dispose(this->skeletonData);
|
||||
this->skeletonData = nullptr;
|
||||
}
|
||||
Super::BeginDestroy();
|
||||
}
|
||||
|
||||
spSkeletonData* USpineSkeletonDataAsset::GetSkeletonData (spAtlas* Atlas, bool ForceReload) {
|
||||
if (!skeletonData || ForceReload) {
|
||||
if (skeletonData) {
|
||||
spSkeletonData_dispose(skeletonData);
|
||||
skeletonData = nullptr;
|
||||
}
|
||||
int dataLen = rawData.Num();
|
||||
if (skeletonDataFileName.GetPlainNameString().Contains(TEXT(".json"))) {
|
||||
spSkeletonJson* json = spSkeletonJson_create(Atlas);
|
||||
this->skeletonData = spSkeletonJson_readSkeletonData(json, (const char*)rawData.GetData());
|
||||
spSkeletonJson_dispose(json);
|
||||
} else {
|
||||
spSkeletonBinary* binary = spSkeletonBinary_create(Atlas);
|
||||
this->skeletonData = spSkeletonBinary_readSkeletonData(binary, (const unsigned char*)rawData.GetData(), (int)rawData.Num());
|
||||
spSkeletonBinary_dispose(binary);
|
||||
}
|
||||
lastAtlas = Atlas;
|
||||
}
|
||||
return this->skeletonData;
|
||||
if (!skeletonData || ForceReload) {
|
||||
if (skeletonData) {
|
||||
spSkeletonData_dispose(skeletonData);
|
||||
skeletonData = nullptr;
|
||||
}
|
||||
int dataLen = rawData.Num();
|
||||
if (skeletonDataFileName.GetPlainNameString().Contains(TEXT(".json"))) {
|
||||
spSkeletonJson* json = spSkeletonJson_create(Atlas);
|
||||
this->skeletonData = spSkeletonJson_readSkeletonData(json, (const char*)rawData.GetData());
|
||||
spSkeletonJson_dispose(json);
|
||||
} else {
|
||||
spSkeletonBinary* binary = spSkeletonBinary_create(Atlas);
|
||||
this->skeletonData = spSkeletonBinary_readSkeletonData(binary, (const unsigned char*)rawData.GetData(), (int)rawData.Num());
|
||||
spSkeletonBinary_dispose(binary);
|
||||
}
|
||||
lastAtlas = Atlas;
|
||||
}
|
||||
return this->skeletonData;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@ -6,41 +6,41 @@
|
||||
|
||||
UCLASS(ClassGroup=(Spine))
|
||||
class SPINEPLUGIN_API USpineAtlasAsset: public UObject {
|
||||
GENERATED_BODY()
|
||||
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
spAtlas* GetAtlas (bool ForceReload = false);
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Spine)
|
||||
TArray<UTexture2D*> atlasPages;
|
||||
|
||||
FString GetRawData () const;
|
||||
|
||||
FName GetAtlasFileName () const;
|
||||
|
||||
virtual void BeginDestroy () override;
|
||||
|
||||
spAtlas* GetAtlas (bool ForceReload = false);
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Spine)
|
||||
TArray<UTexture2D*> atlasPages;
|
||||
|
||||
FString GetRawData () const;
|
||||
|
||||
FName GetAtlasFileName () const;
|
||||
|
||||
virtual void BeginDestroy () override;
|
||||
|
||||
protected:
|
||||
spAtlas* atlas = nullptr;
|
||||
|
||||
UPROPERTY()
|
||||
FString rawData;
|
||||
|
||||
UPROPERTY()
|
||||
FName atlasFileName;
|
||||
|
||||
spAtlas* atlas = nullptr;
|
||||
|
||||
UPROPERTY()
|
||||
FString rawData;
|
||||
|
||||
UPROPERTY()
|
||||
FName atlasFileName;
|
||||
|
||||
#if WITH_EDITORONLY_DATA
|
||||
|
||||
public:
|
||||
void SetRawData (const FString &RawData);
|
||||
void SetAtlasFileName (const FName &AtlasFileName);
|
||||
|
||||
void SetRawData (const FString &RawData);
|
||||
void SetAtlasFileName (const FName &AtlasFileName);
|
||||
|
||||
protected:
|
||||
UPROPERTY(VisibleAnywhere, Instanced, Category=ImportSettings)
|
||||
class UAssetImportData* importData;
|
||||
|
||||
virtual void PostInitProperties ( ) override;
|
||||
virtual void GetAssetRegistryTags(TArray<FAssetRegistryTag>& OutTags) const override;
|
||||
virtual void Serialize (FArchive& Ar) override;
|
||||
UPROPERTY(VisibleAnywhere, Instanced, Category=ImportSettings)
|
||||
class UAssetImportData* importData;
|
||||
|
||||
virtual void PostInitProperties ( ) override;
|
||||
virtual void GetAssetRegistryTags(TArray<FAssetRegistryTag>& OutTags) const override;
|
||||
virtual void Serialize (FArchive& Ar) override;
|
||||
#endif
|
||||
};
|
||||
|
||||
@ -12,18 +12,18 @@ class SPINEPLUGIN_API USpineSkeletonComponent : public UActorComponent
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Spine)
|
||||
USpineAtlasAsset* Atlas;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Spine)
|
||||
USpineSkeletonDataAsset* SkeletonData;
|
||||
|
||||
spAnimationStateData* GetAnimationStateData () { return stateData; };
|
||||
|
||||
spAnimationState* GetAnimationState () { return state; };
|
||||
|
||||
spSkeleton* GetSkeleton () { return skeleton; };
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Spine)
|
||||
USpineAtlasAsset* Atlas;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Spine)
|
||||
USpineSkeletonDataAsset* SkeletonData;
|
||||
|
||||
spAnimationStateData* GetAnimationStateData () { return stateData; };
|
||||
|
||||
spAnimationState* GetAnimationState () { return state; };
|
||||
|
||||
spSkeleton* GetSkeleton () { return skeleton; };
|
||||
|
||||
USpineSkeletonComponent ();
|
||||
|
||||
virtual void BeginPlay () override;
|
||||
@ -35,9 +35,9 @@ public:
|
||||
protected:
|
||||
void DisposeState();
|
||||
|
||||
spAnimationStateData* stateData;
|
||||
spAnimationState* state;
|
||||
spSkeleton* skeleton;
|
||||
spAnimationStateData* stateData;
|
||||
spAnimationState* state;
|
||||
spSkeleton* skeleton;
|
||||
USpineAtlasAsset* lastAtlas = nullptr;
|
||||
USpineSkeletonDataAsset* lastData = nullptr;
|
||||
};
|
||||
|
||||
@ -6,36 +6,36 @@
|
||||
|
||||
UCLASS(ClassGroup=(Spine))
|
||||
class SPINEPLUGIN_API USpineSkeletonDataAsset: public UObject {
|
||||
GENERATED_BODY()
|
||||
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
spSkeletonData* GetSkeletonData(spAtlas* Atlas, bool ForceReload = false);
|
||||
|
||||
FName GetSkeletonDataFileName () const;
|
||||
TArray<uint8>& GetRawData ();
|
||||
|
||||
virtual void BeginDestroy () override;
|
||||
|
||||
spSkeletonData* GetSkeletonData(spAtlas* Atlas, bool ForceReload = false);
|
||||
|
||||
FName GetSkeletonDataFileName () const;
|
||||
TArray<uint8>& GetRawData ();
|
||||
|
||||
virtual void BeginDestroy () override;
|
||||
|
||||
protected:
|
||||
UPROPERTY()
|
||||
TArray<uint8> rawData;
|
||||
|
||||
spAtlas* lastAtlas = nullptr;
|
||||
spSkeletonData* skeletonData = nullptr;
|
||||
|
||||
UPROPERTY()
|
||||
FName skeletonDataFileName;
|
||||
|
||||
UPROPERTY()
|
||||
TArray<uint8> rawData;
|
||||
|
||||
spAtlas* lastAtlas = nullptr;
|
||||
spSkeletonData* skeletonData = nullptr;
|
||||
|
||||
UPROPERTY()
|
||||
FName skeletonDataFileName;
|
||||
|
||||
#if WITH_EDITORONLY_DATA
|
||||
public:
|
||||
void SetSkeletonDataFileName (const FName &skeletonDataFileName);
|
||||
|
||||
void SetSkeletonDataFileName (const FName &skeletonDataFileName);
|
||||
|
||||
protected:
|
||||
UPROPERTY(VisibleAnywhere, Instanced, Category=ImportSettings)
|
||||
class UAssetImportData* importData;
|
||||
|
||||
virtual void PostInitProperties ( ) override;
|
||||
virtual void GetAssetRegistryTags(TArray<FAssetRegistryTag>& OutTags) const override;
|
||||
virtual void Serialize (FArchive& Ar) override;
|
||||
UPROPERTY(VisibleAnywhere, Instanced, Category=ImportSettings)
|
||||
class UAssetImportData* importData;
|
||||
|
||||
virtual void PostInitProperties ( ) override;
|
||||
virtual void GetAssetRegistryTags(TArray<FAssetRegistryTag>& OutTags) const override;
|
||||
virtual void Serialize (FArchive& Ar) override;
|
||||
#endif
|
||||
};
|
||||
|
||||
@ -12,7 +12,7 @@ UCLASS(ClassGroup=(Spine), meta=(BlueprintSpawnableComponent))
|
||||
class SPINEPLUGIN_API USpineSkeletonRendererComponent: public UProceduralMeshComponent {
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
public:
|
||||
USpineSkeletonRendererComponent (const FObjectInitializer& ObjectInitializer);
|
||||
|
||||
virtual void BeginPlay () override;
|
||||
@ -24,10 +24,10 @@ public:
|
||||
|
||||
UPROPERTY(Category = Spine, EditAnywhere, BlueprintReadWrite)
|
||||
float DepthOffset = 0.1f;
|
||||
|
||||
UPROPERTY(Category = Spine, EditAnywhere, BlueprintReadWrite)
|
||||
FName TextureParameterName;
|
||||
|
||||
|
||||
UPROPERTY(Category = Spine, EditAnywhere, BlueprintReadWrite)
|
||||
FName TextureParameterName;
|
||||
|
||||
protected:
|
||||
void UpdateMesh (spSkeleton* Skeleton);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user