[Bf-committers] [Bf-blender-cvs] SVN commit: /data/svn/bf-blender [41427] branches/bmesh/blender/source/ blender/bmesh/operators/subdivideop.c: subdivide smooth now works as in trunk.

Campbell Barton ideasman42 at gmail.com
Tue Nov 8 00:37:16 CET 2011


Not stored, I meant the normal of the vertex if it had the shape key
applied, this could be calculated but would mean getting the coords
for all face users and building it for each vertex or temp applying
the shape, getting the normals and storing in a separate array.

On Tue, Nov 8, 2011 at 10:30 AM, joe <joeedh at gmail.com> wrote:
> Shape keys have normals?
>
> On Mon, Oct 31, 2011 at 10:17 PM, Campbell Barton <ideasman42 at gmail.com> wrote:
>> Revision: 41427
>>          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=41427
>> Author:   campbellbarton
>> Date:     2011-11-01 05:17:46 +0000 (Tue, 01 Nov 2011)
>> Log Message:
>> -----------
>> subdivide smooth now works as in trunk.
>> - r35832 joeedh removed this with comment "removed the "smoothness" parameter (which never worked, anyway, even in trunk)", not sure I agree here... just because its not perfect doesnt mean its not working, anyway, to support in bmesh at the same level as trunk is not much effort.
>> - calculating the coordinates was being done on every shape key, I can see this could be useful to subdiv worked on all shape keys BUT the existing code didnt do this properly, for it to work right the normals would need to be updated for each shape key too when calculating smoothing, so now just calculate the new subdivided location and apply the difference to all other shape keys.
>>
>> Revision Links:
>> --------------
>>    http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=35832
>>
>> Modified Paths:
>> --------------
>>    branches/bmesh/blender/source/blender/bmesh/operators/subdivideop.c
>>
>> Modified: branches/bmesh/blender/source/blender/bmesh/operators/subdivideop.c
>> ===================================================================
>> --- branches/bmesh/blender/source/blender/bmesh/operators/subdivideop.c 2011-11-01 04:31:25 UTC (rev 41426)
>> +++ branches/bmesh/blender/source/blender/bmesh/operators/subdivideop.c 2011-11-01 05:17:46 UTC (rev 41427)
>> @@ -168,74 +168,80 @@
>>  static void alter_co(BMesh *bm, BMVert *v, BMEdge *UNUSED(origed), const subdparams *params, float perc,
>>                     BMVert *vsta, BMVert *vend)
>>  {
>> -       float tvec[3], fac;
>> -       float *co=NULL, *origco=NULL;
>> +       float tvec[3], prev_co[3], fac;
>> +       float *co=NULL;
>>        int i, totlayer = CustomData_number_of_layers(&bm->vdata, CD_SHAPEKEY);
>>
>>        BM_Vert_UpdateAllNormals(bm, v);
>>
>> -       origco = CustomData_bmesh_get_n(&bm->vdata, v->head.data, CD_SHAPEKEY, params->origkey);
>> -       sub_v3_v3v3(tvec, origco, v->co);
>> -
>> -       for (i=0; i<totlayer; i++) {
>> -               co = CustomData_bmesh_get_n(&bm->vdata, v->head.data, CD_SHAPEKEY, i);
>> -               sub_v3_v3(co, tvec);
>> +       co = CustomData_bmesh_get_n(&bm->vdata, v->head.data, CD_SHAPEKEY, params->origkey);
>> +       copy_v3_v3(prev_co, co);
>> +
>> +       if(params->beauty & B_SMOOTH) {
>> +               /* we calculate an offset vector vec1[], to be added to *co */
>> +               float len, nor[3], nor1[3], nor2[3], smooth=params->smooth;
>> +
>> +               sub_v3_v3v3(nor, vsta->co, vend->co);
>> +               len= 0.5f*normalize_v3(nor);
>> +
>> +               copy_v3_v3(nor1, vsta->no);
>> +               copy_v3_v3(nor2, vend->no);
>> +
>> +               /* cosine angle */
>> +               fac=  dot_v3v3(nor, nor1);
>> +               mul_v3_v3fl(tvec, nor1, fac);
>> +
>> +               /* cosine angle */
>> +               fac= -dot_v3v3(nor, nor2);
>> +               madd_v3_v3fl(tvec, nor2, fac);
>> +
>> +               /* falloff for multi subdivide */
>> +               smooth *= sqrtf(fabsf(1.0f - 2.0f*fabsf(0.5f-perc)));
>> +
>> +               mul_v3_fl(tvec, smooth * len);
>> +
>> +               add_v3_v3(co, tvec);
>>        }
>> +       else if(params->beauty & B_SPHERE) { /* subdivide sphere */
>> +               normalize_v3(co);
>> +               mul_v3_fl(co, params->smooth);
>> +       }
>>
>> +       if(params->beauty & B_FRACTAL) {
>> +               float len = len_v3v3(vsta->co, vend->co);
>> +               float vec2[3] = {0.0f, 0.0f, 0.0f}, co2[3];
>> +
>> +               fac= params->fractal*len;
>> +
>> +               add_v3_v3(vec2, vsta->no);
>> +               add_v3_v3(vec2, vend->no);
>> +               mul_v3_fl(vec2, 0.5f);
>> +
>> +               add_v3_v3v3(co2, v->co, params->off);
>> +               tvec[0] = fac*(BLI_gTurbulence(1.0, co2[0], co2[1], co2[2], 15, 0, 1)-0.5f);
>> +               tvec[1] = fac*(BLI_gTurbulence(1.0, co2[0], co2[1], co2[2], 15, 0, 1)-0.5f);
>> +               tvec[2] = fac*(BLI_gTurbulence(1.0, co2[0], co2[1], co2[2], 15, 0, 1)-0.5f);
>> +
>> +               mul_v3_v3(vec2, tvec);
>> +
>> +               /*add displacement*/
>> +               add_v3_v3v3(co, co, vec2);
>> +       }
>> +
>> +       /* apply the new difference to the rest of the shape keys,
>> +        * note that this doent take rotations into account, we _could_ support
>> +        * this by getting the normals and coords for each shape key and
>> +        * re-calculate the smooth value for each but this is quite involved.
>> +        * for now its ok to simply apply the difference IMHO - campbell */
>> +       sub_v3_v3v3(tvec, prev_co, co);
>> +
>>        for (i=0; i<totlayer; i++) {
>> -               co = CustomData_bmesh_get_n(&bm->vdata, v->head.data, CD_SHAPEKEY, i);
>> -
>> -               if(params->beauty & B_SMOOTH) {
>> -                       /* we calculate an offset vector vec1[], to be added to *co */
>> -                       float len, nor[3], nor1[3], nor2[3], smooth=params->smooth;
>> -
>> -                       sub_v3_v3v3(nor, vsta->co, vend->co);
>> -                       len= 0.5f*normalize_v3(nor);
>> -
>> -                       copy_v3_v3(nor1, vsta->no);
>> -                       copy_v3_v3(nor2, vend->no);
>> -
>> -                       /* cosine angle */
>> -                       fac=  dot_v3v3(nor, nor1);
>> -                       mul_v3_v3fl(tvec, nor1, fac);
>> -
>> -                       /* cosine angle */
>> -                       fac= -dot_v3v3(nor, nor2);
>> -                       madd_v3_v3fl(tvec, nor2, fac);
>> -
>> -                       /* falloff for multi subdivide */
>> -                       smooth *= sqrtf(fabsf(1.0f - 2.0f*fabsf(0.5f-perc)));
>> -
>> -                       mul_v3_fl(tvec, smooth * len);
>> -
>> -                       add_v3_v3(co, tvec);
>> +               if (params->origkey != i) {
>> +                       co = CustomData_bmesh_get_n(&bm->vdata, v->head.data, CD_SHAPEKEY, i);
>> +                       sub_v3_v3(co, tvec);
>>                }
>> -               else if(params->beauty & B_SPHERE) { /* subdivide sphere */
>> -                       normalize_v3(co);
>> -                       mul_v3_fl(co, params->smooth);
>> -               }
>> -
>> -               if(params->beauty & B_FRACTAL) {
>> -                       float len = len_v3v3(vsta->co, vend->co);
>> -                       float vec2[3] = {0.0f, 0.0f, 0.0f}, co2[3];
>> -
>> -                       fac= params->fractal*len;
>> +       }
>>
>> -                       add_v3_v3(vec2, vsta->no);
>> -                       add_v3_v3(vec2, vend->no);
>> -                       mul_v3_fl(vec2, 0.5f);
>> -
>> -                       add_v3_v3v3(co2, v->co, params->off);
>> -                       tvec[0] = fac*(BLI_gTurbulence(1.0, co2[0], co2[1], co2[2], 15, 0, 1)-0.5f);
>> -                       tvec[1] = fac*(BLI_gTurbulence(1.0, co2[0], co2[1], co2[2], 15, 0, 1)-0.5f);
>> -                       tvec[2] = fac*(BLI_gTurbulence(1.0, co2[0], co2[1], co2[2], 15, 0, 1)-0.5f);
>> -
>> -                       mul_v3_v3(vec2, tvec);
>> -
>> -                       /*add displacement*/
>> -                       add_v3_v3v3(co, co, vec2);
>> -               }
>> -       }
>>  }
>>
>>  /* assumes in the edge is the correct interpolated vertices already */
>>
>> _______________________________________________
>> Bf-blender-cvs mailing list
>> Bf-blender-cvs at blender.org
>> http://lists.blender.org/mailman/listinfo/bf-blender-cvs
>>
> _______________________________________________
> Bf-committers mailing list
> Bf-committers at blender.org
> http://lists.blender.org/mailman/listinfo/bf-committers
>



-- 
- Campbell


More information about the Bf-committers mailing list