[Bf-blender-cvs] [4d506e981e4] greasepencil-object: Merge branch 'blender2.8' into greasepencil-object

Joshua Leung noreply at git.blender.org
Tue May 8 19:35:16 CEST 2018


Commit: 4d506e981e47367bc731a3d7084d998bac692f87
Author: Joshua Leung
Date:   Tue May 8 19:07:23 2018 +0200
Branches: greasepencil-object
https://developer.blender.org/rB4d506e981e47367bc731a3d7084d998bac692f87

Merge branch 'blender2.8' into greasepencil-object

# Conflicts:
#	source/blender/blenloader/intern/versioning_280.c
#	source/blender/editors/gpencil/gpencil_edit.c
#	source/blender/editors/gpencil/gpencil_paint.c
#	source/blender/editors/gpencil/gpencil_utils.c
#	source/blender/editors/object/object_transform.c

===================================================================



===================================================================

diff --cc source/blender/blenloader/intern/versioning_280.c
index 2a44623af44,0cfab7976d6..c7335af1d0e
--- a/source/blender/blenloader/intern/versioning_280.c
+++ b/source/blender/blenloader/intern/versioning_280.c
@@@ -693,107 -687,8 +693,88 @@@ void do_versions_after_linking_280(Mai
  			}
  		}
  	}
 +
 +	/* Grease Pencil Object */
 +	/* Convert grease pencil datablock to GP object */
 +#if 0 /* XXX: Needs review - maybe we don't want to do this, as annotations could cause havok on cycles files! */
 +	for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
 +		if (scene->gpd) {
 +			Object *ob;
 +			ViewLayer *view_layer = scene->view_layers.first; /* Weak, but at least it goes somewhere... */
 +			if (view_layer == NULL) {
 +				view_layer = BKE_view_layer_add(scene, "Viewport");
 +				printf("added scene layer again - %p\n", view_layer);
 +			}
 +
 +			ob = BKE_object_add_for_data(main, scene, view_layer, OB_GPENCIL, "GP_Scene", &scene->gpd->id, false);
 +			zero_v3(ob->loc);
 +
 +			/* convert grease pencil palettes (version >= 2.78)  to materials */
 +			bGPdata *gpd = scene->gpd;
 +			for (const bGPDpalette *palette = gpd->palettes.first; palette; palette = palette->next) {
 +				for (bGPDpalettecolor *palcolor = palette->colors.first; palcolor; palcolor = palcolor->next) {
 +
 +					/* create material slot */
 +					BKE_object_material_slot_add(ob);
 +					Material *ma = BKE_material_add_gpencil(main, palcolor->info);
 +					assign_material(ob, ma, ob->totcol, BKE_MAT_ASSIGN_EXISTING);
 +
 +					/* copy color settings */
 +					GpencilColorData *gpcolor = ma->gpcolor;
 +					copy_v4_v4(gpcolor->rgb, palcolor->color);
 +					copy_v4_v4(gpcolor->fill, palcolor->fill);
 +					gpcolor->flag = palcolor->flag;
 +
 +					/* fix strokes */
 +					for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) {
 +						for (bGPDframe *gpf = gpl->frames.first; gpf; gpf = gpf->next) {
 +							for (bGPDstroke *gps = gpf->strokes.first; gps; gps = gps->next) {
 +								if (STREQ(gps->colorname, palcolor->info)) {
 +									gps->mat_nr = ob->totcol - 1;
 +								}
 +							}
 +						}
 +					}
 +				}
 +			}
 +
 +			/* set cache as dirty */
 +			BKE_gpencil_batch_cache_dirty(ob->data);
 +
 +			scene->gpd = NULL;
 +		}
 +	}
 +
 +	/* Handle object-linked grease pencil datablocks */
 +	for (Object *ob = main->object.first; ob; ob = ob->id.next) {
 +		if (ob->gpd) {
 +			if (ob->type == OB_GPENCIL) {
 +				/* GP Object - remap the links */
 +				ob->data = ob->gpd;
 +				ob->gpd = NULL;
 +			}
 +			else if (ob->type == OB_EMPTY) {
 +				/* Empty with GP data - This should be able to be converted
 +				 * to a GP object with little data loss
 +				 */
 +				ob->data = ob->gpd;
 +				ob->gpd = NULL;
 +				ob->type = OB_GPENCIL;
 +			}
 +			else {
 +				/* FIXME: What to do in this case?
 +				 *
 +				 * We cannot create new objects for these, as we don't have a scene & scene layer
 +				 * to put them into from here...
 +				 */
 +				printf("WARNING: Old Grease Pencil data ('%s') still exists on Object '%s'\n",
 +					ob->gpd->id.name + 2, ob->id.name + 2);
 +			}
 +		}
 +	}
 +#endif
  }
  
- static void do_version_layer_collections_idproperties(ListBase *lb)
- {
- 	IDPropertyTemplate val = {0};
- 	for (LayerCollection *lc = lb->first; lc; lc = lc->next) {
- 		lc->properties = IDP_New(IDP_GROUP, &val, ROOT_PROP);
- 		BKE_layer_collection_engine_settings_create(lc->properties);
- 
- 		/* No overrides at first */
- 		for (IDProperty *prop = lc->properties->data.group.first; prop; prop = prop->next) {
- 			while (prop->data.group.first) {
- 				IDP_FreeFromGroup(prop, prop->data.group.first);
- 			}
- 		}
- 
- 		/* Do it recursively */
- 		do_version_layer_collections_idproperties(&lc->layer_collections);
- 	}
- }
- 
  static void do_version_view_layer_visibility(ViewLayer *view_layer)
  {
  	LayerCollection *layer_collection;
diff --cc source/blender/editors/gpencil/gpencil_brush.c
index 2ffa9be1bbe,1cb882e9a43..78996e5cb4c
--- a/source/blender/editors/gpencil/gpencil_brush.c
+++ b/source/blender/editors/gpencil/gpencil_brush.c
@@@ -575,11 -504,10 +575,11 @@@ static void gp_brush_calc_midpoint(tGP_
  		 */
  		View3D *v3d = gso->sa->spacedata.first;
  		RegionView3D *rv3d = gso->ar->regiondata;
- 		float *rvec = ED_view3d_cursor3d_get(gso->scene, v3d);
+ 		float *rvec = ED_view3d_cursor3d_get(gso->scene, v3d)->location;
  		float zfac = ED_view3d_calc_zfac(rv3d, rvec, NULL);
  		
 -		float mval_f[2] = {UNPACK2(gso->mval)};
 +		float mval_f[2];
 +		copy_v2fl_v2i(mval_f, gso->mval);
  		float mval_prj[2];
  		float dvec[3];
  		
diff --cc source/blender/editors/gpencil/gpencil_edit.c
index 38ba19cd34e,d8cbbb16542..7811c680daa
--- a/source/blender/editors/gpencil/gpencil_edit.c
+++ b/source/blender/editors/gpencil/gpencil_edit.c
@@@ -1991,10 -1462,9 +1991,10 @@@ static int gp_snap_to_cursor(bContext *
  	
  	Scene *scene = CTX_data_scene(C);
  	View3D *v3d = CTX_wm_view3d(C);
 -	
 +	Object *obact = CTX_data_active_object(C);                                          \
 +
  	const bool use_offset = RNA_boolean_get(op->ptr, "use_offset");
- 	const float *cursor_global = ED_view3d_cursor3d_get(scene, v3d);
+ 	const float *cursor_global = ED_view3d_cursor3d_get(scene, v3d)->location;
  	
  	for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) {
  		/* only editable and visible layers are considered */
@@@ -2077,9 -1550,8 +2077,9 @@@ static int gp_snap_cursor_to_sel(bConte
  	
  	Scene *scene = CTX_data_scene(C);
  	View3D *v3d = CTX_wm_view3d(C);
 -	
 +	Object *obact = CTX_data_active_object(C);                                          \
 +
- 	float *cursor = ED_view3d_cursor3d_get(scene, v3d);
+ 	float *cursor = ED_view3d_cursor3d_get(scene, v3d)->location;
  	float centroid[3] = {0.0f};
  	float min[3], max[3];
  	size_t count = 0;
diff --cc source/blender/editors/gpencil/gpencil_paint.c
index 9eba2a98e35,3f3349a752c..0801c0de93b
--- a/source/blender/editors/gpencil/gpencil_paint.c
+++ b/source/blender/editors/gpencil/gpencil_paint.c
@@@ -1654,42 -1427,6 +1654,42 @@@ static bool gp_session_initdata(bContex
  					printf("Error: 3D-View active region doesn't have any region data, so cannot be drawable\n");
  				return 0;
  			}
 +			
 +			/* if active object doesn't exist or it's not a Grease Pencil object, 
 +			 * use the scene's gp_object (), or create one if it doesn't exist
 +			 */
- 			float *cur = ED_view3d_cursor3d_get(p->scene, v3d);
++			float *cur = ED_view3d_cursor3d_get(p->scene, v3d)->location;
 +			if ((!obact) || (obact->type != OB_GPENCIL)) {
 +				if (p->scene->gp_object) {
 +					/* use existing default */
 +					/* XXX: This will still lose whatever mode we were in before,
 +					 *      making GP less convenient for annotations than it used to be
 +					 */
 +					obact = p->scene->gp_object;
 +					
 +					/* temporarily activate the object */
 +					ViewLayer *view_layer = CTX_data_view_layer(C);
 +					Base *base = BKE_view_layer_base_find(view_layer, obact);
 +					if (base) {
 +						if (CTX_data_edit_object(C)) 
 +							ED_object_editmode_exit(C, EM_FREEDATA | EM_WAITCURSOR | EM_DO_UNDO);  /* freedata, and undo */
 +						
 +						view_layer->basact = base;
 +						ED_object_base_activate(C, base);
 +					}
 +					else {
 +						printf("ERROR: Couldn't find base for active gp_object (view_layer = %p, obact = %s)\n", view_layer, obact->id.name);
 +					}
 +				}
 +				else {
 +					/* create new default object */
 +					obact = ED_add_gpencil_object(C, p->scene, cur);
 +					p->scene->gp_object = obact;
 +				}
 +			}
 +			/* assign object after all checks to be sure we have one active */
 +			p->ob = obact;
 +
  			break;
  		}
  		case SPACE_NODE:
diff --cc source/blender/editors/gpencil/gpencil_utils.c
index 55e4f94f012,babe68ba439..d172d221eb0
--- a/source/blender/editors/gpencil/gpencil_utils.c
+++ b/source/blender/editors/gpencil/gpencil_utils.c
@@@ -776,91 -839,53 +775,91 @@@ void gp_stroke_convertcoords_tpoint
  }
  
  /**
 -* Apply smooth for strength to stroke point
 -* \param gps              Stroke to smooth
 -* \param i                Point index
 -* \param inf              Amount of smoothing to apply
 -*/
 -bool gp_smooth_stroke_strength(bGPDstroke *gps, int i, float inf)
 + * Get drawing reference point for conversion or projection of the stroke
 + * \param[out] r_vec : Reference point found
 + */
 +void ED_gp_get_drawing_reference(View3D *v3d, Scene *scene, Object *ob, bGPDlayer *gpl, char align_flag, float r_vec[3])
  {
- 	const float *fp = ED_view3d_cursor3d_get(scene, v3d);
 -	bGPDspoint *ptb = &gps->points[i];
 -
 -	/* Do nothing if not enough points */
 -	if (gps->totpoints <= 2) {
 -		return false;
++	const float *fp = ED_view3d_cursor3d_get(scene, v3d)->location;
 +
 +	/* if using a gpencil object at cursor mode, can use the location of the object */
 +	if (align_flag & GP_PROJECT_VIEWSPACE) {
 +		if (ob && (ob->type == OB_GPENCIL)) {
 +			/* use last stroke position for layer */
 +			if (gpl && gpl->flag & GP_LAYER_USE_LOCATION) {
 +				if (gpl->actframe) {
 +					bGPDframe *gpf = gpl->actframe;
 +					if (gpf->strokes.last) {
 +						bGPDstroke *gps = gpf->strokes.last;
 +						if (gps->totpoints > 0) {
 +							copy_v3_v3(r_vec, &gps->points[gps->totpoints - 1].x);
 +							mul_m4_v3(ob->obmat, r_vec);
 +							return;
 +						}
 +					}
 +				}
 +			}
 +			/* fallback (no strokes) - use cursor or object location */
 +			if (align_flag & GP_PROJECT_CURSOR) {
 +				/* use 3D-cursor */
 +				copy_v3_v3(r_vec, fp);
 +			}
 +			else {
 +				/* use object location */
 +				copy_v3_v3(r_vec, ob->obmat[3]);
 +			}
 +		}
  	}
 +	else {
 +		/* use 3D-cursor */
 +		copy_v3_v3(r_vec, fp);
 +	}
 +}
  
 -	/* Compute theoretical optimal value using distances */
 -	bGPDspoint *pta, *ptc;
 -	int before = i - 1;
 -	int after = i + 1;
  
 -	CLAMP_MIN(before, 0);
 -	CLAMP_MAX(after, gps->totpoints - 1);
 +/**
 + * Reproject all points of the stroke to a plane locked to axis to avoid stroke offset
 + */
 +void ED_gp_project_stroke_to_plane(Object *ob, RegionView3D *rv3d, bGPDstroke *gps, const float origin[3], const int axis, char UNUSED(type))
 +{
 +	float plane_normal[3];
 +	float vn[3];
 +
 +	f

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list