OK - I loaded the latest versions. Ignore my previous suggestion. Using
your files, just replace your version of ev_command_enter with this:
Basically, I just replaced your loop with a function. I then have the
function called by requestAnimationFrame for each item in the loop
It's fun to see the turtles walk!
function ev_command_enter_ajax(elements)
{
var number = elements[0];
viewXYZ = elements[1];
viewUP = elements[2];
var r = 0;
var drawFrame = function() {
var ts = [];
for(var i = 0; i < 13; i++) {
element = r*13+i+3;
ts.push(elements[element]);
}
linecolor=eval(ts[0]);
linecolors = linecolors.concat(linecolor);
move=eval(ts[1]);
moves = moves.concat(move);
leftColors=eval(ts[2]);
rightColors=eval(ts[3]);
backColors=eval(ts[4]);
bottoms=eval(ts[5]);
lefts=eval(ts[6]);
rights=eval(ts[7]);
backs=eval(ts[8]);
bottomNs=eval(ts[9]);
leftNs=eval(ts[10]);
rightNs=eval(ts[11]);
backNs=eval(ts[12]);
draw();
r++;
if (r < number) {
requestAnimationFrame(drawFrame);
}
}
requestAnimationFrame(drawFrame);
}
On Tue, Apr 29, 2014 at 4:33 PM, Brian Schott <[email protected]>wrote:
> Joe,
>
> I tried your first idea and do not see a slowdown, and do not see lines
> drawn.
> The version using heavy_process does not work: when the app is initialized,
> no starting canvas appears.
> The version with a new drawlines() does not show any lines nor turtles.
>
> I've got my fingers crossed something easy-ish works.
>
> Thanks, again,
>
> (Sent you files separately.)
>
> On Tue, Apr 29, 2014 at 3:57 PM, Joe Bogner <[email protected]> wrote:
>
> >
> > function drawLines(linecolors,moves) {
> > gl.lineWidth(2);
> > gl.uniform1i( uLit, 0 );
> > for(var i=0;i<linecolors.length;i++)
> > {
> > var drawFrame = function() { drawPrimitive( gl.LINES,
> > linecolors[i], moves[i]); }
> > requestAnimationFrame(drawFrame);
> > }
> > gl.lineWidth(1);
> > }
> >
> > Fun other links:
> >
> > http://jsfiddle.net/calpo/H7EEE/
> >
> > http://jsfiddle.net/ondras/xmCSY/
> >
> > If you wanted to "slow down" the animation, you could probably steal this
> > function:
> >
> > function heavy_process(){
> > var stoptime = 8;
> > var start = (new Date()).getTime();
> > while((new Date()).getTime() - start < stoptime){
> > // sleep
> > }
> >
> >
> > and then do:
> >
> > var drawFrame = function() { heavy_process(); drawPrimitive( gl.LINES,
> > linecolors[i], moves[i]); }
> >
> > instead of what was above
> >
> > I can try it if I had a running version
> >
> > I can't recall if requestAnimationFrame blocks or not. If it doesn't
> block,
> > then you'll need to restructure your code or just pass a callback in
> >
> > This could be as simple as:
> >
> > function
> >
> >
> drawTurtles(linecolors,moves,leftColor,rightColor,backColor,bottom,left,right,back,bottomNs,leftNs,rightNs,backNs){
> > gl.uniform1i( uLit, 0 );
> >
> > var after = function() {
> > bottomColor = [ 1,1,1,0];
> > gl.uniform1i( uLit, 1 );
> > for(var i=0;i<leftColor.length;i++)
> > {
> > gl.uniform3f( uNormal, leftNs[i][0],leftNs[i][1],leftNs[i][2]);
> > drawPrimitive( gl.TRIANGLES, leftColor[i], left[i]);
> > gl.uniform3f( uNormal,
> rightNs[i][0],rightNs[i][1],rightNs[i][2]);
> > drawPrimitive( gl.TRIANGLES, rightColor[i], right[i]);
> > gl.uniform3f( uNormal, backNs[i][0],backNs[i][1],backNs[i][2]);
> > drawPrimitive( gl.TRIANGLES, backColor[i], back[i]);
> > gl.uniform3f( uNormal,
> > -bottomNs[i][0],-bottomNs[i][1],-bottomNs[i][2]);
> > drawPrimitive( gl.TRIANGLES, bottomColor, bottom[i]);
> > }
> >
> > }
> > drawLines(linecolors,moves, after)
> > }
> >
> > Then your drawLines becomes:
> >
> > function drawLines(linecolors,moves, callback) {
> > gl.lineWidth(2);
> > gl.uniform1i( uLit, 0 );
> > for(var i=0;i<linecolors.length;i++)
> > {
> > var drawFrame = function() {
> > heavy_process();
> > drawPrimitive( gl.LINES, linecolors[i], moves[i]);
> >
> > //resume the rest of the drawing after the last frame is
> > drawn
> > if (i == linecolors.length-1) { callback(); }
> > }
> > requestAnimationFrame(drawFrame);
> >
> > }
> > gl.lineWidth(1);
> > }
> >
> > haven't tested
> >
> >
> >
> --
> (B=)
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm