Commit: c519abe4665587aa3b7503e99a8a55380ab7a2fb
Author: Martin Felke
Date:   Fri Nov 14 16:49:34 2014 +0100
Branches: fracture_modifier
https://developer.blender.org/rBc519abe4665587aa3b7503e99a8a55380ab7a2fb

tweaks for convert to keyframe objects and fix normals

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

M       release/scripts/startup/bl_operators/rigidbody.py
M       source/blender/blenloader/intern/readfile.c
M       source/blender/editors/object/object_modifier.c
M       source/blender/modifiers/intern/MOD_fracture.c

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

diff --git a/release/scripts/startup/bl_operators/rigidbody.py 
b/release/scripts/startup/bl_operators/rigidbody.py
index 40c1924..e9b2d0d 100644
--- a/release/scripts/startup/bl_operators/rigidbody.py
+++ b/release/scripts/startup/bl_operators/rigidbody.py
@@ -114,10 +114,11 @@ class BakeToKeyframes(Operator):
         obj = context.object
         return (obj and obj.rigid_body)
 
-    def has_fracture_modifier(self, ob):
+    def has_fracture_modifier(self, ob, report=False):
         for m in ob.modifiers:
             if m.type == 'FRACTURE':
-               self.report({'WARNING'}, "Object '%s' has a fracture modifier, 
use 'Convert to Objects' before 'Bake to Keyframes'" % ob.name)
+               if (report == True):
+                   self.report({'WARNING'}, "Object '%s' has a fracture 
modifier, use 'Convert to Objects' before 'Bake to Keyframes'" % ob.name)
                return True
         return False
 
@@ -132,7 +133,7 @@ class BakeToKeyframes(Operator):
         constraints = []
         # filter objects selection
         for obj in context.selected_objects:
-            if (not obj.rigid_body or obj.rigid_body.type != 'ACTIVE' or 
self.has_fracture_modifier(obj)):
+            if (not obj.rigid_body or obj.rigid_body.type != 'ACTIVE' or 
self.has_fracture_modifier(obj, True)):
                 obj.select = False
             if (obj.rigid_body_constraint):
                constraints.append(obj)
@@ -181,18 +182,29 @@ class BakeToKeyframes(Operator):
 
                 bpy.ops.anim.keyframe_insert(type='BUILTIN_KSI_LocRot', 
confirm_success=False)
 
-            #remove (selected) constraints first
-            for obj in constraints:
-                obj.select = True
-
-            bpy.ops.rigidbody.constraints_remove()
-
-            for obj in constraints:
-                obj.select = False
-                obj.hide = True
-            
-            # remove baked objects from simulation
-            bpy.ops.rigidbody.objects_remove()
+            # remove baked objects from simulation, only if no Fracture 
Modifier is detected (messes up bake possibly)!
+            hasFracture = False
+            for obj in bpy.data.objects:
+                 if (self.has_fracture_modifier(obj)):
+                     hasFracture = True
+                     break
+
+            if (hasFracture == False):
+                #remove (selected) constraints first
+                for obj in constraints:
+                    obj.select = True
+
+                bpy.ops.rigidbody.constraints_remove()
+
+                for obj in constraints:
+                    obj.select = False
+                    obj.hide = True
+
+                bpy.ops.rigidbody.objects_remove()
+            else:
+                 # set to kinematic only
+                 for obj in objects:
+                    obj.rigid_body.kinematic = True
 
             # clean up keyframes
             for obj in objects:
diff --git a/source/blender/blenloader/intern/readfile.c 
b/source/blender/blenloader/intern/readfile.c
index cdc5ee1..db006f7 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -5048,25 +5048,27 @@ static void direct_link_modifiers(FileData *fd, 
ListBase *lb)
                                mverts = 
CDDM_get_verts(fmd->visible_mesh_cached);
 
                                for (mi = fmd->meshIslands.first; mi; mi = 
mi->next) {
+                                       MVert *mv;
                                        int k = 0;
                                        read_meshIsland(fd, &mi);
                                        mi->vertices_cached = 
MEM_mallocN(sizeof(MVert*) * mi->vertex_count, "mi->vertices_cached readfile");
+                                       mv = 
mi->physics_mesh->getVertArray(mi->physics_mesh);
 
                                        for (k = 0; k < mi->vertex_count; k++) {
                                                MVert* v = mverts + vertstart + 
k ;
+                                               MVert* v2 = mv + k;
                                                mi->vertices_cached[k] = v;
                                                mi->vertco[k*3] = v->co[0];
                                                mi->vertco[k*3+1] = v->co[1];
                                                mi->vertco[k*3+2] = v->co[2];
 
                                                if (mi->vertno != NULL && 
fmd->fix_normals) {
-                                                       float no[3];
                                                        short sno[3];
-                                                       no[0] = mi->vertno[k*3];
-                                                       no[1] = 
mi->vertno[k*3+1];
-                                                       no[2] = 
mi->vertno[k*3+2];
-                                                       
normal_float_to_short_v3(sno, no);
-                                                       
copy_v3_v3_short(mi->vertices_cached[k]->no, sno);
+                                                       sno[0] = 
mi->vertno[k*3];
+                                                       sno[1] = 
mi->vertno[k*3+1];
+                                                       sno[2] = 
mi->vertno[k*3+2];
+                                                       copy_v3_v3_short(v->no, 
sno);
+                                                       
copy_v3_v3_short(v2->no, sno);
                                                }
                                        }
                                        vertstart += mi->vertex_count;
diff --git a/source/blender/editors/object/object_modifier.c 
b/source/blender/editors/object/object_modifier.c
index 6500a94..66a810d 100644
--- a/source/blender/editors/object/object_modifier.c
+++ b/source/blender/editors/object/object_modifier.c
@@ -2682,9 +2682,9 @@ void 
OBJECT_OT_rigidbody_convert_to_objects(wmOperatorType *ot)
 
 static bool convert_modifier_to_keyframes(FractureModifierData* fmd, Group* 
gr, Object* ob, Scene* scene, int start, int end)
 {
-       bool is_baked = false;
+//     bool is_baked = false;
        PointCache* cache = NULL;
-       PTCacheID pid;
+//     PTCacheID pid;
        MeshIsland *mi = NULL;
        int j = 0;
        Object *parent = NULL;
@@ -2699,6 +2699,7 @@ static bool 
convert_modifier_to_keyframes(FractureModifierData* fmd, Group* gr,
                cache = scene->rigidbody_world->pointcache;
        }
 
+#if 0
        if (cache && cache->flag & PTCACHE_BAKED)
        {
                start = cache->startframe;
@@ -2706,6 +2707,7 @@ static bool 
convert_modifier_to_keyframes(FractureModifierData* fmd, Group* gr,
                BKE_ptcache_id_from_rigidbody(&pid, NULL, 
scene->rigidbody_world);
                is_baked = true;
        }
+#endif
 
        if (cache && (cache->flag & PTCACHE_OUTDATED) /* && !(cache->flag & 
PTCACHE_BAKED)*/)
        {
@@ -2754,14 +2756,13 @@ static bool 
convert_modifier_to_keyframes(FractureModifierData* fmd, Group* gr,
 
                ED_rigidbody_object_add(scene, ob_new, RBO_TYPE_ACTIVE, NULL);
                ob_new->rigidbody_object->flag |= RBO_FLAG_KINEMATIC;
+               ob_new->rigidbody_object->mass = mi->rigidbody->mass;
 
                /*set origin to centroid*/
                copy_v3_v3(cent, mi->centroid);
                mul_m4_v3(ob_new->obmat, cent);
                copy_v3_v3(ob_new->loc, cent);
 
-
-
                if (start < mi->start_frame) {
                        start = mi->start_frame;
                }
@@ -2770,49 +2771,52 @@ static bool 
convert_modifier_to_keyframes(FractureModifierData* fmd, Group* gr,
                        end = mi->start_frame + mi->frame_count;
                }
 
-               for (i = start+1; i < end-1; i++)
+               for (i = start; i < end; i++)
                {
                        /*move object (loc, rot)*/
-
-                       float loc[3] = {0.0f, 0.0f, 0.0f}, rot[4] = {0.0f, 
0.0f, 0.0f, 0.0f};
-                       float mat[4][4];
-                       float size[3] = {1.0f, 1.0f, 1.0f};
-
-                       //is there a bake, if yes... use that
-                       if (is_baked)
+                       if (i > start)
                        {
-                               BKE_ptcache_id_time(&pid, scene, (float)i, 
NULL, NULL, NULL);
-                               if (BKE_ptcache_read(&pid, (float)i))
+                               float loc[3] = {0.0f, 0.0f, 0.0f}, rot[4] = 
{0.0f, 0.0f, 0.0f, 0.0f};
+                               float mat[4][4];
+                               float size[3] = {1.0f, 1.0f, 1.0f};
+
+                               //is there a bake, if yes... use that (disabled 
for now, odd probs...)
+#if 0
+                               if (is_baked)
                                {
-                                       BKE_ptcache_validate(cache, i);
-                                       copy_v3_v3(loc, mi->rigidbody->pos);
-                                       copy_qt_qt(rot, mi->rigidbody->orn);
+                                       BKE_ptcache_id_time(&pid, scene, 
(float)i, NULL, NULL, NULL);
+                                       if (BKE_ptcache_read(&pid, (float)i))
+                                       {
+                                               BKE_ptcache_validate(cache, i);
+                                               copy_v3_v3(loc, 
mi->rigidbody->pos);
+                                               copy_qt_qt(rot, 
mi->rigidbody->orn);
+                                       }
+                               }
+                               else
+#endif
+                               {
+                                       loc[0] = mi->locs[i*3];
+                                       loc[1] = mi->locs[i*3+1];
+                                       loc[2] = mi->locs[i*3+2];
+
+                                       rot[0] = mi->rots[i*4];
+                                       rot[1] = mi->rots[i*4+1];
+                                       rot[2] = mi->rots[i*4+2];
+                                       rot[3] = mi->rots[i*4+3];
                                }
-                       }
-                       else
-                       {
-                               loc[0] = mi->locs[i*3];
-                               loc[1] = mi->locs[i*3+1];
-                               loc[2] = mi->locs[i*3+2];
-
-                               rot[0] = mi->rots[i*4];
-                               rot[1] = mi->rots[i*4+1];
-                               rot[2] = mi->rots[i*4+2];
-                               rot[3] = mi->rots[i*4+3];
-                       }
-
-                       sub_v3_v3(loc, obloc);
-                       add_v3_v3(loc, diff);
 
-                       loc_quat_size_to_mat4(mat, loc, rot, size);
+                               sub_v3_v3(loc, obloc);
+                               add_v3_v3(loc, diff);
 
-                       BKE_scene_frame_set(scene, (double)i);
+                               loc_quat_size_to_mat4(mat, loc, rot, size);
+                               BKE_scene_frame_set(scene, (double)i);
 
-                       copy_m4_m4(ob_new->obmat, mat);
+                               copy_m4_m4(ob_new->obmat, mat);
 
-                       copy_v3_v3(ob_new->loc, loc);
-                       copy_qt_qt(ob_new->quat, rot);
-                       quat_to_eul(ob_new->rot, rot);
+                               copy_v3_v3(ob_new->loc, loc);
+                               copy_qt_qt(ob_new->quat, rot);
+                               quat_to_eul(ob_new->rot, rot);
+                       }
 
                        insert_keyframe(NULL, (ID*)ob_new, NULL, "Location", 
"location", 0, i, 32);
                        insert_keyframe(NULL, (ID*)ob_new, NULL, "Location", 
"location", 1, i, 32);
@@ -2821,6 +2825,10 @@ static bool 
convert_modifier_to_keyframes(FractureModifierData* fmd, Group* gr,
                        insert_keyframe(NULL, (ID*)ob_new, NULL, "Rotation", 
"rotation_euler", 0, i, 32);
                        insert_keyframe(NULL, (ID*)ob_new, NULL, "Rotation", 
"rotation_euler", 1, i, 32);
                        insert_keyframe(NULL, (ID*)ob_new, NULL, "Rotation", 
"rotation_euler", 2, i, 32);
+
+                       insert_keyframe(NULL, (ID*)ob_new, NULL, "Scale", 
"scale", 0, i, 32);
+                       insert_keyframe(NULL, (ID*)ob_new, NULL, "Scale", 
"scale", 1, i, 32);
+                       insert_keyframe(NULL, (ID*)ob_new, NULL, "Scale", 
"scale", 2, i, 32);
                }
 
                j++;
@@ -2950,11 +2958,12 @@ static int rigidbody_convert_keyframes_exec(bContext 
*C, wmOperator *op)
                                DAG_relations_tag_update(G.main);
                                WM_event_add_notifier(C, NC_OBJECT | 
ND_TRANSFORM, NULL);
                                WM_event_add_notifier(C, NC_OBJECT | ND_PARENT, 
NULL);
+                               WM_event_add_notifier(C, NC_SCENE | ND_FRAME, 
NULL);
                                return OPERATOR_FINISHED;
                        }
                        else
                        {
-                               BKE_report(op->reports, RPT_WARNING, "No valid 
cache data found, please run or bake simulation first");
+                               BKE_report(op->reports, RPT_WARNING, "No valid 
cache data found, please run simulation first (baked ones too !)");
                                return OPERATOR_CANCELLED;
                        }
                }
diff --git a/source/blender/modifiers/intern/MOD_fracture.c 
b/source/blender/modifiers/intern/MOD_fracture.c
index 77164f3..3edd8cf 100644
--- a/source/blender/modifiers/intern/MOD_fracture.c
+++ b/source/blender/modifiers/intern/MOD_fracture.c
@@ -460,7 +460,6 @@ static void find_normal(DerivedMesh *dm, KDTree *tree, 
float co[3], short no[3],
                normal_short_to_float_v3(vno, mvert.no);
                if ((dot_v3v3(fno, vno) > 0.0f)

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to