POV-Ray : Newsgroups : povray.text.scene-files : cloth sim Server Time
1 Nov 2024 05:22:36 EDT (-0400)
  cloth sim (Message 1 to 3 of 3)  
From: Reusser
Subject: cloth sim
Date: 12 Sep 2001 19:59:29
Message: <120920011856007461%reu1000@chorus.net>
I haven't really worked on this for a while and I regret to inform you
that I don't even know if this version will work, but I can tell you
that in order to try it, you need to have persistent variables turned
on with megapov.  Feel free to comment or ask any questions.  If it
goes crazy, try decreasing the little number (aln) and increasing the
number of repetitions.  

Finally, if anyone knows how to take the mesh grid created at the
bottom and make it a smooth mesh with mesh2, PLEASE LET ME KNOW.  I
really have no idea at the moment.  Thanks in advance.

 - Rico




#version unofficial megapov .7;

#ifndef(c1)
   $D = 2;
   $upoints = 31;
   $vpoints = 31;
   $grav = .005/3;
   $nl = 2/(upoints-1);
   $aln = .012;//change this number, but keep it small
   $damping = .95;//between .95 and .99
   
   $c1 = array[upoints][vpoints]
   $c2 = array[upoints][vpoints]
   $v1 = array[upoints][vpoints]
   
   $U=0;
   #while (U<upoints)
      $V=0;
      #while (V<vpoints)
         $c1[U][V] = <-1+2/(upoints-1)*U,1.3,-1+2/(vpoints-1)*V>;
         $v1[U][V] = <0,0,0>;
         $V=V+1;
      #end
      $U=U+1;
   #end
   
   #debug "\n defined undefined variables"
#end

$sphere_center = <-.6,0,0>;
$sphere_radius = .5 ;
$sphere_center2 = <.7,0,0>;
$sphere_radius2 = .25 ;

$repetitions = 4;
$Count = 1;
#while (Count<=repetitions)
   #debug concat("\n beginning repetition number ",str(Count,0,0))
   $U=0;
   #while (U<upoints)
      $V=0;
      #while (V<upoints)
         $dU=-D;
         $vmovement = -grav*y;
         #while (dU<=D)
            $dV=-D;
            #while (dV<=D)
               #if (U+dU>=0 & U+dU<upoints & V+dV>=0 & V+dV<vpoints &
                  dU*dU+dV*dV!=0)//might need to fix spacing
                  $vspring =
                     c1[U+dU][V+dV]-c1[U][V];
                  $length=vlength(vspring);
                  $new_norm_l = nl*sqrt(dV*dV+dU*dU);
                  $sforce = (length-new_norm_l)/(length*length)*aln;
                  $vforce = vspring*sforce;
                  $vmovement = vmovement + vforce;
               #end
               $dV = dV+1;
            #end
            $dU = dU+1;
         #end
         $v1[U][V] = v1[U][V] * damping + vmovement;
         $c2[U][V] = c1[U][V] + v1[U][V];
         $V=V+1;
      #end
      $U=U+1;
   #end
   #debug concat("\n finished cloth simulation repetition number 
   ",str(Count,0,0))
   
   $U=0;
   #while (U<upoints)
      $V=0;
      #while (V<vpoints)
         $point = c2[U][V];
         $dist = vlength(point-sphere_center);
         #if (dist<sphere_radius)
            $vforce = point-sphere_center;
            $vforce = vforce/dist*sphere_radius;
            $c2[U][V] = sphere_center + vforce;
            $v1[U][V] = v1[U][V]*0;//friction on the sphere
         #end
         $V=V+1;
      #end
      $U=U+1;
   #end
   #debug "\n checked for sphere intersection"
   $U=0;
   #while (U<upoints)
      $V=0;
      #while (V<vpoints)
         $point = c2[U][V];
         $dist = vlength(point-sphere_center2);
         #if (dist<sphere_radius2)
            $vforce = point-sphere_center2;
            $vforce = vforce/dist*sphere_radius2;
            $c2[U][V] = sphere_center2 + vforce;
            $v1[U][V] = v1[U][V]*0;//friction on the other sphere
         #end
         $V=V+1;
      #end
      $U=U+1;
   #end
   #debug "\n checked for sphere intersection"
   
   $U=0;
   #while (U<upoints)
      $V=0;
      #while (V<vpoints)
         $c1[U][V] = c2[U][V];
         $V=V+1;
      #end
      $U=U+1;
   #end
   #debug "\n finished transferring variables"
   $Count = Count+1;
#end


mesh{
   #debug "\n building mesh"
   $U=0;
   #while (U<upoints-1)
      $V=0;
      #while (V<upoints-1)
         triangle{
            c1[U][V],
            c1[U+1][V],
            c1[U][V+1]
         }
         triangle{
            c1[U][V+1]
            c1[U+1][V]
            c1[U+1][V+1]
         }
         $V=V+1;
      #end
      $U=U+1;
   #end
   pigment {color rgb 1}
}

camera{
   location <1,.3,-3>
   look_at <0,-.5,0>
}
light_source{
   <25,5,-10>
   rgb 1
   area_light y*8,z*8,3,3 jitter adaptive 1
}
light_source{
   <25,-35,-10>
   rgb 1
   area_light x*8,z*8,3,3 jitter adaptive 1
}

sphere{sphere_center,sphere_radius-.02  pigment {color rgb <1,.5,0>}}
sphere{sphere_center2,sphere_radius2-.02  pigment {color rgb <.5,1,0>}}


Post a reply to this message

From: Andy Cocker
Subject: Re: cloth sim
Date: 13 Sep 2001 18:50:48
Message: <3ba13848@news.povray.org>
"Reusser" <reu### [at] chorusnet> wrote in message
news:120920011856007461%reu### [at] chorusnet...
> Finally, if anyone knows how to take the mesh grid created at the
> bottom and make it a smooth mesh with mesh2, PLEASE LET ME KNOW.  I
> really have no idea at the moment.  Thanks in advance.

Hi Rico,

Thanks for posting this - I've not run it yet, but I shall soon.

Regarding smooth meshes, I've posted one of the output .inc files from Cloth
Sim in povray.binaries.scene-files. Look for Reusser-Cloth. It shows how
Mesh 2 are written. Maybe this will help you - it's a little over my head at
the moment.

All the best,

Andy Cocker


Post a reply to this message

From: Reusser
Subject: Re: cloth sim
Date: 16 Sep 2001 10:07:05
Message: <160920010903264718%reu1000@chorus.net>
In article <3ba13848@news.povray.org>, Andy Cocker
<big### [at] mariner9fsnetcouk> wrote:

> Hi Rico,
> 
> Thanks for posting this - I've not run it yet, but I shall soon.
> 
> Regarding smooth meshes, I've posted one of the output .inc files from Cloth
> Sim in povray.binaries.scene-files. Look for Reusser-Cloth. It shows how
> Mesh 2 are written. Maybe this will help you - it's a little over my head at
> the moment.
> 
> All the best,
> 
> Andy Cocker

Thank you very much!  I haven't looked at it yet, but I hope it will be
able to help.

 - Rico


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.