Skip to content

Commit

Permalink
- fbx: read textures.
Browse files Browse the repository at this point in the history
  • Loading branch information
acgessler committed Jul 3, 2012
1 parent 97b6936 commit 2391468
Show file tree
Hide file tree
Showing 2 changed files with 135 additions and 1 deletion.
70 changes: 70 additions & 0 deletions code/FBXDocument.h
Expand Up @@ -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
{
Expand All @@ -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;
};


Expand Down
66 changes: 65 additions & 1 deletion code/FBXMaterial.cpp
Expand Up @@ -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"

Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 2391468

Please sign in to comment.