OK. Here's the long awaited first step (V0.01!) of SoftBody. It is called
from within mesh_modifiers (kernel deform.c). It copies vertices to a temporal particle system (struct SoftBody with BodyPoint structs) to do physics tricks with it. For each frame change the delta movements (based on standard ipo anim or even other deforms (later) are applied to the physics system. How to apply and calculate satisfying results is not my thing... so here I'll commu- nicate with others for. Since it's in the modifier stack, the SoftBody code can run entirely on original data (no displists!). Right now I've implemented 2 things; - "Goal" which is a per vertex value for how much the current position should take into account (goal=1 is without physics). This is a powerful method for artists to get control over what moves and not. Right now i read the vertex color for it. - And some spring stuff, which now only works based on force moving it to the originial location. This doesnt work with 'goal'... erhm. - You can re-use physics vars from engine, used right now is (in Object) - damping - springf (spring factor) - softflag (to set types, or activate softbody for it - The SoftBody pointer in struct Object is only runtime, nothing saved in file To prevent all users going to complain it doesn't work, I've hidden the functionality. :) The buttons to set softbody 'on' only show now (psst psst) when the object has name "soft" as first 4 characters. You can find the buttons in the F7 Particle Interaction Panel (which should be renamed 'physics properties' later or so. Demo file: http://www.blender.org/bf/softbody.blend
This commit is contained in:
@@ -45,12 +45,16 @@
|
||||
#include "DNA_mesh_types.h"
|
||||
#include "DNA_meshdata_types.h"
|
||||
#include "DNA_object_types.h"
|
||||
#include "DNA_scene_types.h"
|
||||
|
||||
#include "BKE_curve.h"
|
||||
#include "BKE_deform.h"
|
||||
#include "BKE_displist.h"
|
||||
#include "BKE_effect.h"
|
||||
#include "BKE_global.h"
|
||||
#include "BKE_lattice.h"
|
||||
#include "BKE_object.h"
|
||||
#include "BKE_softbody.h"
|
||||
#include "BKE_utildefines.h"
|
||||
|
||||
#include "BLI_blenlib.h"
|
||||
@@ -214,6 +218,7 @@ int mesh_modifier(Object *ob, char mode)
|
||||
else if(ob->effect.first); // weak... particles too
|
||||
else if(ob->parent && ob->parent->type==OB_LATTICE);
|
||||
else if(ob->parent && ob->partype==PARSKEL);
|
||||
else if(ob->softflag);
|
||||
else return 0;
|
||||
|
||||
if(me->totvert==0) return 0;
|
||||
@@ -236,7 +241,13 @@ int mesh_modifier(Object *ob, char mode)
|
||||
|
||||
if(ob->effect.first) done |= object_wave(ob);
|
||||
|
||||
/* deform: input mesh, output ob dl_verts. is used by subsurf */
|
||||
if(ob->softflag) {
|
||||
float ctime= bsystem_time(ob, NULL, (float)G.scene->r.cfra, 0.0);
|
||||
done= 1;
|
||||
object_softbody_step(ob, ctime);
|
||||
}
|
||||
|
||||
/* deform: input mesh, output ob dl_verts. is used by subsurf (output should be in mesh ton!) */
|
||||
done |= object_deform(ob);
|
||||
|
||||
/* put deformed vertices in dl->verts, optional subsurf will replace that */
|
||||
|
||||
@@ -2372,6 +2372,7 @@ void test_all_displists(void)
|
||||
}
|
||||
}
|
||||
|
||||
if(ob->softflag) freedisplist_object(ob);
|
||||
/* warn, ob pointer changed in case of OB_MALL */
|
||||
|
||||
if ELEM(ob->type, OB_CURVE, OB_SURF) {
|
||||
|
||||
@@ -101,6 +101,7 @@
|
||||
#include "BKE_lattice.h"
|
||||
#include "BKE_constraint.h"
|
||||
#include "BKE_scene.h"
|
||||
#include "BKE_softbody.h"
|
||||
|
||||
#include "BPY_extern.h"
|
||||
|
||||
@@ -211,6 +212,7 @@ void free_object(Object *ob)
|
||||
BPY_free_scriptlink(&ob->scriptlink);
|
||||
|
||||
if(ob->pd) MEM_freeN(ob->pd);
|
||||
if(ob->soft) free_softbody(ob->soft);
|
||||
}
|
||||
|
||||
void unlink_object(Object *ob)
|
||||
@@ -770,6 +772,7 @@ Object *copy_object(Object *ob)
|
||||
|
||||
obn->disp.first= obn->disp.last= NULL;
|
||||
obn->hooks.first= obn->hooks.last= NULL;
|
||||
obn->soft= NULL;
|
||||
|
||||
return obn;
|
||||
}
|
||||
|
||||
@@ -2304,6 +2304,7 @@ static void direct_link_object(FileData *fd, Object *ob)
|
||||
}
|
||||
|
||||
ob->pd= newdataadr(fd, ob->pd);
|
||||
ob->soft= NULL;
|
||||
|
||||
link_list(fd, &ob->prop);
|
||||
prop= ob->prop.first;
|
||||
|
||||
@@ -51,6 +51,7 @@ struct BoundBox;
|
||||
struct Path;
|
||||
struct Material;
|
||||
struct bConstraintChannel;
|
||||
struct SoftBody;
|
||||
|
||||
typedef struct bDeformGroup {
|
||||
struct bDeformGroup *next, *prev;
|
||||
@@ -149,7 +150,7 @@ typedef struct Object {
|
||||
* For a Sphere, the form factor is by default = 0.4
|
||||
*/
|
||||
|
||||
float formfactor, dummy_1;
|
||||
float formfactor, springf; /* springf temp for softbody */
|
||||
float rdamping, sizefac;
|
||||
|
||||
char dt, dtx;
|
||||
@@ -185,7 +186,7 @@ typedef struct Object {
|
||||
* bit 15: Always ignore activity culling
|
||||
*/
|
||||
int gameflag2;
|
||||
int pad;
|
||||
short softflag, pad; /* temporal stuff softbody experiment */
|
||||
float anisotropicFriction[3];
|
||||
|
||||
ListBase constraints;
|
||||
@@ -193,6 +194,7 @@ typedef struct Object {
|
||||
ListBase hooks;
|
||||
|
||||
PartDeflect *pd; /* particle deflector/attractor/collision data */
|
||||
struct SoftBody *soft; /* only runtime, not saved in file! */
|
||||
struct Life *life;
|
||||
|
||||
LBuf lbuf;
|
||||
|
||||
@@ -1413,6 +1413,13 @@ static void object_panel_deflectors(Object *ob)
|
||||
uiDefButF(block, NUM, B_DIFF, "Rnd Damping: ", 10,10,200,20, &ob->pd->pdef_rdamp, 0.0, 1.0, 10, 0, "Random variation of damping");
|
||||
uiDefButF(block, NUM, B_DIFF, "Permeability: ", 10,-10,200,20, &ob->pd->pdef_perm, 0.0, 1.0, 10, 0, "Chance that the particle will pass through the mesh");
|
||||
}
|
||||
uiBlockEndAlign(block);
|
||||
}
|
||||
|
||||
if(strncmp(ob->id.name+2, "soft", 4)==0) {
|
||||
uiDefButS(block, TOG|BIT|0, B_DIFF, "Soft Body", 220,160,200,20, &ob->softflag, 0, 0, 0, 0, "Sets object to become soft body");
|
||||
uiDefButF(block, NUM, B_DIFF, "Spring: ", 220,140,200,20, &ob->springf, 0.0, 1.0, 10, 0, "Spring constant");
|
||||
uiDefButF(block, NUM, B_DIFF, "Damp: ", 220,120,200,20, &ob->damping, 0.0, 1.0, 10, 0, "General damping in softbody on point movements");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4105,6 +4105,7 @@ void draw_object(Base *base)
|
||||
if(ob->parent && ob->partype==PARSKEL) makeDispList(ob);
|
||||
else if(ob->hooks.first) makeDispList(ob);
|
||||
else if(ob->effect.first) makeDispList(ob);
|
||||
else if(ob->softflag) makeDispList(ob);
|
||||
else if(me->disp.first==NULL && mesh_uses_displist(me)) makeDispList(ob);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,6 +113,7 @@
|
||||
#include "BKE_property.h"
|
||||
#include "BKE_sca.h"
|
||||
#include "BKE_scene.h"
|
||||
#include "BKE_softbody.h"
|
||||
#include "BKE_subsurf.h"
|
||||
#include "BKE_texture.h"
|
||||
#include "BKE_utildefines.h"
|
||||
@@ -1547,6 +1548,8 @@ void exit_editmode(int freedata) /* freedata==0 at render, 1= freedata, 2= do un
|
||||
}
|
||||
scrarea_queue_headredraw(curarea);
|
||||
|
||||
if(ob->softflag) object_to_softbody(ob);
|
||||
|
||||
if(G.obedit==NULL && freedata==2)
|
||||
BIF_undo_push("Editmode");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user