Browse Source

Added a setting in Import.json config file to toggle texture compression, defaulted to false. Moved loading of Import.json to the asset database to only happen once on project load. Moved existing model import settings under a ModelImporter object in the json schema.
NB: Breaking change for existing Import.json files, new format is:
{
"desktop": {

"ModelImporter": {
"aiFlagsDefault": {
"convertToLeftHanded": true,
"joinIdenticalVertices": true,
"triangulate": true,
"genSmoothNormals": true,
"limitBoneWeights": true,
"improveCacheLocality": true,
"fixInfacingNormals": false,
"findInvalidData": true,
"genUVCoords": true,
"findInstances": true,
"optimizeMeshes": true
}
},

"TextureImporter": {
"compressTextures": false
}
}

}

Matt Benic 9 years ago
parent
commit
6335dc4d9f

+ 17 - 1
Source/Atomic/Resource/Configuration.cpp

@@ -63,6 +63,11 @@ namespace Atomic
     }
 
 
+    Configuration::Configuration() :
+        isLoaded_(false)
+    {
+    }
+
     bool Configuration::LoadFromFile(Context *context, const String& filename)
     {
 
@@ -89,6 +94,11 @@ namespace Atomic
 
     void Configuration::ApplyConfig(VariantMap& settings, bool overwrite)
     {
+        if (!isLoaded_) {
+            LOGERROR("Configuration::ApplyConfig - Applying a config that has not yet been populated");
+            return;
+        }
+
         VariantMap::ConstIterator itr = valueMap_.Begin();
         if (overwrite)
         {
@@ -111,7 +121,7 @@ namespace Atomic
 
     bool Configuration::LoadFromJSON(const String& json)
     {
-        valueMap_.Clear();
+        Clear();
 
         JSONValue jroot;
 
@@ -127,7 +137,13 @@ namespace Atomic
         if (!LoadDesktopConfig(jroot))
             return false;
 
+        isLoaded_ = true;
         return true;
     }
 
+    void Configuration::Clear()
+    {
+        valueMap_.Clear();
+    }
+
 }

+ 5 - 0
Source/Atomic/Resource/Configuration.h

@@ -34,13 +34,17 @@ class Configuration
 {
 public:
 
+    Configuration();
+
     bool LoadFromFile(Context* context, const String& filename);
     bool LoadFromJSON(const String& json);
+    void Clear();
 
     /// Apply the configuration to a setting variant map, values that exist will not be overriden
     void ApplyConfig(VariantMap& settings, bool overwrite = false);
 
     const VariantMap& GetConfig() { return valueMap_; }
+    const bool IsLoaded() const { return isLoaded_; }
 
 protected:
     static bool GetBoolValue(const JSONValue& jvalue, bool defaultValue);
@@ -53,6 +57,7 @@ protected:
 
 private:
     String filename_;
+    bool isLoaded_;
 };
 }
 

+ 1 - 1
Source/Atomic/Resource/JSONFile.cpp

@@ -146,7 +146,7 @@ bool JSONFile::ParseJSON(const String& json, JSONValue& value, bool reportError)
     if (document.Parse<0>(json.CString()).HasParseError())
     {
         if (reportError)
-            LOGERROR("Could not parse JSON data from string");
+            LOGERRORF("Could not parse JSON data from string with error: %s", document.GetParseError());
 
         return false;
     }

+ 21 - 0
Source/ToolCore/Assets/AssetDatabase.cpp

@@ -30,6 +30,7 @@
 #include <Atomic/Resource/ResourceEvents.h>
 #include <Atomic/Resource/ResourceCache.h>
 
+#include "../Import/ImportConfig.h"
 #include "../ToolEvents.h"
 #include "../ToolSystem.h"
 #include "../Project/Project.h"
@@ -102,6 +103,24 @@ void AssetDatabase::RegisterGUID(const String& guid)
     usedGUID_.Push(guid);
 }
 
+void AssetDatabase::ReadImportConfig()
+{
+    ImportConfig::Clear();
+
+    ToolSystem* tsystem = GetSubsystem<ToolSystem>();
+    Project* project = tsystem->GetProject();
+
+    String projectPath = project->GetProjectPath();
+
+    String filename = projectPath + "Settings/Import.json";
+
+    FileSystem* fileSystem = GetSubsystem<FileSystem>();
+    if (!fileSystem->FileExists(filename))
+        return;
+
+    ImportConfig::LoadFromFile(context_, filename);
+}
+
 void AssetDatabase::Import(const String& path)
 {
     FileSystem* fs = GetSubsystem<FileSystem>();
@@ -434,6 +453,8 @@ void AssetDatabase::HandleProjectLoaded(StringHash eventType, VariantMap& eventD
 {
     project_ = GetSubsystem<ToolSystem>()->GetProject();
 
+    ReadImportConfig();
+
     FileSystem* fs = GetSubsystem<FileSystem>();
 
     if (!fs->DirExists(GetCachePath()))

+ 1 - 0
Source/ToolCore/Assets/AssetDatabase.h

@@ -79,6 +79,7 @@ private:
 
     void PruneOrphanedDotAssetFiles();
 
+    void ReadImportConfig();
     void Import(const String& path);
 
     bool ImportDirtyAssets();

+ 23 - 3
Source/ToolCore/Assets/TextureImporter.cpp

@@ -26,6 +26,8 @@
 #include <Atomic/Atomic2D/StaticSprite2D.h>
 #include <Atomic/IO/FileSystem.h>
 
+#include <ToolCore/Import/ImportConfig.h>
+
 #include "Asset.h"
 #include "AssetDatabase.h"
 #include "TextureImporter.h"
@@ -33,9 +35,10 @@
 namespace ToolCore
 {
 
-TextureImporter::TextureImporter(Context* context, Asset *asset) : AssetImporter(context, asset)
+TextureImporter::TextureImporter(Context* context, Asset *asset) : AssetImporter(context, asset),
+compressTextures_(false)
 {
-
+    ApplyProjectImportConfig();
 }
 
 TextureImporter::~TextureImporter()
@@ -70,7 +73,8 @@ bool TextureImporter::Import()
 
     // #623 BEGIN TODO: Save per-platform compressed version to cache
 #if ATOMIC_PLATFORM_WINDOWS
-    if (!image->IsCompressed())
+    if (compressTextures_ &&
+        !image->IsCompressed())
     {
         fileSystem->CreateDirs(cachePath, "DDS/" + Atomic::GetPath(asset_->GetRelativePath()));
         image->SaveDDS(compressedPath);
@@ -91,6 +95,22 @@ bool TextureImporter::Import()
     return true;
 }
 
+void TextureImporter::ApplyProjectImportConfig()
+{
+    if (ImportConfig::IsLoaded())
+    {
+        VariantMap tiParameters;
+        ImportConfig::ApplyConfig(tiParameters);
+        VariantMap::ConstIterator itr = tiParameters.Begin();
+
+        for (; itr != tiParameters.End(); itr++)
+        {
+            if (itr->first_ == "tiProcess_CompressTextures")
+                compressTextures_ = itr->second_.GetBool();
+        }
+    }
+}
+
 bool TextureImporter::LoadSettingsInternal(JSONValue& jsonRoot)
 {
     if (!AssetImporter::LoadSettingsInternal(jsonRoot))

+ 2 - 0
Source/ToolCore/Assets/TextureImporter.h

@@ -44,10 +44,12 @@ public:
 protected:
 
     bool Import();
+    void ApplyProjectImportConfig();
 
     virtual bool LoadSettingsInternal(JSONValue& jsonRoot);
     virtual bool SaveSettingsInternal(JSONValue& jsonRoot);
 
+    bool compressTextures_;
 };
 
 }

+ 23 - 4
Source/ToolCore/Import/ImportConfig.cpp

@@ -33,8 +33,9 @@ namespace Atomic
 
 ImportConfig ImportConfig::importConfig_;
 
-bool ImportConfig::LoadAIFlagsDefaultConfig(const JSONValue& jflags)
+bool ImportConfig::LoadModelImporterConfig(const JSONValue& jModelImporterConfig)
 {
+    const JSONValue& jflags = jModelImporterConfig["aiFlagsDefault"];
     if (!jflags.IsObject())
         return false;
 
@@ -72,6 +73,20 @@ bool ImportConfig::LoadAIFlagsDefaultConfig(const JSONValue& jflags)
     return true;
 }
 
+bool ImportConfig::LoadTextureImporterConfig(const JSONValue& jTextureImporterConfig)
+{
+    for (JSONObject::ConstIterator i = jTextureImporterConfig.Begin(); i != jTextureImporterConfig.End(); ++i)
+    {
+        String key = i->first_;
+        const JSONValue& jvalue = i->second_;
+
+        if (key == "compressTextures")
+            valueMap_["tiProcess_CompressTextures"] = GetBoolValue(jvalue, false);
+    }
+
+    return true;
+}
+
 bool ImportConfig::LoadDesktopConfig(JSONValue root)
 {
     const JSONValue& jdesktop = root["desktop"];
@@ -79,10 +94,14 @@ bool ImportConfig::LoadDesktopConfig(JSONValue root)
     if (!jdesktop.IsObject())
         return false;
 
-    const JSONValue& jflags = jdesktop["aiFlagsDefault"];
-    if (jflags.IsObject())
-        LoadAIFlagsDefaultConfig(jflags);
+    const JSONValue& jModelImporterConfig = jdesktop["ModelImporter"];
+    if (jModelImporterConfig.IsObject())
+        LoadModelImporterConfig(jModelImporterConfig);
  
+    const JSONValue& jTextureImporterConfig = jdesktop["TextureImporter"];
+    if (jTextureImporterConfig.IsObject())
+        LoadTextureImporterConfig(jTextureImporterConfig);
+
     return true;
 }
 

+ 5 - 1
Source/ToolCore/Import/ImportConfig.h

@@ -39,14 +39,18 @@ public:
 
     static bool LoadFromFile(Context* context, const String& filename) { return importConfig_.Configuration::LoadFromFile(context, filename); }
     static bool LoadFromJSON(const String& json) { return importConfig_.Configuration::LoadFromJSON(json); }
+    static void Clear() { importConfig_.Configuration::Clear();  }
 
     /// Apply the configuration to a setting variant map, values that exist will not be overriden
     static void ApplyConfig(VariantMap& settings, bool overwrite = false) { return importConfig_.Configuration::ApplyConfig(settings, overwrite); }
 
+    static bool IsLoaded() { return importConfig_.Configuration::IsLoaded(); };
+
 private:
 
     virtual bool LoadDesktopConfig(JSONValue root);
-    bool LoadAIFlagsDefaultConfig(const JSONValue& jflags);
+    bool LoadModelImporterConfig(const JSONValue& jModelImporterConfig);
+    bool LoadTextureImporterConfig(const JSONValue& jTextureImporterConfig);
 
     static ImportConfig importConfig_;
 };

+ 4 - 16
Source/ToolCore/Import/OpenAssetImporter.cpp

@@ -27,7 +27,6 @@
 #include <Atomic/IO/Log.h>
 #include <Atomic/IO/File.h>
 #include <Atomic/IO/FileSystem.h>
-#include <ToolCore/Import/ImportConfig.h>
 
 #include <Atomic/Resource/XMLFile.h>
 #include <Atomic/Resource/ResourceCache.h>
@@ -43,6 +42,7 @@
 
 #include <ToolCore/Project/Project.h>
 #include <ToolCore/ToolSystem.h>
+#include <ToolCore/Import/ImportConfig.h>
 
 #include "OpenAssetImporter.h"
 
@@ -90,7 +90,7 @@ OpenAssetImporter::OpenAssetImporter(Context* context) : Object(context) ,
         aiProcess_FindInstances |
         aiProcess_OptimizeMeshes;
 
-    ReadImportConfig();
+    ApplyProjectImportConfig();
 
     // TODO:  make this an option on importer
 
@@ -908,26 +908,14 @@ void OpenAssetImporter::SetOveriddenFlags(VariantMap& aiFlagParameters)
 
 }
 
-void OpenAssetImporter::ReadImportConfig()
+void OpenAssetImporter::ApplyProjectImportConfig()
 {
-    ToolSystem* tsystem = GetSubsystem<ToolSystem>();
-    Project* project = tsystem->GetProject();
-
-    String projectPath = project->GetProjectPath();
-
-    String filename = projectPath + "Settings/Import.json";
-
-    FileSystem* fileSystem = GetSubsystem<FileSystem>();
-    if (!fileSystem->FileExists(filename))
-        return;
-
-    if (ImportConfig::LoadFromFile(context_, filename))
+    if (ImportConfig::IsLoaded())
     {
         VariantMap aiFlagParameters;
         ImportConfig::ApplyConfig(aiFlagParameters);
         SetOveriddenFlags(aiFlagParameters);
     }
-
 }
 
 void OpenAssetImporter::BuildBoneCollisionInfo(OutModel& model)

+ 1 - 1
Source/ToolCore/Import/OpenAssetImporter.h

@@ -82,7 +82,7 @@ private:
     void BuildBoneCollisionInfo(OutModel& model);
     void CollectAnimations(OutModel* model = 0);
 
-    void ReadImportConfig();
+    void ApplyProjectImportConfig();
     void SetOveriddenFlags(VariantMap& aiFlagParameters);
     void ApplyFlag(int processStep, bool active);