Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTon Roosendaal <ton@blender.org>2005-11-17 14:40:57 +0300
committerTon Roosendaal <ton@blender.org>2005-11-17 14:40:57 +0300
commitec477f7a638b4d048c288e347ae6b467f4675576 (patch)
treeb21009c0fedee765b9b39831b13bacde66ba5030 /source/blender/blenkernel
parent96221a5331bc8652083ff4c1bc1c7086a4b71a5f (diff)
Another Orange sneak-in feature: SoftBody support for Curves & Surfaces.
Well, it already worked a bit, but without weight options or edge stiffness. You now can set the weights using the "Properties" Panel in the 3D Window (allows multiple selections too) or with Wkey in Edit Mode. Bezier curves have this too. NOTE: Lattice SoftBody Goal created yesterday won't work anymore! I've had to recode weight support for Nurbs Points, using a new weight variable... this because the existing W variable was in use for Nurbs already. Also Lattices have this new Weight variable, so the code is nice uniform. Sorry for the artists who already created complex Lattices... :) NOTE2: Surface Objects don't support edge stiffness yet NOTE3: I've removed ancient screen coordinates from the Bezier struct, which makes - even with added weight and padding - the struct smaller! Demo file: http://download.blender.org/demo/test/2.40/softbody_curve_lattice.blend
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r--source/blender/blenkernel/intern/displist.c3
-rw-r--r--source/blender/blenkernel/intern/softbody.c101
2 files changed, 95 insertions, 9 deletions
diff --git a/source/blender/blenkernel/intern/displist.c b/source/blender/blenkernel/intern/displist.c
index f668aa507b4..34500bfeea9 100644
--- a/source/blender/blenkernel/intern/displist.c
+++ b/source/blender/blenkernel/intern/displist.c
@@ -1429,7 +1429,7 @@ static ModifierData *curve_get_tesselate_point(Object *ob, int forRender, int ed
if (editmode && !(md->mode&eModifierMode_Editmode)) continue;
if (mti->isDisabled && mti->isDisabled(md)) continue;
- if (md->type==eModifierType_Hook) {
+ if (md->type==eModifierType_Hook || md->type==eModifierType_Softbody) {
preTesselatePoint = md;
}
}
@@ -1464,6 +1464,7 @@ void curve_calc_modifiers_pre(Object *ob, ListBase *nurb, int forRender, float (
deformedVerts = curve_getVertexCos(ob->data, nurb, &numVerts);
originalVerts = MEM_dupallocN(deformedVerts);
}
+
mti->deformVerts(md, ob, NULL, deformedVerts, numVerts);
if (md==preTesselatePoint)
diff --git a/source/blender/blenkernel/intern/softbody.c b/source/blender/blenkernel/intern/softbody.c
index 7f3dda44255..11bacfd8683 100644
--- a/source/blender/blenkernel/intern/softbody.c
+++ b/source/blender/blenkernel/intern/softbody.c
@@ -70,6 +70,7 @@ variables on the UI for now
#include "BLI_blenlib.h"
#include "BLI_arithb.h"
+#include "BKE_curve.h"
#include "BKE_displist.h"
#include "BKE_effect.h"
#include "BKE_global.h"
@@ -1043,7 +1044,7 @@ static void makelatticesprings(Lattice *lt, BodySpring *bs, int dostiff)
static void lattice_to_softbody(Object *ob,int *rcs)
{
Lattice *lt= ob->data;
- SoftBody *sb= ob->soft;
+ SoftBody *sb;
int totvert, totspring = 0;
totvert= lt->pntsu*lt->pntsv*lt->pntsw;
@@ -1059,7 +1060,8 @@ static void lattice_to_softbody(Object *ob,int *rcs)
/* renew ends with ob->soft with points and edges, also checks & makes ob->soft */
- renew_softbody(ob, totvert, totspring,rcs);
+ renew_softbody(ob, totvert, totspring, rcs);
+ sb= ob->soft; /* can be created in renew_softbody() */
/* weights from bpoints, same code used as for mesh vertices */
if((ob->softflag & OB_SB_GOAL) && sb->vertgroup) {
@@ -1069,9 +1071,7 @@ static void lattice_to_softbody(Object *ob,int *rcs)
int a;
for(a=0; a<totvert; a++, bp++, bpnt++) {
-
- bp->goal= sb->mingoal + bpnt->vec[3]*goalfac;
-
+ bp->goal= sb->mingoal + bpnt->weight*goalfac;
/* a little ad hoc changing the goal control to be less *sharp* */
bp->goal = (float)pow(bp->goal, 4.0f);
}
@@ -1084,6 +1084,87 @@ static void lattice_to_softbody(Object *ob,int *rcs)
}
}
+/* makes totally fresh start situation */
+static void curve_surf_to_softbody(Object *ob, int *rcs)
+{
+ Curve *cu= ob->data;
+ SoftBody *sb;
+ int totvert, totspring = 0;
+
+ totvert= count_curveverts(&cu->nurb);
+
+ if (ob->softflag & OB_SB_EDGES){
+ if(ob->type==OB_CURVE) {
+ totspring= totvert - BLI_countlist(&cu->nurb);
+ }
+ }
+
+ /* renew ends with ob->soft with points and edges, also checks & makes ob->soft */
+ renew_softbody(ob, totvert, totspring, rcs);
+ sb= ob->soft; /* can be created in renew_softbody() */
+
+ /* weights from bpoints, same code used as for mesh vertices */
+ if((ob->softflag & OB_SB_GOAL) && sb->vertgroup) {
+ BodyPoint *bp= sb->bpoint;
+ BodySpring *bs= sb->bspring;
+ Nurb *nu;
+ BezTriple *bezt;
+ BPoint *bpnt;
+ float goalfac= ABS(sb->maxgoal - sb->mingoal);
+ int a, curindex=0;
+
+ for(nu= cu->nurb.first; nu; nu= nu->next) {
+ if(nu->bezt) {
+ for(bezt=nu->bezt, a=0; a<nu->pntsu; a++, bezt++, bp++, curindex+=3) {
+ bp->goal= sb->mingoal + bezt->weight*goalfac;
+ /* a little ad hoc changing the goal control to be less *sharp* */
+ bp->goal = (float)pow(bp->goal, 4.0f);
+ /* all three triples */
+ bp++;
+ bp->goal= (bp-1)->goal;
+ bp++;
+ bp->goal= (bp-1)->goal;
+
+ if(totspring) {
+ if(a>0) {
+ bs->v1= curindex-1;
+ bs->v2= curindex;
+ bs->strength= 1.0;
+ bs++;
+ }
+ bs->v1= curindex;
+ bs->v2= curindex+1;
+ bs->strength= 1.0;
+ bs++;
+
+ bs->v1= curindex+1;
+ bs->v2= curindex+2;
+ bs->strength= 1.0;
+ bs++;
+ }
+ }
+ }
+ else {
+ for(bpnt=nu->bp, a=0; a<nu->pntsu*nu->pntsv; a++, bpnt++, bp++, curindex++) {
+ bp->goal= sb->mingoal + bpnt->weight*goalfac;
+ /* a little ad hoc changing the goal control to be less *sharp* */
+ bp->goal = (float)pow(bp->goal, 4.0f);
+
+ if(totspring && a>0) {
+ bs->v1= curindex-1;
+ bs->v2= curindex;
+ bs->strength= 1.0;
+ bs++;
+ }
+ }
+ }
+ }
+ }
+
+ if(totspring)
+ build_bps_springlist(ob); /* link bps to springs */
+}
+
/* copies softbody result back in object */
static void softbody_to_object(Object *ob, float (*vertexCos)[3], int numVerts)
@@ -1288,13 +1369,17 @@ void sbObjectStep(Object *ob, float framenr, float (*vertexCos)[3], int numVerts
{
switch(ob->type) {
case OB_MESH:
- mesh_to_softbody(ob,&rcs);
+ mesh_to_softbody(ob, &rcs);
break;
case OB_LATTICE:
- lattice_to_softbody(ob,&rcs);
+ lattice_to_softbody(ob, &rcs);
+ break;
+ case OB_CURVE:
+ case OB_SURF:
+ curve_surf_to_softbody(ob, &rcs);
break;
default:
- renew_softbody(ob, numVerts, 0,&rcs);
+ renew_softbody(ob, numVerts, 0, &rcs);
break;
}