Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions happly.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

#include <algorithm>
#include <array>
#include <cctype>
#include <fstream>
Expand Down Expand Up @@ -1206,6 +1207,44 @@ class PLYData {
return result;
}

/**
* @brief Common-case helper get mesh vertex UVs
*
* @param vertexElementName The element name to use (default: "vertex")
*
* @return A vector of vertex UVs.
*/
std::vector<std::array<double, 2>> getVertexUV(const std::string& vertexElementName = "vertex") {
bool hasUV = false;
for (std::unique_ptr<Property>& prop : getElement(vertexElementName).properties) {
if (prop->name == "u") {
hasUV = true;
}
}

if(!hasUV) {
return std::vector<std::array<double, 2>>();
}

std::vector<double> uPos = getElement(vertexElementName).getProperty<double>("u");
std::vector<double> vPos = getElement(vertexElementName).getProperty<double>("v");
bool allzeros = std::all_of(uPos.begin(), uPos.end(), [](double i) { return i==0.0f; });
allzeros = allzeros || std::all_of(vPos.begin(), vPos.end(), [](double i) { return i==0.0f; });

if(allzeros) {
return std::vector<std::array<double, 2>>();
}

// else, we have valid UVs
std::vector<std::array<double, 2>> result(uPos.size());
for (size_t i = 0; i < result.size(); i++) {
result[i][0] = uPos[i];
result[i][1] = vPos[i];
}

return result;
}

/**
* @brief Common-case helper get mesh vertex colors
*
Expand Down