code cleanup: favor braces when blocks have mixed brace use.
[blender.git] / source / blender / blenkernel / intern / texture.c
index 2c868ca..bdf2ce6 100644 (file)
@@ -42,7 +42,6 @@
 #include "BLI_math.h"
 #include "BLI_kdopbvh.h"
 #include "BLI_utildefines.h"
-#include "BLI_bpath.h"
 
 #include "DNA_key_types.h"
 #include "DNA_object_types.h"
@@ -56,8 +55,6 @@
 
 #include "IMB_imbuf.h"
 
-#include "BKE_plugin_types.h"
-#include "BKE_utildefines.h"
 #include "BKE_global.h"
 #include "BKE_main.h"
 #include "BKE_ocean.h"
 #include "BKE_animsys.h"
 #include "BKE_colortools.h"
 
-
-/* ------------------------------------------------------------------------- */
-
-/* All support for plugin textures: */
-int test_dlerr(const char *name, const char *symbol)
-{
-       char *err;
-       
-       err = BLI_dynlib_get_error_as_string(NULL);
-       if (err) {
-               printf("var1: %s, var2: %s, var3: %s\n", name, symbol, err);
-               return 1;
-       }
-       
-       return 0;
-}
-
-/* ------------------------------------------------------------------------- */
-
-void open_plugin_tex(PluginTex *pit)
-{
-       int (*version)(void);
-       
-       /* init all the happy variables */
-       pit->doit = NULL;
-       pit->pname = NULL;
-       pit->stnames = NULL;
-       pit->varstr = NULL;
-       pit->result = NULL;
-       pit->cfra = NULL;
-       pit->version = 0;
-       pit->instance_init = NULL;
-       
-       /* clear the error list */
-       BLI_dynlib_get_error_as_string(NULL);
-
-       /* no BLI_dynlib_close! multiple opened plugins... */
-       /* if (pit->handle) BLI_dynlib_close(pit->handle); */
-       /* pit->handle= 0; */
-
-       /* open the needed object */
-       pit->handle = BLI_dynlib_open(pit->name);
-       if (test_dlerr(pit->name, pit->name)) return;
-
-       if (pit->handle != NULL) {
-               /* find the address of the version function */
-               version = (int (*)(void))BLI_dynlib_find_symbol(pit->handle, "plugin_tex_getversion");
-               if (test_dlerr(pit->name, "plugin_tex_getversion")) return;
-               
-               if (version != NULL) {
-                       pit->version = version();
-                       if (pit->version >= 2 && pit->version <= 6) {
-                               int (*info_func)(PluginInfo *);
-                               PluginInfo *info = (PluginInfo *) MEM_mallocN(sizeof(PluginInfo), "plugin_info");
-
-                               info_func = (int (*)(PluginInfo *))BLI_dynlib_find_symbol(pit->handle, "plugin_getinfo");
-                               if (!test_dlerr(pit->name, "plugin_getinfo")) {
-                                       info->instance_init = NULL;
-
-                                       info_func(info);
-
-                                       pit->doit = (int (*)(void))info->tex_doit;
-                                       pit->callback = (void (*)(unsigned short))info->callback;
-                                       pit->stypes = info->stypes;
-                                       pit->vars = info->nvars;
-                                       pit->pname = info->name;
-                                       pit->stnames = info->snames;
-                                       pit->varstr = info->varstr;
-                                       pit->result = info->result;
-                                       pit->cfra = info->cfra;
-                                       pit->instance_init = info->instance_init;
-                                       if (info->init) info->init();
-                               }
-                               MEM_freeN(info);
-                       }
-                       else {
-                               printf("Plugin returned unrecognized version number\n");
-                               return;
-                       }
-               }
-       }
-}
-
-/* ------------------------------------------------------------------------- */
-
-/* very badlevel define to bypass linking with BIF_interface.h */
-#define INT 96
-#define FLO 128
-
-PluginTex *add_plugin_tex(char *str)
-{
-       PluginTex *pit;
-       VarStruct *varstr;
-       int a;
-       
-       pit = MEM_callocN(sizeof(PluginTex), "plugintex");
-       
-       BLI_strncpy(pit->name, str, sizeof(pit->name));
-       open_plugin_tex(pit);
-       
-       if (pit->doit == NULL) {
-               if (pit->handle == NULL) {; } //XXX error("no plugin: %s", str);
-               else {; } //XXX error("in plugin: %s", str);
-               MEM_freeN(pit);
-               return NULL;
-       }
-       
-       varstr = pit->varstr;
-       for (a = 0; a < pit->vars; a++, varstr++) {
-               if ( (varstr->type & FLO) == FLO)
-                       pit->data[a] = varstr->def;
-               else if ( (varstr->type & INT) == INT)
-                       *((int *)(pit->data + a)) = (int) varstr->def;
-       }
-
-       if (pit->instance_init)
-               pit->instance_init((void *) pit->data);
-
-       return pit;
-}
-
-/* ------------------------------------------------------------------------- */
-
-void free_plugin_tex(PluginTex *pit)
-{
-       if (pit == NULL) return;
-               
-       /* no BLI_dynlib_close: same plugin can be opened multiple times, 1 handle */
-       MEM_freeN(pit); 
-}
-
 /* ****************** Mapping ******************* */
 
 TexMapping *add_tex_mapping(void)
@@ -233,7 +99,8 @@ void init_tex_mapping(TexMapping *texmap)
        float smat[3][3], rmat[3][3], mat[3][3], proj[3][3];
 
        if (texmap->projx == PROJ_X && texmap->projy == PROJ_Y && texmap->projz == PROJ_Z &&
-           is_zero_v3(texmap->loc) && is_zero_v3(texmap->rot) && is_one_v3(texmap->size)) {
+           is_zero_v3(texmap->loc) && is_zero_v3(texmap->rot) && is_one_v3(texmap->size))
+       {
                unit_m4(texmap->mat);
 
                texmap->flag |= TEXMAP_UNIT_MATRIX;
@@ -389,7 +256,9 @@ int do_colorband(const ColorBand *coba, float in, float out[4])
                                left.pos = 0.0f;
                                cbd2 = &left;
                        }
-                       else cbd2 = cbd1 - 1;
+                       else {
+                               cbd2 = cbd1 - 1;
+                       }
                        
                        if (in >= cbd1->pos && coba->ipotype < 2) {
                                out[0] = cbd1->r;
@@ -470,7 +339,7 @@ void colorband_table_RGBA(ColorBand *coba, float **array, int *size)
                do_colorband(coba, (float)a / (float)CM_TABLE, &(*array)[a * 4]);
 }
 
-int vergcband(const void *a1, const void *a2)
+static int vergcband(const void *a1, const void *a2)
 {
        const CBData *x1 = a1, *x2 = a2;
 
@@ -549,8 +418,6 @@ int colorband_element_remove(struct ColorBand *coba, int index)
 
 void BKE_texture_free(Tex *tex)
 {
-       free_plugin_tex(tex->plugin);
-       
        if (tex->coba) MEM_freeN(tex->coba);
        if (tex->env) BKE_free_envmap(tex->env);
        if (tex->pd) BKE_free_pointdensity(tex->pd);
@@ -572,10 +439,6 @@ void BKE_texture_free(Tex *tex)
 
 void default_tex(Tex *tex)
 {
-       PluginTex *pit;
-       VarStruct *varstr;
-       int a;
-
        tex->type = TEX_CLOUDS;
        tex->stype = 0;
        tex->flag = TEX_CHECKER_ODD;
@@ -643,15 +506,6 @@ void default_tex(Tex *tex)
                tex->ot->output = TEX_OCN_DISPLACEMENT;
                tex->ot->object = NULL;
        }
-       pit = tex->plugin;
-       if (pit) {
-               varstr = pit->varstr;
-               if (varstr) {
-                       for (a = 0; a < pit->vars; a++, varstr++) {
-                               pit->data[a] = varstr->def;
-                       }
-               }
-       }
        
        tex->iuser.fie_ima = 2;
        tex->iuser.ok = 1;
@@ -688,9 +542,8 @@ void tex_set_type(Tex *tex, int type)
 
 /* ------------------------------------------------------------------------- */
 
-Tex *add_texture(const char *name)
+Tex *add_texture(Main *bmain, const char *name)
 {
-       Main *bmain = G.main;
        Tex *tex;
 
        tex = BKE_libblock_alloc(&bmain->tex, ID_TE, name);
@@ -718,7 +571,7 @@ void default_mtex(MTex *mtex)
        mtex->size[1] = 1.0;
        mtex->size[2] = 1.0;
        mtex->tex = NULL;
-       mtex->texflag = MTEX_3TAP_BUMP | MTEX_BUMP_OBJECTSPACE;
+       mtex->texflag = MTEX_3TAP_BUMP | MTEX_BUMP_OBJECTSPACE | MTEX_MAPTO_BOUNDS;
        mtex->colormodel = 0;
        mtex->r = 1.0;
        mtex->g = 0.0;
@@ -763,6 +616,7 @@ void default_mtex(MTex *mtex)
        mtex->gravityfac = 1.0f;
        mtex->fieldfac = 1.0f;
        mtex->normapspace = MTEX_NSPACE_TANGENT;
+       mtex->brush_map_mode = MTEX_MAP_MODE_TILED;
 }
 
 
@@ -793,7 +647,7 @@ MTex *add_mtex_id(ID *id, int slot)
        
        if (slot == -1) {
                /* find first free */
-               int i;          
+               int i;
                for (i = 0; i < MAX_MTEX; i++) {
                        if (!mtex_ar[i]) {
                                slot = i;
@@ -832,11 +686,6 @@ Tex *BKE_texture_copy(Tex *tex)
        if (texn->type == TEX_IMAGE) id_us_plus((ID *)texn->ima);
        else texn->ima = NULL;
        
-       if (texn->plugin) {
-               texn->plugin = MEM_dupallocN(texn->plugin);
-               open_plugin_tex(texn->plugin);
-       }
-       
        if (texn->coba) texn->coba = MEM_dupallocN(texn->coba);
        if (texn->env) texn->env = BKE_copy_envmap(texn->env);
        if (texn->pd) texn->pd = BKE_copy_pointdensity(texn->pd);
@@ -864,11 +713,6 @@ Tex *localize_texture(Tex *tex)
        
        /* image texture: BKE_texture_free also doesn't decrease */
        
-       if (texn->plugin) {
-               texn->plugin = MEM_dupallocN(texn->plugin);
-               open_plugin_tex(texn->plugin);
-       }
-       
        if (texn->coba) texn->coba = MEM_dupallocN(texn->coba);
        if (texn->env) {
                texn->env = BKE_copy_envmap(texn->env);
@@ -1057,7 +901,7 @@ void autotexname(Tex *tex)
 {
        Main *bmain = G.main;
        char texstr[20][15] = {"None", "Clouds", "Wood", "Marble", "Magic", "Blend",
-                                  "Stucci", "Noise", "Image", "Plugin", "EnvMap", "Musgrave",
+                                  "Stucci", "Noise", "Image", "EnvMap", "Musgrave",
                                   "Voronoi", "DistNoise", "Point Density", "Voxel Data", "Ocean", "", "", ""};
        Image *ima;
        char di[FILE_MAXDIR], fi[FILE_MAXFILE];
@@ -1066,20 +910,21 @@ void autotexname(Tex *tex)
                if (tex->use_nodes) {
                        new_id(&bmain->tex, (ID *)tex, "Noddy");
                }
-               else
-               if (tex->type == TEX_IMAGE) {
+               else if (tex->type == TEX_IMAGE) {
                        ima = tex->ima;
                        if (ima) {
-                               BLI_strncpy(di, ima->name, sizeof(di));
-                               BLI_splitdirstring(di, fi);
+                               BLI_split_file_part(ima->name, fi, sizeof(fi));
                                strcpy(di, "I.");
                                strcat(di, fi);
                                new_id(&bmain->tex, (ID *)tex, di);
                        }
-                       else new_id(&bmain->tex, (ID *)tex, texstr[tex->type]);
+                       else {
+                               new_id(&bmain->tex, (ID *)tex, texstr[tex->type]);
+                       }
+               }
+               else {
+                       new_id(&bmain->tex, (ID *)tex, texstr[tex->type]);
                }
-               else if (tex->type == TEX_PLUGIN && tex->plugin) new_id(&bmain->tex, (ID *)tex, tex->plugin->pname);
-               else new_id(&bmain->tex, (ID *)tex, texstr[tex->type]);
        }
 }
 #endif
@@ -1231,19 +1076,21 @@ void set_current_material_texture(Material *ma, Tex *newtex)
 {
        Tex *tex = NULL;
        bNode *node;
-       
-       if (ma && ma->use_nodes && ma->nodetree) {
-               node = nodeGetActiveID(ma->nodetree, ID_TE);
 
-               if (node) {
-                       tex = (Tex *)node->id;
-                       id_us_min(&tex->id);
+       if ((ma->use_nodes && ma->nodetree) &&
+           (node = nodeGetActiveID(ma->nodetree, ID_TE)))
+       {
+               tex = (Tex *)node->id;
+               id_us_min(&tex->id);
+               if (newtex) {
                        node->id = &newtex->id;
                        id_us_plus(&newtex->id);
-                       ma = NULL;
+               }
+               else {
+                       node->id = NULL;
                }
        }
-       if (ma) {
+       else {
                int act = (int)ma->texact;
 
                tex = (ma->mtex[act]) ? ma->mtex[act]->tex : NULL;
@@ -1449,7 +1296,7 @@ PointDensity *BKE_add_pointdensity(void)
        pd->falloff_curve->preset = CURVE_PRESET_LINE;
        pd->falloff_curve->cm->flag &= ~CUMA_EXTEND_EXTRAPOLATE;
        curvemap_reset(pd->falloff_curve->cm, &pd->falloff_curve->clipr, pd->falloff_curve->preset, CURVEMAP_SLOPE_POSITIVE);
-       curvemapping_changed(pd->falloff_curve, 0);
+       curvemapping_changed(pd->falloff_curve, FALSE);
 
        return pd;
 } 
@@ -1564,21 +1411,17 @@ void BKE_free_oceantex(struct OceanTex *ot)
 /* ------------------------------------------------------------------------- */
 int BKE_texture_dependsOnTime(const struct Tex *texture)
 {
-       if (texture->plugin) {
-               // assume all plugins depend on time
-               return 1;
-       } 
-       else if (texture->ima &&
+       if (texture->ima &&
                 ELEM(texture->ima->source, IMA_SRC_SEQUENCE, IMA_SRC_MOVIE))
        {
                return 1;
        }
        else if (texture->adt) {
-               // assume anything in adt means the texture is animated
+               /* assume anything in adt means the texture is animated */
                return 1;
        }
        else if (texture->type == TEX_NOISE) {
-               // noise always varies with time
+               /* noise always varies with time */
                return 1;
        }
        return 0;