Blender V5.3
blender::io::ply Namespace Reference

Classes

class  FileBuffer
class  FileBufferAscii
class  FileBufferBinary
class  GsplatPlyDataBuilder
class  io_ply_import_gsplat
struct  PlyCustomAttribute
struct  PlyData
struct  PlyElement
class  PLYExportPLYDataTest
class  PLYExportTest
struct  PlyHeader
struct  PlyProperty
class  PlyReadBuffer
struct  uv_vertex_key

Enumerations

enum  PlyDataTypes {
  NONE , CHAR , UCHAR , SHORT ,
  USHORT , INT , UINT , FLOAT ,
  DOUBLE , PLY_TYPE_COUNT
}
enum  PlyFormatType { ASCII , BINARY_LE , BINARY_BE }

Functions

void exporter_main (bContext *C, const PLYExportParams &export_params)
void write_vertices (FileBuffer &buffer, const PlyData &ply_data)
void write_faces (FileBuffer &buffer, const PlyData &ply_data)
void write_edges (FileBuffer &buffer, const PlyData &ply_data)
void write_header (FileBuffer &buffer, const PlyData &ply_data, const PLYExportParams &export_params)
static Mesh * do_triangulation (const Mesh *mesh, bool force_triangulation)
static void set_world_axes_transform (const Object &object, const eIOAxis forward, const eIOAxis up, float r_world_and_axes_transform[4][4], float r_world_and_axes_normal_transform[3][3])
static void generate_vertex_map (const Mesh *mesh, const PLYExportParams &export_params, Vector< int > &r_ply_to_vertex, Vector< int > &r_vertex_to_ply, Vector< int > &r_loop_to_ply, Vector< float2 > &r_uvs)
static float * find_or_add_attribute (const StringRef name, int64_t size, uint32_t vertex_offset, Vector< PlyCustomAttribute > &r_attributes)
static void load_custom_attributes (const Mesh *mesh, const Span< int > ply_to_vertex, uint32_t vertex_offset, Vector< PlyCustomAttribute > &r_attributes)
void load_plydata (PlyData &plyData, Depsgraph *depsgraph, const PLYExportParams &export_params)
static bool parse_keyword (Span< char > &str, StringRef keyword)
static Span< char > parse_word (Span< char > &str)
static void skip_space (Span< char > &str)
static PlyDataTypes type_from_string (Span< char > word)
const char * read_header (PlyReadBuffer &file, PlyHeader &r_header)
static void report_exception (const PLYImportParams &import_params, const StringRefNull ob_name, const std::exception &ex)
static std::unique_ptr< PlyData > read_ply_to_data (const PLYImportParams &import_params, const StringRefNull ob_name)
static bool is_data_gaussian_splat (const PlyData &data)
static std::string get_datablock_name (const StringRefNull filepath)
Mesh * import_mesh (const PLYImportParams &import_params)
PointCloud * import_point_cloud (const PLYImportParams &import_params)
bke::GeometrySet import_geometry_set (const PLYImportParams &import_params)
void importer_main (bContext *C, const PLYImportParams &import_params)
static void importer_main_impl (Main *bmain, Scene *scene, ViewLayer *view_layer, const PLYImportParams &import_params, const std::string &datablock_name)
void importer_main (Main *bmain, Scene *scene, ViewLayer *view_layer, const PLYImportParams &import_params)
static int get_index (const PlyElement &element, StringRef property)
template<typename T>
static const char * parse_ascii_value (const char *p, const char *end, T &dst)
template<typename T>
static const char * parse_row_ascii (PlyReadBuffer &file, const PlyElement &element, Vector< T > &r_values)
template<typename T, typename F>
static T float_to_value (const F value)
template<typename T>
static T get_binary_value (PlyDataTypes type, const uint8_t *&r_ptr)
template<typename T>
static const char * parse_row_binary (PlyReadBuffer &file, const PlyHeader &header, const PlyElement &element, Vector< uint8_t > &r_scratch, Vector< T > &r_values)
static const char * load_vertex_element (PlyReadBuffer &file, const PlyHeader &header, const PlyElement &element, PlyData *data)
static bool read_list_count (PlyReadBuffer &file, const PlyProperty &prop, Vector< uint8_t > &scratch, bool big_endian, uint32_t &r_count)
static bool read_list_values (PlyReadBuffer &file, const PlyProperty &prop, const uint32_t count, Vector< uint8_t > &scratch)
static bool skip_property (PlyReadBuffer &file, const PlyProperty &prop, Vector< uint8_t > &scratch, bool big_endian)
static const char * load_face_element (PlyReadBuffer &file, const PlyHeader &header, const PlyElement &element, PlyData *data)
static const char * load_tristrips_element (PlyReadBuffer &file, const PlyHeader &header, const PlyElement &element, PlyData *data)
static const char * load_edge_element (PlyReadBuffer &file, const PlyHeader &header, const PlyElement &element, PlyData *data)
static const char * skip_element (PlyReadBuffer &file, const PlyHeader &header, const PlyElement &element)
std::unique_ptr< PlyData > import_ply_data (PlyReadBuffer &file, PlyHeader &header)
static std::optional< Span< float > > find_custom_attribute (const PlyData &data, const StringRefNull name)
static Vector< Span< float > > get_rest_custom_attributes (const PlyData &data)
static bool is_builtin_gsplat_attribute (StringRefNull name)
PointCloud * convert_gsplat_ply_to_point_cloud (const PlyData &data, const PLYImportParams &params)
Mesh * convert_ply_to_mesh (PlyData &data, const PLYImportParams &params)
static std::unique_ptr< PlyData > load_cube (PLYExportParams &params)
static std::string read_temp_file_in_string (const std::string &file_path)
static char read (std::ifstream &file)
static std::vector< char > read_temp_file_in_vectorchar (const std::string &file_path)
 TEST_F (PLYExportTest, WriteHeaderAscii)
 TEST_F (PLYExportTest, WriteHeaderBinary)
 TEST_F (PLYExportTest, WriteVerticesAscii)
 TEST_F (PLYExportTest, WriteVerticesBinary)
 TEST_F (PLYExportTest, WriteFacesAscii)
 TEST_F (PLYExportTest, WriteFacesBinary)
 TEST_F (PLYExportTest, WriteVertexNormalsAscii)
 TEST_F (PLYExportTest, WriteVertexNormalsBinary)
 TEST_F (PLYExportPLYDataTest, CubeLoadPLYData)
 TEST_F (PLYExportPLYDataTest, CubeLoadPLYDataUV)
 TEST_F (PLYExportPLYDataTest, CubeLooseEdgesLoadPLYData)
 TEST_F (PLYExportPLYDataTest, CubeLooseEdgesLoadPLYDataUV)
 TEST_F (PLYExportPLYDataTest, CubesVertexAttrs)
 TEST_F (PLYExportPLYDataTest, SuzanneLoadPLYDataUV)
 TEST_F (io_ply_import_gsplat, missing_required_attributes)
 TEST_F (io_ply_import_gsplat, basic_attributes)
 TEST_F (io_ply_import_gsplat, canonical_counts_import_all_coefficients)
 TEST_F (io_ply_import_gsplat, non_canonical_count_keeps_channels)
 TEST_F (io_ply_import_gsplat, mid_band_count_keeps_channels)
 TEST_F (io_ply_import_gsplat, count_not_multiple_of_three_drops_sh)
 TEST_F (io_ply_import_gsplat, above_max_degree_drops_sh)
 TEST (ply_import, BufferRefillTest)

Variables

static const int data_type_size [] = {0, 1, 1, 2, 2, 4, 4, 4, 8}
static const float data_type_normalizer []
constexpr int MAX_SH_DEGREE = 4
constexpr int MAX_REST_ATTRIBUTES = 24 * 3
const char *const temp_file_path = "output\xc4\x84\xd0\x96.ply"

Enumeration Type Documentation

◆ PlyDataTypes

Enumerator
NONE 
CHAR 
UCHAR 
SHORT 
USHORT 
INT 
UINT 
FLOAT 
DOUBLE 
PLY_TYPE_COUNT 

Definition at line 20 of file ply_data.hh.

◆ PlyFormatType

Enumerator
ASCII 
BINARY_LE 
BINARY_BE 

Definition at line 43 of file ply_data.hh.

Function Documentation

◆ convert_gsplat_ply_to_point_cloud()

PointCloud * blender::io::ply::convert_gsplat_ply_to_point_cloud ( const PlyData & data,
const PLYImportParams & params )

Converts the PlyData data-structure to a point cloud that represents gsplat.

Returns
A new pointcloud that can be used inside blender.

NOTE: PlyData must represent gaussian splat (contain all related attributes).

Definition at line 80 of file ply_import_gsplat.cc.

References blender::bke::MutableAttributeAccessor::add(), blender::BKE_id_free(), blender::BKE_pointcloud_new_nomain(), blender::BKE_reportf(), BLI_SCOPED_DEFER, convert_gsplat_ply_to_point_cloud(), blender::data, blender::io::ply::PlyCustomAttribute::data, blender::io::gsplat::OriginalActivationFunctions::decode_opacity(), blender::io::gsplat::OriginalActivationFunctions::decode_scale(), blender::io::gsplat::degree_for_dimension(), blender::io::gsplat::dimension_for_degree(), find_custom_attribute(), blender::io::gsplat::GsplatMutableAttributeAccessor::finish(), blender::VArray< T >::from_span(), get_rest_custom_attributes(), blender::GSplat, blender::PLYImportParams::import_attributes, is_builtin_gsplat_attribute(), MAX_REST_ATTRIBUTES, MAX_SH_DEGREE, blender::io::ply::PlyCustomAttribute::name, blender::math::normalize(), blender::bke::Point, blender::io::gsplat::GsplatMutableAttributeAccessor::radiance_base_for_write(), blender::PLYImportParams::reports, blender::io::gsplat::GsplatMutableAttributeAccessor::rotations_for_write(), blender::RPT_WARNING, scale(), blender::io::gsplat::GsplatMutableAttributeAccessor::scales_for_write(), blender::io::gsplat::GsplatMutableAttributeAccessor::sh_for_write(), blender::Vector< T, InlineBufferCapacity, Allocator >::size(), blender::io::validate::size_fits_in_int(), and w().

Referenced by convert_gsplat_ply_to_point_cloud(), import_geometry_set(), import_point_cloud(), importer_main_impl(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), and TEST_F().

◆ convert_ply_to_mesh()

Mesh * blender::io::ply::convert_ply_to_mesh ( PlyData & data,
const PLYImportParams & params )

◆ do_triangulation()

◆ exporter_main()

◆ find_custom_attribute()

std::optional< Span< float > > blender::io::ply::find_custom_attribute ( const PlyData & data,
const StringRefNull name )
static

◆ find_or_add_attribute()

◆ float_to_value()

template<typename T, typename F>
T blender::io::ply::float_to_value ( const F value)
static

Definition at line 170 of file ply_import_data.cc.

References F, float_to_value(), and T.

Referenced by float_to_value(), get_binary_value(), and load_edge_element().

◆ generate_vertex_map()

◆ get_binary_value()

template<typename T>
T blender::io::ply::get_binary_value ( PlyDataTypes type,
const uint8_t *& r_ptr )
static

◆ get_datablock_name()

◆ get_index()

int blender::io::ply::get_index ( const PlyElement & element,
StringRef property )
static

◆ get_rest_custom_attributes()

Vector< Span< float > > blender::io::ply::get_rest_custom_attributes ( const PlyData & data)
static

◆ import_geometry_set()

◆ import_mesh()

Mesh * blender::io::ply::import_mesh ( const PLYImportParams & import_params)

◆ import_ply_data()

std::unique_ptr< PlyData > blender::io::ply::import_ply_data ( PlyReadBuffer & file,
PlyHeader & header )

Loads the information from a PLY file to a PlyData data-structure.

Parameters
fileThe PLY file that was opened.
headerThe information in the PLY header.
Returns
The PlyData data-structure that can be used for conversion to a Mesh.

Definition at line 739 of file ply_import_data.cc.

References ASCII, blender::data, ELEM, blender::element, blender::io::ply::PlyHeader::elements, import_ply_data(), load_edge_element(), load_face_element(), load_tristrips_element(), load_vertex_element(), skip_element(), and blender::io::ply::PlyHeader::type.

Referenced by import_ply_data(), read_ply_to_data(), and TEST().

◆ import_point_cloud()

◆ importer_main() [1/2]

void blender::io::ply::importer_main ( bContext * C,
const PLYImportParams & import_params )

◆ importer_main() [2/2]

void blender::io::ply::importer_main ( Main * bmain,
Scene * scene,
ViewLayer * view_layer,
const PLYImportParams & import_params )

◆ importer_main_impl()

void blender::io::ply::importer_main_impl ( Main * bmain,
Scene * scene,
ViewLayer * view_layer,
const PLYImportParams & import_params,
const std::string & datablock_name )
static

Definition at line 394 of file ply_import.cc.

References blender::BKE_collection_object_add(), blender::BKE_id_free(), blender::BKE_layer_collection_get_active_editable(), blender::BKE_mesh_add(), blender::BKE_mesh_nomain_to_mesh(), blender::BKE_object_add_only_object(), blender::BKE_object_apply_mat4(), blender::BKE_pointcloud_add(), blender::BKE_pointcloud_nomain_to_pointcloud(), blender::BKE_report(), blender::BKE_view_layer_base_deselect_all(), blender::BKE_view_layer_base_find(), blender::BKE_view_layer_base_select_and_set_active(), blender::BKE_view_layer_synced_ensure(), blender::BLI_assert(), BLI_SCOPED_DEFER, blender::LayerCollection::collection, convert_gsplat_ply_to_point_cloud(), convert_ply_to_mesh(), blender::copy_m4_m3(), blender::data, blender::DEG_id_tag_update(), blender::DEG_id_tag_update_ex(), blender::DEG_relations_tag_update(), blender::PLYImportParams::forward_axis, blender::PLYImportParams::global_scale, blender::Collection::id, blender::Scene::id, ID_IS_EDITABLE, blender::ID_RECALC_ANIMATION, blender::ID_RECALC_BASE_FLAGS, blender::ID_RECALC_GEOMETRY, blender::ID_RECALC_SYNC_TO_EVAL, blender::ID_RECALC_TRANSFORM, importer_main_impl(), blender::IO_AXIS_Y, blender::IO_AXIS_Z, is_data_gaussian_splat(), blender::mat3_from_axis_conversion(), blender::OB_EMPTY, blender::OB_MESH, blender::OB_POINTCLOUD, read_ply_to_data(), blender::PLYImportParams::reports, blender::rescale_m4(), blender::RPT_WARNING, blender::UnitSettings::scale_length, blender::UnitSettings::system, blender::Scene::unit, blender::unit_m3(), blender::unit_m4(), blender::PLYImportParams::up_axis, blender::PLYImportParams::use_scene_unit, and blender::USER_UNIT_NONE.

Referenced by importer_main(), and importer_main_impl().

◆ is_builtin_gsplat_attribute()

bool blender::io::ply::is_builtin_gsplat_attribute ( StringRefNull name)
static

◆ is_data_gaussian_splat()

◆ load_cube()

std::unique_ptr< PlyData > blender::io::ply::load_cube ( PLYExportParams & params)
static

◆ load_custom_attributes()

◆ load_edge_element()

◆ load_face_element()

◆ load_plydata()

void blender::io::ply::load_plydata ( PlyData & plyData,
Depsgraph * depsgraph,
const PLYExportParams & export_params )

Definition at line 326 of file ply_export_load_plydata.cc.

References blender::Vector< T, InlineBufferCapacity, Allocator >::append_n_times(), blender::PLYExportParams::apply_modifiers, blender::BASE_SELECTED, blender::BKE_id_free(), blender::BKE_mesh_wrapper_ensure_mdata(), blender::BLI_assert(), blender::io::ply::PlyCustomAttribute::data, blender::DEG_get_evaluated(), blender::DEG_ITER_OBJECT_FLAG_DUPLI, blender::DEG_ITER_OBJECT_FLAG_LINKED_DIRECTLY, blender::DEG_ITER_OBJECT_FLAG_LINKED_VIA_SET, blender::DEG_ITER_OBJECT_FLAG_VISIBLE, DEG_OBJECT_ITER_BEGIN, DEG_OBJECT_ITER_END, blender::DEGObjectIterSettings::depsgraph, do_triangulation(), blender::io::ply::PlyData::edges, blender::PLYExportParams::export_attributes, blender::PLYExportParams::export_normals, blender::PLYExportParams::export_selected_objects, blender::PLYExportParams::export_triangulated_mesh, blender::io::ply::PlyData::face_sizes, blender::io::ply::PlyData::face_vertices, blender::DEGObjectIterSettings::flags, blender::PLYExportParams::forward_axis, generate_vertex_map(), blender::PLYExportParams::global_scale, blender::offset_indices::OffsetIndices< T >::index_range(), blender::IndexRange::IndexRange(), blender::blender::StringRefBase::is_empty(), blender::VArrayCommon< T >::is_empty(), blender::Vector< T, InlineBufferCapacity, Allocator >::is_empty(), blender::linearrgb_to_srgb_v4(), load_custom_attributes(), load_plydata(), blender::bke::AttributeAccessor::lookup_or_default(), blender::io::mesh_coerce_for_export_setup(), blender::mul_m3_v3(), blender::mul_m4_v3(), blender::mul_v3_fl(), blender::None, blender::normalize_v3(), blender::OB_MESH, blender::bke::Point, lexit::Vector< T >::reserve(), lexit::Vector< T >::resize(), set_world_axes_transform(), blender::IndexRange::size(), blender::Vector< T, InlineBufferCapacity, Allocator >::size(), lexit::Vector< T >::size(), blender::sRGB, blender::PLYExportParams::up_axis, blender::io::ply::PlyData::uv_coordinates, blender::io::ply::PlyData::vertex_colors, blender::PLYExportParams::vertex_colors, blender::io::ply::PlyData::vertex_custom_attr, blender::io::ply::PlyData::vertex_normals, and blender::io::ply::PlyData::vertices.

Referenced by exporter_main(), blender::io::ply::PLYExportPLYDataTest::load_ply_data_from_blendfile(), and load_plydata().

◆ load_tristrips_element()

◆ load_vertex_element()

◆ parse_ascii_value()

template<typename T>
const char * blender::io::ply::parse_ascii_value ( const char * p,
const char * end,
T & dst )
static

◆ parse_keyword()

bool blender::io::ply::parse_keyword ( Span< char > & str,
StringRef keyword )
static

◆ parse_row_ascii()

◆ parse_row_binary()

◆ parse_word()

Span< char > blender::io::ply::parse_word ( Span< char > & str)
static

Definition at line 67 of file ply_import.cc.

References len(), parse_word(), and str.

Referenced by parse_word(), and read_header().

◆ read()

char blender::io::ply::read ( std::ifstream & file)
static

Definition at line 113 of file io_ply_exporter_test.cc.

References read().

Referenced by read(), and read_temp_file_in_vectorchar().

◆ read_header()

◆ read_list_count()

◆ read_list_values()

◆ read_ply_to_data()

◆ read_temp_file_in_string()

std::string blender::io::ply::read_temp_file_in_string ( const std::string & file_path)
static

◆ read_temp_file_in_vectorchar()

std::vector< char > blender::io::ply::read_temp_file_in_vectorchar ( const std::string & file_path)
static

◆ report_exception()

void blender::io::ply::report_exception ( const PLYImportParams & import_params,
const StringRefNull ob_name,
const std::exception & ex )
static

◆ set_world_axes_transform()

void blender::io::ply::set_world_axes_transform ( const Object & object,
const eIOAxis forward,
const eIOAxis up,
float r_world_and_axes_transform[4][4],
float r_world_and_axes_normal_transform[3][3] )
static

◆ skip_element()

const char * blender::io::ply::skip_element ( PlyReadBuffer & file,
const PlyHeader & header,
const PlyElement & element )
static

◆ skip_property()

◆ skip_space()

void blender::io::ply::skip_space ( Span< char > & str)
static

Definition at line 78 of file ply_import.cc.

References skip_space(), and str.

Referenced by read_header(), and skip_space().

◆ TEST()

blender::io::ply::TEST ( ply_import ,
BufferRefillTest  )

◆ TEST_F() [1/21]

◆ TEST_F() [2/21]

◆ TEST_F() [3/21]

blender::io::ply::TEST_F ( io_ply_import_gsplat ,
canonical_counts_import_all_coefficients  )

◆ TEST_F() [4/21]

◆ TEST_F() [5/21]

◆ TEST_F() [6/21]

blender::io::ply::TEST_F ( io_ply_import_gsplat ,
missing_required_attributes  )

◆ TEST_F() [7/21]

◆ TEST_F() [8/21]

◆ TEST_F() [9/21]

◆ TEST_F() [10/21]

◆ TEST_F() [11/21]

◆ TEST_F() [12/21]

◆ TEST_F() [13/21]

blender::io::ply::TEST_F ( PLYExportPLYDataTest ,
SuzanneLoadPLYDataUV  )

◆ TEST_F() [14/21]

◆ TEST_F() [15/21]

◆ TEST_F() [16/21]

◆ TEST_F() [17/21]

◆ TEST_F() [18/21]

◆ TEST_F() [19/21]

◆ TEST_F() [20/21]

◆ TEST_F() [21/21]

◆ type_from_string()

PlyDataTypes blender::io::ply::type_from_string ( Span< char > word)
static

◆ write_edges()

void blender::io::ply::write_edges ( FileBuffer & buffer,
const PlyData & ply_data )

◆ write_faces()

◆ write_header()

◆ write_vertices()

Variable Documentation

◆ data_type_normalizer

const float blender::io::ply::data_type_normalizer[]
static
Initial value:
= {
1.0f, 127.0f, 255.0f, 32767.0f, 65535.0f, float(INT_MAX), float(UINT_MAX), 1.0f, 1.0f}
#define INT_MAX
#define UINT_MAX
Definition hash_md5.cc:46
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float

Definition at line 100 of file ply_import_data.cc.

Referenced by load_vertex_element().

◆ data_type_size

const int blender::io::ply::data_type_size[] = {0, 1, 1, 2, 2, 4, 4, 4, 8}
static

◆ MAX_REST_ATTRIBUTES

int blender::io::ply::MAX_REST_ATTRIBUTES = 24 * 3
constexpr

◆ MAX_SH_DEGREE

int blender::io::ply::MAX_SH_DEGREE = 4
constexpr

Definition at line 37 of file ply_import_gsplat.cc.

Referenced by convert_gsplat_ply_to_point_cloud().

◆ temp_file_path

const char* const blender::io::ply::temp_file_path = "output\xc4\x84\xd0\x96.ply"

Definition at line 99 of file io_ply_exporter_test.cc.

Referenced by TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), and TEST_F().