Commit: 55cf7703fd71f79e3f9ae9e523e27ce33396f276
Author: Lukas Tönne
Date:   Mon Jul 14 14:23:50 2014 +0200
https://developer.blender.org/rB55cf7703fd71f79e3f9ae9e523e27ce33396f276

Merge branch 'master' into particles_refactor

Conflicts:
        source/blender/blenkernel/intern/object.c
        source/blender/blenkernel/intern/rigidbody.c
        source/blender/blenloader/intern/writefile.c
        source/blender/python/intern/bpy_interface.c
        source/creator/CMakeLists.txt

===================================================================



===================================================================

diff --cc source/blender/blenkernel/BKE_rigidbody.h
index 46a835c,c946f3a..05a6e48
--- a/source/blender/blenkernel/BKE_rigidbody.h
+++ b/source/blender/blenkernel/BKE_rigidbody.h
@@@ -60,11 -67,11 +60,14 @@@ struct RigidBodyWorld *BKE_rigidbody_wo
  void BKE_rigidbody_world_groups_relink(struct RigidBodyWorld *rbw);
  
  /* 'validate' (i.e. make new or replace old) Physics-Engine objects */
 +struct rbRigidBody *BKE_rigidbody_body_ensure_alloc(struct RigidBodyWorld 
*rbw, struct rbRigidBody *body, bool rebuild);
 +void BKE_rigidbody_body_tag_used(struct rbRigidBody *body);
 +void BKE_rigidbody_validate_sim_shape(Object *ob, bool rebuild);
  void BKE_rigidbody_validate_sim_world(struct Scene *scene, struct 
RigidBodyWorld *rbw, bool rebuild);
  
+ void BKE_rigidbody_calc_volume(struct Object *ob, float *r_vol);
+ void BKE_rigidbody_calc_center_of_mass(struct Object *ob, float r_com[3]);
+ 
  /* -------------- */
  /* Utilities */
  
diff --cc source/blender/blenkernel/intern/object.c
index 7585691,3490bb9..290a9e0
--- a/source/blender/blenkernel/intern/object.c
+++ b/source/blender/blenkernel/intern/object.c
@@@ -98,8 -95,6 +95,7 @@@
  #include "BKE_editmesh.h"
  #include "BKE_mball.h"
  #include "BKE_modifier.h"
- #include "BKE_node.h"
 +#include "BKE_nparticle.h"
  #include "BKE_object.h"
  #include "BKE_paint.h"
  #include "BKE_particle.h"
diff --cc source/blender/blenkernel/intern/rigidbody.c
index d159f49,2aaf8ad..2046fbd
--- a/source/blender/blenkernel/intern/rigidbody.c
+++ b/source/blender/blenkernel/intern/rigidbody.c
@@@ -47,11 -46,8 +47,9 @@@
  #  include "RBI_api.h"
  #endif
  
- #include "DNA_anim_types.h"
  #include "DNA_group_types.h"
- #include "DNA_mesh_types.h"
  #include "DNA_meshdata_types.h"
 +#include "DNA_nparticle_types.h"
  #include "DNA_object_types.h"
  #include "DNA_object_force.h"
  #include "DNA_rigidbody_types.h"
@@@ -60,11 -56,8 +58,9 @@@
  #include "BKE_cdderivedmesh.h"
  #include "BKE_effect.h"
  #include "BKE_global.h"
- #include "BKE_group.h"
  #include "BKE_library.h"
  #include "BKE_mesh.h"
 +#include "BKE_nparticle.h"
  #include "BKE_object.h"
  #include "BKE_pointcache.h"
  #include "BKE_rigidbody.h"
@@@ -425,124 -456,417 +420,300 @@@ void BKE_rigidbody_validate_sim_shape(O
  
  /* --------------------- */
  
+ /* helper function to calculate volume of rigidbody object */
+ // TODO: allow a parameter to specify method used to calculate this?
+ void BKE_rigidbody_calc_volume(Object *ob, float *r_vol)
+ {
+       RigidBodyOb *rbo = ob->rigidbody_object;
+ 
+       float size[3]  = {1.0f, 1.0f, 1.0f};
+       float radius = 1.0f;
+       float height = 1.0f;
+ 
+       float volume = 0.0f;
+ 
+       /* if automatically determining dimensions, use the Object's boundbox
+        *      - assume that all quadrics are standing upright on local z-axis
+        *      - assume even distribution of mass around the Object's pivot
+        *        (i.e. Object pivot is centralised in boundbox)
+        *      - boundbox gives full width
+        */
+       // XXX: all dimensions are auto-determined now... later can add stored 
settings for this
+       BKE_object_dimensions_get(ob, size);
+ 
+       if (ELEM3(rbo->shape, RB_SHAPE_CAPSULE, RB_SHAPE_CYLINDER, 
RB_SHAPE_CONE)) {
+               /* take radius as largest x/y dimension, and height as 
z-dimension */
+               radius = MAX2(size[0], size[1]) * 0.5f;
+               height = size[2];
+       }
+       else if (rbo->shape == RB_SHAPE_SPHERE) {
+               /* take radius to the the largest dimension to try and 
encompass everything */
+               radius = max_fff(size[0], size[1], size[2]) * 0.5f;
+       }
+ 
+       /* calculate volume as appropriate  */
+       switch (rbo->shape) {
+               case RB_SHAPE_BOX:
+                       volume = size[0] * size[1] * size[2];
+                       break;
+ 
+               case RB_SHAPE_SPHERE:
+                       volume = 4.0f / 3.0f * (float)M_PI * radius * radius * 
radius;
+                       break;
+ 
+               /* for now, assume that capsule is close enough to a 
cylinder... */
+               case RB_SHAPE_CAPSULE:
+               case RB_SHAPE_CYLINDER:
+                       volume = (float)M_PI * radius * radius * height;
+                       break;
+ 
+               case RB_SHAPE_CONE:
+                       volume = (float)M_PI / 3.0f * radius * radius * height;
+                       break;
+ 
+               case RB_SHAPE_CONVEXH:
+               case RB_SHAPE_TRIMESH:
+               {
+                       if (ob->type == OB_MESH) {
+                               DerivedMesh *dm = rigidbody_get_mesh(ob);
+                               MVert *mvert;
+                               MFace *mface;
+                               int totvert, totface;
+                               
+                               /* ensure mesh validity, then grab data */
+                               if (dm == NULL)
+                                       return;
+                       
+                               DM_ensure_tessface(dm);
+                       
+                               mvert   = (dm) ? dm->getVertArray(dm) : NULL;
+                               totvert = (dm) ? dm->getNumVerts(dm) : 0;
+                               mface   = (dm) ? dm->getTessFaceArray(dm) : 
NULL;
+                               totface = (dm) ? dm->getNumTessFaces(dm) : 0;
+                               
+                               if (totvert > 0 && totface > 0) {
+                                       BKE_mesh_calc_volume(mvert, totvert, 
mface, totface, &volume, NULL);
+                               }
+                               
+                               /* cleanup temp data */
+                               if (dm && ob->rigidbody_object->mesh_source == 
RBO_MESH_BASE) {
+                                       dm->release(dm);
+                               }
+                       }
+                       else {
+                               /* rough estimate from boundbox as fallback */
+                               /* XXX could implement other types of geometry 
here (curves, etc.) */
+                               volume = size[0] * size[1] * size[2];
+                       }
+                       break;
+               }
+ 
+ #if 0 // XXX: not defined yet
+               case RB_SHAPE_COMPOUND:
+                       volume = 0.0f;
+                       break;
+ #endif
+       }
+ 
+       /* return the volume calculated */
+       if (r_vol) *r_vol = volume;
+ }
+ 
+ void BKE_rigidbody_calc_center_of_mass(Object *ob, float r_com[3])
+ {
+       RigidBodyOb *rbo = ob->rigidbody_object;
+ 
+       float size[3]  = {1.0f, 1.0f, 1.0f};
+       float height = 1.0f;
+ 
+       zero_v3(r_com);
+ 
+       /* if automatically determining dimensions, use the Object's boundbox
+        *      - assume that all quadrics are standing upright on local z-axis
+        *      - assume even distribution of mass around the Object's pivot
+        *        (i.e. Object pivot is centralised in boundbox)
+        *      - boundbox gives full width
+        */
+       // XXX: all dimensions are auto-determined now... later can add stored 
settings for this
+       BKE_object_dimensions_get(ob, size);
+ 
+       /* calculate volume as appropriate  */
+       switch (rbo->shape) {
+               case RB_SHAPE_BOX:
+               case RB_SHAPE_SPHERE:
+               case RB_SHAPE_CAPSULE:
+               case RB_SHAPE_CYLINDER:
+                       break;
+ 
+               case RB_SHAPE_CONE:
+                       /* take radius as largest x/y dimension, and height as 
z-dimension */
+                       height = size[2];
+                       /* cone is geometrically centered on the median,
+                        * center of mass is 1/4 up from the base
+                        */
+                       r_com[2] = -0.25f * height;
+                       break;
+ 
+               case RB_SHAPE_CONVEXH:
+               case RB_SHAPE_TRIMESH:
+               {
+                       if (ob->type == OB_MESH) {
+                               DerivedMesh *dm = rigidbody_get_mesh(ob);
+                               MVert *mvert;
+                               MFace *mface;
+                               int totvert, totface;
+                               
+                               /* ensure mesh validity, then grab data */
+                               if (dm == NULL)
+                                       return;
+                       
+                               DM_ensure_tessface(dm);
+                       
+                               mvert   = (dm) ? dm->getVertArray(dm) : NULL;
+                               totvert = (dm) ? dm->getNumVerts(dm) : 0;
+                               mface   = (dm) ? dm->getTessFaceArray(dm) : 
NULL;
+                               totface = (dm) ? dm->getNumTessFaces(dm) : 0;
+                               
+                               if (totvert > 0 && totface > 0) {
+                                       BKE_mesh_calc_volume(mvert, totvert, 
mface, totface, NULL, r_com);
+                               }
+                               
+                               /* cleanup temp data */
+                               if (dm && ob->rigidbody_object->mesh_source == 
RBO_MESH_BASE) {
+                                       dm->release(dm);
+                               }
+                       }
+                       break;
+               }
+ 
+ #if 0 // XXX: not defined yet
+               case RB_SHAPE_COMPOUND:
+                       volume = 0.0f;
+                       break;
+ #endif
+       }
+ }
+ 
+ /* --------------------- */
+ 
 -/**
 - * Create physics sim representation of object given RigidBody settings
 - *
 - * \param rebuild Even if an instance already exists, replace it
 - */
 -static void rigidbody_validate_sim_object(RigidBodyWorld *rbw, Object *ob, 
bool rebuild)
 +static rbRigidBody *rigidbody_validate_particle(RigidBodyWorld *rbw, Object 
*UNUSED(ob),
 +                                                NParticleDisplayDupliObject 
*dupli, int totdupli,
 +                                                NParticleIterator *iter, bool 
rebuild)
  {
 -      RigidBodyOb *rbo = (ob) ? ob->rigidbody_object : NULL;
 +      int dupli_index;
 +      NParticleDisplayDupliObject *dob;
        float loc[3];
        float rot[4];
 -
 -      /* sanity checks:
 -       *      - object doesn't have RigidBody info already: then why is it 
here?
 -       */
 -      if (rbo == NULL)
 -              return;
 -
 +      rbRigidBody *body;
 +      rbCollisionShape *shape = NULL;
 +      
 +      dupli_index = BKE_nparticle_iter_get_int(iter, "dupli");
 +      if (dupli_index < 0 || dupli_index >= totdupli)
 +              return NULL;
 +      dob = &dupli[dupli_index];
 +      if (!dob->object || !dob->object->rigidbody_object)
 +              return NULL;
 +      
        /* make sure collision shape exists */
        /* FIXME we shouldn't always have to rebuild collision shapes when 
rebuilding objects, but it's needed for constraints to update correctly */
 -      if (rbo->physics_shape == NULL || rebuild)
 -              rigidbody_validate_sim_shape(ob, true);
 -
 -      if (rbo->physics_object && rebuild == false) {
 -              RB_dworld_remove_body(rbw->physics_world, rbo->physics_object);
 -      }
 -      if (!rbo->physics_object || rebuild) {
 -              /* remove rigid body if it already exists before creating a new 
one */
 -              if (rbo->physics_object) {
 -                      RB_body_delete(rbo->physics_object);
 +      if (dob->object->rigidbody_object->physics_shape == NULL || rebuild)
 +              BKE_rigidbody_validate_sim_shape(dob->object, true);
 +      shape = dob->object->rigidbody_object->physics_shape;
 +      
 +      BKE_nparticle_iter_get_vector(iter, "position", loc);
 +      BKE_nparticle_iter_get_quaternion(iter, "rotation", rot);
 +      
 +      body = BKE_nparticle_iter_get_pointer(iter, "rigid_body");
 +      if (!body || rebuild) {
 +              if (body) {
 +                      /* free the existing rigid body, memory reused below */
 +                      RB_body_free(body);
                }
 +              else {
 +                      /* only allocate if no rigid body exists yet,
 +                       * otherwise previous memory is reused
 +                       */
 +                      body = BLI_mempool_alloc(rbw->body_pool);
 +              }
 +      }
 +      else
 +              RB_dworld_remove_body(rbw->physics_world, body);
 +      
 +      RB_body_init(body, shape, loc, rot);
 +      BKE_nparticle_iter_set_pointer(iter, "rigid_body", body);
 +      
 +      RB_body_set_friction(body, 0.5f);
 +      RB_body_set_restitution(body, 0.0f);
  
 -              mat4_to_loc_quat(loc, rot, ob->obmat);
 -
 -              rbo->physics_object = RB_body_new(rbo->physics_shape, loc, rot);
 -
 -              RB_body_set_friction(rbo->physics_object, rbo->friction);
 -              RB_body_set_restitut

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to