|
@@ -5,8 +5,9 @@
|
|
|
#include <Atomic/IO/FileSystem.h>
|
|
#include <Atomic/IO/FileSystem.h>
|
|
|
#include <Atomic/Scene/Node.h>
|
|
#include <Atomic/Scene/Node.h>
|
|
|
|
|
|
|
|
-#include <Atomic/Atomic3D/AnimationController.h>
|
|
|
|
|
|
|
+#include <Atomic/Atomic3D/AnimatedModel.h>
|
|
|
#include <Atomic/Atomic3D/Animation.h>
|
|
#include <Atomic/Atomic3D/Animation.h>
|
|
|
|
|
+#include <Atomic/Atomic3D/StaticModel.h>
|
|
|
#include <Atomic/Atomic3D/Model.h>
|
|
#include <Atomic/Atomic3D/Model.h>
|
|
|
|
|
|
|
|
#include <Atomic/Resource/ResourceCache.h>
|
|
#include <Atomic/Resource/ResourceCache.h>
|
|
@@ -43,9 +44,12 @@ void ModelImporter::SetDefaults()
|
|
|
|
|
|
|
|
bool ModelImporter::ImportModel()
|
|
bool ModelImporter::ImportModel()
|
|
|
{
|
|
{
|
|
|
|
|
+
|
|
|
|
|
+ LOGDEBUGF("Importing Model: %s", asset_->GetPath().CString());
|
|
|
|
|
+
|
|
|
SharedPtr<OpenAssetImporter> importer(new OpenAssetImporter(context_));
|
|
SharedPtr<OpenAssetImporter> importer(new OpenAssetImporter(context_));
|
|
|
|
|
|
|
|
- //importer->SetVerboseLog(true);
|
|
|
|
|
|
|
+ importer->SetVerboseLog(true);
|
|
|
|
|
|
|
|
importer->SetScale(scale_);
|
|
importer->SetScale(scale_);
|
|
|
importer->SetExportAnimations(false);
|
|
importer->SetExportAnimations(false);
|
|
@@ -92,13 +96,19 @@ bool ModelImporter::ImportAnimation(const String& filename, const String& name,
|
|
|
|
|
|
|
|
ResourceCache* cache = GetSubsystem<ResourceCache>();
|
|
ResourceCache* cache = GetSubsystem<ResourceCache>();
|
|
|
|
|
|
|
|
- AnimationController* controller = importNode_->GetComponent<AnimationController>();
|
|
|
|
|
|
|
+ AnimatedModel* animatedModel = importNode_->GetComponent<AnimatedModel>();
|
|
|
|
|
|
|
|
- if (controller)
|
|
|
|
|
|
|
+ if (animatedModel)
|
|
|
{
|
|
{
|
|
|
- SharedPtr<Animation> animation = cache->GetTempResource<Animation>(fileName + extension);
|
|
|
|
|
- if (animation)
|
|
|
|
|
- controller->AddAnimationResource(animation);
|
|
|
|
|
|
|
+ Model* model = animatedModel->GetModel();
|
|
|
|
|
+
|
|
|
|
|
+ if (model)
|
|
|
|
|
+ {
|
|
|
|
|
+ SharedPtr<Animation> animation = cache->GetTempResource<Animation>(fileName + extension);
|
|
|
|
|
+ if (animation)
|
|
|
|
|
+ model->AddAnimationResource(animation);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
LOGINFOF("Import Info: %s : %s", info.name_.CString(), fileName.CString());
|
|
LOGINFOF("Import Info: %s : %s", info.name_.CString(), fileName.CString());
|
|
@@ -183,22 +193,74 @@ bool ModelImporter::ImportAnimations()
|
|
|
|
|
|
|
|
bool ModelImporter::Import()
|
|
bool ModelImporter::Import()
|
|
|
{
|
|
{
|
|
|
|
|
+
|
|
|
|
|
+ String ext = asset_->GetExtension();
|
|
|
String modelAssetFilename = asset_->GetPath();
|
|
String modelAssetFilename = asset_->GetPath();
|
|
|
|
|
|
|
|
importNode_ = new Node(context_);
|
|
importNode_ = new Node(context_);
|
|
|
|
|
|
|
|
- // skip external animations, they will be brought in when importing their
|
|
|
|
|
- // corresponding model
|
|
|
|
|
- if (!modelAssetFilename.Contains("@"))
|
|
|
|
|
|
|
+ if (ext == ".mdl")
|
|
|
{
|
|
{
|
|
|
- ImportModel();
|
|
|
|
|
|
|
+ FileSystem* fs = GetSubsystem<FileSystem>();
|
|
|
|
|
+ ResourceCache* cache = GetSubsystem<ResourceCache>();
|
|
|
|
|
+
|
|
|
|
|
+ // mdl files are native file format that doesn't need to be converted
|
|
|
|
|
+ // doesn't allow scale, animations legacy primarily for ToonTown
|
|
|
|
|
|
|
|
- if (importAnimations_)
|
|
|
|
|
|
|
+ if (!fs->Copy(asset_->GetPath(), asset_->GetCachePath() + ".mdl"))
|
|
|
{
|
|
{
|
|
|
- ImportAnimations();
|
|
|
|
|
|
|
+ importNode_= 0;
|
|
|
|
|
+ return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ Model* mdl = cache->GetResource<Model>( asset_->GetCachePath() + ".mdl");
|
|
|
|
|
+
|
|
|
|
|
+ if (!mdl)
|
|
|
|
|
+ {
|
|
|
|
|
+ importNode_= 0;
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Force a reload, though file watchers will catch this delayed and load again
|
|
|
|
|
+ cache->ReloadResource(mdl);
|
|
|
|
|
+
|
|
|
|
|
+ importNode_->CreateComponent<StaticModel>()->SetModel(mdl);
|
|
|
}
|
|
}
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ // skip external animations, they will be brought in when importing their
|
|
|
|
|
+ // corresponding model
|
|
|
|
|
+
|
|
|
|
|
+ if (!modelAssetFilename.Contains("@"))
|
|
|
|
|
+ {
|
|
|
|
|
+ ImportModel();
|
|
|
|
|
+
|
|
|
|
|
+ if (importAnimations_)
|
|
|
|
|
+ {
|
|
|
|
|
+ ImportAnimations();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ AnimatedModel* animatedModel = importNode_->GetComponent<AnimatedModel>();
|
|
|
|
|
+ if (animatedModel)
|
|
|
|
|
+ {
|
|
|
|
|
+ Model* model = animatedModel->GetModel();
|
|
|
|
|
+ if (model && model->GetAnimationCount())
|
|
|
|
|
+ {
|
|
|
|
|
+ // resave with animation info
|
|
|
|
|
+
|
|
|
|
|
+ File mdlFile(context_);
|
|
|
|
|
+ if (!mdlFile.Open(asset_->GetCachePath() + ".mdl", FILE_WRITE))
|
|
|
|
|
+ {
|
|
|
|
|
+ ErrorExit("Could not open output file " + asset_->GetCachePath() + ".mdl");
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ model->Save(mdlFile);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
|
|
|
File outFile(context_);
|
|
File outFile(context_);
|
|
|
|
|
|