@@ -400,66 +400,6 @@ void save_mesh_ply(std::string filename,
400400 ply_type_f = tinyply::Type::FLOAT64;
401401 }
402402
403- if (has_w_texcoords) {
404- plyf.add_properties_to_element (
405- " face" , { " texcoords" }, ply_type_f, num_faces,
406- reinterpret_cast <std::uint8_t *>(w_texcoords.mutable_data ()), tinyply::Type::UINT8, 6 );
407- }
408- if (has_w_texids) {
409- plyf.add_properties_to_element (
410- " face" , { " texnumber" }, ply_type_i, num_faces,
411- reinterpret_cast <std::uint8_t *>(w_texcoords.mutable_data ()), tinyply::Type::INVALID, 0 );
412- }
413-
414-
415- if (has_f_vertex_ids) {
416- plyf.add_properties_to_element (
417- " face" , { " vertex_indices" }, ply_type_i, num_faces,
418- reinterpret_cast <std::uint8_t *>(f_vertex_ids.mutable_data ()), tinyply::Type::UINT8, 3 );
419- }
420- if (has_f_normals) {
421- plyf.add_properties_to_element (
422- " face" , { " nx" , " ny" , " z" }, ply_type_f, num_faces,
423- reinterpret_cast <std::uint8_t *>(f_normals.mutable_data ()), tinyply::Type::INVALID, 0 );
424- }
425- if (has_f_colors) {
426- plyf.add_properties_to_element (
427- " face" , { " red" , " green" , " blue" , " alpha" }, ply_type_f, num_faces,
428- reinterpret_cast <std::uint8_t *>(f_colors.mutable_data ()), tinyply::Type::INVALID, 0 );
429- }
430- if (has_f_quality) {
431- plyf.add_properties_to_element (
432- " face" , { " quality" }, ply_type_f, num_faces,
433- reinterpret_cast <std::uint8_t *>(f_quality.mutable_data ()), tinyply::Type::INVALID, 0 );
434- }
435- if (has_f_flags) {
436- plyf.add_properties_to_element (
437- " face" , { " flags" }, ply_type_i, num_faces,
438- reinterpret_cast <std::uint8_t *>(f_flags.mutable_data ()), tinyply::Type::INVALID, 0 );
439- }
440- for (auto kv = custom_f_attribs.begin (); kv != custom_f_attribs.end (); kv++) {
441- pybind11::str key = (pybind11::str) kv->first ;
442- pybind11::array value = pybind11::array::ensure (kv->second );
443- if (value.shape (0 ) != num_faces) {
444- throw pybind11::value_error (" Invalid face attribute " + std::string (key) + " . Must have same number of rows as faces." );
445- }
446- size_t num_cols = 1 ;
447- for (int i = 1 ; i < value.ndim (); i += 1 ) {
448- num_cols *= value.shape (i);
449- }
450- if (num_cols == 0 ) {
451- throw pybind11::value_error (" Invalid face attribute " + std::string (key) + " has zero elements." );
452- }
453- try {
454- tinyply::Type ply_dtype = dtype_to_ply_type (value.dtype ());
455- plyf.add_properties_to_element (
456- " face" , { key }, ply_dtype, num_vertices,
457- reinterpret_cast <std::uint8_t *>(value.mutable_data ()), tinyply::Type::UINT8, num_cols);
458- } catch (const std::runtime_error& e) {
459- throw pybind11::value_error (" Invalid dtype for custom face attribute " + std::string (key) + " ." );
460- }
461- }
462-
463403 if (has_v_positions) {
464404 plyf.add_properties_to_element (
465405 " vertex" , { " x" , " y" , " z" }, ply_type_f, num_vertices,
@@ -533,6 +473,67 @@ void save_mesh_ply(std::string filename,
533473 }
534474
535475
476+ if (has_f_vertex_ids) {
477+ plyf.add_properties_to_element (
478+ " face" , { " vertex_indices" }, ply_type_i, num_faces,
479+ reinterpret_cast <std::uint8_t *>(f_vertex_ids.mutable_data ()), tinyply::Type::UINT8, 3 );
480+ }
481+ if (has_f_normals) {
482+ plyf.add_properties_to_element (
483+ " face" , { " nx" , " ny" , " z" }, ply_type_f, num_faces,
484+ reinterpret_cast <std::uint8_t *>(f_normals.mutable_data ()), tinyply::Type::INVALID, 0 );
485+ }
486+ if (has_f_colors) {
487+ plyf.add_properties_to_element (
488+ " face" , { " red" , " green" , " blue" , " alpha" }, ply_type_f, num_faces,
489+ reinterpret_cast <std::uint8_t *>(f_colors.mutable_data ()), tinyply::Type::INVALID, 0 );
490+ }
491+ if (has_f_quality) {
492+ plyf.add_properties_to_element (
493+ " face" , { " quality" }, ply_type_f, num_faces,
494+ reinterpret_cast <std::uint8_t *>(f_quality.mutable_data ()), tinyply::Type::INVALID, 0 );
495+ }
496+ if (has_f_flags) {
497+ plyf.add_properties_to_element (
498+ " face" , { " flags" }, ply_type_i, num_faces,
499+ reinterpret_cast <std::uint8_t *>(f_flags.mutable_data ()), tinyply::Type::INVALID, 0 );
500+ }
501+ for (auto kv = custom_f_attribs.begin (); kv != custom_f_attribs.end (); kv++) {
502+ pybind11::str key = (pybind11::str) kv->first ;
503+ pybind11::array value = pybind11::array::ensure (kv->second );
504+ if (value.shape (0 ) != num_faces) {
505+ throw pybind11::value_error (" Invalid face attribute " + std::string (key) + " . Must have same number of rows as faces." );
506+ }
507+ size_t num_cols = 1 ;
508+ for (int i = 1 ; i < value.ndim (); i += 1 ) {
509+ num_cols *= value.shape (i);
510+ }
511+ if (num_cols == 0 ) {
512+ throw pybind11::value_error (" Invalid face attribute " + std::string (key) + " has zero elements." );
513+ }
514+ try {
515+ tinyply::Type ply_dtype = dtype_to_ply_type (value.dtype ());
516+ plyf.add_properties_to_element (
517+ " face" , { key }, ply_dtype, num_vertices,
518+ reinterpret_cast <std::uint8_t *>(value.mutable_data ()), tinyply::Type::UINT8, num_cols);
519+ } catch (const std::runtime_error& e) {
520+ throw pybind11::value_error (" Invalid dtype for custom face attribute " + std::string (key) + " ." );
521+ }
522+ }
523+
524+ if (has_w_texcoords) {
525+ plyf.add_properties_to_element (
526+ " face" , { " texcoords" }, ply_type_f, num_faces,
527+ reinterpret_cast <std::uint8_t *>(w_texcoords.mutable_data ()), tinyply::Type::UINT8, 6 );
528+ }
529+ if (has_w_texids) {
530+ plyf.add_properties_to_element (
531+ " face" , { " texnumber" }, ply_type_i, num_faces,
532+ reinterpret_cast <std::uint8_t *>(w_texcoords.mutable_data ()), tinyply::Type::INVALID, 0 );
533+ }
534+
535+
536+
536537 std::filebuf fb_binary;
537538 fb_binary.open (filename, std::ios::out | std::ios::binary);
538539 std::ostream outstream_binary (&fb_binary);
0 commit comments