43 const int frame_start =
RNA_int_get(ptr,
"frame_start");
44 const int frame_end =
RNA_int_get(ptr,
"frame_end");
46 if (frame_end <= frame_start) {
60 if (frame_start < scene->r.sfra) {
68 if (frame_end > scene->
r.
efra) {
74 C, op, 250,
IFACE_(
"Bake Object Transform to Grease Pencil"),
IFACE_(
"Bake"));
85 bake_targets.
append(active_object);
94 bake_targets.
append(duplicate_object.ob);
100 if (
object == active_object) {
105 bake_targets.
append(
object);
114 bake_targets.
append(duplicate_object.ob);
126 for (
Object *bake_target : bake_targets) {
129 for (
const int i :
IndexRange(fcurve->totvert)) {
132 keyframes.
add(
int(bezt.
vec[1][0]));
160 const int frame_offset =
RNA_int_get(op->
ptr,
"frame_target") - frame_start;
179 std::optional<Set<int>> keyframes;
186 for (
int frame = frame_start; frame <= frame_end; frame++) {
187 if ((frame - frame_start) %
step != 0 && frame != frame_end) {
191 if (keyframes && keyframes->contains(frame)) {
195 scene.
r.
cfra = frame;
198 for (
Object *source_object : bake_targets) {
200 GreasePencil &source_eval_grease_pencil = *id_cast<GreasePencil *>(source_object_eval->
data);
201 for (
const Layer *source_layer : source_eval_grease_pencil.layers()) {
202 const float4x4 to_target = target_imat * source_layer->to_world_space(*source_object_eval);
203 std::string layer_name = fmt::format(
204 "{}_{}", source_object->id.name + 2, source_layer->name());
206 if (
node ==
nullptr) {
207 Layer &new_layer = target.add_layer(layer_name);
208 target.set_active_layer(&new_layer);
211 Layer &target_layer = target.find_node_by_name(layer_name)->as_layer();
212 std::optional<DrawingPlacement> drawing_placement;
215 scene, *region, *v3d, *target_object_eval, &target_layer, reproject_mode);
219 if (source_frame ==
nullptr) {
223 const int target_frame_num = scene.
r.
cfra + frame_offset;
224 Drawing &source_drawing = *source_eval_grease_pencil.get_drawing_at(*source_layer,
226 Drawing &target_drawing = *target.insert_frame(target_layer, target_frame_num);
234 target_strokes.attributes_for_write().lookup_or_add_for_write_span<
int>(
239 source_material_indices[i] + 1);
245 if (source_material == target_material) {
264 target_material_indices.
finish();
267 if (drawing_placement) {
269 for (const int i : range) {
270 positions[i] = drawing_placement->reproject(positions[i]);
277 scene.r.cfra = prior_frame;
308 ot->
name =
"Bake Object Transform to Grease Pencil";
309 ot->
idname =
"GREASE_PENCIL_OT_bake_grease_pencil_animation";
310 ot->
description =
"Bake Grease Pencil object transform to Grease Pencil keyframes";
318 RNA_def_int(ot->
srna,
"frame_start", 1, 1, 100000,
"Start Frame",
"The start frame", 1, 100000);
321 ot->
srna,
"frame_end", 250, 1, 100000,
"End Frame",
"The end frame of animation", 1, 100000);
324 RNA_def_int(ot->
srna,
"step", 1, 1, 100,
"Step",
"Step between generated frames", 1, 100);
329 "Only Selected Keyframes",
330 "Convert only selected keyframes");
332 ot->
srna,
"frame_target", 1, 1, 100000,
"Target Frame",
"Destination frame", 1, 100000);
340 "Reproject the strokes using the X-Z plane"},
341 {int(
ReprojectMode::Side),
"SIDE", 0,
"Side",
"Reproject the strokes using the Y-Z plane"},
342 {int(
ReprojectMode::Top),
"TOP", 0,
"Top",
"Reproject the strokes using the X-Y plane"},
347 "Reproject the strokes to end up on the same plane, as if drawn from the current "
349 "using 'Cursor' Stroke Placement"},
354 "Reproject the strokes using the orientation of 3D cursor"},
355 {0,
nullptr, 0,
nullptr,
nullptr},
360 rna_grease_pencil_reproject_type_items,
Functions to work with AnimData.
#define CTX_DATA_BEGIN(C, Type, instance, member)
Low-level operations for curves.
General operations, lookup, etc. for materials.
constexpr IndexRange()=default
constexpr IndexRange index_range() const
void append(const T &value)
GAttributeReader lookup_or_default(StringRef name, AttrDomain domain, AttrType data_type, const void *default_value=nullptr) const
AttributeAccessor attributes() const
IndexRange curves_range() const
bke::CurvesGeometry & strokes_for_write()
const bke::CurvesGeometry & strokes() const
DrawingPlacement()=default
VecBase< float, D > step(VecOp< float, D >, VecOp< float, D >) RET
Span< FCurve * > fcurves_for_assigned_action(AnimData *adt)
static Vector< Object * > get_bake_targets(bContext &C, Depsgraph &depsgraph)
static wmOperatorStatus bake_grease_pencil_animation_exec(bContext *C, wmOperator *op)
static wmOperatorStatus bake_grease_pencil_animation_invoke(bContext *C, wmOperator *op, const wmEvent *)
static Set< int > get_selected_object_keyframes(Span< Object * > bake_targets)
static bool bake_grease_pencil_animation_poll(bContext *C)
static void GREASE_PENCIL_OT_bake_grease_pencil_animation(wmOperatorType *ot)
static void ensure_valid_frame_end(Main *, Scene *, PointerRNA *ptr)
Object * add_type(bContext *C, int type, const char *name, const float loc[3], const float rot[3], bool enter_editmode, unsigned short local_view_bits) ATTR_NONNULL(1) ATTR_RETURNS_NONNULL
CartesianBasis invert(const CartesianBasis &basis)
void transform_points(const float4x4 &transform, MutableSpan< float3 > points, bool use_threading=true)
void parallel_for(const IndexRange range, const int64_t grain_size, const Function &function, const TaskSizeHints &size_hints=detail::TaskSizeHints_Static(1))
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void WM_operatortype_append(void(*opfunc)(wmOperatorType *))
void BKE_scene_graph_update_for_newframe(Depsgraph *depsgraph)
ScrArea * CTX_wm_area(const bContext *C)
int RNA_enum_get(PointerRNA *ptr, const char *name)
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
bool BKE_object_material_slot_add(Main *bmain, Object *ob, bool set_active=true)
Material * BKE_object_material_get(Object *ob, short act)
void RNA_int_set(PointerRNA *ptr, const char *name, int value)
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, const int default_value, const char *ui_name, const char *ui_description)
void ED_operatortypes_grease_pencil_bake_animation()
int RNA_int_get(PointerRNA *ptr, const char *name)
void BKE_object_material_assign(Main *bmain, Object *ob, Material *ma, short act, int assign_type)
MatBase< float, 4, 4 > float4x4
void RNA_property_int_set(PointerRNA *ptr, PropertyRNA *prop, int value)
AnimData * BKE_animdata_from_id(const ID *id)
void DEG_id_tag_update(ID *id, unsigned int flags)
T * DEG_get_evaluated(const Depsgraph *depsgraph, T *id)
void object_duplilist(Depsgraph *depsgraph, Object *ob, Set< const Object * > *include_objects, DupliList &r_duplilist)
Depsgraph * CTX_data_ensure_evaluated_depsgraph(const bContext *C, bool rna_write_check=false)
@ BKE_MAT_ASSIGN_USERPREF
VectorList< DupliObject > DupliList
wmOperatorStatus WM_operator_props_dialog_popup(bContext *C, wmOperator *op, int width, std::optional< std::string > title, std::optional< std::string > confirm_text, const bool cancel_default, std::optional< std::string > message, const bool show_icon)
int BKE_object_material_index_get(Object *ob, const Material *ma)
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
PropertyRNA * RNA_def_int(StructOrFunctionRNA *cont_, const char *identifier, const int default_value, const int hardmin, const int hardmax, const char *ui_name, const char *ui_description, const int softmin, const int softmax)
Main * CTX_data_main(const bContext *C)
void RNA_def_property_update_runtime(PropertyRNA *prop, RNAPropertyUpdateFunc func)
void DEG_relations_tag_update(Main *bmain)
Scene * CTX_data_scene(const bContext *C)
VecBase< float, 3 > float3
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
int RNA_property_int_get(PointerRNA *ptr, PropertyRNA *prop)
void WM_cursor_wait(bool val)
Object * CTX_data_active_object(const bContext *C)
float DEG_get_ctime(const Depsgraph *graph)
ARegion * CTX_wm_region(const bContext *C)
bool RNA_property_is_set(PointerRNA *ptr, PropertyRNA *prop)
View3D * CTX_wm_view3d(const bContext *C)
unsigned short local_view_uid
MutableVArraySpan< T > span
wmOperatorStatus(*) exec(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
bool(*) poll(bContext *C) ATTR_WARN_UNUSED_RESULT
wmOperatorStatus(*) invoke(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT