Esempio n. 1
0
static DerivedMesh *fluidsim_read_cache(DerivedMesh *orgdm, FluidsimModifierData *fluidmd, int framenr, int useRenderParams)
{
	int displaymode = 0;
	int curFrame = framenr - 1 /*scene->r.sfra*/; /* start with 0 at start frame */
	char targetDir[FILE_MAXFILE+FILE_MAXDIR], targetFile[FILE_MAXFILE+FILE_MAXDIR];
	FluidsimSettings *fss = fluidmd->fss;
	DerivedMesh *dm = NULL;
	MFace *mface;
	int numfaces;
	int mat_nr, flag, i;

	if(!useRenderParams) {
		displaymode = fss->guiDisplayMode;
	} else {
		displaymode = fss->renderDisplayMode;
	}

	BLI_strncpy(targetDir, fss->surfdataPath, sizeof(targetDir));

	// use preview or final mesh?
	if(displaymode==1)
	{
		// just display original object
		return NULL;
	}
	else if(displaymode==2)
	{
		strcat(targetDir,"fluidsurface_preview_####");
	}
	else
	{ // 3
		strcat(targetDir,"fluidsurface_final_####");
	}

	BLI_path_abs(targetDir, G.main->name);
	BLI_path_frame(targetDir, curFrame, 0); // fixed #frame-no

	BLI_snprintf(targetFile, sizeof(targetFile), "%s.bobj.gz", targetDir);

	dm = fluidsim_read_obj(targetFile);

	if(!dm)
	{
		// switch, abort background rendering when fluidsim mesh is missing
		const char *strEnvName2 = "BLENDER_ELBEEMBOBJABORT"; // from blendercall.cpp

		if(G.background==1) {
			if(getenv(strEnvName2)) {
				int elevel = atoi(getenv(strEnvName2));
				if(elevel>0) {
					printf("Env. var %s set, fluid sim mesh '%s' not found, aborting render...\n",strEnvName2, targetFile);
					exit(1);
				}
			}
		}

		// display org. object upon failure which is in dm
		return NULL;
	}

	// assign material + flags to new dm
	mface = orgdm->getFaceArray(orgdm);
	mat_nr = mface[0].mat_nr;
	flag = mface[0].flag;

	mface = dm->getFaceArray(dm);
	numfaces = dm->getNumFaces(dm);
	for(i=0; i<numfaces; i++)
	{
		mface[i].mat_nr = mat_nr;
		mface[i].flag = flag;
	}

	// load vertex velocities, if they exist...
	// TODO? use generate flag as loading flag as well?
	// warning, needs original .bobj.gz mesh loading filename
	if(displaymode==3)
	{
		fluidsim_read_vel_cache(fluidmd, dm, targetFile);
	}
	else
	{
		if(fss->meshVelocities)
			MEM_freeN(fss->meshVelocities);

		fss->meshVelocities = NULL;
	}

	return dm;
}
Esempio n. 2
0
static DerivedMesh *fluidsim_read_cache(Object *ob, DerivedMesh *orgdm,
                                        FluidsimModifierData *fluidmd, int framenr, int useRenderParams)
{
	int displaymode = 0;
	int curFrame = framenr - 1 /*scene->r.sfra*/; /* start with 0 at start frame */
	char targetFile[FILE_MAX];
	FluidsimSettings *fss = fluidmd->fss;
	DerivedMesh *dm = NULL;
	MPoly *mpoly;
	MPoly mp_example = {0};

	if (!useRenderParams) {
		displaymode = fss->guiDisplayMode;
	}
	else {
		displaymode = fss->renderDisplayMode;
	}

	switch (displaymode) {
		case 1:
			/* just display original object */
			return NULL;
		case 2:
			/* use preview mesh */
			BLI_join_dirfile(targetFile, sizeof(targetFile), fss->surfdataPath, OB_FLUIDSIM_SURF_PREVIEW_OBJ_FNAME);
			break;
		default: /* 3 */
			/* 3. use final mesh */
			BLI_join_dirfile(targetFile, sizeof(targetFile), fss->surfdataPath, OB_FLUIDSIM_SURF_FINAL_OBJ_FNAME);
			break;
	}

	/* offset baked frame */
	curFrame += fss->frameOffset;

	BLI_path_abs(targetFile, modifier_path_relbase(ob));
	BLI_path_frame(targetFile, curFrame, 0); // fixed #frame-no

	// assign material + flags to new dm
	// if there's no faces in original dm, keep materials and flags unchanged
	mpoly = orgdm->getPolyArray(orgdm);
	if (mpoly) {
		mp_example = *mpoly;
	}
	/* else leave NULL'd */

	dm = fluidsim_read_obj(targetFile, &mp_example);

	if (!dm) {
		// switch, abort background rendering when fluidsim mesh is missing
		const char *strEnvName2 = "BLENDER_ELBEEMBOBJABORT"; // from blendercall.cpp

		if (G.background == 1) {
			if (getenv(strEnvName2)) {
				int elevel = atoi(getenv(strEnvName2));
				if (elevel > 0) {
					printf("Env. var %s set, fluid sim mesh '%s' not found, aborting render...\n",
					       strEnvName2, targetFile);
					exit(1);
				}
			}
		}

		// display org. object upon failure which is in dm
		return NULL;
	}

	// load vertex velocities, if they exist...
	// TODO? use generate flag as loading flag as well?
	// warning, needs original .bobj.gz mesh loading filename
	if (displaymode == 3) {
		fluidsim_read_vel_cache(fluidmd, dm, targetFile);
	}
	else {
		if (fss->meshVelocities)
			MEM_freeN(fss->meshVelocities);

		fss->meshVelocities = NULL;
	}

	return dm;
}