23#ifndef VCL_IO_MESH_PLY_DETAIL_EXTRA_H
24#define VCL_IO_MESH_PLY_DETAIL_EXTRA_H
28#include <vclib/io/image.h>
29#include <vclib/io/mesh/settings.h>
30#include <vclib/io/read.h>
32#include <vclib/mesh.h>
33#include <vclib/space/core.h>
35namespace vcl::detail {
37template<MeshConcept MeshType, LoggerConcept LogType = NullLogger>
39 const PlyHeader& header,
42 const LoadSettings& settings = LoadSettings())
44 if constexpr (HasMaterials<MeshType>) {
45 for (
const std::string& str : header.textureFileNames()) {
48 mat.baseColorTextureDescriptor().path() = str;
49 if (settings.loadTextureImages) {
50 Image img = loadImage(mesh.meshBasePath() + str);
52 log.log(
"Cannot load texture " + str, LogType::WARNING_LOG);
55 mesh.pushTextureImage(str, std::move(img));
58 mesh.pushMaterial(mat);
63template<MeshConcept MeshType, LoggerConcept LogType = NullLogger>
67 const std::string& basePath,
69 const SaveSettings& settings)
71 if constexpr (HasMaterials<MeshType>) {
72 for (uint k = 0;
const Material& mat : mesh.materials()) {
73 header.pushTextureFileName(mat.baseColorTextureDescriptor().path());
74 if (settings.saveTextureImages) {
76 mesh.textureImage(mat.baseColorTextureDescriptor().path());
79 "Cannot save empty texture " +
80 mat.baseColorTextureDescriptor().path(),
81 LogType::WARNING_LOG);
87 basePath + mat.baseColorTextureDescriptor().path());
89 catch (
const std::runtime_error& e) {
90 log.log(e.what(), LogType::WARNING_LOG);
99template<LoggerConcept LogType>
100void readPlyUnknownElement(
102 const PlyHeader& header,
106 log.startProgress(
"Reading unknown elements", el.numberElements);
108 if (header.format() == ply::ASCII) {
109 for (uint i = 0; i < el.numberElements; ++i) {
110 readAndTokenizeNextNonEmptyLine(file);
115 for (uint i = 0; i < el.numberElements; ++i) {
116 for (
const PlyProperty& p : el.properties) {
118 uint s = io::readPrimitiveType<int>(file, p.listSizeType);
119 for (uint i = 0; i < s; ++i)
120 io::readPrimitiveType<int>(file, p.type);
123 io::readPrimitiveType<int>(file, p.type);
133template<MeshConcept MeshType, LoggerConcept LogType = NullLogger>
134void readPlyMaterialIndexPostProcessing(
136 MeshInfo& loadedInfo,
137 const LoadSettings& settings)
139 if constexpr (HasMaterials<MeshType>) {
140 if (mesh.materialsNumber() > 0) {
141 if (loadedInfo.hasPerVertexTexCoord() &&
142 !loadedInfo.hasPerVertexMaterialIndex()) {
143 if constexpr (HasPerVertexMaterialIndex<MeshType>) {
144 if (settings.enableOptionalComponents) {
145 enableIfPerVertexMaterialIndexOptional(mesh);
146 loadedInfo.setPerVertexMaterialIndex();
148 if (loadedInfo.hasPerVertexMaterialIndex()) {
150 v.materialIndex() = 0;
155 if (loadedInfo.hasPerFaceWedgeTexCoords() &&
156 !loadedInfo.hasPerFaceMaterialIndex()) {
157 if constexpr (HasPerFaceMaterialIndex<MeshType>) {
158 if (settings.enableOptionalComponents) {
160 loadedInfo.setPerFaceMaterialIndex();
162 if (loadedInfo.hasPerFaceMaterialIndex()) {
163 for (
auto& f : mesh.
faces()) {
164 f.materialIndex() = 0;
static std::string fileNameWithExtension(const std::string &fullpath)
Get the filename with extension of a file.
Definition file_info.h:240
NullLogger nullLogger
The nullLogger object is an object of type NullLogger that is used as default argument in the functio...
Definition null_logger.h:123
bool enableIfPerFaceMaterialIndexOptional(MeshType &m)
If the input mesh has a FaceContainer, and the Face Element has a MaterialIndex Component,...
Definition face_requirements.h:633
constexpr detail::FacesView faces
A view that allows to iterate overt the Face elements of an object.
Definition face.h:84
constexpr detail::VerticesView vertices
A view that allows to iterate over the Vertex elements of an object.
Definition vertex.h:92