Simulation Nodes: bake simulation states to disk #106937
@ -5,6 +5,7 @@
|
||||
#include "BKE_geometry_set.hh"
|
||||
|
||||
#include "BLI_map.hh"
|
||||
#include "BLI_sub_frame.hh"
|
||||
|
||||
namespace blender::bke::sim {
|
||||
|
||||
@ -78,86 +79,6 @@ class ModifierSimulationState {
|
||||
void ensure_bake_loaded() const;
|
||||
};
|
||||
|
||||
struct SubFrame {
|
||||
private:
|
||||
int frame_;
|
||||
float subframe_;
|
||||
|
||||
public:
|
||||
SubFrame(const int frame = 0, float subframe = 0.0f) : frame_(frame), subframe_(subframe)
|
||||
{
|
||||
BLI_assert(subframe >= 0.0f);
|
||||
BLI_assert(subframe < 1.0f);
|
||||
}
|
||||
|
||||
SubFrame(const float frame) : SubFrame(int(floorf(frame)), fractf(frame)) {}
|
||||
|
||||
int frame() const
|
||||
{
|
||||
return frame_;
|
||||
}
|
||||
|
||||
float subframe() const
|
||||
{
|
||||
return subframe_;
|
||||
}
|
||||
|
||||
explicit operator float() const
|
||||
{
|
||||
return float(frame_) + float(subframe_);
|
||||
}
|
||||
|
||||
explicit operator double() const
|
||||
{
|
||||
return double(frame_) + double(subframe_);
|
||||
}
|
||||
|
||||
static SubFrame min()
|
||||
{
|
||||
return {INT32_MIN, 0.0f};
|
||||
}
|
||||
|
||||
static SubFrame max()
|
||||
{
|
||||
return {INT32_MAX, std::nexttowardf(1.0f, 0.0)};
|
||||
}
|
||||
|
||||
friend bool operator==(const SubFrame &a, const SubFrame &b)
|
||||
{
|
||||
return a.frame_ == b.frame_ && a.subframe_ == b.subframe_;
|
||||
}
|
||||
|
||||
friend bool operator!=(const SubFrame &a, const SubFrame &b)
|
||||
{
|
||||
return !(a == b);
|
||||
}
|
||||
|
||||
friend bool operator<(const SubFrame &a, const SubFrame &b)
|
||||
{
|
||||
return a.frame_ < b.frame_ || (a.frame_ == b.frame_ && a.subframe_ < b.subframe_);
|
||||
}
|
||||
|
||||
friend bool operator<=(const SubFrame &a, const SubFrame &b)
|
||||
{
|
||||
return a.frame_ <= b.frame_ || (a.frame_ == b.frame_ && a.subframe_ <= b.subframe_);
|
||||
}
|
||||
|
||||
friend bool operator>(const SubFrame &a, const SubFrame &b)
|
||||
{
|
||||
return a.frame_ > b.frame_ || (a.frame_ == b.frame_ && a.subframe_ > b.subframe_);
|
||||
}
|
||||
|
||||
friend bool operator>=(const SubFrame &a, const SubFrame &b)
|
||||
{
|
||||
return a.frame_ >= b.frame_ || (a.frame_ == b.frame_ && a.subframe_ >= b.subframe_);
|
||||
}
|
||||
|
||||
friend std::ostream &operator<<(std::ostream &stream, const SubFrame &a)
|
||||
{
|
||||
return stream << float(a);
|
||||
}
|
||||
};
|
||||
|
||||
struct ModifierSimulationStateAtFrame {
|
||||
SubFrame frame;
|
||||
ModifierSimulationState state;
|
||||
|
93
source/blender/blenlib/BLI_sub_frame.hh
Normal file
93
source/blender/blenlib/BLI_sub_frame.hh
Normal file
@ -0,0 +1,93 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "BLI_assert.h"
|
||||
#include "BLI_math_base.h"
|
||||
|
||||
namespace blender {
|
||||
|
||||
/**
|
||||
* Contains an integer frame number and a subframe float in the range [0, 1).
|
||||
*/
|
||||
struct SubFrame {
|
||||
private:
|
||||
int frame_;
|
||||
float subframe_;
|
||||
|
||||
public:
|
||||
SubFrame(const int frame = 0, float subframe = 0.0f) : frame_(frame), subframe_(subframe)
|
||||
{
|
||||
BLI_assert(subframe >= 0.0f);
|
||||
BLI_assert(subframe < 1.0f);
|
||||
}
|
||||
|
||||
SubFrame(const float frame) : SubFrame(int(floorf(frame)), fractf(frame)) {}
|
||||
|
||||
int frame() const
|
||||
{
|
||||
return frame_;
|
||||
}
|
||||
|
||||
float subframe() const
|
||||
{
|
||||
return subframe_;
|
||||
}
|
||||
|
||||
explicit operator float() const
|
||||
{
|
||||
return float(frame_) + float(subframe_);
|
||||
}
|
||||
|
||||
explicit operator double() const
|
||||
{
|
||||
return double(frame_) + double(subframe_);
|
||||
}
|
||||
|
||||
static SubFrame min()
|
||||
{
|
||||
return {INT32_MIN, 0.0f};
|
||||
}
|
||||
|
||||
static SubFrame max()
|
||||
{
|
||||
return {INT32_MAX, std::nexttowardf(1.0f, 0.0)};
|
||||
}
|
||||
|
||||
friend bool operator==(const SubFrame &a, const SubFrame &b)
|
||||
{
|
||||
return a.frame_ == b.frame_ && a.subframe_ == b.subframe_;
|
||||
}
|
||||
|
||||
friend bool operator!=(const SubFrame &a, const SubFrame &b)
|
||||
{
|
||||
return !(a == b);
|
||||
}
|
||||
|
||||
friend bool operator<(const SubFrame &a, const SubFrame &b)
|
||||
{
|
||||
return a.frame_ < b.frame_ || (a.frame_ == b.frame_ && a.subframe_ < b.subframe_);
|
||||
}
|
||||
|
||||
friend bool operator<=(const SubFrame &a, const SubFrame &b)
|
||||
{
|
||||
return a.frame_ <= b.frame_ || (a.frame_ == b.frame_ && a.subframe_ <= b.subframe_);
|
||||
}
|
||||
|
||||
friend bool operator>(const SubFrame &a, const SubFrame &b)
|
||||
{
|
||||
return a.frame_ > b.frame_ || (a.frame_ == b.frame_ && a.subframe_ > b.subframe_);
|
||||
}
|
||||
|
||||
friend bool operator>=(const SubFrame &a, const SubFrame &b)
|
||||
{
|
||||
return a.frame_ >= b.frame_ || (a.frame_ == b.frame_ && a.subframe_ >= b.subframe_);
|
||||
}
|
||||
|
||||
friend std::ostream &operator<<(std::ostream &stream, const SubFrame &a)
|
||||
{
|
||||
return stream << float(a);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace blender
|
@ -352,6 +352,7 @@ set(SRC
|
||||
BLI_string_search.h
|
||||
BLI_string_utf8.h
|
||||
BLI_string_utils.h
|
||||
BLI_sub_frame.hh
|
||||
BLI_sys_types.h
|
||||
BLI_system.h
|
||||
BLI_task.h
|
||||
|
@ -97,7 +97,6 @@
|
||||
|
||||
namespace lf = blender::fn::lazy_function;
|
||||
namespace geo_log = blender::nodes::geo_eval_log;
|
||||
using blender::bke::sim::SubFrame;
|
||||
|
||||
namespace blender {
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user