Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

- fbx: read textures.

  • Loading branch information...
commit 23914685f92ece1de0bb59113ac5d12f9569634a 1 parent 97b6936
@acgessler authored
Showing with 135 additions and 1 deletion.
  1. +70 −0 code/FBXDocument.h
  2. +65 −1 code/FBXMaterial.cpp
View
70 code/FBXDocument.h
@@ -112,6 +112,70 @@ class Object
};
+
+
+/** 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<const PropertyTable> props;
+
+ unsigned int crop[4];
+};
+
+
+typedef std::fbx_unordered_map<std::string,Texture*> TextureMap;
+
+
/** DOM class for generic FBX materials */
class Material : public Object
{
@@ -135,11 +199,17 @@ class Material : public Object
return *props.get();
}
+ const TextureMap& Textures() const {
+ return textures;
+ }
+
private:
std::string shading;
bool multilayer;
boost::shared_ptr<const PropertyTable> props;
+
+ TextureMap textures;
};
View
66 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
Please sign in to comment.
Something went wrong with that request. Please try again.