Example #1
0
/* flush any temp data from object editing to DNA before writing files,
 * rendering, copying, etc. */
bool ED_editors_flush_edits(const bContext *C, bool for_render)
{
	bool has_edited = false;
	Object *ob;
	Main *bmain = CTX_data_main(C);

	/* loop through all data to find edit mode or object mode, because during
	 * exiting we might not have a context for edit object and multiple sculpt
	 * objects can exist at the same time */
	for (ob = bmain->object.first; ob; ob = ob->id.next) {
		if (ob->mode & OB_MODE_SCULPT) {
			/* flush multires changes (for sculpt) */
			multires_force_update(ob);
			has_edited = true;

			if (for_render) {
				/* flush changes from dynamic topology sculpt */
				BKE_sculptsession_bm_to_me_for_render(ob);
			}
			else {
				/* Set reorder=false so that saving the file doesn't reorder
			 * the BMesh's elements */
				BKE_sculptsession_bm_to_me(ob, false);
			}
		}
		else if (ob->mode & OB_MODE_EDIT) {
			/* get editmode results */
			has_edited = true;
			ED_object_editmode_load(ob);
		}
	}

	return has_edited;
}
Example #2
0
void multiresModifier_join(Object *ob)
{
    Base *base = NULL;
    int highest_lvl = 0;

    /* First find the highest level of subdivision */
    base = FIRSTBASE;
    while(base) {
        if(TESTBASELIB_BGMODE(v3d, base) && base->object->type==OB_MESH) {
            ModifierData *md;
            for(md = base->object->modifiers.first; md; md = md->next) {
                if(md->type == eModifierType_Multires) {
                    int totlvl = ((MultiresModifierData*)md)->totlvl;
                    if(totlvl > highest_lvl)
                        highest_lvl = totlvl;

                    /* Ensure that all updates are processed */
                    multires_force_update(base->object);
                }
            }
        }
        base = base->next;
    }

    /* No multires meshes selected */
    if(highest_lvl == 0)
        return;

    /* Subdivide all the displacements to the highest level */
    base = FIRSTBASE;
    while(base) {
        if(TESTBASELIB_BGMODE(v3d, base) && base->object->type==OB_MESH) {
            ModifierData *md = NULL;
            MultiresModifierData *mmd = NULL;

            for(md = base->object->modifiers.first; md; md = md->next) {
                if(md->type == eModifierType_Multires)
                    mmd = (MultiresModifierData*)md;
            }

            /* If the object didn't have multires enabled, give it a new modifier */
            if(!mmd) {
                md = base->object->modifiers.first;

                while(md && modifierType_getInfo(md->type)->type == eModifierTypeType_OnlyDeform)
                    md = md->next;

                mmd = (MultiresModifierData*)modifier_new(eModifierType_Multires);
                BLI_insertlinkbefore(&base->object->modifiers, md, mmd);
                modifier_unique_name(&base->object->modifiers, mmd);
            }

            if(mmd)
                multiresModifier_subdivide(mmd, base->object, highest_lvl - mmd->totlvl, 0, 0);
        }
        base = base->next;
    }
}
Example #3
0
static void libblock_remap_data_postprocess_obdata_relink(Main *UNUSED(bmain), Object *ob, ID *new_id)
{
	if (ob->data == new_id) {
		switch (GS(new_id->name)) {
			case ID_ME:
				multires_force_update(ob);
				break;
			case ID_CU:
				BKE_curve_type_test(ob);
				break;
			default:
				break;
		}
		test_object_modifiers(ob);
		test_object_materials(ob, new_id);
	}
}
Example #4
0
void wm_autosave_timer(const bContext *C, wmWindowManager *wm, wmTimer *UNUSED(wt))
{
	wmWindow *win;
	wmEventHandler *handler;
	char filepath[FILE_MAX];
	
	Scene *scene = CTX_data_scene(C);

	WM_event_remove_timer(wm, NULL, wm->autosavetimer);

	/* if a modal operator is running, don't autosave, but try again in 10 seconds */
	for (win = wm->windows.first; win; win = win->next) {
		for (handler = win->modalhandlers.first; handler; handler = handler->next) {
			if (handler->op) {
				wm->autosavetimer = WM_event_add_timer(wm, NULL, TIMERAUTOSAVE, 10.0);
				return;
			}
		}
	}

	if (scene) {
		Object *ob = OBACT;

		if (ob && ob->mode & OB_MODE_SCULPT)
			multires_force_update(ob);
	}

	wm_autosave_location(filepath);

	if (U.uiflag & USER_GLOBALUNDO) {
		/* fast save of last undobuffer, now with UI */
		BKE_undo_save_file(filepath);
	}
	else {
		/*  save as regular blend file */
		int fileflags = G.fileflags & ~(G_FILE_COMPRESS | G_FILE_AUTOPLAY | G_FILE_LOCK | G_FILE_SIGN | G_FILE_HISTORY);

		/* no error reporting to console */
		BLO_write_file(CTX_data_main(C), filepath, fileflags, NULL, NULL);
	}
	/* do timer after file write, just in case file write takes a long time */
	wm->autosavetimer = WM_event_add_timer(wm, NULL, TIMERAUTOSAVE, U.savetime * 60.0);
}
Example #5
0
/* flush any temp data from object editing to DNA before writing files,
 * rendering, copying, etc. */
bool ED_editors_flush_edits(const bContext *C, bool for_render)
{
	bool has_edited = false;
	Object *ob;
	Main *bmain = CTX_data_main(C);

	/* loop through all data to find edit mode or object mode, because during
	 * exiting we might not have a context for edit object and multiple sculpt
	 * objects can exist at the same time */
	for (ob = bmain->object.first; ob; ob = ob->id.next) {
		if (ob->mode & OB_MODE_SCULPT) {
			/* Don't allow flushing while in the middle of a stroke (frees data in use).
			 * Auto-save prevents this from happening but scripts may cause a flush on saving: T53986. */
			if ((ob->sculpt && ob->sculpt->cache) == 0) {
				/* flush multires changes (for sculpt) */
				multires_force_update(ob);
				has_edited = true;

				if (for_render) {
					/* flush changes from dynamic topology sculpt */
					BKE_sculptsession_bm_to_me_for_render(ob);
				}
				else {
					/* Set reorder=false so that saving the file doesn't reorder
					 * the BMesh's elements */
					BKE_sculptsession_bm_to_me(ob, false);
				}
			}
		}
		else if (ob->mode & OB_MODE_EDIT) {
			/* get editmode results */
			has_edited = true;
			ED_object_editmode_load(bmain, ob);
		}
	}

	return has_edited;
}
Example #6
0
/* flush any temp data from object editing to DNA before writing files,
 * rendering, copying, etc. */
void ED_editors_flush_edits(const bContext *C, bool for_render)
{
	Object *obact = CTX_data_active_object(C);
	Object *obedit = CTX_data_edit_object(C);

	/* get editmode results */
	if (obedit)
		ED_object_editmode_load(obedit);

	if (obact && (obact->mode & OB_MODE_SCULPT)) {
		/* flush multires changes (for sculpt) */
		multires_force_update(obact);

		if (for_render) {
			/* flush changes from dynamic topology sculpt */
			sculptsession_bm_to_me_for_render(obact);
		}
		else {
			/* Set reorder=false so that saving the file doesn't reorder
			 * the BMesh's elements */
			sculptsession_bm_to_me(obact, FALSE);
		}
	}
}
Example #7
0
static int modifier_apply_obdata(ReportList *reports, Scene *scene, Object *ob, ModifierData *md)
{
	ModifierTypeInfo *mti= modifierType_getInfo(md->type);

	md->scene= scene;

	if (mti->isDisabled && mti->isDisabled(md, 0)) {
		BKE_report(reports, RPT_ERROR, "Modifier is disabled, skipping apply");
		return 0;
	}

	if (ob->type==OB_MESH) {
		DerivedMesh *dm;
		Mesh *me = ob->data;
		MultiresModifierData *mmd= find_multires_modifier_before(scene, md);

		if(me->key && mti->type != eModifierTypeType_NonGeometrical) {
			BKE_report(reports, RPT_ERROR, "Modifier cannot be applied to Mesh with Shape Keys");
			return 0;
		}

		/* Multires: ensure that recent sculpting is applied */
		if(md->type == eModifierType_Multires)
			multires_force_update(ob);

		if (mmd && mmd->totlvl && mti->type==eModifierTypeType_OnlyDeform) {
			if(!multiresModifier_reshapeFromDeformMod (scene, mmd, ob, md)) {
				BKE_report(reports, RPT_ERROR, "Multires modifier returned error, skipping apply");
				return 0;
			}
		} else {
			dm = mesh_create_derived_for_modifier(scene, ob, md);
			if (!dm) {
				BKE_report(reports, RPT_ERROR, "Modifier returned error, skipping apply");
				return 0;
			}

			DM_to_mesh(dm, me);

			dm->release(dm);

			if(md->type == eModifierType_Multires) {
				CustomData_external_remove(&me->fdata, &me->id, CD_MDISPS, me->totface);
				CustomData_free_layer_active(&me->fdata, CD_MDISPS, me->totface);
			}
		}
	}
	else if (ELEM(ob->type, OB_CURVE, OB_SURF)) {
		Curve *cu;
		int numVerts;
		float (*vertexCos)[3];

		if (ELEM(mti->type, eModifierTypeType_Constructive, eModifierTypeType_Nonconstructive)) {
			BKE_report(reports, RPT_ERROR, "Cannot apply constructive modifiers on curve");
			return 0;
		}

		cu = ob->data;
		BKE_report(reports, RPT_INFO, "Applied modifier only changed CV points, not tesselated/bevel vertices");

		vertexCos = curve_getVertexCos(cu, &cu->nurb, &numVerts);
		mti->deformVerts(md, ob, NULL, vertexCos, numVerts, 0, 0);
		curve_applyVertexCos(cu, &cu->nurb, vertexCos);

		MEM_freeN(vertexCos);

		DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
	}
	else {
		BKE_report(reports, RPT_ERROR, "Cannot apply modifier for this object type");
		return 0;
	}

	/* lattice modifier can be applied to particle system too */
	if(ob->particlesystem.first) {

		ParticleSystem *psys = ob->particlesystem.first;

		for(; psys; psys=psys->next) {
			
			if(psys->part->type != PART_HAIR)
				continue;

			psys_apply_hair_lattice(scene, ob, psys);
		}
	}

	return 1;
}