Пример #1
0
void InflatorEngine::save_mesh(const std::string& filename,
        const MatrixFr& vertices, const MatrixIr& faces, VectorF debug) {
    VectorF flattened_vertices(vertices.rows() * vertices.cols());
    std::copy(vertices.data(), vertices.data() + vertices.rows() *
            vertices.cols(), flattened_vertices.data());
    VectorI flattened_faces(faces.rows() * faces.cols());
    std::copy(faces.data(), faces.data() + faces.rows() * faces.cols(),
            flattened_faces.data());
    VectorI voxels = VectorI::Zero(0);

    Mesh::Ptr mesh = MeshFactory().load_data(
            flattened_vertices, flattened_faces, voxels,
            vertices.cols(), faces.cols(), 0).create_shared();
    mesh->add_attribute("debug");
    mesh->set_attribute("debug", debug);

    MeshWriter::Ptr writer = MeshWriter::create(filename);
    writer->with_attribute("debug");
    writer->write_mesh(*mesh);
}
Пример #2
0
void copy_metadata(std::unique_ptr<DracoMesh>& draco_mesh, Mesh::Ptr mesh) {
    const auto metadata = draco_mesh->GetMetadata();
    if (metadata == nullptr) return;
    const auto& attr_metadatas = metadata->attribute_metadatas();
    for (const auto& attr_metadata : attr_metadatas) {
        std::string name="";
        attr_metadata->GetEntryString("name", &name);
        if (name == "") continue;
        auto uid = attr_metadata->att_unique_id();

        const auto attr = draco_mesh->GetAttributeByUniqueId(uid);
        const auto num_rows = attr->size();
        const auto num_cols = attr->num_components();

        VectorF data(num_rows * num_cols);
        for (size_t i=0; i<num_rows; i++) {
            attr->ConvertValue(draco::AttributeValueIndex(i),
                    data.data() + i*num_cols);
        }
        mesh->add_empty_attribute(name);
        mesh->set_attribute(name, data);
    }
}