------------------------------------------------------------------------------------------------
| 92 | |
| 93 | // ------------------------------------------------------------------------------------------------ |
| 94 | MeshGeometry::MeshGeometry(uint64_t id, const Element& element, const std::string& name, const Document& doc) |
| 95 | : Geometry(id, element,name, doc) |
| 96 | { |
| 97 | const Scope* sc = element.Compound(); |
| 98 | if (!sc) { |
| 99 | DOMError("failed to read Geometry object (class: Mesh), no data scope found"); |
| 100 | } |
| 101 | |
| 102 | // must have Mesh elements: |
| 103 | const Element& Vertices = GetRequiredElement(*sc,"Vertices",&element); |
| 104 | const Element& PolygonVertexIndex = GetRequiredElement(*sc,"PolygonVertexIndex",&element); |
| 105 | |
| 106 | // optional Mesh elements: |
| 107 | const ElementCollection& Layer = sc->GetCollection("Layer"); |
| 108 | |
| 109 | std::vector<aiVector3D> tempVerts; |
| 110 | ParseVectorDataArray(tempVerts,Vertices); |
| 111 | |
| 112 | if(tempVerts.empty()) { |
| 113 | FBXImporter::LogWarn("encountered mesh with no vertices"); |
| 114 | } |
| 115 | |
| 116 | std::vector<int> tempFaces; |
| 117 | ParseVectorDataArray(tempFaces,PolygonVertexIndex); |
| 118 | |
| 119 | if(tempFaces.empty()) { |
| 120 | FBXImporter::LogWarn("encountered mesh with no faces"); |
| 121 | } |
| 122 | |
| 123 | m_vertices.reserve(tempFaces.size()); |
| 124 | m_faces.reserve(tempFaces.size() / 3); |
| 125 | |
| 126 | m_mapping_offsets.resize(tempVerts.size()); |
| 127 | m_mapping_counts.resize(tempVerts.size(),0); |
| 128 | m_mappings.resize(tempFaces.size()); |
| 129 | |
| 130 | const size_t vertex_count = tempVerts.size(); |
| 131 | |
| 132 | // generate output vertices, computing an adjacency table to |
| 133 | // preserve the mapping from fbx indices to *this* indexing. |
| 134 | unsigned int count = 0; |
| 135 | for(int index : tempFaces) { |
| 136 | const int absi = index < 0 ? (-index - 1) : index; |
| 137 | if(static_cast<size_t>(absi) >= vertex_count) { |
| 138 | DOMError("polygon vertex index out of range",&PolygonVertexIndex); |
| 139 | } |
| 140 | |
| 141 | m_vertices.push_back(tempVerts[absi]); |
| 142 | ++count; |
| 143 | |
| 144 | ++m_mapping_counts[absi]; |
| 145 | |
| 146 | if (index < 0) { |
| 147 | m_faces.push_back(count); |
| 148 | count = 0; |
| 149 | } |
| 150 | } |
| 151 |
nothing calls this directly
no test coverage detected