2.5 Material:
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Wed, 20 May 2009 13:34:04 +0000 (13:34 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Wed, 20 May 2009 13:34:04 +0000 (13:34 +0000)
* Added material "type" property, with Surface/Volume/Halo
  options, compatible with sim_physics, as requested for
  material buttons layout. Obviously the Volume setting
  does nothing currently.
* Deprecated MA_HALO flag in favor of this.

release/ui/buttons_material.py
source/blender/blenkernel/intern/ipo.c
source/blender/blenloader/intern/readfile.c
source/blender/editors/interface/interface_icons.c
source/blender/editors/preview/previewrender.c
source/blender/editors/space_view3d/drawobject.c
source/blender/makesdna/DNA_material_types.h
source/blender/makesrna/intern/rna_material.c
source/blender/makesrna/intern/rna_scene.c
source/blender/render/intern/source/convertblender.c
source/blender/render/intern/source/rendercore.c

index 551a62cfc84f897aace167cd2f9d6e224b6a9575..af24bba57c7a3cf5ed1be59985d7d92db06f31b8 100644 (file)
@@ -5,40 +5,41 @@ class MaterialButtonsPanel(bpy.types.Panel):
        __space_type__ = "BUTTONS_WINDOW"
        __region_type__ = "WINDOW"
        __context__ = "material"
+
+       def poll(self, context):
+               ob = context.active_object
+               return (ob and ob.active_material)
        
 class MATERIAL_PT_material(MaterialButtonsPanel):
        __idname__= "MATERIAL_PT_material"
        __label__ = "Material"
-       
+
        def draw(self, context):
                layout = self.layout
-               try:            
-                       mat = context.active_object.active_material
-               except: 
-                       mat = None
-               
-               if not mat:
-                       return
+               mat = context.active_object.active_material
        
+               row = layout.row()
+               row.itemR(mat, "type", expand=True)
+
                row = layout.row()
                row.column().itemR(mat, "diffuse_color")
                row.column().itemR(mat, "specular_color")
                row.column().itemR(mat, "mirror_color")
                
                row = layout.row()
-               row.itemR(mat, "color_model")
                row.itemR(mat, "alpha")
                        
 class MATERIAL_PT_sss(MaterialButtonsPanel):
        __idname__= "MATERIAL_PT_sss"
        __label__ = "Subsurface Scattering"
+
+       def poll(self, context):
+               ob = context.active_object
+               return (ob and ob.active_material and ob.active_material.type == "SURFACE")
        
        def draw(self, context):
                layout = self.layout
-               try:            
-                       sss = context.active_object.active_material.subsurface_scattering
-               except: 
-                       sss = None
+               sss = context.active_object.active_material.subsurface_scattering
                
                if not sss:
                        return
@@ -66,7 +67,7 @@ class MATERIAL_PT_raymir(MaterialButtonsPanel):
        
        def poll(self, context):
                ob = context.active_object
-               return (ob and ob.active_material)
+               return (ob and ob.active_material and ob.active_material.type == "SURFACE")
        
        def draw_header(self, context):
                raym = context.active_object.active_material.raytrace_mirror
@@ -99,16 +100,14 @@ class MATERIAL_PT_raymir(MaterialButtonsPanel):
 class MATERIAL_PT_raytransp(MaterialButtonsPanel):
        __idname__= "MATERIAL_PT_raytransp"
        __label__= "Ray Transparency"
+       
+       def poll(self, context):
+               ob = context.active_object
+               return (ob and ob.active_material and ob.active_material.type == "SURFACE")
 
        def draw(self, context):
                layout = self.layout
-               try:            
-                       rayt = context.active_object.active_material.raytrace_transparency
-               except: 
-                       rayt = None
-
-               if not rayt:
-                       return
+               rayt = context.active_object.active_material.raytrace_transparency
 
                layout.itemR(rayt, "enabled", text="Enable")
                
@@ -135,61 +134,56 @@ class MATERIAL_PT_halo(MaterialButtonsPanel):
        __idname__= "MATERIAL_PT_halo"
        __label__= "Halo"
        
+       def poll(self, context):
+               ob = context.active_object
+               return (ob and ob.active_material and ob.active_material.type == "HALO")
+       
        def draw(self, context):
                layout = self.layout
-               try:            
-                       halo = context.active_object.active_material.halo
-               except: 
-                       halo = None
+               mat = context.active_object.active_material
+               halo = mat.halo
 
-               if not halo:
-                       return
-       
-               layout.itemR(halo, "enabled", text="Enable Halo")
-
-               if halo.enabled:
-                       
-                       split = layout.split()
-                       
-                       sub = split.column()
-                       sub.itemL(text="General Settings:")
-                       sub.itemR(halo, "size")
-                       sub.itemR(halo, "hardness")
-                       sub.itemR(halo, "add")
-                       
-                       sub = split.column()
-                       sub.itemL(text="Elements:")
-                       sub.itemR(halo, "ring")
-                       sub.itemR(halo, "lines")
-                       sub.itemR(halo, "star")
-                       sub.itemR(halo, "flare_mode")
+               split = layout.split()
+               
+               sub = split.column()
+               sub.itemL(text="General Settings:")
+               sub.itemR(halo, "size")
+               sub.itemR(halo, "hardness")
+               sub.itemR(halo, "add")
+               
+               sub = split.column()
+               sub.itemL(text="Elements:")
+               sub.itemR(halo, "ring")
+               sub.itemR(halo, "lines")
+               sub.itemR(halo, "star")
+               sub.itemR(halo, "flare_mode")
 
-                       row = layout.row()
-                       
-                       sub = row.column()
-                       sub.itemL(text="Options:")
-                       sub.itemR(halo, "use_texture", text="Texture")
-                       sub.itemR(halo, "use_vertex_normal", text="Vertex Normal")
-                       sub.itemR(halo, "xalpha")
-                       sub.itemR(halo, "shaded")
-                       sub.itemR(halo, "soft")
-               
-                       sub = row.column()
-                       if (halo.ring):
-                               sub.itemR(halo, "rings")
-                       if (halo.lines):
-                               sub.itemR(halo, "line_number")
-                       if (halo.ring or halo.lines):
-                               sub.itemR(halo, "seed")
-                       if (halo.star):
-                               sub.itemR(halo, "star_tips")
-                       if (halo.flare_mode):
-                               sub.itemL(text="Flare:")
-                               sub.itemR(halo, "flare_size", text="Size")
-                               sub.itemR(halo, "flare_subsize", text="Subsize")
-                               sub.itemR(halo, "flare_boost", text="Boost")
-                               sub.itemR(halo, "flare_seed", text="Seed")
-                               sub.itemR(halo, "flares_sub", text="Sub")
+               row = layout.row()
+               
+               sub = row.column()
+               sub.itemL(text="Options:")
+               sub.itemR(halo, "use_texture", text="Texture")
+               sub.itemR(halo, "use_vertex_normal", text="Vertex Normal")
+               sub.itemR(halo, "xalpha")
+               sub.itemR(halo, "shaded")
+               sub.itemR(halo, "soft")
+       
+               sub = row.column()
+               if (halo.ring):
+                       sub.itemR(halo, "rings")
+               if (halo.lines):
+                       sub.itemR(halo, "line_number")
+               if (halo.ring or halo.lines):
+                       sub.itemR(halo, "seed")
+               if (halo.star):
+                       sub.itemR(halo, "star_tips")
+               if (halo.flare_mode):
+                       sub.itemL(text="Flare:")
+                       sub.itemR(halo, "flare_size", text="Size")
+                       sub.itemR(halo, "flare_subsize", text="Subsize")
+                       sub.itemR(halo, "flare_boost", text="Boost")
+                       sub.itemR(halo, "flare_seed", text="Seed")
+                       sub.itemR(halo, "flares_sub", text="Sub")
                                
 bpy.types.register(MATERIAL_PT_material)
 bpy.types.register(MATERIAL_PT_raymir)
index 43791e32b3805693ed49edbf563d69afd018d04f..6a01311f6fc28795a2e6a3466e952ef200f895ad 100644 (file)
@@ -160,7 +160,7 @@ static AdrBit2Path ma_mode_bits[]= {
 //     ...
        {MA_RAYTRANSP, "raytrace_transparency.enabled", 0},
        {MA_RAYMIRROR, "raytrace_mirror.enabled", 0},
-       {MA_HALO, "halo.enabled", 0}
+//     {MA_HALO, "type", MA_TYPE_HALO}
 };
 
 /* ----------------- */
index c680c6b3b544531141f275d6b3856eecb5e8ceff..9c5735a3020150f5103d80cc99b7bc7ab9e94d5c 100644 (file)
@@ -8912,6 +8912,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
           bump the version (or sub-version.) */
        {
                Object *ob;
+               Material *ma;
                int i;
 
                for(ob = main->object.first; ob; ob = ob->id.next) {
@@ -8977,6 +8978,13 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                                ob->data = olddata;
                        }
                }
+
+               for(ma = main->mat.first; ma; ma = ma->id.next) {
+                       if(ma->mode & MA_HALO) {
+                               ma->material_type= MA_TYPE_HALO;
+                               ma->mode &= ~MA_HALO;
+                       }
+               }
        }
 
        /* WATCH IT!!!: pointers from libdata have not been converted yet here! */
index 0c97c1fd008fb8668e00aa4d2aac628e02bb1066..1b23967a32dce48486f04949f544302fb537cb3a 100644 (file)
@@ -813,7 +813,7 @@ static void icon_set_image(ID *id, DrawInfo *di, PreviewImage* prv_img, int mipl
                } 
                else if (GS(id->name) == ID_MA) {
                        Material* mat = (Material*)id;
-                       if (mat->mode & MA_HALO) {
+                       if (mat->material_type == MA_TYPE_HALO) {
                                set_alpha( (char*) ri.rect, ri.pr_rectx, ri.pr_recty, 255);
                        }
                }
index 407674163a6b9c4dbc60bcd6d653f5ed35f4699f..1d5d809a9ee5c7a82523663d7c79c7d4dfac25b0 100644 (file)
@@ -349,7 +349,7 @@ static Scene *preview_prepare_scene(Scene *scene, int id_type, ShaderPreview *sp
 
                                
                                if(sp->pr_method==PR_ICON_RENDER) {
-                                       if (mat->mode & MA_HALO) {
+                                       if (mat->material_type == MA_TYPE_HALO) {
                                                sce->lay= 1<<MA_FLAT;
                                        } 
                                        else {
index f2528f0241feea6cc92701545bc99e97807f574b..054cd4e966e813ada5d1feeab44baf8196c6f395 100644 (file)
@@ -2281,7 +2281,7 @@ static void draw_mesh_fancy(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base
        Object *ob= base->object;
        Mesh *me = ob->data;
        Material *ma= give_current_material(ob, 1);
-       int hasHaloMat = (ma && (ma->mode&MA_HALO));
+       int hasHaloMat = (ma && (ma->material_type == MA_TYPE_HALO));
        int draw_wire = 0;
        int totvert, totedge, totface;
        DispList *dl;
index 4ffd20605689698014531d601ada7d914b535e10..cd0b73c8f70dbe5bd073c07bff4f2f369939ece7 100644 (file)
@@ -52,7 +52,7 @@ typedef struct Material {
        ID id;
        struct AnimData *adt;   /* animation data (must be immediately after id for utilities to use it) */ 
        
-       short colormodel, flag; 
+       short material_type, flag;      
        /* note, keep this below synced with render_types.h */
        float r, g, b;
        float specr, specg, specb;
@@ -147,11 +147,10 @@ typedef struct Material {
         */
 #define MAXMAT                 16
 
-/* colormodel */
-#define MA_RGB                 0
-#define MA_CMYK                        1
-#define MA_YUV                 2
-#define MA_HSV                 3
+/* material_type */
+#define MA_TYPE_SURFACE        0
+#define MA_TYPE_HALO   1
+#define MA_TYPE_VOLUME 2
 
 /* flag */
                /* for render */
@@ -166,7 +165,7 @@ typedef struct Material {
 #define MA_WIRE                        8
 #define MA_VERTEXCOL   16
 #define MA_HALO_SOFT   16
-#define MA_HALO                        32
+#define MA_HALO                        32                      /* deprecated */
 #define MA_ZTRA                        64
 #define MA_VERTEXCOLP  128
 #define MA_ZINV                        256
index b5f4ee98dfeed6f0f5790cbfc4a2f6ad636768c7..101cd2a801f00cad3ae4902294c53ef9a06b6e25 100644 (file)
@@ -62,14 +62,14 @@ static PointerRNA rna_Material_strand_get(PointerRNA *ptr)
        return rna_pointer_inherit_refine(ptr, &RNA_MaterialStrand, ptr->id.data);
 }
 
-static void rna_Material_mode_halo_set(PointerRNA *ptr, int value)
+static void rna_Material_type_set(PointerRNA *ptr, int value)
 {
        Material *ma= (Material*)ptr->data;
-       
-       if(value)
-               ma->mode |= MA_HALO;
-       else
-               ma->mode &= ~(MA_HALO|MA_STAR|MA_HALO_XALPHA|MA_ZINV|MA_ENV);
+
+       if(ma->material_type == MA_TYPE_HALO && value != MA_TYPE_HALO)
+               ma->mode &= ~(MA_STAR|MA_HALO_XALPHA|MA_ZINV|MA_ENV);
+
+       ma->material_type= value;
 }
 
 static void rna_Material_mtex_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
@@ -178,7 +178,7 @@ static void rna_def_material_mtex(BlenderRNA *brna)
        RNA_def_property_enum_items(prop, prop_mapping_items);
        RNA_def_property_ui_text(prop, "Mapping", "");
 
-       /* XXX: MTex.colormodel, pmapto, pmaptoneg */
+       /* XXX: pmapto, pmaptoneg */
 
        prop= RNA_def_property(srna, "normal_map_space", PROP_ENUM, PROP_NONE);
        RNA_def_property_enum_sdna(prop, NULL, "normapspace");
@@ -204,18 +204,6 @@ static void rna_def_material_colors(StructRNA *srna)
 {
        PropertyRNA *prop;
 
-       static EnumPropertyItem prop_type_items[] = {
-               {MA_RGB, "RGB", "RGB", ""},
-               // {MA_CMYK, "CMYK", "CMYK", ""}, 
-               // {MA_YUV, "YUV", "YUV", ""},
-               {MA_HSV, "HSV", "HSV", ""},
-               {0, NULL, NULL, NULL}};
-       
-       prop= RNA_def_property(srna, "color_model", PROP_ENUM, PROP_NONE);
-       RNA_def_property_enum_sdna(prop, NULL, "colormodel");
-       RNA_def_property_enum_items(prop, prop_type_items);
-       RNA_def_property_ui_text(prop, "Color Model", "Color model to display color values with in the user interface.");
-       
        prop= RNA_def_property(srna, "diffuse_color", PROP_FLOAT, PROP_COLOR);
        RNA_def_property_float_sdna(prop, NULL, "r");
        RNA_def_property_array(prop, 3);
@@ -466,12 +454,6 @@ static void rna_def_material_halo(BlenderRNA *brna)
        RNA_def_struct_nested(brna, srna, "Material");
        RNA_def_struct_ui_text(srna, "Material Halo", "Halo particle effect settings for a Material datablock.");
 
-       prop= RNA_def_property(srna, "enabled", PROP_BOOLEAN, PROP_NONE);
-       RNA_def_property_boolean_sdna(prop, NULL, "mode", MA_HALO); /* use bitflags */
-       RNA_def_property_ui_text(prop, "Enabled", "Enables halo rendering of material.");
-       RNA_def_property_boolean_funcs(prop, NULL, "rna_Material_mode_halo_set");
-       RNA_def_property_update(prop, NC_MATERIAL|ND_SHADING_DRAW, NULL);
-       
        prop= RNA_def_property(srna, "size", PROP_FLOAT, PROP_NONE);
        RNA_def_property_float_sdna(prop, NULL, "hasize");
        RNA_def_property_range(prop, 0.0f, 100.0f);
@@ -737,12 +719,25 @@ void rna_def_material_strand(BlenderRNA *brna)
 
 void RNA_def_material(BlenderRNA *brna)
 {
-       StructRNA *srna= NULL;
-       PropertyRNA *prop= NULL;
+       StructRNA *srna;
+       PropertyRNA *prop;
+
+       static EnumPropertyItem prop_type_items[] = {
+               {MA_TYPE_SURFACE, "SURFACE", "Surface", "Render object as a surface."},
+               {MA_TYPE_VOLUME, "VOLUME", "Volume", "Render object as a volume."},
+               {MA_TYPE_HALO, "HALO", "Halo", "Render object as halo particles."},
+               {0, NULL, NULL, NULL}};
 
        srna= RNA_def_struct(brna, "Material", "ID");
        RNA_def_struct_ui_text(srna, "Material", "Material datablock to defined the appearance of geometric objects for rendering.");
-
+       
+       prop= RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);
+       RNA_def_property_enum_sdna(prop, NULL, "material_type");
+       RNA_def_property_enum_items(prop, prop_type_items);
+       RNA_def_property_ui_text(prop, "Type", "Material type defining how the object is rendered.");
+       RNA_def_property_enum_funcs(prop, NULL, "rna_Material_type_set");
+       RNA_def_property_update(prop, NC_MATERIAL|ND_SHADING_DRAW, NULL);
+       
        prop= RNA_def_property(srna, "ambient", PROP_FLOAT, PROP_NONE);
        RNA_def_property_float_sdna(prop, NULL, "amb");
        RNA_def_property_range(prop, 0, 1);
index 78f0b156eb2f617592aa0174ea5e98618832e576..3ba73aef52db272978edd8e2e33ffa80b6617080 100644 (file)
@@ -256,7 +256,7 @@ void rna_def_scene_render_data(BlenderRNA *brna)
        prop= RNA_def_property(srna, "color_mode", PROP_ENUM, PROP_NONE);
        RNA_def_property_enum_bitflag_sdna(prop, NULL, "planes");
        RNA_def_property_enum_items(prop, color_mode_items);
-       RNA_def_property_ui_text(prop, "Colour Mode", "What Colour Mode images are saved in (BW, RGB, RGBA)");
+       RNA_def_property_ui_text(prop, "Color Mode", "What Color Mode images are saved in (BW, RGB, RGBA)");
        
        prop= RNA_def_property(srna, "resolution_x", PROP_INT, PROP_NONE);
        RNA_def_property_int_sdna(prop, NULL, "xsch");
index ce324239492d1268d554e9463f6918b6e336fbfd..4ca7244e976b67b7a4d30a269cd3eaa49c88be62 100644 (file)
@@ -1387,7 +1387,7 @@ static void render_new_particle(Render *re, ObjectRen *obr, DerivedMesh *dm, Mat
 
        if(ma->mode&MA_WIRE)
                static_particle_wire(obr, ma, loc, loc1, sd->first, sd->line);
-       else if(ma->mode & MA_HALO){
+       else if(ma->material_type == MA_TYPE_HALO) {
                har= RE_inithalo_particle(re, obr, dm, ma, loc, loc1, sd->orco, sd->uvco, sd->size, 1.0, seed);
                if(har) har->lay= obr->ob->lay;
        }
@@ -1593,7 +1593,7 @@ static int render_new_particle_system(Render *re, ObjectRen *obr, ParticleSystem
                path_nbr=(int)pow(2.0,(double) part->ren_step);
 
                if(path_nbr) {
-                       if((ma->mode & (MA_HALO|MA_WIRE))==0) {
+                       if((ma->material_type != MA_TYPE_HALO) && (ma->mode & MA_WIRE)==0) {
                                sd.orco = MEM_mallocN(3*sizeof(float)*(totpart+totchild), "particle orcos");
                                set_object_orco(re, psys, sd.orco);
                        }
@@ -3035,7 +3035,7 @@ static void init_render_mesh(Render *re, ObjectRen *obr, int timeoffset)
        
        ma= give_render_material(re, ob, 1);
 
-       if(ma->mode & MA_HALO) {
+       if(ma->material_type == MA_TYPE_HALO) {
                make_render_halos(re, obr, me, totvert, mvert, ma, orco);
        }
        else {
@@ -4401,7 +4401,7 @@ static int allow_render_dupli_instance(Render *re, DupliObject *dob, Object *obd
        if(totmaterial) {
                for(a= 0; a<*totmaterial; a++) {
                        ma= give_current_material(obd, a);
-                       if(ma && (ma->mode & MA_HALO))
+                       if(ma && (ma->material_type == MA_TYPE_HALO))
                                return 0;
                }
        }
index deb6f0db74381ebd26b282612000ab7701615bb7..27dd43a4ef9e56c3b5938ad45424fea4803bd0ee 100644 (file)
@@ -703,7 +703,7 @@ static void atm_tile(RenderPart *pa, RenderLayer *rl)
                        for(sample=0; sample<totsample; sample++) {
                                float *zrect= RE_RenderLayerGetPass(rlpp[sample], SCE_PASS_Z) + od;
                                float *rgbrect = rlpp[sample]->rectf + 4*od;
-                               float rgb[3];
+                               float rgb[3] = {0};
                                int done= 0;
                                
                                for(go=R.lights.first; go; go= go->next) {