summaryrefslogtreecommitdiff
path: root/graphics/asymptote/webgl/gl.js
diff options
context:
space:
mode:
Diffstat (limited to 'graphics/asymptote/webgl/gl.js')
-rw-r--r--graphics/asymptote/webgl/gl.js98
1 files changed, 51 insertions, 47 deletions
diff --git a/graphics/asymptote/webgl/gl.js b/graphics/asymptote/webgl/gl.js
index 00375ee57f..024a886fc6 100644
--- a/graphics/asymptote/webgl/gl.js
+++ b/graphics/asymptote/webgl/gl.js
@@ -522,7 +522,7 @@ class vertexBuffer {
}
// indexed colored vertex
- iVertex(i,v,n,c=[0,0,0,0]) {
+ iVertex(i,v,n,onscreen,c=[0,0,0,0]) {
let i6=6*i;
this.vertices[i6]=v[0];
this.vertices[i6+1]=v[1];
@@ -536,7 +536,8 @@ class vertexBuffer {
this.colors[i4+1]=c[1];
this.colors[i4+2]=c[2];
this.colors[i4+3]=c[3];
- this.indices.push(i);
+ if(onscreen)
+ this.indices.push(i);
}
append(data) {
@@ -718,7 +719,7 @@ class BezierPatch extends Geometry {
if(color) {
let sum=color[0][3]+color[1][3]+color[2][3];
this.transparent=(n == 16 || n == 4) ?
- sum+color[3][3] < 1020 : sum < 765;
+ sum+color[3][3] < 4 : sum < 3;
} else
this.transparent=Materials[MaterialIndex].diffuse[3] < 1;
@@ -1811,7 +1812,7 @@ class BezierPatch extends Geometry {
// Check the horizontal flatness.
let h=Flatness(p0,p12,p3,p15);
// Check straightness of the horizontal edges and interior control curves.
- h=Math.max(Straightness(p0,p[4],p[8],p12));
+ h=Math.max(h,Straightness(p0,p[4],p[8],p12));
h=Math.max(h,Straightness(p[1],p[5],p[9],p[13]));
h=Math.max(h,Straightness(p3,p[7],p[11],p15));
h=Math.max(h,Straightness(p[2],p[6],p[10],p[14]));
@@ -2158,14 +2159,15 @@ class Triangles extends Geometry {
super();
this.CenterIndex=CenterIndex;
this.MaterialIndex=MaterialIndex;
- this.Min=this.Bounds(Positions,Math.min);
- this.Max=this.Bounds(Positions,Math.max);
- this.controlpoints=Positions;
- this.Normals=Normals;
- this.Colors=Colors;
- this.Indices=Indices;
+ this.controlpoints=window.Positions;
+ this.Normals=window.Normals;
+ this.Colors=window.Colors;
+ this.Indices=window.Indices;
this.transparent=Materials[this.MaterialIndex].diffuse[3] < 1;
+
+ this.Min=this.Bounds(this.controlpoints,Math.min);
+ this.Max=this.Bounds(this.controlpoints,Math.max);
}
Bounds(p,m) {
@@ -2188,6 +2190,7 @@ class Triangles extends Geometry {
}
process(p) {
+
this.data.vertices=new Array(6*p.length);
// Override materialIndex to encode color vs material
materialIndex=this.Colors.length > 0 ?
@@ -2199,41 +2202,40 @@ class Triangles extends Geometry {
let P0=p[PI[0]];
let P1=p[PI[1]];
let P2=p[PI[2]];
- if(!this.offscreen([P0,P1,P2])) {
- let NI=index.length > 1 ? index[1] : PI;
- if(!NI || NI.length == 0) NI=PI;
- if(this.Colors.length > 0) {
- let CI=index.length > 2 ? index[2] : PI;
- if(!CI || CI.length == 0) CI=PI;
- let C0=this.Colors[CI[0]];
- let C1=this.Colors[CI[1]];
- let C2=this.Colors[CI[2]];
- this.transparent |= C0[3]+C1[3]+C2[3] < 765;
- if(wireframe == 0) {
- this.data.iVertex(PI[0],P0,this.Normals[NI[0]],C0);
- this.data.iVertex(PI[1],P1,this.Normals[NI[1]],C1);
- this.data.iVertex(PI[2],P2,this.Normals[NI[2]],C2);
- } else {
- this.data.iVertex(PI[0],P0,this.Normals[NI[0]],C0);
- this.data.iVertex(PI[1],P1,this.Normals[NI[1]],C1);
- this.data.iVertex(PI[1],P1,this.Normals[NI[1]],C1);
- this.data.iVertex(PI[2],P2,this.Normals[NI[2]],C2);
- this.data.iVertex(PI[2],P2,this.Normals[NI[2]],C2);
- this.data.iVertex(PI[0],P0,this.Normals[NI[0]],C0);
- }
+ let onscreen=!this.offscreen([P0,P1,P2]);
+ let NI=index.length > 1 ? index[1] : PI;
+ if(!NI || NI.length == 0) NI=PI;
+ if(this.Colors.length > 0) {
+ let CI=index.length > 2 ? index[2] : PI;
+ if(!CI || CI.length == 0) CI=PI;
+ let C0=this.Colors[CI[0]];
+ let C1=this.Colors[CI[1]];
+ let C2=this.Colors[CI[2]];
+ this.transparent |= C0[3]+C1[3]+C2[3] < 3;
+ if(wireframe == 0) {
+ this.data.iVertex(PI[0],P0,this.Normals[NI[0]],onscreen,C0);
+ this.data.iVertex(PI[1],P1,this.Normals[NI[1]],onscreen,C1);
+ this.data.iVertex(PI[2],P2,this.Normals[NI[2]],onscreen,C2);
} else {
- if(wireframe == 0) {
- this.data.iVertex(PI[0],P0,this.Normals[NI[0]]);
- this.data.iVertex(PI[1],P1,this.Normals[NI[1]]);
- this.data.iVertex(PI[2],P2,this.Normals[NI[2]]);
- } else {
- this.data.iVertex(PI[0],P0,this.Normals[NI[0]]);
- this.data.iVertex(PI[1],P1,this.Normals[NI[1]]);
- this.data.iVertex(PI[1],P1,this.Normals[NI[1]]);
- this.data.iVertex(PI[2],P2,this.Normals[NI[2]]);
- this.data.iVertex(PI[2],P2,this.Normals[NI[2]]);
- this.data.iVertex(PI[0],P0,this.Normals[NI[0]]);
- }
+ this.data.iVertex(PI[0],P0,this.Normals[NI[0]],onscreen,C0);
+ this.data.iVertex(PI[1],P1,this.Normals[NI[1]],onscreen,C1);
+ this.data.iVertex(PI[1],P1,this.Normals[NI[1]],onscreen,C1);
+ this.data.iVertex(PI[2],P2,this.Normals[NI[2]],onscreen,C2);
+ this.data.iVertex(PI[2],P2,this.Normals[NI[2]],onscreen,C2);
+ this.data.iVertex(PI[0],P0,this.Normals[NI[0]],onscreen,C0);
+ }
+ } else {
+ if(wireframe == 0) {
+ this.data.iVertex(PI[0],P0,this.Normals[NI[0]],onscreen);
+ this.data.iVertex(PI[1],P1,this.Normals[NI[1]],onscreen);
+ this.data.iVertex(PI[2],P2,this.Normals[NI[2]],onscreen);
+ } else {
+ this.data.iVertex(PI[0],P0,this.Normals[NI[0]],onscreen);
+ this.data.iVertex(PI[1],P1,this.Normals[NI[1]],onscreen);
+ this.data.iVertex(PI[1],P1,this.Normals[NI[1]],onscreen);
+ this.data.iVertex(PI[2],P2,this.Normals[NI[2]],onscreen);
+ this.data.iVertex(PI[2],P2,this.Normals[NI[2]],onscreen);
+ this.data.iVertex(PI[0],P0,this.Normals[NI[0]],onscreen);
}
}
}
@@ -3224,10 +3226,10 @@ function resize()
window.parent.asyProjection=false;
if(W.absolute && !W.embedded) {
- W.canvasWidth=W.canvasWith0*window.devicePixelRatio;
+ W.canvasWidth=W.canvasWidth0*window.devicePixelRatio;
W.canvasHeight=W.canvasHeight0*window.devicePixelRatio;
} else {
- let Aspect=W.canvasWith0/W.canvasHeight0;
+ let Aspect=W.canvasWidth0/W.canvasHeight0;
W.canvasWidth=Math.max(window.innerWidth-windowTrim,windowTrim);
W.canvasHeight=Math.max(window.innerHeight-windowTrim,windowTrim);
@@ -3788,7 +3790,7 @@ function webGLStart()
W.canvas.addEventListener("touchmove",handleTouchMove,false);
document.addEventListener("keydown",handleKey,false);
- W.canvasWith0=W.canvasWidth;
+ W.canvasWidth0=W.canvasWidth;
W.canvasHeight0=W.canvasHeight;
mat4.identity(rotMat);
@@ -3800,6 +3802,8 @@ function webGLStart()
if(W.ibl)
initIBL().then(SetIBL).then(redrawScene);
+
+ home();
}
window.webGLStart=webGLStart;