mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-21 17:56:04 +08:00
[ue4] Extended skeleton data editor preview. It now shows bones, slots, animations, and skins. Closes #1047.
This commit is contained in:
parent
444f604df3
commit
4ba46d76e8
@ -76,6 +76,7 @@ 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"));
|
||||
LoadInfo();
|
||||
}
|
||||
|
||||
#endif
|
||||
@ -92,13 +93,85 @@ void USpineSkeletonDataAsset::BeginDestroy () {
|
||||
Super::BeginDestroy();
|
||||
}
|
||||
|
||||
class SP_API NullAttachmentLoader : public AttachmentLoader {
|
||||
public:
|
||||
|
||||
virtual RegionAttachment* newRegionAttachment(Skin& skin, const String& name, const String& path) {
|
||||
return new(__FILE__, __LINE__) RegionAttachment(name);
|
||||
}
|
||||
|
||||
virtual MeshAttachment* newMeshAttachment(Skin& skin, const String& name, const String& path) {
|
||||
return new(__FILE__, __LINE__) MeshAttachment(name);
|
||||
}
|
||||
|
||||
virtual BoundingBoxAttachment* newBoundingBoxAttachment(Skin& skin, const String& name) {
|
||||
return new(__FILE__, __LINE__) BoundingBoxAttachment(name);
|
||||
}
|
||||
|
||||
virtual PathAttachment* newPathAttachment(Skin& skin, const String& name) {
|
||||
return new(__FILE__, __LINE__) PathAttachment(name);
|
||||
}
|
||||
|
||||
virtual PointAttachment* newPointAttachment(Skin& skin, const String& name) {
|
||||
return new(__FILE__, __LINE__) PointAttachment(name);
|
||||
}
|
||||
|
||||
virtual ClippingAttachment* newClippingAttachment(Skin& skin, const String& name) {
|
||||
return new(__FILE__, __LINE__) ClippingAttachment(name);
|
||||
}
|
||||
|
||||
virtual void configureAttachment(Attachment* attachment) {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
void USpineSkeletonDataAsset::LoadInfo() {
|
||||
#if WITH_EDITORONLY_DATA
|
||||
int dataLen = rawData.Num();
|
||||
NullAttachmentLoader loader;
|
||||
SkeletonData* skeletonData = nullptr;
|
||||
if (skeletonDataFileName.GetPlainNameString().Contains(TEXT(".json"))) {
|
||||
SkeletonJson* json = new (__FILE__, __LINE__) SkeletonJson(&loader);
|
||||
skeletonData = json->readSkeletonData((const char*)rawData.GetData());
|
||||
if (!skeletonData) {
|
||||
FMessageDialog::Debugf(FText::FromString(UTF8_TO_TCHAR(json->getError().buffer())));
|
||||
UE_LOG(SpineLog, Error, TEXT("Couldn't load skeleton data and atlas: %s"), UTF8_TO_TCHAR(json->getError().buffer()));
|
||||
}
|
||||
delete json;
|
||||
} else {
|
||||
SkeletonBinary* binary = new (__FILE__, __LINE__) SkeletonBinary(&loader);
|
||||
skeletonData = binary->readSkeletonData((const unsigned char*)rawData.GetData(), (int)rawData.Num());
|
||||
if (!skeletonData) {
|
||||
FMessageDialog::Debugf(FText::FromString(UTF8_TO_TCHAR(binary->getError().buffer())));
|
||||
UE_LOG(SpineLog, Error, TEXT("Couldn't load skeleton data and atlas: %s"), UTF8_TO_TCHAR(binary->getError().buffer()));
|
||||
}
|
||||
delete binary;
|
||||
}
|
||||
if (skeletonData) {
|
||||
Bones.Empty();
|
||||
for (int i = 0; i < skeletonData->getBones().size(); i++)
|
||||
Bones.Add(skeletonData->getBones()[i]->getName().buffer());
|
||||
Skins.Empty();
|
||||
for (int i = 0; i < skeletonData->getSkins().size(); i++)
|
||||
Skins.Add(skeletonData->getSkins()[i]->getName().buffer());
|
||||
Animations.Empty();
|
||||
for (int i = 0; i < skeletonData->getAnimations().size(); i++)
|
||||
Animations.Add(skeletonData->getAnimations()[i]->getName().buffer());
|
||||
delete skeletonData;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void USpineSkeletonDataAsset::SetRawData(TArray<uint8> &Data) {
|
||||
this->rawData.Empty();
|
||||
this->rawData.Append(Data);
|
||||
|
||||
if (skeletonData) {
|
||||
delete skeletonData;
|
||||
skeletonData = nullptr;
|
||||
}
|
||||
|
||||
LoadInfo();
|
||||
}
|
||||
|
||||
SkeletonData* USpineSkeletonDataAsset::GetSkeletonData (Atlas* Atlas) {
|
||||
|
||||
@ -71,6 +71,18 @@ public:
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||
TArray<FSpineAnimationStateMixData> MixData;
|
||||
|
||||
UPROPERTY(Transient, VisibleAnywhere)
|
||||
TArray<FString> Bones;
|
||||
|
||||
UPROPERTY(Transient, VisibleAnywhere)
|
||||
TArray<FString> Slots;
|
||||
|
||||
UPROPERTY(Transient, VisibleAnywhere)
|
||||
TArray<FString> Skins;
|
||||
|
||||
UPROPERTY(Transient, VisibleAnywhere)
|
||||
TArray<FString> Animations;
|
||||
|
||||
protected:
|
||||
UPROPERTY()
|
||||
TArray<uint8> rawData;
|
||||
@ -94,4 +106,6 @@ protected:
|
||||
virtual void GetAssetRegistryTags(TArray<FAssetRegistryTag>& OutTags) const override;
|
||||
virtual void Serialize (FArchive& Ar) override;
|
||||
#endif
|
||||
|
||||
void LoadInfo();
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user