|
@@ -1,5 +1,14 @@
|
|
|
|
|
|
|
|
|
|
+#include <Atomic/Core/ProcessUtils.h>
|
|
|
#include <Atomic/IO/Log.h>
|
|
#include <Atomic/IO/Log.h>
|
|
|
|
|
+#include <Atomic/IO/File.h>
|
|
|
|
|
+#include <Atomic/IO/FileSystem.h>
|
|
|
|
|
+#include <Atomic/Scene/Node.h>
|
|
|
|
|
+
|
|
|
|
|
+#include <Atomic/Atomic3D/AnimationController.h>
|
|
|
|
|
+#include <Atomic/Atomic3D/Animation.h>
|
|
|
|
|
+
|
|
|
|
|
+#include <Atomic/Resource/ResourceCache.h>
|
|
|
|
|
|
|
|
#include "../Import/OpenAssetImporter.h"
|
|
#include "../Import/OpenAssetImporter.h"
|
|
|
|
|
|
|
@@ -11,7 +20,8 @@ namespace ToolCore
|
|
|
{
|
|
{
|
|
|
|
|
|
|
|
/// Node + Model (static or animated)
|
|
/// Node + Model (static or animated)
|
|
|
-ModelImporter::ModelImporter(Context* context) : AssetImporter(context)
|
|
|
|
|
|
|
+ModelImporter::ModelImporter(Context* context, Asset *asset) : AssetImporter(context),
|
|
|
|
|
+ asset_(asset)
|
|
|
{
|
|
{
|
|
|
SetDefaults();
|
|
SetDefaults();
|
|
|
}
|
|
}
|
|
@@ -26,45 +36,45 @@ void ModelImporter::SetDefaults()
|
|
|
AssetImporter::SetDefaults();
|
|
AssetImporter::SetDefaults();
|
|
|
|
|
|
|
|
scale_ = 1.0f;
|
|
scale_ = 1.0f;
|
|
|
- startTime_ = -1.0f;
|
|
|
|
|
- endTime_ = -1.0f;
|
|
|
|
|
importAnimations_ = false;
|
|
importAnimations_ = false;
|
|
|
|
|
+ animationInfo_.Clear();
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-bool ModelImporter::Import(const String& guid)
|
|
|
|
|
|
|
+bool ModelImporter::ImportModel()
|
|
|
{
|
|
{
|
|
|
- AssetDatabase* db = GetSubsystem<AssetDatabase>();
|
|
|
|
|
- Asset* asset = db->GetAssetByGUID(guid);
|
|
|
|
|
-
|
|
|
|
|
- if (!asset)
|
|
|
|
|
- return false;
|
|
|
|
|
-
|
|
|
|
|
SharedPtr<OpenAssetImporter> importer(new OpenAssetImporter(context_));
|
|
SharedPtr<OpenAssetImporter> importer(new OpenAssetImporter(context_));
|
|
|
|
|
|
|
|
//importer->SetVerboseLog(true);
|
|
//importer->SetVerboseLog(true);
|
|
|
|
|
|
|
|
- bool animationsOnly = false;
|
|
|
|
|
-
|
|
|
|
|
- String modelAssetFilename = asset->GetPath();
|
|
|
|
|
|
|
+ importer->SetScale(scale_);
|
|
|
|
|
+ importer->SetExportAnimations(false);
|
|
|
|
|
+ importer->SetImportNode(importNode_);
|
|
|
|
|
|
|
|
- if (modelAssetFilename.Contains("@"))
|
|
|
|
|
|
|
+ if (importer->Load(asset_->GetPath()))
|
|
|
{
|
|
{
|
|
|
- animationsOnly = true;
|
|
|
|
|
|
|
+ importer->ExportModel(asset_->GetCachePath());
|
|
|
|
|
+
|
|
|
|
|
+ return true;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- importer->SetScale(scale_);
|
|
|
|
|
- importer->SetStartTime(startTime_);
|
|
|
|
|
- importer->SetEndTime(endTime_);
|
|
|
|
|
- importer->SetExportAnimations(importAnimations_);
|
|
|
|
|
|
|
+ return false;
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
- if (importer->Load(asset->GetPath()))
|
|
|
|
|
- {
|
|
|
|
|
- String cachePath = db->GetCachePath();
|
|
|
|
|
|
|
+bool ModelImporter::ImportAnimation(const String& name, float startTime, float endTime)
|
|
|
|
|
+{
|
|
|
|
|
+ SharedPtr<OpenAssetImporter> importer(new OpenAssetImporter(context_));
|
|
|
|
|
|
|
|
- cachePath += guid;
|
|
|
|
|
|
|
+ //importer->SetVerboseLog(true);
|
|
|
|
|
|
|
|
- importer->ExportModel(cachePath, animationsOnly);
|
|
|
|
|
|
|
+ importer->SetScale(scale_);
|
|
|
|
|
+ importer->SetExportAnimations(true);
|
|
|
|
|
+ importer->SetStartTime(startTime);
|
|
|
|
|
+ importer->SetEndTime(endTime);
|
|
|
|
|
+
|
|
|
|
|
+ if (importer->Load(asset_->GetPath()))
|
|
|
|
|
+ {
|
|
|
|
|
+ importer->ExportModel(asset_->GetCachePath(), name, true);
|
|
|
|
|
|
|
|
const Vector<OpenAssetImporter::AnimationInfo>& infos = importer->GetAnimationInfos();
|
|
const Vector<OpenAssetImporter::AnimationInfo>& infos = importer->GetAnimationInfos();
|
|
|
|
|
|
|
@@ -72,14 +82,85 @@ bool ModelImporter::Import(const String& guid)
|
|
|
{
|
|
{
|
|
|
const OpenAssetImporter::AnimationInfo& info = infos.At(i);
|
|
const OpenAssetImporter::AnimationInfo& info = infos.At(i);
|
|
|
|
|
|
|
|
- LOGINFOF("Import Info: %s : %s", info.name_.CString(), info.cacheFilename_.CString());
|
|
|
|
|
|
|
+ String pathName, fileName, extension;
|
|
|
|
|
+
|
|
|
|
|
+ SplitPath(info.cacheFilename_, pathName, fileName, extension);
|
|
|
|
|
+
|
|
|
|
|
+ ResourceCache* cache = GetSubsystem<ResourceCache>();
|
|
|
|
|
+
|
|
|
|
|
+ AnimationController* controller = importNode_->GetComponent<AnimationController>();
|
|
|
|
|
+
|
|
|
|
|
+ if (controller)
|
|
|
|
|
+ {
|
|
|
|
|
+ SharedPtr<Animation> animation = cache->GetTempResource<Animation>(fileName + extension);
|
|
|
|
|
+ if (animation)
|
|
|
|
|
+ controller->AddAnimationResource(animation);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ LOGINFOF("Import Info: %s : %s", info.name_.CString(), fileName.CString());
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ return true;
|
|
|
}
|
|
}
|
|
|
- else
|
|
|
|
|
|
|
+
|
|
|
|
|
+ return false;
|
|
|
|
|
+
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+bool ModelImporter::ImportAnimations()
|
|
|
|
|
+{
|
|
|
|
|
+ if (!animationInfo_.Size())
|
|
|
{
|
|
{
|
|
|
|
|
+ return ImportAnimation("RootAnim");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ for (unsigned i = 0; i < animationInfo_.Size(); i++)
|
|
|
|
|
+ {
|
|
|
|
|
+ const SharedPtr<AnimationImportInfo>& info = animationInfo_[i];
|
|
|
|
|
+ if (!ImportAnimation(info->GetName(), info->GetStartTime(), info->GetEndTime()))
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return true;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+bool ModelImporter::Import(const String& guid)
|
|
|
|
|
+{
|
|
|
|
|
+ AssetDatabase* db = GetSubsystem<AssetDatabase>();
|
|
|
|
|
+ Asset* asset = db->GetAssetByGUID(guid);
|
|
|
|
|
+
|
|
|
|
|
+ if (!asset)
|
|
|
return false;
|
|
return false;
|
|
|
|
|
+
|
|
|
|
|
+ bool animationsOnly = false;
|
|
|
|
|
+
|
|
|
|
|
+ String modelAssetFilename = asset->GetPath();
|
|
|
|
|
+
|
|
|
|
|
+ importNode_ = new Node(context_);
|
|
|
|
|
+
|
|
|
|
|
+ if (modelAssetFilename.Contains("@"))
|
|
|
|
|
+ {
|
|
|
|
|
+ animationsOnly = true;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ if (!animationsOnly)
|
|
|
|
|
+ ImportModel();
|
|
|
|
|
+
|
|
|
|
|
+ if (importAnimations_)
|
|
|
|
|
+ {
|
|
|
|
|
+ ImportAnimations();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ File outFile(context_);
|
|
|
|
|
+
|
|
|
|
|
+ if (!outFile.Open(asset_->GetCachePath(), FILE_WRITE))
|
|
|
|
|
+ ErrorExit("Could not open output file " + asset_->GetCachePath());
|
|
|
|
|
+
|
|
|
|
|
+ importNode_->SaveXML(outFile);
|
|
|
|
|
+
|
|
|
|
|
+ importNode_ = 0;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -94,13 +175,28 @@ bool ModelImporter::LoadSettingsInternal()
|
|
|
|
|
|
|
|
if (import.HasMember("scale"))
|
|
if (import.HasMember("scale"))
|
|
|
scale_ = import.GetFloat("scale");
|
|
scale_ = import.GetFloat("scale");
|
|
|
- if (import.HasMember("startTime"))
|
|
|
|
|
- startTime_ = import.GetFloat("startTime");
|
|
|
|
|
- if (import.HasMember("endTime"))
|
|
|
|
|
- endTime_ = import.GetFloat("endTime");
|
|
|
|
|
|
|
+
|
|
|
if (import.HasMember("importAnimations"))
|
|
if (import.HasMember("importAnimations"))
|
|
|
importAnimations_ = import.GetBool("importAnimations");
|
|
importAnimations_ = import.GetBool("importAnimations");
|
|
|
|
|
|
|
|
|
|
+ if (import.HasMember("animInfo"))
|
|
|
|
|
+ {
|
|
|
|
|
+ JSONValue animInfo = import.GetChild("animInfo");
|
|
|
|
|
+ for (unsigned i = 0; i < animInfo.GetSize(); i++)
|
|
|
|
|
+ {
|
|
|
|
|
+ JSONValue anim = animInfo.GetChild(i);
|
|
|
|
|
+
|
|
|
|
|
+ SharedPtr<AnimationImportInfo> info(new AnimationImportInfo(context_));
|
|
|
|
|
+
|
|
|
|
|
+ info->name_ = anim.GetString("name");
|
|
|
|
|
+ info->SetStartTime(anim.GetFloat("startTime"));
|
|
|
|
|
+ info->SetEndTime(anim.GetFloat("endTime"));
|
|
|
|
|
+
|
|
|
|
|
+ animationInfo_.Push(info);
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -109,12 +205,21 @@ bool ModelImporter::SaveSettingsInternal()
|
|
|
if (!AssetImporter::SaveSettingsInternal())
|
|
if (!AssetImporter::SaveSettingsInternal())
|
|
|
return false;
|
|
return false;
|
|
|
|
|
|
|
|
- JSONValue import = jsonRoot_.CreateChild("ModelImporter");
|
|
|
|
|
|
|
+ JSONValue save = jsonRoot_.CreateChild("ModelImporter");
|
|
|
|
|
+
|
|
|
|
|
+ save.SetFloat("scale", scale_);
|
|
|
|
|
+ save.SetBool("importAnimations", importAnimations_);
|
|
|
|
|
+
|
|
|
|
|
+ JSONValue animInfo = save.CreateChild("animInfo", JSON_ARRAY);
|
|
|
|
|
|
|
|
- import.SetFloat("scale", scale_);
|
|
|
|
|
- import.SetFloat("startTime", startTime_);
|
|
|
|
|
- import.SetFloat("endTime", endTime_);
|
|
|
|
|
- import.SetBool("importAnimations", importAnimations_);
|
|
|
|
|
|
|
+ for (unsigned i = 0; i < animationInfo_.Size(); i++)
|
|
|
|
|
+ {
|
|
|
|
|
+ const SharedPtr<AnimationImportInfo>& info = animationInfo_[i];
|
|
|
|
|
+ JSONValue jinfo = animInfo.CreateChild();
|
|
|
|
|
+ jinfo.SetString("name", info->GetName());
|
|
|
|
|
+ jinfo.SetFloat("startTime", info->GetStartTime());
|
|
|
|
|
+ jinfo.SetFloat("endTime", info->GetEndTime());
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|