浏览代码

init commit

start of attempt 3
marauder2k7 9 月之前
父节点
当前提交
eca0820134

+ 232 - 129
Engine/source/T3D/assets/ImageAsset.cpp

@@ -106,6 +106,56 @@ ConsoleSetType(TypeImageAssetId)
    // Warn.
    // Warn.
    Con::warnf("(TypeImageAssetId) - Cannot set multiple args to a single asset.");
    Con::warnf("(TypeImageAssetId) - Cannot set multiple args to a single asset.");
 }
 }
+
+//-----------------------------------------------------------------------------
+
+//-----------------------------------------------------------------------------
+// REFACTOR
+//-----------------------------------------------------------------------------
+
+IMPLEMENT_STRUCT(AssetPtr<ImageAsset>, AssetPtrImageAsset,, "")
+END_IMPLEMENT_STRUCT
+
+ConsoleType(ImageAssetPtr, TypeImageAssetPtrRefactor, AssetPtr<ImageAsset>, "")
+
+
+ConsoleGetType(TypeImageAssetPtrRefactor)
+{
+   // Fetch asset Id.
+   return (*((AssetPtr<ImageAsset>*)dptr)).getAssetId();
+}
+
+ConsoleSetType(TypeImageAssetPtrRefactor)
+{
+   // Was a single argument specified?
+   if (argc == 1)
+   {
+      // Yes, so fetch field value.
+      const char* pFieldValue = argv[0];
+
+      // Fetch asset pointer.
+      AssetPtr<ImageAsset>* pAssetPtr = dynamic_cast<AssetPtr<ImageAsset>*>((AssetPtrBase*)(dptr));
+
+      // Is the asset pointer the correct type?
+      if (pAssetPtr == NULL)
+      {
+         // No, so fail.
+         Con::warnf("(TypeImageAssetPtr) - Failed to set asset Id '%d'.", pFieldValue);
+         return;
+      }
+
+      // Set asset.
+      pAssetPtr->setAssetId(pFieldValue);
+
+      return;
+   }
+
+   // Warn.
+   Con::warnf("(TypeImageAssetPtr) - Cannot set multiple args to a single asset.");
+}
+
+//-----------------------------------------------------------------------------
+// REFACTOR END
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 
 
 ImplementEnumType(ImageAssetType,
 ImplementEnumType(ImageAssetType,
@@ -131,14 +181,6 @@ const String ImageAsset::mErrCodeStrings[] =
    "UnKnown"
    "UnKnown"
 };
 };
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
-ImageAsset::ImageAsset() : AssetBase(), mIsValidImage(false), mUseMips(true), mIsHDRImage(false), mImageType(Albedo)
-{
-   mImageFileName = StringTable->EmptyString();
-   mImagePath = StringTable->EmptyString();
-   mLoadedState = AssetErrCode::NotLoaded;
-   mChangeSignal.notify(this, &ImageAsset::onAssetRefresh);
-}
-
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 
 
 ImageAsset::~ImageAsset()
 ImageAsset::~ImageAsset()
@@ -164,17 +206,28 @@ void ImageAsset::initPersistFields()
    // Call parent.
    // Call parent.
    Parent::initPersistFields();
    Parent::initPersistFields();
 
 
-   addProtectedField("imageFile", TypeAssetLooseFilePath, Offset(mImageFileName, ImageAsset),
-      &setImageFileName, &getImageFileName, "Path to the image file.");
+   addProtectedField("imageFile", TypeAssetLooseFilePath, Offset(mImageFile, ImageAsset), &setImageFile, &getImageFile, &writeImageFile, "Path to the image file.");
 
 
-   addField("useMips", TypeBool, Offset(mUseMips, ImageAsset), "Should the image use mips? (Currently unused).");
-   addField("isHDRImage", TypeBool, Offset(mIsHDRImage, ImageAsset), "Is the image in an HDR format? (Currently unused)");
+   addProtectedField("useMips", TypeBool, Offset(mUseMips, ImageAsset), &setGenMips, &defaultProtectedGetFn, &writeGenMips, "Generate mip maps?");
+   addProtectedField("isHDRImage", TypeBool, Offset(mIsHDRImage, ImageAsset), &setTextureHDR, &defaultProtectedGetFn, &writeTextureHDR, "HDR Image?");
 
 
    addField("imageType", TypeImageAssetType, Offset(mImageType, ImageAsset), "What the main use-case for the image is for.");
    addField("imageType", TypeImageAssetType, Offset(mImageType, ImageAsset), "What the main use-case for the image is for.");
 }
 }
+bool ImageAsset::onAdd()
+{
+   // Call Parent.
+   if (!Parent::onAdd())
+      return false;
+
+   return true;
+}
+
+void ImageAsset::onRemove()
+{
+   // Call Parent.
+   Parent::onRemove();
+}
 
 
-//------------------------------------------------------------------------------
-//Utility function to 'fill out' bindings and resources with a matching asset if one exists
 U32 ImageAsset::getAssetByFilename(StringTableEntry fileName, AssetPtr<ImageAsset>* imageAsset)
 U32 ImageAsset::getAssetByFilename(StringTableEntry fileName, AssetPtr<ImageAsset>* imageAsset)
 {
 {
    AssetQuery query;
    AssetQuery query;
@@ -262,168 +315,162 @@ U32 ImageAsset::getAssetById(StringTableEntry assetId, AssetPtr<ImageAsset>* ima
    }
    }
 }
 }
 
 
-//------------------------------------------------------------------------------
-void ImageAsset::copyTo(SimObject* object)
+void ImageAsset::initializeAsset(void)
 {
 {
-   // Call to parent.
-   Parent::copyTo(object);
+   // Call parent.
+   Parent::initializeAsset();
+
+   // Ensure the image-file is expanded.
+   mImageFile = expandAssetFilePath(mImageFile);
 }
 }
 
 
-U32 ImageAsset::load()
+void ImageAsset::onAssetRefresh(void)
 {
 {
-   if (mLoadedState == AssetErrCode::Ok) return mLoadedState;
-   if (mImagePath)
-   {
-      // this is a target.
-      if (mImageFileName[0] == '$' || mImageFileName[0] == '#')
-      {
-         NamedTexTargetRef namedTarget = NamedTexTarget::find(mImageFileName + 1);
-         if (namedTarget) {
-            mLoadedState = Ok;
-            mIsValidImage = true;
-            return mLoadedState;
-         }
-         else
-         {
-            Con::errorf("ImageAsset::initializeAsset: Attempted find named target %s failed.", mImageFileName);
-         }
-      }
-      if (!Torque::FS::IsFile(mImagePath))
-      {
-         Con::errorf("ImageAsset::initializeAsset: Attempted to load file %s but it was not valid!", mImageFileName);
-         mLoadedState = BadFileReference;
-         return mLoadedState;
-      }
+   // Ignore if not yet added to the sim.
+   if (!isProperlyAdded())
+      return;
 
 
-      mLoadedState = Ok;
-      mIsValidImage = true;
-      return mLoadedState;
-   }
-   mLoadedState = BadFileReference;
+   // Call parent.
+   Parent::onAssetRefresh();
 
 
-   mIsValidImage = false;
-   return mLoadedState;
+   //mLoadedState = NotLoaded;
 }
 }
 
 
-void ImageAsset::initializeAsset()
+//------------------------------------------------------------------------------
+
+void ImageAsset::copyTo(SimObject* object)
 {
 {
-   ResourceManager::get().getChangedSignal().notify(this, &ImageAsset::_onResourceChanged);
+   // Call to parent.
+   Parent::copyTo(object);
 
 
-   if (mImageFileName[0] != '$' && mImageFileName[0] != '#')
-   {
-      mImagePath = getOwned() ? expandAssetFilePath(mImageFileName) : mImagePath;
-   }
-   else
-   {
-      mImagePath = mImageFileName;
-   }
+   ImageAsset* pAsset = static_cast<ImageAsset*>(object);
+
+   // Sanity!
+   AssertFatal(pAsset != NULL, "ImageAsset::copyTo() - Object is not the correct type.");
+
+   pAsset->setImageFile(getImageFile());
+   pAsset->setGenMips(getGenMips());
+   pAsset->setTextureHDR(getTextureHDR());
 }
 }
 
 
-void ImageAsset::onAssetRefresh()
+void ImageAsset::setImageFile(StringTableEntry pImageFile)
 {
 {
-   if (mImageFileName[0] != '$' && mImageFileName[0] != '#')
-   {
-      mImagePath = getOwned() ? expandAssetFilePath(mImageFileName) : mImagePath;
-   }
-   else
-   {
-      mImagePath = mImageFileName;
-   }
+   // Sanity!
+   AssertFatal(pImageFile != NULL, "Cannot use a NULL image file.");
 
 
-   AssetManager::typeAssetDependsOnHash::Iterator assetDependenciesItr = mpOwningAssetManager->getDependedOnAssets()->find(mpAssetDefinition->mAssetId);
-   // Iterate all dependencies.
-   while (assetDependenciesItr != mpOwningAssetManager->getDependedOnAssets()->end() && assetDependenciesItr->key == mpAssetDefinition->mAssetId)
-   {
-      StringTableEntry assetId = assetDependenciesItr->value;
-      AssetBase* dependent = AssetDatabase.acquireAsset<AssetBase>(assetId);
-      dependent->refreshAsset();
-   }
+   pImageFile = StringTable->insert(pImageFile);
+
+   if (pImageFile == mImageFile)
+      return;
+
+   // if we previously loaded, remove the listener for the file.
+   if (mLoadedState == Ok)
+      Torque::FS::RemoveChangeNotification(mImageFile, this, &ImageAsset::_onFileChanged);
+
+   mImageFile = getOwned() ? expandAssetFilePath(pImageFile) : StringTable->insert(pImageFile);
+
+   refreshAsset();
 }
 }
 
 
-void ImageAsset::_onResourceChanged(const Torque::Path& path)
+void ImageAsset::setGenMips(const bool pGenMips)
 {
 {
-   if (path != Torque::Path(mImagePath))
+   if (pGenMips == mUseMips)
       return;
       return;
 
 
+   mUseMips = pGenMips;
+
    refreshAsset();
    refreshAsset();
 }
 }
 
 
-void ImageAsset::setImageFileName(const char* pScriptFile)
+
+void ImageAsset::setTextureHDR(const bool pIsHDR)
 {
 {
-   // Sanity!
-   AssertFatal(pScriptFile != NULL, "Cannot use a NULL image file.");
+   if (pIsHDR == mIsHDRImage)
+      return;
 
 
-   // Update.
-   mImageFileName = StringTable->insert(pScriptFile, true);
+   mIsHDRImage = pIsHDR;
 
 
-   // Refresh the asset.
    refreshAsset();
    refreshAsset();
 }
 }
 
 
-GFXTexHandle ImageAsset::getTexture(GFXTextureProfile* requestedProfile)
+U32 ImageAsset::load()
 {
 {
-   load();
-   if (mResourceMap.contains(requestedProfile))
+   if (mLoadedState == Ok)
+      return mLoadedState;
+
+   if (!Torque::FS::IsFile(mImageFile))
    {
    {
-      mLoadedState = Ok;
-      return mResourceMap.find(requestedProfile)->value;
+      Con::errorf("ImageAsset::initializeAsset: Attempted to load file %s but it was not valid!", mImageFile);
+      mLoadedState = BadFileReference;
+      return mLoadedState;
    }
    }
    else
    else
    {
    {
-      // this is a target.
-      if (mImageFileName[0] == '$' || mImageFileName[0] == '#')
+      Torque::FS::AddChangeNotification(mImageFile, this, &ImageAsset::_onFileChanged);
+      mLoadedState = Ok;
+   }
+
+   return mLoadedState;
+}
+
+GFXTexHandle ImageAsset::getTexture(GFXTextureProfile* requestedProfile)
+{
+   load();
+
+   if (mLoadedState == Ok)
+   {
+      if (mResourceMap.contains(requestedProfile))
       {
       {
-         mLoadedState = Ok;
-         NamedTexTargetRef namedTarget = NamedTexTarget::find(mImageFileName + 1);
-         if (namedTarget.isValid() && namedTarget->getTexture())
-         {
-            mNamedTarget = namedTarget;
-            mIsValidImage = true;
-            mResourceMap.insert(requestedProfile, mNamedTarget->getTexture());
-            mChangeSignal.trigger();
-            return mNamedTarget->getTexture();
-         }
+         return mResourceMap.find(requestedProfile)->value;
       }
       }
       else
       else
       {
       {
+
          //If we don't have an existing map case to the requested format, we'll just create it and insert it in
          //If we don't have an existing map case to the requested format, we'll just create it and insert it in
-         GFXTexHandle newTex = TEXMGR->createTexture(mImagePath, requestedProfile);
+         GFXTexHandle newTex;
+         newTex.set(mImageFile, requestedProfile, avar("%s() - mTextureObject (line %d)", __FUNCTION__, __LINE__));
          if (newTex)
          if (newTex)
          {
          {
+            mLoadedState = AssetErrCode::Ok;
             mResourceMap.insert(requestedProfile, newTex);
             mResourceMap.insert(requestedProfile, newTex);
-            mLoadedState = Ok;
             return newTex;
             return newTex;
          }
          }
-         else
-            mLoadedState = BadFileReference;
       }
       }
    }
    }
 
 
+   mLoadedState = AssetErrCode::Failed;
+
    return nullptr;
    return nullptr;
 }
 }
 
 
-const char* ImageAsset::getImageInfo()
+void ImageAsset::generateTexture(void)
 {
 {
-   if (mIsValidImage)
+   // implement some defaults, eventually SRGB should be optional.
+   U32 flags = GFXTextureProfile::Static | GFXTextureProfile::SRGB;
+
+   // dont want mips?
+   if (!mUseMips)
    {
    {
-      static const U32 bufSize = 2048;
-      char* returnBuffer = Con::getReturnBuffer(bufSize);
+      flags |= GFXTextureProfile::NoMipmap;
+   }
 
 
-      GFXTexHandle newTex = TEXMGR->createTexture(mImagePath, &GFXStaticTextureSRGBProfile);
-      if (newTex)
-      {
-         dSprintf(returnBuffer, bufSize, "%s %d %d %d", GFXStringTextureFormat[newTex->getFormat()], newTex->getHeight(), newTex->getWidth(), newTex->getDepth());
-         newTex = nullptr;
-      }
-      else
-      {
-         dSprintf(returnBuffer, bufSize, "ImageAsset::getImageInfo() - Failed to get image info for %s", getAssetId());
-      }
+   GFXTextureProfile::Types type = GFXTextureProfile::Types::DiffuseMap;
 
 
-      return returnBuffer;
+   if (mImageType == ImageTypes::Normal) {
+      type = GFXTextureProfile::Types::NormalMap;
    }
    }
 
 
-   return "";
+   GFXTextureProfile* genProfile = new GFXTextureProfile("ImageAssetGennedProfile", type, flags);
+
+   mTextureHandle.set(mImageFile, genProfile, avar("%s() - mTextureObject (line %d)", __FUNCTION__, __LINE__));
+   mResourceMap.insert(genProfile, mTextureHandle);
+
+   if (mTextureHandle.isValid())
+      mLoadedState = AssetErrCode::Ok;
+   else
+      mLoadedState = AssetErrCode::Failed;
+
+   ResourceManager::get().getChangedSignal().notify(this, &ImageAsset::_onResourceChanged);
 }
 }
 
 
 const char* ImageAsset::getImageTypeNameFromType(ImageAsset::ImageTypes type)
 const char* ImageAsset::getImageTypeNameFromType(ImageAsset::ImageTypes type)
@@ -452,7 +499,7 @@ const char* ImageAsset::getImageTypeNameFromType(ImageAsset::ImageTypes type)
    return _names[type];
    return _names[type];
 }
 }
 
 
-ImageAsset::ImageTypes ImageAsset::getImageTypeFromName(const char* name)
+ImageAsset::ImageTypes ImageAsset::getImageTypeFromName(StringTableEntry name)
 {
 {
    if (dStrIsEmpty(name))
    if (dStrIsEmpty(name))
    {
    {
@@ -475,11 +522,69 @@ ImageAsset::ImageTypes ImageAsset::getImageTypeFromName(const char* name)
    return (ImageTypes)ret;
    return (ImageTypes)ret;
 }
 }
 
 
-DefineEngineMethod(ImageAsset, getImagePath, const char*, (), ,
+void ImageAsset::_onFileChanged(const Torque::Path& path)
+{
+   if (path != Torque::Path(mImageFile))
+      return;
+
+   refreshAsset();
+}
+
+void ImageAsset::_onResourceChanged(const Torque::Path& path)
+{
+   if (path != Torque::Path(mImageFile))
+      return;
+
+   refreshAsset();
+}
+
+void ImageAsset::onTamlPreWrite(void)
+{
+   // Call parent.
+   Parent::onTamlPreWrite();
+
+   // Ensure the image-file is collapsed.
+   mImageFile = getOwned() ? collapseAssetFilePath(mImageFile) : mImageFile;
+}
+
+void ImageAsset::onTamlPostWrite(void)
+{
+   // Call parent.
+   Parent::onTamlPostWrite();
+
+   // Ensure the image-file is expanded.
+   mImageFile = getOwned() ? expandAssetFilePath(mImageFile) : mImageFile;
+}
+
+const char* ImageAsset::getImageInfo()
+{
+   if (isAssetValid())
+   {
+      static const U32 bufSize = 2048;
+      char* returnBuffer = Con::getReturnBuffer(bufSize);
+
+      GFXTexHandle newTex = TEXMGR->createTexture(mImageFile, &GFXStaticTextureSRGBProfile);
+      if (newTex)
+      {
+         dSprintf(returnBuffer, bufSize, "%s %d %d %d", GFXStringTextureFormat[newTex->getFormat()], newTex->getHeight(), newTex->getWidth(), newTex->getDepth());
+         newTex = nullptr;
+      }
+      else
+      {
+         dSprintf(returnBuffer, bufSize, "ImageAsset::getImageInfo() - Failed to get image info for %s", getAssetId());
+      }
+
+      return returnBuffer;
+   }
+
+   return "";
+}
+
+DefineEngineMethod(ImageAsset, getImageFile, const char*, (), ,
    "Gets the image filepath of this asset.\n"
    "Gets the image filepath of this asset.\n"
    "@return File path of the image file.")
    "@return File path of the image file.")
 {
 {
-   return object->getImagePath();
+   return object->getImageFile();
 }
 }
 
 
 DefineEngineMethod(ImageAsset, getImageInfo, const char*, (), ,
 DefineEngineMethod(ImageAsset, getImageInfo, const char*, (), ,
@@ -496,7 +601,7 @@ DefineEngineStaticMethod(ImageAsset, getAssetIdByFilename, const char*, (const c
 {
 {
    return ImageAsset::getAssetIdByFilename(StringTable->insert(filePath));
    return ImageAsset::getAssetIdByFilename(StringTable->insert(filePath));
 }
 }
-
+#endif
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 // GuiInspectorTypeAssetId
 // GuiInspectorTypeAssetId
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
@@ -652,7 +757,7 @@ bool GuiInspectorTypeImageAssetPtr::renderTooltip(const Point2I& hoverPos, const
    if (imgAsset == NULL || assetState == ImageAsset::Failed)
    if (imgAsset == NULL || assetState == ImageAsset::Failed)
       return false;
       return false;
 
 
-   StringTableEntry filename = imgAsset->getImagePath();
+   StringTableEntry filename = imgAsset->getImageFile();
    if (!filename || !filename[0])
    if (!filename || !filename[0])
       return false;
       return false;
 
 
@@ -665,7 +770,7 @@ bool GuiInspectorTypeImageAssetPtr::renderTooltip(const Point2I& hoverPos, const
       if (AssetDatabase.isDeclaredAsset(previewFilename))
       if (AssetDatabase.isDeclaredAsset(previewFilename))
       {
       {
          ImageAsset* previewAsset = AssetDatabase.acquireAsset<ImageAsset>(previewFilename);
          ImageAsset* previewAsset = AssetDatabase.acquireAsset<ImageAsset>(previewFilename);
-         previewFilename = previewAsset->getImagePath();
+         previewFilename = previewAsset->getImageFile();
       }
       }
    }
    }
 
 
@@ -802,5 +907,3 @@ void GuiInspectorTypeImageAssetId::consoleInit()
 
 
    ConsoleBaseType::getType(TypeImageAssetId)->setInspectorFieldType("GuiInspectorTypeImageAssetId");
    ConsoleBaseType::getType(TypeImageAssetId)->setInspectorFieldType("GuiInspectorTypeImageAssetId");
 }
 }
-
-#endif

+ 111 - 52
Engine/source/T3D/assets/ImageAsset.h

@@ -79,6 +79,39 @@ public:
       ImageTypeCount = 11
       ImageTypeCount = 11
    };
    };
 
 
+   class Frame
+   {
+   public:
+      Frame(const S32 pixelOffsetX, const S32 pixelOffsetY,
+         const U32 pixelWidth, const U32 pixelHeight,
+         const F32 texelWidthScale, const F32 texelHeightScale,
+         StringTableEntry inRegionName = StringTable->EmptyString())
+         : regionName(inRegionName)
+      {
+         pixelOffset.set(pixelOffsetY, pixelOffsetY);
+         pixelSize.set(pixelWidth, pixelHeight);
+
+         texelLower.set(pixelOffsetX * texelWidthScale, pixelOffsetY * texelHeightScale);
+         texelSize.set(pixelWidth * texelWidthScale, pixelHeight * texelHeightScale);
+         texelUpper.set(texelLower.x + texelSize.x, texelLower.y + texelSize.y);
+      }
+
+      void setFlip(bool flipX, bool flipY)
+      {
+         if (flipX) mSwap(texelLower.x, texelUpper.x);
+         if (flipY) mSwap(texelLower.y, texelUpper.y);
+      }
+
+      Point2I pixelOffset;
+      Point2I pixelSize;
+
+      Point2F texelLower;
+      Point2F texelUpper;
+      Point2F texelSize;
+
+      StringTableEntry regionName;
+   };
+
    static StringTableEntry smNoImageAssetFallback;
    static StringTableEntry smNoImageAssetFallback;
 
 
    enum ImageAssetErrCode
    enum ImageAssetErrCode
@@ -96,26 +129,16 @@ public:
       if (errCode > ImageAssetErrCode::Extended) return "undefined error";
       if (errCode > ImageAssetErrCode::Extended) return "undefined error";
       return mErrCodeStrings[errCode - Parent::Extended];
       return mErrCodeStrings[errCode - Parent::Extended];
    };
    };
+private:
 
 
-protected:
-   StringTableEntry mImageFileName;
-   StringTableEntry mImagePath;
-   NamedTexTargetRef mNamedTarget;
-
-   bool mIsValidImage;
-   bool mUseMips;
-   bool mIsHDRImage;
-
-   ImageTypes mImageType;
-
+   StringTableEntry  mImageFile;
+   bool              mUseMips;
+   bool              mIsHDRImage;
+   GFXTexHandle      mTextureHandle;
+   ImageTypes        mImageType;
    HashMap<GFXTextureProfile*, GFXTexHandle> mResourceMap;
    HashMap<GFXTextureProfile*, GFXTexHandle> mResourceMap;
 
 
-   typedef Signal<void()> ImageAssetChanged;
-   ImageAssetChanged mChangeSignal;
-
-   typedef Signal<void(S32 index)> ImageAssetArrayChanged;
-   ImageAssetArrayChanged mChangeArraySignal;
-
+   void generateTexture(void);
 public:
 public:
    ImageAsset();
    ImageAsset();
    virtual ~ImageAsset();
    virtual ~ImageAsset();
@@ -125,6 +148,10 @@ public:
 
 
    /// Engine.
    /// Engine.
    static void initPersistFields();
    static void initPersistFields();
+
+   /// Sim
+   bool onAdd() override;
+   void onRemove() override;
    void copyTo(SimObject* object) override;
    void copyTo(SimObject* object) override;
 
 
    /// Declare Console Object.
    /// Declare Console Object.
@@ -132,44 +159,75 @@ public:
 
 
    void _onResourceChanged(const Torque::Path& path);
    void _onResourceChanged(const Torque::Path& path);
 
 
-   ImageAssetChanged& getChangedSignal() { return mChangeSignal; }
-   ImageAssetArrayChanged& getChangedArraySignal() { return mChangeArraySignal; }
-
-   void                    setImageFileName(StringTableEntry pScriptFile);
-   inline StringTableEntry getImageFileName(void) const { return mImageFileName; };
+   // asset Base load
+   U32 load() override;
 
 
-   inline StringTableEntry getImagePath(void) const { return mImagePath; };
+   void                    setImageFile(StringTableEntry pImageFile);
+   inline StringTableEntry getImageFile(void) const { return mImageFile; };
 
 
-   bool isValid() { return mIsValidImage; }
+   void                    setGenMips(const bool pGenMips);
+   inline bool             getGenMips(void) const { return mUseMips; };
 
 
-   GFXTexHandle getTexture(GFXTextureProfile* requestedProfile);
+   void                    setTextureHDR(const bool pIsHDR);
+   inline bool             getTextureHDR(void) const { return mIsHDRImage; };
 
 
-   StringTableEntry getImageInfo();
+   inline GFXTexHandle& getTexture(void) { load(); generateTexture(); return mTextureHandle; }
+   GFXTexHandle            getTexture(GFXTextureProfile* requestedProfile);
 
 
    static StringTableEntry getImageTypeNameFromType(ImageTypes type);
    static StringTableEntry getImageTypeNameFromType(ImageTypes type);
-   static ImageTypes getImageTypeFromName(StringTableEntry name);
+   static ImageTypes       getImageTypeFromName(StringTableEntry name);
 
 
-   void setImageType(ImageTypes type) { mImageType = type; }
-   ImageTypes getImageType() { return mImageType; }
+   void                    setImageType(ImageTypes type) { mImageType = type; }
+   ImageTypes              getImageType() { return mImageType; }
+
+   inline U32              getTextureWidth(void) const { return mTextureHandle->getWidth(); }
+   inline U32              getTextureHeight(void) const { return mTextureHandle->getHeight(); }
+   inline U32              getTextureDepth(void) const { return mTextureHandle->getDepth(); }
+
+   inline U32              getTextureBitmapWidth(void) const { return mTextureHandle->getBitmapWidth(); }
+   inline U32              getTextureBitmapHeight(void) const { return mTextureHandle->getBitmapHeight(); }
+   inline U32              getTextureBitmapDepth(void) const { return mTextureHandle->getBitmapDepth(); }
+   bool                    isAssetValid(void) const override { return !mTextureHandle.isNull(); }
 
 
    static U32 getAssetByFilename(StringTableEntry fileName, AssetPtr<ImageAsset>* imageAsset);
    static U32 getAssetByFilename(StringTableEntry fileName, AssetPtr<ImageAsset>* imageAsset);
    static StringTableEntry getAssetIdByFilename(StringTableEntry fileName);
    static StringTableEntry getAssetIdByFilename(StringTableEntry fileName);
    static U32 getAssetById(StringTableEntry assetId, AssetPtr<ImageAsset>* imageAsset);
    static U32 getAssetById(StringTableEntry assetId, AssetPtr<ImageAsset>* imageAsset);
    static U32 getAssetById(String assetId, AssetPtr<ImageAsset>* imageAsset) { return getAssetById(assetId.c_str(), imageAsset); };
    static U32 getAssetById(String assetId, AssetPtr<ImageAsset>* imageAsset) { return getAssetById(assetId.c_str(), imageAsset); };
 
 
-   U32 load() override;
+
+   const char* getImageInfo();
 
 
 protected:
 protected:
-   void            initializeAsset(void) override;
-   void            onAssetRefresh(void) override;
+   // Asset Base callback
+   void initializeAsset(void) override;
+   void onAssetRefresh(void) override;
+   void _onFileChanged(const Torque::Path& path);
+
+   /// Taml callbacks.
+   void onTamlPreWrite(void) override;
+   void onTamlPostWrite(void) override;
 
 
-   static bool setImageFileName(void* obj, StringTableEntry index, StringTableEntry data) { static_cast<ImageAsset*>(obj)->setImageFileName(data); return false; }
-   static StringTableEntry getImageFileName(void* obj, StringTableEntry data) { return static_cast<ImageAsset*>(obj)->getImageFileName(); }
+protected:
+   // Texture file 
+   static bool setImageFile(void* obj, StringTableEntry index, StringTableEntry data) { static_cast<ImageAsset*>(obj)->setImageFile(data); return false; }
+   static const char* getImageFile(void* obj, StringTableEntry data) { return static_cast<ImageAsset*>(obj)->getImageFile(); }
+   static bool writeImageFile(void* obj, StringTableEntry pFieldName) { return static_cast<ImageAsset*>(obj)->getImageFile() != StringTable->EmptyString(); }
+
+   // Gen mips?
+   static bool setGenMips(void* obj, StringTableEntry index, StringTableEntry data) { static_cast<ImageAsset*>(obj)->setGenMips(dAtob(data)); return false; }
+   static bool writeGenMips(void* obj, StringTableEntry pFieldName) { return static_cast<ImageAsset*>(obj)->getGenMips() == true; }
+
+   // Texture Is Hdr?
+   static bool setTextureHDR(void* obj, StringTableEntry index, StringTableEntry data) { static_cast<ImageAsset*>(obj)->setTextureHDR(dAtob(data)); return false; }
+   static bool writeTextureHDR(void* obj, StringTableEntry pFieldName) { return static_cast<ImageAsset*>(obj)->getTextureHDR() == true; }
 };
 };
 
 
 DefineConsoleType(TypeImageAssetPtr, ImageAsset)
 DefineConsoleType(TypeImageAssetPtr, ImageAsset)
 DefineConsoleType(TypeImageAssetId, String)
 DefineConsoleType(TypeImageAssetId, String)
 
 
+DECLARE_STRUCT(AssetPtr<ImageAsset>)
+DefineConsoleType(TypeImageAssetPtrRefactor, AssetPtr<ImageAsset> )
+
 typedef ImageAsset::ImageTypes ImageAssetType;
 typedef ImageAsset::ImageTypes ImageAssetType;
 DefineEnumType(ImageAssetType);
 DefineEnumType(ImageAssetType);
 
 
@@ -196,10 +254,6 @@ public: \
    {\
    {\
       if(m##name##AssetId != _in || m##name##Name != _in)\
       if(m##name##AssetId != _in || m##name##Name != _in)\
       {\
       {\
-         if (m##name##Asset.notNull())\
-         {\
-            m##name##Asset->getChangedSignal().remove(this, &className::changeFunc);\
-         }\
          if (_in == NULL || _in == StringTable->EmptyString())\
          if (_in == NULL || _in == StringTable->EmptyString())\
          {\
          {\
             m##name##Name = StringTable->EmptyString();\
             m##name##Name = StringTable->EmptyString();\
@@ -251,10 +305,6 @@ public: \
       }\
       }\
       if (get##name() != StringTable->EmptyString() && m##name##Name != StringTable->insert("texhandle"))\
       if (get##name() != StringTable->EmptyString() && m##name##Name != StringTable->insert("texhandle"))\
       {\
       {\
-         if (m##name##Asset.notNull())\
-         {\
-            m##name##Asset->getChangedSignal().notify(this, &className::changeFunc);\
-         }\
          \
          \
          if (get##name()[0] != '$' && get##name()[0] != '#') {\
          if (get##name()[0] != '$' && get##name()[0] != '#') {\
             m##name.set(get##name(), m##name##Profile, avar("%s() - mTextureObject (line %d)", __FUNCTION__, __LINE__));\
             m##name.set(get##name(), m##name##Profile, avar("%s() - mTextureObject (line %d)", __FUNCTION__, __LINE__));\
@@ -285,11 +335,8 @@ public: \
    \
    \
    const StringTableEntry get##name() const\
    const StringTableEntry get##name() const\
    {\
    {\
-      if (m##name##Asset && (m##name##Asset->getImageFileName() != StringTable->EmptyString()))\
-         if (m##name##Asset->getImageFileName()[0] == '#' || m##name##Asset->getImageFileName()[0] == '$')\
-            return m##name##Asset->getImageFileName();\
-         else\
-            return  Platform::makeRelativePathName(m##name##Asset->getImagePath(), Platform::getMainDotCsDir());\
+      if (m##name##Asset && (m##name##Asset->getImageFile() != StringTable->EmptyString()))\
+         return  Platform::makeRelativePathName(m##name##Asset->getImageFile(), Platform::getMainDotCsDir());\
       else if (m##name##AssetId != StringTable->EmptyString())\
       else if (m##name##AssetId != StringTable->EmptyString())\
          return m##name##AssetId;\
          return m##name##AssetId;\
       else if (m##name##Name != StringTable->EmptyString())\
       else if (m##name##Name != StringTable->EmptyString())\
@@ -435,11 +482,8 @@ public: \
    \
    \
    const StringTableEntry get##name(const U32& index) const\
    const StringTableEntry get##name(const U32& index) const\
    {\
    {\
-      if (m##name##Asset[index] && (m##name##Asset[index]->getImageFileName() != StringTable->EmptyString()))\
-         if (m##name##Asset[index]->getImageFileName()[0] == '#' || m##name##Asset[index]->getImageFileName()[0] == '$')\
-            return m##name##Asset[index]->getImageFileName();\
-         else\
-            return  Platform::makeRelativePathName(m##name##Asset[index]->getImagePath(), Platform::getMainDotCsDir());\
+      if (m##name##Asset[index] && (m##name##Asset[index]->getImageFile() != StringTable->EmptyString()))\
+         return  Platform::makeRelativePathName(m##name##Asset[index]->getImageFile(), Platform::getMainDotCsDir());\
       else if (m##name##AssetId[index] != StringTable->EmptyString())\
       else if (m##name##AssetId[index] != StringTable->EmptyString())\
          return m##name##AssetId[index];\
          return m##name##AssetId[index];\
       else if (m##name##Name[index] != StringTable->EmptyString())\
       else if (m##name##Name[index] != StringTable->EmptyString())\
@@ -542,4 +586,19 @@ if (m##name##AssetId[index] != StringTable->EmptyString())\
 
 
 #pragma endregion
 #pragma endregion
 
 
+#pragma region Refactor Asset Macros
 
 
+#define DECLARE_IMAGEASSET_REFACTOR(className, name, profile)                                                                                                                 \
+private:                                                                                                                                                                      \
+   AssetPtr<ImageAsset> m##name##Asset;                                                                                                                                       \
+public:                                                                                                                                                                       \
+   void _set##name(StringTableEntry _in);                                                                                                                                     \
+   inline StringTableEntry _get##name(void) const { return m##name##Asset.getAssetId(); }                                                                                     \
+   GFXTexHandle get##name() { return m##name##Asset.notNull() ? m##name##Asset->getTexture(&profile) : NULL; }                                                                \
+   AssetPtr<ImageAsset> get##name##Asset(void) { return m##name##Asset; }                                                                                                     \
+   static bool _set##name##Data(void* obj, const char* index, const char* data) { static_cast<className*>(obj)->_set##name(_getStringTable()->insert(data)); return false;}   
+
+#define INITPERSISTFIELD_IMAGEASSET_REFACTOR(name, consoleClass, docs)                                                                                                        \
+   addProtectedField(assetText(name, Asset), TypeImageAssetPtrRefactor, Offset(m##name##Asset, consoleClass), _set##name##Data, &defaultProtectedGetFn, assetDoc(name, asset docs.));
+
+#pragma endregion

+ 1 - 1
Engine/source/T3D/assets/LevelAsset.cpp

@@ -230,7 +230,7 @@ StringTableEntry LevelAsset::getPreviewImagePath(void) const
 {
 {
    if (mPreviewImageAsset.notNull() && mPreviewImageAsset->isAssetValid())
    if (mPreviewImageAsset.notNull() && mPreviewImageAsset->isAssetValid())
    {
    {
-      return mPreviewImageAsset->getImagePath();
+      return mPreviewImageAsset->getImageFile();
    }
    }
 
 
    return StringTable->EmptyString();
    return StringTable->EmptyString();

+ 3 - 3
Engine/source/T3D/assets/assetImporter.cpp

@@ -1877,7 +1877,7 @@ void AssetImporter::processMaterialAsset(AssetImportObject* assetItem)
                      {
                      {
                         //got a match!
                         //got a match!
                         ImageAsset* foundImageAsset = AssetDatabase.acquireAsset<ImageAsset>(testAssetId.c_str());
                         ImageAsset* foundImageAsset = AssetDatabase.acquireAsset<ImageAsset>(testAssetId.c_str());
-                        imagePath = foundImageAsset->getImagePath();
+                        imagePath = foundImageAsset->getImageFile();
 
 
                         AssetImportObject* newImageAssetObj = addImportingAsset("ImageAsset", imagePath, assetItem, "");
                         AssetImportObject* newImageAssetObj = addImportingAsset("ImageAsset", imagePath, assetItem, "");
 
 
@@ -1921,7 +1921,7 @@ void AssetImporter::processMaterialAsset(AssetImportObject* assetItem)
                         {
                         {
                            //got a match!
                            //got a match!
                            ImageAsset* foundImageAsset = AssetDatabase.acquireAsset<ImageAsset>(testAssetId.c_str());
                            ImageAsset* foundImageAsset = AssetDatabase.acquireAsset<ImageAsset>(testAssetId.c_str());
-                           imagePath = foundImageAsset->getImagePath();
+                           imagePath = foundImageAsset->getImageFile();
 
 
                            AssetImportObject* newImageAssetObj = addImportingAsset("ImageAsset", imagePath, assetItem, "");
                            AssetImportObject* newImageAssetObj = addImportingAsset("ImageAsset", imagePath, assetItem, "");
 
 
@@ -2834,7 +2834,7 @@ Torque::Path AssetImporter::importImageAsset(AssetImportObject* assetItem)
 #endif
 #endif
    
    
    newAsset->setAssetName(assetName);
    newAsset->setAssetName(assetName);
-   newAsset->setImageFileName(imageFileName.c_str());
+   newAsset->setImageFile(imageFileName.c_str());
 
 
    //If it's not a re-import, check that the file isn't being in-place imported. If it isn't, store off the original
    //If it's not a re-import, check that the file isn't being in-place imported. If it isn't, store off the original
    //file path for reimporting support later
    //file path for reimporting support later

+ 0 - 5
Engine/source/afx/ce/afxZodiac.cpp

@@ -349,11 +349,6 @@ void afxZodiacData::onPerformSubstitutions()
       {
       {
          if (getTexture() != StringTable->EmptyString() && mTextureName != StringTable->insert("texhandle"))
          if (getTexture() != StringTable->EmptyString() && mTextureName != StringTable->insert("texhandle"))
          {
          {
-            if (mTextureAsset.notNull())
-            {
-               mTextureAsset->getChangedSignal().notify(this, &afxZodiacData::onImageChanged);
-            }
-               
             mTexture.set(getTexture(), mTextureProfile, avar("%s() - mTextureObject (line %d)", __FUNCTION__, __LINE__));
             mTexture.set(getTexture(), mTextureProfile, avar("%s() - mTextureObject (line %d)", __FUNCTION__, __LINE__));
          }
          }
       }
       }

+ 5 - 5
Engine/source/gui/buttons/guiBitmapButtonCtrl.cpp

@@ -301,7 +301,7 @@ void GuiBitmapButtonCtrl::setBitmap( StringTableEntry name )
             if( mUseModifiers )
             if( mUseModifiers )
                baseName += modifiers[ i ];
                baseName += modifiers[ i ];
 
 
-            mTextures[ i ].mTextureNormal = GFXTexHandle( mBitmapAsset->getImagePath(), &GFXDefaultGUIProfile, avar("%s() - mTextureNormal (line %d)", __FUNCTION__, __LINE__));
+            mTextures[ i ].mTextureNormal = GFXTexHandle( mBitmapAsset->getImageFile(), &GFXDefaultGUIProfile, avar("%s() - mTextureNormal (line %d)", __FUNCTION__, __LINE__));
             
             
             if( mUseStates )
             if( mUseStates )
             {
             {
@@ -323,7 +323,7 @@ void GuiBitmapButtonCtrl::setBitmap( StringTableEntry name )
                         mTextures[i].mTextureNormalAsset->load();
                         mTextures[i].mTextureNormalAsset->load();
                         if (mTextures[i].mTextureNormalAsset->getStatus() == AssetBase::Ok)
                         if (mTextures[i].mTextureNormalAsset->getStatus() == AssetBase::Ok)
                         {
                         {
-                           mTextures[i].mTextureNormal = GFXTexHandle(mTextures[i].mTextureNormalAsset->getImagePath(), &GFXDefaultGUIProfile, avar("%s() - mTextureDepressed (line %d)", __FUNCTION__, __LINE__));
+                           mTextures[i].mTextureNormal = GFXTexHandle(mTextures[i].mTextureNormalAsset->getImageFile(), &GFXDefaultGUIProfile, avar("%s() - mTextureDepressed (line %d)", __FUNCTION__, __LINE__));
                            break;
                            break;
                         }
                         }
                      }
                      }
@@ -345,7 +345,7 @@ void GuiBitmapButtonCtrl::setBitmap( StringTableEntry name )
                      mTextures[i].mTextureHilightAsset->load();
                      mTextures[i].mTextureHilightAsset->load();
                      if (mTextures[i].mTextureHilightAsset->getStatus() == AssetBase::Ok)
                      if (mTextures[i].mTextureHilightAsset->getStatus() == AssetBase::Ok)
                      {
                      {
-                        mTextures[i].mTextureHilight = GFXTexHandle(mTextures[i].mTextureHilightAsset->getImagePath(), &GFXDefaultGUIProfile, avar("%s() - mTextureDepressed (line %d)", __FUNCTION__, __LINE__));
+                        mTextures[i].mTextureHilight = GFXTexHandle(mTextures[i].mTextureHilightAsset->getImageFile(), &GFXDefaultGUIProfile, avar("%s() - mTextureDepressed (line %d)", __FUNCTION__, __LINE__));
                         break;
                         break;
                      }
                      }
                   }
                   }
@@ -369,7 +369,7 @@ void GuiBitmapButtonCtrl::setBitmap( StringTableEntry name )
                      mTextures[i].mTextureDepressedAsset->load();
                      mTextures[i].mTextureDepressedAsset->load();
                      if (mTextures[i].mTextureDepressedAsset->getStatus() == AssetBase::Ok)
                      if (mTextures[i].mTextureDepressedAsset->getStatus() == AssetBase::Ok)
                      {
                      {
-                        mTextures[i].mTextureDepressed = GFXTexHandle(mTextures[i].mTextureDepressedAsset->getImagePath(), &GFXDefaultGUIProfile, avar("%s() - mTextureDepressed (line %d)", __FUNCTION__, __LINE__));
+                        mTextures[i].mTextureDepressed = GFXTexHandle(mTextures[i].mTextureDepressedAsset->getImageFile(), &GFXDefaultGUIProfile, avar("%s() - mTextureDepressed (line %d)", __FUNCTION__, __LINE__));
                         break;
                         break;
                      }
                      }
                   }
                   }
@@ -393,7 +393,7 @@ void GuiBitmapButtonCtrl::setBitmap( StringTableEntry name )
                      mTextures[i].mTextureInactiveAsset->load();
                      mTextures[i].mTextureInactiveAsset->load();
                      if (mTextures[i].mTextureInactiveAsset->getStatus() == AssetBase::Ok)
                      if (mTextures[i].mTextureInactiveAsset->getStatus() == AssetBase::Ok)
                      {
                      {
-                        mTextures[i].mTextureInactive = GFXTexHandle(mTextures[i].mTextureInactiveAsset->getImagePath(), &GFXDefaultGUIProfile, avar("%s() - mTextureDepressed (line %d)", __FUNCTION__, __LINE__));
+                        mTextures[i].mTextureInactive = GFXTexHandle(mTextures[i].mTextureInactiveAsset->getImageFile(), &GFXDefaultGUIProfile, avar("%s() - mTextureDepressed (line %d)", __FUNCTION__, __LINE__));
                         break;
                         break;
                      }
                      }
                   }
                   }

+ 2 - 2
Engine/source/gui/core/guiTypes.cpp

@@ -203,7 +203,7 @@ bool GuiControlProfile::protectedSetBitmap( void *object, const char *index, con
       {
       {
          if (profile->mBitmapAsset.notNull() && profile->getBitmap() != StringTable->insert("texHandle"))
          if (profile->mBitmapAsset.notNull() && profile->getBitmap() != StringTable->insert("texHandle"))
          {
          {
-            profile->mBitmap.set(profile->mBitmapAsset->getImagePath(), profile->mBitmapProfile, avar("%s() - mTextureObject (line %d)", __FUNCTION__, __LINE__));
+            profile->mBitmap.set(profile->mBitmapAsset->getImageFile(), profile->mBitmapProfile, avar("%s() - mTextureObject (line %d)", __FUNCTION__, __LINE__));
          }
          }
 
 
          //verify the bitmap
          //verify the bitmap
@@ -648,7 +648,7 @@ void GuiControlProfile::incLoadCount()
       {
       {
          if (mBitmapAsset.notNull() && getBitmap() != StringTable->insert("texHandle"))
          if (mBitmapAsset.notNull() && getBitmap() != StringTable->insert("texHandle"))
          {
          {
-            mBitmap.set(mBitmapAsset->getImagePath(), mBitmapProfile, avar("%s() - mTextureObject (line %d)", __FUNCTION__, __LINE__));
+            mBitmap.set(mBitmapAsset->getImageFile(), mBitmapProfile, avar("%s() - mTextureObject (line %d)", __FUNCTION__, __LINE__));
          }
          }
 
 
          //verify the bitmap
          //verify the bitmap

+ 2 - 10
Engine/source/gui/core/guiTypes.h

@@ -475,10 +475,6 @@ public:
    {
    {
       if (mBitmapAssetId != _in || mBitmapName != _in)
       if (mBitmapAssetId != _in || mBitmapName != _in)
       {
       {
-         if (mBitmapAsset.notNull())
-         {
-            mBitmapAsset->getChangedSignal().remove(this, &GuiControlProfile::onBitmapChanged); 
-         }
          if (_in == StringTable->EmptyString())
          if (_in == StringTable->EmptyString())
          {
          {
             mBitmapName = StringTable->EmptyString(); 
             mBitmapName = StringTable->EmptyString(); 
@@ -530,10 +526,6 @@ public:
       }
       }
       if (getBitmap() != StringTable->EmptyString() && mBitmapName != StringTable->insert("texhandle"))
       if (getBitmap() != StringTable->EmptyString() && mBitmapName != StringTable->insert("texhandle"))
       {
       {
-         if (mBitmapAsset.notNull())
-         {
-            mBitmapAsset->getChangedSignal().notify(this, &GuiControlProfile::onBitmapChanged);
-         }
       }
       }
       else
       else
       {
       {
@@ -551,8 +543,8 @@ public:
    
    
    const StringTableEntry getBitmap() const
    const StringTableEntry getBitmap() const
    {
    {
-      if (mBitmapAsset && (mBitmapAsset->getImageFileName() != StringTable->EmptyString()))
-         return  Platform::makeRelativePathName(mBitmapAsset->getImagePath(), Platform::getMainDotCsDir());
+      if (mBitmapAsset && (mBitmapAsset->getImageFile() != StringTable->EmptyString()))
+         return  Platform::makeRelativePathName(mBitmapAsset->getImageFile(), Platform::getMainDotCsDir());
       else if (mBitmapAssetId != StringTable->EmptyString())
       else if (mBitmapAssetId != StringTable->EmptyString())
          return mBitmapAssetId;
          return mBitmapAssetId;
       else if (mBitmapName != StringTable->EmptyString())
       else if (mBitmapName != StringTable->EmptyString())

+ 1 - 1
Engine/source/materials/materialDefinition.cpp

@@ -674,7 +674,7 @@ void Material::_mapMaterial()
          }
          }
          else if (!mDiffuseMapAsset->isNull())
          else if (!mDiffuseMapAsset->isNull())
          {
          {
-            mMapTo = mDiffuseMapAsset[0]->getImageFileName();
+            mMapTo = mDiffuseMapAsset[0]->getImageFile();
          }
          }
       }
       }
    }
    }

+ 2 - 0
Engine/source/math/mMathFn.h

@@ -531,5 +531,7 @@ inline F64 mSquared( F64 n )
    return n * n;
    return n * n;
 }
 }
 
 
+template< typename T >
+inline void mSwap(T& a, T& b) { T temp = b; b = a; a = temp; }
 
 
 #endif //_MMATHFN_H_
 #endif //_MMATHFN_H_