Commit: 4e3a364241b7ead53d2a29b2d10fa2435d73f286
Author: Antonio Vazquez
Date: Sat Aug 1 19:36:55 2020 +0200
Branches: greasepencil-object
https://developer.blender.org/rB4e3a364241b7ead53d2a29b2d10fa2435d73f286
GPencil: Add clipping camera exporting to SVG
===================================================================
M source/blender/editors/io/io_gpencil.c
M source/blender/io/gpencil/gpencil_io_exporter.h
M source/blender/io/gpencil/intern/gpencil_io_svg.cc
===================================================================
diff --git a/source/blender/editors/io/io_gpencil.c
b/source/blender/editors/io/io_gpencil.c
index a1de0f3d9d5..d24d9236add 100644
--- a/source/blender/editors/io/io_gpencil.c
+++ b/source/blender/editors/io/io_gpencil.c
@@ -169,12 +169,14 @@ static int wm_gpencil_export_exec(bContext *C, wmOperator
*op)
const bool use_fill = RNA_boolean_get(op->ptr, "use_fill");
const bool use_norm_thickness = RNA_boolean_get(op->ptr,
"use_normalized_thickness");
const bool use_selected_objects = RNA_boolean_get(op->ptr,
"use_selected_objects");
+ const bool use_clip_camera = RNA_boolean_get(op->ptr, "use_clip_camera");
/* Set flags. */
int flag = 0;
SET_FLAG_FROM_TEST(flag, use_fill, GP_EXPORT_FILL);
SET_FLAG_FROM_TEST(flag, use_norm_thickness, GP_EXPORT_NORM_THICKNESS);
SET_FLAG_FROM_TEST(flag, use_selected_objects, GP_EXPORT_SELECTED_OBJECTS);
+ SET_FLAG_FROM_TEST(flag, use_clip_camera, GP_EXPORT_CLIP_CAMERA);
struct GpencilExportParams params = {
.C = C,
@@ -266,6 +268,7 @@ static void ui_gpencil_export_settings(uiLayout *layout,
PointerRNA *imfptr)
sub = uiLayoutColumn(col, true);
uiItemR(sub, imfptr, "use_fill", 0, NULL, ICON_NONE);
uiItemR(sub, imfptr, "use_normalized_thickness", 0, NULL, ICON_NONE);
+ uiItemR(sub, imfptr, "use_clip_camera", 0, NULL, ICON_NONE);
}
static void wm_gpencil_export_draw(bContext *C, wmOperator *op)
@@ -377,6 +380,11 @@ void WM_OT_gpencil_export(wmOperatorType *ot)
true,
"All Selected Objects",
"Export all selected objects, unselect for export active
object only");
+ RNA_def_boolean(ot->srna,
+ "use_clip_camera",
+ false,
+ "Clip Camera",
+ "Clip drawings to camera size when export in camera view");
/* This dummy prop is used to check whether we need to init the start and
* end frame values to that of the scene's, otherwise they are reset at
diff --git a/source/blender/io/gpencil/gpencil_io_exporter.h
b/source/blender/io/gpencil/gpencil_io_exporter.h
index edfbbc57222..7cbd0b460d5 100644
--- a/source/blender/io/gpencil/gpencil_io_exporter.h
+++ b/source/blender/io/gpencil/gpencil_io_exporter.h
@@ -58,6 +58,8 @@ typedef enum eGpencilExportParams_Flag {
GP_EXPORT_NORM_THICKNESS = (1 << 1),
/* Export all selected objects. */
GP_EXPORT_SELECTED_OBJECTS = (1 << 2),
+ /* Clip camera area. */
+ GP_EXPORT_CLIP_CAMERA = (1 << 3),
} eGpencilExportParams_Flag;
bool gpencil_io_export(const struct GpencilExportParams *params);
diff --git a/source/blender/io/gpencil/intern/gpencil_io_svg.cc
b/source/blender/io/gpencil/intern/gpencil_io_svg.cc
index 279aa4860c2..10bf8c7973a 100644
--- a/source/blender/io/gpencil/intern/gpencil_io_svg.cc
+++ b/source/blender/io/gpencil/intern/gpencil_io_svg.cc
@@ -123,20 +123,19 @@ void GpencilExporterSVG::create_document_header(void)
std::string viewbox = "0 0 " + width + " " + height;
main_node.append_attribute("viewBox").set_value(viewbox.c_str());
-#if 0 /* TODO: Do we need camera border? */
/* Camera border. */
- if (is_camera_mode()) {
- pugi::xml_node cam_node = main_node.append_child("rect");
- cam_node.append_attribute("stroke").set_value("#FF0000");
- cam_node.append_attribute("stroke-width").set_value("10");
- cam_node.append_attribute("stroke-opacity").set_value("0.5");
- cam_node.append_attribute("fill").set_value("none");
- cam_node.append_attribute("x").set_value(0);
- cam_node.append_attribute("width").set_value((camera_rect_.xmax -
camera_rect_.xmin) * camera_ratio_);
- cam_node.append_attribute("y").set_value(0);
- cam_node.append_attribute("height").set_value((camera_rect_.ymax -
camera_rect_.ymin) * camera_ratio_);
- }
-#endif
+ 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");
+ }
}
/* Main layer loop. */
@@ -147,6 +146,11 @@ void GpencilExporterSVG::export_layers(void)
pugi::xml_node ob_node = main_node.append_child("g");
ob_node.append_attribute("id").set_value(ob->id.name + 2);
+ /* Clip area. */
+ if (is_camera_mode() && ((params_.flag & GP_EXPORT_CLIP_CAMERA) != 0)) {
+ ob_node.append_attribute("clip-path").set_value("url(#clip-path)");
+ }
+
/* 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;
_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs