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

Function copy_face_attributes

tools/Compression/Draco/DracoCompressionEngine.cpp:100–134  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

98}
99
100void copy_face_attributes(Mesh::Ptr mesh,
101 std::unique_ptr<draco::Mesh>& draco_mesh) {
102 const auto num_faces = mesh->get_num_faces();
103 const auto& attribute_names = mesh->get_attribute_names();
104 for (const auto& name : attribute_names) {
105 const auto& values = mesh->get_attribute(name);
106 if (values.size() % num_faces != 0) continue;
107 const auto num_rows = num_faces;
108 const auto num_cols = values.size() / num_faces;
109 draco::GeometryAttribute attr;
110 if (name == "face_normal") {
111 attr.Init(draco::GeometryAttribute::NORMAL, nullptr,
112 num_cols, draco::DT_FLOAT64, false,
113 sizeof(Float) * num_cols, 0);
114 } else if (name.substr(0, 4) == "face"){
115 attr.Init(draco::GeometryAttribute::GENERIC, nullptr,
116 num_cols, draco::DT_FLOAT64, false,
117 sizeof(Float) * num_cols, 0);
118 } else {
119 // Not a face attribute.
120 continue;
121 }
122 const auto id = draco_mesh->AddAttribute(attr, true, num_rows);
123 draco_mesh->SetAttributeElementType(id, draco::MESH_FACE_ATTRIBUTE);
124 for (size_t i=0; i<num_rows; i++) {
125 draco_mesh->attribute(id)->SetAttributeValue(
126 draco::AttributeValueIndex(i), values.data() + i*num_cols);
127 }
128
129 std::unique_ptr<draco::AttributeMetadata> metadata =
130 std::make_unique<draco::AttributeMetadata>();
131 metadata->AddEntryString("name", name);
132 draco_mesh->AddAttributeMetadata(id, std::move(metadata));
133 }
134}
135
136std::unique_ptr<draco::Mesh> to_draco_mesh(Mesh::Ptr mesh,
137 bool with_attributes=true) {

Callers

nothing calls this directly

Calls 5

get_num_facesMethod · 0.45
get_attribute_namesMethod · 0.45
get_attributeMethod · 0.45
sizeMethod · 0.45
InitMethod · 0.45

Tested by

no test coverage detected