Animation: Auto frame curves Y extents when hitting normalize #105857

Merged
Christoph Lendenfeld merged 11 commits from ChrisLend/blender:normalize_set_range into main 2023-03-30 10:01:24 +02:00
6 changed files with 38 additions and 30 deletions
Showing only changes of commit 468d67faea - Show all commits

View File

@ -56,8 +56,8 @@ class BoundBox {
__forceinline void grow(const BoundBox &bbox)
{
grow(bbox.min);
grow(bbox.max);
min = ccl::min(bbox.min, min);
max = ccl::max(bbox.max, max);
}
__forceinline void grow_safe(const float3 &pt)
@ -81,8 +81,12 @@ class BoundBox {
__forceinline void grow_safe(const BoundBox &bbox)
{
grow_safe(bbox.min);
grow_safe(bbox.max);
if (isfinite_safe(bbox.min)) {
min = ccl::min(bbox.min, min);
}
if (isfinite_safe(bbox.max)) {
max = ccl::max(bbox.max, max);
}
}
__forceinline void intersect(const BoundBox &bbox)

View File

@ -66,7 +66,12 @@ static bool get_normalized_fcurve_bounds(FCurve *fcu,
rctf *r_bounds)
{
const bool fcu_selection_only = false;
BKE_fcurve_calc_bounds(fcu, fcu_selection_only, include_handles, range, r_bounds);
const bool found_bounds = BKE_fcurve_calc_bounds(
fcu, fcu_selection_only, include_handles, range, r_bounds);
if (!found_bounds) {
return false;
}
const short mapping_flag = ANIM_get_normalization_flags(ac);

View File

@ -114,7 +114,8 @@ void load_plydata(PlyData &plyData, Depsgraph *depsgraph, const PLYExportParams
const float2 *uv_map = static_cast<const float2 *>(
CustomData_get_layer(&mesh->ldata, CD_PROP_FLOAT2));
Map<UV_vertex_key, int> vertex_map = generate_vertex_map(mesh, uv_map, export_params);
Map<UV_vertex_key, int> vertex_map;
generate_vertex_map(mesh, uv_map, export_params, vertex_map);
set_world_axes_transform(
&export_object_eval_, export_params.forward_axis, export_params.up_axis);
@ -221,25 +222,24 @@ void load_plydata(PlyData &plyData, Depsgraph *depsgraph, const PLYExportParams
DEG_OBJECT_ITER_END;
}
Map<UV_vertex_key, int> generate_vertex_map(const Mesh *mesh,
const float2 *uv_map,
const PLYExportParams &export_params)
void generate_vertex_map(const Mesh *mesh,
const float2 *uv_map,
const PLYExportParams &export_params,
Map<UV_vertex_key, int> &r_map)
{
Map<UV_vertex_key, int> vertex_map;
const Span<MPoly> polys = mesh->polys();
const Span<MLoop> loops = mesh->loops();
const int totvert = mesh->totvert;
vertex_map.reserve(totvert);
r_map.reserve(totvert);
if (uv_map == nullptr || !export_params.export_uv) {
for (int vertex_index = 0; vertex_index < totvert; ++vertex_index) {
UV_vertex_key key = UV_vertex_key({0, 0}, vertex_index);
vertex_map.add_new(key, int(vertex_map.size()));
r_map.add_new(key, int(r_map.size()));
}
return vertex_map;
return;
}
const float limit[2] = {STD_UV_CONNECT_LIMIT, STD_UV_CONNECT_LIMIT};
@ -259,7 +259,7 @@ Map<UV_vertex_key, int> generate_vertex_map(const Mesh *mesh,
if (uv_vert == nullptr) {
UV_vertex_key key = UV_vertex_key({0, 0}, vertex_index);
vertex_map.add_new(key, int(vertex_map.size()));
r_map.add_new(key, int(r_map.size()));
}
for (; uv_vert; uv_vert = uv_vert->next) {
@ -267,10 +267,10 @@ Map<UV_vertex_key, int> generate_vertex_map(const Mesh *mesh,
const int loopstart = polys[uv_vert->poly_index].loopstart;
float2 vert_uv_coords(uv_map[loopstart + uv_vert->loop_of_poly_index]);
UV_vertex_key key = UV_vertex_key(vert_uv_coords, vertex_index);
vertex_map.add(key, int(vertex_map.size()));
r_map.add(key, int(r_map.size()));
}
}
BKE_mesh_uv_vert_map_free(uv_vert_map);
return vertex_map;
}
} // namespace blender::io::ply

View File

@ -13,6 +13,7 @@
#include "BKE_mesh.h"
#include "BKE_mesh_mapping.h"
#include "BKE_object.h"
#include "BLI_hash.hh"
#include "BLI_math.h"
#include "RNA_types.h"
@ -45,16 +46,14 @@ struct UV_vertex_key {
uint64_t hash() const
{
return ((std::hash<float>()(UV.x) ^ (std::hash<float>()(UV.y) << 1)) >> 1) ^
(std::hash<int>()(mesh_vertex_index) << 1);
return get_default_hash_3(UV.x, UV.y, mesh_vertex_index);
}
};
blender::Map<UV_vertex_key, int> generate_vertex_map(const Mesh *mesh,
const float2 *uv_map,
const PLYExportParams &export_params);
void load_plydata(PlyData &plyData, const bContext *C, const PLYExportParams &export_params);
void generate_vertex_map(const Mesh *mesh,
const float2 *uv_map,
const PLYExportParams &export_params,
Map<UV_vertex_key, int> &r_map);
void load_plydata(PlyData &plyData, Depsgraph *depsgraph, const PLYExportParams &export_params);
} // namespace blender::io::ply

View File

@ -66,16 +66,16 @@ void FileBuffer::write_newline()
void FileBuffer::ensure_space(size_t at_least)
{
if (blocks_.is_empty() || (blocks_.last().capacity() - blocks_.last().size() < at_least)) {
blocks_.append(VectorChar());
blocks_.reserve(std::max(at_least, buffer_chunk_size_));
if (blocks_.empty() || (blocks_.back().capacity() - blocks_.back().size() < at_least)) {
VectorChar &b = blocks_.emplace_back(VectorChar());
b.reserve(std::max(at_least, buffer_chunk_size_));
}
}
void FileBuffer::write_bytes(Span<char> bytes)
{
ensure_space(bytes.size());
VectorChar &bb = blocks_.last();
VectorChar &bb = blocks_.back();
bb.insert(bb.end(), bytes.begin(), bytes.end());
}

View File

@ -33,7 +33,7 @@ namespace blender::io::ply {
*/
class FileBuffer : private NonMovable {
using VectorChar = Vector<char>;
Vector<VectorChar> blocks_;
std::vector<VectorChar> blocks_;
size_t buffer_chunk_size_;
const char *filepath_;
FILE *outfile_;
@ -84,7 +84,7 @@ class FileBuffer : private NonMovable {
fmt::format_to(fmt::appender(buf), fmt, std::forward<T>(args)...);
size_t len = buf.size();
ensure_space(len);
VectorChar &bb = blocks_.last();
VectorChar &bb = blocks_.back();
bb.insert(bb.end(), buf.begin(), buf.end());
}