MCPcopy Create free account
hub / github.com/PyMesh/PyMesh / copy_vertex_attributes

Function copy_vertex_attributes

tools/Compression/Draco/DracoCompressionEngine.cpp:61–98  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

59
60template <typename DracoMesh>
61void copy_vertex_attributes(Mesh::Ptr mesh,
62 std::unique_ptr<DracoMesh>& draco_mesh) {
63 const auto num_vertices = mesh->get_num_vertices();
64 const auto& attribute_names = mesh->get_attribute_names();
65 for (const auto& name : attribute_names) {
66 const auto& values = mesh->get_attribute(name);
67 if (values.size() % num_vertices != 0) continue;
68 const auto num_rows = num_vertices;
69 const auto num_cols = values.size() / num_vertices;
70 draco::GeometryAttribute attr;
71 if (name == "vertex_normal") {
72 attr.Init(draco::GeometryAttribute::NORMAL, nullptr,
73 num_cols, draco::DT_FLOAT64, false,
74 sizeof(Float) * num_cols, 0);
75 } else if (name == "vertex_texture") {
76 attr.Init(draco::GeometryAttribute::TEX_COORD, nullptr,
77 num_cols, draco::DT_FLOAT64, false,
78 sizeof(Float) * num_cols, 0);
79 } else if (name.substr(0, 6) == "vertex"){
80 attr.Init(draco::GeometryAttribute::GENERIC, nullptr,
81 num_cols, draco::DT_FLOAT64, false,
82 sizeof(Float) * num_cols, 0);
83 } else {
84 // Not a vertex attribute.
85 continue;
86 }
87 const auto id = draco_mesh->AddAttribute(attr, true, num_rows);
88 for (size_t i=0; i<num_rows; i++) {
89 draco_mesh->attribute(id)->SetAttributeValue(
90 draco::AttributeValueIndex(i), values.data() +i*num_cols);
91 }
92
93 std::unique_ptr<draco::AttributeMetadata> metadata =
94 std::make_unique<draco::AttributeMetadata>();
95 metadata->AddEntryString("name", name);
96 draco_mesh->AddAttributeMetadata(id, std::move(metadata));
97 }
98}
99
100void copy_face_attributes(Mesh::Ptr mesh,
101 std::unique_ptr<draco::Mesh>& draco_mesh) {

Callers 2

to_draco_meshFunction · 0.85
to_draco_point_cloudFunction · 0.85

Calls 5

get_num_verticesMethod · 0.45
get_attribute_namesMethod · 0.45
get_attributeMethod · 0.45
sizeMethod · 0.45
InitMethod · 0.45

Tested by

no test coverage detected