Made GUI even more intuitive with explanations why something is not available etc., fixed some uninitialized variable. NEW: show pinned verts as big red balls in 3dview - please tell me how to improve that visual feedback :)
This commit is contained in:
@@ -80,6 +80,7 @@ typedef struct ClothVertex
|
||||
float goal; /* goal, from SB */
|
||||
float impulse[3]; /* used in collision.c */
|
||||
unsigned int impulse_count; /* same as above */
|
||||
float avg_spring_len; /* average length of connected springs, UNUSED ATM */
|
||||
}
|
||||
ClothVertex;
|
||||
|
||||
@@ -156,8 +157,8 @@ typedef enum
|
||||
} CLOTH_SPRINGS_FLAGS;
|
||||
|
||||
/* Bits to or into the ClothVertex.flags. */
|
||||
#define CVERT_FLAG_PINNED 1
|
||||
#define CVERT_FLAG_COLLISION 2
|
||||
#define CLOTH_VERT_FLAG_PINNED 1
|
||||
#define CLOTH_VERT_FLAG_COLLISION 2
|
||||
|
||||
|
||||
// needed for buttons_object.c
|
||||
|
||||
@@ -124,7 +124,7 @@ static CM_SOLVER_DEF solvers [] =
|
||||
static void cloth_to_object ( Object *ob, ClothModifierData *clmd, float ( *vertexCos ) [3], unsigned int numverts );
|
||||
static void cloth_from_mesh ( Object *ob, ClothModifierData *clmd, DerivedMesh *dm );
|
||||
static int cloth_from_object ( Object *ob, ClothModifierData *clmd, DerivedMesh *dm, float ( *vertexCos ) [3], unsigned int numverts, float framenr );
|
||||
int cloth_build_springs ( Cloth *cloth, DerivedMesh *dm );
|
||||
int cloth_build_springs ( ClothModifierData *clmd, DerivedMesh *dm );
|
||||
static void cloth_apply_vgroup ( ClothModifierData *clmd, DerivedMesh *dm, short vgroup );
|
||||
|
||||
|
||||
@@ -502,12 +502,17 @@ static void cloth_write_cache(Object *ob, ClothModifierData *clmd, float framenr
|
||||
Cloth *cloth = clmd->clothObject;
|
||||
|
||||
if(!cloth)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
stack_index = modifiers_indexInObject(ob, (ModifierData *)clmd);
|
||||
|
||||
fp = BKE_ptcache_id_fopen((ID *)ob, 'w', framenr, stack_index);
|
||||
if(!fp) return;
|
||||
if(!fp)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for(a = 0; a < cloth->numverts; a++)
|
||||
{
|
||||
@@ -554,10 +559,10 @@ static int cloth_read_cache(Object *ob, ClothModifierData *clmd, float framenr)
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
|
||||
if(clmd->sim_parms->solver_type == 0)
|
||||
implicit_set_positions(clmd);
|
||||
}
|
||||
|
||||
if(clmd->sim_parms->solver_type == 0)
|
||||
implicit_set_positions(clmd);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -622,6 +627,8 @@ void clothModifier_do ( ClothModifierData *clmd, Object *ob, DerivedMesh *dm,
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
// printf("ct: %f, st: %f, r.cfra: %f, dt: %f\n", current_time, clmd->sim_parms->sim_time, ( float ) G.scene->r.cfra, deltaTime);
|
||||
|
||||
// unused in the moment, calculated seperately in implicit.c
|
||||
clmd->sim_parms->dt = 1.0f / clmd->sim_parms->stepsPerFrame;
|
||||
@@ -681,11 +688,7 @@ void clothModifier_do ( ClothModifierData *clmd, Object *ob, DerivedMesh *dm,
|
||||
cloth_write_cache(ob, clmd, framenr);
|
||||
|
||||
}
|
||||
else // just retrieve the cached frame
|
||||
{
|
||||
cloth_read_cache(ob, clmd, framenr);
|
||||
}
|
||||
|
||||
|
||||
// Copy the result back to the object.
|
||||
cloth_to_object ( ob, clmd, vertexCos, numverts );
|
||||
|
||||
@@ -694,12 +697,14 @@ void clothModifier_do ( ClothModifierData *clmd, Object *ob, DerivedMesh *dm,
|
||||
}
|
||||
|
||||
}
|
||||
else if ( ( deltaTime <= 0.0f ) || ( deltaTime > 1.0f ) )
|
||||
else
|
||||
{
|
||||
if ( clmd->clothObject != NULL )
|
||||
{
|
||||
if(cloth_read_cache(ob, clmd, framenr))
|
||||
{
|
||||
cloth_to_object ( ob, clmd, vertexCos, numverts );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -866,7 +871,7 @@ static void cloth_to_object ( Object *ob, ClothModifierData *clmd, float ( *vert
|
||||
for ( i = 0; i < numverts; i++, verts++ )
|
||||
{
|
||||
VECCOPY ( vertexCos[i], verts->x );
|
||||
Mat4MulVecfl ( ob->imat, vertexCos[i] ); /* softbody is in global coords */
|
||||
Mat4MulVecfl ( ob->imat, vertexCos[i] ); /* cloth is in global coords */
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -921,9 +926,9 @@ static void cloth_apply_vgroup ( ClothModifierData *clmd, DerivedMesh *dm, short
|
||||
|
||||
verts->goal = ( float ) pow ( verts->goal , 4.0f );
|
||||
|
||||
if ( dvert->dw [j].weight >=SOFTGOALSNAP )
|
||||
if ( verts->goal >=SOFTGOALSNAP )
|
||||
{
|
||||
verts->flags |= CVERT_FLAG_PINNED;
|
||||
verts->flags |= CLOTH_VERT_FLAG_PINNED;
|
||||
}
|
||||
|
||||
// TODO enable mass painting here, for the moment i let "goals" go first
|
||||
@@ -1018,7 +1023,7 @@ static int cloth_from_object ( Object *ob, ClothModifierData *clmd, DerivedMesh
|
||||
VECCOPY ( verts->impulse, tnull );
|
||||
}
|
||||
|
||||
if ( !cloth_build_springs ( clmd->clothObject, dm ) )
|
||||
if ( !cloth_build_springs ( clmd, dm ) )
|
||||
{
|
||||
cloth_free_modifier ( ob, clmd );
|
||||
modifier_setError ( & ( clmd->modifier ), "Can't build springs." );
|
||||
@@ -1042,11 +1047,11 @@ static int cloth_from_object ( Object *ob, ClothModifierData *clmd, DerivedMesh
|
||||
case OB_LATTICE:
|
||||
printf ( "Not supported: OB_LATTICE\n" );
|
||||
// lattice_to_softbody(ob);
|
||||
return 1;
|
||||
return 0;
|
||||
case OB_CURVE:
|
||||
case OB_SURF:
|
||||
printf ( "Not supported: OB_SURF| OB_CURVE\n" );
|
||||
return 1;
|
||||
return 0;
|
||||
default: return 0; // TODO - we do not support changing meshes
|
||||
}
|
||||
|
||||
@@ -1123,8 +1128,9 @@ int cloth_add_spring ( ClothModifierData *clmd, unsigned int indexA, unsigned in
|
||||
return 0;
|
||||
}
|
||||
|
||||
int cloth_build_springs ( Cloth *cloth, DerivedMesh *dm )
|
||||
int cloth_build_springs ( ClothModifierData *clmd, DerivedMesh *dm )
|
||||
{
|
||||
Cloth *cloth = clmd->clothObject;
|
||||
ClothSpring *spring = NULL, *tspring = NULL, *tspring2 = NULL;
|
||||
unsigned int struct_springs = 0, shear_springs=0, bend_springs = 0;
|
||||
unsigned int i = 0;
|
||||
@@ -1169,6 +1175,7 @@ int cloth_build_springs ( Cloth *cloth, DerivedMesh *dm )
|
||||
spring->kl = medge[i].v2;
|
||||
VECSUB ( temp, cloth->verts[spring->kl].x, cloth->verts[spring->ij].x );
|
||||
spring->restlen = sqrt ( INPR ( temp, temp ) );
|
||||
clmd->coll_parms->avg_spring_len += spring->restlen;
|
||||
spring->type = CLOTH_SPRING_TYPE_STRUCTURAL;
|
||||
spring->flags = 0;
|
||||
struct_springs++;
|
||||
@@ -1181,6 +1188,8 @@ int cloth_build_springs ( Cloth *cloth, DerivedMesh *dm )
|
||||
}
|
||||
}
|
||||
|
||||
clmd->coll_parms->avg_spring_len /= struct_springs;
|
||||
|
||||
// shear springs
|
||||
for ( i = 0; i < numfaces; i++ )
|
||||
{
|
||||
|
||||
@@ -89,7 +89,7 @@ typedef struct CollisionSettings
|
||||
short loop_count; /* How many iterations for the collision loop. */
|
||||
struct LinkNode *collision_list; /* e.g. pointer to temp memory for collisions */
|
||||
int flags; /* collision flags defined in BKE_cloth.h */
|
||||
int pad;
|
||||
float avg_spring_len; /* for selfcollision */
|
||||
}
|
||||
CollisionSettings;
|
||||
|
||||
|
||||
@@ -4937,6 +4937,8 @@ static void object_panel_cloth(Object *ob)
|
||||
block= uiNewBlock(&curarea->uiblocks, "object_cloth", UI_EMBOSS, UI_HELV, curarea->win);
|
||||
if(uiNewPanel(curarea, block, "Cloth ", "Physics", 640, 0, 318, 204)==0) return;
|
||||
uiSetButLock(object_data_is_libdata(ob), ERROR_LIBDATA_MESSAGE);
|
||||
|
||||
val = (clmd ? 1:0);
|
||||
|
||||
but = uiDefButI(block, TOG, REDRAWBUTSOBJECT, "Cloth", 10,200,130,20, &val, 0, 0, 0, 0, "Sets object to become cloth");
|
||||
|
||||
@@ -4977,12 +4979,10 @@ static void object_panel_cloth(Object *ob)
|
||||
/* GOAL STUFF */
|
||||
uiBlockBeginAlign(block);
|
||||
|
||||
if(BLI_countlist (&ob->defbase) > 0)
|
||||
{
|
||||
uiDefButBitI(block, TOG, CLOTH_SIMSETTINGS_FLAG_GOAL, REDRAWVIEW3D, "Pinning of cloth", 10,70,150,20, &clmd->sim_parms->flags, 0, 0, 0, 0, "Define forces for vertices to stick to animated position");
|
||||
}
|
||||
|
||||
if (clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_GOAL)
|
||||
uiDefButBitI(block, TOG, CLOTH_SIMSETTINGS_FLAG_GOAL, REDRAWVIEW3D, "Pinning of cloth", 10,70,150,20, &clmd->sim_parms->flags, 0, 0, 0, 0, "Define forces for vertices to stick to animated position");
|
||||
|
||||
if ((clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_GOAL) && (BLI_countlist (&ob->defbase) > 0))
|
||||
{
|
||||
if(ob->type==OB_MESH)
|
||||
{
|
||||
@@ -5013,13 +5013,9 @@ static void object_panel_cloth(Object *ob)
|
||||
MEM_freeN (clvg1);
|
||||
MEM_freeN (clvg2);
|
||||
}
|
||||
else
|
||||
{
|
||||
uiDefButS(block, TOG, B_CLOTH_RENEW, "W", 140,70,20,20, &clmd->sim_parms->vgroup_mass, 0, 1, 0, 0, "Use control point weight values");
|
||||
uiDefButF(block, NUM, B_CLOTH_RENEW, "Goal:", 160,70,150,20, &clmd->sim_parms->defgoal, 0.0, 1.0, 10, 0, "Default Goal (vertex target position) value, when no Vertex Group used");
|
||||
}
|
||||
|
||||
uiDefButF(block, NUM, B_CLOTH_RENEW, "Pin Stiff:", 10,50,150,20, &clmd->sim_parms->goalspring, 0.0, 500.0, 10, 0, "Pin (vertex target position) spring stiffness");
|
||||
uiDefBut(block, LABEL, 0, " ", 160,50,150,20, NULL, 0.0, 0, 0, 0, "");
|
||||
/*
|
||||
// nobody is changing these ones anyway
|
||||
uiDefButF(block, NUM, B_CLOTH_RENEW, "G Damp:", 160,50,150,20, &clmd->sim_parms->goalfrict , 0.0, 50.0, 10, 0, "Goal (vertex target position) friction");
|
||||
@@ -5027,6 +5023,12 @@ static void object_panel_cloth(Object *ob)
|
||||
uiDefButF(block, NUM, B_CLOTH_RENEW, "G Max:", 160,30,150,20, &clmd->sim_parms->maxgoal, 0.0, 1.0, 10, 0, "Goal maximum, vertex group weights are scaled to match this range");
|
||||
*/
|
||||
}
|
||||
else if (clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_GOAL)
|
||||
{
|
||||
uiDefBut(block, LABEL, 0, " ", 160,70,150,20, NULL, 0.0, 0, 0, 0, "");
|
||||
uiDefBut(block, LABEL, 0, "No vertex group for pinning available.", 10,50,300,20, NULL, 0.0, 0, 0, 0, "");
|
||||
}
|
||||
|
||||
uiBlockEndAlign(block);
|
||||
|
||||
/*
|
||||
@@ -5078,18 +5080,26 @@ static void object_panel_cloth_II(Object *ob)
|
||||
sprintf (str, "Frame %d cached. [%d in preroll, %d in total]", length-clmd->sim_parms->preroll, clmd->sim_parms->preroll, length);
|
||||
*/
|
||||
|
||||
uiDefButBitI(block, TOG, CLOTH_SIMSETTINGS_FLAG_CCACHE_PROTECT, REDRAWVIEW3D, "Protect Cache", 10,120,300,20, &clmd->sim_parms->flags, 0, 0, 0, 0, "Protect cache from automatic freeing when scene changed");
|
||||
|
||||
if(!(clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_CCACHE_PROTECT))
|
||||
if (!G.relbase_valid)
|
||||
{
|
||||
uiDefBut(block, LABEL, 0, "Clear cache:", 10,100,90,20, NULL, 0.0, 0, 0, 0, "");
|
||||
uiDefBut(block, BUT, B_CLOTH_CLEARCACHEALL, "All", 100, 100,100,20, NULL, 0.0, 0.0, 0, 0, "Free ALL cloth cache without preroll");
|
||||
uiDefBut(block, BUT, B_CLOTH_CLEARCACHEFRAME, "From next frame", 200, 100,110,20, NULL, 0.0, 0.0, 0, 0, "Free cloth cache starting from next frame");
|
||||
uiDefBut(block, LABEL, 0, " ", 10,80,300,20, NULL, 0.0, 0, 0, 0, "");
|
||||
uiDefBut(block, LABEL, 0, "Cache deactivated until file is saved.", 10,120,300,20, NULL, 0.0, 0, 0, 0, "");
|
||||
uiDefBut(block, LABEL, 0, " ", 10,100,300,40, NULL, 0.0, 0, 0, 0, "");
|
||||
}
|
||||
else
|
||||
{
|
||||
uiDefBut(block, LABEL, 0, " ", 10,100,300,40, NULL, 0.0, 0, 0, 0, "");
|
||||
uiDefButBitI(block, TOG, CLOTH_SIMSETTINGS_FLAG_CCACHE_PROTECT, REDRAWVIEW3D, "Protect Cache", 10,120,300,20, &clmd->sim_parms->flags, 0, 0, 0, 0, "Protect cache from automatic freeing when scene changed");
|
||||
|
||||
if(!(clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_CCACHE_PROTECT))
|
||||
{
|
||||
uiDefBut(block, LABEL, 0, "Clear cache:", 10,100,90,20, NULL, 0.0, 0, 0, 0, "");
|
||||
uiDefBut(block, BUT, B_CLOTH_CLEARCACHEALL, "All", 100, 100,100,20, NULL, 0.0, 0.0, 10, 0, "Free ALL cloth cache without preroll");
|
||||
uiDefBut(block, BUT, B_CLOTH_CLEARCACHEFRAME, "From next frame", 200, 100,110,20, NULL, 0.0, 0.0, 10, 0, "Free cloth cache starting from next frame");
|
||||
uiDefBut(block, LABEL, 0, " ", 10,80,300,20, NULL, 0.0, 0, 0, 0, "");
|
||||
}
|
||||
else
|
||||
{
|
||||
uiDefBut(block, LABEL, 0, " ", 10,100,300,40, NULL, 0.0, 0, 0, 0, "");
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -5399,6 +5399,57 @@ void draw_object(Base *base, int flag)
|
||||
if(col) cpack(col);
|
||||
glDepthMask(GL_TRUE);
|
||||
}
|
||||
|
||||
/* code for drawing pinned cloth verts */
|
||||
if(modifiers_isClothEnabled(ob))
|
||||
{
|
||||
ClothModifierData *clmd = (ClothModifierData *)modifiers_findByType(ob, eModifierType_Cloth);
|
||||
Cloth *cloth = clmd->clothObject;
|
||||
ClothVertex *verts;
|
||||
float col[3], point[3];
|
||||
col[0] = 0.53;
|
||||
col[1] = 0.04;
|
||||
col[2] = 0.0;
|
||||
glColor3fv(col);
|
||||
|
||||
/* inverse matrix is not uptodate... */
|
||||
Mat4Invert ( ob->imat, ob->obmat );
|
||||
|
||||
if(cloth)
|
||||
{
|
||||
verts = cloth->verts;
|
||||
|
||||
for(i = 0; i < cloth->numverts; i++)
|
||||
{
|
||||
if(verts[i].flags & CLOTH_VERT_FLAG_PINNED)
|
||||
{
|
||||
float size[3], cent[3];
|
||||
GLUquadricObj *qobj = gluNewQuadric();
|
||||
|
||||
gluQuadricDrawStyle(qobj, GLU_FILL);
|
||||
|
||||
size[0]= clmd->coll_parms->avg_spring_len / 3.0;
|
||||
size[1]= clmd->coll_parms->avg_spring_len / 3.0;
|
||||
size[2]= clmd->coll_parms->avg_spring_len / 3.0;
|
||||
|
||||
VECCOPY ( point, verts[i].x );
|
||||
Mat4MulVecfl ( ob->imat, point );
|
||||
|
||||
cent[0]= point[0];
|
||||
cent[1]= point[1];
|
||||
cent[2]= point[2];
|
||||
|
||||
glPushMatrix();
|
||||
glTranslatef(cent[0], cent[1], cent[2]);
|
||||
glScalef(size[0], size[1], size[2]);
|
||||
gluSphere(qobj, 1.0, 8, 5);
|
||||
glPopMatrix();
|
||||
|
||||
gluDeleteQuadric(qobj);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
bConstraint *con;
|
||||
|
||||
Reference in New Issue
Block a user