| 169 | |
| 170 | template<typename DracoMesh> |
| 171 | VectorF extract_vertices(std::unique_ptr<DracoMesh>& draco_mesh, size_t& dim) { |
| 172 | const auto num_vertices = draco_mesh->num_points(); |
| 173 | const auto positions = draco_mesh->GetNamedAttribute( |
| 174 | draco::GeometryAttribute::POSITION); |
| 175 | assert(positions->IsValid()); |
| 176 | dim = positions->num_components(); |
| 177 | |
| 178 | VectorF vertices(num_vertices * dim); |
| 179 | if (dim == 2) { |
| 180 | for (size_t i=0; i<num_vertices; i++) { |
| 181 | const auto p = positions->template GetValue<Float, 2>( |
| 182 | draco::AttributeValueIndex(i)); |
| 183 | vertices(i*2 ) = p[0]; |
| 184 | vertices(i*2+1) = p[1]; |
| 185 | } |
| 186 | } else if (dim == 3) { |
| 187 | for (size_t i=0; i<num_vertices; i++) { |
| 188 | const auto p = positions->template GetValue<Float, 3>( |
| 189 | draco::AttributeValueIndex(i)); |
| 190 | vertices(i*3 ) = p[0]; |
| 191 | vertices(i*3+1) = p[1]; |
| 192 | vertices(i*3+2) = p[2]; |
| 193 | } |
| 194 | } else { |
| 195 | throw NotImplementedError("Draco mesh encodes high dimensional data"); |
| 196 | } |
| 197 | return vertices; |
| 198 | } |
| 199 | |
| 200 | template<typename DracoMesh> |
| 201 | VectorI extract_faces(std::unique_ptr<DracoMesh>& draco_mesh) { |