Beispiel #1
0
/* helper for apply() - perform sliding for custom properties */
static void pose_slide_apply_props(tPoseSlideOp *pso, tPChanFCurveLink *pfl)
{
	PointerRNA ptr = {{NULL}};
	LinkData *ld;
	int len = strlen(pfl->pchan_path);
	
	/* setup pointer RNA for resolving paths */
	RNA_pointer_create(NULL, &RNA_PoseBone, pfl->pchan, &ptr);
	
	/* custom properties are just denoted using ["..."][etc.] after the end of the base path, 
	 * so just check for opening pair after the end of the path
	 */
	for (ld = pfl->fcurves.first; ld; ld = ld->next) {
		FCurve *fcu = (FCurve *)ld->data;
		char *bPtr, *pPtr;
		
		if (fcu->rna_path == NULL)
			continue;
		
		/* do we have a match? 
		 *	- bPtr is the RNA Path with the standard part chopped off
		 *	- pPtr is the chunk of the path which is left over
		 */
		bPtr = strstr(fcu->rna_path, pfl->pchan_path) + len;
		pPtr = strstr(bPtr, "[\"");   /* dummy " for texteditor bugs */
		
		if (pPtr) {
			/* use RNA to try and get a handle on this property, then, assuming that it is just
			 * numerical, try and grab the value as a float for temp editing before setting back
			 */
			PropertyRNA *prop = RNA_struct_find_property(&ptr, pPtr);
			
			if (prop) {
				switch (RNA_property_type(prop)) {
					case PROP_FLOAT:
					{
						float tval = RNA_property_float_get(&ptr, prop);
						pose_slide_apply_val(pso, fcu, &tval);
						RNA_property_float_set(&ptr, prop, tval);
						break;
					}
					case PROP_BOOLEAN:
					case PROP_ENUM:
					case PROP_INT:
					{
						float tval = (float)RNA_property_int_get(&ptr, prop);
						pose_slide_apply_val(pso, fcu, &tval);
						RNA_property_int_set(&ptr, prop, (int)tval);
						break;
					}
					default:
						/* cannot handle */
						//printf("Cannot Pose Slide non-numerical property\n");
						break;
				}
			}
		}
	}
}
Beispiel #2
0
static void gizmo_value_operator_redo_value_set(const wmGizmo *gz,
                                                wmGizmoProperty *gz_prop,
                                                const void *value_p)
{
  const float *value = value_p;
  BLI_assert(gz_prop->type->array_length == 1);
  UNUSED_VARS_NDEBUG(gz_prop);

  struct ValueOpRedoGroup *igzgroup = gz->parent_gzgroup->customdata;
  wmOperator *op = igzgroup->state.op;
  RNA_property_float_set(op->ptr, op->type->prop, *value);
  gizmo_op_redo_exec(igzgroup);
}
static void bake_set_props(wmOperator *op, Scene *scene)
{
	PropertyRNA *prop;
	BakeData *bake = &scene->r.bake;

	prop = RNA_struct_find_property(op->ptr, "filepath");
	if (!RNA_property_is_set(op->ptr, prop)) {
		RNA_property_string_set(op->ptr, prop, bake->filepath);
	}

	prop =  RNA_struct_find_property(op->ptr, "width");
	if (!RNA_property_is_set(op->ptr, prop)) {
		RNA_property_int_set(op->ptr, prop, bake->width);
	}

	prop =  RNA_struct_find_property(op->ptr, "height");
	if (!RNA_property_is_set(op->ptr, prop)) {
		RNA_property_int_set(op->ptr, prop, bake->width);
	}

	prop = RNA_struct_find_property(op->ptr, "margin");
	if (!RNA_property_is_set(op->ptr, prop)) {
		RNA_property_int_set(op->ptr, prop, bake->margin);
	}

	prop = RNA_struct_find_property(op->ptr, "use_selected_to_active");
	if (!RNA_property_is_set(op->ptr, prop)) {
		RNA_property_boolean_set(op->ptr, prop, (bake->flag & R_BAKE_TO_ACTIVE) != 0);
	}

	prop = RNA_struct_find_property(op->ptr, "cage_extrusion");
	if (!RNA_property_is_set(op->ptr, prop)) {
		RNA_property_float_set(op->ptr, prop, bake->cage_extrusion);
	}

	prop = RNA_struct_find_property(op->ptr, "cage_object");
	if (!RNA_property_is_set(op->ptr, prop)) {
		RNA_property_string_set(op->ptr, prop, bake->cage);
	}

	prop = RNA_struct_find_property(op->ptr, "normal_space");
	if (!RNA_property_is_set(op->ptr, prop)) {
		RNA_property_enum_set(op->ptr, prop, bake->normal_space);
	}

	prop = RNA_struct_find_property(op->ptr, "normal_r");
	if (!RNA_property_is_set(op->ptr, prop)) {
		RNA_property_enum_set(op->ptr, prop, bake->normal_swizzle[0]);
	}

	prop = RNA_struct_find_property(op->ptr, "normal_g");
	if (!RNA_property_is_set(op->ptr, prop)) {
		RNA_property_enum_set(op->ptr, prop, bake->normal_swizzle[1]);
	}

	prop = RNA_struct_find_property(op->ptr, "normal_b");
	if (!RNA_property_is_set(op->ptr, prop)) {
		RNA_property_enum_set(op->ptr, prop, bake->normal_swizzle[2]);
	}

	prop = RNA_struct_find_property(op->ptr, "save_mode");
	if (!RNA_property_is_set(op->ptr, prop)) {
		RNA_property_enum_set(op->ptr, prop, bake->save_mode);
	}

	prop = RNA_struct_find_property(op->ptr, "use_clear");
	if (!RNA_property_is_set(op->ptr, prop)) {
		RNA_property_boolean_set(op->ptr, prop, (bake->flag & R_BAKE_CLEAR) != 0);
	}

	prop = RNA_struct_find_property(op->ptr, "use_cage");
	if (!RNA_property_is_set(op->ptr, prop)) {
		RNA_property_boolean_set(op->ptr, prop, (bake->flag & R_BAKE_CAGE) != 0);
	}

	prop = RNA_struct_find_property(op->ptr, "use_split_materials");
	if (!RNA_property_is_set(op->ptr, prop)) {
		RNA_property_boolean_set(op->ptr, prop, (bake->flag & R_BAKE_SPLIT_MAT) != 0);
	}

	prop = RNA_struct_find_property(op->ptr, "use_automatic_name");
	if (!RNA_property_is_set(op->ptr, prop)) {
		RNA_property_boolean_set(op->ptr, prop, (bake->flag & R_BAKE_AUTO_NAME) != 0);
	}
}
Beispiel #4
0
void DocumentImporter::finish()
{
	if (mImportStage != General)
		return;

	Main *bmain = CTX_data_main(mContext);
	// TODO: create a new scene except the selected <visual_scene> - use current blender scene for it
	Scene *sce = CTX_data_scene(mContext);
	unit_converter.calculate_scale(*sce);

	std::vector<Object *> *objects_to_scale = new std::vector<Object *>();

	/** TODO Break up and put into 2-pass parsing of DAE */
	std::vector<const COLLADAFW::VisualScene *>::iterator it;
	for (it = vscenes.begin(); it != vscenes.end(); it++) {
		PointerRNA sceneptr, unit_settings;
		PropertyRNA *system, *scale;
		
		// for scene unit settings: system, scale_length

		RNA_id_pointer_create(&sce->id, &sceneptr);
		unit_settings = RNA_pointer_get(&sceneptr, "unit_settings");
		system = RNA_struct_find_property(&unit_settings, "system");
		scale = RNA_struct_find_property(&unit_settings, "scale_length");

		if (this->import_settings->import_units) {
			
			switch (unit_converter.isMetricSystem()) {
				case UnitConverter::Metric:
					RNA_property_enum_set(&unit_settings, system, USER_UNIT_METRIC);
					break;
				case UnitConverter::Imperial:
					RNA_property_enum_set(&unit_settings, system, USER_UNIT_IMPERIAL);
					break;
				default:
					RNA_property_enum_set(&unit_settings, system, USER_UNIT_NONE);
					break;
			}
			float unit_factor = unit_converter.getLinearMeter();
			RNA_property_float_set(&unit_settings, scale, unit_factor);
			fprintf(stdout, "Collada: Adjusting Blender units to Importset units: %f.\n", unit_factor);

		}

		// Write nodes to scene
		const COLLADAFW::NodePointerArray& roots = (*it)->getRootNodes();
		for (unsigned int i = 0; i < roots.getCount(); i++) {
			std::vector<Object *> *objects_done = write_node(roots[i], NULL, sce, NULL, false);
			objects_to_scale->insert(objects_to_scale->end(), objects_done->begin(), objects_done->end());
			delete objects_done;
		}

		// update scene
		DAG_relations_tag_update(bmain);
		WM_event_add_notifier(mContext, NC_OBJECT | ND_TRANSFORM, NULL);

	}


	mesh_importer.optimize_material_assignements();

	armature_importer.set_tags_map(this->uid_tags_map);
	armature_importer.make_armatures(mContext);
	armature_importer.make_shape_keys();
	DAG_relations_tag_update(bmain);

#if 0
	armature_importer.fix_animation();
#endif

	for (std::vector<const COLLADAFW::VisualScene *>::iterator it = vscenes.begin(); it != vscenes.end(); it++) {
		const COLLADAFW::NodePointerArray& roots = (*it)->getRootNodes();

		for (unsigned int i = 0; i < roots.getCount(); i++) {
			translate_anim_recursive(roots[i], NULL, NULL);
		}
	}

	if (libnode_ob.size()) {
		Scene *sce = CTX_data_scene(mContext);

		fprintf(stderr, "got %d library nodes to free\n", (int)libnode_ob.size());
		// free all library_nodes
		std::vector<Object *>::iterator it;
		for (it = libnode_ob.begin(); it != libnode_ob.end(); it++) {
			Object *ob = *it;

			Base *base = BKE_scene_base_find(sce, ob);
			if (base) {
				BLI_remlink(&sce->base, base);
				BKE_libblock_free_us(G.main, base->object);
				if (sce->basact == base)
					sce->basact = NULL;
				MEM_freeN(base);
			}
		}
		libnode_ob.clear();

		DAG_relations_tag_update(bmain);
	}
	
	bc_match_scale(objects_to_scale, unit_converter, !this->import_settings->import_units);

	delete objects_to_scale;
}
Beispiel #5
0
void DocumentImporter::finish()
{
	if(mImportStage!=General)
		return;
		
	/** TODO Break up and put into 2-pass parsing of DAE */
	std::vector<const COLLADAFW::VisualScene*>::iterator it;
	for (it = vscenes.begin(); it != vscenes.end(); it++) {
		PointerRNA sceneptr, unit_settings;
		PropertyRNA *system, *scale;
		// TODO: create a new scene except the selected <visual_scene> - use current blender scene for it
		Scene *sce = CTX_data_scene(mContext);
		
		// for scene unit settings: system, scale_length
		RNA_id_pointer_create(&sce->id, &sceneptr);
		unit_settings = RNA_pointer_get(&sceneptr, "unit_settings");
		system = RNA_struct_find_property(&unit_settings, "system");
		scale = RNA_struct_find_property(&unit_settings, "scale_length");
		
		switch(unit_converter.isMetricSystem()) {
			case UnitConverter::Metric:
				RNA_property_enum_set(&unit_settings, system, USER_UNIT_METRIC);
				break;
			case UnitConverter::Imperial:
				RNA_property_enum_set(&unit_settings, system, USER_UNIT_IMPERIAL);
				break;
			default:
				RNA_property_enum_set(&unit_settings, system, USER_UNIT_NONE);
				break;
		}
		RNA_property_float_set(&unit_settings, scale, unit_converter.getLinearMeter());
		
		const COLLADAFW::NodePointerArray& roots = (*it)->getRootNodes();

		for (unsigned int i = 0; i < roots.getCount(); i++) {
			write_node(roots[i], NULL, sce, NULL, false);
		}
	}
	armature_importer.set_tags_map(this->uid_tags_map);
	armature_importer.make_armatures(mContext);

#if 0
	armature_importer.fix_animation();
#endif

	for (std::vector<const COLLADAFW::VisualScene*>::iterator it = vscenes.begin(); it != vscenes.end(); it++) {
		const COLLADAFW::NodePointerArray& roots = (*it)->getRootNodes();

		for (unsigned int i = 0; i < roots.getCount(); i++)
			translate_anim_recursive(roots[i],NULL,NULL);
	}

	if (libnode_ob.size()) {
		Scene *sce = CTX_data_scene(mContext);

		fprintf(stderr, "got %d library nodes to free\n", (int)libnode_ob.size());
		// free all library_nodes
		std::vector<Object*>::iterator it;
		for (it = libnode_ob.begin(); it != libnode_ob.end(); it++) {
			Object *ob = *it;

			Base *base = object_in_scene(ob, sce);
			if (base) {
				BLI_remlink(&sce->base, base);
				free_libblock_us(&G.main->object, base->object);
				if (sce->basact==base)
					sce->basact= NULL;
				MEM_freeN(base);
			}
		}
		libnode_ob.clear();

		DAG_scene_sort(CTX_data_main(mContext), sce);
		DAG_ids_flush_update(CTX_data_main(mContext), 0);
	}
}
Beispiel #6
0
static int object_warp_verts_exec(bContext *C, wmOperator *op)
{
	const float warp_angle = RNA_float_get(op->ptr, "warp_angle");
	const float offset_angle = RNA_float_get(op->ptr, "offset_angle");

	TransVertStore tvs = {NULL};
	Object *obedit = CTX_data_edit_object(C);

	/* typically from 'rv3d' and 3d cursor */
	float viewmat[4][4];
	float center[3];

	/* 'viewmat' relative vars */
	float mat_view[4][4];
	float center_view[3];

	float min, max;


	ED_transverts_create_from_obedit(&tvs, obedit, TM_ALL_JOINTS | TM_SKIP_HANDLES);
	if (tvs.transverts == NULL) {
		return OPERATOR_CANCELLED;
	}


	/* get viewmatrix */
	{
		PropertyRNA *prop_viewmat = RNA_struct_find_property(op->ptr, "viewmat");
		if (RNA_property_is_set(op->ptr, prop_viewmat)) {
			RNA_property_float_get_array(op->ptr, prop_viewmat, (float *)viewmat);
		}
		else {
			RegionView3D *rv3d = CTX_wm_region_view3d(C);

			if (rv3d) {
				copy_m4_m4(viewmat, rv3d->viewmat);
			}
			else {
				unit_m4(viewmat);
			}

			RNA_property_float_set_array(op->ptr, prop_viewmat, (float *)viewmat);
		}
	}


	/* get center */
	{
		PropertyRNA *prop_center = RNA_struct_find_property(op->ptr, "center");
		if (RNA_property_is_set(op->ptr, prop_center)) {
			RNA_property_float_get_array(op->ptr, prop_center, center);
		}
		else {
			Scene *scene = CTX_data_scene(C);
			View3D *v3d = CTX_wm_view3d(C);
			const float *cursor;

			cursor = ED_view3d_cursor3d_get(scene, v3d);
			copy_v3_v3(center, cursor);

			RNA_property_float_set_array(op->ptr, prop_center, center);
		}
	}


	object_warp_calc_view_matrix(mat_view, center_view, obedit, viewmat, center, offset_angle);


	/* get minmax */
	{
		PropertyRNA *prop_min = RNA_struct_find_property(op->ptr, "min");
		PropertyRNA *prop_max = RNA_struct_find_property(op->ptr, "max");

		if (RNA_property_is_set(op->ptr, prop_min) ||
		    RNA_property_is_set(op->ptr, prop_max))
		{
			min = RNA_property_float_get(op->ptr, prop_min);
			max = RNA_property_float_get(op->ptr, prop_max);
		}
		else {
			/* handy to set the bounds of the mesh */
			object_warp_transverts_minmax_x(&tvs, mat_view, center_view, &min, &max);

			RNA_property_float_set(op->ptr, prop_min, min);
			RNA_property_float_set(op->ptr, prop_max, max);
		}

		if (min > max) {
			SWAP(float, min, max);
		}
	}

	if (min != max) {
		object_warp_transverts(&tvs, mat_view, center_view, warp_angle, min, max);
	}

	ED_transverts_update_obedit(&tvs, obedit);
	ED_transverts_free(&tvs);

	WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, obedit);

	return OPERATOR_FINISHED;
}
Beispiel #7
0
/* sets the sample depth RGB, maintaining A */
static void depthdropper_depth_set(bContext *C, DepthDropper *ddr, const float depth)
{
	RNA_property_float_set(&ddr->ptr, ddr->prop, depth);
	RNA_property_update(C, &ddr->ptr, ddr->prop);
}
Beispiel #8
0
/* helper for apply() - perform sliding for custom properties or bbone properties */
static void pose_slide_apply_props(tPoseSlideOp *pso, tPChanFCurveLink *pfl, const char prop_prefix[])
{
	PointerRNA ptr = {{NULL}};
	LinkData *ld;
	int len = strlen(pfl->pchan_path);
	
	/* setup pointer RNA for resolving paths */
	RNA_pointer_create(NULL, &RNA_PoseBone, pfl->pchan, &ptr);
	
	/* - custom properties are just denoted using ["..."][etc.] after the end of the base path, 
	 *   so just check for opening pair after the end of the path
	 * - bbone properties are similar, but they always start with a prefix "bbone_*",
	 *   so a similar method should work here for those too
	 */
	for (ld = pfl->fcurves.first; ld; ld = ld->next) {
		FCurve *fcu = (FCurve *)ld->data;
		const char *bPtr, *pPtr;
		
		if (fcu->rna_path == NULL)
			continue;
		
		/* do we have a match? 
		 *	- bPtr is the RNA Path with the standard part chopped off
		 *	- pPtr is the chunk of the path which is left over
		 */
		bPtr = strstr(fcu->rna_path, pfl->pchan_path) + len;
		pPtr = strstr(bPtr, prop_prefix);
		
		if (pPtr) {
			/* use RNA to try and get a handle on this property, then, assuming that it is just
			 * numerical, try and grab the value as a float for temp editing before setting back
			 */
			PropertyRNA *prop = RNA_struct_find_property(&ptr, pPtr);
			
			if (prop) {
				switch (RNA_property_type(prop)) {
					/* continuous values that can be smoothly interpolated... */
					case PROP_FLOAT:
					{
						float tval = RNA_property_float_get(&ptr, prop);
						pose_slide_apply_val(pso, fcu, &tval);
						RNA_property_float_set(&ptr, prop, tval);
						break;
					}
					case PROP_INT:
					{
						float tval = (float)RNA_property_int_get(&ptr, prop);
						pose_slide_apply_val(pso, fcu, &tval);
						RNA_property_int_set(&ptr, prop, (int)tval);
						break;
					}
					
					/* values which can only take discrete values */
					case PROP_BOOLEAN:
					{
						float tval = (float)RNA_property_boolean_get(&ptr, prop);
						pose_slide_apply_val(pso, fcu, &tval);
						RNA_property_boolean_set(&ptr, prop, (int)tval); // XXX: do we need threshold clamping here?
						break;
					}
					case PROP_ENUM:
					{
						/* don't handle this case - these don't usually represent interchangeable
						 * set of values which should be interpolated between
						 */
						break;
					}
					
					default:
						/* cannot handle */
						//printf("Cannot Pose Slide non-numerical property\n");
						break;
				}
			}
		}
	}
}