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