static void load_frame_image_sequence(VoxelData *vd, Tex *tex) { ImBuf *ibuf; Image *ima = tex->ima; ImageUser *tiuser = &tex->iuser; ImageUser iuser = *(tiuser); int x = 0, y = 0, z = 0; const float *rf; if (!ima) return; if (iuser.frames == 0) return; ima->source = IMA_SRC_SEQUENCE; iuser.framenr = 1 + iuser.offset; /* find the first valid ibuf and use it to initialize the resolution of the data set */ /* need to do this in advance so we know how much memory to allocate */ ibuf = BKE_image_acquire_ibuf(ima, &iuser, NULL); while (!ibuf && (iuser.framenr < iuser.frames)) { iuser.framenr++; ibuf = BKE_image_acquire_ibuf(ima, &iuser, NULL); } if (!ibuf) return; if (!ibuf->rect_float) IMB_float_from_rect(ibuf); vd->flag |= TEX_VD_STILL; vd->resol[0] = ibuf->x; vd->resol[1] = ibuf->y; vd->resol[2] = iuser.frames; vd->dataset = MEM_mapallocN(sizeof(float) * vd_resol_size(vd), "voxel dataset"); for (z = 0; z < iuser.frames; z++) { /* get a new ibuf for each frame */ if (z > 0) { iuser.framenr++; BKE_image_release_ibuf(ima, ibuf, NULL); ibuf = BKE_image_acquire_ibuf(ima, &iuser, NULL); if (!ibuf) break; if (!ibuf->rect_float) IMB_float_from_rect(ibuf); } rf = ibuf->rect_float; for (y = 0; y < ibuf->y; y++) { for (x = 0; x < ibuf->x; x++) { /* currently averaged to monchrome */ vd->dataset[BLI_VOXEL_INDEX(x, y, z, vd->resol)] = (rf[0] + rf[1] + rf[2]) / 3.0f; rf += 4; } } BKE_image_free_anim_ibufs(ima, iuser.framenr); } BKE_image_release_ibuf(ima, ibuf, NULL); vd->ok = 1; return; }
static int load_frame_blendervoxel(VoxelData *vd, FILE *fp, int frame) { const size_t size = vd_resol_size(vd); size_t offset = sizeof(VoxelDataHeader); if (is_vd_res_ok(vd) == false) return 0; vd->dataset = MEM_mapallocN(sizeof(float) * size, "voxel dataset"); if (vd->dataset == NULL) return 0; if (fseek(fp, frame * size * sizeof(float) + offset, 0) == -1) return 0; if (fread(vd->dataset, sizeof(float), size, fp) != size) return 0; vd->cachedframe = frame; vd->ok = 1; return 1; }
static int load_frame_raw8(VoxelData *vd, FILE *fp, int frame) { const size_t size = vd_resol_size(vd); size_t i; char *data_c; if (is_vd_res_ok(vd) == false) return 0; vd->dataset = MEM_mapallocN(sizeof(float) * size, "voxel dataset"); if (vd->dataset == NULL) return 0; data_c = (char *)MEM_mallocN(sizeof(char) * size, "temporary voxel file reading storage"); if (data_c == NULL) { MEM_freeN(vd->dataset); vd->dataset = NULL; return 0; } if (fseek(fp, (frame - 1) * size * sizeof(char), 0) == -1) { MEM_freeN(data_c); MEM_freeN(vd->dataset); vd->dataset = NULL; return 0; } if (fread(data_c, sizeof(char), size, fp) != size) { MEM_freeN(data_c); MEM_freeN(vd->dataset); vd->dataset = NULL; return 0; } for (i = 0; i < size; i++) { vd->dataset[i] = (float)data_c[i] / 255.f; } MEM_freeN(data_c); vd->cachedframe = frame; vd->ok = 1; return 1; }
static void init_frame_smoke(VoxelData *vd, int cfra) { #ifdef WITH_SMOKE Object *ob; ModifierData *md; vd->dataset = NULL; if (vd->object == NULL) return; ob = vd->object; /* draw code for smoke */ if ((md = (ModifierData *)modifiers_findByType(ob, eModifierType_Smoke))) { SmokeModifierData *smd = (SmokeModifierData *)md; SmokeDomainSettings *sds = smd->domain; if (sds && sds->fluid) { BLI_rw_mutex_lock(sds->fluid_mutex, THREAD_LOCK_READ); if (!sds->fluid) { BLI_rw_mutex_unlock(sds->fluid_mutex); return; } if (cfra < sds->point_cache[0]->startframe) ; /* don't show smoke before simulation starts, this could be made an option in the future */ else if (vd->smoked_type == TEX_VD_SMOKEHEAT) { size_t totRes; size_t i; float *heat; if (!smoke_has_heat(sds->fluid)) { BLI_rw_mutex_unlock(sds->fluid_mutex); return; } copy_v3_v3_int(vd->resol, sds->res); totRes = vd_resol_size(vd); vd->dataset = MEM_mapallocN(sizeof(float) * (totRes), "smoke data"); /* get heat data */ heat = smoke_get_heat(sds->fluid); /* scale heat values from -2.0-2.0 to 0.0-1.0 */ for (i = 0; i < totRes; i++) { vd->dataset[i] = (heat[i] + 2.0f) / 4.0f; } } else if (vd->smoked_type == TEX_VD_SMOKEVEL) { size_t totRes; size_t i; float *xvel, *yvel, *zvel; copy_v3_v3_int(vd->resol, sds->res); totRes = vd_resol_size(vd); vd->dataset = MEM_mapallocN(sizeof(float) * (totRes), "smoke data"); /* get velocity data */ xvel = smoke_get_velocity_x(sds->fluid); yvel = smoke_get_velocity_y(sds->fluid); zvel = smoke_get_velocity_z(sds->fluid); /* map velocities between 0 and 0.3f */ for (i = 0; i < totRes; i++) { vd->dataset[i] = sqrtf(xvel[i] * xvel[i] + yvel[i] * yvel[i] + zvel[i] * zvel[i]) * 3.0f; } } else if (vd->smoked_type == TEX_VD_SMOKEFLAME) { size_t totRes; float *flame; if (sds->flags & MOD_SMOKE_HIGHRES) { if (!smoke_turbulence_has_fuel(sds->wt)) { BLI_rw_mutex_unlock(sds->fluid_mutex); return; } smoke_turbulence_get_res(sds->wt, vd->resol); flame = smoke_turbulence_get_flame(sds->wt); } else { if (!smoke_has_fuel(sds->fluid)) { BLI_rw_mutex_unlock(sds->fluid_mutex); return; } copy_v3_v3_int(vd->resol, sds->res); flame = smoke_get_flame(sds->fluid); } /* always store copy, as smoke internal data can change */ totRes = vd_resol_size(vd); vd->dataset = MEM_mapallocN(sizeof(float)*(totRes), "smoke data"); memcpy(vd->dataset, flame, sizeof(float)*totRes); } else { size_t totCells; int depth = 4; vd->data_type = TEX_VD_RGBA_PREMUL; /* data resolution */ if (sds->flags & MOD_SMOKE_HIGHRES) { smoke_turbulence_get_res(sds->wt, vd->resol); } else { copy_v3_v3_int(vd->resol, sds->res); } /* TODO: is_vd_res_ok(rvd) doesnt check this resolution */ totCells = vd_resol_size(vd) * depth; /* always store copy, as smoke internal data can change */ vd->dataset = MEM_mapallocN(sizeof(float) * totCells, "smoke data"); if (sds->flags & MOD_SMOKE_HIGHRES) { if (smoke_turbulence_has_colors(sds->wt)) { smoke_turbulence_get_rgba(sds->wt, vd->dataset, 1); } else { smoke_turbulence_get_rgba_from_density(sds->wt, sds->active_color, vd->dataset, 1); } } else { if (smoke_has_colors(sds->fluid)) { smoke_get_rgba(sds->fluid, vd->dataset, 1); } else { smoke_get_rgba_from_density(sds->fluid, sds->active_color, vd->dataset, 1); } } } /* end of fluid condition */ BLI_rw_mutex_unlock(sds->fluid_mutex); } } vd->ok = 1; #else // WITH_SMOKE (void)vd; (void)cfra; vd->dataset = NULL; #endif }
static void init_frame_smoke(VoxelData *vd, float cfra) { #ifdef WITH_SMOKE Object *ob; ModifierData *md; vd->dataset = NULL; if (vd->object == NULL) return; ob= vd->object; /* draw code for smoke */ if( (md = (ModifierData *)modifiers_findByType(ob, eModifierType_Smoke)) ) { SmokeModifierData *smd = (SmokeModifierData *)md; if(smd->domain && smd->domain->fluid) { if(cfra < smd->domain->point_cache[0]->startframe) ; /* don't show smoke before simulation starts, this could be made an option in the future */ else if (vd->smoked_type == TEX_VD_SMOKEHEAT) { size_t totRes; size_t i; float *heat; VECCOPY(vd->resol, smd->domain->res); totRes= vd_resol_size(vd); // scaling heat values from -2.0-2.0 to 0.0-1.0 vd->dataset = MEM_mapallocN(sizeof(float)*(totRes), "smoke data"); heat = smoke_get_heat(smd->domain->fluid); for (i=0; i<totRes; i++) { vd->dataset[i] = (heat[i]+2.0f)/4.0f; } //vd->dataset = smoke_get_heat(smd->domain->fluid); } else if (vd->smoked_type == TEX_VD_SMOKEVEL) { size_t totRes; size_t i; float *xvel, *yvel, *zvel; VECCOPY(vd->resol, smd->domain->res); totRes= vd_resol_size(vd); // scaling heat values from -2.0-2.0 to 0.0-1.0 vd->dataset = MEM_mapallocN(sizeof(float)*(totRes), "smoke data"); xvel = smoke_get_velocity_x(smd->domain->fluid); yvel = smoke_get_velocity_y(smd->domain->fluid); zvel = smoke_get_velocity_z(smd->domain->fluid); for (i=0; i<totRes; i++) { vd->dataset[i] = sqrt(xvel[i]*xvel[i] + yvel[i]*yvel[i] + zvel[i]*zvel[i])*3.0f; } } else { size_t totRes; float *density; if (smd->domain->flags & MOD_SMOKE_HIGHRES) { smoke_turbulence_get_res(smd->domain->wt, vd->resol); density = smoke_turbulence_get_density(smd->domain->wt); } else { VECCOPY(vd->resol, smd->domain->res); density = smoke_get_density(smd->domain->fluid); } /* TODO: is_vd_res_ok(rvd) doesnt check this resolution */ totRes= vd_resol_size(vd); /* always store copy, as smoke internal data can change */ vd->dataset = MEM_mapallocN(sizeof(float)*(totRes), "smoke data"); memcpy(vd->dataset, density, sizeof(float)*totRes); } // end of fluid condition } } vd->ok = 1; #else // WITH_SMOKE (void)vd; (void)cfra; vd->dataset= NULL; #endif }