Initial Grease Pencil 3.0 stage #106848

Merged
Falk David merged 224 commits from filedescriptor/blender:grease-pencil-v3 into main 2023-05-30 11:14:22 +02:00
3 changed files with 75 additions and 37 deletions
Showing only changes of commit 1549aeabd8 - Show all commits

View File

@ -17,37 +17,6 @@ class GreasePencilLayerRuntime {
Map<int, int> frames;
};
// class GreasePencilLayer : ::GreasePencilLayer {
// public:
// GreasePencilLayer();
// GreasePencilLayer(const GreasePencilLayer &other);
// GreasePencilLayer(GreasePencilLayer &&other);
// GreasePencilLayer &operator=(const GreasePencilLayer &other);
// GreasePencilLayer &operator=(GreasePencilLayer &&other);
// ~GreasePencilLayer();
// /* --------------------------------------------------------------------
// * Accessors.
// */
// int frames_num() const;
// };
class GreasePencil : ::GreasePencil {
public:
GreasePencil() = delete;
GreasePencil(const GreasePencil &other);
GreasePencil(GreasePencil &&other);
GreasePencil &operator=(const GreasePencil &other);
GreasePencil &operator=(GreasePencil &&other);
~GreasePencil();
/* --------------------------------------------------------------------
* Accessors.
*/
Span<GreasePencilDrawingOrReference> drawings() const;
};
} // namespace blender::bke

View File

@ -5,8 +5,11 @@
*/
#include "BKE_anim_data.h"
#include "BKE_curves.hh"
#include "BKE_customdata.h"
#include "BKE_grease_pencil.hh"
#include "BKE_idtype.h"
#include "BKE_lib_id.h"
#include "BKE_lib_query.h"
#include "BLI_span.hh"
@ -22,6 +25,9 @@
#include "MEM_guardedalloc.h"
using blender::Span;
using blender::Vector;
static void grease_pencil_init_data(ID *id)
{
}
@ -52,10 +58,73 @@ static void grease_pencil_foreach_id(ID *id, LibraryForeachIDData *data)
static void grease_pencil_blend_write(BlendWriter *writer, ID *id, const void *id_address)
{
GreasePencil *grease_pencil = (GreasePencil *)id;
/* TODO: Flush runtime data to storage. */
/* Write LibData */
BLO_write_id_struct(writer, GreasePencil, id_address, &grease_pencil->id);
BKE_id_blend_write(writer, &grease_pencil->id);
/* Drawings. */
for (int i = 0; i < grease_pencil->drawing_array_size; i++) {
GreasePencilDrawingOrReference *drawing_or_ref = grease_pencil->drawing_array[i];
BLO_write_struct(writer, GreasePencilDrawingOrReference, drawing_or_ref);
switch (drawing_or_ref->type) {
case GREASE_PENCIL_DRAWING: {
GreasePencilDrawing *drawing = reinterpret_cast<GreasePencilDrawing *>(drawing_or_ref);
drawing->geometry.wrap().blend_write(writer, &grease_pencil->id);
break;
}
case GREASE_PENCIL_DRAWING_REFERENCE: {
GreasePencilDrawingReference *drawing_reference =
reinterpret_cast<GreasePencilDrawingReference *>(drawing_or_ref);
BLO_write_raw(writer, sizeof(void *), drawing_reference->id_reference);
break;
}
}
}
for (int i = 0; i < grease_pencil->layer_tree_storage.nodes_num; i++) {
GreasePencilLayerTreeNode *node = grease_pencil->layer_tree_storage.nodes[i];
BLO_write_struct(writer, GreasePencilLayerTreeNode, node);
switch (node->type) {
case GREASE_PENCIL_LAYER_TREE_LEAF: {
GreasePencilLayerTreeLeaf *node_leaf = reinterpret_cast<GreasePencilLayerTreeLeaf *>(node);
/* Write layer data. */
BLO_write_int32_array(
writer, node_leaf->layer.frames_storage.size, node_leaf->layer.frames_storage.keys);
BLO_write_int32_array(
writer, node_leaf->layer.frames_storage.size, node_leaf->layer.frames_storage.values);
break;
}
case GREASE_PENCIL_LAYER_TREE_GROUP: {
GreasePencilLayerTreeGroup *group = reinterpret_cast<GreasePencilLayerTreeGroup *>(node);
BLO_write_raw(writer, sizeof(int), &group->children_num);
break;
}
}
}
/* Materials. */
BLO_write_pointer_array(
writer, grease_pencil->material_array_size, grease_pencil->material_array);
/* Animation data. */
filedescriptor marked this conversation as resolved Outdated

This cannot be 'just' copied like that, would assign the same batch_cache value to both copies e.g.

In general runtime data should not need to be copied anyway.

This cannot be 'just' copied like that, would assign the same `batch_cache` value to both copies e.g. In general runtime data should not need to be copied anyway.
if (grease_pencil->adt) {
BKE_animdata_blend_write(writer, grease_pencil->adt);
}
}
static void grease_pencil_blend_read_data(BlendDataReader *reader, ID *id)
{
GreasePencil *grease_pencil = (GreasePencil *)id;
/* TODO: Convert storage data to runtime structs. */
BLO_read_data_address(reader, &grease_pencil->adt);

These two lines could use MEM_SAFE_FREE macro instead.

These two lines could use `MEM_SAFE_FREE` macro instead.

MEM_SAFE_FREE does not replace MEM_delete, it replaces MEM_freeN, which is different.

`MEM_SAFE_FREE` does not replace `MEM_delete`, it replaces `MEM_freeN`, which is different.

I was under the impression that any memory allocated with MEM_new should use MEM_delete because we also need to run the destructor.

I was under the impression that any memory allocated with `MEM_new` should use `MEM_delete` because we also need to run the destructor.
BKE_animdata_blend_read_data(reader, grease_pencil->adt);
}
static void grease_pencil_blend_read_lib(BlendLibReader *reader, ID *id)
@ -100,7 +169,7 @@ IDTypeInfo IDType_ID_GP = {
/*lib_override_apply_post*/ nullptr,
};
blender::Span<GreasePencilDrawingOrReference> blender::bke::GreasePencil::drawings() const
{
return blender::Span<GreasePencilDrawingOrReference>{this->drawing_array, this->drawing_array_size};
}
// Span<GreasePencilDrawingOrReference> blender::bke::GreasePencil::drawings() const

C++ cast here

C++ cast here
// {
// return Span<GreasePencilDrawingOrReference>{this->drawing_array, this->drawing_array_size};
// }
filedescriptor marked this conversation as resolved Outdated

Code is missing re-reading active_layer address...

Code is missing re-reading `active_layer` address...

View File

@ -179,10 +179,10 @@ typedef struct GreasePencil {
/**
* An array of GreasePencilDrawing's.
*/
GreasePencilDrawingOrReference *drawing_array;
GreasePencilDrawingOrReference **drawing_array;
int drawing_array_size;

Pretty sure null-terminated goes without saying for char * pointers in DNA, I don't think it's worth mentioning here

Pretty sure null-terminated goes without saying for `char *` pointers in DNA, I don't think it's worth mentioning here

Not sure about dynamic names for strings. It is not something typically used in the DNA.

Not sure about dynamic names for strings. It is not something typically used in the DNA.

It's been done more recently I think. It's properly integrated with RNA now too, to avoid that boilerplate. It's nice not to have to worry about choosing a future-proof length.

It's been done more recently I think. It's properly integrated with RNA now too, to avoid that boilerplate. It's nice not to have to worry about choosing a future-proof length.
#ifdef __cplusplus
blender::Span<GreasePencilDrawingOrReference> drawings() const;
blender::Span<GreasePencilDrawingOrReference *> drawings() const;
#endif
char _pad[4];