Added ability to save and load planar environment maps, rather than only cube.
This commit is contained in:
@@ -787,27 +787,35 @@ static int save_envmap(wmOperator *op, Scene *scene, EnvMap *env, char *str, int
|
||||
|
||||
dx= env->cube[1]->x;
|
||||
|
||||
ibuf = IMB_allocImBuf(3*dx, 2*dx, 24, IB_rectfloat, 0);
|
||||
if (env->type == ENV_CUBE) {
|
||||
ibuf = IMB_allocImBuf(3*dx, 2*dx, 24, IB_rectfloat, 0);
|
||||
|
||||
IMB_rectcpy(ibuf, env->cube[0], 0, 0, 0, 0, dx, dx);
|
||||
IMB_rectcpy(ibuf, env->cube[1], dx, 0, 0, 0, dx, dx);
|
||||
IMB_rectcpy(ibuf, env->cube[2], 2*dx, 0, 0, 0, dx, dx);
|
||||
IMB_rectcpy(ibuf, env->cube[3], 0, dx, 0, 0, dx, dx);
|
||||
IMB_rectcpy(ibuf, env->cube[4], dx, dx, 0, 0, dx, dx);
|
||||
IMB_rectcpy(ibuf, env->cube[5], 2*dx, dx, 0, 0, dx, dx);
|
||||
}
|
||||
else if (env->type == ENV_PLANE) {
|
||||
ibuf = IMB_allocImBuf(dx, dx, 24, IB_rectfloat, 0);
|
||||
IMB_rectcpy(ibuf, env->cube[1], 0, 0, 0, 0, dx, dx);
|
||||
}
|
||||
|
||||
if (scene->r.color_mgt_flag & R_COLOR_MANAGEMENT)
|
||||
ibuf->profile = IB_PROFILE_LINEAR_RGB;
|
||||
|
||||
IMB_rectcpy(ibuf, env->cube[0], 0, 0, 0, 0, dx, dx);
|
||||
IMB_rectcpy(ibuf, env->cube[1], dx, 0, 0, 0, dx, dx);
|
||||
IMB_rectcpy(ibuf, env->cube[2], 2*dx, 0, 0, 0, dx, dx);
|
||||
IMB_rectcpy(ibuf, env->cube[3], 0, dx, 0, 0, dx, dx);
|
||||
IMB_rectcpy(ibuf, env->cube[4], dx, dx, 0, 0, dx, dx);
|
||||
IMB_rectcpy(ibuf, env->cube[5], 2*dx, dx, 0, 0, dx, dx);
|
||||
|
||||
if (BKE_write_ibuf(scene, ibuf, str, imtype, scene->r.subimtype, scene->r.quality))
|
||||
if (BKE_write_ibuf(scene, ibuf, str, imtype, scene->r.subimtype, scene->r.quality)) {
|
||||
retval = OPERATOR_FINISHED;
|
||||
}
|
||||
else {
|
||||
BKE_reportf(op->reports, RPT_ERROR, "Error saving environment map to %s.", str);
|
||||
retval = OPERATOR_CANCELLED;
|
||||
}
|
||||
|
||||
IMB_freeImBuf(ibuf);
|
||||
ibuf = NULL;
|
||||
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
@@ -862,8 +870,6 @@ static int envmap_save_poll(bContext *C)
|
||||
return 0;
|
||||
if (!tex->env || !tex->env->ok)
|
||||
return 0;
|
||||
if (tex->env->type==ENV_PLANE)
|
||||
return 0;
|
||||
if (tex->env->cube[1]==NULL)
|
||||
return 0;
|
||||
|
||||
@@ -938,7 +944,8 @@ static int envmap_clear_all_exec(bContext *C, wmOperator *op)
|
||||
Tex *tex;
|
||||
|
||||
for (tex=bmain->tex.first; tex; tex=tex->id.next)
|
||||
BKE_free_envmapdata(tex->env);
|
||||
if (tex->env)
|
||||
BKE_free_envmapdata(tex->env);
|
||||
|
||||
WM_event_add_notifier(C, NC_TEXTURE|NA_EDITED, tex);
|
||||
|
||||
|
||||
@@ -349,6 +349,16 @@ static EnumPropertyItem *rna_ImageTexture_filter_itemf(bContext *C, PointerRNA *
|
||||
return item;
|
||||
}
|
||||
|
||||
static void rna_Envmap_source_update(Main *bmain, Scene *scene, PointerRNA *ptr)
|
||||
{
|
||||
Tex *tex= ptr->id.data;
|
||||
|
||||
if (tex->env)
|
||||
BKE_free_envmapdata(tex->env);
|
||||
|
||||
rna_Texture_update(bmain, scene, ptr);
|
||||
}
|
||||
|
||||
static PointerRNA rna_PointDensity_psys_get(PointerRNA *ptr)
|
||||
{
|
||||
PointDensity *pd= ptr->data;
|
||||
@@ -738,7 +748,7 @@ static void rna_def_environment_map(BlenderRNA *brna)
|
||||
RNA_def_property_enum_sdna(prop, NULL, "stype");
|
||||
RNA_def_property_enum_items(prop, prop_source_items);
|
||||
RNA_def_property_ui_text(prop, "Source", "");
|
||||
RNA_def_property_update(prop, 0, "rna_Texture_update");
|
||||
RNA_def_property_update(prop, 0, "rna_Envmap_source_update");
|
||||
|
||||
prop= RNA_def_property(srna, "viewpoint_object", PROP_POINTER, PROP_NONE);
|
||||
RNA_def_property_pointer_sdna(prop, NULL, "object");
|
||||
|
||||
@@ -74,15 +74,23 @@ static void envmap_split_ima(EnvMap *env, ImBuf *ibuf)
|
||||
|
||||
dx= ibuf->y;
|
||||
dx/= 2;
|
||||
if(3*dx != ibuf->x) {
|
||||
if (3*dx == ibuf->x) {
|
||||
env->type = ENV_CUBE;
|
||||
} else if (ibuf->x == ibuf->y) {
|
||||
env->type = ENV_PLANE;
|
||||
} else {
|
||||
printf("Incorrect envmap size\n");
|
||||
env->ok= 0;
|
||||
env->ima->ok= 0;
|
||||
return;
|
||||
}
|
||||
else {
|
||||
|
||||
if (env->type == ENV_CUBE) {
|
||||
for(part=0; part<6; part++) {
|
||||
env->cube[part]= IMB_allocImBuf(dx, dx, 24, IB_rect|IB_rectfloat, 0);
|
||||
}
|
||||
IMB_float_from_rect(ibuf);
|
||||
|
||||
IMB_rectcpy(env->cube[0], ibuf,
|
||||
0, 0, 0, 0, dx, dx);
|
||||
IMB_rectcpy(env->cube[1], ibuf,
|
||||
@@ -97,6 +105,12 @@ static void envmap_split_ima(EnvMap *env, ImBuf *ibuf)
|
||||
0, 0, 2*dx, dx, dx, dx);
|
||||
env->ok= ENV_OSA;
|
||||
}
|
||||
else { /* ENV_PLANE */
|
||||
env->cube[1]= IMB_dupImBuf(ibuf);
|
||||
IMB_float_from_rect(env->cube[1]);
|
||||
|
||||
env->ok= ENV_OSA;
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
@@ -658,10 +672,11 @@ int envmaptex(Tex *tex, float *texvec, float *dxt, float *dyt, int osatex, TexRe
|
||||
texres->tin= 0.0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(env->stype==ENV_LOAD) {
|
||||
env->ima= tex->ima;
|
||||
if(env->ima && env->ima->ok) {
|
||||
if(env->cube[0]==NULL) {
|
||||
if(env->cube[1]==NULL) {
|
||||
ImBuf *ibuf= BKE_image_get_ibuf(env->ima, NULL);
|
||||
if(ibuf)
|
||||
envmap_split_ima(env, ibuf);
|
||||
@@ -672,7 +687,6 @@ int envmaptex(Tex *tex, float *texvec, float *dxt, float *dyt, int osatex, TexRe
|
||||
}
|
||||
|
||||
if(env->ok==0) {
|
||||
|
||||
texres->tin= 0.0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user