[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [13372] branches/cloth/blender/source/ blender: Enabled first + last simulation frame, hopefully fixed some cache problems, changed 3d view ball to a pushpin layout -feel free to enhance in drawobject .c line 5440
Daniel Genrich
daniel.genrich at gmx.net
Wed Jan 23 16:30:23 CET 2008
Revision: 13372
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=13372
Author: genscher
Date: 2008-01-23 16:30:23 +0100 (Wed, 23 Jan 2008)
Log Message:
-----------
Enabled first + last simulation frame, hopefully fixed some cache problems, changed 3d view ball to a pushpin layout -feel free to enhance in drawobject.c line 5440
Modified Paths:
--------------
branches/cloth/blender/source/blender/blenkernel/intern/cloth.c
branches/cloth/blender/source/blender/makesdna/DNA_cloth_types.h
branches/cloth/blender/source/blender/src/buttons_object.c
branches/cloth/blender/source/blender/src/drawobject.c
Modified: branches/cloth/blender/source/blender/blenkernel/intern/cloth.c
===================================================================
--- branches/cloth/blender/source/blender/blenkernel/intern/cloth.c 2008-01-23 15:06:44 UTC (rev 13371)
+++ branches/cloth/blender/source/blender/blenkernel/intern/cloth.c 2008-01-23 15:30:23 UTC (rev 13372)
@@ -160,6 +160,8 @@
clmd->sim_parms->firstframe = 1;
clmd->sim_parms->lastframe = 250;
clmd->sim_parms->vgroup_mass = 0;
+ clmd->sim_parms->lastcachedframe = 0;
+
clmd->coll_parms->self_friction = 5.0;
clmd->coll_parms->friction = 10.0;
clmd->coll_parms->loop_count = 1;
@@ -483,46 +485,6 @@
int modifiers_indexInObject(Object *ob, ModifierData *md_seek);
-void cloth_clear_cache(Object *ob, ClothModifierData *clmd, float framenr)
-{
- int stack_index = -1;
-
- if(!(clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_CCACHE_PROTECT))
- {
- stack_index = modifiers_indexInObject(ob, (ModifierData *)clmd);
-
- BKE_ptcache_id_clear((ID *)ob, PTCACHE_CLEAR_AFTER, framenr, stack_index);
- }
-}
-static void cloth_write_cache(Object *ob, ClothModifierData *clmd, float framenr)
-{
- FILE *fp = NULL;
- int stack_index = -1;
- unsigned int a;
- 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;
- }
-
- for(a = 0; a < cloth->numverts; a++)
- {
- fwrite(&cloth->verts[a].x, sizeof(float),3,fp);
- fwrite(&cloth->verts[a].xconst, sizeof(float),3,fp);
- fwrite(&cloth->verts[a].v, sizeof(float),3,fp);
- }
-
- fclose(fp);
-}
static int cloth_read_cache(Object *ob, ClothModifierData *clmd, float framenr)
{
FILE *fp = NULL;
@@ -567,7 +529,56 @@
return ret;
}
+void cloth_clear_cache(Object *ob, ClothModifierData *clmd, float framenr)
+{
+ int stack_index = -1;
+
+ if(!(clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_CCACHE_PROTECT))
+ {
+ stack_index = modifiers_indexInObject(ob, (ModifierData *)clmd);
+
+ BKE_ptcache_id_clear((ID *)ob, PTCACHE_CLEAR_AFTER, framenr, stack_index);
+ }
+
+ if(framenr>0)
+ {
+ cloth_read_cache(ob, clmd, framenr);
+ }
+}
+static void cloth_write_cache(Object *ob, ClothModifierData *clmd, float framenr)
+{
+ FILE *fp = NULL;
+ int stack_index = -1;
+ unsigned int a;
+ 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;
+ }
+
+ for(a = 0; a < cloth->numverts; a++)
+ {
+ fwrite(&cloth->verts[a].x, sizeof(float),3,fp);
+ fwrite(&cloth->verts[a].xconst, sizeof(float),3,fp);
+ fwrite(&cloth->verts[a].v, sizeof(float),3,fp);
+ }
+
+ clmd->sim_parms->lastcachedframe = MAX2(clmd->sim_parms->lastcachedframe, framenr);
+
+ fclose(fp);
+}
+
+
/**
* cloth_deform_verts - simulates one step, framenr is in frames.
*
@@ -585,48 +596,24 @@
// only be active during a specific period:
// that's "first frame" and "last frame" on GUI
- /*
- if ( ! ( clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_COLLOBJ ) )
+ if ( current_time < clmd->sim_parms->firstframe )
{
- if ( clmd->clothObject )
+ return;
+ }
+ else if ( current_time > clmd->sim_parms->lastframe )
+ {
+ int stack_index = modifiers_indexInObject(ob, (ModifierData *)clmd);
+
+ if(BKE_ptcache_id_exist((ID *)ob, clmd->sim_parms->lastcachedframe, stack_index))
{
- if ( clmd->sim_parms->cache )
+ if(cloth_read_cache(ob, clmd, framenr))
{
- if ( current_time < clmd->sim_parms->firstframe )
- {
- int frametime = cloth_cache_first_frame ( clmd );
- if ( cloth_cache_search_frame ( clmd, frametime ) )
- {
- cloth_cache_get_frame ( clmd, frametime );
- cloth_to_object ( ob, clmd, vertexCos, numverts );
- }
- return;
- }
- else if ( current_time > clmd->sim_parms->lastframe )
- {
- int frametime = cloth_cache_last_frame ( clmd );
- if ( cloth_cache_search_frame ( clmd, frametime ) )
- {
- cloth_cache_get_frame ( clmd, frametime );
- cloth_to_object ( ob, clmd, vertexCos, numverts );
- }
- return;
- }
- else if ( ABS ( deltaTime ) >= 2.0f ) // no timewarps allowed
- {
- if ( cloth_cache_search_frame ( clmd, framenr ) )
- {
- cloth_cache_get_frame ( clmd, framenr );
- cloth_to_object ( ob, clmd, vertexCos, numverts );
- }
- clmd->sim_parms->sim_time = current_time;
- return;
- }
+ // Copy the result back to the object.
+ cloth_to_object ( ob, clmd, vertexCos, numverts );
}
-
}
+ return;
}
- */
// printf("ct: %f, st: %f, r.cfra: %f, dt: %f\n", current_time, clmd->sim_parms->sim_time, ( float ) G.scene->r.cfra, deltaTime);
Modified: branches/cloth/blender/source/blender/makesdna/DNA_cloth_types.h
===================================================================
--- branches/cloth/blender/source/blender/makesdna/DNA_cloth_types.h 2008-01-23 15:06:44 UTC (rev 13371)
+++ branches/cloth/blender/source/blender/makesdna/DNA_cloth_types.h 2008-01-23 15:30:23 UTC (rev 13372)
@@ -76,6 +76,8 @@
int maxspringlen; /* in percent!; if tearing enabled, a spring will get cut */
int lastframe; /* frame on which simulation stops */
int firstframe; /* frame on which simulation starts */
+ int lastcachedframe;
+ int pad3;
}
SimulationSettings;
Modified: branches/cloth/blender/source/blender/src/buttons_object.c
===================================================================
--- branches/cloth/blender/source/blender/src/buttons_object.c 2008-01-23 15:06:44 UTC (rev 13371)
+++ branches/cloth/blender/source/blender/src/buttons_object.c 2008-01-23 15:30:23 UTC (rev 13372)
@@ -2295,7 +2295,7 @@
CFRA= 1;
update_for_newframe_muted();
DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA);
- cloth_clear_cache(ob, clmd, 2);
+ cloth_clear_cache(ob, clmd, 1);
allqueue(REDRAWBUTSOBJECT, 0);
allqueue(REDRAWVIEW3D, 0);
}
@@ -2306,7 +2306,7 @@
ClothModifierData *clmd = (ClothModifierData *)modifiers_findByType(ob, eModifierType_Cloth);
if(clmd)
{
- cloth_clear_cache(ob, clmd, MAX2(2.0,G.scene->r.cfra + 1.0));
+ cloth_clear_cache(ob, clmd, MAX2(1.0,G.scene->r.cfra + 1.0));
allqueue(REDRAWBUTSOBJECT, 0);
}
}
Modified: branches/cloth/blender/source/blender/src/drawobject.c
===================================================================
--- branches/cloth/blender/source/blender/src/drawobject.c 2008-01-23 15:06:44 UTC (rev 13371)
+++ branches/cloth/blender/source/blender/src/drawobject.c 2008-01-23 15:30:23 UTC (rev 13372)
@@ -5406,7 +5406,7 @@
ClothModifierData *clmd = (ClothModifierData *)modifiers_findByType(ob, eModifierType_Cloth);
Cloth *cloth = clmd->clothObject;
ClothVertex *verts;
- float col[3], point[3];
+ float col[3];
col[0] = 0.53;
col[1] = 0.04;
col[2] = 0.0;
@@ -5417,35 +5417,52 @@
if(cloth)
{
- verts = cloth->verts;
-
- for(i = 0; i < cloth->numverts; i++)
- {
- if(verts[i].flags & CLOTH_VERT_FLAG_PINNED)
+ /* don't paint anything if cloth has RESET status */
+ if(!(clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_RESET))
+ {
+ verts = cloth->verts;
+
+ for(i = 0; i < cloth->numverts; i++)
{
- 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);
+ 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 ( cent, verts[i].x );
+ Mat4MulVecfl ( ob->imat, cent );
+
+ glPushMatrix();
+ glTranslatef(cent[0], cent[1], cent[2]);
+ glScalef(size[0], size[1], size[2]);
+
+ // gluSphere(qobj, 1.0, 8, 5);
+ glTranslatef(0, 0, 1.0);
+ gluDisk(qobj, 0, 0.4, 8, 5);
+ gluCylinder(qobj, 0.4, 0.4, 1.0, 8, 5);
+
+ glTranslatef(0, 0, 1.0);
+ gluDisk(qobj, 0, 0.4, 8, 5);
+
+ glTranslatef(0, 0, -2.0);
+ /*
+ col[0] = 0.53;
+ col[1] = 0.54;
+ col[2] = 0.0;
+ glColor3fv(col);
+ */
+ gluCylinder(qobj, 0.0, 0.2, 1.0, 8, 5);
+
+ glPopMatrix();
+
+ gluDeleteQuadric(qobj);
+ }
}
}
}
More information about the Bf-blender-cvs
mailing list