Just the functional assimp lib rather than the entire assimp repository unnecessarily.

This commit is contained in:
Areloch 2019-02-28 16:37:15 -06:00
parent 0f7641a282
commit e9ea38eda3
1747 changed files with 9012 additions and 925008 deletions

View file

@ -2,8 +2,7 @@
Open Asset Import Library (assimp)
----------------------------------------------------------------------
Copyright (c) 2006-2018, assimp team
Copyright (c) 2006-2017, assimp team
All rights reserved.
@ -44,7 +43,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "OgreBinarySerializer.h"
#include "OgreParsingUtils.h"
#include <assimp/TinyFormatter.h>
#include "TinyFormatter.h"
#include <assimp/DefaultLogger.hpp>
#include <memory>
@ -72,11 +71,11 @@ AI_WONT_RETURN void ThrowAttibuteError(const XmlReader* reader, const std::strin
}
template<>
int32_t OgreXmlSerializer::ReadAttribute<int32_t>(const char *name) const
int32_t OgreXmlSerializer::ReadAttribute<int32_t>(const std::string &name) const
{
if (HasAttribute(name))
if (HasAttribute(name.c_str()))
{
return static_cast<int32_t>(m_reader->getAttributeValueAsInt(name));
return static_cast<int32_t>(m_reader->getAttributeValueAsInt(name.c_str()));
}
else
{
@ -86,9 +85,9 @@ int32_t OgreXmlSerializer::ReadAttribute<int32_t>(const char *name) const
}
template<>
uint32_t OgreXmlSerializer::ReadAttribute<uint32_t>(const char *name) const
uint32_t OgreXmlSerializer::ReadAttribute<uint32_t>(const std::string &name) const
{
if (HasAttribute(name))
if (HasAttribute(name.c_str()))
{
/** @note This is hackish. But we are never expecting unsigned values that go outside the
int32_t range. Just monitor for negative numbers and kill the import. */
@ -110,9 +109,9 @@ uint32_t OgreXmlSerializer::ReadAttribute<uint32_t>(const char *name) const
}
template<>
uint16_t OgreXmlSerializer::ReadAttribute<uint16_t>(const char *name) const
uint16_t OgreXmlSerializer::ReadAttribute<uint16_t>(const std::string &name) const
{
if (HasAttribute(name))
if (HasAttribute(name.c_str()))
{
return static_cast<uint16_t>(ReadAttribute<uint32_t>(name));
}
@ -124,11 +123,11 @@ uint16_t OgreXmlSerializer::ReadAttribute<uint16_t>(const char *name) const
}
template<>
float OgreXmlSerializer::ReadAttribute<float>(const char *name) const
float OgreXmlSerializer::ReadAttribute<float>(const std::string &name) const
{
if (HasAttribute(name))
if (HasAttribute(name.c_str()))
{
return m_reader->getAttributeValueAsFloat(name);
return m_reader->getAttributeValueAsFloat(name.c_str());
}
else
{
@ -138,9 +137,9 @@ float OgreXmlSerializer::ReadAttribute<float>(const char *name) const
}
template<>
std::string OgreXmlSerializer::ReadAttribute<std::string>(const char *name) const
std::string OgreXmlSerializer::ReadAttribute<std::string>(const std::string &name) const
{
const char* value = m_reader->getAttributeValue(name);
const char* value = m_reader->getAttributeValue(name.c_str());
if (value)
{
return std::string(value);
@ -153,7 +152,7 @@ std::string OgreXmlSerializer::ReadAttribute<std::string>(const char *name) cons
}
template<>
bool OgreXmlSerializer::ReadAttribute<bool>(const char *name) const
bool OgreXmlSerializer::ReadAttribute<bool>(const std::string &name) const
{
std::string value = Ogre::ToLower(ReadAttribute<std::string>(name));
if (ASSIMP_stricmp(value, "true") == 0)
@ -171,9 +170,9 @@ bool OgreXmlSerializer::ReadAttribute<bool>(const char *name) const
}
}
bool OgreXmlSerializer::HasAttribute(const char *name) const
bool OgreXmlSerializer::HasAttribute(const std::string &name) const
{
return (m_reader->getAttributeValue(name) != 0);
return (m_reader->getAttributeValue(name.c_str()) != 0);
}
std::string &OgreXmlSerializer::NextNode()
@ -190,7 +189,7 @@ std::string &OgreXmlSerializer::NextNode()
CurrentNodeName(true);
#if (OGRE_XML_SERIALIZER_DEBUG == 1)
ASSIMP_LOG_DEBUG"<" + m_currentNodeName + ">");
DefaultLogger::get()->debug("<" + m_currentNodeName + ">");
#endif
return m_currentNodeName;
}
@ -210,114 +209,115 @@ std::string OgreXmlSerializer::CurrentNodeName(bool forceRead)
std::string &OgreXmlSerializer::SkipCurrentNode()
{
#if (OGRE_XML_SERIALIZER_DEBUG == 1)
ASSIMP_LOG_DEBUG("Skipping node <" + m_currentNodeName + ">");
DefaultLogger::get()->debug("Skipping node <" + m_currentNodeName + ">");
#endif
for(;;) {
if (!m_reader->read()) {
for(;;)
{
if (!m_reader->read())
{
m_currentNodeName = "";
return m_currentNodeName;
}
if ( m_reader->getNodeType() != irr::io::EXN_ELEMENT_END ) {
if (m_reader->getNodeType() != irr::io::EXN_ELEMENT_END)
continue;
} else if ( std::string( m_reader->getNodeName() ) == m_currentNodeName ) {
else if (std::string(m_reader->getNodeName()) == m_currentNodeName)
break;
}
}
return NextNode();
}
// Mesh XML constants
// <mesh>
static const char *nnMesh = "mesh";
static const char *nnSharedGeometry = "sharedgeometry";
static const char *nnSubMeshes = "submeshes";
static const char *nnSubMesh = "submesh";
static const char *nnSubMeshNames = "submeshnames";
static const char *nnSkeletonLink = "skeletonlink";
static const char *nnLOD = "levelofdetail";
static const char *nnExtremes = "extremes";
static const char *nnPoses = "poses";
static const char *nnAnimations = "animations";
const std::string nnMesh = "mesh";
const std::string nnSharedGeometry = "sharedgeometry";
const std::string nnSubMeshes = "submeshes";
const std::string nnSubMesh = "submesh";
const std::string nnSubMeshNames = "submeshnames";
const std::string nnSkeletonLink = "skeletonlink";
const std::string nnLOD = "levelofdetail";
const std::string nnExtremes = "extremes";
const std::string nnPoses = "poses";
const std::string nnAnimations = "animations";
// <submesh>
static const char *nnFaces = "faces";
static const char *nnFace = "face";
static const char *nnGeometry = "geometry";
static const char *nnTextures = "textures";
const std::string nnFaces = "faces";
const std::string nnFace = "face";
const std::string nnGeometry = "geometry";
const std::string nnTextures = "textures";
// <mesh/submesh>
static const char *nnBoneAssignments = "boneassignments";
const std::string nnBoneAssignments = "boneassignments";
// <sharedgeometry/geometry>
static const char *nnVertexBuffer = "vertexbuffer";
const std::string nnVertexBuffer = "vertexbuffer";
// <vertexbuffer>
static const char *nnVertex = "vertex";
static const char *nnPosition = "position";
static const char *nnNormal = "normal";
static const char *nnTangent = "tangent";
static const char *nnBinormal = "binormal";
static const char *nnTexCoord = "texcoord";
static const char *nnColorDiffuse = "colour_diffuse";
static const char *nnColorSpecular = "colour_specular";
const std::string nnVertex = "vertex";
const std::string nnPosition = "position";
const std::string nnNormal = "normal";
const std::string nnTangent = "tangent";
const std::string nnBinormal = "binormal";
const std::string nnTexCoord = "texcoord";
const std::string nnColorDiffuse = "colour_diffuse";
const std::string nnColorSpecular = "colour_specular";
// <boneassignments>
static const char *nnVertexBoneAssignment = "vertexboneassignment";
const std::string nnVertexBoneAssignment = "vertexboneassignment";
// Skeleton XML constants
// <skeleton>
static const char *nnSkeleton = "skeleton";
static const char *nnBones = "bones";
static const char *nnBoneHierarchy = "bonehierarchy";
static const char *nnAnimationLinks = "animationlinks";
const std::string nnSkeleton = "skeleton";
const std::string nnBones = "bones";
const std::string nnBoneHierarchy = "bonehierarchy";
const std::string nnAnimationLinks = "animationlinks";
// <bones>
static const char *nnBone = "bone";
static const char *nnRotation = "rotation";
static const char *nnAxis = "axis";
static const char *nnScale = "scale";
const std::string nnBone = "bone";
const std::string nnRotation = "rotation";
const std::string nnAxis = "axis";
const std::string nnScale = "scale";
// <bonehierarchy>
static const char *nnBoneParent = "boneparent";
const std::string nnBoneParent = "boneparent";
// <animations>
static const char *nnAnimation = "animation";
static const char *nnTracks = "tracks";
const std::string nnAnimation = "animation";
const std::string nnTracks = "tracks";
// <tracks>
static const char *nnTrack = "track";
static const char *nnKeyFrames = "keyframes";
static const char *nnKeyFrame = "keyframe";
static const char *nnTranslate = "translate";
static const char *nnRotate = "rotate";
const std::string nnTrack = "track";
const std::string nnKeyFrames = "keyframes";
const std::string nnKeyFrame = "keyframe";
const std::string nnTranslate = "translate";
const std::string nnRotate = "rotate";
// Common XML constants
static const char *anX = "x";
static const char *anY = "y";
static const char *anZ = "z";
const std::string anX = "x";
const std::string anY = "y";
const std::string anZ = "z";
// Mesh
MeshXml *OgreXmlSerializer::ImportMesh(XmlReader *reader) {
MeshXml *OgreXmlSerializer::ImportMesh(XmlReader *reader)
{
OgreXmlSerializer serializer(reader);
MeshXml *mesh = new MeshXml();
serializer.ReadMesh(mesh);
return mesh;
}
void OgreXmlSerializer::ReadMesh(MeshXml *mesh) {
void OgreXmlSerializer::ReadMesh(MeshXml *mesh)
{
if (NextNode() != nnMesh) {
throw DeadlyImportError("Root node is <" + m_currentNodeName + "> expecting <mesh>");
}
ASSIMP_LOG_DEBUG("Reading Mesh");
DefaultLogger::get()->debug("Reading Mesh");
NextNode();
@ -351,7 +351,7 @@ void OgreXmlSerializer::ReadMesh(MeshXml *mesh) {
else if (m_currentNodeName == nnSkeletonLink)
{
mesh->skeletonRef = ReadAttribute<std::string>("name");
ASSIMP_LOG_DEBUG_F("Read skeleton link ", mesh->skeletonRef);
DefaultLogger::get()->debug("Read skeleton link " + mesh->skeletonRef);
NextNode();
}
// Assimp incompatible/ignored nodes
@ -363,7 +363,7 @@ void OgreXmlSerializer::ReadMesh(MeshXml *mesh) {
void OgreXmlSerializer::ReadGeometry(VertexDataXml *dest)
{
dest->count = ReadAttribute<uint32_t>("vertexcount");
ASSIMP_LOG_DEBUG_F( " - Reading geometry of ", dest->count, " vertices");
DefaultLogger::get()->debug(Formatter::format() << " - Reading geometry of " << dest->count << " vertices");
NextNode();
while(m_currentNodeName == nnVertexBuffer) {
@ -385,22 +385,22 @@ void OgreXmlSerializer::ReadGeometryVertexBuffer(VertexDataXml *dest)
if (positions)
{
ASSIMP_LOG_DEBUG(" - Contains positions");
DefaultLogger::get()->debug(" - Contains positions");
dest->positions.reserve(dest->count);
}
if (normals)
{
ASSIMP_LOG_DEBUG(" - Contains normals");
DefaultLogger::get()->debug(" - Contains normals");
dest->normals.reserve(dest->count);
}
if (tangents)
{
ASSIMP_LOG_DEBUG(" - Contains tangents");
DefaultLogger::get()->debug(" - Contains tangents");
dest->tangents.reserve(dest->count);
}
if (uvs > 0)
{
ASSIMP_LOG_DEBUG_F( " - Contains ", uvs, " texture coords");
DefaultLogger::get()->debug(Formatter::format() << " - Contains " << uvs << " texture coords");
dest->uvs.resize(uvs);
for(size_t i=0, len=dest->uvs.size(); i<len; ++i) {
dest->uvs[i].reserve(dest->count);
@ -508,7 +508,7 @@ void OgreXmlSerializer::ReadGeometryVertexBuffer(VertexDataXml *dest)
}
}
if (warn) {
ASSIMP_LOG_WARN_F("Vertex buffer attribute read not implemented for element: ", m_currentNodeName);
DefaultLogger::get()->warn("Vertex buffer attribute read not implemented for element: " + m_currentNodeName);
}
}
@ -537,13 +537,13 @@ void OgreXmlSerializer::ReadGeometryVertexBuffer(VertexDataXml *dest)
void OgreXmlSerializer::ReadSubMesh(MeshXml *mesh)
{
static const char *anMaterial = "material";
static const char *anUseSharedVertices = "usesharedvertices";
static const char *anCount = "count";
static const char *anV1 = "v1";
static const char *anV2 = "v2";
static const char *anV3 = "v3";
static const char *anV4 = "v4";
static const std::string anMaterial = "material";
static const std::string anUseSharedVertices = "usesharedvertices";
static const std::string anCount = "count";
static const std::string anV1 = "v1";
static const std::string anV2 = "v2";
static const std::string anV3 = "v3";
static const std::string anV4 = "v4";
SubMeshXml* submesh = new SubMeshXml();
@ -554,9 +554,9 @@ void OgreXmlSerializer::ReadSubMesh(MeshXml *mesh)
submesh->usesSharedVertexData = ReadAttribute<bool>(anUseSharedVertices);
}
ASSIMP_LOG_DEBUG_F( "Reading SubMesh ", mesh->subMeshes.size());
ASSIMP_LOG_DEBUG_F( " - Material: '", submesh->materialRef, "'");
ASSIMP_LOG_DEBUG_F( " - Uses shared geometry: ", (submesh->usesSharedVertexData ? "true" : "false"));
DefaultLogger::get()->debug(Formatter::format() << "Reading SubMesh " << mesh->subMeshes.size());
DefaultLogger::get()->debug(Formatter::format() << " - Material: '" << submesh->materialRef << "'");
DefaultLogger::get()->debug(Formatter::format() << " - Uses shared geometry: " << (submesh->usesSharedVertexData ? "true" : "false"));
// TODO: maybe we have always just 1 faces and 1 geometry and always in this order. this loop will only work correct, when the order
// of faces and geometry changed, and not if we have more than one of one
@ -587,7 +587,7 @@ void OgreXmlSerializer::ReadSubMesh(MeshXml *mesh)
/// @todo Support quads if Ogre even supports them in XML (I'm not sure but I doubt it)
if (!quadWarned && HasAttribute(anV4)) {
ASSIMP_LOG_WARN("Submesh <face> has quads with <v4>, only triangles are supported at the moment!");
DefaultLogger::get()->warn("Submesh <face> has quads with <v4>, only triangles are supported at the moment!");
quadWarned = true;
}
@ -597,25 +597,31 @@ void OgreXmlSerializer::ReadSubMesh(MeshXml *mesh)
NextNode();
}
if (submesh->indexData->faces.size() == submesh->indexData->faceCount) {
ASSIMP_LOG_DEBUG_F( " - Faces ", submesh->indexData->faceCount);
} else {
if (submesh->indexData->faces.size() == submesh->indexData->faceCount)
{
DefaultLogger::get()->debug(Formatter::format() << " - Faces " << submesh->indexData->faceCount);
}
else
{
throw DeadlyImportError(Formatter::format() << "Read only " << submesh->indexData->faces.size() << " faces when should have read " << submesh->indexData->faceCount);
}
} else if (m_currentNodeName == nnGeometry) {
}
else if (m_currentNodeName == nnGeometry)
{
if (submesh->usesSharedVertexData) {
throw DeadlyImportError("Found <geometry> in <submesh> when use shared geometry is true. Invalid mesh file.");
}
submesh->vertexData = new VertexDataXml();
ReadGeometry(submesh->vertexData);
} else if (m_currentNodeName == nnBoneAssignments) {
}
else if (m_currentNodeName == nnBoneAssignments)
{
ReadBoneAssignments(submesh->vertexData);
}
// Assimp incompatible/ignored nodes
else {
else
SkipCurrentNode();
}
}
submesh->index = static_cast<unsigned int>(mesh->subMeshes.size());
@ -628,9 +634,9 @@ void OgreXmlSerializer::ReadBoneAssignments(VertexDataXml *dest)
throw DeadlyImportError("Cannot read bone assignments, vertex data is null.");
}
static const char *anVertexIndex = "vertexindex";
static const char *anBoneIndex = "boneindex";
static const char *anWeight = "weight";
static const std::string anVertexIndex = "vertexindex";
static const std::string anBoneIndex = "boneindex";
static const std::string anWeight = "weight";
std::set<uint32_t> influencedVertices;
@ -670,7 +676,7 @@ void OgreXmlSerializer::ReadBoneAssignments(VertexDataXml *dest)
}
}
ASSIMP_LOG_DEBUG_F( " - ", dest->boneAssignments.size(), " bone assignments");
DefaultLogger::get()->debug(Formatter::format() << " - " << dest->boneAssignments.size() << " bone assignments");
}
// Skeleton
@ -725,13 +731,13 @@ XmlReaderPtr OgreXmlSerializer::OpenReader(Assimp::IOSystem *pIOHandler, const s
{
if (!EndsWith(filename, ".skeleton.xml", false))
{
ASSIMP_LOG_ERROR_F("Imported Mesh is referencing to unsupported '", filename, "' skeleton file.");
DefaultLogger::get()->error("Imported Mesh is referencing to unsupported '" + filename + "' skeleton file.");
return XmlReaderPtr();
}
if (!pIOHandler->Exists(filename))
{
ASSIMP_LOG_ERROR_F("Failed to find skeleton file '", filename, "' that is referenced by imported Mesh.");
DefaultLogger::get()->error("Failed to find skeleton file '" + filename + "' that is referenced by imported Mesh.");
return XmlReaderPtr();
}
@ -754,7 +760,7 @@ void OgreXmlSerializer::ReadSkeleton(Skeleton *skeleton)
throw DeadlyImportError("Root node is <" + m_currentNodeName + "> expecting <skeleton>");
}
ASSIMP_LOG_DEBUG("Reading Skeleton");
DefaultLogger::get()->debug("Reading Skeleton");
// Optional blend mode from root node
if (HasAttribute("blendmode")) {
@ -787,7 +793,7 @@ void OgreXmlSerializer::ReadAnimations(Skeleton *skeleton)
throw DeadlyImportError("Cannot read <animations> for a Skeleton without bones");
}
ASSIMP_LOG_DEBUG(" - Animations");
DefaultLogger::get()->debug(" - Animations");
NextNode();
while(m_currentNodeName == nnAnimation)
@ -803,7 +809,7 @@ void OgreXmlSerializer::ReadAnimations(Skeleton *skeleton)
ReadAnimationTracks(anim);
skeleton->animations.push_back(anim);
ASSIMP_LOG_DEBUG_F( " ", anim->name, " (", anim->length, " sec, ", anim->tracks.size(), " tracks)");
DefaultLogger::get()->debug(Formatter::format() << " " << anim->name << " (" << anim->length << " sec, " << anim->tracks.size() << " tracks)");
}
}
@ -861,7 +867,7 @@ void OgreXmlSerializer::ReadAnimationKeyFrames(Animation *anim, VertexAnimationT
{
axis.x = 1.0f;
if (angle != 0) {
ASSIMP_LOG_WARN_F("Found invalid a key frame with a zero rotation axis in animation: ", anim->name);
DefaultLogger::get()->warn("Found invalid a key frame with a zero rotation axis in animation: " + anim->name);
}
}
keyframe.rotation = aiQuaternion(axis, angle);
@ -909,17 +915,14 @@ void OgreXmlSerializer::ReadBoneHierarchy(Skeleton *skeleton)
}
}
static bool BoneCompare(Bone *a, Bone *b)
bool BoneCompare(Bone *a, Bone *b)
{
ai_assert( nullptr != a );
ai_assert( nullptr != b );
return (a->id < b->id);
}
void OgreXmlSerializer::ReadBones(Skeleton *skeleton)
{
ASSIMP_LOG_DEBUG(" - Bones");
DefaultLogger::get()->debug(" - Bones");
NextNode();
while(m_currentNodeName == nnBone)
@ -988,7 +991,7 @@ void OgreXmlSerializer::ReadBones(Skeleton *skeleton)
for (size_t i=0, len=skeleton->bones.size(); i<len; ++i)
{
Bone *b = skeleton->bones[i];
ASSIMP_LOG_DEBUG_F( " ", b->id, " ", b->name);
DefaultLogger::get()->debug(Formatter::format() << " " << b->id << " " << b->name);
if (b->id != static_cast<uint16_t>(i)) {
throw DeadlyImportError(Formatter::format() << "Bone ids are not in sequence starting from 0. Missing index " << i);