Skip to content

Mesh IO: Add multi-chart (multi-texture) support to PLY writes #19

Description

@csparker247

Background

The mesh-io work (#14) intentionally shipped PLY texture support as single-chart only. write_obj has a std::vector<std::filesystem::path> overload that groups faces by chart and emits per-chart usemtl material0/material1/... (with a matching .mtl), but write_ply has no vector overload — it emits a single comment TextureFile <path> line.

This was a deliberate scope decision at the time, recorded in conductor/tracks/mesh-io_20260323/spec.md (Out of Scope: "Multi-texture PLY write (no well-supported standard outside MeshLab)") on the grounds that multi-texture PLY has no broadly-supported ecosystem standard.

Note the asymmetry already in place: read_ply already recovers multiple comment TextureFile lines into its texture_paths out-parameter (MeshLab convention, covered by PLYTest.ReadCommentTextureFile_HandCraftedPLY). So PLY can already read multi-chart texture references — it just can't write them.

Proposal

Add a multi-chart write_ply overload mirroring the OBJ one:

void write_ply(
    const std::filesystem::path& path,
    const Mesh<T, Dims, VTraits>& mesh,
    const UVMapT& uvmap,
    const std::vector<std::filesystem::path>& texture_paths);
  • static_assert(traits::has_chart<UVMapT>::value, ...), matching the multi-chart write_obj contract.
  • Emit one comment TextureFile <path> line per texture, in chart-index order, immediately after the format line (the same layout read_ply already parses).
  • Per-wedge UVs continue to go in the face texcoord property as today; charts are distinguished by the chart index on each UV coordinate. Decide how/whether to record per-face chart assignment in the PLY body (e.g. a per-face chart/material_index scalar property) so a written multi-chart PLY round-trips chart indices, not just texture paths.

Acceptance criteria

  • write_ply vector overload exists and static_asserts on traits::has_chart.
  • Writes one comment TextureFile line per chart, in index order.
  • Round-trip test: write a 2-chart mesh, read it back, recover both texture paths and per-corner chart indices.
  • Single-chart behavior and the existing single-path overload are unchanged.
  • Doxygen @notes on write_ply/read_ply that currently say "PLY write is single-texture only" are updated.
  • read_mesh/write_mesh facade dispatches the new overload for .ply.

References

  • Follow-up to Mesh IO: OBJ and PLY read/write #14
  • include/educelab/core/io/MeshIO_PLY.hppwrite_ply Tier 3 (single-path)
  • include/educelab/core/io/MeshIO_OBJ.hpp:724write_obj multi-chart overload (reference implementation)
  • tests/src/TestMeshIO.cppOBJTest.PositionsWithUVs_MultiChart_PerChartUsemtl (reference test)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions