26#include <fmt/format.h>
47 return fmt::format(
"#{:02X}{:02X}{:02X}", rgb[0], rgb[1], rgb[2]);
52 const float stroke_opacity,
53 const std::optional<float> miter_limit_angle,
60 node.append_attribute(
"stroke").set_value(stroke_hex.c_str());
61 node.append_attribute(
"stroke-opacity").set_value(stroke_color.
a * stroke_opacity);
63 node.append_attribute(
"fill").set_value(
"none");
64 node.append_attribute(
"stroke-linecap").set_value(round_cap ?
"round" :
"square");
66 if (miter_limit_angle) {
68 node.append_attribute(
"stroke-linejoin").set_value(
"round");
71 node.append_attribute(
"stroke-linejoin").set_value(
"bevel");
75 const float miter_limit = 1.0f /
math::sin(*miter_limit_angle / 2.0f);
77 node.append_attribute(
"stroke-linejoin").set_value(
"miter");
78 node.append_attribute(
"stroke-miterlimit").set_value(miter_limit);
85 const float layer_opacity)
91 node.append_attribute(
"fill").set_value(stroke_hex.c_str());
92 node.append_attribute(
"stroke").set_value(
"none");
93 node.append_attribute(
"fill-opacity").set_value(fill_color.
a * layer_opacity);
101 const float thickness,
102 const std::string &hexcolor)
104 pugi::xml_node rect_node =
node.append_child(
"rect");
105 rect_node.append_attribute(
"x").set_value(
x);
106 rect_node.append_attribute(
"y").set_value(
y);
107 rect_node.append_attribute(
"width").set_value(width);
108 rect_node.append_attribute(
"height").set_value(height);
109 rect_node.append_attribute(
"fill").set_value(
"none");
110 if (thickness > 0.0f) {
111 rect_node.append_attribute(
"stroke").set_value(hexcolor.c_str());
112 rect_node.append_attribute(
"stroke-width").set_value(thickness);
119 std::string get_node_uuid_string();
147 std::optional<float> width);
152std::string SVGExporter::get_node_uuid_string()
154 std::string
id = fmt::format(
".uuid_{:#x}", this->_node_uuid++);
160 this->_node_uuid = 0;
164 const int frame_number = scene.
r.
cfra;
178 const int orig_frame = scene.
r.
cfra;
183 if (selection_only) {
207 pugi::xml_node frames_group_node = main_node.append_child(
"g");
208 frames_group_node.append_attribute(
"id").set_value(
"blender_frames");
209 frames_group_node.append_attribute(
"display").set_value(
"none");
211 const int frame_count = frames.
size();
215 scene.
r.
cfra = frame_number;
222 scene.
r.
cfra = orig_frame;
239 std::string frametxt =
"blender_frame." + std::to_string(frame_number);
253 pugi::xml_node clip_node =
node.append_child(
"clipPath");
254 clip_node.append_attribute(
"id").set_value(
255 (
"clip-path." + std::to_string(frame_number)).c_str());
260 pugi::xml_node frame_node =
node.append_child(
"g");
261 frame_node.append_attribute(
"id").set_value(
frame_name(frame_number).c_str());
265 frame_node.append_attribute(
"clip-path")
266 .set_value((
"url(#clip-path." + std::to_string(frame_number) +
")").c_str());
270 const Object *ob = info.object;
272 pugi::xml_node ob_node = frame_node.append_child(
"g");
276 std::string object_id = std::string(obtxt) + this->get_node_uuid_string();
277 ob_node.append_attribute(
"id").set_value(object_id.c_str());
282 const GreasePencil *grease_pencil_eval = id_cast<const GreasePencil *>(ob_eval->
data);
285 if (!
layer->is_visible()) {
288 const Drawing *drawing = grease_pencil_eval->get_drawing_at(*
layer, frame_number);
289 if (drawing ==
nullptr) {
294 pugi::xml_node layer_node = ob_node.append_child(
"g");
295 std::string layer_node_id =
"layer." +
layer->name() + this->get_node_uuid_string();
296 layer_node.append_attribute(
"id").set_value(layer_node_id.c_str());
300 if (
curves.has_curve_with_type({CURVE_TYPE_CATMULL_ROM, CURVE_TYPE_NURBS})) {
303 .complement(
curves.curves_range(), memory);
306 options.convert_bezier_handles_to_poly_points =
false;
307 options.convert_bezier_handles_to_catmull_rom_points =
false;
308 options.keep_bezier_shape_as_nurbs =
true;
309 options.keep_catmull_rom_shape_as_nurbs =
true;
331 const float4x4 layer_to_world =
layer.to_world_space(
object);
334 const std::optional<Span<float3>> positions_left,
335 const std::optional<Span<float3>> positions_right,
342 const std::optional<float> width,
343 const std::optional<float> miter_limit_angle,
344 const bool round_cap,
345 const bool is_outline) {
346 pugi::xml_node element_node =
write_path(layer_node,
360 element_node.append_attribute(
"fill-rule").set_value(
"nonzero");
363 element_node.append_attribute(
"fill-rule").set_value(
"evenodd");
379 pugi::xml_node
decl =
main_doc_.prepend_child(pugi::node_declaration);
380 decl.append_attribute(
"version") =
"1.0";
381 decl.append_attribute(
"encoding") =
"UTF-8";
383 pugi::xml_node comment =
main_doc_.append_child(pugi::node_comment);
384 std::string txt = std::string(
" Generator: Blender, ") +
svg_exporter_name +
" - " +
386 comment.set_value(txt.c_str());
388 pugi::xml_node doctype =
main_doc_.append_child(pugi::node_doctype);
390 "svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" "
391 "\"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\"");
396 pugi::xml_node main_node =
main_doc_.append_child(
"svg");
397 main_node.append_attribute(
"version").set_value(
"1.1");
398 main_node.append_attribute(
"x").set_value(
"0px");
399 main_node.append_attribute(
"y").set_value(
"0px");
400 main_node.append_attribute(
"xmlns").set_value(
"http://www.w3.org/2000/svg");
402 std::string width, height;
413 main_node.append_attribute(
"width").set_value((width +
"px").c_str());
414 main_node.append_attribute(
"height").set_value((height +
"px").c_str());
415 std::string viewbox =
"0 0 " + width +
" " + height;
416 main_node.append_attribute(
"viewBox").set_value(viewbox.c_str());
423 const float duration)
425 pugi::xml_node use_node = parent_node.append_child(
"use");
426 use_node.append_attribute(
"id").set_value(
"blender_animation");
428 use_node.append_attribute(
"href").set_value(href_text.c_str());
430 pugi::xml_node animate_node = use_node.append_child(
"animate");
431 animate_node.append_attribute(
"id").set_value(
"frame-by-frame_animation");
432 animate_node.append_attribute(
"attributeName").set_value(
"href");
434 std::string duration_text = std::to_string(duration) +
"s";
435 animate_node.append_attribute(
"dur").set_value(duration_text.c_str());
436 animate_node.append_attribute(
"repeatCount").set_value(
"indefinite");
438 std::string animated_frame_ids = [&]() {
439 std::string frame_ids_text;
441 std::string frame_url_entry =
"#" +
frame_name(frame) +
";";
442 frame_ids_text.append(frame_url_entry);
444 return frame_ids_text;
447 animate_node.append_attribute(
"values").set_value(animated_frame_ids.c_str());
461 const std::optional<float> width)
463 pugi::xml_node element_node =
node.append_child(
"path");
466 element_node.append_attribute(
"stroke-width").set_value(*width);
470 for (
const int curve_i : shape) {
472 const IndexRange points = points_by_curve[curve_i];
476 if (types[curve_i] !=
CURVE_TYPE_BEZIER || !positions_left || !positions_right) {
487 if (cyclic[curve_i]) {
506 if (i != curve_pos.
size() - 2) {
518 if (cyclic[curve_i]) {
534 element_node.append_attribute(
"d").set_value(txt.c_str());
545 std::wstring wstr(filepath_16);
Low-level operations for curves.
Low-level operations for grease pencil.
#define SNPRINTF_UTF8(dst, format,...)
#define GP_STROKE_MITER_ANGLE_BEVEL
#define GP_STROKE_MITER_ANGLE_ROUND
Object is a sort of wrapper for general info.
#define BLI_assert_unreachable()
static IndexMask from_predicate(const IndexMask &universe, LinearAllocator<> &memory, Fn &&predicate, exec_mode::Mode mode=exec_mode::parallel)
constexpr IndexRange drop_back(int64_t n) const
constexpr IndexRange()=default
constexpr Span slice(int64_t start, int64_t size) const
constexpr const T & first() const
constexpr int64_t size() const
constexpr const T & last(const int64_t n=0) const
constexpr IndexRange index_range() const
constexpr const char * c_str() const
bke::CurvesGeometry & strokes_for_write()
const bke::CurvesGeometry & strokes() const
void tag_topology_changed()
void foreach_index(Fn &&fn, Mode mode=exec_mode::serial) const
GreasePencilExporter(const IOContext &context, const ExportParams ¶ms)
std::string coord_to_svg_string(const float2 &screen_co) const
void foreach_shape_in_layer(const Object &object, const bke::greasepencil::Layer &layer, const bke::greasepencil::Drawing &drawing, WriteShapeFn shape_fn)
Bounds< float2 > camera_rect_
std::optional< float4x4 > camera_persmat_
const ExportParams params_
void prepare_render_params(Scene &scene, int frame_number)
Vector< ObjectInfo > retrieve_objects() const
bool is_selected_frame(const GreasePencil &grease_pencil, int frame_number) const
Bounds< float2 > screen_rect_
float2 project_to_screen(const float4x4 &transform, const float3 &position) const
GreasePencilExporter(const IOContext &context, const ExportParams ¶ms)
void export_grease_pencil_layer(pugi::xml_node node, const Object &object, const bke::greasepencil::Layer &layer, const bke::greasepencil::Drawing &drawing)
pugi::xml_document main_doc_
void export_grease_pencil_objects(pugi::xml_node node, int frame_number)
pugi::xml_node write_path(pugi::xml_node node, const float4x4 &transform, const Span< float3 > positions, const std::optional< Span< float3 > > positions_left, const std::optional< Span< float3 > > positions_right, const OffsetIndices< int > points_by_curve, const Span< int > shape, const VArray< bool > &cyclic, const VArray< int8_t > &types, std::optional< float > width)
void write_document_header()
pugi::xml_node write_main_node()
pugi::xml_node write_animation_node(pugi::xml_node parent_node, IndexMask frames, float duration)
bool write_to_file(StringRefNull filepath)
ExportStatus export_scene(Scene &scene, StringRefNull filepath)
CCL_NAMESPACE_BEGIN struct Options options
void free(Subdiv *subdiv)
bke::CurvesGeometry convert_curves(const bke::CurvesGeometry &src_curves, const IndexMask &selection, CurveType dst_type, const bke::AttributeFilter &attribute_filter, const ConvertCurvesOptions &options={})
@ InvalidActiveObjectType
static std::string rgb_to_hexstr(const float color[3])
static void write_fill_color_attribute(pugi::xml_node node, const ColorGeometry4f &fill_color, const float layer_opacity)
static void write_stroke_color_attribute(pugi::xml_node node, const ColorGeometry4f &stroke_color, const float stroke_opacity, const std::optional< float > miter_limit_angle, const bool round_cap)
constexpr const char * svg_exporter_name
static void write_rect(pugi::xml_node node, const float x, const float y, const float width, const float height, const float thickness, const std::string &hexcolor)
ExportStatus export_svg(const IOContext &context, const ExportParams ¶ms, Scene &scene, StringRefNull filepath)
static std::string frame_name(int frame_number)
constexpr const char * svg_exporter_version
T sin(const AngleRadianBase< T > &a)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void BKE_scene_graph_update_for_newframe(Depsgraph *depsgraph)
unsigned __int64 uint64_t
void linearrgb_to_srgb_v3_v3(float srgb[3], const float linear[3])
MatBase< float, 4, 4 > float4x4
MINLINE void rgb_float_to_uchar(unsigned char r_col[3], const float col_f[3])
VecBase< float, 2 > float2
T * DEG_get_evaluated(const Depsgraph *depsgraph, T *id)
bool BKE_scene_camera_switch_update(Scene *scene)
ColorSceneLinear4f< eAlpha::Premultiplied > ColorGeometry4f
wchar_t * alloc_utf16_from_8(const char *in8, size_t add)