2012-06-26 16:31:19 +00:00
|
|
|
/*
|
|
|
|
Open Asset Import Library (assimp)
|
|
|
|
----------------------------------------------------------------------
|
|
|
|
|
|
|
|
Copyright (c) 2006-2012, assimp team
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
Redistribution and use of this software in source and binary forms,
|
|
|
|
with or without modification, are permitted provided that the
|
|
|
|
following conditions are met:
|
|
|
|
|
|
|
|
* Redistributions of source code must retain the above
|
|
|
|
copyright notice, this list of conditions and the
|
|
|
|
following disclaimer.
|
|
|
|
|
|
|
|
* Redistributions in binary form must reproduce the above
|
|
|
|
copyright notice, this list of conditions and the
|
|
|
|
following disclaimer in the documentation and/or other
|
|
|
|
materials provided with the distribution.
|
|
|
|
|
|
|
|
* Neither the name of the assimp team, nor the names of its
|
|
|
|
contributors may be used to endorse or promote products
|
|
|
|
derived from this software without specific prior
|
|
|
|
written permission of the assimp team.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
----------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** @file FBXDocument.h
|
|
|
|
* @brief FBX DOM
|
|
|
|
*/
|
|
|
|
#ifndef INCLUDED_AI_FBX_DOCUMENT_H
|
|
|
|
#define INCLUDED_AI_FBX_DOCUMENT_H
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include <map>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
namespace Assimp {
|
|
|
|
namespace FBX {
|
|
|
|
|
|
|
|
class Parser;
|
|
|
|
class Object;
|
2012-06-28 17:16:14 +00:00
|
|
|
struct ImportSettings;
|
2012-06-26 16:31:19 +00:00
|
|
|
|
2012-07-02 14:51:19 +00:00
|
|
|
class PropertyTable;
|
2012-07-02 15:37:00 +00:00
|
|
|
class Document;
|
2012-07-04 14:33:21 +00:00
|
|
|
class Material;
|
|
|
|
class Geometry;
|
2012-07-02 14:51:19 +00:00
|
|
|
|
2012-06-26 16:31:19 +00:00
|
|
|
|
|
|
|
/** Represents a delay-parsed FBX objects. Many objects in the scene
|
|
|
|
* are not needed by assimp, so it makes no sense to parse them
|
|
|
|
* upfront. */
|
|
|
|
class LazyObject
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2012-07-03 17:36:38 +00:00
|
|
|
LazyObject(uint64_t id, const Element& element, const Document& doc);
|
2012-06-26 16:31:19 +00:00
|
|
|
~LazyObject();
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2012-07-21 18:02:00 +00:00
|
|
|
const Object* Get(bool dieOnError = false);
|
2012-06-26 16:31:19 +00:00
|
|
|
|
|
|
|
template <typename T>
|
2012-07-21 18:02:00 +00:00
|
|
|
const T* Get(bool dieOnError = false) {
|
|
|
|
const Object* const ob = Get(dieOnError);
|
2012-07-20 22:45:37 +00:00
|
|
|
return ob ? dynamic_cast<const T*>(ob) : NULL;
|
2012-06-26 16:31:19 +00:00
|
|
|
}
|
|
|
|
|
2012-07-03 17:36:38 +00:00
|
|
|
uint64_t ID() const {
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
2012-07-21 15:12:04 +00:00
|
|
|
bool IsBeingConstructed() const {
|
2012-07-21 18:02:00 +00:00
|
|
|
return (flags & BEING_CONSTRUCTED) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FailedToConstruct() const {
|
|
|
|
return (flags & FAILED_TO_CONSTRUCT) != 0;
|
2012-07-21 15:12:04 +00:00
|
|
|
}
|
|
|
|
|
2012-07-21 16:02:10 +00:00
|
|
|
const Element& GetElement() const {
|
|
|
|
return element;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Document& GetDocument() const {
|
|
|
|
return doc;
|
|
|
|
}
|
|
|
|
|
2012-06-26 16:31:19 +00:00
|
|
|
private:
|
|
|
|
|
2012-07-02 15:37:00 +00:00
|
|
|
const Document& doc;
|
2012-06-26 16:31:19 +00:00
|
|
|
const Element& element;
|
|
|
|
boost::scoped_ptr<const Object> object;
|
2012-07-03 17:36:38 +00:00
|
|
|
|
|
|
|
const uint64_t id;
|
2012-07-21 18:02:00 +00:00
|
|
|
|
|
|
|
enum Flags {
|
|
|
|
BEING_CONSTRUCTED = 0x1,
|
|
|
|
FAILED_TO_CONSTRUCT = 0x2
|
|
|
|
};
|
|
|
|
|
|
|
|
unsigned int flags;
|
2012-06-26 16:31:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Base class for in-memory (DOM) representations of FBX objects */
|
|
|
|
class Object
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2012-07-03 17:36:38 +00:00
|
|
|
Object(uint64_t id, const Element& element, const std::string& name);
|
2012-06-28 21:44:23 +00:00
|
|
|
virtual ~Object();
|
2012-06-26 16:31:19 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
2012-07-02 17:59:31 +00:00
|
|
|
const Element& SourceElement() const {
|
|
|
|
return element;
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::string& Name() const {
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
2012-07-03 17:36:38 +00:00
|
|
|
uint64_t ID() const {
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
2012-06-26 16:31:19 +00:00
|
|
|
protected:
|
|
|
|
const Element& element;
|
2012-06-26 17:19:13 +00:00
|
|
|
const std::string name;
|
2012-07-03 17:36:38 +00:00
|
|
|
const uint64_t id;
|
2012-06-26 16:31:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-07-20 22:45:37 +00:00
|
|
|
/** DOM base class for FBX models (even though its semantics are more "node" than "model" */
|
2012-07-04 14:33:21 +00:00
|
|
|
class Model : public Object
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
Model(uint64_t id, const Element& element, const Document& doc, const std::string& name);
|
|
|
|
~Model();
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
const std::string& Shading() const {
|
|
|
|
return shading;
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::string& Culling() const {
|
|
|
|
return culling;
|
|
|
|
}
|
|
|
|
|
|
|
|
const PropertyTable& Props() const {
|
|
|
|
ai_assert(props.get());
|
|
|
|
return *props.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Get material links */
|
|
|
|
const std::vector<const Material*>& GetMaterials() const {
|
|
|
|
return materials;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** Get geometry links */
|
|
|
|
const std::vector<const Geometry*>& GetGeometry() const {
|
|
|
|
return geometry;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
void ResolveLinks(const Element& element, const Document& doc);
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
std::vector<const Material*> materials;
|
|
|
|
std::vector<const Geometry*> geometry;
|
|
|
|
|
|
|
|
std::string shading;
|
|
|
|
std::string culling;
|
|
|
|
boost::shared_ptr<const PropertyTable> props;
|
|
|
|
};
|
|
|
|
|
2012-07-03 12:59:40 +00:00
|
|
|
|
|
|
|
|
|
|
|
/** DOM class for generic FBX textures */
|
|
|
|
class Texture : public Object
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2012-07-03 17:36:38 +00:00
|
|
|
Texture(uint64_t id, const Element& element, const Document& doc, const std::string& name);
|
2012-07-03 12:59:40 +00:00
|
|
|
~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];
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-07-03 17:42:14 +00:00
|
|
|
typedef std::fbx_unordered_map<std::string, const Texture*> TextureMap;
|
2012-07-03 12:59:40 +00:00
|
|
|
|
|
|
|
|
2012-07-02 15:37:00 +00:00
|
|
|
/** DOM class for generic FBX materials */
|
|
|
|
class Material : public Object
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2012-07-03 17:36:38 +00:00
|
|
|
Material(uint64_t id, const Element& element, const Document& doc, const std::string& name);
|
2012-07-02 15:37:00 +00:00
|
|
|
~Material();
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
const std::string& GetShadingModel() const {
|
|
|
|
return shading;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsMultilayer() const {
|
|
|
|
return multilayer;
|
|
|
|
}
|
|
|
|
|
2012-07-02 17:59:31 +00:00
|
|
|
const PropertyTable& Props() const {
|
|
|
|
ai_assert(props.get());
|
|
|
|
return *props.get();
|
2012-07-02 15:37:00 +00:00
|
|
|
}
|
|
|
|
|
2012-07-03 12:59:40 +00:00
|
|
|
const TextureMap& Textures() const {
|
|
|
|
return textures;
|
|
|
|
}
|
|
|
|
|
2012-07-02 15:37:00 +00:00
|
|
|
private:
|
|
|
|
|
|
|
|
std::string shading;
|
|
|
|
bool multilayer;
|
|
|
|
boost::shared_ptr<const PropertyTable> props;
|
2012-07-03 12:59:40 +00:00
|
|
|
|
|
|
|
TextureMap textures;
|
2012-07-02 15:37:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-06-26 16:31:19 +00:00
|
|
|
/** DOM base class for all kinds of FBX geometry */
|
|
|
|
class Geometry : public Object
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2012-07-03 17:36:38 +00:00
|
|
|
Geometry(uint64_t id, const Element& element, const std::string& name);
|
2012-06-26 16:31:19 +00:00
|
|
|
~Geometry();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/** DOM class for FBX geometry of type "Mesh"*/
|
|
|
|
class MeshGeometry : public Geometry
|
|
|
|
{
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2012-07-04 13:07:57 +00:00
|
|
|
MeshGeometry(uint64_t id, const Element& element, const std::string& name, const Document& doc);
|
2012-06-26 16:31:19 +00:00
|
|
|
~MeshGeometry();
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
/** Get a list of all vertex points, non-unique*/
|
|
|
|
const std::vector<aiVector3D>& GetVertices() const {
|
|
|
|
return vertices;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Get a list of all vertex normals or an empty array if
|
|
|
|
* no normals are specified. */
|
|
|
|
const std::vector<aiVector3D>& GetNormals() const {
|
|
|
|
return normals;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Get a list of all vertex tangents or an empty array
|
|
|
|
* if no tangents are specified */
|
|
|
|
const std::vector<aiVector3D>& GetTangents() const {
|
|
|
|
return tangents;
|
|
|
|
}
|
2012-06-28 14:51:55 +00:00
|
|
|
|
|
|
|
/** Get a list of all vertex binormals or an empty array
|
|
|
|
* if no binormals are specified */
|
|
|
|
const std::vector<aiVector3D>& GetBinormals() const {
|
|
|
|
return binormals;
|
|
|
|
}
|
2012-06-26 16:31:19 +00:00
|
|
|
|
|
|
|
/** Return list of faces - each entry denotes a face and specifies
|
|
|
|
* how many vertices it has. Vertices are taken from the
|
|
|
|
* vertex data arrays in sequential order. */
|
|
|
|
const std::vector<unsigned int>& GetFaceIndexCounts() const {
|
|
|
|
return faces;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Get a UV coordinate slot, returns an empty array if
|
|
|
|
* the requested slot does not exist. */
|
2012-06-27 21:02:00 +00:00
|
|
|
const std::vector<aiVector2D>& GetTextureCoords(unsigned int index) const {
|
|
|
|
static const std::vector<aiVector2D> empty;
|
2012-06-26 16:31:19 +00:00
|
|
|
return index >= AI_MAX_NUMBER_OF_TEXTURECOORDS ? empty : uvs[index];
|
|
|
|
}
|
|
|
|
|
2012-07-03 18:41:21 +00:00
|
|
|
|
|
|
|
/** Get a UV coordinate slot, returns an empty array if
|
|
|
|
* the requested slot does not exist. */
|
|
|
|
std::string GetTextureCoordChannelName(unsigned int index) const {
|
|
|
|
return index >= AI_MAX_NUMBER_OF_TEXTURECOORDS ? "" : uvNames[index];
|
|
|
|
}
|
|
|
|
|
2012-06-26 16:31:19 +00:00
|
|
|
/** Get a vertex color coordinate slot, returns an empty array if
|
|
|
|
* the requested slot does not exist. */
|
|
|
|
const std::vector<aiColor4D>& GetVertexColors(unsigned int index) const {
|
|
|
|
static const std::vector<aiColor4D> empty;
|
|
|
|
return index >= AI_MAX_NUMBER_OF_COLOR_SETS ? empty : colors[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** Get per-face-vertex material assignments */
|
|
|
|
const std::vector<unsigned int>& GetMaterialIndices() const {
|
|
|
|
return materials;
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2012-06-27 21:02:00 +00:00
|
|
|
private:
|
|
|
|
|
|
|
|
void ReadLayer(const Scope& layer);
|
|
|
|
void ReadLayerElement(const Scope& layerElement);
|
|
|
|
void ReadVertexData(const std::string& type, int index, const Scope& source);
|
|
|
|
|
2012-06-28 00:06:24 +00:00
|
|
|
void ReadVertexDataUV(std::vector<aiVector2D>& uv_out, const Scope& source,
|
|
|
|
const std::string& MappingInformationType,
|
|
|
|
const std::string& ReferenceInformationType);
|
|
|
|
|
|
|
|
void ReadVertexDataNormals(std::vector<aiVector3D>& normals_out, const Scope& source,
|
|
|
|
const std::string& MappingInformationType,
|
|
|
|
const std::string& ReferenceInformationType);
|
|
|
|
|
2012-06-28 14:51:55 +00:00
|
|
|
void ReadVertexDataColors(std::vector<aiColor4D>& colors_out, const Scope& source,
|
|
|
|
const std::string& MappingInformationType,
|
|
|
|
const std::string& ReferenceInformationType);
|
|
|
|
|
|
|
|
void ReadVertexDataTangents(std::vector<aiVector3D>& tangents_out, const Scope& source,
|
|
|
|
const std::string& MappingInformationType,
|
|
|
|
const std::string& ReferenceInformationType);
|
|
|
|
|
|
|
|
void ReadVertexDataBinormals(std::vector<aiVector3D>& binormals_out, const Scope& source,
|
|
|
|
const std::string& MappingInformationType,
|
|
|
|
const std::string& ReferenceInformationType);
|
|
|
|
|
2012-06-28 15:13:13 +00:00
|
|
|
void ReadVertexDataMaterials(std::vector<unsigned int>& materials_out, const Scope& source,
|
|
|
|
const std::string& MappingInformationType,
|
|
|
|
const std::string& ReferenceInformationType);
|
|
|
|
|
2012-06-26 16:31:19 +00:00
|
|
|
private:
|
|
|
|
|
|
|
|
// cached data arrays
|
|
|
|
std::vector<unsigned int> materials;
|
|
|
|
std::vector<aiVector3D> vertices;
|
|
|
|
std::vector<unsigned int> faces;
|
|
|
|
std::vector<aiVector3D> tangents;
|
2012-06-28 14:51:55 +00:00
|
|
|
std::vector<aiVector3D> binormals;
|
2012-06-26 16:31:19 +00:00
|
|
|
std::vector<aiVector3D> normals;
|
2012-07-03 18:41:21 +00:00
|
|
|
|
|
|
|
std::string uvNames[AI_MAX_NUMBER_OF_TEXTURECOORDS];
|
2012-06-27 21:02:00 +00:00
|
|
|
std::vector<aiVector2D> uvs[AI_MAX_NUMBER_OF_TEXTURECOORDS];
|
2012-06-26 16:31:19 +00:00
|
|
|
std::vector<aiColor4D> colors[AI_MAX_NUMBER_OF_COLOR_SETS];
|
2012-06-27 22:35:40 +00:00
|
|
|
|
|
|
|
std::vector<unsigned int> mapping_counts;
|
|
|
|
std::vector<unsigned int> mapping_offsets;
|
|
|
|
std::vector<unsigned int> mappings;
|
2012-06-26 16:31:19 +00:00
|
|
|
};
|
|
|
|
|
2012-07-21 19:28:02 +00:00
|
|
|
typedef std::vector<uint64_t> KeyTimeList;
|
|
|
|
typedef std::vector<float> KeyValueList;
|
2012-07-20 22:45:37 +00:00
|
|
|
|
|
|
|
/** Represents a FBX animation curve (i.e. a 1-dimensional set of keyframes and values therefor) */
|
|
|
|
class AnimationCurve : public Object
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
AnimationCurve(uint64_t id, const Element& element, const std::string& name, const Document& doc);
|
|
|
|
~AnimationCurve();
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
/** get list of keyframe positions (time).
|
|
|
|
* Invariant: |GetKeys()| > 0 */
|
2012-07-21 19:28:02 +00:00
|
|
|
const KeyTimeList& GetKeys() const {
|
2012-07-20 22:45:37 +00:00
|
|
|
return keys;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** get list of keyframe values.
|
|
|
|
* Invariant: |GetKeys()| == |GetValues()| && |GetKeys()| > 0*/
|
2012-07-21 19:28:02 +00:00
|
|
|
const KeyValueList& GetValues() const {
|
2012-07-20 22:45:37 +00:00
|
|
|
return values;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const std::vector<float>& GetAttributes() const {
|
|
|
|
return attributes;
|
|
|
|
}
|
|
|
|
|
2012-07-21 19:28:02 +00:00
|
|
|
const std::vector<unsigned int>& GetFlags() const {
|
2012-07-20 22:45:37 +00:00
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
2012-07-21 19:28:02 +00:00
|
|
|
KeyTimeList keys;
|
|
|
|
KeyValueList values;
|
2012-07-20 22:45:37 +00:00
|
|
|
std::vector<float> attributes;
|
2012-07-21 19:28:02 +00:00
|
|
|
std::vector<unsigned int> flags;
|
2012-07-20 22:45:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// property-name -> animation curve
|
|
|
|
typedef std::map<std::string, const AnimationCurve*> AnimationCurveMap;
|
|
|
|
|
|
|
|
|
|
|
|
/** Represents a FBX animation curve (i.e. a mapping from single animation curves to nodes) */
|
|
|
|
class AnimationCurveNode : public Object
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
AnimationCurveNode(uint64_t id, const Element& element, const std::string& name, const Document& doc);
|
|
|
|
~AnimationCurveNode();
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
const PropertyTable& Props() const {
|
|
|
|
ai_assert(props.get());
|
|
|
|
return *props.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const AnimationCurveMap Curves() const {
|
|
|
|
return curves;
|
|
|
|
}
|
|
|
|
|
2012-07-21 15:12:04 +00:00
|
|
|
/** Model instance the curve is assigned to, this is always non-NULL */
|
2012-07-20 22:45:37 +00:00
|
|
|
const Model* TargetNode() const {
|
|
|
|
return target;
|
|
|
|
}
|
|
|
|
|
2012-07-21 15:12:04 +00:00
|
|
|
/** Property of TargetNode() that is being animated*/
|
2012-07-21 02:15:10 +00:00
|
|
|
const std::string& TargetProperty() const {
|
|
|
|
return prop;
|
|
|
|
}
|
|
|
|
|
2012-07-20 22:45:37 +00:00
|
|
|
private:
|
|
|
|
|
|
|
|
const Model* target;
|
|
|
|
boost::shared_ptr<const PropertyTable> props;
|
|
|
|
AnimationCurveMap curves;
|
2012-07-21 02:15:10 +00:00
|
|
|
|
|
|
|
std::string prop;
|
2012-07-20 22:45:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef std::vector<const AnimationCurveNode*> AnimationCurveNodeList;
|
|
|
|
|
|
|
|
|
|
|
|
/** Represents a FBX animation layer (i.e. a list of node animations) */
|
|
|
|
class AnimationLayer : public Object
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
AnimationLayer(uint64_t id, const Element& element, const std::string& name, const Document& doc);
|
|
|
|
~AnimationLayer();
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
const PropertyTable& Props() const {
|
|
|
|
ai_assert(props.get());
|
|
|
|
return *props.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
const AnimationCurveNodeList& Nodes() const {
|
|
|
|
return nodes;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
boost::shared_ptr<const PropertyTable> props;
|
|
|
|
AnimationCurveNodeList nodes;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
typedef std::vector<const AnimationLayer*> AnimationLayerList;
|
|
|
|
|
|
|
|
|
|
|
|
/** Represents a FBX animation stack (i.e. a list of animation layers) */
|
|
|
|
class AnimationStack : public Object
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
AnimationStack(uint64_t id, const Element& element, const std::string& name, const Document& doc);
|
|
|
|
~AnimationStack();
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
const PropertyTable& Props() const {
|
|
|
|
ai_assert(props.get());
|
|
|
|
return *props.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const AnimationLayerList& Layers() const {
|
|
|
|
return layers;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
boost::shared_ptr<const PropertyTable> props;
|
|
|
|
AnimationLayerList layers;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-07-03 14:50:58 +00:00
|
|
|
/** Represents a link between two FBX objects. */
|
|
|
|
class Connection
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
Connection(uint64_t insertionOrder, uint64_t src, uint64_t dest, const std::string& prop, const Document& doc);
|
|
|
|
~Connection();
|
|
|
|
|
|
|
|
// note: a connection ensures that the source and dest objects exist, but
|
|
|
|
// not that they have DOM representations, so the return value of one of
|
|
|
|
// these functions can still be NULL.
|
|
|
|
const Object* SourceObject() const;
|
|
|
|
const Object* DestinationObject() const;
|
|
|
|
|
2012-07-21 15:12:04 +00:00
|
|
|
// these, however, are always guaranteed to be valid
|
|
|
|
LazyObject& LazySourceObject() const;
|
|
|
|
LazyObject& LazyDestinationObject() const;
|
|
|
|
|
|
|
|
|
|
|
|
/** return the name of the property the connection is attached to.
|
|
|
|
* this is an empty string for object to object (OO) connections. */
|
2012-07-03 14:50:58 +00:00
|
|
|
const std::string& PropertyName() const {
|
|
|
|
return prop;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t InsertionOrder() const {
|
|
|
|
return insertionOrder;
|
|
|
|
}
|
|
|
|
|
2012-07-03 15:57:21 +00:00
|
|
|
int CompareTo(const Connection* c) const {
|
|
|
|
// note: can't subtract because this would overflow uint64_t
|
|
|
|
if(InsertionOrder() > c->InsertionOrder()) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else if(InsertionOrder() < c->InsertionOrder()) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-07-05 15:18:54 +00:00
|
|
|
bool Compare(const Connection* c) const {
|
|
|
|
return InsertionOrder() < c->InsertionOrder();
|
|
|
|
}
|
|
|
|
|
2012-07-03 14:50:58 +00:00
|
|
|
public:
|
|
|
|
|
|
|
|
uint64_t insertionOrder;
|
2012-07-03 23:45:15 +00:00
|
|
|
const std::string prop;
|
2012-07-03 14:50:58 +00:00
|
|
|
|
|
|
|
uint64_t src, dest;
|
|
|
|
const Document& doc;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-06-26 16:31:19 +00:00
|
|
|
// XXX again, unique_ptr would be useful. shared_ptr is too
|
|
|
|
// bloated since the objects have a well-defined single owner
|
|
|
|
// during their entire lifetime (Document). FBX files have
|
|
|
|
// up to many thousands of objects (most of which we never use),
|
|
|
|
// so the memory overhead for them should be kept at a minimum.
|
|
|
|
typedef std::map<uint64_t, LazyObject*> ObjectMap;
|
2012-07-02 15:37:00 +00:00
|
|
|
typedef std::fbx_unordered_map<std::string, boost::shared_ptr<const PropertyTable> > PropertyTemplateMap;
|
2012-06-26 16:31:19 +00:00
|
|
|
|
2012-07-03 14:50:58 +00:00
|
|
|
|
|
|
|
typedef std::multimap<uint64_t, const Connection*> ConnectionMap;
|
|
|
|
|
2012-07-03 15:57:21 +00:00
|
|
|
|
2012-06-26 16:31:19 +00:00
|
|
|
/** DOM root for a FBX file */
|
|
|
|
class Document
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2012-06-28 17:16:14 +00:00
|
|
|
Document(const Parser& parser, const ImportSettings& settings);
|
2012-06-26 16:31:19 +00:00
|
|
|
~Document();
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2012-07-03 14:50:58 +00:00
|
|
|
LazyObject* GetObject(uint64_t id) const;
|
|
|
|
|
2012-07-06 20:46:19 +00:00
|
|
|
|
|
|
|
unsigned int FBXVersion() const {
|
|
|
|
return fbxVersion;
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::string& Creator() const {
|
|
|
|
return creator;
|
|
|
|
}
|
|
|
|
|
|
|
|
// elements (in this order): Uear, Month, Day, Hour, Second, Millisecond
|
|
|
|
const unsigned int* CreationTimeStamp() const {
|
|
|
|
return creationTimeStamp;
|
|
|
|
}
|
|
|
|
|
2012-07-02 14:51:19 +00:00
|
|
|
const PropertyTemplateMap& Templates() const {
|
|
|
|
return templates;
|
|
|
|
}
|
|
|
|
|
2012-06-26 16:31:19 +00:00
|
|
|
const ObjectMap& Objects() const {
|
|
|
|
return objects;
|
|
|
|
}
|
|
|
|
|
2012-06-28 17:16:14 +00:00
|
|
|
const ImportSettings& Settings() const {
|
|
|
|
return settings;
|
|
|
|
}
|
|
|
|
|
2012-07-03 14:50:58 +00:00
|
|
|
const ConnectionMap& ConnectionsBySource() const {
|
|
|
|
return src_connections;
|
|
|
|
}
|
|
|
|
|
|
|
|
const ConnectionMap& ConnectionsByDestination() const {
|
|
|
|
return dest_connections;
|
|
|
|
}
|
|
|
|
|
2012-07-21 18:02:00 +00:00
|
|
|
// note: the implicit rule in all DOM classes is to always resolve
|
|
|
|
// from destination to source (since the FBX object hierarchy is,
|
|
|
|
// with very few exceptions, a DAG, this avoids cycles). In all
|
|
|
|
// cases that may involve back-facing edges in the object graph,
|
|
|
|
// use LazyObject::IsBeingConstructed() to check.
|
|
|
|
|
2012-07-03 15:57:21 +00:00
|
|
|
std::vector<const Connection*> GetConnectionsBySourceSequenced(uint64_t source) const;
|
|
|
|
std::vector<const Connection*> GetConnectionsByDestinationSequenced(uint64_t dest) const;
|
|
|
|
|
2012-07-21 18:02:00 +00:00
|
|
|
std::vector<const Connection*> GetConnectionsBySourceSequenced(uint64_t source, const char* classname) const;
|
|
|
|
std::vector<const Connection*> GetConnectionsByDestinationSequenced(uint64_t dest, const char* classname) const;
|
|
|
|
|
2012-07-21 16:02:10 +00:00
|
|
|
std::vector<const Connection*> GetConnectionsBySourceSequenced(uint64_t source, const char* const* classnames, size_t count) const;
|
|
|
|
std::vector<const Connection*> GetConnectionsByDestinationSequenced(uint64_t dest, const char* const* classnames, size_t count) const;
|
|
|
|
|
2012-07-20 22:45:37 +00:00
|
|
|
const std::vector<const AnimationStack*>& AnimationStacks() const;
|
|
|
|
|
2012-07-21 16:02:10 +00:00
|
|
|
private:
|
|
|
|
|
|
|
|
std::vector<const Connection*> GetConnectionsSequenced(uint64_t id, const ConnectionMap&) const;
|
2012-07-21 18:02:00 +00:00
|
|
|
std::vector<const Connection*> GetConnectionsSequenced(uint64_t id, bool is_src, const ConnectionMap&, const char* const* classnames, size_t count) const;
|
2012-07-21 16:02:10 +00:00
|
|
|
|
2012-07-02 14:51:19 +00:00
|
|
|
private:
|
|
|
|
|
2012-07-06 20:46:19 +00:00
|
|
|
void ReadHeader();
|
2012-07-02 14:51:19 +00:00
|
|
|
void ReadObjects();
|
|
|
|
void ReadPropertyTemplates();
|
2012-07-03 14:50:58 +00:00
|
|
|
void ReadConnections();
|
2012-07-02 14:51:19 +00:00
|
|
|
|
2012-06-26 16:31:19 +00:00
|
|
|
private:
|
|
|
|
|
2012-06-28 17:16:14 +00:00
|
|
|
const ImportSettings& settings;
|
|
|
|
|
2012-06-26 16:31:19 +00:00
|
|
|
ObjectMap objects;
|
|
|
|
const Parser& parser;
|
2012-07-02 14:51:19 +00:00
|
|
|
|
|
|
|
PropertyTemplateMap templates;
|
2012-07-03 14:50:58 +00:00
|
|
|
ConnectionMap src_connections;
|
|
|
|
ConnectionMap dest_connections;
|
2012-07-06 20:46:19 +00:00
|
|
|
|
|
|
|
unsigned int fbxVersion;
|
|
|
|
std::string creator;
|
|
|
|
unsigned int creationTimeStamp[7];
|
|
|
|
|
2012-07-20 22:45:37 +00:00
|
|
|
std::vector<uint64_t> animationStacks;
|
|
|
|
mutable std::vector<const AnimationStack*> animationStacksResolved;
|
2012-06-26 16:31:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|