26 #define NANOSVG_ALL_COLOR_KEYWORDS
27 #define NANOSVG_IMPLEMENTATION
45 NSVGimage *svg_data =
nullptr;
46 svg_data = nsvgParseFromFile(
filepath_,
"mm", 96.0f);
47 if (svg_data ==
nullptr) {
48 std::cout <<
" Could not open SVG.\n ";
55 std::cout <<
"Unable to create new object.\n";
70 char prv_id[70] = {
"*"};
72 for (NSVGshape *shape = svg_data->shapes; shape; shape = shape->next) {
73 char *layer_id = (shape->id_parent[0] ==
'\0') ?
BLI_sprintfN(
"Layer_%03d", prefix) :
75 if (!
STREQ(prv_id, layer_id)) {
78 layer_id = (shape->id_parent[0] ==
'\0') ?
BLI_sprintfN(
"Layer_%03d", prefix) :
80 strcpy(prv_id, layer_id);
96 bool is_stroke = (
bool)shape->stroke.type;
97 bool is_fill = (
bool)shape->fill.type;
98 if ((!is_stroke) && (!is_fill)) {
103 const char *
const mat_names[] = {
"Stroke",
"Fill",
"Both"};
105 if ((is_stroke) && (!is_fill)) {
108 else if ((!is_stroke) && (is_fill)) {
111 else if ((is_stroke) && (is_fill)) {
117 for (NSVGpath *path = shape->paths; path; path = path->next) {
118 create_stroke(
gpd_, gpf, shape, path, mat_index, matrix);
123 nsvgDelete(svg_data);
144 void GpencilImporterSVG::create_stroke(
bGPdata *gpd,
149 const float matrix[4][4])
151 const bool is_stroke = (
bool)shape->stroke.type;
152 const bool is_fill = (
bool)shape->fill.type;
155 const float step = 1.0f / (
float)(edges - 1);
162 if (path->closed ==
'1') {
170 NSVGpaint fill = shape->fill;
171 convert_color(fill.color, gps->vert_color_fill);
172 gps->fill_opacity_fac = gps->vert_color_fill[3];
173 gps->vert_color_fill[3] = 1.0f;
177 for (
int i = 0; i < path->npts - 1; i += 3) {
178 float *p = &path->pts[i * 2];
180 for (
int v = 0;
v < edges;
v++) {
194 NSVGpaint fill = shape->fill;
198 NSVGpaint stroke = shape->stroke;
217 unsigned char rgb_u[4];
219 rgb_u[0] = ((pack) >> 0) & 0xFF;
220 rgb_u[1] = ((pack) >> 8) & 0xFF;
221 rgb_u[2] = ((pack) >> 16) & 0xFF;
222 rgb_u[3] = ((pack) >> 24) & 0xFF;
224 r_col[0] = (
float)rgb_u[0] / 255.0f;
225 r_col[1] = (
float)rgb_u[1] / 255.0f;
226 r_col[2] = (
float)rgb_u[2] / 255.0f;
227 r_col[3] = (
float)rgb_u[3] / 255.0f;
230 void GpencilImporterSVG::convert_color(
const int32_t color,
float r_linear_rgba[4])
236 r_linear_rgba[3] =
rgba[3];
typedef float(TangentPoint)[2]
struct bGPDlayer * BKE_gpencil_layer_addnew(struct bGPdata *gpd, const char *name, bool setactive, bool add_to_header)
struct bGPDstroke * BKE_gpencil_stroke_new(int mat_idx, int totpoints, short thickness)
struct bGPDframe * BKE_gpencil_layer_frame_get(struct bGPDlayer *gpl, int cframe, eGP_GetFrame_Mode addnew)
void BKE_gpencil_centroid_3d(struct bGPdata *gpd, float r_centroid[3])
void BKE_gpencil_stroke_geometry_update(struct bGPdata *gpd, struct bGPDstroke *gps)
void BKE_gpencil_stroke_boundingbox_calc(struct bGPDstroke *gps)
void BKE_gpencil_stroke_merge_distance(struct bGPdata *gpd, struct bGPDframe *gpf, struct bGPDstroke *gps, float threshold, bool use_unselected)
#define LISTBASE_FOREACH(type, var, list)
void BLI_addtail(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
void * BLI_findstring(const struct ListBase *listbase, const char *id, int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
MINLINE void srgb_to_linearrgb_v3_v3(float linear[3], const float srgb[3])
void unit_m4(float m[4][4])
void rescale_m4(float mat[4][4], const float scale[3])
void mul_m4_v3(const float M[4][4], float r[3])
void rotate_m4(float mat[4][4], char axis, float angle)
MINLINE void sub_v3_v3(float r[3], const float a[3])
void interp_v2_v2v2v2v2_cubic(float p[2], const float v1[2], const float v2[2], const float v3[2], const float v4[2], float u)
MINLINE void mul_v3_fl(float r[3], float f)
size_t size_t char * BLI_sprintfN(const char *__restrict format,...) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1) ATTR_MALLOC ATTR_PRINTF_FORMAT(1
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
ATTR_WARN_UNUSED_RESULT const BMVert * v
void filepath_set(const char *filepath)
GpencilImporterSVG(const char *filepath, const struct GpencilIOParams *iparams)
struct Object * create_object()
int32_t create_material(const char *name, bool stroke, bool fill)
void(* MEM_freeN)(void *vmemh)
static void unpack_nano_color(const unsigned int pack, float r_col[4])
static const pxr::TfToken rgba("rgba", pxr::TfToken::Immortal)