Initial support for FBX embedded textures
This commit is contained in:
@@ -50,6 +50,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#include "FBXImportSettings.h"
|
||||
#include "FBXDocumentUtil.h"
|
||||
#include "FBXProperties.h"
|
||||
#include "ByteSwapper.h"
|
||||
#include <boost/foreach.hpp>
|
||||
|
||||
namespace Assimp {
|
||||
@@ -147,6 +148,7 @@ Material::~Material()
|
||||
Texture::Texture(uint64_t id, const Element& element, const Document& doc, const std::string& name)
|
||||
: Object(id,element,name)
|
||||
, uvScaling(1.0f,1.0f)
|
||||
, media(0)
|
||||
{
|
||||
const Scope& sc = GetRequiredScope(element);
|
||||
|
||||
@@ -199,6 +201,23 @@ Texture::Texture(uint64_t id, const Element& element, const Document& doc, const
|
||||
}
|
||||
|
||||
props = GetPropertyTable(doc,"Texture.FbxFileTexture",element,sc);
|
||||
|
||||
// resolve video links
|
||||
if(doc.Settings().readTextures) {
|
||||
const std::vector<const Connection*>& conns = doc.GetConnectionsByDestinationSequenced(ID());
|
||||
BOOST_FOREACH(const Connection* con, conns) {
|
||||
const Object* const ob = con->SourceObject();
|
||||
if(!ob) {
|
||||
DOMWarning("failed to read source object for texture link, ignoring",&element);
|
||||
continue;
|
||||
}
|
||||
|
||||
const Video* const video = dynamic_cast<const Video*>(ob);
|
||||
if(video) {
|
||||
media = video;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -253,6 +272,68 @@ void LayeredTexture::fillTexture(const Document& doc)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
Video::Video(uint64_t id, const Element& element, const Document& doc, const std::string& name)
|
||||
: Object(id,element,name)
|
||||
, contentLength(0)
|
||||
, content(0)
|
||||
{
|
||||
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 Content = sc["Content"];
|
||||
|
||||
if(Type) {
|
||||
type = ParseTokenAsString(GetRequiredToken(*Type,0));
|
||||
}
|
||||
|
||||
if(FileName) {
|
||||
fileName = ParseTokenAsString(GetRequiredToken(*FileName,0));
|
||||
}
|
||||
|
||||
if(RelativeFilename) {
|
||||
relativeFileName = ParseTokenAsString(GetRequiredToken(*RelativeFilename,0));
|
||||
}
|
||||
|
||||
if(Content) {
|
||||
const Token& token = GetRequiredToken(*Content, 0);
|
||||
const char* data = token.begin();
|
||||
if(!token.IsBinary()) {
|
||||
DOMWarning("video content is not binary data, ignoring", &element);
|
||||
}
|
||||
else if(static_cast<size_t>(token.end() - data) < 5) {
|
||||
DOMError("binary data array is too short, need five (5) bytes for type signature and element count", &element);
|
||||
}
|
||||
else if(*data != 'R') {
|
||||
DOMWarning("video content is not raw binary data, ignoring", &element);
|
||||
}
|
||||
else {
|
||||
// read number of elements
|
||||
uint32_t len = 0;
|
||||
::memcpy(&len, data + 1, sizeof(len));
|
||||
AI_SWAP4(len);
|
||||
|
||||
contentLength = len;
|
||||
|
||||
content = new uint8_t[len];
|
||||
::memcpy(content, data + 5, len);
|
||||
}
|
||||
}
|
||||
|
||||
props = GetPropertyTable(doc,"Video.FbxVideo",element,sc);
|
||||
}
|
||||
|
||||
|
||||
Video::~Video()
|
||||
{
|
||||
if(content) {
|
||||
delete[] content;
|
||||
}
|
||||
}
|
||||
|
||||
} //!FBX
|
||||
} //!Assimp
|
||||
|
||||
|
||||
Reference in New Issue
Block a user