Help on viewport animation

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

Help on viewport animation

jpmendes
I need some help on viewport animation.

I'm currently making the animation of a CNC machine and all is going well except concerning the viewport animation. Lets see...
At first I wrongly thought that I could pass parameters from modules to $vpr, $vpt and $vpd using $globals. As this is impossible, I tried using functions at top level to do the same.

for instance if I do:
$vpt=[100+300*MT(1),0,0];
$vpr=[0,0,200*MT(1)];
$vpd=1500;
where MT(i) function is the relative time within animation sequence "i" and depends on $t, the viewport animates.

However if I do:
 
  function Cam() = CS==1 ? [10,200,1, 20,20,1, 20,20,1, 20,92,2, 20,29,1, 20,92,2, 200,200,1] :
                        CS==2 ? [10,200,1, 20,20,1, 20,20,1, 29,92,2, 29,29,1, 29,92,2, 200,200,1] : 0 ;
                                                 
Where CS is my current sequence and Cam() contains the parameters for the viewport animation.

And then if I do:
 
  function VPX(CS)=Cam()[0]+S(CS,Cam()[1],Cam()[2],0);
  function VPRZ(CS)=Cam()[15]+S(CS,Cam()[16],Cam()[17],0);
 
 Where my function S(a,b,c,d), that is systematically used in my animation without problems, also depends on $t.

And then do:

$vpt=[VPX(CS), 100, 100];
$vpr=[0,0,VPRZ(CS)];
$vpd=1500;
 
echo("Camera: ", Cam()[0],Cam()[1], Cam()[2],VPX(CS), VPRZ(CS));
 
I see that VPX(CS) and VPRZ(CS) change with time as expected, but $vpt and $vpr stay with the first calculated values until the end of the sequence.

What am I doing wrong?

Thanks.

jpmendes
Reply | Threaded
Open this post in threaded view
|

Re: Help on viewport animation

runsun
Don't know what's wrong, but if you can rotate the objects (instead of changing viewport), this might be useful:

Animating gif with 3D rotation
$ Runsun Pan, PhD
$ libs: scadx, doctest, faces(git), offline doc(git), runscad.py(2,git), editor of choice: CudaText ( OpenSCAD lexer); $ Tips; $ Snippets
Reply | Threaded
Open this post in threaded view
|

Re: Help on viewport animation

nophead
In reply to this post by jpmendes
Should CS be a parameter of Cam() perhaps?

On 31 March 2016 at 19:29, jpmendes <[hidden email]> wrote:
I need some help on viewport animation.

I'm currently making the animation of a CNC machine and all is going well
except concerning the viewport animation. Lets see...
At first I wrongly thought that I could pass parameters from modules to
$vpr, $vpt and $vpd using $globals. As this is impossible, I tried using
functions at top level to do the same.

for instance if I do:
$vpt=[100+300*MT(1),0,0];
$vpr=[0,0,200*MT(1)];
$vpd=1500;
where MT(i) function is the relative time within animation sequence "i" and
depends on $t, the viewport animates.

However if I do:

  function Cam() = CS==1 ? [10,200,1, 20,20,1, 20,20,1, 20,92,2, 20,29,1,
20,92,2, 200,200,1] :
                        CS==2 ? [10,200,1, 20,20,1, 20,20,1, 29,92,2, 29,29,1, 29,92,2,
200,200,1] : 0 ;

Where CS is my current sequence and Cam() contains the parameters for the
viewport animation.

And then if I do:

  function VPX(CS)=Cam()[0]+S(CS,Cam()[1],Cam()[2],0);
  function VPRZ(CS)=Cam()[15]+S(CS,Cam()[16],Cam()[17],0);

 Where my function S(a,b,c,d), that is systematically used in my animation
without problems, also depends on $t.

And then do:

$vpt=[VPX(CS), 100, 100];
$vpr=[0,0,VPRZ(CS)];
$vpd=1500;

echo("Camera: ", Cam()[0],Cam()[1], Cam()[2],VPX(CS), VPRZ(CS));

I see that VPX(CS) and VPRZ(CS) change with time as expected, but $vpt and
$vpr stay with the first calculated values until the end of the sequence.

What am I doing wrong?

Thanks.

jpmendes



--
View this message in context: http://forum.openscad.org/Help-on-viewport-animation-tp16858.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Help on viewport animation

doug.moen
In reply to this post by jpmendes
check if you are assigning $vpt= more than once in your script. OpenSCAD won't warn you about that, it will just ignore all but the last definition of $vpt.

On 31 March 2016 at 14:29, jpmendes <[hidden email]> wrote:
I need some help on viewport animation.

I'm currently making the animation of a CNC machine and all is going well
except concerning the viewport animation. Lets see...
At first I wrongly thought that I could pass parameters from modules to
$vpr, $vpt and $vpd using $globals. As this is impossible, I tried using
functions at top level to do the same.

for instance if I do:
$vpt=[100+300*MT(1),0,0];
$vpr=[0,0,200*MT(1)];
$vpd=1500;
where MT(i) function is the relative time within animation sequence "i" and
depends on $t, the viewport animates.

However if I do:

  function Cam() = CS==1 ? [10,200,1, 20,20,1, 20,20,1, 20,92,2, 20,29,1,
20,92,2, 200,200,1] :
                        CS==2 ? [10,200,1, 20,20,1, 20,20,1, 29,92,2, 29,29,1, 29,92,2,
200,200,1] : 0 ;

Where CS is my current sequence and Cam() contains the parameters for the
viewport animation.

And then if I do:

  function VPX(CS)=Cam()[0]+S(CS,Cam()[1],Cam()[2],0);
  function VPRZ(CS)=Cam()[15]+S(CS,Cam()[16],Cam()[17],0);

 Where my function S(a,b,c,d), that is systematically used in my animation
without problems, also depends on $t.

And then do:

$vpt=[VPX(CS), 100, 100];
$vpr=[0,0,VPRZ(CS)];
$vpd=1500;

echo("Camera: ", Cam()[0],Cam()[1], Cam()[2],VPX(CS), VPRZ(CS));

I see that VPX(CS) and VPRZ(CS) change with time as expected, but $vpt and
$vpr stay with the first calculated values until the end of the sequence.

What am I doing wrong?

Thanks.

jpmendes



--
View this message in context: http://forum.openscad.org/Help-on-viewport-animation-tp16858.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org




_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Help on viewport animation

jpmendes
@ Doug
Nope, there is only one place where $vp's are referenced.

@ nopehead
I tried Cam(CS) without success.

Thanks anyway

BTW this is a test sample of the two first sequences without the CNC, just to speed up things. Although there are some adjustments to be done, that's the idea.

anima_tst.mp4

Another problem I'm facing is: for this simple animation, generating the png's directly by checking "Dump Pictures"  my file rate generation is about 1 second per picture. However if I use a script for generating the images with about 4x the standard resolution, it takes about a minute per picture. That means more than 2 days for my estimated 7500 steps animation. Considering the inclusion of all the components in the animation maybe a week will not be enough. The CNC is belt driven and I have to calculate the belt deformation for each step, and it takes about 20 secs in my machine.
Reply | Threaded
Open this post in threaded view
|

Re: Help on viewport animation

Neon22
@jpmendes I'm happy to help out with rendering a sequence.
I have 16 cores, possibly more than one instance can be rendered at the same time ?
Assuming you hve a time constraint....
Reply | Threaded
Open this post in threaded view
|

Re: Help on viewport animation

nophead
In reply to this post by jpmendes
I don't know what your S() function is but this dummy seems to produce camera movement and the $vp variables do change.

sphere(10);

function Cam() =
 CS==1 ? [10,200,1, 20,20,1, 20,20,1, 20,92,2, 20,29,1, 20,92,2, 200,200,1] :
 CS==2 ? [10,200,1, 20,20,1, 20,20,1, 29,92,2, 29,29,1, 29,92,2, 200,200,1] : 0 ;

function VPX(CS)=Cam()[0]+S(CS,Cam()[1],Cam()[2],0);
function VPRZ(CS)=Cam()[15]+S(CS,Cam()[16],Cam()[17],0);
function S(a,b,c,d) = a + b + c + d + 10 * $t;

CS = 2;
 
$vpt=[VPX(CS), 100, 100];
$vpr=[0,0,VPRZ(CS)];
$vpd=1500;
 
echo("Camera: ", Cam()[0],Cam()[1], Cam()[2],VPX(CS), VPRZ(CS));
echo($vpt, $vpr, $vpd);



On 31 March 2016 at 21:58, jpmendes <[hidden email]> wrote:
@ Doug
Nope, there is only one place where $vp's are referenced.

@ nopehead
I tried Cam(CS) without success.

Thanks anyway

BTW this is a test sample of the two first sequences without the CNC, just
to speed up things. Although there are some adjustments to be done, that's
the idea.

anima_tst.mp4 <http://forum.openscad.org/file/n16866/anima_tst.mp4>

Another problem I'm facing is: for this simple animation, generating the
png's directly by checking "Dump Pictures"  my file rate generation is about
1 second per picture. However if I use a script for generating the images
with about 4x the standard resolution, it takes about a minute per picture.
That means more than 2 days for my estimated 7500 steps animation.
Considering the inclusion of all the components in the animation maybe a
week will not be enough. The CNC is belt driven and I have to calculate the
belt deformation for each step, and it takes about 20 secs in my machine.




--
View this message in context: http://forum.openscad.org/Help-on-viewport-animation-tp16858p16866.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Help on viewport animation

jpmendes
@neon22
Thanks, I may consider the offer for the final render. Maybe I can use my son's 6 core pc if he takes some days off, summer is comming ... :-).  For now I have my 11 year old, 2 cores Athlon 4200 only.

@nopehead

My S function is a bit straight forward. I intend to perfect it later. Now what I'm trying to do is  a simple animator that I can use whenever I need.

// S -Relative speed within the sequence time with movement inversion point (perliminary).
// d - distance, s - relative speed, InvT - inversion point between 1 and 0.
function S(i,d,s,InvT) = (InvT==undef)? (d*pow(MT(i),s)):
                       (MT(i)-InvT<0)? (d*pow(-MT(i)+InvT,s)):
                       (d*pow(MT(i)-InvT,s));

// MT - relative time within the sequence time slot (1 --> 0)
function MT(i) = (T(i)-$t>=0)? (TTime/SeqTPlan[i-1])*(T(i)-$t): 0;

As you can see S() depends on $t through MT(i)



Reply | Threaded
Open this post in threaded view
|

Re: Help on viewport animation

nophead
This moves:

sphere(10);

function Cam() =
 CS==1 ? [10,200,1, 20,20,1, 20,20,1, 20,92,2, 20,29,1, 20,92,2, 200,200,1] :
 CS==2 ? [10,200,1, 20,20,1, 20,20,1, 29,92,2, 29,29,1, 29,92,2, 200,200,1] : 0 ;

function VPX(CS)=Cam()[0]+S(CS,Cam()[1],Cam()[2],0);
function VPRZ(CS)=Cam()[15]+S(CS,Cam()[16],Cam()[17],0);
function S(a,b,c,d) = a + b + c + d + 10 * $t;
// d - distance, s - relative speed, InvT - inversion point between 1 and 0.
function S(i,d,s,InvT) = (InvT==undef)? (d*pow(MT(i),s)):
                       (MT(i)-InvT<0)? (d*pow(-MT(i)+InvT,s)):
                       (d*pow(MT(i)-InvT,s));

// MT - relative time within the sequence time slot (1 --> 0)
function MT(i) = $t;

CS = 2;
 
$vpt=[VPX(CS), 100, 100];
$vpr=[0,0,VPRZ(CS)];
$vpd=1500;
 
echo("Camera: ", Cam()[0],Cam()[1], Cam()[2],VPX(CS), VPRZ(CS));
echo($vpt, $vpr, $vpd);

So I suspect your MT() function has a bug.


On 31 March 2016 at 23:08, jpmendes <[hidden email]> wrote:
@neon22
Thanks, I may consider the offer for the final render. Maybe I can use my
son's 6 core pc if he takes some days off, summer is comming ... :-).  For
now I have my 11 year old, 2 cores Athlon 4200 only.

@nopehead

My S function is a bit straight forward. I intend to perfect it later. Now
what I'm trying to do is  a simple animator that I can use whenever I need.

// S -Relative speed within the sequence time with movement inversion point
(perliminary).
// d - distance, s - relative speed, InvT - inversion point between 1 and 0.
function S(i,d,s,InvT) = (InvT==undef)? (d*pow(MT(i),s)):
                       (MT(i)-InvT<0)? (d*pow(-MT(i)+InvT,s)):
                       (d*pow(MT(i)-InvT,s));

// MT - relative time within the sequence time slot (1 --> 0)
function MT(i) = (T(i)-$t>=0)? (TTime/SeqTPlan[i-1])*(T(i)-$t): 0;

As you can see S() depends on $t through MT(i)







--
View this message in context: http://forum.openscad.org/Help-on-viewport-animation-tp16858p16870.html
Sent from the OpenSCAD mailing list archive at Nabble.com.

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: Help on viewport animation

jpmendes

Yes you are right MT() has a bug. Problem solved. But I cheated a bit.
My real MT(i) was:

function MT(i) = ($ST>1||$ST<0)? 0 : ($tst==0)? NT(i) : ($ST==undef)? 1 : $ST;

and NT(i) is the MT(i) function I posted before.

function NT(i) = (T(i)-$t>=0)? (TTime/SeqTPlan[i-1])*(T(i)-$t): 0;

Since my variable $tst is set to 0,  I replaced directly NT(i)  with MT(i) for posting simplification.
My MT(i) was a debugging help to test animation sequences without the animation mode checked.
The problem is that I forgot that $ST is undef when I am not in test mode and probably the evaluation of the expression is in such a way that $ST is evaluated before $tst, and as a result MT(i) is always 1.
The reason for the globals was that I was hopping to pass values from modules to the top level but that's not possible.

Thanks a lot for the help.
jpmendes