~siretart/ubuntu/utopic/blender/libav10

« back to all changes in this revision

Viewing changes to source/blender/blenkernel/intern/softbody.c

  • Committer: Package Import Robot
  • Author(s): Kevin Roy
  • Date: 2011-10-21 14:21:47 UTC
  • mfrom: (14.2.10 sid)
  • Revision ID: package-import@ubuntu.com-20111021142147-2yjgibwwnmqibacp
Tags: 2.59-1
* New Upstream Release 2.59 (Closes: #641085)
* debian/control: libglew dependency changed
  - changed Depends libglew1.5-dev to libglew1.6-dev
   due to transition. (Closes: #636177)
* update manpages
* change depends yafray to new yafaray packages 
      (Thanks to Matteo F. Vescovi)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*  softbody.c
2
2
 *
3
 
 * $Id: softbody.c 36821 2011-05-22 16:29:51Z campbellbarton $
 
3
 * $Id: softbody.c 38235 2011-07-08 13:22:58Z blendix $
4
4
 *
5
5
 * ***** BEGIN GPL LICENSE BLOCK *****
6
6
 *
75
75
#include "BKE_curve.h"
76
76
#include "BKE_effect.h"
77
77
#include "BKE_global.h"
 
78
#include "BKE_modifier.h"
78
79
#include "BKE_softbody.h"
79
80
#include "BKE_DerivedMesh.h"
80
81
#include "BKE_pointcache.h"
289
290
 
290
291
 
291
292
 
292
 
static ccd_Mesh *ccd_mesh_make(Object *ob, DerivedMesh *dm)
 
293
static ccd_Mesh *ccd_mesh_make(Object *ob)
293
294
{
 
295
        CollisionModifierData *cmd;
294
296
        ccd_Mesh *pccd_M = NULL;
295
297
        ccdf_minmax *mima =NULL;
296
298
        MFace *mface=NULL;
297
299
        float v[3],hull;
298
300
        int i;
299
301
 
 
302
        cmd =(CollisionModifierData *)modifiers_findByType(ob, eModifierType_Collision);
 
303
 
300
304
        /* first some paranoia checks */
301
 
        if (!dm) return NULL;
302
 
        if (!dm->getNumVerts(dm) || !dm->getNumFaces(dm)) return NULL;
 
305
        if (!cmd) return NULL;
 
306
        if (!cmd->numverts || !cmd->numfaces) return NULL;
303
307
 
304
308
        pccd_M = MEM_mallocN(sizeof(ccd_Mesh),"ccd_Mesh");
305
 
        pccd_M->totvert = dm->getNumVerts(dm);
306
 
        pccd_M->totface = dm->getNumFaces(dm);
 
309
        pccd_M->totvert = cmd->numverts;
 
310
        pccd_M->totface = cmd->numfaces;
307
311
        pccd_M->savety  = CCD_SAVETY;
308
312
        pccd_M->bbmin[0]=pccd_M->bbmin[1]=pccd_M->bbmin[2]=1e30f;
309
313
        pccd_M->bbmax[0]=pccd_M->bbmax[1]=pccd_M->bbmax[2]=-1e30f;
314
318
        hull = MAX2(ob->pd->pdef_sbift,ob->pd->pdef_sboft);
315
319
 
316
320
        /* alloc and copy verts*/
317
 
        pccd_M->mvert = dm->dupVertArray(dm);
318
 
        /* ah yeah, put the verices to global coords once */
319
 
        /* and determine the ortho BB on the fly */
 
321
        pccd_M->mvert = MEM_dupallocN(cmd->xnew);
 
322
        /* note that xnew coords are already in global space, */
 
323
        /* determine the ortho BB */
320
324
        for(i=0; i < pccd_M->totvert; i++){
321
 
                mul_m4_v3(ob->obmat, pccd_M->mvert[i].co);
322
 
 
323
325
                /* evaluate limits */
324
326
                VECCOPY(v,pccd_M->mvert[i].co);
325
327
                pccd_M->bbmin[0] = MIN2(pccd_M->bbmin[0],v[0]-hull);
332
334
 
333
335
        }
334
336
        /* alloc and copy faces*/
335
 
        pccd_M->mface = dm->dupFaceArray(dm);
 
337
        pccd_M->mface = MEM_dupallocN(cmd->mfaces);
336
338
 
337
339
        /* OBBs for idea1 */
338
340
        pccd_M->mima = MEM_mallocN(sizeof(ccdf_minmax)*pccd_M->totface,"ccd_Mesh_Faces_mima");
386
388
        }
387
389
        return pccd_M;
388
390
}
389
 
static void ccd_mesh_update(Object *ob,ccd_Mesh *pccd_M, DerivedMesh *dm)
 
391
static void ccd_mesh_update(Object *ob,ccd_Mesh *pccd_M)
390
392
{
391
 
         ccdf_minmax *mima =NULL;
 
393
        CollisionModifierData *cmd;
 
394
        ccdf_minmax *mima =NULL;
392
395
        MFace *mface=NULL;
393
396
        float v[3],hull;
394
397
        int i;
395
398
 
 
399
        cmd =(CollisionModifierData *)modifiers_findByType(ob, eModifierType_Collision);
 
400
 
396
401
        /* first some paranoia checks */
397
 
        if (!dm) return ;
398
 
        if (!dm->getNumVerts(dm) || !dm->getNumFaces(dm)) return ;
 
402
        if (!cmd) return ;
 
403
        if (!cmd->numverts || !cmd->numfaces) return ;
399
404
 
400
 
        if ((pccd_M->totvert != dm->getNumVerts(dm)) ||
401
 
                (pccd_M->totface != dm->getNumFaces(dm))) return;
 
405
        if ((pccd_M->totvert != cmd->numverts) ||
 
406
                (pccd_M->totface != cmd->numfaces)) return;
402
407
 
403
408
        pccd_M->bbmin[0]=pccd_M->bbmin[1]=pccd_M->bbmin[2]=1e30f;
404
409
        pccd_M->bbmax[0]=pccd_M->bbmax[1]=pccd_M->bbmax[2]=-1e30f;
411
416
        if(pccd_M->mprevvert) MEM_freeN(pccd_M->mprevvert);
412
417
        pccd_M->mprevvert = pccd_M->mvert;
413
418
        /* alloc and copy verts*/
414
 
        pccd_M->mvert = dm->dupVertArray(dm);
415
 
        /* ah yeah, put the verices to global coords once */
416
 
        /* and determine the ortho BB on the fly */
 
419
        pccd_M->mvert = MEM_dupallocN(cmd->xnew);
 
420
        /* note that xnew coords are already in global space, */
 
421
        /* determine the ortho BB */
417
422
        for(i=0; i < pccd_M->totvert; i++){
418
 
                mul_m4_v3(ob->obmat, pccd_M->mvert[i].co);
419
 
 
420
423
                /* evaluate limits */
421
424
                VECCOPY(v,pccd_M->mvert[i].co);
422
425
                pccd_M->bbmin[0] = MIN2(pccd_M->bbmin[0],v[0]-hull);
555
558
 
556
559
                        /*+++ only with deflecting set */
557
560
                        if(ob->pd && ob->pd->deflect && BLI_ghash_lookup(hash, ob) == NULL) {
558
 
                                DerivedMesh *dm= NULL;
559
 
 
560
 
                                if(ob->softflag & OB_SB_COLLFINAL) /* so maybe someone wants overkill to collide with subsurfed */
561
 
                                        dm = mesh_get_derived_final(scene, ob, CD_MASK_BAREMESH);
562
 
                                else
563
 
                                        dm = mesh_get_derived_deform(scene, ob, CD_MASK_BAREMESH);
564
 
 
565
 
                                if(dm){
566
 
                                        ccd_Mesh *ccdmesh = ccd_mesh_make(ob, dm);
567
 
                                        BLI_ghash_insert(hash, ob, ccdmesh);
568
 
 
569
 
                                        /* we did copy & modify all we need so give 'em away again */
570
 
                                        dm->release(dm);
571
 
 
572
 
                                }
 
561
                                ccd_Mesh *ccdmesh = ccd_mesh_make(ob);
 
562
                                BLI_ghash_insert(hash, ob, ccdmesh);
573
563
                        }/*--- only with deflecting set */
574
564
 
575
565
                }/* mesh && layer*/
595
585
 
596
586
                        /*+++ only with deflecting set */
597
587
                        if(ob->pd && ob->pd->deflect) {
598
 
                                DerivedMesh *dm= NULL;
599
 
 
600
 
                                if(ob->softflag & OB_SB_COLLFINAL) { /* so maybe someone wants overkill to collide with subsurfed */
601
 
                                        dm = mesh_get_derived_final(scene, ob, CD_MASK_BAREMESH);
602
 
                                } else {
603
 
                                        dm = mesh_get_derived_deform(scene, ob, CD_MASK_BAREMESH);
604
 
                                }
605
 
                                if(dm){
606
 
                                        ccd_Mesh *ccdmesh = BLI_ghash_lookup(hash,ob);
607
 
                                        if (ccdmesh)
608
 
                                                ccd_mesh_update(ob,ccdmesh,dm);
609
 
 
610
 
                                        /* we did copy & modify all we need so give 'em away again */
611
 
                                        dm->release(dm);
612
 
                                }
 
588
                                ccd_Mesh *ccdmesh = BLI_ghash_lookup(hash,ob);
 
589
                                if (ccdmesh)
 
590
                                        ccd_mesh_update(ob,ccdmesh);
613
591
                        }/*--- only with deflecting set */
614
592
 
615
593
                }/* mesh && layer*/