P3D performace improvement.
On my computer, the normal P3D runs with regular frame rate drops down to 8.
I worked on a solution to fix this and my best one works much better.
The fix was binding an array to a filp function, in order to reuse the same buffer.
I named it flip because it's like flipping a normal double buffer.
The apparent side effect of this solution is that the image is mirrored and upside-down.
This can regardless be an alternative for those who can't stand working with P3D in a webpage project.
Replies welcome any year.
Code:
var p3d,flip;
var init = function() {
if(flip){return;}var e=["constructor","prototype","$ensureContext"];
if(!this[e[0]][e[1]][e[2]]){return !0;}p3d=createGraphics(width,height,P3D);
p3d.lights();flip=nf[e[0]]("a","b","c","d","a.readPixels(0,0,a.drawingBuffer"+
"Width,a.drawingBufferHeight,a.RGBA,a.UNSIGNED_BYTE,b);d.data.set(b);c.putIm"+
"ageData(d,0,0)").bind(this,p3d[e[0]][e[1]][e[2]](),nf[e[0]]("x","return new"+
" Uint8Array(x)")(width*height*4),e=this[e[0]][e[1]][e[2]](),
e.createImageData(width,height));
};
var c = [0,0,0], t = [0,0,0], up = [0,1,0];
var len = 346.410161513775591;
var rot = 90;
var img = [
getImage("avatars/old-spice-man-blue"),
getImage("avatars/orange-juice-squid"),
getImage("avatars/mr-pink"),
getImage("avatars/mr-pants-with-hat"),
getImage("avatars/marcimus-red")
];
var idx = 0, lmt = img.length;
draw = function() {
if (init()) {return;}
rot = frameCount;
c[0] = len*cos(rot);
c[2] = len*sin(rot);
if (frameCount%360===90) {
idx++;
idx %= lmt;
}
var x1,y1,z1, x2,y2,z2;
try {
p3d.beginCamera();
} catch (e) {
p3d.endCamera();
p3d.beginCamera();
}
p3d.camera(c[0],c[1],c[2],t[0],t[1],t[2],up[0],up[1],up[2]);
p3d.background(0);
p3d.pushMatrix();
p3d.ambient(0);
p3d.emissive(0);
p3d.noStroke();
p3d.sphereDetail(32);
p3d.fill(255);
p3d.sphere(100);
p3d.emissive(255);
p3d.translate(0,0,-200);
p3d.rotateY(PI/2-frameCount/180*PI);
p3d.textureMode(NORMALIZED);
p3d.beginShape();
p3d.texture(img[idx]);
p3d.vertex(-100,100,1,0);
p3d.vertex(100,100,0,0);
p3d.vertex(100,-100,0,1);
p3d.vertex(-100,-100,1,1);
p3d.endShape(CLOSE);
p3d.popMatrix();
try {
p3d.endCamera();
} catch (e) {}
flip();
textSize(12);
fill(0xffffff00);
text("FPS: "+~~this.__frameRate, 2, height-2);
};
Post is closed for comments.