|
@@ -48,12 +48,11 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
#include <functional>
|
|
|
|
|
|
-#include "FBXMeshGeometry.h"
|
|
|
#include "FBXDocument.h"
|
|
|
-#include "FBXImporter.h"
|
|
|
-#include "FBXImportSettings.h"
|
|
|
#include "FBXDocumentUtil.h"
|
|
|
-
|
|
|
+#include "FBXImportSettings.h"
|
|
|
+#include "FBXImporter.h"
|
|
|
+#include "FBXMeshGeometry.h"
|
|
|
|
|
|
namespace Assimp {
|
|
|
namespace FBX {
|
|
@@ -61,17 +60,15 @@ namespace FBX {
|
|
|
using namespace Util;
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
-Geometry::Geometry(uint64_t id, const Element& element, const std::string& name, const Document& doc)
|
|
|
- : Object(id, element, name)
|
|
|
- , skin()
|
|
|
-{
|
|
|
- const std::vector<const Connection*>& conns = doc.GetConnectionsByDestinationSequenced(ID(),"Deformer");
|
|
|
- for(const Connection* con : conns) {
|
|
|
- const Skin* const sk = ProcessSimpleConnection<Skin>(*con, false, "Skin -> Geometry", element);
|
|
|
- if(sk) {
|
|
|
+Geometry::Geometry(uint64_t id, const Element &element, const std::string &name, const Document &doc) :
|
|
|
+ Object(id, element, name), skin() {
|
|
|
+ const std::vector<const Connection *> &conns = doc.GetConnectionsByDestinationSequenced(ID(), "Deformer");
|
|
|
+ for (const Connection *con : conns) {
|
|
|
+ const Skin *const sk = ProcessSimpleConnection<Skin>(*con, false, "Skin -> Geometry", element);
|
|
|
+ if (sk) {
|
|
|
skin = sk;
|
|
|
}
|
|
|
- const BlendShape* const bsp = ProcessSimpleConnection<BlendShape>(*con, false, "BlendShape -> Geometry", element);
|
|
|
+ const BlendShape *const bsp = ProcessSimpleConnection<BlendShape>(*con, false, "BlendShape -> Geometry", element);
|
|
|
if (bsp) {
|
|
|
blendShapes.push_back(bsp);
|
|
|
}
|
|
@@ -79,48 +76,46 @@ Geometry::Geometry(uint64_t id, const Element& element, const std::string& name,
|
|
|
}
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
-Geometry::~Geometry()
|
|
|
-{
|
|
|
+Geometry::~Geometry() {
|
|
|
// empty
|
|
|
}
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
-const std::vector<const BlendShape*>& Geometry::GetBlendShapes() const {
|
|
|
+const std::vector<const BlendShape *> &Geometry::GetBlendShapes() const {
|
|
|
return blendShapes;
|
|
|
}
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
-const Skin* Geometry::DeformerSkin() const {
|
|
|
+const Skin *Geometry::DeformerSkin() const {
|
|
|
return skin;
|
|
|
}
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
-MeshGeometry::MeshGeometry(uint64_t id, const Element& element, const std::string& name, const Document& doc)
|
|
|
-: Geometry(id, element,name, doc)
|
|
|
-{
|
|
|
- const Scope* sc = element.Compound();
|
|
|
+MeshGeometry::MeshGeometry(uint64_t id, const Element &element, const std::string &name, const Document &doc) :
|
|
|
+ Geometry(id, element, name, doc) {
|
|
|
+ const Scope *sc = element.Compound();
|
|
|
if (!sc) {
|
|
|
DOMError("failed to read Geometry object (class: Mesh), no data scope found");
|
|
|
}
|
|
|
|
|
|
// must have Mesh elements:
|
|
|
- const Element& Vertices = GetRequiredElement(*sc,"Vertices",&element);
|
|
|
- const Element& PolygonVertexIndex = GetRequiredElement(*sc,"PolygonVertexIndex",&element);
|
|
|
+ const Element &Vertices = GetRequiredElement(*sc, "Vertices", &element);
|
|
|
+ const Element &PolygonVertexIndex = GetRequiredElement(*sc, "PolygonVertexIndex", &element);
|
|
|
|
|
|
// optional Mesh elements:
|
|
|
- const ElementCollection& Layer = sc->GetCollection("Layer");
|
|
|
+ const ElementCollection &Layer = sc->GetCollection("Layer");
|
|
|
|
|
|
std::vector<aiVector3D> tempVerts;
|
|
|
- ParseVectorDataArray(tempVerts,Vertices);
|
|
|
+ ParseVectorDataArray(tempVerts, Vertices);
|
|
|
|
|
|
- if(tempVerts.empty()) {
|
|
|
+ if (tempVerts.empty()) {
|
|
|
FBXImporter::LogWarn("encountered mesh with no vertices");
|
|
|
}
|
|
|
|
|
|
std::vector<int> tempFaces;
|
|
|
- ParseVectorDataArray(tempFaces,PolygonVertexIndex);
|
|
|
+ ParseVectorDataArray(tempFaces, PolygonVertexIndex);
|
|
|
|
|
|
- if(tempFaces.empty()) {
|
|
|
+ if (tempFaces.empty()) {
|
|
|
FBXImporter::LogWarn("encountered mesh with no faces");
|
|
|
}
|
|
|
|
|
@@ -128,7 +123,7 @@ MeshGeometry::MeshGeometry(uint64_t id, const Element& element, const std::strin
|
|
|
m_faces.reserve(tempFaces.size() / 3);
|
|
|
|
|
|
m_mapping_offsets.resize(tempVerts.size());
|
|
|
- m_mapping_counts.resize(tempVerts.size(),0);
|
|
|
+ m_mapping_counts.resize(tempVerts.size(), 0);
|
|
|
m_mappings.resize(tempFaces.size());
|
|
|
|
|
|
const size_t vertex_count = tempVerts.size();
|
|
@@ -136,10 +131,10 @@ MeshGeometry::MeshGeometry(uint64_t id, const Element& element, const std::strin
|
|
|
// generate output vertices, computing an adjacency table to
|
|
|
// preserve the mapping from fbx indices to *this* indexing.
|
|
|
unsigned int count = 0;
|
|
|
- for(int index : tempFaces) {
|
|
|
+ for (int index : tempFaces) {
|
|
|
const int absi = index < 0 ? (-index - 1) : index;
|
|
|
- if(static_cast<size_t>(absi) >= vertex_count) {
|
|
|
- DOMError("polygon vertex index out of range",&PolygonVertexIndex);
|
|
|
+ if (static_cast<size_t>(absi) >= vertex_count) {
|
|
|
+ DOMError("polygon vertex index out of range", &PolygonVertexIndex);
|
|
|
}
|
|
|
|
|
|
m_vertices.push_back(tempVerts[absi]);
|
|
@@ -162,7 +157,7 @@ MeshGeometry::MeshGeometry(uint64_t id, const Element& element, const std::strin
|
|
|
}
|
|
|
|
|
|
cursor = 0;
|
|
|
- for(int index : tempFaces) {
|
|
|
+ for (int index : tempFaces) {
|
|
|
const int absi = index < 0 ? (-index - 1) : index;
|
|
|
m_mappings[m_mapping_offsets[absi] + m_mapping_counts[absi]++] = cursor++;
|
|
|
}
|
|
@@ -172,19 +167,18 @@ MeshGeometry::MeshGeometry(uint64_t id, const Element& element, const std::strin
|
|
|
// if settings.readAllLayers is false:
|
|
|
// * read only the layer with index 0, but warn about any further layers
|
|
|
for (ElementMap::const_iterator it = Layer.first; it != Layer.second; ++it) {
|
|
|
- const TokenList& tokens = (*it).second->Tokens();
|
|
|
+ const TokenList &tokens = (*it).second->Tokens();
|
|
|
|
|
|
- const char* err;
|
|
|
+ const char *err;
|
|
|
const int index = ParseTokenAsInt(*tokens[0], err);
|
|
|
- if(err) {
|
|
|
- DOMError(err,&element);
|
|
|
+ if (err) {
|
|
|
+ DOMError(err, &element);
|
|
|
}
|
|
|
|
|
|
- if(doc.Settings().readAllLayers || index == 0) {
|
|
|
- const Scope& layer = GetRequiredScope(*(*it).second);
|
|
|
+ if (doc.Settings().readAllLayers || index == 0) {
|
|
|
+ const Scope &layer = GetRequiredScope(*(*it).second);
|
|
|
ReadLayer(layer);
|
|
|
- }
|
|
|
- else {
|
|
|
+ } else {
|
|
|
FBXImporter::LogWarn("ignoring additional geometry layers");
|
|
|
}
|
|
|
}
|
|
@@ -196,151 +190,142 @@ MeshGeometry::~MeshGeometry() {
|
|
|
}
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
-const std::vector<aiVector3D>& MeshGeometry::GetVertices() const {
|
|
|
+const std::vector<aiVector3D> &MeshGeometry::GetVertices() const {
|
|
|
return m_vertices;
|
|
|
}
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
-const std::vector<aiVector3D>& MeshGeometry::GetNormals() const {
|
|
|
+const std::vector<aiVector3D> &MeshGeometry::GetNormals() const {
|
|
|
return m_normals;
|
|
|
}
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
-const std::vector<aiVector3D>& MeshGeometry::GetTangents() const {
|
|
|
+const std::vector<aiVector3D> &MeshGeometry::GetTangents() const {
|
|
|
return m_tangents;
|
|
|
}
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
-const std::vector<aiVector3D>& MeshGeometry::GetBinormals() const {
|
|
|
+const std::vector<aiVector3D> &MeshGeometry::GetBinormals() const {
|
|
|
return m_binormals;
|
|
|
}
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
-const std::vector<unsigned int>& MeshGeometry::GetFaceIndexCounts() const {
|
|
|
+const std::vector<unsigned int> &MeshGeometry::GetFaceIndexCounts() const {
|
|
|
return m_faces;
|
|
|
}
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
-const std::vector<aiVector2D>& MeshGeometry::GetTextureCoords( unsigned int index ) const {
|
|
|
+const std::vector<aiVector2D> &MeshGeometry::GetTextureCoords(unsigned int index) const {
|
|
|
static const std::vector<aiVector2D> empty;
|
|
|
- return index >= AI_MAX_NUMBER_OF_TEXTURECOORDS ? empty : m_uvs[ index ];
|
|
|
+ return index >= AI_MAX_NUMBER_OF_TEXTURECOORDS ? empty : m_uvs[index];
|
|
|
}
|
|
|
|
|
|
-std::string MeshGeometry::GetTextureCoordChannelName( unsigned int index ) const {
|
|
|
- return index >= AI_MAX_NUMBER_OF_TEXTURECOORDS ? "" : m_uvNames[ index ];
|
|
|
+std::string MeshGeometry::GetTextureCoordChannelName(unsigned int index) const {
|
|
|
+ return index >= AI_MAX_NUMBER_OF_TEXTURECOORDS ? "" : m_uvNames[index];
|
|
|
}
|
|
|
|
|
|
-const std::vector<aiColor4D>& MeshGeometry::GetVertexColors( unsigned int index ) const {
|
|
|
+const std::vector<aiColor4D> &MeshGeometry::GetVertexColors(unsigned int index) const {
|
|
|
static const std::vector<aiColor4D> empty;
|
|
|
- return index >= AI_MAX_NUMBER_OF_COLOR_SETS ? empty : m_colors[ index ];
|
|
|
+ return index >= AI_MAX_NUMBER_OF_COLOR_SETS ? empty : m_colors[index];
|
|
|
}
|
|
|
|
|
|
-const MatIndexArray& MeshGeometry::GetMaterialIndices() const {
|
|
|
+const MatIndexArray &MeshGeometry::GetMaterialIndices() const {
|
|
|
return m_materials;
|
|
|
}
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
-const unsigned int* MeshGeometry::ToOutputVertexIndex( unsigned int in_index, unsigned int& count ) const {
|
|
|
- if ( in_index >= m_mapping_counts.size() ) {
|
|
|
+const unsigned int *MeshGeometry::ToOutputVertexIndex(unsigned int in_index, unsigned int &count) const {
|
|
|
+ if (in_index >= m_mapping_counts.size()) {
|
|
|
return nullptr;
|
|
|
}
|
|
|
|
|
|
- ai_assert( m_mapping_counts.size() == m_mapping_offsets.size() );
|
|
|
- count = m_mapping_counts[ in_index ];
|
|
|
+ ai_assert(m_mapping_counts.size() == m_mapping_offsets.size());
|
|
|
+ count = m_mapping_counts[in_index];
|
|
|
|
|
|
- ai_assert( m_mapping_offsets[ in_index ] + count <= m_mappings.size() );
|
|
|
+ ai_assert(m_mapping_offsets[in_index] + count <= m_mappings.size());
|
|
|
|
|
|
- return &m_mappings[ m_mapping_offsets[ in_index ] ];
|
|
|
+ return &m_mappings[m_mapping_offsets[in_index]];
|
|
|
}
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
-unsigned int MeshGeometry::FaceForVertexIndex( unsigned int in_index ) const {
|
|
|
- ai_assert( in_index < m_vertices.size() );
|
|
|
+unsigned int MeshGeometry::FaceForVertexIndex(unsigned int in_index) const {
|
|
|
+ ai_assert(in_index < m_vertices.size());
|
|
|
|
|
|
// in the current conversion pattern this will only be needed if
|
|
|
// weights are present, so no need to always pre-compute this table
|
|
|
- if ( m_facesVertexStartIndices.empty() ) {
|
|
|
- m_facesVertexStartIndices.resize( m_faces.size() + 1, 0 );
|
|
|
+ if (m_facesVertexStartIndices.empty()) {
|
|
|
+ m_facesVertexStartIndices.resize(m_faces.size() + 1, 0);
|
|
|
|
|
|
- std::partial_sum( m_faces.begin(), m_faces.end(), m_facesVertexStartIndices.begin() + 1 );
|
|
|
+ std::partial_sum(m_faces.begin(), m_faces.end(), m_facesVertexStartIndices.begin() + 1);
|
|
|
m_facesVertexStartIndices.pop_back();
|
|
|
}
|
|
|
|
|
|
- ai_assert( m_facesVertexStartIndices.size() == m_faces.size() );
|
|
|
+ ai_assert(m_facesVertexStartIndices.size() == m_faces.size());
|
|
|
const std::vector<unsigned int>::iterator it = std::upper_bound(
|
|
|
- m_facesVertexStartIndices.begin(),
|
|
|
- m_facesVertexStartIndices.end(),
|
|
|
- in_index
|
|
|
- );
|
|
|
+ m_facesVertexStartIndices.begin(),
|
|
|
+ m_facesVertexStartIndices.end(),
|
|
|
+ in_index);
|
|
|
|
|
|
- return static_cast< unsigned int >( std::distance( m_facesVertexStartIndices.begin(), it - 1 ) );
|
|
|
+ return static_cast<unsigned int>(std::distance(m_facesVertexStartIndices.begin(), it - 1));
|
|
|
}
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
-void MeshGeometry::ReadLayer(const Scope& layer)
|
|
|
-{
|
|
|
- const ElementCollection& LayerElement = layer.GetCollection("LayerElement");
|
|
|
+void MeshGeometry::ReadLayer(const Scope &layer) {
|
|
|
+ const ElementCollection &LayerElement = layer.GetCollection("LayerElement");
|
|
|
for (ElementMap::const_iterator eit = LayerElement.first; eit != LayerElement.second; ++eit) {
|
|
|
- const Scope& elayer = GetRequiredScope(*(*eit).second);
|
|
|
+ const Scope &elayer = GetRequiredScope(*(*eit).second);
|
|
|
|
|
|
ReadLayerElement(elayer);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
-void MeshGeometry::ReadLayerElement(const Scope& layerElement)
|
|
|
-{
|
|
|
- const Element& Type = GetRequiredElement(layerElement,"Type");
|
|
|
- const Element& TypedIndex = GetRequiredElement(layerElement,"TypedIndex");
|
|
|
+void MeshGeometry::ReadLayerElement(const Scope &layerElement) {
|
|
|
+ const Element &Type = GetRequiredElement(layerElement, "Type");
|
|
|
+ const Element &TypedIndex = GetRequiredElement(layerElement, "TypedIndex");
|
|
|
|
|
|
- const std::string& type = ParseTokenAsString(GetRequiredToken(Type,0));
|
|
|
- const int typedIndex = ParseTokenAsInt(GetRequiredToken(TypedIndex,0));
|
|
|
+ const std::string &type = ParseTokenAsString(GetRequiredToken(Type, 0));
|
|
|
+ const int typedIndex = ParseTokenAsInt(GetRequiredToken(TypedIndex, 0));
|
|
|
|
|
|
- const Scope& top = GetRequiredScope(element);
|
|
|
+ const Scope &top = GetRequiredScope(element);
|
|
|
const ElementCollection candidates = top.GetCollection(type);
|
|
|
|
|
|
for (ElementMap::const_iterator it = candidates.first; it != candidates.second; ++it) {
|
|
|
- const int index = ParseTokenAsInt(GetRequiredToken(*(*it).second,0));
|
|
|
- if(index == typedIndex) {
|
|
|
- ReadVertexData(type,typedIndex,GetRequiredScope(*(*it).second));
|
|
|
+ const int index = ParseTokenAsInt(GetRequiredToken(*(*it).second, 0));
|
|
|
+ if (index == typedIndex) {
|
|
|
+ ReadVertexData(type, typedIndex, GetRequiredScope(*(*it).second));
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
FBXImporter::LogError(Formatter::format("failed to resolve vertex layer element: ")
|
|
|
- << type << ", index: " << typedIndex);
|
|
|
+ << type << ", index: " << typedIndex);
|
|
|
}
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
-void MeshGeometry::ReadVertexData(const std::string& type, int index, const Scope& source)
|
|
|
-{
|
|
|
- const std::string& MappingInformationType = ParseTokenAsString(GetRequiredToken(
|
|
|
- GetRequiredElement(source,"MappingInformationType"),0)
|
|
|
- );
|
|
|
+void MeshGeometry::ReadVertexData(const std::string &type, int index, const Scope &source) {
|
|
|
+ const std::string &MappingInformationType = ParseTokenAsString(GetRequiredToken(
|
|
|
+ GetRequiredElement(source, "MappingInformationType"), 0));
|
|
|
|
|
|
- const std::string& ReferenceInformationType = ParseTokenAsString(GetRequiredToken(
|
|
|
- GetRequiredElement(source,"ReferenceInformationType"),0)
|
|
|
- );
|
|
|
+ const std::string &ReferenceInformationType = ParseTokenAsString(GetRequiredToken(
|
|
|
+ GetRequiredElement(source, "ReferenceInformationType"), 0));
|
|
|
|
|
|
if (type == "LayerElementUV") {
|
|
|
- if(index >= AI_MAX_NUMBER_OF_TEXTURECOORDS) {
|
|
|
+ if (index >= AI_MAX_NUMBER_OF_TEXTURECOORDS) {
|
|
|
FBXImporter::LogError(Formatter::format("ignoring UV layer, maximum number of UV channels exceeded: ")
|
|
|
- << index << " (limit is " << AI_MAX_NUMBER_OF_TEXTURECOORDS << ")" );
|
|
|
+ << index << " (limit is " << AI_MAX_NUMBER_OF_TEXTURECOORDS << ")");
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- const Element* Name = source["Name"];
|
|
|
+ const Element *Name = source["Name"];
|
|
|
m_uvNames[index] = "";
|
|
|
- if(Name) {
|
|
|
- m_uvNames[index] = ParseTokenAsString(GetRequiredToken(*Name,0));
|
|
|
+ if (Name) {
|
|
|
+ m_uvNames[index] = ParseTokenAsString(GetRequiredToken(*Name, 0));
|
|
|
}
|
|
|
|
|
|
- ReadVertexDataUV(m_uvs[index],source,
|
|
|
- MappingInformationType,
|
|
|
- ReferenceInformationType
|
|
|
- );
|
|
|
- }
|
|
|
- else if (type == "LayerElementMaterial") {
|
|
|
+ ReadVertexDataUV(m_uvs[index], source,
|
|
|
+ MappingInformationType,
|
|
|
+ ReferenceInformationType);
|
|
|
+ } else if (type == "LayerElementMaterial") {
|
|
|
if (m_materials.size() > 0) {
|
|
|
FBXImporter::LogError("ignoring additional material layer");
|
|
|
return;
|
|
@@ -348,10 +333,9 @@ void MeshGeometry::ReadVertexData(const std::string& type, int index, const Scop
|
|
|
|
|
|
std::vector<int> temp_materials;
|
|
|
|
|
|
- ReadVertexDataMaterials(temp_materials,source,
|
|
|
- MappingInformationType,
|
|
|
- ReferenceInformationType
|
|
|
- );
|
|
|
+ ReadVertexDataMaterials(temp_materials, source,
|
|
|
+ MappingInformationType,
|
|
|
+ ReferenceInformationType);
|
|
|
|
|
|
// sometimes, there will be only negative entries. Drop the material
|
|
|
// layer in such a case (I guess it means a default material should
|
|
@@ -359,58 +343,50 @@ void MeshGeometry::ReadVertexData(const std::string& type, int index, const Scop
|
|
|
// avoids losing the material if there are more material layers
|
|
|
// coming of which at least one contains actual data (did observe
|
|
|
// that with one test file).
|
|
|
- const size_t count_neg = std::count_if(temp_materials.begin(),temp_materials.end(),[](int n) { return n < 0; });
|
|
|
- if(count_neg == temp_materials.size()) {
|
|
|
+ const size_t count_neg = std::count_if(temp_materials.begin(), temp_materials.end(), [](int n) { return n < 0; });
|
|
|
+ if (count_neg == temp_materials.size()) {
|
|
|
FBXImporter::LogWarn("ignoring dummy material layer (all entries -1)");
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
std::swap(temp_materials, m_materials);
|
|
|
- }
|
|
|
- else if (type == "LayerElementNormal") {
|
|
|
+ } else if (type == "LayerElementNormal") {
|
|
|
if (m_normals.size() > 0) {
|
|
|
FBXImporter::LogError("ignoring additional normal layer");
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- ReadVertexDataNormals(m_normals,source,
|
|
|
- MappingInformationType,
|
|
|
- ReferenceInformationType
|
|
|
- );
|
|
|
- }
|
|
|
- else if (type == "LayerElementTangent") {
|
|
|
+ ReadVertexDataNormals(m_normals, source,
|
|
|
+ MappingInformationType,
|
|
|
+ ReferenceInformationType);
|
|
|
+ } else if (type == "LayerElementTangent") {
|
|
|
if (m_tangents.size() > 0) {
|
|
|
FBXImporter::LogError("ignoring additional tangent layer");
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- ReadVertexDataTangents(m_tangents,source,
|
|
|
- MappingInformationType,
|
|
|
- ReferenceInformationType
|
|
|
- );
|
|
|
- }
|
|
|
- else if (type == "LayerElementBinormal") {
|
|
|
+ ReadVertexDataTangents(m_tangents, source,
|
|
|
+ MappingInformationType,
|
|
|
+ ReferenceInformationType);
|
|
|
+ } else if (type == "LayerElementBinormal") {
|
|
|
if (m_binormals.size() > 0) {
|
|
|
FBXImporter::LogError("ignoring additional binormal layer");
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- ReadVertexDataBinormals(m_binormals,source,
|
|
|
- MappingInformationType,
|
|
|
- ReferenceInformationType
|
|
|
- );
|
|
|
- }
|
|
|
- else if (type == "LayerElementColor") {
|
|
|
- if(index >= AI_MAX_NUMBER_OF_COLOR_SETS) {
|
|
|
+ ReadVertexDataBinormals(m_binormals, source,
|
|
|
+ MappingInformationType,
|
|
|
+ ReferenceInformationType);
|
|
|
+ } else if (type == "LayerElementColor") {
|
|
|
+ if (index >= AI_MAX_NUMBER_OF_COLOR_SETS) {
|
|
|
FBXImporter::LogError(Formatter::format("ignoring vertex color layer, maximum number of color sets exceeded: ")
|
|
|
- << index << " (limit is " << AI_MAX_NUMBER_OF_COLOR_SETS << ")" );
|
|
|
+ << index << " (limit is " << AI_MAX_NUMBER_OF_COLOR_SETS << ")");
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- ReadVertexDataColors(m_colors[index],source,
|
|
|
- MappingInformationType,
|
|
|
- ReferenceInformationType
|
|
|
- );
|
|
|
+ ReadVertexDataColors(m_colors[index], source,
|
|
|
+ MappingInformationType,
|
|
|
+ ReferenceInformationType);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -419,21 +395,20 @@ void MeshGeometry::ReadVertexData(const std::string& type, int index, const Scop
|
|
|
// output is in polygon vertex order. This logic is used for reading normals, UVs, colors,
|
|
|
// tangents ..
|
|
|
template <typename T>
|
|
|
-void ResolveVertexDataArray(std::vector<T>& data_out, const Scope& source,
|
|
|
- const std::string& MappingInformationType,
|
|
|
- const std::string& ReferenceInformationType,
|
|
|
- const char* dataElementName,
|
|
|
- const char* indexDataElementName,
|
|
|
- size_t vertex_count,
|
|
|
- const std::vector<unsigned int>& mapping_counts,
|
|
|
- const std::vector<unsigned int>& mapping_offsets,
|
|
|
- const std::vector<unsigned int>& mappings)
|
|
|
-{
|
|
|
+void ResolveVertexDataArray(std::vector<T> &data_out, const Scope &source,
|
|
|
+ const std::string &MappingInformationType,
|
|
|
+ const std::string &ReferenceInformationType,
|
|
|
+ const char *dataElementName,
|
|
|
+ const char *indexDataElementName,
|
|
|
+ size_t vertex_count,
|
|
|
+ const std::vector<unsigned int> &mapping_counts,
|
|
|
+ const std::vector<unsigned int> &mapping_offsets,
|
|
|
+ const std::vector<unsigned int> &mappings) {
|
|
|
bool isDirect = ReferenceInformationType == "Direct";
|
|
|
bool isIndexToDirect = ReferenceInformationType == "IndexToDirect";
|
|
|
|
|
|
// fall-back to direct data if there is no index data element
|
|
|
- if ( isIndexToDirect && !HasElement( source, indexDataElementName ) ) {
|
|
|
+ if (isIndexToDirect && !HasElement(source, indexDataElementName)) {
|
|
|
isDirect = true;
|
|
|
isIndexToDirect = false;
|
|
|
}
|
|
@@ -461,13 +436,12 @@ void ResolveVertexDataArray(std::vector<T>& data_out, const Scope& source,
|
|
|
data_out[mappings[j]] = tempData[i];
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
- else if (MappingInformationType == "ByVertice" && isIndexToDirect) {
|
|
|
- std::vector<T> tempData;
|
|
|
- ParseVectorDataArray(tempData, GetRequiredElement(source, dataElementName));
|
|
|
+ } else if (MappingInformationType == "ByVertice" && isIndexToDirect) {
|
|
|
+ std::vector<T> tempData;
|
|
|
+ ParseVectorDataArray(tempData, GetRequiredElement(source, dataElementName));
|
|
|
|
|
|
std::vector<int> uvIndices;
|
|
|
- ParseVectorDataArray(uvIndices,GetRequiredElement(source,indexDataElementName));
|
|
|
+ ParseVectorDataArray(uvIndices, GetRequiredElement(source, indexDataElementName));
|
|
|
|
|
|
if (uvIndices.size() != vertex_count) {
|
|
|
FBXImporter::LogError(Formatter::format("length of input data unexpected for ByVertice mapping: ")
|
|
@@ -481,32 +455,29 @@ void ResolveVertexDataArray(std::vector<T>& data_out, const Scope& source,
|
|
|
|
|
|
const unsigned int istart = mapping_offsets[i], iend = istart + mapping_counts[i];
|
|
|
for (unsigned int j = istart; j < iend; ++j) {
|
|
|
- if (static_cast<size_t>(uvIndices[i]) >= tempData.size()) {
|
|
|
- DOMError("index out of range",&GetRequiredElement(source,indexDataElementName));
|
|
|
+ if (static_cast<size_t>(uvIndices[i]) >= tempData.size()) {
|
|
|
+ DOMError("index out of range", &GetRequiredElement(source, indexDataElementName));
|
|
|
}
|
|
|
- data_out[mappings[j]] = tempData[uvIndices[i]];
|
|
|
+ data_out[mappings[j]] = tempData[uvIndices[i]];
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
- else if (MappingInformationType == "ByPolygonVertex" && isDirect) {
|
|
|
- std::vector<T> tempData;
|
|
|
- ParseVectorDataArray(tempData, GetRequiredElement(source, dataElementName));
|
|
|
+ } else if (MappingInformationType == "ByPolygonVertex" && isDirect) {
|
|
|
+ std::vector<T> tempData;
|
|
|
+ ParseVectorDataArray(tempData, GetRequiredElement(source, dataElementName));
|
|
|
|
|
|
- if (tempData.size() != vertex_count) {
|
|
|
+ if (tempData.size() != vertex_count) {
|
|
|
FBXImporter::LogError(Formatter::format("length of input data unexpected for ByPolygon mapping: ")
|
|
|
- << tempData.size() << ", expected " << vertex_count
|
|
|
- );
|
|
|
+ << tempData.size() << ", expected " << vertex_count);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- data_out.swap(tempData);
|
|
|
- }
|
|
|
- else if (MappingInformationType == "ByPolygonVertex" && isIndexToDirect) {
|
|
|
- std::vector<T> tempData;
|
|
|
- ParseVectorDataArray(tempData, GetRequiredElement(source, dataElementName));
|
|
|
+ data_out.swap(tempData);
|
|
|
+ } else if (MappingInformationType == "ByPolygonVertex" && isIndexToDirect) {
|
|
|
+ std::vector<T> tempData;
|
|
|
+ ParseVectorDataArray(tempData, GetRequiredElement(source, dataElementName));
|
|
|
|
|
|
std::vector<int> uvIndices;
|
|
|
- ParseVectorDataArray(uvIndices,GetRequiredElement(source,indexDataElementName));
|
|
|
+ ParseVectorDataArray(uvIndices, GetRequiredElement(source, indexDataElementName));
|
|
|
|
|
|
if (uvIndices.size() != vertex_count) {
|
|
|
FBXImporter::LogError(Formatter::format("length of input data unexpected for ByPolygonVertex mapping: ")
|
|
@@ -518,120 +489,111 @@ void ResolveVertexDataArray(std::vector<T>& data_out, const Scope& source,
|
|
|
|
|
|
const T empty;
|
|
|
unsigned int next = 0;
|
|
|
- for(int i : uvIndices) {
|
|
|
- if ( -1 == i ) {
|
|
|
- data_out[ next++ ] = empty;
|
|
|
+ for (int i : uvIndices) {
|
|
|
+ if (-1 == i) {
|
|
|
+ data_out[next++] = empty;
|
|
|
continue;
|
|
|
}
|
|
|
if (static_cast<size_t>(i) >= tempData.size()) {
|
|
|
- DOMError("index out of range",&GetRequiredElement(source,indexDataElementName));
|
|
|
+ DOMError("index out of range", &GetRequiredElement(source, indexDataElementName));
|
|
|
}
|
|
|
|
|
|
- data_out[next++] = tempData[i];
|
|
|
+ data_out[next++] = tempData[i];
|
|
|
}
|
|
|
- }
|
|
|
- else {
|
|
|
+ } else {
|
|
|
FBXImporter::LogError(Formatter::format("ignoring vertex data channel, access type not implemented: ")
|
|
|
- << MappingInformationType << "," << ReferenceInformationType);
|
|
|
+ << MappingInformationType << "," << ReferenceInformationType);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
-void MeshGeometry::ReadVertexDataNormals(std::vector<aiVector3D>& normals_out, const Scope& source,
|
|
|
- const std::string& MappingInformationType,
|
|
|
- const std::string& ReferenceInformationType)
|
|
|
-{
|
|
|
- ResolveVertexDataArray(normals_out,source,MappingInformationType,ReferenceInformationType,
|
|
|
- "Normals",
|
|
|
- "NormalsIndex",
|
|
|
- m_vertices.size(),
|
|
|
- m_mapping_counts,
|
|
|
- m_mapping_offsets,
|
|
|
- m_mappings);
|
|
|
+void MeshGeometry::ReadVertexDataNormals(std::vector<aiVector3D> &normals_out, const Scope &source,
|
|
|
+ const std::string &MappingInformationType,
|
|
|
+ const std::string &ReferenceInformationType) {
|
|
|
+ ResolveVertexDataArray(normals_out, source, MappingInformationType, ReferenceInformationType,
|
|
|
+ "Normals",
|
|
|
+ "NormalsIndex",
|
|
|
+ m_vertices.size(),
|
|
|
+ m_mapping_counts,
|
|
|
+ m_mapping_offsets,
|
|
|
+ m_mappings);
|
|
|
}
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
-void MeshGeometry::ReadVertexDataUV(std::vector<aiVector2D>& uv_out, const Scope& source,
|
|
|
- const std::string& MappingInformationType,
|
|
|
- const std::string& ReferenceInformationType)
|
|
|
-{
|
|
|
- ResolveVertexDataArray(uv_out,source,MappingInformationType,ReferenceInformationType,
|
|
|
- "UV",
|
|
|
- "UVIndex",
|
|
|
- m_vertices.size(),
|
|
|
- m_mapping_counts,
|
|
|
- m_mapping_offsets,
|
|
|
- m_mappings);
|
|
|
+void MeshGeometry::ReadVertexDataUV(std::vector<aiVector2D> &uv_out, const Scope &source,
|
|
|
+ const std::string &MappingInformationType,
|
|
|
+ const std::string &ReferenceInformationType) {
|
|
|
+ ResolveVertexDataArray(uv_out, source, MappingInformationType, ReferenceInformationType,
|
|
|
+ "UV",
|
|
|
+ "UVIndex",
|
|
|
+ m_vertices.size(),
|
|
|
+ m_mapping_counts,
|
|
|
+ m_mapping_offsets,
|
|
|
+ m_mappings);
|
|
|
}
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
-void MeshGeometry::ReadVertexDataColors(std::vector<aiColor4D>& colors_out, const Scope& source,
|
|
|
- const std::string& MappingInformationType,
|
|
|
- const std::string& ReferenceInformationType)
|
|
|
-{
|
|
|
- ResolveVertexDataArray(colors_out,source,MappingInformationType,ReferenceInformationType,
|
|
|
- "Colors",
|
|
|
- "ColorIndex",
|
|
|
- m_vertices.size(),
|
|
|
- m_mapping_counts,
|
|
|
- m_mapping_offsets,
|
|
|
- m_mappings);
|
|
|
+void MeshGeometry::ReadVertexDataColors(std::vector<aiColor4D> &colors_out, const Scope &source,
|
|
|
+ const std::string &MappingInformationType,
|
|
|
+ const std::string &ReferenceInformationType) {
|
|
|
+ ResolveVertexDataArray(colors_out, source, MappingInformationType, ReferenceInformationType,
|
|
|
+ "Colors",
|
|
|
+ "ColorIndex",
|
|
|
+ m_vertices.size(),
|
|
|
+ m_mapping_counts,
|
|
|
+ m_mapping_offsets,
|
|
|
+ m_mappings);
|
|
|
}
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
static const char *TangentIndexToken = "TangentIndex";
|
|
|
static const char *TangentsIndexToken = "TangentsIndex";
|
|
|
|
|
|
-void MeshGeometry::ReadVertexDataTangents(std::vector<aiVector3D>& tangents_out, const Scope& source,
|
|
|
- const std::string& MappingInformationType,
|
|
|
- const std::string& ReferenceInformationType)
|
|
|
-{
|
|
|
- const char * str = source.Elements().count( "Tangents" ) > 0 ? "Tangents" : "Tangent";
|
|
|
- const char * strIdx = source.Elements().count( "Tangents" ) > 0 ? TangentsIndexToken : TangentIndexToken;
|
|
|
- ResolveVertexDataArray(tangents_out,source,MappingInformationType,ReferenceInformationType,
|
|
|
- str,
|
|
|
- strIdx,
|
|
|
- m_vertices.size(),
|
|
|
- m_mapping_counts,
|
|
|
- m_mapping_offsets,
|
|
|
- m_mappings);
|
|
|
+void MeshGeometry::ReadVertexDataTangents(std::vector<aiVector3D> &tangents_out, const Scope &source,
|
|
|
+ const std::string &MappingInformationType,
|
|
|
+ const std::string &ReferenceInformationType) {
|
|
|
+ const char *str = source.Elements().count("Tangents") > 0 ? "Tangents" : "Tangent";
|
|
|
+ const char *strIdx = source.Elements().count("Tangents") > 0 ? TangentsIndexToken : TangentIndexToken;
|
|
|
+ ResolveVertexDataArray(tangents_out, source, MappingInformationType, ReferenceInformationType,
|
|
|
+ str,
|
|
|
+ strIdx,
|
|
|
+ m_vertices.size(),
|
|
|
+ m_mapping_counts,
|
|
|
+ m_mapping_offsets,
|
|
|
+ m_mappings);
|
|
|
}
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
static const std::string BinormalIndexToken = "BinormalIndex";
|
|
|
static const std::string BinormalsIndexToken = "BinormalsIndex";
|
|
|
|
|
|
-void MeshGeometry::ReadVertexDataBinormals(std::vector<aiVector3D>& binormals_out, const Scope& source,
|
|
|
- const std::string& MappingInformationType,
|
|
|
- const std::string& ReferenceInformationType)
|
|
|
-{
|
|
|
- const char * str = source.Elements().count( "Binormals" ) > 0 ? "Binormals" : "Binormal";
|
|
|
- const char * strIdx = source.Elements().count( "Binormals" ) > 0 ? BinormalsIndexToken.c_str() : BinormalIndexToken.c_str();
|
|
|
- ResolveVertexDataArray(binormals_out,source,MappingInformationType,ReferenceInformationType,
|
|
|
- str,
|
|
|
- strIdx,
|
|
|
- m_vertices.size(),
|
|
|
- m_mapping_counts,
|
|
|
- m_mapping_offsets,
|
|
|
- m_mappings);
|
|
|
+void MeshGeometry::ReadVertexDataBinormals(std::vector<aiVector3D> &binormals_out, const Scope &source,
|
|
|
+ const std::string &MappingInformationType,
|
|
|
+ const std::string &ReferenceInformationType) {
|
|
|
+ const char *str = source.Elements().count("Binormals") > 0 ? "Binormals" : "Binormal";
|
|
|
+ const char *strIdx = source.Elements().count("Binormals") > 0 ? BinormalsIndexToken.c_str() : BinormalIndexToken.c_str();
|
|
|
+ ResolveVertexDataArray(binormals_out, source, MappingInformationType, ReferenceInformationType,
|
|
|
+ str,
|
|
|
+ strIdx,
|
|
|
+ m_vertices.size(),
|
|
|
+ m_mapping_counts,
|
|
|
+ m_mapping_offsets,
|
|
|
+ m_mappings);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
-void MeshGeometry::ReadVertexDataMaterials(std::vector<int>& materials_out, const Scope& source,
|
|
|
- const std::string& MappingInformationType,
|
|
|
- const std::string& ReferenceInformationType)
|
|
|
-{
|
|
|
+void MeshGeometry::ReadVertexDataMaterials(std::vector<int> &materials_out, const Scope &source,
|
|
|
+ const std::string &MappingInformationType,
|
|
|
+ const std::string &ReferenceInformationType) {
|
|
|
const size_t face_count = m_faces.size();
|
|
|
- if( 0 == face_count )
|
|
|
- {
|
|
|
+ if (0 == face_count) {
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// materials are handled separately. First of all, they are assigned per-face
|
|
|
// and not per polyvert. Secondly, ReferenceInformationType=IndexToDirect
|
|
|
// has a slightly different meaning for materials.
|
|
|
- ParseVectorDataArray(materials_out,GetRequiredElement(source,"Materials"));
|
|
|
+ ParseVectorDataArray(materials_out, GetRequiredElement(source, "Materials"));
|
|
|
|
|
|
if (MappingInformationType == "AllSame") {
|
|
|
// easy - same material for all faces
|
|
@@ -648,27 +610,26 @@ void MeshGeometry::ReadVertexDataMaterials(std::vector<int>& materials_out, cons
|
|
|
} else if (MappingInformationType == "ByPolygon" && ReferenceInformationType == "IndexToDirect") {
|
|
|
materials_out.resize(face_count);
|
|
|
|
|
|
- if(materials_out.size() != face_count) {
|
|
|
+ if (materials_out.size() != face_count) {
|
|
|
FBXImporter::LogError(Formatter::format("length of input data unexpected for ByPolygon mapping: ")
|
|
|
- << materials_out.size() << ", expected " << face_count
|
|
|
- );
|
|
|
+ << materials_out.size() << ", expected " << face_count);
|
|
|
return;
|
|
|
}
|
|
|
} else {
|
|
|
FBXImporter::LogError(Formatter::format("ignoring material assignments, access type not implemented: ")
|
|
|
- << MappingInformationType << "," << ReferenceInformationType);
|
|
|
+ << MappingInformationType << "," << ReferenceInformationType);
|
|
|
}
|
|
|
}
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
-ShapeGeometry::ShapeGeometry(uint64_t id, const Element& element, const std::string& name, const Document& doc)
|
|
|
-: Geometry(id, element, name, doc) {
|
|
|
+ShapeGeometry::ShapeGeometry(uint64_t id, const Element &element, const std::string &name, const Document &doc) :
|
|
|
+ Geometry(id, element, name, doc) {
|
|
|
const Scope *sc = element.Compound();
|
|
|
if (nullptr == sc) {
|
|
|
DOMError("failed to read Geometry object (class: Shape), no data scope found");
|
|
|
}
|
|
|
- const Element& Indexes = GetRequiredElement(*sc, "Indexes", &element);
|
|
|
- const Element& Normals = GetRequiredElement(*sc, "Normals", &element);
|
|
|
- const Element& Vertices = GetRequiredElement(*sc, "Vertices", &element);
|
|
|
+ const Element &Indexes = GetRequiredElement(*sc, "Indexes", &element);
|
|
|
+ const Element &Normals = GetRequiredElement(*sc, "Normals", &element);
|
|
|
+ const Element &Vertices = GetRequiredElement(*sc, "Vertices", &element);
|
|
|
ParseVectorDataArray(m_indices, Indexes);
|
|
|
ParseVectorDataArray(m_vertices, Vertices);
|
|
|
ParseVectorDataArray(m_normals, Normals);
|
|
@@ -679,27 +640,26 @@ ShapeGeometry::~ShapeGeometry() {
|
|
|
// empty
|
|
|
}
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
-const std::vector<aiVector3D>& ShapeGeometry::GetVertices() const {
|
|
|
+const std::vector<aiVector3D> &ShapeGeometry::GetVertices() const {
|
|
|
return m_vertices;
|
|
|
}
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
-const std::vector<aiVector3D>& ShapeGeometry::GetNormals() const {
|
|
|
+const std::vector<aiVector3D> &ShapeGeometry::GetNormals() const {
|
|
|
return m_normals;
|
|
|
}
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
-const std::vector<unsigned int>& ShapeGeometry::GetIndices() const {
|
|
|
+const std::vector<unsigned int> &ShapeGeometry::GetIndices() const {
|
|
|
return m_indices;
|
|
|
}
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
-LineGeometry::LineGeometry(uint64_t id, const Element& element, const std::string& name, const Document& doc)
|
|
|
- : Geometry(id, element, name, doc)
|
|
|
-{
|
|
|
- const Scope* sc = element.Compound();
|
|
|
+LineGeometry::LineGeometry(uint64_t id, const Element &element, const std::string &name, const Document &doc) :
|
|
|
+ Geometry(id, element, name, doc) {
|
|
|
+ const Scope *sc = element.Compound();
|
|
|
if (!sc) {
|
|
|
DOMError("failed to read Geometry object (class: Line), no data scope found");
|
|
|
}
|
|
|
- const Element& Points = GetRequiredElement(*sc, "Points", &element);
|
|
|
- const Element& PointsIndex = GetRequiredElement(*sc, "PointsIndex", &element);
|
|
|
+ const Element &Points = GetRequiredElement(*sc, "Points", &element);
|
|
|
+ const Element &PointsIndex = GetRequiredElement(*sc, "PointsIndex", &element);
|
|
|
ParseVectorDataArray(m_vertices, Points);
|
|
|
ParseVectorDataArray(m_indices, PointsIndex);
|
|
|
}
|
|
@@ -709,14 +669,13 @@ LineGeometry::~LineGeometry() {
|
|
|
// empty
|
|
|
}
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
-const std::vector<aiVector3D>& LineGeometry::GetVertices() const {
|
|
|
+const std::vector<aiVector3D> &LineGeometry::GetVertices() const {
|
|
|
return m_vertices;
|
|
|
}
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
-const std::vector<int>& LineGeometry::GetIndices() const {
|
|
|
+const std::vector<int> &LineGeometry::GetIndices() const {
|
|
|
return m_indices;
|
|
|
}
|
|
|
-} // !FBX
|
|
|
-} // !Assimp
|
|
|
+} // namespace FBX
|
|
|
+} // namespace Assimp
|
|
|
#endif
|
|
|
-
|