Minor Update - Texture Are Saved - V10.1.0
This commit is contained in:
@@ -32,11 +32,21 @@ enum class TextureType
|
||||
|
||||
struct TextureContainer
|
||||
{
|
||||
|
||||
// Textures
|
||||
std::vector<ID3D11ShaderResourceView*> diffuse;
|
||||
std::vector<ID3D11ShaderResourceView*> normal;
|
||||
std::vector<ID3D11ShaderResourceView*> specular;
|
||||
std::vector<ID3D11ShaderResourceView*> alpha;
|
||||
|
||||
// Textures Paths
|
||||
std::vector<std::wstring> diffusePaths;
|
||||
std::vector<std::wstring> normalPaths;
|
||||
std::vector<std::wstring> specularPaths;
|
||||
std::vector<std::wstring> alphaPaths;
|
||||
|
||||
|
||||
// Get the vector of textures based on the type
|
||||
std::vector<ID3D11ShaderResourceView*>& Get(TextureType type) const {
|
||||
switch (type) {
|
||||
case TextureType::Diffuse: return const_cast<std::vector<ID3D11ShaderResourceView*>&>(diffuse);
|
||||
@@ -47,6 +57,20 @@ struct TextureContainer
|
||||
}
|
||||
}
|
||||
|
||||
// Get the vector of textures paths based on the type
|
||||
std::vector<std::wstring> GetPaths(TextureType type) const {
|
||||
switch (type)
|
||||
{
|
||||
case TextureType::Diffuse: return std::vector<std::wstring>(diffusePaths);
|
||||
case TextureType::Normal: return std::vector<std::wstring>(normalPaths);
|
||||
case TextureType::Specular: return std::vector<std::wstring>(specularPaths);
|
||||
case TextureType::Alpha: return std::vector<std::wstring>(alphaPaths);
|
||||
default: return std::vector<std::wstring>(diffusePaths);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Get The texture based on the type and index
|
||||
ID3D11ShaderResourceView* GetTexture(TextureType type, int index) const {
|
||||
auto& vec = Get(type);
|
||||
if (index >= 0 && index < vec.size())
|
||||
@@ -54,31 +78,53 @@ struct TextureContainer
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Get The texture path based on the type and index
|
||||
std::wstring GetTexturePath(TextureType type, int index) const
|
||||
{
|
||||
std::vector<std::wstring> path = GetPaths(type);
|
||||
if (index >= 0 && index < path.size())
|
||||
return path[index];
|
||||
return L"";
|
||||
}
|
||||
|
||||
// Release all textures and textures paths
|
||||
|
||||
void ReleaseAll() {
|
||||
ReleaseVector(diffuse);
|
||||
ReleaseVector(normal);
|
||||
ReleaseVector(specular);
|
||||
ReleaseVector(alpha);
|
||||
|
||||
ReleaseVector(diffusePaths);
|
||||
ReleaseVector(normalPaths);
|
||||
ReleaseVector(specularPaths);
|
||||
ReleaseVector(alphaPaths);
|
||||
}
|
||||
|
||||
void AssignTexture(TextureContainer& textContainer, ID3D11ShaderResourceView* texture , int index)
|
||||
// Assign a texture and its path to the appropriate vector based on the index
|
||||
void AssignTexture(TextureContainer& textContainer, ID3D11ShaderResourceView* texture , const std::wstring paths, int index)
|
||||
{
|
||||
switch (index)
|
||||
{
|
||||
case 0:
|
||||
textContainer.diffuse.push_back(texture);
|
||||
textContainer.diffusePaths.push_back(paths);
|
||||
break;
|
||||
case 1:
|
||||
textContainer.normal.push_back(texture);
|
||||
textContainer.normalPaths.push_back(paths);
|
||||
break;
|
||||
case 2:
|
||||
textContainer.specular.push_back(texture);
|
||||
textContainer.specularPaths.push_back(paths);
|
||||
break;
|
||||
case 3:
|
||||
textContainer.alpha.push_back(texture);
|
||||
textContainer.alphaPaths.push_back(paths);
|
||||
break;
|
||||
default:
|
||||
textContainer.diffuse.push_back(texture);
|
||||
textContainer.diffusePaths.push_back(paths);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -93,6 +139,10 @@ private:
|
||||
}
|
||||
vec.clear();
|
||||
}
|
||||
|
||||
void ReleaseVector(std::vector<std::wstring>& vec) {
|
||||
vec.clear();
|
||||
}
|
||||
};
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Class name: ModelClass
|
||||
@@ -172,6 +222,9 @@ public:
|
||||
// M<>thodes pour ajouter une nouvelle texture
|
||||
bool AddTexture(ID3D11Device* device, ID3D11DeviceContext* deviceContext,std::wstring filename, TextureType type);
|
||||
bool AddTexture(ID3D11ShaderResourceView* texture, TextureType type);
|
||||
|
||||
void SetTextureContainer (TextureContainer& texturesContainer) { m_Textures = texturesContainer; }
|
||||
TextureContainer GetTextureContainer() const { return m_Textures; }
|
||||
|
||||
private:
|
||||
bool InitializeBuffers(ID3D11Device*);
|
||||
|
@@ -98,7 +98,7 @@ public:
|
||||
std::string ObjectTypeToString(ObjectType objectType);
|
||||
|
||||
void LaunchObject();
|
||||
void LoadTexturesFromPath(std::vector<std::wstring>& texturePaths, TextureContainer& texturesContainer,D3DClass* m_Direct3D);
|
||||
void LoadTexturesFromPath(std::vector<std::wstring>& texturePaths, TextureContainer& texturesContainer, D3DClass* m_Direct3D);
|
||||
void SetAlpha(float alpha) { m_alpha = alpha; }
|
||||
float GetAlpha() const { return m_alpha; }
|
||||
void SetInitialStretch(float initialStretch) { m_initialStretch = initialStretch; }
|
||||
@@ -134,6 +134,7 @@ private:
|
||||
|
||||
float m_boundingRadius;
|
||||
std::wstring m_modelPath;
|
||||
TextureContainer m_texturesContainer;
|
||||
float m_alpha = 0.0f;
|
||||
float m_initialStretch = 0.0f;
|
||||
float m_springConstant = 10.0f;
|
||||
|
Reference in New Issue
Block a user