Changeset View
Changeset View
Standalone View
Standalone View
source/blender/geometry/intern/mesh_to_volume.cc
| Show First 20 Lines • Show All 58 Lines • ▼ Show 20 Lines | |||||
| { | { | ||||
| const MLoopTri &looptri = looptris_[polygon_index]; | const MLoopTri &looptri = looptris_[polygon_index]; | ||||
| const MVert &vertex = vertices_[loops_[looptri.tri[vertex_index]].v]; | const MVert &vertex = vertices_[loops_[looptri.tri[vertex_index]].v]; | ||||
| const float3 transformed_co = transform_ * float3(vertex.co); | const float3 transformed_co = transform_ * float3(vertex.co); | ||||
| pos = &transformed_co.x; | pos = &transformed_co.x; | ||||
| } | } | ||||
| float volume_compute_voxel_size(const Depsgraph *depsgraph, | float volume_compute_voxel_size(const Depsgraph *depsgraph, | ||||
| const float3 &bb_min, | FunctionRef<void(float3 &r_min, float3 &r_max)> bounds_fn, | ||||
| const float3 &bb_max, | |||||
| const MeshToVolumeResolution res, | const MeshToVolumeResolution res, | ||||
| const float exterior_band_width, | const float exterior_band_width, | ||||
| const float4x4 &transform) | const float4x4 &transform) | ||||
| { | { | ||||
| const float volume_simplify = BKE_volume_simplify_factor(depsgraph); | const float volume_simplify = BKE_volume_simplify_factor(depsgraph); | ||||
| if (volume_simplify == 0.0f) { | if (volume_simplify == 0.0f) { | ||||
| return 0.0f; | return 0.0f; | ||||
| } | } | ||||
| if (res.mode == MESH_TO_VOLUME_RESOLUTION_MODE_VOXEL_SIZE) { | if (res.mode == MESH_TO_VOLUME_RESOLUTION_MODE_VOXEL_SIZE) { | ||||
| return res.settings.voxel_size / volume_simplify; | return res.settings.voxel_size / volume_simplify; | ||||
| } | } | ||||
| if (res.settings.voxel_amount <= 0) { | if (res.settings.voxel_amount <= 0) { | ||||
| return 0; | return 0; | ||||
| } | } | ||||
| float3 bb_min; | |||||
| float3 bb_max; | |||||
| bounds_fn(bb_min, bb_max); | |||||
| /* Compute the voxel size based on the desired number of voxels and the approximated bounding | /* Compute the voxel size based on the desired number of voxels and the approximated bounding | ||||
| * box of the volume. */ | * box of the volume. */ | ||||
| const float diagonal = math::distance(transform * bb_max, transform * bb_min); | const float diagonal = math::distance(transform * bb_max, transform * bb_min); | ||||
| const float approximate_volume_side_length = diagonal + exterior_band_width * 2.0f; | const float approximate_volume_side_length = diagonal + exterior_band_width * 2.0f; | ||||
| const float voxel_size = approximate_volume_side_length / res.settings.voxel_amount / | const float voxel_size = approximate_volume_side_length / res.settings.voxel_amount / | ||||
| volume_simplify; | volume_simplify; | ||||
| return voxel_size; | return voxel_size; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 77 Lines • Show Last 20 Lines | |||||