Blender V2.61 - r43446
|
00001 /* 00002 * ***** BEGIN GPL LICENSE BLOCK ***** 00003 * 00004 * This program is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU General Public License 00006 * as published by the Free Software Foundation; either version 2 00007 * of the License, or (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software Foundation, 00016 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00017 * 00018 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. 00019 * All rights reserved. 00020 * 00021 * The Original Code is: all of this file. 00022 * 00023 * Contributor(s): none yet. 00024 * 00025 * ***** END GPL LICENSE BLOCK ***** 00026 */ 00027 00033 #include <stdio.h> 00034 #include <stdlib.h> 00035 #include <string.h> 00036 #include <math.h> 00037 00038 #include "MEM_guardedalloc.h" 00039 00040 #include "BLI_blenlib.h" 00041 #include "BLI_dynlib.h" 00042 #include "BLI_math.h" 00043 #include "BLI_kdopbvh.h" 00044 #include "BLI_utildefines.h" 00045 #include "BLI_bpath.h" 00046 00047 #include "DNA_key_types.h" 00048 #include "DNA_object_types.h" 00049 #include "DNA_lamp_types.h" 00050 #include "DNA_material_types.h" 00051 #include "DNA_world_types.h" 00052 #include "DNA_brush_types.h" 00053 #include "DNA_node_types.h" 00054 #include "DNA_color_types.h" 00055 #include "DNA_particle_types.h" 00056 00057 #include "IMB_imbuf.h" 00058 00059 #include "BKE_plugin_types.h" 00060 #include "BKE_utildefines.h" 00061 #include "BKE_global.h" 00062 #include "BKE_main.h" 00063 #include "BKE_ocean.h" 00064 00065 #include "BKE_library.h" 00066 #include "BKE_image.h" 00067 #include "BKE_material.h" 00068 #include "BKE_texture.h" 00069 #include "BKE_key.h" 00070 #include "BKE_icons.h" 00071 #include "BKE_node.h" 00072 #include "BKE_animsys.h" 00073 #include "BKE_colortools.h" 00074 00075 00076 /* ------------------------------------------------------------------------- */ 00077 00078 /* All support for plugin textures: */ 00079 int test_dlerr(const char *name, const char *symbol) 00080 { 00081 char *err; 00082 00083 err= BLI_dynlib_get_error_as_string(NULL); 00084 if(err) { 00085 printf("var1: %s, var2: %s, var3: %s\n", name, symbol, err); 00086 return 1; 00087 } 00088 00089 return 0; 00090 } 00091 00092 /* ------------------------------------------------------------------------- */ 00093 00094 void open_plugin_tex(PluginTex *pit) 00095 { 00096 int (*version)(void); 00097 00098 /* init all the happy variables */ 00099 pit->doit= NULL; 00100 pit->pname= NULL; 00101 pit->stnames= NULL; 00102 pit->varstr= NULL; 00103 pit->result= NULL; 00104 pit->cfra= NULL; 00105 pit->version= 0; 00106 pit->instance_init= NULL; 00107 00108 /* clear the error list */ 00109 BLI_dynlib_get_error_as_string(NULL); 00110 00111 /* no BLI_dynlib_close! multiple opened plugins... */ 00112 /* if(pit->handle) BLI_dynlib_close(pit->handle); */ 00113 /* pit->handle= 0; */ 00114 00115 /* open the needed object */ 00116 pit->handle= BLI_dynlib_open(pit->name); 00117 if(test_dlerr(pit->name, pit->name)) return; 00118 00119 if (pit->handle != NULL) { 00120 /* find the address of the version function */ 00121 version= (int (*)(void)) BLI_dynlib_find_symbol(pit->handle, "plugin_tex_getversion"); 00122 if (test_dlerr(pit->name, "plugin_tex_getversion")) return; 00123 00124 if (version != NULL) { 00125 pit->version= version(); 00126 if( pit->version >= 2 && pit->version <=6) { 00127 int (*info_func)(PluginInfo *); 00128 PluginInfo *info= (PluginInfo*) MEM_mallocN(sizeof(PluginInfo), "plugin_info"); 00129 00130 info_func= (int (*)(PluginInfo *))BLI_dynlib_find_symbol(pit->handle, "plugin_getinfo"); 00131 if (!test_dlerr(pit->name, "plugin_getinfo")) { 00132 info->instance_init = NULL; 00133 00134 info_func(info); 00135 00136 pit->doit= (int(*)(void)) info->tex_doit; 00137 pit->callback= (void(*)(unsigned short)) info->callback; 00138 pit->stypes= info->stypes; 00139 pit->vars= info->nvars; 00140 pit->pname= info->name; 00141 pit->stnames= info->snames; 00142 pit->varstr= info->varstr; 00143 pit->result= info->result; 00144 pit->cfra= info->cfra; 00145 pit->instance_init = info->instance_init; 00146 if (info->init) info->init(); 00147 } 00148 MEM_freeN(info); 00149 } else { 00150 printf ("Plugin returned unrecognized version number\n"); 00151 return; 00152 } 00153 } 00154 } 00155 } 00156 00157 /* ------------------------------------------------------------------------- */ 00158 00159 /* very badlevel define to bypass linking with BIF_interface.h */ 00160 #define INT 96 00161 #define FLO 128 00162 00163 PluginTex *add_plugin_tex(char *str) 00164 { 00165 PluginTex *pit; 00166 VarStruct *varstr; 00167 int a; 00168 00169 pit= MEM_callocN(sizeof(PluginTex), "plugintex"); 00170 00171 BLI_strncpy(pit->name, str, sizeof(pit->name)); 00172 open_plugin_tex(pit); 00173 00174 if(pit->doit==NULL) { 00175 if(pit->handle==NULL) {;} //XXX error("no plugin: %s", str); 00176 else {;} //XXX error("in plugin: %s", str); 00177 MEM_freeN(pit); 00178 return NULL; 00179 } 00180 00181 varstr= pit->varstr; 00182 for(a=0; a<pit->vars; a++, varstr++) { 00183 if( (varstr->type & FLO)==FLO) 00184 pit->data[a]= varstr->def; 00185 else if( (varstr->type & INT)==INT) 00186 *((int *)(pit->data+a))= (int) varstr->def; 00187 } 00188 00189 if (pit->instance_init) 00190 pit->instance_init((void *) pit->data); 00191 00192 return pit; 00193 } 00194 00195 /* ------------------------------------------------------------------------- */ 00196 00197 void free_plugin_tex(PluginTex *pit) 00198 { 00199 if(pit==NULL) return; 00200 00201 /* no BLI_dynlib_close: same plugin can be opened multiple times, 1 handle */ 00202 MEM_freeN(pit); 00203 } 00204 00205 /* ****************** Mapping ******************* */ 00206 00207 TexMapping *add_tex_mapping(void) 00208 { 00209 TexMapping *texmap= MEM_callocN(sizeof(TexMapping), "TexMapping"); 00210 00211 default_tex_mapping(texmap); 00212 00213 return texmap; 00214 } 00215 00216 void default_tex_mapping(TexMapping *texmap) 00217 { 00218 memset(texmap, 0, sizeof(TexMapping)); 00219 00220 texmap->size[0]= texmap->size[1]= texmap->size[2]= 1.0f; 00221 texmap->max[0]= texmap->max[1]= texmap->max[2]= 1.0f; 00222 unit_m4(texmap->mat); 00223 00224 texmap->projx= PROJ_X; 00225 texmap->projy= PROJ_Y; 00226 texmap->projz= PROJ_Z; 00227 texmap->mapping= MTEX_FLAT; 00228 } 00229 00230 void init_tex_mapping(TexMapping *texmap) 00231 { 00232 float smat[3][3], rmat[3][3], mat[3][3], proj[3][3]; 00233 00234 if(texmap->projx == PROJ_X && texmap->projy == PROJ_Y && texmap->projz == PROJ_Z && 00235 is_zero_v3(texmap->loc) && is_zero_v3(texmap->rot) && is_one_v3(texmap->size)) { 00236 unit_m4(texmap->mat); 00237 00238 texmap->flag |= TEXMAP_UNIT_MATRIX; 00239 } 00240 else { 00241 /* axis projection */ 00242 zero_m3(proj); 00243 00244 if(texmap->projx != PROJ_N) 00245 proj[texmap->projx-1][0]= 1.0f; 00246 if(texmap->projy != PROJ_N) 00247 proj[texmap->projy-1][1]= 1.0f; 00248 if(texmap->projz != PROJ_N) 00249 proj[texmap->projz-1][2]= 1.0f; 00250 00251 /* scale */ 00252 size_to_mat3(smat, texmap->size); 00253 00254 /* rotation */ 00255 /* TexMapping rotation are now in radians. */ 00256 eul_to_mat3(rmat, texmap->rot); 00257 00258 /* compose it all */ 00259 mul_m3_m3m3(mat, rmat, smat); 00260 mul_m3_m3m3(mat, proj, mat); 00261 00262 /* translation */ 00263 copy_m4_m3(texmap->mat, mat); 00264 copy_v3_v3(texmap->mat[3], texmap->loc); 00265 00266 texmap->flag &= ~TEXMAP_UNIT_MATRIX; 00267 } 00268 } 00269 00270 ColorMapping *add_color_mapping(void) 00271 { 00272 ColorMapping *colormap= MEM_callocN(sizeof(ColorMapping), "ColorMapping"); 00273 00274 default_color_mapping(colormap); 00275 00276 return colormap; 00277 } 00278 00279 void default_color_mapping(ColorMapping *colormap) 00280 { 00281 memset(colormap, 0, sizeof(ColorMapping)); 00282 00283 init_colorband(&colormap->coba, 1); 00284 00285 colormap->bright= 1.0; 00286 colormap->contrast= 1.0; 00287 colormap->saturation= 1.0; 00288 00289 colormap->blend_color[0]= 0.8f; 00290 colormap->blend_color[1]= 0.8f; 00291 colormap->blend_color[2]= 0.8f; 00292 colormap->blend_type= MA_RAMP_BLEND; 00293 colormap->blend_factor= 0.0f; 00294 } 00295 00296 /* ****************** COLORBAND ******************* */ 00297 00298 void init_colorband(ColorBand *coba, int rangetype) 00299 { 00300 int a; 00301 00302 coba->data[0].pos= 0.0; 00303 coba->data[1].pos= 1.0; 00304 00305 if(rangetype==0) { 00306 coba->data[0].r= 0.0; 00307 coba->data[0].g= 0.0; 00308 coba->data[0].b= 0.0; 00309 coba->data[0].a= 0.0; 00310 00311 coba->data[1].r= 1.0; 00312 coba->data[1].g= 1.0; 00313 coba->data[1].b= 1.0; 00314 coba->data[1].a= 1.0; 00315 } 00316 else { 00317 coba->data[0].r= 0.0; 00318 coba->data[0].g= 0.0; 00319 coba->data[0].b= 0.0; 00320 coba->data[0].a= 1.0; 00321 00322 coba->data[1].r= 1.0; 00323 coba->data[1].g= 1.0; 00324 coba->data[1].b= 1.0; 00325 coba->data[1].a= 1.0; 00326 } 00327 00328 for(a=2; a<MAXCOLORBAND; a++) { 00329 coba->data[a].r= 0.5; 00330 coba->data[a].g= 0.5; 00331 coba->data[a].b= 0.5; 00332 coba->data[a].a= 1.0; 00333 coba->data[a].pos= 0.5; 00334 } 00335 00336 coba->tot= 2; 00337 00338 } 00339 00340 ColorBand *add_colorband(int rangetype) 00341 { 00342 ColorBand *coba; 00343 00344 coba= MEM_callocN( sizeof(ColorBand), "colorband"); 00345 init_colorband(coba, rangetype); 00346 00347 return coba; 00348 } 00349 00350 /* ------------------------------------------------------------------------- */ 00351 00352 int do_colorband(const ColorBand *coba, float in, float out[4]) 00353 { 00354 const CBData *cbd1, *cbd2, *cbd0, *cbd3; 00355 float fac, mfac, t[4]; 00356 int a; 00357 00358 if(coba==NULL || coba->tot==0) return 0; 00359 00360 cbd1= coba->data; 00361 if(coba->tot==1) { 00362 out[0]= cbd1->r; 00363 out[1]= cbd1->g; 00364 out[2]= cbd1->b; 00365 out[3]= cbd1->a; 00366 } 00367 else { 00368 if(in <= cbd1->pos && coba->ipotype<2) { 00369 out[0]= cbd1->r; 00370 out[1]= cbd1->g; 00371 out[2]= cbd1->b; 00372 out[3]= cbd1->a; 00373 } 00374 else { 00375 CBData left, right; 00376 00377 /* we're looking for first pos > in */ 00378 for(a=0; a<coba->tot; a++, cbd1++) if(cbd1->pos > in) break; 00379 00380 if(a==coba->tot) { 00381 cbd2= cbd1-1; 00382 right= *cbd2; 00383 right.pos= 1.0f; 00384 cbd1= &right; 00385 } 00386 else if(a==0) { 00387 left= *cbd1; 00388 left.pos= 0.0f; 00389 cbd2= &left; 00390 } 00391 else cbd2= cbd1-1; 00392 00393 if(in >= cbd1->pos && coba->ipotype<2) { 00394 out[0]= cbd1->r; 00395 out[1]= cbd1->g; 00396 out[2]= cbd1->b; 00397 out[3]= cbd1->a; 00398 } 00399 else { 00400 00401 if(cbd2->pos!=cbd1->pos) 00402 fac= (in-cbd1->pos)/(cbd2->pos-cbd1->pos); 00403 else { 00404 /* was setting to 0.0 in 2.56 & previous, but this 00405 * is incorrect for the last element, see [#26732] */ 00406 fac= (a != coba->tot) ? 0.0f : 1.0f; 00407 } 00408 00409 if (coba->ipotype==4) { 00410 /* constant */ 00411 out[0]= cbd2->r; 00412 out[1]= cbd2->g; 00413 out[2]= cbd2->b; 00414 out[3]= cbd2->a; 00415 return 1; 00416 } 00417 00418 if(coba->ipotype>=2) { 00419 /* ipo from right to left: 3 2 1 0 */ 00420 00421 if(a>=coba->tot-1) cbd0= cbd1; 00422 else cbd0= cbd1+1; 00423 if(a<2) cbd3= cbd2; 00424 else cbd3= cbd2-1; 00425 00426 CLAMP(fac, 0.0f, 1.0f); 00427 00428 if(coba->ipotype==3) 00429 key_curve_position_weights(fac, t, KEY_CARDINAL); 00430 else 00431 key_curve_position_weights(fac, t, KEY_BSPLINE); 00432 00433 out[0]= t[3]*cbd3->r +t[2]*cbd2->r +t[1]*cbd1->r +t[0]*cbd0->r; 00434 out[1]= t[3]*cbd3->g +t[2]*cbd2->g +t[1]*cbd1->g +t[0]*cbd0->g; 00435 out[2]= t[3]*cbd3->b +t[2]*cbd2->b +t[1]*cbd1->b +t[0]*cbd0->b; 00436 out[3]= t[3]*cbd3->a +t[2]*cbd2->a +t[1]*cbd1->a +t[0]*cbd0->a; 00437 CLAMP(out[0], 0.0f, 1.0f); 00438 CLAMP(out[1], 0.0f, 1.0f); 00439 CLAMP(out[2], 0.0f, 1.0f); 00440 CLAMP(out[3], 0.0f, 1.0f); 00441 } 00442 else { 00443 00444 if(coba->ipotype==1) { /* EASE */ 00445 mfac= fac*fac; 00446 fac= 3.0f*mfac-2.0f*mfac*fac; 00447 } 00448 mfac= 1.0f-fac; 00449 00450 out[0]= mfac*cbd1->r + fac*cbd2->r; 00451 out[1]= mfac*cbd1->g + fac*cbd2->g; 00452 out[2]= mfac*cbd1->b + fac*cbd2->b; 00453 out[3]= mfac*cbd1->a + fac*cbd2->a; 00454 } 00455 } 00456 } 00457 } 00458 return 1; /* OK */ 00459 } 00460 00461 void colorband_table_RGBA(ColorBand *coba, float **array, int *size) 00462 { 00463 int a; 00464 00465 *size = CM_TABLE+1; 00466 *array = MEM_callocN(sizeof(float)*(*size)*4, "ColorBand"); 00467 00468 for(a=0; a<*size; a++) 00469 do_colorband(coba, (float)a/(float)CM_TABLE, &(*array)[a*4]); 00470 } 00471 00472 int vergcband(const void *a1, const void *a2) 00473 { 00474 const CBData *x1=a1, *x2=a2; 00475 00476 if( x1->pos > x2->pos ) return 1; 00477 else if( x1->pos < x2->pos) return -1; 00478 return 0; 00479 } 00480 00481 CBData *colorband_element_add(struct ColorBand *coba, float position) 00482 { 00483 int a; 00484 00485 if(coba->tot==MAXCOLORBAND) { 00486 return NULL; 00487 } 00488 else if(coba->tot > 0) { 00489 CBData *xnew; 00490 float col[4]; 00491 00492 do_colorband(coba, position, col); 00493 00494 xnew = &coba->data[coba->tot]; 00495 xnew->pos = position; 00496 00497 xnew->r = col[0]; 00498 xnew->g = col[1]; 00499 xnew->b = col[2]; 00500 xnew->a = col[3]; 00501 } 00502 00503 coba->tot++; 00504 coba->cur = coba->tot-1; 00505 00506 for(a = 0; a < coba->tot; a++) 00507 coba->data[a].cur = a; 00508 00509 qsort(coba->data, coba->tot, sizeof(CBData), vergcband); 00510 00511 for(a = 0; a < coba->tot; a++) { 00512 if(coba->data[a].cur == coba->cur) { 00513 coba->cur = a; 00514 break; 00515 } 00516 } 00517 00518 return coba->data + coba->cur; 00519 } 00520 00521 int colorband_element_remove(struct ColorBand *coba, int index) 00522 { 00523 int a; 00524 00525 if(coba->tot < 2) 00526 return 0; 00527 00528 if(index < 0 || index >= coba->tot) 00529 return 0; 00530 00531 for(a = index; a < coba->tot; a++) { 00532 coba->data[a] = coba->data[a + 1]; 00533 } 00534 if(coba->cur) coba->cur--; 00535 coba->tot--; 00536 return 1; 00537 } 00538 00539 /* ******************* TEX ************************ */ 00540 00541 void free_texture(Tex *tex) 00542 { 00543 free_plugin_tex(tex->plugin); 00544 00545 if(tex->coba) MEM_freeN(tex->coba); 00546 if(tex->env) BKE_free_envmap(tex->env); 00547 if(tex->pd) BKE_free_pointdensity(tex->pd); 00548 if(tex->vd) BKE_free_voxeldata(tex->vd); 00549 if(tex->ot) BKE_free_oceantex(tex->ot); 00550 BKE_free_animdata((struct ID *)tex); 00551 00552 BKE_previewimg_free(&tex->preview); 00553 BKE_icon_delete((struct ID*)tex); 00554 tex->id.icon_id = 0; 00555 00556 if(tex->nodetree) { 00557 ntreeFreeTree(tex->nodetree); 00558 MEM_freeN(tex->nodetree); 00559 } 00560 } 00561 00562 /* ------------------------------------------------------------------------- */ 00563 00564 void default_tex(Tex *tex) 00565 { 00566 PluginTex *pit; 00567 VarStruct *varstr; 00568 int a; 00569 00570 tex->type= TEX_CLOUDS; 00571 tex->stype= 0; 00572 tex->flag= TEX_CHECKER_ODD; 00573 tex->imaflag= TEX_INTERPOL|TEX_MIPMAP|TEX_USEALPHA; 00574 tex->extend= TEX_REPEAT; 00575 tex->cropxmin= tex->cropymin= 0.0; 00576 tex->cropxmax= tex->cropymax= 1.0; 00577 tex->texfilter = TXF_EWA; 00578 tex->afmax = 8; 00579 tex->xrepeat= tex->yrepeat= 1; 00580 tex->fie_ima= 2; 00581 tex->sfra= 1; 00582 tex->frames= 0; 00583 tex->offset= 0; 00584 tex->noisesize= 0.25; 00585 tex->noisedepth= 2; 00586 tex->turbul= 5.0; 00587 tex->nabla= 0.025; // also in do_versions 00588 tex->bright= 1.0; 00589 tex->contrast= 1.0; 00590 tex->saturation= 1.0; 00591 tex->filtersize= 1.0; 00592 tex->rfac= 1.0; 00593 tex->gfac= 1.0; 00594 tex->bfac= 1.0; 00595 /* newnoise: init. */ 00596 tex->noisebasis = 0; 00597 tex->noisebasis2 = 0; 00598 /* musgrave */ 00599 tex->mg_H = 1.0; 00600 tex->mg_lacunarity = 2.0; 00601 tex->mg_octaves = 2.0; 00602 tex->mg_offset = 1.0; 00603 tex->mg_gain = 1.0; 00604 tex->ns_outscale = 1.0; 00605 /* distnoise */ 00606 tex->dist_amount = 1.0; 00607 /* voronoi */ 00608 tex->vn_w1 = 1.0; 00609 tex->vn_w2 = tex->vn_w3 = tex->vn_w4 = 0.0; 00610 tex->vn_mexp = 2.5; 00611 tex->vn_distm = 0; 00612 tex->vn_coltype = 0; 00613 00614 if (tex->env) { 00615 tex->env->stype=ENV_ANIM; 00616 tex->env->clipsta=0.1; 00617 tex->env->clipend=100; 00618 tex->env->cuberes=600; 00619 tex->env->depth=0; 00620 } 00621 00622 if (tex->pd) { 00623 tex->pd->radius = 0.3f; 00624 tex->pd->falloff_type = TEX_PD_FALLOFF_STD; 00625 } 00626 00627 if (tex->vd) { 00628 tex->vd->resol[0] = tex->vd->resol[1] = tex->vd->resol[2] = 0; 00629 tex->vd->interp_type=TEX_VD_LINEAR; 00630 tex->vd->file_format=TEX_VD_SMOKE; 00631 } 00632 00633 if (tex->ot) { 00634 tex->ot->output = TEX_OCN_DISPLACEMENT; 00635 tex->ot->object = NULL; 00636 } 00637 pit = tex->plugin; 00638 if (pit) { 00639 varstr= pit->varstr; 00640 if(varstr) { 00641 for(a=0; a<pit->vars; a++, varstr++) { 00642 pit->data[a] = varstr->def; 00643 } 00644 } 00645 } 00646 00647 tex->iuser.fie_ima= 2; 00648 tex->iuser.ok= 1; 00649 tex->iuser.frames= 100; 00650 tex->iuser.sfra= 1; 00651 00652 tex->preview = NULL; 00653 } 00654 00655 void tex_set_type(Tex *tex, int type) 00656 { 00657 switch(type) { 00658 00659 case TEX_VOXELDATA: 00660 if (tex->vd == NULL) 00661 tex->vd = BKE_add_voxeldata(); 00662 break; 00663 case TEX_POINTDENSITY: 00664 if (tex->pd == NULL) 00665 tex->pd = BKE_add_pointdensity(); 00666 break; 00667 case TEX_ENVMAP: 00668 if (tex->env == NULL) 00669 tex->env = BKE_add_envmap(); 00670 break; 00671 case TEX_OCEAN: 00672 if (tex->ot == NULL) 00673 tex->ot = BKE_add_oceantex(); 00674 break; 00675 } 00676 00677 tex->type = type; 00678 } 00679 00680 /* ------------------------------------------------------------------------- */ 00681 00682 Tex *add_texture(const char *name) 00683 { 00684 Main *bmain= G.main; 00685 Tex *tex; 00686 00687 tex= alloc_libblock(&bmain->tex, ID_TE, name); 00688 00689 default_tex(tex); 00690 00691 return tex; 00692 } 00693 00694 /* ------------------------------------------------------------------------- */ 00695 00696 void default_mtex(MTex *mtex) 00697 { 00698 mtex->texco= TEXCO_ORCO; 00699 mtex->mapto= MAP_COL; 00700 mtex->object= NULL; 00701 mtex->projx= PROJ_X; 00702 mtex->projy= PROJ_Y; 00703 mtex->projz= PROJ_Z; 00704 mtex->mapping= MTEX_FLAT; 00705 mtex->ofs[0]= 0.0; 00706 mtex->ofs[1]= 0.0; 00707 mtex->ofs[2]= 0.0; 00708 mtex->size[0]= 1.0; 00709 mtex->size[1]= 1.0; 00710 mtex->size[2]= 1.0; 00711 mtex->tex= NULL; 00712 mtex->texflag= MTEX_3TAP_BUMP | MTEX_BUMP_OBJECTSPACE; 00713 mtex->colormodel= 0; 00714 mtex->r= 1.0; 00715 mtex->g= 0.0; 00716 mtex->b= 1.0; 00717 mtex->k= 1.0; 00718 mtex->def_var= 1.0; 00719 mtex->blendtype= MTEX_BLEND; 00720 mtex->colfac= 1.0; 00721 mtex->norfac= 1.0; 00722 mtex->varfac= 1.0; 00723 mtex->dispfac=0.2; 00724 mtex->colspecfac= 1.0f; 00725 mtex->mirrfac= 1.0f; 00726 mtex->alphafac= 1.0f; 00727 mtex->difffac= 1.0f; 00728 mtex->specfac= 1.0f; 00729 mtex->emitfac= 1.0f; 00730 mtex->hardfac= 1.0f; 00731 mtex->raymirrfac= 1.0f; 00732 mtex->translfac= 1.0f; 00733 mtex->ambfac= 1.0f; 00734 mtex->colemitfac= 1.0f; 00735 mtex->colreflfac= 1.0f; 00736 mtex->coltransfac= 1.0f; 00737 mtex->densfac= 1.0f; 00738 mtex->scatterfac= 1.0f; 00739 mtex->reflfac= 1.0f; 00740 mtex->shadowfac= 1.0f; 00741 mtex->zenupfac= 1.0f; 00742 mtex->zendownfac= 1.0f; 00743 mtex->blendfac= 1.0f; 00744 mtex->timefac= 1.0f; 00745 mtex->lengthfac= 1.0f; 00746 mtex->clumpfac= 1.0f; 00747 mtex->kinkfac= 1.0f; 00748 mtex->roughfac= 1.0f; 00749 mtex->padensfac= 1.0f; 00750 mtex->lifefac= 1.0f; 00751 mtex->sizefac= 1.0f; 00752 mtex->ivelfac= 1.0f; 00753 mtex->dampfac= 1.0f; 00754 mtex->gravityfac= 1.0f; 00755 mtex->fieldfac= 1.0f; 00756 mtex->normapspace= MTEX_NSPACE_TANGENT; 00757 } 00758 00759 00760 /* ------------------------------------------------------------------------- */ 00761 00762 MTex *add_mtex(void) 00763 { 00764 MTex *mtex; 00765 00766 mtex= MEM_callocN(sizeof(MTex), "add_mtex"); 00767 00768 default_mtex(mtex); 00769 00770 return mtex; 00771 } 00772 00773 /* slot -1 for first free ID */ 00774 MTex *add_mtex_id(ID *id, int slot) 00775 { 00776 MTex **mtex_ar; 00777 short act; 00778 00779 give_active_mtex(id, &mtex_ar, &act); 00780 00781 if(mtex_ar==NULL) { 00782 return NULL; 00783 } 00784 00785 if(slot==-1) { 00786 /* find first free */ 00787 int i; 00788 for (i= 0; i < MAX_MTEX; i++) { 00789 if (!mtex_ar[i]) { 00790 slot= i; 00791 break; 00792 } 00793 } 00794 if(slot == -1) { 00795 return NULL; 00796 } 00797 } 00798 else { 00799 /* make sure slot is valid */ 00800 if(slot < 0 || slot >= MAX_MTEX) { 00801 return NULL; 00802 } 00803 } 00804 00805 if (mtex_ar[slot]) { 00806 id_us_min((ID *)mtex_ar[slot]->tex); 00807 MEM_freeN(mtex_ar[slot]); 00808 mtex_ar[slot]= NULL; 00809 } 00810 00811 mtex_ar[slot]= add_mtex(); 00812 00813 return mtex_ar[slot]; 00814 } 00815 00816 /* ------------------------------------------------------------------------- */ 00817 00818 Tex *copy_texture(Tex *tex) 00819 { 00820 Tex *texn; 00821 00822 texn= copy_libblock(&tex->id); 00823 if(texn->type==TEX_IMAGE) id_us_plus((ID *)texn->ima); 00824 else texn->ima= NULL; 00825 00826 if(texn->plugin) { 00827 texn->plugin= MEM_dupallocN(texn->plugin); 00828 open_plugin_tex(texn->plugin); 00829 } 00830 00831 if(texn->coba) texn->coba= MEM_dupallocN(texn->coba); 00832 if(texn->env) texn->env= BKE_copy_envmap(texn->env); 00833 if(texn->pd) texn->pd= BKE_copy_pointdensity(texn->pd); 00834 if(texn->vd) texn->vd= MEM_dupallocN(texn->vd); 00835 if(texn->ot) texn->ot= BKE_copy_oceantex(texn->ot); 00836 if(tex->preview) texn->preview = BKE_previewimg_copy(tex->preview); 00837 00838 if(tex->nodetree) { 00839 if (tex->nodetree->execdata) { 00840 ntreeTexEndExecTree(tex->nodetree->execdata, 1); 00841 } 00842 texn->nodetree= ntreeCopyTree(tex->nodetree); 00843 } 00844 00845 return texn; 00846 } 00847 00848 /* texture copy without adding to main dbase */ 00849 Tex *localize_texture(Tex *tex) 00850 { 00851 Tex *texn; 00852 00853 texn= copy_libblock(&tex->id); 00854 BLI_remlink(&G.main->tex, texn); 00855 00856 /* image texture: free_texture also doesn't decrease */ 00857 00858 if(texn->plugin) { 00859 texn->plugin= MEM_dupallocN(texn->plugin); 00860 open_plugin_tex(texn->plugin); 00861 } 00862 00863 if(texn->coba) texn->coba= MEM_dupallocN(texn->coba); 00864 if(texn->env) { 00865 texn->env= BKE_copy_envmap(texn->env); 00866 id_us_min(&texn->env->ima->id); 00867 } 00868 if(texn->pd) texn->pd= BKE_copy_pointdensity(texn->pd); 00869 if(texn->vd) { 00870 texn->vd= MEM_dupallocN(texn->vd); 00871 if(texn->vd->dataset) 00872 texn->vd->dataset= MEM_dupallocN(texn->vd->dataset); 00873 } 00874 if(texn->ot) { 00875 texn->ot= BKE_copy_oceantex(tex->ot); 00876 } 00877 00878 texn->preview = NULL; 00879 00880 if(tex->nodetree) { 00881 texn->nodetree= ntreeLocalize(tex->nodetree); 00882 } 00883 00884 return texn; 00885 } 00886 00887 00888 /* ------------------------------------------------------------------------- */ 00889 00890 static void extern_local_texture(Tex *tex) 00891 { 00892 id_lib_extern((ID *)tex->ima); 00893 } 00894 00895 void make_local_texture(Tex *tex) 00896 { 00897 Main *bmain= G.main; 00898 Material *ma; 00899 World *wrld; 00900 Lamp *la; 00901 Brush *br; 00902 ParticleSettings *pa; 00903 int a, is_local= FALSE, is_lib= FALSE; 00904 00905 /* - only lib users: do nothing 00906 * - only local users: set flag 00907 * - mixed: make copy 00908 */ 00909 00910 if(tex->id.lib==NULL) return; 00911 00912 if(tex->id.us==1) { 00913 id_clear_lib_data(bmain, &tex->id); 00914 extern_local_texture(tex); 00915 return; 00916 } 00917 00918 ma= bmain->mat.first; 00919 while(ma) { 00920 for(a=0; a<MAX_MTEX; a++) { 00921 if(ma->mtex[a] && ma->mtex[a]->tex==tex) { 00922 if(ma->id.lib) is_lib= TRUE; 00923 else is_local= TRUE; 00924 } 00925 } 00926 ma= ma->id.next; 00927 } 00928 la= bmain->lamp.first; 00929 while(la) { 00930 for(a=0; a<MAX_MTEX; a++) { 00931 if(la->mtex[a] && la->mtex[a]->tex==tex) { 00932 if(la->id.lib) is_lib= TRUE; 00933 else is_local= TRUE; 00934 } 00935 } 00936 la= la->id.next; 00937 } 00938 wrld= bmain->world.first; 00939 while(wrld) { 00940 for(a=0; a<MAX_MTEX; a++) { 00941 if(wrld->mtex[a] && wrld->mtex[a]->tex==tex) { 00942 if(wrld->id.lib) is_lib= TRUE; 00943 else is_local= TRUE; 00944 } 00945 } 00946 wrld= wrld->id.next; 00947 } 00948 br= bmain->brush.first; 00949 while(br) { 00950 if(br->mtex.tex==tex) { 00951 if(br->id.lib) is_lib= TRUE; 00952 else is_local= TRUE; 00953 } 00954 br= br->id.next; 00955 } 00956 pa= bmain->particle.first; 00957 while(pa) { 00958 for(a=0; a<MAX_MTEX; a++) { 00959 if(pa->mtex[a] && pa->mtex[a]->tex==tex) { 00960 if(pa->id.lib) is_lib= TRUE; 00961 else is_local= TRUE; 00962 } 00963 } 00964 pa= pa->id.next; 00965 } 00966 00967 if(is_local && is_lib == FALSE) { 00968 id_clear_lib_data(bmain, &tex->id); 00969 extern_local_texture(tex); 00970 } 00971 else if(is_local && is_lib) { 00972 Tex *tex_new= copy_texture(tex); 00973 00974 tex_new->id.us= 0; 00975 00976 /* Remap paths of new ID using old library as base. */ 00977 BKE_id_lib_local_paths(bmain, tex->id.lib, &tex_new->id); 00978 00979 ma= bmain->mat.first; 00980 while(ma) { 00981 for(a=0; a<MAX_MTEX; a++) { 00982 if(ma->mtex[a] && ma->mtex[a]->tex==tex) { 00983 if(ma->id.lib==NULL) { 00984 ma->mtex[a]->tex= tex_new; 00985 tex_new->id.us++; 00986 tex->id.us--; 00987 } 00988 } 00989 } 00990 ma= ma->id.next; 00991 } 00992 la= bmain->lamp.first; 00993 while(la) { 00994 for(a=0; a<MAX_MTEX; a++) { 00995 if(la->mtex[a] && la->mtex[a]->tex==tex) { 00996 if(la->id.lib==NULL) { 00997 la->mtex[a]->tex= tex_new; 00998 tex_new->id.us++; 00999 tex->id.us--; 01000 } 01001 } 01002 } 01003 la= la->id.next; 01004 } 01005 wrld= bmain->world.first; 01006 while(wrld) { 01007 for(a=0; a<MAX_MTEX; a++) { 01008 if(wrld->mtex[a] && wrld->mtex[a]->tex==tex) { 01009 if(wrld->id.lib==NULL) { 01010 wrld->mtex[a]->tex= tex_new; 01011 tex_new->id.us++; 01012 tex->id.us--; 01013 } 01014 } 01015 } 01016 wrld= wrld->id.next; 01017 } 01018 br= bmain->brush.first; 01019 while(br) { 01020 if(br->mtex.tex==tex) { 01021 if(br->id.lib==NULL) { 01022 br->mtex.tex= tex_new; 01023 tex_new->id.us++; 01024 tex->id.us--; 01025 } 01026 } 01027 br= br->id.next; 01028 } 01029 pa= bmain->particle.first; 01030 while(pa) { 01031 for(a=0; a<MAX_MTEX; a++) { 01032 if(pa->mtex[a] && pa->mtex[a]->tex==tex) { 01033 if(pa->id.lib==NULL) { 01034 pa->mtex[a]->tex= tex_new; 01035 tex_new->id.us++; 01036 tex->id.us--; 01037 } 01038 } 01039 } 01040 pa= pa->id.next; 01041 } 01042 } 01043 } 01044 01045 /* ------------------------------------------------------------------------- */ 01046 01047 void autotexname(Tex *tex) 01048 { 01049 Main *bmain= G.main; 01050 char texstr[20][15]= {"None" , "Clouds" , "Wood", "Marble", "Magic" , "Blend", 01051 "Stucci", "Noise" , "Image", "Plugin", "EnvMap" , "Musgrave", 01052 "Voronoi", "DistNoise", "Point Density", "Voxel Data", "Ocean", "", "", ""}; 01053 Image *ima; 01054 char di[FILE_MAXDIR], fi[FILE_MAXFILE]; 01055 01056 if(tex) { 01057 if(tex->use_nodes) { 01058 new_id(&bmain->tex, (ID *)tex, "Noddy"); 01059 } 01060 else 01061 if(tex->type==TEX_IMAGE) { 01062 ima= tex->ima; 01063 if(ima) { 01064 BLI_strncpy(di, ima->name, sizeof(di)); 01065 BLI_splitdirstring(di, fi); 01066 strcpy(di, "I."); 01067 strcat(di, fi); 01068 new_id(&bmain->tex, (ID *)tex, di); 01069 } 01070 else new_id(&bmain->tex, (ID *)tex, texstr[tex->type]); 01071 } 01072 else if(tex->type==TEX_PLUGIN && tex->plugin) new_id(&bmain->tex, (ID *)tex, tex->plugin->pname); 01073 else new_id(&bmain->tex, (ID *)tex, texstr[tex->type]); 01074 } 01075 } 01076 01077 /* ------------------------------------------------------------------------- */ 01078 01079 Tex *give_current_object_texture(Object *ob) 01080 { 01081 Material *ma, *node_ma; 01082 Tex *tex= NULL; 01083 01084 if(ob==NULL) return NULL; 01085 if(ob->totcol==0 && !(ob->type==OB_LAMP)) return NULL; 01086 01087 if(ob->type==OB_LAMP) { 01088 tex= give_current_lamp_texture(ob->data); 01089 } else { 01090 ma= give_current_material(ob, ob->actcol); 01091 01092 if((node_ma=give_node_material(ma))) 01093 ma= node_ma; 01094 01095 tex= give_current_material_texture(ma); 01096 } 01097 01098 return tex; 01099 } 01100 01101 Tex *give_current_lamp_texture(Lamp *la) 01102 { 01103 MTex *mtex= NULL; 01104 Tex *tex= NULL; 01105 01106 if(la) { 01107 mtex= la->mtex[(int)(la->texact)]; 01108 if(mtex) tex= mtex->tex; 01109 } 01110 01111 return tex; 01112 } 01113 01114 void set_current_lamp_texture(Lamp *la, Tex *newtex) 01115 { 01116 int act= la->texact; 01117 01118 if(la->mtex[act] && la->mtex[act]->tex) 01119 id_us_min(&la->mtex[act]->tex->id); 01120 01121 if(newtex) { 01122 if(!la->mtex[act]) { 01123 la->mtex[act]= add_mtex(); 01124 la->mtex[act]->texco= TEXCO_GLOB; 01125 } 01126 01127 la->mtex[act]->tex= newtex; 01128 id_us_plus(&newtex->id); 01129 } 01130 else if(la->mtex[act]) { 01131 MEM_freeN(la->mtex[act]); 01132 la->mtex[act]= NULL; 01133 } 01134 } 01135 01136 bNode *give_current_material_texture_node(Material *ma) 01137 { 01138 if(ma && ma->use_nodes && ma->nodetree) 01139 return nodeGetActiveID(ma->nodetree, ID_TE); 01140 01141 return NULL; 01142 } 01143 01144 Tex *give_current_material_texture(Material *ma) 01145 { 01146 MTex *mtex= NULL; 01147 Tex *tex= NULL; 01148 bNode *node; 01149 01150 if(ma && ma->use_nodes && ma->nodetree) { 01151 /* first check texture, then material, this works together 01152 with a hack that clears the active ID flag for textures on 01153 making a material node active */ 01154 node= nodeGetActiveID(ma->nodetree, ID_TE); 01155 01156 if(node) { 01157 tex= (Tex *)node->id; 01158 ma= NULL; 01159 } 01160 } 01161 01162 if(ma) { 01163 mtex= ma->mtex[(int)(ma->texact)]; 01164 if(mtex) tex= mtex->tex; 01165 } 01166 01167 return tex; 01168 } 01169 01170 int give_active_mtex(ID *id, MTex ***mtex_ar, short *act) 01171 { 01172 switch(GS(id->name)) { 01173 case ID_MA: 01174 *mtex_ar= ((Material *)id)->mtex; 01175 if(act) *act= (((Material *)id)->texact); 01176 break; 01177 case ID_WO: 01178 *mtex_ar= ((World *)id)->mtex; 01179 if(act) *act= (((World *)id)->texact); 01180 break; 01181 case ID_LA: 01182 *mtex_ar= ((Lamp *)id)->mtex; 01183 if(act) *act= (((Lamp *)id)->texact); 01184 break; 01185 case ID_PA: 01186 *mtex_ar= ((ParticleSettings *)id)->mtex; 01187 if(act) *act= (((ParticleSettings *)id)->texact); 01188 break; 01189 default: 01190 *mtex_ar = NULL; 01191 if(act) *act= 0; 01192 return FALSE; 01193 } 01194 01195 return TRUE; 01196 } 01197 01198 void set_active_mtex(ID *id, short act) 01199 { 01200 if(act<0) act= 0; 01201 else if(act>=MAX_MTEX) act= MAX_MTEX-1; 01202 01203 switch(GS(id->name)) { 01204 case ID_MA: 01205 ((Material *)id)->texact= act; 01206 break; 01207 case ID_WO: 01208 ((World *)id)->texact= act; 01209 break; 01210 case ID_LA: 01211 ((Lamp *)id)->texact= act; 01212 break; 01213 case ID_PA: 01214 ((ParticleSettings *)id)->texact= act; 01215 break; 01216 } 01217 } 01218 01219 void set_current_material_texture(Material *ma, Tex *newtex) 01220 { 01221 Tex *tex= NULL; 01222 bNode *node; 01223 01224 if(ma && ma->use_nodes && ma->nodetree) { 01225 node= nodeGetActiveID(ma->nodetree, ID_TE); 01226 01227 if(node) { 01228 tex= (Tex *)node->id; 01229 id_us_min(&tex->id); 01230 node->id= &newtex->id; 01231 id_us_plus(&newtex->id); 01232 ma= NULL; 01233 } 01234 } 01235 if(ma) { 01236 int act= (int)ma->texact; 01237 01238 tex= (ma->mtex[act])? ma->mtex[act]->tex: NULL; 01239 id_us_min(&tex->id); 01240 01241 if(newtex) { 01242 if(!ma->mtex[act]) 01243 ma->mtex[act]= add_mtex(); 01244 01245 ma->mtex[act]->tex= newtex; 01246 id_us_plus(&newtex->id); 01247 } 01248 else if(ma->mtex[act]) { 01249 MEM_freeN(ma->mtex[act]); 01250 ma->mtex[act]= NULL; 01251 } 01252 } 01253 } 01254 01255 int has_current_material_texture(Material *ma) 01256 { 01257 bNode *node; 01258 01259 if(ma && ma->use_nodes && ma->nodetree) { 01260 node= nodeGetActiveID(ma->nodetree, ID_TE); 01261 01262 if(node) 01263 return 1; 01264 } 01265 01266 return (ma != NULL); 01267 } 01268 01269 Tex *give_current_world_texture(World *world) 01270 { 01271 MTex *mtex= NULL; 01272 Tex *tex= NULL; 01273 01274 if(!world) return NULL; 01275 01276 mtex= world->mtex[(int)(world->texact)]; 01277 if(mtex) tex= mtex->tex; 01278 01279 return tex; 01280 } 01281 01282 void set_current_world_texture(World *wo, Tex *newtex) 01283 { 01284 int act= wo->texact; 01285 01286 if(wo->mtex[act] && wo->mtex[act]->tex) 01287 id_us_min(&wo->mtex[act]->tex->id); 01288 01289 if(newtex) { 01290 if(!wo->mtex[act]) { 01291 wo->mtex[act]= add_mtex(); 01292 wo->mtex[act]->texco= TEXCO_VIEW; 01293 } 01294 01295 wo->mtex[act]->tex= newtex; 01296 id_us_plus(&newtex->id); 01297 } 01298 else if(wo->mtex[act]) { 01299 MEM_freeN(wo->mtex[act]); 01300 wo->mtex[act]= NULL; 01301 } 01302 } 01303 01304 Tex *give_current_brush_texture(Brush *br) 01305 { 01306 return br->mtex.tex; 01307 } 01308 01309 void set_current_brush_texture(Brush *br, Tex *newtex) 01310 { 01311 if(br->mtex.tex) 01312 id_us_min(&br->mtex.tex->id); 01313 01314 if(newtex) { 01315 br->mtex.tex= newtex; 01316 id_us_plus(&newtex->id); 01317 } 01318 } 01319 01320 Tex *give_current_particle_texture(ParticleSettings *part) 01321 { 01322 MTex *mtex= NULL; 01323 Tex *tex= NULL; 01324 01325 if(!part) return NULL; 01326 01327 mtex= part->mtex[(int)(part->texact)]; 01328 if(mtex) tex= mtex->tex; 01329 01330 return tex; 01331 } 01332 01333 void set_current_particle_texture(ParticleSettings *part, Tex *newtex) 01334 { 01335 int act= part->texact; 01336 01337 if(part->mtex[act] && part->mtex[act]->tex) 01338 id_us_min(&part->mtex[act]->tex->id); 01339 01340 if(newtex) { 01341 if(!part->mtex[act]) { 01342 part->mtex[act]= add_mtex(); 01343 part->mtex[act]->texco= TEXCO_ORCO; 01344 part->mtex[act]->blendtype= MTEX_MUL; 01345 } 01346 01347 part->mtex[act]->tex= newtex; 01348 id_us_plus(&newtex->id); 01349 } 01350 else if(part->mtex[act]) { 01351 MEM_freeN(part->mtex[act]); 01352 part->mtex[act]= NULL; 01353 } 01354 } 01355 01356 /* ------------------------------------------------------------------------- */ 01357 01358 EnvMap *BKE_add_envmap(void) 01359 { 01360 EnvMap *env; 01361 01362 env= MEM_callocN(sizeof(EnvMap), "envmap"); 01363 env->type= ENV_CUBE; 01364 env->stype= ENV_ANIM; 01365 env->clipsta= 0.1; 01366 env->clipend= 100.0; 01367 env->cuberes= 600; 01368 env->viewscale = 0.5; 01369 01370 return env; 01371 } 01372 01373 /* ------------------------------------------------------------------------- */ 01374 01375 EnvMap *BKE_copy_envmap(EnvMap *env) 01376 { 01377 EnvMap *envn; 01378 int a; 01379 01380 envn= MEM_dupallocN(env); 01381 envn->ok= 0; 01382 for(a=0; a<6; a++) envn->cube[a]= NULL; 01383 if(envn->ima) id_us_plus((ID *)envn->ima); 01384 01385 return envn; 01386 } 01387 01388 /* ------------------------------------------------------------------------- */ 01389 01390 void BKE_free_envmapdata(EnvMap *env) 01391 { 01392 unsigned int part; 01393 01394 for(part=0; part<6; part++) { 01395 if(env->cube[part]) 01396 IMB_freeImBuf(env->cube[part]); 01397 env->cube[part]= NULL; 01398 } 01399 env->ok= 0; 01400 } 01401 01402 /* ------------------------------------------------------------------------- */ 01403 01404 void BKE_free_envmap(EnvMap *env) 01405 { 01406 01407 BKE_free_envmapdata(env); 01408 MEM_freeN(env); 01409 01410 } 01411 01412 /* ------------------------------------------------------------------------- */ 01413 01414 PointDensity *BKE_add_pointdensity(void) 01415 { 01416 PointDensity *pd; 01417 01418 pd= MEM_callocN(sizeof(PointDensity), "pointdensity"); 01419 pd->flag = 0; 01420 pd->radius = 0.3f; 01421 pd->falloff_type = TEX_PD_FALLOFF_STD; 01422 pd->falloff_softness = 2.0; 01423 pd->source = TEX_PD_PSYS; 01424 pd->point_tree = NULL; 01425 pd->point_data = NULL; 01426 pd->noise_size = 0.5f; 01427 pd->noise_depth = 1; 01428 pd->noise_fac = 1.0f; 01429 pd->noise_influence = TEX_PD_NOISE_STATIC; 01430 pd->coba = add_colorband(1); 01431 pd->speed_scale = 1.0f; 01432 pd->totpoints = 0; 01433 pd->object = NULL; 01434 pd->psys = 0; 01435 pd->psys_cache_space= TEX_PD_WORLDSPACE; 01436 pd->falloff_curve = curvemapping_add(1, 0, 0, 1, 1); 01437 01438 pd->falloff_curve->preset = CURVE_PRESET_LINE; 01439 pd->falloff_curve->cm->flag &= ~CUMA_EXTEND_EXTRAPOLATE; 01440 curvemap_reset(pd->falloff_curve->cm, &pd->falloff_curve->clipr, pd->falloff_curve->preset, CURVEMAP_SLOPE_POSITIVE); 01441 curvemapping_changed(pd->falloff_curve, 0); 01442 01443 return pd; 01444 } 01445 01446 PointDensity *BKE_copy_pointdensity(PointDensity *pd) 01447 { 01448 PointDensity *pdn; 01449 01450 pdn= MEM_dupallocN(pd); 01451 pdn->point_tree = NULL; 01452 pdn->point_data = NULL; 01453 if(pdn->coba) pdn->coba= MEM_dupallocN(pdn->coba); 01454 pdn->falloff_curve = curvemapping_copy(pdn->falloff_curve); /* can be NULL */ 01455 return pdn; 01456 } 01457 01458 void BKE_free_pointdensitydata(PointDensity *pd) 01459 { 01460 if (pd->point_tree) { 01461 BLI_bvhtree_free(pd->point_tree); 01462 pd->point_tree = NULL; 01463 } 01464 if (pd->point_data) { 01465 MEM_freeN(pd->point_data); 01466 pd->point_data = NULL; 01467 } 01468 if(pd->coba) { 01469 MEM_freeN(pd->coba); 01470 pd->coba = NULL; 01471 } 01472 01473 curvemapping_free(pd->falloff_curve); /* can be NULL */ 01474 } 01475 01476 void BKE_free_pointdensity(PointDensity *pd) 01477 { 01478 BKE_free_pointdensitydata(pd); 01479 MEM_freeN(pd); 01480 } 01481 01482 /* ------------------------------------------------------------------------- */ 01483 01484 void BKE_free_voxeldatadata(struct VoxelData *vd) 01485 { 01486 if (vd->dataset) { 01487 MEM_freeN(vd->dataset); 01488 vd->dataset = NULL; 01489 } 01490 01491 } 01492 01493 void BKE_free_voxeldata(struct VoxelData *vd) 01494 { 01495 BKE_free_voxeldatadata(vd); 01496 MEM_freeN(vd); 01497 } 01498 01499 struct VoxelData *BKE_add_voxeldata(void) 01500 { 01501 VoxelData *vd; 01502 01503 vd= MEM_callocN(sizeof(struct VoxelData), "voxeldata"); 01504 vd->dataset = NULL; 01505 vd->resol[0] = vd->resol[1] = vd->resol[2] = 1; 01506 vd->interp_type= TEX_VD_LINEAR; 01507 vd->file_format= TEX_VD_SMOKE; 01508 vd->int_multiplier = 1.0; 01509 vd->extend = TEX_CLIP; 01510 vd->object = NULL; 01511 vd->cachedframe = -1; 01512 vd->ok = 0; 01513 01514 return vd; 01515 } 01516 01517 struct VoxelData *BKE_copy_voxeldata(struct VoxelData *vd) 01518 { 01519 VoxelData *vdn; 01520 01521 vdn= MEM_dupallocN(vd); 01522 vdn->dataset = NULL; 01523 01524 return vdn; 01525 } 01526 01527 /* ------------------------------------------------------------------------- */ 01528 01529 struct OceanTex *BKE_add_oceantex(void) 01530 { 01531 OceanTex *ot; 01532 01533 ot= MEM_callocN(sizeof(struct OceanTex), "ocean texture"); 01534 ot->output = TEX_OCN_DISPLACEMENT; 01535 ot->object = NULL; 01536 01537 return ot; 01538 } 01539 01540 struct OceanTex *BKE_copy_oceantex(struct OceanTex *ot) 01541 { 01542 OceanTex *otn= MEM_dupallocN(ot); 01543 01544 return otn; 01545 } 01546 01547 void BKE_free_oceantex(struct OceanTex *ot) 01548 { 01549 MEM_freeN(ot); 01550 } 01551 01552 01553 /* ------------------------------------------------------------------------- */ 01554 int BKE_texture_dependsOnTime(const struct Tex *texture) 01555 { 01556 if(texture->plugin) { 01557 // assume all plugins depend on time 01558 return 1; 01559 } 01560 else if( texture->ima && 01561 ELEM(texture->ima->source, IMA_SRC_SEQUENCE, IMA_SRC_MOVIE)) { 01562 return 1; 01563 } 01564 else if(texture->adt) { 01565 // assume anything in adt means the texture is animated 01566 return 1; 01567 } 01568 else if(texture->type == TEX_NOISE) { 01569 // noise always varies with time 01570 return 1; 01571 } 01572 return 0; 01573 } 01574 01575 /* ------------------------------------------------------------------------- */