[Bf-blender-cvs] [47470b67afc] greasepencil-object: GPencil: Export SVG using size of the boundbox if not using camera
Antonio Vazquez
noreply at git.blender.org
Mon Aug 3 12:34:42 CEST 2020
Commit: 47470b67afcb362d967b3e15508798686650294a
Author: Antonio Vazquez
Date: Mon Aug 3 12:29:59 2020 +0200
Branches: greasepencil-object
https://developer.blender.org/rB47470b67afcb362d967b3e15508798686650294a
GPencil: Export SVG using size of the boundbox if not using camera
===================================================================
M source/blender/io/gpencil/gpencil_io_exporter.h
M source/blender/io/gpencil/intern/gpencil_io_base.cc
M source/blender/io/gpencil/intern/gpencil_io_base.h
M source/blender/io/gpencil/intern/gpencil_io_capi.cc
M source/blender/io/gpencil/intern/gpencil_io_svg.cc
M source/blender/io/gpencil/intern/gpencil_io_svg.h
===================================================================
diff --git a/source/blender/io/gpencil/gpencil_io_exporter.h b/source/blender/io/gpencil/gpencil_io_exporter.h
index 20d488231f5..8a926506be5 100644
--- a/source/blender/io/gpencil/gpencil_io_exporter.h
+++ b/source/blender/io/gpencil/gpencil_io_exporter.h
@@ -47,6 +47,8 @@ struct GpencilExportParams {
double frame_end;
/** Frame subfix. */
char frame[5];
+ /* Current frame. */
+ int cfra;
/** Flags. */
int flag;
/** Stroke sampling. */
diff --git a/source/blender/io/gpencil/intern/gpencil_io_base.cc b/source/blender/io/gpencil/intern/gpencil_io_base.cc
index fa925f87b7a..adbeb32aa20 100644
--- a/source/blender/io/gpencil/intern/gpencil_io_base.cc
+++ b/source/blender/io/gpencil/intern/gpencil_io_base.cc
@@ -71,19 +71,31 @@ GpencilExporter::GpencilExporter(const struct GpencilExportParams *iparams)
params_.mode = iparams->mode;
params_.flag = iparams->flag;
params_.stroke_sample = iparams->stroke_sample;
+ params_.cfra = iparams->cfra;
/* Easy access data. */
bmain = CTX_data_main(params_.C);
depsgraph = CTX_data_depsgraph_pointer(params_.C);
rv3d = (RegionView3D *)params_.region->regiondata;
gpd = (bGPdata *)params_.obact->data;
+ const bool only_active_frame = ((params_.flag & GP_EXPORT_ACTIVE_FRAME) != 0);
Scene *scene = CTX_data_scene(params_.C);
- render_x_ = (scene->r.xsch * scene->r.size) / 100;
- render_y_ = (scene->r.ysch * scene->r.size) / 100;
+
+ /* Load list of selected objects. */
+ create_object_list();
+
+ winx_ = params_.region->winx;
+ winy_ = params_.region->winy;
+
+ invert_axis_[0] = false;
+ invert_axis_[1] = true;
/* Camera rectangle. */
if (rv3d->persp == RV3D_CAMOB) {
+ render_x_ = (scene->r.xsch * scene->r.size) / 100;
+ render_y_ = (scene->r.ysch * scene->r.size) / 100;
+
ED_view3d_calc_camera_border(CTX_data_scene(params_.C),
depsgraph,
params_.region,
@@ -98,24 +110,35 @@ GpencilExporter::GpencilExporter(const struct GpencilExportParams *iparams)
}
else {
is_camera = false;
- render_x_ = params_.region->winx;
- render_y_ = params_.region->winy;
- camera_ratio_ = 1.0f;
- offset_[0] = 0.0f;
- offset_[1] = 0.0f;
+ if (only_active_frame && (ob_list_.size() == 1)) {
+ /* Calc selected object boundbox. Need set initial value to some variables. */
+ camera_ratio_ = 1.0f;
+ offset_[0] = 0.0f;
+ offset_[1] = 0.0f;
+
+ selected_objects_boundbox();
+ rctf boundbox;
+ get_select_boundbox(&boundbox);
+
+ render_x_ = boundbox.xmax - boundbox.xmin; // winx_;
+ render_y_ = boundbox.ymax - boundbox.ymin; // winy_;
+ offset_[0] = boundbox.xmin;
+ offset_[1] = boundbox.ymin;
+ }
}
- winx_ = params_.region->winx;
- winy_ = params_.region->winy;
-
/* Prepare output filename with full path. */
set_out_filename(params_.filename);
+}
+
+/** Create a list of selected objects sorted from back to front */
+void GpencilExporter::create_object_list(void)
+{
+ ViewLayer *view_layer = CTX_data_view_layer(params_.C);
- /* Load list of selected objects. */
float camera_z_axis[3];
copy_v3_v3(camera_z_axis, rv3d->viewinv[2]);
- ViewLayer *view_layer = CTX_data_view_layer(params_.C);
LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) {
Object *object = base->object;
@@ -153,7 +176,6 @@ GpencilExporter::GpencilExporter(const struct GpencilExportParams *iparams)
[](const ObjectZ &obz1, const ObjectZ &obz2) { return obz1.zdepth < obz2.zdepth; });
}
}
-
/**
* Set output file input_text full path.
* \param C: Context.
@@ -419,23 +441,25 @@ bool GpencilExporter::is_camera_mode(void)
/* Calc selected strokes boundbox. */
void GpencilExporter::selected_objects_boundbox(void)
{
+ const float gap = 10.0f;
const bGPDspoint *pt;
int i;
+ float screen_co[2];
float r_min[2], r_max[2];
INIT_MINMAX2(r_min, r_max);
for (ObjectZ &obz : ob_list_) {
Object *ob = obz.ob;
/* Use evaluated version to get strokes with modifiers. */
- Object *ob_eval_ = (Object *)DEG_get_evaluated_id(depsgraph, &ob->id);
- bGPdata *gpd_eval = (bGPdata *)ob_eval_->data;
+ Object *ob_eval = (Object *)DEG_get_evaluated_id(depsgraph, &ob->id);
+ bGPdata *gpd_eval = (bGPdata *)ob_eval->data;
LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd_eval->layers) {
if (gpl->flag & GP_LAYER_HIDE) {
continue;
}
- BKE_gpencil_parent_matrix_get(depsgraph, ob, gpl, diff_mat_);
+ BKE_gpencil_parent_matrix_get(depsgraph, ob_eval, gpl, diff_mat_);
bGPDframe *gpf = gpl->actframe;
if (gpf == NULL) {
@@ -448,13 +472,15 @@ void GpencilExporter::selected_objects_boundbox(void)
}
for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) {
/* Convert to 2D. */
- float screen_co[2];
gpencil_3d_point_to_screen_space(&pt->x, screen_co);
minmax_v2v2_v2(r_min, r_max, screen_co);
}
}
}
}
+ /* Add small gap. */
+ add_v2_fl(r_min, gap * -1.0f);
+ add_v2_fl(r_max, gap);
select_box.xmin = r_min[0];
select_box.ymin = r_min[1];
@@ -462,7 +488,7 @@ void GpencilExporter::selected_objects_boundbox(void)
select_box.ymax = r_max[1];
}
-void GpencilExporter::get_select_boundbox(rcti *boundbox)
+void GpencilExporter::get_select_boundbox(rctf *boundbox)
{
boundbox->xmin = select_box.xmin;
boundbox->xmax = select_box.xmax;
diff --git a/source/blender/io/gpencil/intern/gpencil_io_base.h b/source/blender/io/gpencil/intern/gpencil_io_base.h
index 84e3271eb6a..0f2d23886db 100644
--- a/source/blender/io/gpencil/intern/gpencil_io_base.h
+++ b/source/blender/io/gpencil/intern/gpencil_io_base.h
@@ -83,6 +83,7 @@ class GpencilExporter {
float camera_ratio_;
float offset_[2];
rctf camera_rect_;
+ int cfra_;
float stroke_color_[4], fill_color_[4];
@@ -94,12 +95,13 @@ class GpencilExporter {
bool gp_style_is_fill(void);
float stroke_average_opacity(void);
bool is_camera_mode(void);
+ bool is_bound_mode(void);
void gpl_current_set(struct bGPDlayer *gpl);
void gpf_current_set(struct bGPDframe *gpf);
void gps_current_set(struct Object *ob, struct bGPDstroke *gps, const bool set_colors);
- void get_select_boundbox(rcti *boundbox);
+ void get_select_boundbox(rctf *boundbox);
private:
struct bGPDlayer *gpl_cur;
@@ -113,6 +115,7 @@ class GpencilExporter {
rcti select_box;
void set_out_filename(char *filename);
+ void create_object_list(void);
};
} // namespace blender::io::gpencil
diff --git a/source/blender/io/gpencil/intern/gpencil_io_capi.cc b/source/blender/io/gpencil/intern/gpencil_io_capi.cc
index eb428b39e01..499e607c753 100644
--- a/source/blender/io/gpencil/intern/gpencil_io_capi.cc
+++ b/source/blender/io/gpencil/intern/gpencil_io_capi.cc
@@ -102,7 +102,7 @@ bool gpencil_io_export(GpencilExportParams *params)
CFRA = i;
BKE_scene_graph_update_for_newframe(depsgraph, bmain);
sprintf(params->frame, "%04d", i);
-
+ params->cfra = i;
done |= gpencil_io_export_frame(params);
}
}
diff --git a/source/blender/io/gpencil/intern/gpencil_io_svg.cc b/source/blender/io/gpencil/intern/gpencil_io_svg.cc
index 8724d764cd1..284c0f9da7c 100644
--- a/source/blender/io/gpencil/intern/gpencil_io_svg.cc
+++ b/source/blender/io/gpencil/intern/gpencil_io_svg.cc
@@ -66,12 +66,6 @@ GpencilExporterSVG::GpencilExporterSVG(const struct GpencilExportParams *iparams
{
invert_axis_[0] = false;
invert_axis_[1] = true;
-
- /* Calc selected object boundbox. */
- selected_objects_boundbox();
-
- rcti boundbox;
- get_select_boundbox(&boundbox);
}
/* Main write method for SVG format. */
@@ -115,14 +109,8 @@ void GpencilExporterSVG::create_document_header(void)
std::string width;
std::string height;
- if (is_camera_mode()) {
- width = std::to_string(render_x_);
- height = std::to_string(render_y_);
- }
- else {
- width = std::to_string(winx_);
- height = std::to_string(winy_);
- }
+ width = std::to_string(render_x_);
+ height = std::to_string(render_y_);
main_node.append_attribute("width").set_value((width + "px").c_str());
main_node.append_attribute("height").set_value((height + "px").c_str());
@@ -133,14 +121,13 @@ void GpencilExporterSVG::create_document_header(void)
if (is_camera_mode() && ((params_.flag & GP_EXPORT_CLIP_CAMERA) != 0)) {
pugi::xml_node clip_node = main_node.append_child("clipPath");
clip_node.append_attribute("id").set_value("clip-path");
- pugi::xml_node rect_node = clip_node.append_child("rect");
- rect_node.append_attribute("x").set_value(0);
- rect_node.append_attribute("width").set_value((camera_rect_.xmax - camera_rect_.xmin) *
- camera_ratio_);
- rect_node.append_attribute("y").set_value(0);
- rect_node.append_attribute("height").set_value((camera_rect_.ymax - camera_rect_.ymin) *
- camera_ratio_);
- rect_node.append_attribute("fill").set_value("none");
+ create_rect(clip_node,
+ 0,
+ 0,
+ (camera_rect_.xmax - camera_rect_.xmin) * camera_ratio_,
+ (camera_rect_.xmax - camera_rect_.xmin) * camera_ratio_,
+ 0.0f,
+ "#000000");
}
}
@@ -149,7 +136,22 @@ void GpencilExporterSVG::export_layers(void)
{
for (ObjectZ &obz : ob_list_) {
Object *ob = obz.ob;
- pugi::xml_node ob_node = main_node.append_child("g");
+ frame_node = main_node.append_child("g");
+ std::string frametxt = " Frame_ " + std::to_string(params_.cfra);
+ frame_node.append_attribute("id").set_value(frametxt.c_str());
+
+ /* Test */
+ rctf bb;
+ get_select_boundbox(&bb);
+ create_rect(frame_node,
+ bb.xmin - offset_[0],
+ bb.ymin - offset_[1],
+ (bb.xmax - bb.xmin),
+ (bb.ymax - bb.ymin),
+ 5.0f,
+ "#FF0000");
+
+ pugi::xml_node ob_node = frame_node.append_child("g");
ob_node.append_attribute("id").set_value
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list