38 #include "pugixml.hpp"
40 namespace blender ::io ::gpencil {
43 GpencilExporterSVG::GpencilExporterSVG(
const char *filepath,
const GpencilIOParams *iparams)
54 create_document_header();
60 export_gpencil_layers();
73 std::wstring wstr(filepath_cstr_16);
74 result = main_doc_.save_file(wstr.c_str());
84 void GpencilExporterSVG::create_document_header()
87 pugi::xml_node decl = main_doc_.prepend_child(pugi::node_declaration);
88 decl.append_attribute(
"version") =
"1.0";
89 decl.append_attribute(
"encoding") =
"UTF-8";
91 pugi::xml_node comment = main_doc_.append_child(pugi::node_comment);
94 comment.set_value(txt);
96 pugi::xml_node doctype = main_doc_.append_child(pugi::node_doctype);
98 "svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" "
99 "\"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\"");
101 main_node_ = main_doc_.append_child(
"svg");
102 main_node_.append_attribute(
"version").set_value(
"1.0");
103 main_node_.append_attribute(
"x").set_value(
"0px");
104 main_node_.append_attribute(
"y").set_value(
"0px");
105 main_node_.append_attribute(
"xmlns").set_value(
"http://www.w3.org/2000/svg");
113 main_node_.append_attribute(
"width").set_value((
width +
"px").c_str());
114 main_node_.append_attribute(
"height").set_value((
height +
"px").c_str());
115 std::string viewbox =
"0 0 " +
width +
" " +
height;
116 main_node_.append_attribute(
"viewBox").set_value(viewbox.c_str());
119 void GpencilExporterSVG::export_gpencil_layers()
131 pugi::xml_node clip_node = main_node_.append_child(
"clipPath");
137 frame_node_ = main_node_.append_child(
"g");
139 frame_node_.append_attribute(
"id").set_value(frametxt.c_str());
143 frame_node_.append_attribute(
"clip-path")
147 pugi::xml_node ob_node = frame_node_.append_child(
"g");
150 sprintf(obtxt,
"blender_object_%s", ob->
id.
name + 2);
151 ob_node.append_attribute(
"id").set_value(obtxt);
164 if ((gpf ==
nullptr) || (gpf->
strokes.
first ==
nullptr)) {
169 std::string txt =
"Layer: ";
170 txt.append(gpl->info);
171 ob_node.append_child(pugi::node_comment).set_value(txt.c_str());
173 pugi::xml_node node_gpl = ob_node.append_child(
"g");
174 node_gpl.append_attribute(
"id").set_value(gpl->info);
177 if (gps->totpoints < 2) {
188 gps_duplicate->
mat_nr + 1);
198 gps_duplicate->
thickness += gpl->line_change;
210 export_stroke_to_polyline(gpl, gps_duplicate, node_gpl, is_stroke,
true);
216 export_stroke_to_polyline(gpl, gps_duplicate, node_gpl, is_stroke,
false);
227 export_stroke_to_path(gpl, gps_perimeter, node_gpl,
false);
239 void GpencilExporterSVG::export_stroke_to_path(
bGPDlayer *gpl,
241 pugi::xml_node node_gpl,
244 pugi::xml_node node_gps = node_gpl.append_child(
"path");
247 std::string stroke_hex;
254 node_gps.append_attribute(
"fill-opacity")
261 stroke_hex = rgb_to_hexstr(
col);
263 node_gps.append_attribute(
"fill").set_value(stroke_hex.c_str());
264 node_gps.append_attribute(
"stroke").set_value(
"none");
266 std::string txt =
"M";
267 for (
const int i : IndexRange(gps->
totpoints)) {
280 node_gps.append_attribute(
"d").set_value(txt.c_str());
283 void GpencilExporterSVG::export_stroke_to_polyline(
bGPDlayer *gpl,
285 pugi::xml_node node_gpl,
286 const bool is_stroke,
295 gps_temp->
points = MEM_new<bGPDspoint>(
"gp_stroke_points");
305 pugi::xml_node node_gps = node_gpl.append_child(do_fill || cyclic ?
"polygon" :
"polyline");
307 color_string_set(gpl, gps, node_gps, do_fill);
309 if (is_stroke && !do_fill) {
310 node_gps.append_attribute(
"stroke-width").set_value((radius * 2.0f) - gpl->
line_change);
314 for (
const int i : IndexRange(gps->
totpoints)) {
323 node_gps.append_attribute(
"points").set_value(txt.c_str());
326 void GpencilExporterSVG::color_string_set(
bGPDlayer *gpl,
328 pugi::xml_node node_gps,
338 std::string stroke_hex = rgb_to_hexstr(
col);
339 node_gps.append_attribute(
"fill").set_value(stroke_hex.c_str());
340 node_gps.append_attribute(
"stroke").set_value(
"none");
346 std::string stroke_hex = rgb_to_hexstr(
col);
347 node_gps.append_attribute(
"stroke").set_value(stroke_hex.c_str());
348 node_gps.append_attribute(
"stroke-opacity")
352 node_gps.append_attribute(
"fill").set_value(
"none");
353 node_gps.append_attribute(
"stroke-linecap").set_value(round_cap ?
"round" :
"square");
356 node_gps.append_attribute(
"fill").set_value(stroke_hex.c_str());
368 std::string hexcolor)
370 pugi::xml_node rect_node =
node.append_child(
"rect");
371 rect_node.append_attribute(
"x").set_value(
x);
372 rect_node.append_attribute(
"y").set_value(
y);
373 rect_node.append_attribute(
"width").set_value(
width);
374 rect_node.append_attribute(
"height").set_value(
height);
375 rect_node.append_attribute(
"fill").set_value(
"none");
376 if (thickness > 0.0f) {
377 rect_node.append_attribute(
"stroke").set_value(hexcolor.c_str());
378 rect_node.append_attribute(
"stroke-width").set_value(thickness);
387 std::string hexcolor)
389 pugi::xml_node nodetxt =
node.append_child(
"text");
391 nodetxt.append_attribute(
"x").set_value(
x);
392 nodetxt.append_attribute(
"y").set_value(
y);
394 nodetxt.append_attribute(
"font-size").set_value(
size);
395 nodetxt.append_attribute(
"fill").set_value(hexcolor.c_str());
396 nodetxt.text().set(text.c_str());
399 std::string GpencilExporterSVG::rgb_to_hexstr(
const float color[3])
405 sprintf(hex_string,
"#%02X%02X%02X",
r,
g,
b);
407 std::string hexstr = hex_string;
struct bGPDstroke * BKE_gpencil_stroke_duplicate(struct bGPDstroke *gps_src, bool dup_points, bool dup_curve)
#define GPENCIL_ALPHA_OPACITY_THRESH
void BKE_gpencil_free_stroke(struct bGPDstroke *gps)
float BKE_gpencil_stroke_average_pressure_get(struct bGPDstroke *gps)
struct bGPDstroke * BKE_gpencil_stroke_perimeter_from_view(struct RegionView3D *rv3d, struct bGPdata *gpd, const struct bGPDlayer *gpl, struct bGPDstroke *gps, int subdivisions, const float diff_mat[4][4])
bool BKE_gpencil_stroke_sample(struct bGPdata *gpd, struct bGPDstroke *gps, const float dist, const bool select, const float sharp_threshold)
bool BKE_gpencil_stroke_is_pressure_constant(struct bGPDstroke *gps)
General operations, lookup, etc. for materials.
struct MaterialGPencilStyle * BKE_gpencil_material_settings(struct Object *ob, short act)
#define LISTBASE_FOREACH(type, var, list)
MINLINE void linearrgb_to_srgb_v3_v3(float srgb[3], const float linear[3])
float mat4_to_scale(const float M[4][4])
MINLINE void copy_v3_v3(float r[3], const float a[3])
void interp_v3_v3v3(float r[3], const float a[3], const float b[3], float t)
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, size_t maxncpy) ATTR_NONNULL()
struct ID * DEG_get_evaluated_id(const struct Depsgraph *depsgraph, struct ID *id)
@ GP_MATERIAL_STROKE_SHOW
Object is a sort of wrapper for general info.
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble w _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat w _GL_VOID_RET _GL_VOID GLint GLint GLint w _GL_VOID_RET _GL_VOID GLshort GLshort GLshort w _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble y2 _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat y2 _GL_VOID_RET _GL_VOID GLint GLint GLint y2 _GL_VOID_RET _GL_VOID GLshort GLshort GLshort y2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLuint *buffer _GL_VOID_RET _GL_VOID GLdouble t _GL_VOID_RET _GL_VOID GLfloat t _GL_VOID_RET _GL_VOID GLint t _GL_VOID_RET _GL_VOID GLshort t _GL_VOID_RET _GL_VOID GLdouble GLdouble r _GL_VOID_RET _GL_VOID GLfloat GLfloat r _GL_VOID_RET _GL_VOID GLint GLint r _GL_VOID_RET _GL_VOID GLshort GLshort r _GL_VOID_RET _GL_VOID GLdouble GLdouble r
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei height
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint y
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei width
Group Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value Generate a normal vector and a dot product Bright Control the brightness and contrast of the input color Vector Map an input vectors to used to fine tune the interpolation of the input Camera Retrieve information about the camera and how it relates to the current shading point s position Clamp a value between a minimum and a maximum Vector Perform vector math operation Invert a color
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
static void add_rect(pugi::xml_node node, float x, float y, float width, float height, float thickness, std::string hexcolor)
static void add_text(pugi::xml_node node, float x, float y, std::string text, float size, std::string hexcolor)
void filepath_set(const char *filepath)
float stroke_point_radius_get(struct bGPDlayer *gpl, struct bGPDstroke *gps)
blender::Vector< ObjectZ > ob_list_
struct Depsgraph * depsgraph_
void create_object_list()
struct RegionView3D * rv3d_
void prepare_stroke_export_colors(struct Object *ob, struct bGPDstroke *gps)
float2 gpencil_3D_point_to_2D(const float3 co)
float stroke_average_opacity_get()
void prepare_layer_export_matrix(struct Object *ob, struct bGPDlayer *gpl)
@ GP_EXPORT_NORM_THICKNESS
#define SVG_EXPORTER_NAME
#define SVG_EXPORTER_VERSION
bool ED_gpencil_stroke_material_visible(Object *ob, const bGPDstroke *gps)
std::string to_string(const T &n)
static const pxr::TfToken b("b", pxr::TfToken::Immortal)
static const pxr::TfToken g("g", pxr::TfToken::Immortal)
#define UTF16_ENCODE(in8str)
#define UTF16_UN_ENCODE(in8str)