tornavis/source/blender/blenkernel/BKE_volume_to_mesh.hh

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

72 lines
2.1 KiB
C++
Raw Normal View History

/* SPDX-License-Identifier: GPL-2.0-or-later */
2021-11-23 11:59:53 +01:00
#pragma once
#include "BLI_span.hh"
#include "DNA_modifier_types.h"
#ifdef WITH_OPENVDB
# include <openvdb/openvdb.h>
#endif
struct Mesh;
namespace blender::bke {
struct VolumeToMeshResolution {
VolumeToMeshResolutionMode mode;
union {
float voxel_size;
float voxel_amount;
} settings;
};
#ifdef WITH_OPENVDB
/**
* The result of converting a volume grid to mesh data, in the format used by the OpenVDB API.
*/
struct OpenVDBMeshData {
std::vector<openvdb::Vec3s> verts;
std::vector<openvdb::Vec3I> tris;
std::vector<openvdb::Vec4I> quads;
bool is_empty() const
{
return verts.empty();
}
};
struct Mesh *volume_to_mesh(const openvdb::GridBase &grid,
const VolumeToMeshResolution &resolution,
float threshold,
float adaptivity);
2022-01-18 03:05:07 +01:00
/**
* Convert an OpenVDB volume grid to corresponding mesh data: vertex positions and quad and
* triangle indices.
*/
struct OpenVDBMeshData volume_to_mesh_data(const openvdb::GridBase &grid,
const VolumeToMeshResolution &resolution,
float threshold,
float adaptivity);
2022-01-18 03:05:07 +01:00
/**
* Convert mesh data from the format provided by OpenVDB into Blender's #Mesh data structure.
* This can be used to add mesh data from a grid into an existing mesh rather than merging multiple
* meshes later on.
*/
void fill_mesh_from_openvdb_data(const Span<openvdb::Vec3s> vdb_verts,
const Span<openvdb::Vec3I> vdb_tris,
const Span<openvdb::Vec4I> vdb_quads,
int vert_offset,
int poly_offset,
int loop_offset,
Mesh: Move positions to a generic attribute **Changes** As described in T93602, this patch removes all use of the `MVert` struct, replacing it with a generic named attribute with the name `"position"`, consistent with other geometry types. Variable names have been changed from `verts` to `positions`, to align with the attribute name and the more generic design (positions are not vertices, they are just an attribute stored on the point domain). This change is made possible by previous commits that moved all other data out of `MVert` to runtime data or other generic attributes. What remains is mostly a simple type change. Though, the type still shows up 859 times, so the patch is quite large. One compromise is that now `CD_MASK_BAREMESH` now contains `CD_PROP_FLOAT3`. With the general move towards generic attributes over custom data types, we are removing use of these type masks anyway. **Benefits** The most obvious benefit is reduced memory usage and the benefits that brings in memory-bound situations. `float3` is only 3 bytes, in comparison to `MVert` which was 4. When there are millions of vertices this starts to matter more. The other benefits come from using a more generic type. Instead of writing algorithms specifically for `MVert`, code can just use arrays of vectors. This will allow eliminating many temporary arrays or wrappers used to extract positions. Many possible improvements aren't implemented in this patch, though I did switch simplify or remove the process of creating temporary position arrays in a few places. The design clarity that "positions are just another attribute" brings allows removing explicit copying of vertices in some procedural operations-- they are just processed like most other attributes. **Performance** This touches so many areas that it's hard to benchmark exhaustively, but I observed some areas as examples. * The mesh line node with 4 million count was 1.5x (8ms to 12ms) faster. * The Spring splash screen went from ~4.3 to ~4.5 fps. * The subdivision surface modifier/node was slightly faster RNA access through Python may be slightly slower, since now we need a name lookup instead of just a custom data type lookup for each index. **Future Improvements** * Remove uses of "vert_coords" functions: * `BKE_mesh_vert_coords_alloc` * `BKE_mesh_vert_coords_get` * `BKE_mesh_vert_coords_apply{_with_mat4}` * Remove more hidden copying of positions * General simplification now possible in many areas * Convert more code to C++ to use `float3` instead of `float[3]` * Currently `reinterpret_cast` is used for those C-API functions Differential Revision: https://developer.blender.org/D15982
2023-01-10 06:10:43 +01:00
MutableSpan<float3> vert_positions,
MutableSpan<MPoly> polys,
MutableSpan<MLoop> loops);
#endif
} // namespace blender::bke