From 23914685f92ece1de0bb59113ac5d12f9569634a Mon Sep 17 00:00:00 2001 From: Alexander Gessler Date: Tue, 3 Jul 2012 14:59:40 +0200 Subject: [PATCH] - fbx: read textures. --- code/FBXDocument.h | 70 ++++++++++++++++++++++++++++++++++++++++++++ code/FBXMaterial.cpp | 66 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 135 insertions(+), 1 deletion(-) diff --git a/code/FBXDocument.h b/code/FBXDocument.h index 7bbb4fcf8..5b99c1a94 100644 --- a/code/FBXDocument.h +++ b/code/FBXDocument.h @@ -112,6 +112,70 @@ protected: }; + + +/** DOM class for generic FBX textures */ +class Texture : public Object +{ +public: + + Texture(const Element& element, const Document& doc, const std::string& name); + ~Texture(); + +public: + + const std::string& Type() const { + return type; + } + + const std::string& FileName() const { + return fileName; + } + + const std::string& RelativeFilename() const { + return relativeFileName; + } + + const std::string& AlphaSource() const { + return alphaSource; + } + + const aiVector2D& UVTranslation() const { + return uvTrans; + } + + const aiVector2D& UVScaling() const { + return uvScaling; + } + + const PropertyTable& Props() const { + ai_assert(props.get()); + return *props.get(); + } + + // return a 4-tuple + const unsigned int* Crop() const { + return crop; + } + +private: + + aiVector2D uvTrans; + aiVector2D uvScaling; + + std::string type; + std::string relativeFileName; + std::string fileName; + std::string alphaSource; + boost::shared_ptr props; + + unsigned int crop[4]; +}; + + +typedef std::fbx_unordered_map TextureMap; + + /** DOM class for generic FBX materials */ class Material : public Object { @@ -135,11 +199,17 @@ public: return *props.get(); } + const TextureMap& Textures() const { + return textures; + } + private: std::string shading; bool multilayer; boost::shared_ptr props; + + TextureMap textures; }; diff --git a/code/FBXMaterial.cpp b/code/FBXMaterial.cpp index 74761b98a..bbb00deba 100644 --- a/code/FBXMaterial.cpp +++ b/code/FBXMaterial.cpp @@ -39,7 +39,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /** @file FBXMaterial.cpp - * @brief Assimp::FBX::Material implementation + * @brief Assimp::FBX::Material and Assimp::FBX::Texture implementation */ #include "AssimpPCH.h" @@ -100,6 +100,70 @@ Material::~Material() { } +// ------------------------------------------------------------------------------------------------ +Texture::Texture(const Element& element, const Document& doc, const std::string& name) +: Object(element,name) +, uvScaling(1.0f,1.0f) +{ + const Scope& sc = GetRequiredScope(element); + + const Element* const Type = sc["Type"]; + const Element* const FileName = sc["FileName"]; + const Element* const RelativeFilename = sc["RelativeFilename"]; + const Element* const ModelUVTranslation = sc["ModelUVTranslation"]; + const Element* const ModelUVScaling = sc["ModelUVScaling"]; + const Element* const Texture_Alpha_Source = sc["Texture_Alpha_Source"]; + const Element* const Cropping = sc["Cropping"]; + + if(Type) { + type = ParseTokenAsString(GetRequiredToken(*Type,0)); + } + + if(FileName) { + fileName = ParseTokenAsString(GetRequiredToken(*FileName,0)); + } + + if(RelativeFilename) { + relativeFileName = ParseTokenAsString(GetRequiredToken(*RelativeFilename,0)); + } + + if(ModelUVTranslation) { + uvTrans = aiVector2D(ParseTokenAsFloat(GetRequiredToken(*ModelUVTranslation,0)), + ParseTokenAsFloat(GetRequiredToken(*ModelUVTranslation,1)) + ); + } + + if(ModelUVScaling) { + uvScaling = aiVector2D(ParseTokenAsFloat(GetRequiredToken(*ModelUVScaling,0)), + ParseTokenAsFloat(GetRequiredToken(*ModelUVScaling,1)) + ); + } + + if(Cropping) { + crop[0] = ParseTokenAsInt(GetRequiredToken(*Cropping,0)); + crop[1] = ParseTokenAsInt(GetRequiredToken(*Cropping,1)); + crop[2] = ParseTokenAsInt(GetRequiredToken(*Cropping,2)); + crop[3] = ParseTokenAsInt(GetRequiredToken(*Cropping,3)); + } + else { + // vc8 doesn't support the crop() syntax in initialization lists + // (and vc9 WARNS about the new (i.e. compliant) behaviour). + crop[0] = crop[1] = crop[2] = crop[3] = 0; + } + + if(Texture_Alpha_Source) { + alphaSource = ParseTokenAsString(GetRequiredToken(*Texture_Alpha_Source,0)); + } + + props = GetPropertyTable(doc,"Texture.FbxFileTexture",element,sc); +} + + +Texture::~Texture() +{ + +} + } //!FBX } //!Assimp