Show Cone option for spot lamps, to visualize which objects are being affected.
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Mon, 25 Jan 2010 14:47:32 +0000 (14:47 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Mon, 25 Jan 2010 14:47:32 +0000 (14:47 +0000)
release/scripts/ui/properties_data_lamp.py
source/blender/editors/space_view3d/drawobject.c
source/blender/makesdna/DNA_lamp_types.h
source/blender/makesrna/intern/rna_camera.c
source/blender/makesrna/intern/rna_lamp.c

index 24f6486..d12138e 100644 (file)
@@ -352,6 +352,7 @@ class DATA_PT_spot(DataButtonsPanel):
         sub.prop(lamp, "spot_size", text="Size")
         sub.prop(lamp, "spot_blend", text="Blend", slider=True)
         col.prop(lamp, "square")
+        col.prop(lamp, "show_cone")
 
         if wide_ui:
             col = split.column()
index 6911a24..57d6f7f 100644 (file)
@@ -765,18 +765,89 @@ static void spotvolume(float *lvec, float *vvec, float inp)
        return;
 }
 
-static void drawlamp(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object *ob)
+static void draw_spot_cone(Lamp *la, float x, float z)
 {
-       Lamp *la;
+       float vec[3];
+
+       z= fabs(z);
+
+       glBegin(GL_TRIANGLE_FAN);
+       glVertex3f(0.0f, 0.0f, -x);
+
+       if(la->mode & LA_SQUARE) {
+               vec[0]= z;
+               vec[1]= z;
+               vec[2]= 0.0;
+
+               glVertex3fv(vec);
+               vec[1]= -z;
+               glVertex3fv(vec);
+               vec[0]= -z;
+               glVertex3fv(vec);
+               vec[1]= z;
+               glVertex3fv(vec);
+       }
+       else {
+               float angle;
+               int a;
+
+               for(a=0; a<33; a++) {
+                       angle= a*M_PI*2/(33-1);
+                       glVertex3f(z*cos(angle), z*sin(angle), 0);
+               }
+       }
+
+       glEnd();
+}
+
+static void draw_transp_spot_volume(Lamp *la, float x, float z)
+{
+       glEnable(GL_CULL_FACE);
+       glEnable(GL_BLEND);
+       glDepthMask(0);
+
+       /* draw backside darkening */
+       glCullFace(GL_FRONT);
+
+       glBlendFunc(GL_ZERO, GL_SRC_ALPHA);
+       glColor4f(0.0f, 0.0f, 0.0f, 0.4f);
+
+       draw_spot_cone(la, x, z);
+
+       /* draw front side lightening */
+       glCullFace(GL_BACK);
+
+       glBlendFunc(GL_ONE,  GL_ONE); 
+       glColor4f(0.2f, 0.2f, 0.2f, 1.0f);
+
+       draw_spot_cone(la, x, z);
+
+       /* restore state */
+       glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+       glDisable(GL_BLEND);
+       glDepthMask(1);
+       glDisable(GL_CULL_FACE);
+       glCullFace(GL_BACK);
+}
+
+static void drawlamp(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base, int dt, int flag)
+{
+       Object *ob= base->object;
+       Lamp *la= ob->data;
        float vec[3], lvec[3], vvec[3], circrad, x,y,z;
        float pixsize, lampsize;
        float imat[4][4], curcol[4];
        char col[4];
+       int drawcone= (dt>OB_WIRE && !(G.f & G_PICKSEL) && la->type == LA_SPOT && (la->mode & LA_SHOW_CONE));
 
        if(G.f & G_RENDER_SHADOW)
                return;
        
-       la= ob->data;
+       if(drawcone && !v3d->transp) {
+               /* in this case we need to draw delayed */
+               add_view3d_after(v3d, base, V3D_TRANSP, flag);
+               return;
+       }
        
        /* we first draw only the screen aligned & fixed scale stuff */
        glPushMatrix();
@@ -888,12 +959,8 @@ static void drawlamp(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object *ob)
                y = cos( M_PI*la->spotsize/360.0 );
                spotvolume(lvec, vvec, y);
                x = -la->dist;
-               lvec[0] *=  x ; 
-               lvec[1] *=  x ; 
-               lvec[2] *=  x;
-               vvec[0] *= x ; 
-               vvec[1] *= x ; 
-               vvec[2] *= x;
+               mul_v3_fl(lvec, x);
+               mul_v3_fl(vvec, x);
 
                /* draw the angled sides of the cone */
                glBegin(GL_LINE_STRIP);
@@ -932,7 +999,9 @@ static void drawlamp(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object *ob)
                        if (spotblcirc != 0 && spotblcirc != fabs(z))
                                circ(0.0, 0.0, spotblcirc);
                }
-               
+
+               if(drawcone)
+                       draw_transp_spot_volume(la, x, z);
        }
        else if ELEM(la->type, LA_HEMI, LA_SUN) {
                
@@ -5516,7 +5585,7 @@ void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, int flag)
                        drawaxes(ob->empty_drawsize, flag, ob->empty_drawtype);
                        break;
                case OB_LAMP:
-                       drawlamp(scene, v3d, rv3d, ob);
+                       drawlamp(scene, v3d, rv3d, base, dt, flag);
                        if(dtx || (base->flag & SELECT)) wmMultMatrix(ob->obmat);
                        break;
                case OB_CAMERA:
index c321c9f..e5a7abe 100644 (file)
@@ -145,6 +145,7 @@ typedef struct Lamp {
 #define LA_YF_SOFT             16384
 #define LA_LAYER_SHADOW        32768
 #define LA_SHAD_TEX     (1<<16)
+#define LA_SHOW_CONE    (1<<17)
 
 /* layer_shadow */
 #define LA_LAYER_SHADOW_BOTH   0
index e853852..be7feb9 100644 (file)
@@ -79,7 +79,6 @@ void RNA_def_camera(BlenderRNA *brna)
 
        prop= RNA_def_property(srna, "passepartout_alpha", PROP_FLOAT, PROP_FACTOR);
        RNA_def_property_float_sdna(prop, NULL, "passepartalpha");
-       RNA_def_property_range(prop, 0.0f, 1.0f);
        RNA_def_property_ui_text(prop, "Passepartout Alpha", "Opacity (alpha) of the darkened overlay in Camera view.");
        RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, NULL);
 
index 5112e68..47d7b5f 100644 (file)
@@ -646,6 +646,11 @@ static void rna_def_spot_lamp(BlenderRNA *brna)
        RNA_def_property_ui_text(prop, "Spot Size", "Angle of the spotlight beam in degrees.");
        RNA_def_property_update(prop, 0, "rna_Lamp_draw_update");
 
+       prop= RNA_def_property(srna, "show_cone", PROP_BOOLEAN, PROP_NONE);
+       RNA_def_property_boolean_sdna(prop, NULL, "mode", LA_SHOW_CONE);
+       RNA_def_property_ui_text(prop, "Show Cone", "Draw transparent cone in 3D view to visualize which objects are contained in it.");
+       RNA_def_property_update(prop, 0, "rna_Lamp_draw_update");
+
        prop= RNA_def_property(srna, "shadow_buffer_clip_start", PROP_FLOAT, PROP_DISTANCE);
        RNA_def_property_float_sdna(prop, NULL, "clipsta");
        RNA_def_property_range(prop, 0.0f, 9999.0f);