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>
38void addMaterialsFromHeaderTextures(
39 const PlyHeader& header,
43 if constexpr (HasMaterials<MeshType>) {
44 for (
const std::string& str : header.textureFileNames()) {
47 mat.baseColorTextureDescriptor().path() = str;
48 mesh.pushMaterial(mat);
53template<MeshConcept MeshType, LoggerConcept LogType = NullLogger>
54void addTexturesToHeader(PlyHeader& header,
const MeshType& mesh)
56 if constexpr (HasMaterials<MeshType>) {
57 for (
const Material& mat : mesh.materials()) {
58 header.pushTextureFileName(mat.baseColorTextureDescriptor().path());
63template<LoggerConcept LogType>
64void readPlyUnknownElement(
66 const PlyHeader& header,
70 log.startProgress(
"Reading unknown elements", el.elementCount);
72 if (header.format() == ply::ASCII) {
73 for (uint i = 0; i < el.elementCount; ++i) {
74 readAndTokenizeNextNonEmptyLine(file);
79 for (uint i = 0; i < el.elementCount; ++i) {
80 for (
const PlyProperty& p : el.properties) {
82 uint s = io::readPrimitiveType<int>(file, p.listSizeType);
83 for (uint i = 0; i < s; ++i)
84 io::readPrimitiveType<int>(file, p.type);
87 io::readPrimitiveType<int>(file, p.type);
97template<MeshConcept MeshType, LoggerConcept LogType = NullLogger>
98void readPlyMaterialIndexPostProcessing(
100 MeshInfo& loadedInfo,
101 const LoadSettings& settings)
103 if constexpr (HasMaterials<MeshType>) {
104 if (mesh.materialCount() > 0) {
105 if (loadedInfo.hasPerVertexTexCoord() &&
106 !loadedInfo.hasPerVertexMaterialIndex()) {
107 if constexpr (HasPerVertexMaterialIndex<MeshType>) {
108 if (settings.enableOptionalComponents) {
109 enableIfPerVertexMaterialIndexOptional(mesh);
110 loadedInfo.setPerVertexMaterialIndex();
112 if (loadedInfo.hasPerVertexMaterialIndex()) {
114 v.materialIndex() = 0;
119 if (loadedInfo.hasPerFaceWedgeTexCoords() &&
120 !loadedInfo.hasPerFaceMaterialIndex()) {
121 if constexpr (HasPerFaceMaterialIndex<MeshType>) {
122 if (settings.enableOptionalComponents) {
124 loadedInfo.setPerFaceMaterialIndex();
126 if (loadedInfo.hasPerFaceMaterialIndex()) {
127 for (
auto& f : mesh.
faces()) {
128 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