GPencil: Add operator to create new grease pencil object #108462

Merged
Falk David merged 7 commits from filedescriptor/blender:gp-add-stroke into main 2023-05-31 18:00:32 +02:00
Member

This adds the operator OBJECT_OT_grease_pencil_add to create a new grease pencil object.

Currently it supports the EMPTY and STROKE type.

This also replaces the add menu for the legacy grease pencil type in the Shift+A menu.

This adds the operator `OBJECT_OT_grease_pencil_add` to create a new grease pencil object. Currently it supports the `EMPTY` and `STROKE` type. This also replaces the add menu for the legacy grease pencil type in the Shift+A menu.
Falk David added 3 commits 2023-05-31 15:41:46 +02:00
Falk David added this to the (deleted) project 2023-05-31 15:42:32 +02:00
Hans Goudey requested changes 2023-05-31 15:49:08 +02:00
@ -0,0 +22,4 @@
namespace blender::ed::greasepencil {
typedef struct ColorTemplate {
Member

typedef is unnecessary in C++ code

`typedef` is unnecessary in C++ code
filedescriptor marked this conversation as resolved
@ -0,0 +73,4 @@
#define POINT_SIZE 5
static std::array<float, 175 *POINT_SIZE> stroke_data = {
Member

Does it still make sense to store multiple attributes grouped together like this? What about having one static array for each attribute?

Does it still make sense to store multiple attributes grouped together like this? What about having one static array for each attribute?
Author
Member

I was thinking to do that, but didn't want to mess with the static data. I think this is fine for now.

I was thinking to do that, but didn't want to mess with the static data. I think this is fine for now.
filedescriptor marked this conversation as resolved
@ -0,0 +187,4 @@
const Span<int> offsets,
const Span<int> materials,
const Span<int> radii_factor,
float4x4 matrix)
Member

Pass float4x4 by const reference

Pass `float4x4` by const reference
filedescriptor marked this conversation as resolved
@ -0,0 +243,4 @@
grease_pencil.add_empty_drawings(1);
GreasePencilFrame frame{.drawing_index = 0, .flag = 0, .type = BEZT_KEYTYPE_KEYFRAME};
Member

Designated initializers can't be used in C++

Designated initializers can't be used in C++
Author
Member

Hm this compiles for me. What should I be using instead?

Hm this compiles for me. What should I be using instead?
Member

It won't on windows.

GreasePencilFrame frame{};
frame.drawing_index = 0;
...
It won't on windows. ``` GreasePencilFrame frame{}; frame.drawing_index = 0; ... ```
filedescriptor marked this conversation as resolved
@ -0,0 +247,4 @@
new_layer.insert_frame(frame_numer, std::move(frame));
}
void create_stroke(Main &bmain, Object &object, float4x4 matrix, int frame_numer)
Member

int frame_numer -> const int frame_numer

`int frame_numer` -> `const int frame_numer`
filedescriptor marked this conversation as resolved
Falk David added 1 commit 2023-05-31 17:33:10 +02:00
Falk David added 1 commit 2023-05-31 17:33:50 +02:00
Falk David added 1 commit 2023-05-31 17:35:49 +02:00
Falk David requested review from Hans Goudey 2023-05-31 17:36:15 +02:00
Hans Goudey requested changes 2023-05-31 17:48:35 +02:00
@ -0,0 +275,4 @@
GreasePencilDrawing &drawing = *reinterpret_cast<GreasePencilDrawing *>(
grease_pencil.drawings_for_write()[1]);
std::array stroke_offsets{0, 175};
Member

If you like it better too, you could put these directly in the arguments like so:

  drawing.geometry.wrap() = create_drawing_data(stroke_positions,
                                                stroke_radii,
                                                stroke_opacities,
                                                {0, 175},
                                                {material_index},
                                                {75},
                                                matrix);
If you like it better too, you could put these directly in the arguments like so: ``` drawing.geometry.wrap() = create_drawing_data(stroke_positions, stroke_radii, stroke_opacities, {0, 175}, {material_index}, {75}, matrix); ```
filedescriptor marked this conversation as resolved
@ -0,0 +285,4 @@
materials,
radii_factor,
matrix);
drawing.tag_positions_changed();
Member

Typically tagging caches changes shouldn't be necessary when creating something from scratch, since the caches start out dirty. I've found skipping it to work fine in curve code and it saves a fair amount of boilerplate.

Typically tagging caches changes shouldn't be necessary when creating something from scratch, since the caches start out dirty. I've found skipping it to work fine in curve code and it saves a fair amount of boilerplate.
filedescriptor marked this conversation as resolved
@ -0,0 +289,4 @@
GreasePencilFrame frame_lines{0, 0, BEZT_KEYTYPE_KEYFRAME};
GreasePencilFrame frame_color{1, 0, BEZT_KEYTYPE_KEYFRAME};
layer_lines.insert_frame(frame_numer, std::move(frame_lines));
Member

std::move won't do anything here, since GreasePencilFrame is a trivial struct

`std::move` won't do anything here, since `GreasePencilFrame` is a trivial struct
filedescriptor marked this conversation as resolved
@ -1579,0 +1635,4 @@
}
case GP_STROKE: {
float radius = RNA_float_get(op->ptr, "radius");
float scale[3];
Member

const float3 scale(radius);

`const float3 scale(radius);`
filedescriptor marked this conversation as resolved
@ -1579,0 +1639,4 @@
copy_v3_fl(scale, radius);
float mat[4][4];
ED_object_new_primitive_matrix(C, object, loc, rot, scale, mat);
Member

This should work here:

float4x4 mat;
ED_object_new_primitive_matrix(C, object, loc, rot, scale, mat.ptr());
This should work here: ``` float4x4 mat; ED_object_new_primitive_matrix(C, object, loc, rot, scale, mat.ptr()); ```
filedescriptor marked this conversation as resolved
Falk David added 1 commit 2023-05-31 17:54:07 +02:00
Falk David requested review from Hans Goudey 2023-05-31 17:54:26 +02:00
Hans Goudey approved these changes 2023-05-31 17:57:19 +02:00
Falk David merged commit b14cdb440a into main 2023-05-31 18:00:31 +02:00
Falk David deleted branch gp-add-stroke 2023-05-31 18:00:34 +02:00
Falk David modified the project from (deleted) to Grease Pencil 2023-05-31 18:01:54 +02:00
Sign in to join this conversation.
No reviewers
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#108462
No description provided.