diff --git a/include/MatTexCollection.h b/include/MatTexCollection.h index 4f9d57c3577831d13a598d3d0f59fca6280db718..5acc47e786e57da9612d2957ef348942a59b4864 100644 --- a/include/MatTexCollection.h +++ b/include/MatTexCollection.h @@ -191,11 +191,14 @@ private: vector<TextureWrapper> textures; }; +/* + * A class that wraps up all the various NIF property objects that affect the + * color and texture of an object. It's especially useful to be able to use it + * to hide the differences between old and new texture properties. + */ class MaterialWrapper { public: - /*! NIFLIB_HIDDEN function. For internal use only. */ - NIFLIB_HIDDEN MaterialWrapper( NiMaterialProperty * mat, NiTexturingProperty * texing, NiTextureProperty * tex, NiMultiTextureProperty * multi, NiSpecularProperty * spec, NiAlphaProperty * alpha, MatTexCollection * creator ); - /*! NIFLIB_HIDDEN function. For internal use only. */ + /*! Destructor */ NIFLIB_API ~MaterialWrapper(); /*! @@ -259,23 +262,76 @@ public: */ NIFLIB_API unsigned int GetTextureIndex( TexType slot ); + /* + * Sets a new texture to the specified texture slot. Overwrites any + * texture that's already there. + * \param[in] slot The type of texture slot to set a new texture for. + * \param[in] tex_index The index of the texture to set the specified slot + * to. Must be an index from the same MatTexCollection that holds this + * material wrapper. + */ NIFLIB_API void SetTextureIndex( TexType slot, unsigned int tex_index ); - NIFLIB_API unsigned int GetTexUVSetIndex( TexType tex ); + /* + * Retrieves the UV Set Index of the texture in the specified slot. This + * is the index into the array of UV sets in the NiTriBasedGeom object that + * this material will be applied to. + * \param[in] slot The type of texture slot to get the UV set index for. + * \return The UV set index used by the specified texture slot. + */ + NIFLIB_API unsigned int GetTexUVSetIndex( TexType slot ); - NIFLIB_API void SetTexUVSetIndex( TexType tex, unsigned int uv_set ); + /* + * Sets the UV Set Index of the texture in the specified slot. This + * is the index into the array of UV sets in the NiTriBasedGeom object that + * this material will be applied to. + * \param[in] slot The type of texture slot to set the UV set index for. + * \param[in] uv_set The new UV set index that will be used by the + * specified texture slot. + */ + NIFLIB_API void SetTexUVSetIndex( TexType slot, unsigned int uv_set ); - NIFLIB_API TexClampMode GetTexClampMode( TexType tex ); + /* + * Retrieves the texture clamp mode of the specified texture slot. This + * specifies the way that textures will be displayed for UV coordinates + * that fall outside the 0-1 range. + * \param[in] slot The type of texture slot to get the clamp mode for. + * \return The clamp mode of the specified texture slot. + */ + NIFLIB_API TexClampMode GetTexClampMode( TexType slot ); - NIFLIB_API void SetTexClampMode( TexType tex, TexClampMode mode ); + /* + * Sets the texture clamp mode of the specified texture slot. This + * specifies the way that textures will be displayed for UV coordinates + * that fall outside the 0-1 range. + * \param[in] slot The type of texture slot to get the clamp mode for. + * \param[in] mode The new clamp mode for the specified texture slot. + */ + NIFLIB_API void SetTexClampMode( TexType slot, TexClampMode mode ); - NIFLIB_API TexFilterMode GetTexFilterMode( TexType tex ); + /* + * Retrieves the texture filter mode of the specified texture slot. This + * specifies the way the texure will look when it's minified or magnified. + * \param[in] slot The type of texture slot to set the filter mode for. + * \return The texture filter mode of the specified texture slot. + */ + NIFLIB_API TexFilterMode GetTexFilterMode( TexType slot ); - NIFLIB_API void SetTexFilterMode( TexType tex, TexFilterMode mode ); + /* + * Sets the texture filter mode of the specified texture slot. This + * specifies the way the texure will look when it's minified or magnified. + * \param[in] slot The type of texture slot to set the filter mode for. + * \param[in] mode The new texture filter mode for the specified texture + * slot. + */ + NIFLIB_API void SetTexFilterMode( TexType slot, TexFilterMode mode ); private: friend class MatTexCollection; + /*! NIFLIB_HIDDEN function. For internal use only. */ + NIFLIB_HIDDEN MaterialWrapper( NiMaterialProperty * mat, NiTexturingProperty * texing, NiTextureProperty * tex, NiMultiTextureProperty * multi, NiSpecularProperty * spec, NiAlphaProperty * alpha, MatTexCollection * creator ); + /*! The NiMaterialProperty that this object wraps, if any. */ Ref<NiMaterialProperty> mat_prop; /*! The NiTexturingProperty that this object wraps, if any. */ @@ -292,38 +348,110 @@ private: MatTexCollection * _creator; }; +/* + * A class that wraps up the objects that diferent versions of NIF files use to + * store textures and allows them to me manipulated through the same class. + */ class TextureWrapper { public: - NIFLIB_HIDDEN TextureWrapper( NiSourceTexture * src ); - NIFLIB_HIDDEN TextureWrapper( NiImage * img ); + /*! Destructor */ NIFLIB_API ~TextureWrapper(); + /* + * Used to determine whether the texture that this object stores is + * stored in an external file, rather than being packed into the NIF + * file itself. + * \return True if the texture is external, false otherwise. + */ NIFLIB_API bool IsTextureExternal(); + /* + * Retrieves the file name of the external texture. If the texture is not + * external, an empty string or the name of the original file may be + * returned. + * \return The file name of the external texture, if any. + */ NIFLIB_API string GetTextureFileName(); + /* + * Changes the texture mode to external, if it isn't already, and sets the + * file name of the new texture location. + * \param[in] The new file name for the external texture. + */ NIFLIB_API void SetExternalTexture( const string & file_name ); + /* + * Gets the pixel layout of the texture. This describes the image format + * of the texture, such as palattized, 32-bit, etc. + * \return The pixel layout of the texture. + */ NIFLIB_API PixelLayout GetPixelLayout(); + /* + * Sets the pixel layout of the texture. This describes the image format + * of the texture, such as palattized, 32-bit, etc. Older texture objects + * don't seem to have this option, so calling this function won't affect + * them. + * \param[in] layout The new pixel layout for the texture. + */ NIFLIB_API void SetPixelLayout( PixelLayout layout ); - + /* + * Gets the mipmap format of the texture. This indicates whether or not + * the textures will use mipmaps which are smaller versions of the texture + * that are cached to improve the look of the texture as it is scaled down. + * \return The mipmap format of the texture. + */ NIFLIB_API MipMapFormat GetMipMapFormat(); + /* + * Sets the mipmap format of the texture. This indicates whether or not + * the textures will use mipmaps which are smaller versions of the texture + * that are cached to improve the look of the texture as it is scaled down. + * Older texture objects don't seem to have this option, so calling this + * function won't affect them. + * \param[in] format The new mipmap format for the texture. + */ NIFLIB_API void SetMipMapFormat( MipMapFormat format ); + /* + * Gets the alpha format of the texture. This indicates the type of alpha + * information the texture will contain, such as none, binary, or smooth. + * \return The alpha format of the texture. + */ NIFLIB_API AlphaFormat GetAlphaFormat(); + /* + * Sets the alpha format of the texture. This indicates the type of alpha + * information the texture will contain, such as none, binary, or smooth. + * Older texture objects don't seem to have this option, so calling this + * function won't affect them. + * \param[in] format The new alpha format for the texture. + */ NIFLIB_API void SetAlphaFormat( AlphaFormat format ); + /* + * Retrieves the generic name property of the texture object, if it has one. + * \return The NiObjectNET name of the texture object, if any. + */ NIFLIB_API string GetObjectName(); + /* + * Sets the generic name property of the texture object, if it has one. If + * the object doesn't have the name parameter, this function will do + * nothing. + * \param[in] The new NiObjectNET name for the texture object. + */ NIFLIB_API void SetObjectName( const string & name ); private: friend class MatTexCollection; friend class MaterialWrapper; + /*! NIFLIB_HIDDEN function. For internal use only. */ + NIFLIB_HIDDEN TextureWrapper( NiSourceTexture * src ); + /*! NIFLIB_HIDDEN function. For internal use only. */ + NIFLIB_HIDDEN TextureWrapper( NiImage * img ); + /*! The NiSourceTexture that this object wraps, if any. */ Ref<NiSourceTexture> src_tex; /*! The NiImage that this object wraps, if any. */ diff --git a/src/MatTexCollection.cpp b/src/MatTexCollection.cpp index 29b70236112daa3de7c9bc7866a01d8eb8f439b1..1214cf6603af8744dc48bb0e240ed3500a90e47a 100644 --- a/src/MatTexCollection.cpp +++ b/src/MatTexCollection.cpp @@ -356,11 +356,11 @@ Ref<NiAlphaProperty> MaterialWrapper::GetTranslucencyInfo() { //--Texture Functions--// -bool MaterialWrapper::HasTexture( TexType tex ) { +bool MaterialWrapper::HasTexture( TexType slot ) { if ( texing_prop != NULL ) { - return texing_prop->HasTexture( int(tex) ); + return texing_prop->HasTexture( int(slot) ); } - if ( tex_prop != NULL && tex == BASE_MAP ) { + if ( tex_prop != NULL && slot == BASE_MAP ) { if ( tex_prop->GetImage() != NULL ) { return true; } @@ -417,13 +417,13 @@ void MaterialWrapper::SetTextureIndex( TexType slot, unsigned int tex_index ) { //TODO: Figure out which slots are what in NiMultiTextureProperty so this can be implemented for that too } -unsigned int MaterialWrapper::GetTexUVSetIndex( TexType tex ) { +unsigned int MaterialWrapper::GetTexUVSetIndex( TexType slot ) { if ( texing_prop != NULL ) { - if ( texing_prop->HasTexture( int(tex) ) == false ) { + if ( texing_prop->HasTexture( int(slot) ) == false ) { throw runtime_error("The texture at the specified index does not exist."); } - TexDesc td = texing_prop->GetTexture( int(tex) ); + TexDesc td = texing_prop->GetTexture( int(slot) ); return td.uvSet; } @@ -431,27 +431,27 @@ unsigned int MaterialWrapper::GetTexUVSetIndex( TexType tex ) { return 0; } -void MaterialWrapper::SetTexUVSetIndex( TexType tex, unsigned int uv_set ) { +void MaterialWrapper::SetTexUVSetIndex( TexType slot, unsigned int uv_set ) { if ( texing_prop != NULL ) { - if ( texing_prop->HasTexture( int(tex) ) == false ) { + if ( texing_prop->HasTexture( int(slot) ) == false ) { throw runtime_error("The texture at the specified index does not exist."); } - TexDesc td = texing_prop->GetTexture( int(tex) ); + TexDesc td = texing_prop->GetTexture( int(slot) ); td.uvSet = uv_set; - texing_prop->SetTexture( int(tex), td ); + texing_prop->SetTexture( int(slot), td ); } //Just silently fail for now. Not sure where this data may or may not be stored in the old style texture properties. } -TexClampMode MaterialWrapper::GetTexClampMode( TexType tex ) { +TexClampMode MaterialWrapper::GetTexClampMode( TexType slot ) { if ( texing_prop != NULL ) { - if ( texing_prop->HasTexture( int(tex) ) == false ) { + if ( texing_prop->HasTexture( int(slot) ) == false ) { throw runtime_error("The texture at the specified index does not exist."); } - TexDesc td = texing_prop->GetTexture( int(tex) ); + TexDesc td = texing_prop->GetTexture( int(slot) ); return td.clampMode; } @@ -459,27 +459,27 @@ TexClampMode MaterialWrapper::GetTexClampMode( TexType tex ) { return WRAP_S_WRAP_T; } -void MaterialWrapper::SetTexClampMode( TexType tex, TexClampMode mode ) { +void MaterialWrapper::SetTexClampMode( TexType slot, TexClampMode mode ) { if ( texing_prop != NULL ) { - if ( texing_prop->HasTexture( int(tex) ) == false ) { + if ( texing_prop->HasTexture( int(slot) ) == false ) { throw runtime_error("The texture at the specified index does not exist."); } - TexDesc td = texing_prop->GetTexture( int(tex) ); + TexDesc td = texing_prop->GetTexture( int(slot) ); td.clampMode = mode; - texing_prop->SetTexture( int(tex), td ); + texing_prop->SetTexture( int(slot), td ); } //Just silently fail for now. Not sure where this data may or may not be stored in the old style texture properties. } -TexFilterMode MaterialWrapper::GetTexFilterMode( TexType tex ) { +TexFilterMode MaterialWrapper::GetTexFilterMode( TexType slot ) { if ( texing_prop != NULL ) { - if ( texing_prop->HasTexture( int(tex) ) == false ) { + if ( texing_prop->HasTexture( int(slot) ) == false ) { throw runtime_error("The texture at the specified index does not exist."); } - TexDesc td = texing_prop->GetTexture( int(tex) ); + TexDesc td = texing_prop->GetTexture( int(slot) ); return td.filterMode; } @@ -487,15 +487,15 @@ TexFilterMode MaterialWrapper::GetTexFilterMode( TexType tex ) { return FILTER_BILERP; } -void MaterialWrapper::SetTexFilterMode( TexType tex, TexFilterMode mode ) { +void MaterialWrapper::SetTexFilterMode( TexType slot, TexFilterMode mode ) { if ( texing_prop != NULL ) { - if ( texing_prop->HasTexture( int(tex) ) == false ) { + if ( texing_prop->HasTexture( int(slot) ) == false ) { throw runtime_error("The texture at the specified index does not exist."); } - TexDesc td = texing_prop->GetTexture( int(tex) ); + TexDesc td = texing_prop->GetTexture( int(slot) ); td.filterMode = mode; - texing_prop->SetTexture( int(tex), td ); + texing_prop->SetTexture( int(slot), td ); } //Just silently fail for now. Not sure where this data may or may not be stored in the old style texture properties.